本文整理汇总了C++中bsStatic函数的典型用法代码示例。如果您正苦于以下问题:C++ bsStatic函数的具体用法?C++ bsStatic怎么用?C++ bsStatic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bsStatic函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sky_ping_message_process
// Checks that the server is up and running. This function is synchronous and
// does not use a worker.
//
// server - The server.
// header - The message header.
// table - The table the message is working against
// input - The input file stream.
// output - The output file stream.
//
// Returns 0 if successful, otherwise returns -1.
int sky_ping_message_process(sky_server *server,
sky_message_header *header,
sky_table *table, FILE *input, FILE *output)
{
size_t sz;
check(server != NULL, "Server required");
check(header != NULL, "Message header required");
check(input != NULL, "Input stream required");
check(output != NULL, "Output stream required");
UNUSED(table);
struct tagbstring status_str = bsStatic("status");
struct tagbstring ok_str = bsStatic("ok");
// Return:
// {status:"OK"}
minipack_fwrite_map(output, 1, &sz);
check(sz > 0, "Unable to write output");
check(sky_minipack_fwrite_bstring(output, &status_str) == 0, "Unable to write status key");
check(sky_minipack_fwrite_bstring(output, &ok_str) == 0, "Unable to write status value");
// Clean up.
fclose(input);
fclose(output);
return 0;
error:
if(input) fclose(input);
if(output) fclose(output);
return -1;
}
示例2: sky_delete_table_message_process
// Deletes a table to the server. This function is synchronous and does not use
// a worker.
//
// server - The server.
// header - The message header.
// table - The table the message is working against
// input - The input file stream.
// output - The output file stream.
//
// Returns 0 if successful, otherwise returns -1.
int sky_delete_table_message_process(sky_server *server,
sky_message_header *header,
sky_table *_table, FILE *input, FILE *output)
{
int rc = 0;
size_t sz;
sky_delete_table_message *message = NULL;
sky_table *table = NULL;
bstring path = NULL;
check(server != NULL, "Server required");
check(header != NULL, "Message header required");
check(input != NULL, "Input stream required");
check(output != NULL, "Output stream required");
(void)_table;
struct tagbstring status_str = bsStatic("status");
struct tagbstring ok_str = bsStatic("ok");
// Parse message.
message = sky_delete_table_message_create(); check_mem(message);
rc = sky_delete_table_message_unpack(message, input);
check(rc == 0, "Unable to parse 'delete_table' message");
// Retrieve table reference from server.
rc = sky_server_get_table(server, message->name, &table);
check(rc == 0, "Unable to find table: %s", bdata(message->name));
check(table != NULL, "Table does not exist: %s", bdata(message->name));
// Detach table first.
path = bstrcpy(table->path); check_mem(path);
rc = sky_server_close_table(server, table);
check(rc == 0, "Unable to close table before deletion");
// If the table exists then delete it.
if(sky_file_exists(path)) {
rc = sky_file_rm_r(path);
check(rc == 0, "Unable to delete table: %s", bdata(path));
}
// Return.
// {status:"OK"}
minipack_fwrite_map(output, 1, &sz);
check(sz > 0, "Unable to write output");
check(sky_minipack_fwrite_bstring(output, &status_str) == 0, "Unable to write status key");
check(sky_minipack_fwrite_bstring(output, &ok_str) == 0, "Unable to write status value");
fclose(input);
fclose(output);
bdestroy(path);
sky_delete_table_message_free(message);
return 0;
error:
if(input) fclose(input);
if(output) fclose(output);
bdestroy(path);
sky_delete_table_message_free(message);
return -1;
}
示例3: test_sky_table_open
int test_sky_table_open() {
struct tagbstring lock_file_path = bsStatic("tmp/.skylock");
struct tagbstring data_file_path = bsStatic("tmp/0/data");
struct tagbstring header_file_path = bsStatic("tmp/0/header");
cleantmp();
int rc;
sky_table *table = sky_table_create();
table->path = bfromcstr("tmp");
// Open table.
rc = sky_table_open(table);
mu_assert_int_equals(rc, 0);
mu_assert(sky_file_exists(&lock_file_path), "");
mu_assert(sky_file_exists(&data_file_path), "");
mu_assert(sky_file_exists(&header_file_path), "");
// Close table.
rc = sky_table_close(table);
mu_assert_int_equals(rc, 0);
mu_assert(!sky_file_exists(&lock_file_path), "");
mu_assert(sky_file_exists(&data_file_path), "");
mu_assert(sky_file_exists(&header_file_path), "");
sky_table_free(table);
return 0;
}
示例4: qip_is_function_type_name
// Retrieves a flag stating if the type name is a function type.
//
// name - The name of the type.
//
// Returns true if the the type is a function type, otherwise returns false.
bool qip_is_function_type_name(bstring name)
{
struct tagbstring function_str1 = bsStatic("Function");
struct tagbstring function_str2 = bsStatic("Function<");
return binstr(name, 0, &function_str1) != BSTR_ERR
|| binstr(name, 0, &function_str2) != BSTR_ERR;
}
示例5: test1
int test1 (void) {
int ret = 0;
printf ("TEST: CBString = operator\n");
try {
CBString c0;
struct tagbstring t = bsStatic ("test");
ret += c0.iswriteprotected();
c0.writeprotect ();
ret += 1 != c0.iswriteprotected();
EXCEPTION_EXPECTED (c0 = 'x');
EXCEPTION_EXPECTED (c0 = (unsigned char) 'x');
EXCEPTION_EXPECTED (c0 = "test");
EXCEPTION_EXPECTED (c0 = CBString ("test"));
EXCEPTION_EXPECTED (c0 = t);
}
catch (struct CBStringException err) {
printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
ret ++;
}
try {
CBString c0, c1;
struct tagbstring t = bsStatic ("test");
printf ("\tc = 'x';\n");
c0 = 'x';
ret += (c0 != "x");
ret += '\0' != ((const char *)c0)[c0.length()];
printf ("\tc = (unsigned char)'x';\n");
c0 = (unsigned char) 'x';
ret += (c0 != "x");
ret += '\0' != ((const char *)c0)[c0.length()];
printf ("\tc = \"test\";\n");
c0 = "test";
ret += (c0 != "test");
ret += '\0' != ((const char *)c0)[c0.length()];
printf ("\tc = CBStr[\"test\"];\n");
c1 = c0;
ret += (c0 != c1);
ret += '\0' != ((const char *)c1)[c1.length()];
printf ("\tc = tbstr[\"test\"];\n");
c0 = t;
ret += (c0 != "test");
ret += '\0' != ((const char *)c0)[c0.length()];
}
catch (struct CBStringException err) {
printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
ret ++;
}
printf ("\t# failures: %d\n", ret);
return ret;
}
示例6: test2
int test2 (void) {
int ret = 0;
printf ("TEST: CBString += operator\n");
try {
CBString c0;
struct tagbstring t = bsStatic ("test");
c0.writeprotect ();
EXCEPTION_EXPECTED (c0 += 'x');
EXCEPTION_EXPECTED (c0 += (unsigned char) 'x');
EXCEPTION_EXPECTED (c0 += "test");
EXCEPTION_EXPECTED (c0 += CBString ("test"));
EXCEPTION_EXPECTED (c0 += t);
}
catch (struct CBStringException err) {
printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
ret ++;
}
try {
CBString c0;
struct tagbstring t = bsStatic ("extra");
c0 = "test";
printf ("\tc += 'x';\n");
c0 += 'x';
ret += (c0 != "testx");
ret += '\0' != ((const char *)c0)[c0.length()];
printf ("\tc += (unsigned char)'x';\n");
c0 += (unsigned char) 'y';
ret += (c0 != "testxy");
ret += '\0' != ((const char *)c0)[c0.length()];
printf ("\tc += \"test\";\n");
c0 += "test";
ret += (c0 != "testxytest");
ret += '\0' != ((const char *)c0)[c0.length()];
printf ("\tc += CBStr[\"test\"];\n");
c0 += CBString (c0);
ret += (c0 != "testxytesttestxytest");
ret += '\0' != ((const char *)c0)[c0.length()];
printf ("\tc += tbstr[\"test\"];\n");
c0 += t;
ret += (c0 != "testxytesttestxytestextra");
ret += '\0' != ((const char *)c0)[c0.length()];
}
catch (struct CBStringException err) {
printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
ret ++;
}
printf ("\t# failures: %d\n", ret);
return ret;
}
示例7: sky_get_properties_message_process
// Retrieves a list of properties from the server for a table. This function is
// synchronous and does not use a worker.
//
// server - The server.
// header - The message header.
// table - The table the message is working against
// input - The input file stream.
// output - The output file stream.
//
// Returns 0 if successful, otherwise returns -1.
int sky_get_properties_message_process(sky_server *server,
sky_message_header *header,
sky_table *table, FILE *input, FILE *output)
{
int rc = 0;
size_t sz;
sky_get_properties_message *message = NULL;
check(server != NULL, "Server required");
check(header != NULL, "Message header required");
check(table != NULL, "Table required");
check(input != NULL, "Input stream required");
check(output != NULL, "Output stream required");
struct tagbstring status_str = bsStatic("status");
struct tagbstring ok_str = bsStatic("ok");
struct tagbstring properties_str = bsStatic("properties");
// Parse message.
message = sky_get_properties_message_create(); check_mem(message);
rc = sky_get_properties_message_unpack(message, input);
check(rc == 0, "Unable to parse 'get_properties' message");
// Return.
// {status:"OK", properties:[{...}]}
minipack_fwrite_map(output, 2, &sz);
check(sz > 0, "Unable to write output");
check(sky_minipack_fwrite_bstring(output, &status_str) == 0, "Unable to write status key");
check(sky_minipack_fwrite_bstring(output, &ok_str) == 0, "Unable to write status value");
check(sky_minipack_fwrite_bstring(output, &properties_str) == 0, "Unable to write properties key");
// Loop over properties and serialize them.
minipack_fwrite_array(output, table->property_file->property_count, &sz);
check(sz > 0, "Unable to write properties array");
uint32_t i;
for(i=0; i<table->property_file->property_count; i++) {
sky_property *property = table->property_file->properties[i];
check(sky_property_pack(property, output) == 0, "Unable to write property");
}
// Clean up.
sky_get_properties_message_free(message);
fclose(input);
fclose(output);
return 0;
error:
sky_get_properties_message_free(message);
if(input) fclose(input);
if(output) fclose(output);
return -1;
}
示例8: test_sky_data_file_deduplicate_insertion_event_data
int test_sky_data_file_deduplicate_insertion_event_data() {
struct tagbstring STR1 = bsStatic("foo");
struct tagbstring STR2 = bsStatic("bar");
struct tagbstring STR3 = bsStatic("zzz");
int rc;
sky_event *event;
sky_data_file *data_file;
INIT_DATA_FILE("tests/fixtures/data_files/dedup/0/a", 0);
// Add initial event.
event = sky_event_create(1, 10LL, 1);
event->data_count = 8;
event->data = calloc(event->data_count, sizeof(*event->data));
event->data[0] = sky_event_data_create_string(-1, &STR2);
event->data[1] = sky_event_data_create_int(-2, 200);
event->data[2] = sky_event_data_create_double(-3, 1.0);
event->data[3] = sky_event_data_create_boolean(-4, false);
event->data[4] = sky_event_data_create_string(1, &STR1);
event->data[5] = sky_event_data_create_int(2, 100);
event->data[6] = sky_event_data_create_double(3, 100.2);
event->data[7] = sky_event_data_create_boolean(4, true);
rc = sky_data_file_add_event(data_file, event);
mu_assert_int_equals(rc, 0);
ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/b");
// Add the same event data, different timestamp.
event->timestamp = 11LL;
rc = sky_data_file_add_event(data_file, event);
mu_assert_int_equals(rc, 0);
sky_event_free(event);
ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/c");
// Add somewhat different object state event.
event = sky_event_create(1, 12LL, 0);
event->data_count = 4;
event->data = calloc(event->data_count, sizeof(*event->data));
event->data[0] = sky_event_data_create_string(1, &STR3);
event->data[1] = sky_event_data_create_int(2, 20);
event->data[2] = sky_event_data_create_double(3, 100.2);
event->data[3] = sky_event_data_create_boolean(4, false);
rc = sky_data_file_add_event(data_file, event);
mu_assert_int_equals(rc, 0);
sky_event_free(event);
ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/d");
sky_data_file_free(data_file);
return 0;
}
示例9: tor_pt_check_config
int
tor_pt_check_config(const tor_pt_config_t *cfg, const bstring methodname)
{
struct tagbstring supported_ver = bsStatic(TOR_PT_MANAGED_TRANSPORT_V1);
struct tagbstring all_methods = bsStatic("*");
int i;
if (cfg->transport_ver == NULL) {
fprintf(stdout, "ENV-ERROR No Managed Transport Version specified\n");
return -1;
}
for (i = 0; i < cfg->transport_ver->qty; i++) {
if (0 == bstrcmp(&supported_ver, cfg->transport_ver->entry[i]))
goto found_compatible_version;
}
fprintf(stdout, "VERSION-ERROR no-version\n");
return -1;
found_compatible_version:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress"
fprintf(stdout, "VERSION %s\n", bdata(&supported_ver));
#pragma GCC diagnostic pop
if (cfg->is_client) {
for (i = 0; i < cfg->client.methods->qty; i++) {
if (0 == bstrcmp(&all_methods,
cfg->client.methods->entry[i]))
goto found_compatible_method;
if (0 == bstrcmp(methodname,
cfg->client.methods->entry[i]))
goto found_compatible_method;
}
tor_pt_on_client_done();
return -1;
} else {
/* Validate the server options */
}
found_compatible_method:
return 0;
}
示例10: test_sky_action_file_save
int test_sky_action_file_save() {
int rc;
struct tagbstring path = bsStatic("tmp/actions");
// Initialize action file.
sky_action_file *action_file = sky_action_file_create();
sky_action_file_set_path(action_file, &path);
// Action 1
sky_action *action1 = sky_action_create();
action1->name = bfromcstr("foo");
rc = sky_action_file_add_action(action_file, action1);
mu_assert_int_equals(rc, 0);
mu_assert_int_equals(action_file->action_count, 1);
// Action 2
sky_action *action2 = sky_action_create();
action2->name = bfromcstr("this_is_a_really_long_action_name_woohoo");
rc = sky_action_file_add_action(action_file, action2);
mu_assert_int_equals(rc, 0);
mu_assert_int_equals(action_file->action_count, 2);
// Save
rc = sky_action_file_save(action_file);
mu_assert_int_equals(rc, 0);
mu_assert_file("tmp/actions", "tests/fixtures/action_files/0");
sky_action_file_free(action_file);
return 0;
}
示例11: START_TEST
END_TEST
START_TEST(core_012)
{
struct tagbstring t = bsStatic("Hello world");
struct bStream * s;
int ret = 0;
bstring b, c;
s = bsFromBstr(&t);
ck_assert(s != NULL);
b = bfromcstr("");
ck_assert(b != NULL);
ret = bsread(b, s, 6);
ck_assert_int_eq(ret, 0);
ret = biseqcstr(b, "Hello ");
ck_assert_int_eq(ret, 1);
if (b) {
b->slen = 0;
}
ret = bsread(b, s, 6);
ck_assert_int_eq(ret, 0);
ret = biseqcstr(b, "world");
ck_assert_int_eq(ret, 1);
c = bsclose(s);
ck_assert(c == NULL);
ret = bdestroy(b);
ck_assert_int_eq(ret, BSTR_OK);
}
示例12: test1
int test1 (void) {
struct tagbstring t = bsStatic ("Hello world");
bstring b, c, d;
int ret = 0;
printf ("TEST: bTail and bHead functions.\n");
b = bTail (&t, 5);
c = bHead (&t, 5);
ret += 0 >= biseqcstr (b, "world");
ret += 0 >= biseqcstr (c, "Hello");
bdestroy (b);
bdestroy (c);
b = bTail (&t, 0);
c = bHead (&t, 0);
ret += 0 >= biseqcstr (b, "");
ret += 0 >= biseqcstr (c, "");
bdestroy (b);
bdestroy (c);
d = bstrcpy (&t);
b = bTail (d, 5);
c = bHead (d, 5);
ret += 0 >= biseqcstr (b, "world");
ret += 0 >= biseqcstr (c, "Hello");
bdestroy (b);
bdestroy (c);
bdestroy (d);
printf ("\t# failures: %d\n", ret);
return ret;
}
示例13: Host_load
int Host_load(tst_t *settings, Value *val)
{
CONFIRM_TYPE("Host");
Class *cls = val->as.cls;
char *sql = NULL;
struct tagbstring ROUTES_VAR = bsStatic("routes");
const char *name = AST_str(settings, cls->params, "name", VAL_QSTRING);
check(name, "No name set for Host.");
sql = sqlite3_mprintf(bdata(&HOST_SQL), SERVER_ID, name, name);
int rc = DB_exec(sql, NULL, NULL);
check(rc == 0, "Failed to store Host: %s", name);
cls->id = HOST_ID = DB_lastid();
Value *routes = AST_get(settings, cls->params, &ROUTES_VAR, VAL_HASH);
check(routes, "Didn't find any routes for %s", name);
AST_walk_hash(settings, routes, Route_load);
sqlite3_free(sql);
return 0;
error:
if(sql) sqlite3_free(sql);
return -1;
}
示例14: test13
int test13 (void) {
struct tagbstring t0 = bsStatic ("Random String");
struct vfgetc vctx;
bstring b;
int ret = 0;
int i;
printf ("TEST: bSecureInput, bSecureDestroy.\n");
for (i=0; i < 1000; i++) {
unsigned char * h;
vctx.ofs = 0;
vctx.base = &t0;
b = bSecureInput (INT_MAX, '\n', (bNgetc) test13_fgetc, &vctx);
ret += 1 != biseq (b, &t0);
h = b->data;
bSecureDestroy (b);
/* WARNING! Technically unsound code follows: */
ret += (0 == memcmp (h, t0.data, t0.slen));
if (ret) break;
}
printf ("\t# failures: %d\n", ret);
return ret;
}
示例15: sky_property_pack
// Serializes a property to a file stream.
//
// property - The property.
// file - The file stream to write to.
//
// Returns 0 if successful, otherwise returns -1.
int sky_property_pack(sky_property *property, FILE *file)
{
int rc;
size_t sz;
check(property != NULL, "Property required");
check(file != NULL, "File stream required");
struct tagbstring id_str = bsStatic("id");
struct tagbstring type_str = bsStatic("type");
struct tagbstring data_type_str = bsStatic("dataType");
struct tagbstring name_str = bsStatic("name");
// Update the type just in case.
rc = sky_property_update_type(property);
check(rc == 0, "Unable to update property type");
// Map
minipack_fwrite_map(file, 4, &sz);
check(sz > 0, "Unable to write map");
// ID
check(sky_minipack_fwrite_bstring(file, &id_str) == 0, "Unable to write id key");
minipack_fwrite_int(file, property->id, &sz);
check(sz > 0, "Unable to write id value");
// Type
check(sky_minipack_fwrite_bstring(file, &type_str) == 0, "Unable to write type key");
minipack_fwrite_uint(file, property->type, &sz);
check(sz > 0, "Unable to write type value");
// Data Type
check(sky_minipack_fwrite_bstring(file, &data_type_str) == 0, "Unable to write data type key");
bstring data_type_name = sky_data_type_to_str(property->data_type);
check(sky_minipack_fwrite_bstring(file, data_type_name) == 0, "Unable to write data type value");
bdestroy(data_type_name);
// Name
check(sky_minipack_fwrite_bstring(file, &name_str) == 0, "Unable to write name key");
check(sky_minipack_fwrite_bstring(file, property->name) == 0, "Unable to write name value");
return 0;
error:
return -1;
}