本文整理汇总了C++中smartlist_new函数的典型用法代码示例。如果您正苦于以下问题:C++ smartlist_new函数的具体用法?C++ smartlist_new怎么用?C++ smartlist_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了smartlist_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_container_smartlist_join
/** Run unit tests for concatenate-a-smartlist-of-strings functions. */
static void
test_container_smartlist_join(void)
{
smartlist_t *sl = smartlist_new();
smartlist_t *sl2 = smartlist_new(), *sl3 = smartlist_new(),
*sl4 = smartlist_new();
char *joined=NULL;
/* unique, sorted. */
smartlist_split_string(sl,
"Abashments Ambush Anchorman Bacon Banks Borscht "
"Bunks Inhumane Insurance Knish Know Manners "
"Maraschinos Stamina Sunbonnets Unicorns Wombats",
" ", 0, 0);
/* non-unique, sorted. */
smartlist_split_string(sl2,
"Ambush Anchorman Anchorman Anemias Anemias Bacon "
"Crossbowmen Inhumane Insurance Knish Know Manners "
"Manners Maraschinos Wombats Wombats Work",
" ", 0, 0);
SMARTLIST_FOREACH_JOIN(sl, char *, cp1,
sl2, char *, cp2,
strcmp(cp1,cp2),
smartlist_add(sl3, cp2)) {
test_streq(cp1, cp2);
smartlist_add(sl4, cp1);
} SMARTLIST_FOREACH_JOIN_END(cp1, cp2);
示例2: test_rend_cache_store_v2_desc_as_dir_with_different_content
static void
test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
{
(void)data;
rend_cache_store_status_t ret;
rend_service_descriptor_t *generated = NULL;
smartlist_t *descs = smartlist_new();
time_t t;
char *service_id = NULL;
rend_encoded_v2_service_descriptor_t *desc_holder_one = NULL;
rend_encoded_v2_service_descriptor_t *desc_holder_two = NULL;
NS_MOCK(router_get_my_routerinfo);
NS_MOCK(hid_serv_responsible_for_desc_id);
rend_cache_init();
t = time(NULL);
create_descriptor(&generated, &service_id, 3);
generated->timestamp = t + RECENT_TIME;
rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
REND_NO_AUTH, NULL, NULL);
desc_holder_one = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
smartlist_set(descs, 0, NULL);
SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
rend_encoded_v2_service_descriptor_free(d));
smartlist_free(descs);
descs = smartlist_new();
generated->timestamp = t + RECENT_TIME;
generated->protocols = 41;
rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
REND_NO_AUTH, NULL, NULL);
desc_holder_two = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
smartlist_set(descs, 0, NULL);
// Test when we have another descriptor stored, with a different descriptor
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
hid_serv_responsible_for_desc_id_response = 1;
rend_cache_store_v2_desc_as_dir(desc_holder_one->desc_str);
ret = rend_cache_store_v2_desc_as_dir(desc_holder_two->desc_str);
tt_int_op(ret, OP_EQ, RCS_OKAY);
done:
NS_UNMOCK(router_get_my_routerinfo);
NS_UNMOCK(hid_serv_responsible_for_desc_id);
rend_cache_free_all();
rend_service_descriptor_free(generated);
tor_free(service_id);
SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
rend_encoded_v2_service_descriptor_free(d));
smartlist_free(descs);
rend_encoded_v2_service_descriptor_free(desc_holder_one);
rend_encoded_v2_service_descriptor_free(desc_holder_two);
}
示例3: setup_mock_consensus
static void
setup_mock_consensus(void)
{
current_md_consensus = current_ns_consensus =
tor_malloc_zero(sizeof(networkstatus_t));
current_md_consensus->net_params = smartlist_new();
current_md_consensus->routerstatus_list = smartlist_new();
}
示例4: routerset_new
/** Return a new empty routerset. */
routerset_t *
routerset_new(void)
{
routerset_t *result = tor_malloc_zero(sizeof(routerset_t));
result->list = smartlist_new();
result->names = strmap_new();
result->digests = digestmap_new();
result->policies = smartlist_new();
result->country_names = smartlist_new();
return result;
}
示例5: helper_create_rend_service
static rend_service_t *
helper_create_rend_service(const char *path)
{
rend_service_t *s = tor_malloc_zero(sizeof(rend_service_t));
s->ports = smartlist_new();
s->intro_nodes = smartlist_new();
s->expiring_nodes = smartlist_new();
if (path) {
s->directory = tor_strdup(path);
}
return s;
}
示例6: dir_common_setup_vote
/** Initialize networkstatus vote object attributes. */
void
dir_common_setup_vote(networkstatus_t **vote, time_t now)
{
*vote = tor_malloc_zero(sizeof(networkstatus_t));
(*vote)->type = NS_TYPE_VOTE;
(*vote)->published = now;
(*vote)->supported_methods = smartlist_new();
(*vote)->known_flags = smartlist_new();
(*vote)->net_params = smartlist_new();
(*vote)->routerstatus_list = smartlist_new();
(*vote)->voters = smartlist_new();
}
示例7: test_container_smartlist_overlap
/** Run unit tests for smartlist set manipulation functions. */
static void
test_container_smartlist_overlap(void *arg)
{
smartlist_t *sl = smartlist_new();
smartlist_t *ints = smartlist_new();
smartlist_t *odds = smartlist_new();
smartlist_t *evens = smartlist_new();
smartlist_t *primes = smartlist_new();
int i;
(void)arg;
for (i=1; i < 10; i += 2)
smartlist_add(odds, (void*)(uintptr_t)i);
for (i=0; i < 10; i += 2)
smartlist_add(evens, (void*)(uintptr_t)i);
/* add_all */
smartlist_add_all(ints, odds);
smartlist_add_all(ints, evens);
tt_int_op(smartlist_len(ints),OP_EQ, 10);
smartlist_add(primes, (void*)2);
smartlist_add(primes, (void*)3);
smartlist_add(primes, (void*)5);
smartlist_add(primes, (void*)7);
/* overlap */
tt_assert(smartlist_overlap(ints, odds));
tt_assert(smartlist_overlap(odds, primes));
tt_assert(smartlist_overlap(evens, primes));
tt_assert(!smartlist_overlap(odds, evens));
/* intersect */
smartlist_add_all(sl, odds);
smartlist_intersect(sl, primes);
tt_int_op(smartlist_len(sl),OP_EQ, 3);
tt_assert(smartlist_contains(sl, (void*)3));
tt_assert(smartlist_contains(sl, (void*)5));
tt_assert(smartlist_contains(sl, (void*)7));
/* subtract */
smartlist_add_all(sl, primes);
smartlist_subtract(sl, odds);
tt_int_op(smartlist_len(sl),OP_EQ, 1);
tt_assert(smartlist_contains(sl, (void*)2));
done:
smartlist_free(odds);
smartlist_free(evens);
smartlist_free(ints);
smartlist_free(primes);
smartlist_free(sl);
}
示例8: test_container_smartlist_strings_eq
static void
test_container_smartlist_strings_eq(void *arg)
{
(void)arg;
smartlist_t *sl1 = smartlist_new();
smartlist_t *sl2 = smartlist_new();
#define EQ_SHOULD_SAY(s1,s2,val) \
do { \
SMARTLIST_FOREACH(sl1, char *, cp, tor_free(cp)); \
SMARTLIST_FOREACH(sl2, char *, cp, tor_free(cp)); \
smartlist_clear(sl1); \
smartlist_clear(sl2); \
smartlist_split_string(sl1, (s1), ":", 0, 0); \
smartlist_split_string(sl2, (s2), ":", 0, 0); \
tt_int_op((val), OP_EQ, smartlist_strings_eq(sl1, sl2)); \
} while (0)
/* Both NULL, so equal */
tt_int_op(1, ==, smartlist_strings_eq(NULL, NULL));
/* One NULL, not equal. */
tt_int_op(0, ==, smartlist_strings_eq(NULL, sl1));
tt_int_op(0, ==, smartlist_strings_eq(sl1, NULL));
/* Both empty, both equal. */
EQ_SHOULD_SAY("", "", 1);
/* One empty, not equal */
EQ_SHOULD_SAY("", "ab", 0);
EQ_SHOULD_SAY("", "xy:z", 0);
EQ_SHOULD_SAY("abc", "", 0);
EQ_SHOULD_SAY("abc:cd", "", 0);
/* Different lengths, not equal. */
EQ_SHOULD_SAY("hello:world", "hello", 0);
EQ_SHOULD_SAY("hello", "hello:friends", 0);
/* Same lengths, not equal */
EQ_SHOULD_SAY("Hello:world", "goodbye:world", 0);
EQ_SHOULD_SAY("Hello:world", "Hello:stars", 0);
/* Actually equal */
EQ_SHOULD_SAY("ABC", "ABC", 1);
EQ_SHOULD_SAY(" ab : cd : e", " ab : cd : e", 1);
done:
SMARTLIST_FOREACH(sl1, char *, cp, tor_free(cp));
SMARTLIST_FOREACH(sl2, char *, cp, tor_free(cp));
smartlist_free(sl1);
smartlist_free(sl2);
}
示例9: cert_dl_status_sks_for_auth_id_mock
static smartlist_t *
cert_dl_status_sks_for_auth_id_mock(const char *digest)
{
smartlist_t *list = NULL;
char sk[DIGEST_LEN];
char digest_str[HEX_DIGEST_LEN+1];
char *tmp;
int len;
tt_assert(digest != NULL);
base16_encode(digest_str, HEX_DIGEST_LEN + 1,
digest, DIGEST_LEN);
digest_str[HEX_DIGEST_LEN] = '\0';
/*
* Build a list of two hard-coded digests, depending on what we
* were just passed.
*/
if (strcmp(digest_str, auth_id_digest_1_str) == 0) {
list = smartlist_new();
len = base16_decode(sk, DIGEST_LEN,
auth_1_sk_1_str, strlen(auth_1_sk_1_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, sk, DIGEST_LEN);
smartlist_add(list, tmp);
len = base16_decode(sk, DIGEST_LEN,
auth_1_sk_2_str, strlen(auth_1_sk_2_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, sk, DIGEST_LEN);
smartlist_add(list, tmp);
} else if (strcmp(digest_str, auth_id_digest_2_str) == 0) {
list = smartlist_new();
len = base16_decode(sk, DIGEST_LEN,
auth_2_sk_1_str, strlen(auth_2_sk_1_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, sk, DIGEST_LEN);
smartlist_add(list, tmp);
len = base16_decode(sk, DIGEST_LEN,
auth_2_sk_2_str, strlen(auth_2_sk_2_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, sk, DIGEST_LEN);
smartlist_add(list, tmp);
}
done:
return list;
}
示例10: get_majority_srv_from_votes
/* Using a list of <b>votes</b>, return the SRV object from them that has
* been voted by the majority of dirauths. If <b>current</b> is set, we look
* for the current SRV value else the previous one. The returned pointer is
* an object located inside a vote. NULL is returned if no appropriate value
* could be found. */
STATIC sr_srv_t *
get_majority_srv_from_votes(const smartlist_t *votes, int current)
{
int count = 0;
sr_srv_t *most_frequent_srv = NULL;
sr_srv_t *the_srv = NULL;
smartlist_t *srv_list;
tor_assert(votes);
srv_list = smartlist_new();
/* Walk over votes and register any SRVs found. */
SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
sr_srv_t *srv_tmp = NULL;
if (!v->sr_info.participate) {
/* Ignore vote that do not participate. */
continue;
}
/* Do we want previous or current SRV? */
srv_tmp = current ? v->sr_info.current_srv : v->sr_info.previous_srv;
if (!srv_tmp) {
continue;
}
smartlist_add(srv_list, srv_tmp);
} SMARTLIST_FOREACH_END(v);
示例11: get_ns_str_from_sr_values
/* Given the previous SRV and the current SRV, return a heap allocated
* string with their data that could be put in a vote or a consensus. Caller
* must free the returned string. Return NULL if no SRVs were provided. */
static char *
get_ns_str_from_sr_values(const sr_srv_t *prev_srv, const sr_srv_t *cur_srv)
{
smartlist_t *chunks = NULL;
char *srv_str;
if (!prev_srv && !cur_srv) {
return NULL;
}
chunks = smartlist_new();
if (prev_srv) {
char *srv_line = srv_to_ns_string(prev_srv, previous_srv_str);
smartlist_add(chunks, srv_line);
}
if (cur_srv) {
char *srv_line = srv_to_ns_string(cur_srv, current_srv_str);
smartlist_add(chunks, srv_line);
}
/* Join the line(s) here in one string to return. */
srv_str = smartlist_join_strings(chunks, "", 0, NULL);
SMARTLIST_FOREACH(chunks, char *, s, tor_free(s));
smartlist_free(chunks);
return srv_str;
}
示例12: pick_oos_victims_mock
static smartlist_t *
pick_oos_victims_mock(int n)
{
smartlist_t *l = NULL;
int i;
++pick_oos_mock_calls;
tt_int_op(n, OP_GT, 0);
if (!pick_oos_mock_fail) {
/*
* connection_check_oos() just passes the list onto
* kill_conn_list_for_oos(); we don't need to simulate
* its content for this mock, just its existence, but
* we do need to check the parameter.
*/
l = smartlist_new();
for (i = 0; i < n; ++i) smartlist_add(l, NULL);
} else {
l = NULL;
}
pick_oos_mock_last_n = n;
done:
return l;
}
示例13: dir_common_generate_ri_from_rs
/** Helper: Make a new routerinfo containing the right information for a
* given vote_routerstatus_t. */
routerinfo_t *
dir_common_generate_ri_from_rs(const vote_routerstatus_t *vrs)
{
routerinfo_t *r;
const routerstatus_t *rs = &vrs->status;
static time_t published = 0;
r = tor_malloc_zero(sizeof(routerinfo_t));
r->cert_expiration_time = TIME_MAX;
memcpy(r->cache_info.identity_digest, rs->identity_digest, DIGEST_LEN);
memcpy(r->cache_info.signed_descriptor_digest, rs->descriptor_digest,
DIGEST_LEN);
r->cache_info.do_not_cache = 1;
r->cache_info.routerlist_index = -1;
r->cache_info.signed_descriptor_body =
tor_strdup("123456789012345678901234567890123");
r->cache_info.signed_descriptor_len =
strlen(r->cache_info.signed_descriptor_body);
r->exit_policy = smartlist_new();
r->cache_info.published_on = ++published + time(NULL);
if (rs->has_bandwidth) {
/*
* Multiply by 1000 because the routerinfo_t and the routerstatus_t
* seem to use different units (*sigh*) and because we seem stuck on
* icky and perverse decimal kilobytes (*double sigh*) - see
* router_get_advertised_bandwidth_capped() of routerlist.c and
* routerstatus_format_entry() of dirserv.c.
*/
r->bandwidthrate = rs->bandwidth_kb * 1000;
r->bandwidthcapacity = rs->bandwidth_kb * 1000;
}
return r;
}
示例14: test_policy_summary_helper
/** Helper: Parse the exit policy string in <b>policy_str</b>, and make sure
* that policies_summarize() produces the string <b>expected_summary</b> from
* it. */
static void
test_policy_summary_helper(const char *policy_str,
const char *expected_summary)
{
config_line_t line;
smartlist_t *policy = smartlist_new();
char *summary = NULL;
char *summary_after = NULL;
int r;
short_policy_t *short_policy = NULL;
line.key = (char*)"foo";
line.value = (char *)policy_str;
line.next = NULL;
r = policies_parse_exit_policy(&line, &policy, 1, 0, 0, 1);
test_eq(r, 0);
summary = policy_summarize(policy, AF_INET);
test_assert(summary != NULL);
test_streq(summary, expected_summary);
short_policy = parse_short_policy(summary);
tt_assert(short_policy);
summary_after = write_short_policy(short_policy);
test_streq(summary, summary_after);
done:
tor_free(summary_after);
tor_free(summary);
if (policy)
addr_policy_list_free(policy);
short_policy_free(short_policy);
}
示例15: tor_capture_bugs_
void
tor_capture_bugs_(int n)
{
tor_end_capture_bugs_();
bug_messages = smartlist_new();
n_bugs_to_capture = n;
}