本文整理汇总了C++中smartlist_add函数的典型用法代码示例。如果您正苦于以下问题:C++ smartlist_add函数的具体用法?C++ smartlist_add怎么用?C++ smartlist_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了smartlist_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_container_smartlist_sort_ptrs
static void
test_container_smartlist_sort_ptrs(void *arg)
{
(void)arg;
int array[10];
int *arrayptrs[11];
smartlist_t *sl = smartlist_new();
unsigned i=0, j;
for (j = 0; j < ARRAY_LENGTH(array); ++j) {
smartlist_add(sl, &array[j]);
arrayptrs[i++] = &array[j];
if (j == 5) {
smartlist_add(sl, &array[j]);
arrayptrs[i++] = &array[j];
}
}
for (i = 0; i < 10; ++i) {
smartlist_shuffle(sl);
smartlist_sort_pointers(sl);
for (j = 0; j < ARRAY_LENGTH(arrayptrs); ++j) {
tt_ptr_op(smartlist_get(sl, j), ==, arrayptrs[j]);
}
}
done:
smartlist_free(sl);
}
示例2: descbr_get_digests_mock
static smartlist_t *
descbr_get_digests_mock(void)
{
char digest[DIGEST_LEN], *tmp;
int len;
smartlist_t *list = NULL;
if (!disable_descbr) {
/* Just pretend we have only the two hard-coded digests listed above */
list = smartlist_new();
len = base16_decode(digest, DIGEST_LEN,
descbr_digest_1_str, strlen(descbr_digest_1_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, digest, DIGEST_LEN);
smartlist_add(list, tmp);
len = base16_decode(digest, DIGEST_LEN,
descbr_digest_2_str, strlen(descbr_digest_2_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, digest, DIGEST_LEN);
smartlist_add(list, tmp);
}
done:
return list;
}
示例3: geoip_add_entry
/** Add an entry to the GeoIP table, mapping all IPs between <b>low</b> and
* <b>high</b>, inclusive, to the 2-letter country code <b>country</b>.
*/
static void
geoip_add_entry(uint32_t low, uint32_t high, const char *country)
{
intptr_t idx;
geoip_entry_t *ent;
void *idxplus1_;
if (high < low)
return;
idxplus1_ = strmap_get_lc(country_idxplus1_by_lc_code, country);
if (!idxplus1_) {
geoip_country_t *c = tor_malloc_zero(sizeof(geoip_country_t));
strlcpy(c->countrycode, country, sizeof(c->countrycode));
tor_strlower(c->countrycode);
smartlist_add(geoip_countries, c);
idx = smartlist_len(geoip_countries) - 1;
strmap_set_lc(country_idxplus1_by_lc_code, country, (void*)(idx+1));
} else {
idx = ((uintptr_t)idxplus1_)-1;
}
{
geoip_country_t *c = smartlist_get(geoip_countries, idx);
tor_assert(!strcasecmp(c->countrycode, country));
}
ent = tor_malloc_zero(sizeof(geoip_entry_t));
ent->ip_low = low;
ent->ip_high = high;
ent->country = idx;
smartlist_add(geoip_entries, ent);
}
示例4: crypto_write_tagged_contents_to_file
/** Write the <b>datalen</b> bytes from <b>data</b> to the file named
* <b>fname</b> in the tagged-data format. This format contains a
* 32-byte header, followed by the data itself. The header is the
* NUL-padded string "== <b>typestring</b>: <b>tag</b> ==". The length
* of <b>typestring</b> and <b>tag</b> must therefore be no more than
* 24.
**/
int
crypto_write_tagged_contents_to_file(const char *fname,
const char *typestring,
const char *tag,
const uint8_t *data,
size_t datalen)
{
char header[32];
smartlist_t *chunks = smartlist_new();
sized_chunk_t ch0, ch1;
int r = -1;
memset(header, 0, sizeof(header));
if (tor_snprintf(header, sizeof(header),
"== %s: %s ==", typestring, tag) < 0)
goto end;
ch0.bytes = header;
ch0.len = 32;
ch1.bytes = (const char*) data;
ch1.len = datalen;
smartlist_add(chunks, &ch0);
smartlist_add(chunks, &ch1);
r = write_chunks_to_file(fname, chunks, 1, 0);
end:
smartlist_free(chunks);
return r;
}
示例5: cert_dl_status_auth_ids_mock
static smartlist_t *
cert_dl_status_auth_ids_mock(void)
{
char digest[DIGEST_LEN], *tmp;
int len;
smartlist_t *list = NULL;
/* Just pretend we have only the two hard-coded digests listed above */
list = smartlist_new();
len = base16_decode(digest, DIGEST_LEN,
auth_id_digest_1_str, strlen(auth_id_digest_1_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, digest, DIGEST_LEN);
smartlist_add(list, tmp);
len = base16_decode(digest, DIGEST_LEN,
auth_id_digest_2_str, strlen(auth_id_digest_2_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, digest, DIGEST_LEN);
smartlist_add(list, tmp);
done:
return list;
}
示例6: test_container_smartlist_digests
/** Run unit tests for smartlist-of-digests functions. */
static void
test_container_smartlist_digests(void)
{
smartlist_t *sl = smartlist_new();
/* contains_digest */
smartlist_add(sl, tor_memdup("AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN));
smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN));
smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN));
test_eq(0, smartlist_contains_digest(NULL, "AAAAAAAAAAAAAAAAAAAA"));
test_assert(smartlist_contains_digest(sl, "AAAAAAAAAAAAAAAAAAAA"));
test_assert(smartlist_contains_digest(sl, "\00090AAB2AAAAaasdAAAAA"));
test_eq(0, smartlist_contains_digest(sl, "\00090AAB2AAABaasdAAAAA"));
/* sort digests */
smartlist_sort_digests(sl);
test_memeq(smartlist_get(sl, 0), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
test_memeq(smartlist_get(sl, 1), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
test_memeq(smartlist_get(sl, 2), "AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN);
test_eq(3, smartlist_len(sl));
/* uniq_digests */
smartlist_uniq_digests(sl);
test_eq(2, smartlist_len(sl));
test_memeq(smartlist_get(sl, 0), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
test_memeq(smartlist_get(sl, 1), "AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN);
done:
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
smartlist_free(sl);
}
示例7: test_container_smartlist_digests
/** Run unit tests for smartlist-of-digests functions. */
static void
test_container_smartlist_digests(void *unused)
{
smartlist_t *sl = smartlist_create();
/* digest_isin. */
smartlist_add(sl, xmemdup("AAAAAAAAAAAAAAAAAAAA", SHA256_LENGTH));
smartlist_add(sl, xmemdup("\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH));
smartlist_add(sl, xmemdup("\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH));
tt_int_op(smartlist_digest_isin(NULL, "AAAAAAAAAAAAAAAAAAAA"), ==, 0);
tt_assert(smartlist_digest_isin(sl, "AAAAAAAAAAAAAAAAAAAA"));
tt_assert(smartlist_digest_isin(sl, "\00090AAB2AAAAaasdAAAAA"));
tt_int_op(smartlist_digest_isin(sl, "\00090AAB2AAABaasdAAAAA"), ==, 0);
/* sort digests */
smartlist_sort_digests(sl);
tt_mem_op(smartlist_get(sl, 0), ==, "\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH);
tt_mem_op(smartlist_get(sl, 1), ==, "\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH);
tt_mem_op(smartlist_get(sl, 2), ==, "AAAAAAAAAAAAAAAAAAAA", SHA256_LENGTH);
tt_int_op(smartlist_len(sl), ==, 3);
/* uniq_digests */
smartlist_uniq_digests(sl);
tt_int_op(smartlist_len(sl), ==, 2);
tt_mem_op(smartlist_get(sl, 0), ==, "\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH);
tt_mem_op(smartlist_get(sl, 1), ==, "AAAAAAAAAAAAAAAAAAAA", SHA256_LENGTH);
end:
SMARTLIST_FOREACH(sl, char *, cp, free(cp));
smartlist_free(sl);
}
示例8: 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;
}
示例9: NS
static void
NS(test_main)(void *arg)
{
/* Choose origin_circuit_t wlog. */
origin_circuit_t *mock_circuit1, *mock_circuit2;
int expected_circuits = 2, actual_circuits;
(void)arg;
mock_circuit1 = tor_malloc_zero(sizeof(origin_circuit_t));
mock_circuit2 = tor_malloc_zero(sizeof(origin_circuit_t));
mock_global_circuitlist = smartlist_new();
smartlist_add(mock_global_circuitlist, TO_CIRCUIT(mock_circuit1));
smartlist_add(mock_global_circuitlist, TO_CIRCUIT(mock_circuit2));
NS_MOCK(circuit_get_global_list);
actual_circuits = count_circuits();
tt_assert(expected_circuits == actual_circuits);
done:
tor_free(mock_circuit1);
tor_free(mock_circuit2);
smartlist_free(mock_global_circuitlist);
mock_global_circuitlist = NULL;
NS_UNMOCK(circuit_get_global_list);
}
示例10: NS
static void
NS(test_main)(void *arg)
{
routerset_t *set = routerset_new();
smartlist_t *out = smartlist_new();
int r;
(void)arg;
NS_MOCK(nodelist_get_list);
smartlist_add(set->country_names, tor_strdup("{xx}"));
NS(mock_smartlist) = smartlist_new();
NS(mock_node).is_running = 0;
smartlist_add(NS(mock_smartlist), (void *)&NS(mock_node));
routerset_get_all_nodes(out, set, NULL, 1);
r = smartlist_len(out);
routerset_free(set);
smartlist_free(out);
smartlist_free(NS(mock_smartlist));
tt_int_op(r, ==, 0);
tt_int_op(CALLED(nodelist_get_list), ==, 1);
done:
;
}
示例11: policy_expand_private
/** Replace all "private" entries in *<b>policy</b> with their expanded
* equivalents. */
void
policy_expand_private(smartlist_t **policy)
{
uint16_t port_min, port_max;
int i;
smartlist_t *tmp;
if (!*policy) /*XXXX disallow NULL policies? */
return;
tmp = smartlist_create();
SMARTLIST_FOREACH(*policy, addr_policy_t *, p,
{
if (! p->is_private) {
smartlist_add(tmp, p);
continue;
}
for (i = 0; private_nets[i]; ++i) {
addr_policy_t policy;
memcpy(&policy, p, sizeof(addr_policy_t));
policy.is_private = 0;
policy.is_canonical = 0;
if (tor_addr_parse_mask_ports(private_nets[i], &policy.addr,
&policy.maskbits, &port_min, &port_max)<0) {
tor_assert(0);
}
smartlist_add(tmp, addr_policy_get_canonical_entry(&policy));
}
addr_policy_free(p);
});
示例12: test_container_smartlist_basic
/** Run unit tests for basic dynamic-sized array functionality. */
static void
test_container_smartlist_basic(void *arg)
{
smartlist_t *sl;
char *v0 = tor_strdup("v0");
char *v1 = tor_strdup("v1");
char *v2 = tor_strdup("v2");
char *v3 = tor_strdup("v3");
char *v4 = tor_strdup("v4");
char *v22 = tor_strdup("v22");
char *v99 = tor_strdup("v99");
char *v555 = tor_strdup("v555");
/* XXXX test sort_digests, uniq_strings, uniq_digests */
/* Test smartlist add, del_keeporder, insert, get. */
(void)arg;
sl = smartlist_new();
smartlist_add(sl, v1);
smartlist_add(sl, v2);
smartlist_add(sl, v3);
smartlist_add(sl, v4);
smartlist_del_keeporder(sl, 1);
smartlist_insert(sl, 1, v22);
smartlist_insert(sl, 0, v0);
smartlist_insert(sl, 5, v555);
tt_ptr_op(v0,OP_EQ, smartlist_get(sl,0));
tt_ptr_op(v1,OP_EQ, smartlist_get(sl,1));
tt_ptr_op(v22,OP_EQ, smartlist_get(sl,2));
tt_ptr_op(v3,OP_EQ, smartlist_get(sl,3));
tt_ptr_op(v4,OP_EQ, smartlist_get(sl,4));
tt_ptr_op(v555,OP_EQ, smartlist_get(sl,5));
/* Try deleting in the middle. */
smartlist_del(sl, 1);
tt_ptr_op(v555,OP_EQ, smartlist_get(sl, 1));
/* Try deleting at the end. */
smartlist_del(sl, 4);
tt_int_op(4,OP_EQ, smartlist_len(sl));
/* test isin. */
tt_assert(smartlist_contains(sl, v3));
tt_assert(!smartlist_contains(sl, v99));
done:
smartlist_free(sl);
tor_free(v0);
tor_free(v1);
tor_free(v2);
tor_free(v3);
tor_free(v4);
tor_free(v22);
tor_free(v99);
tor_free(v555);
}
示例13: test_oos_kill_conn_list
static void
test_oos_kill_conn_list(void *arg)
{
connection_t *c1, *c2;
or_connection_t *or_c1 = NULL;
dir_connection_t *dir_c2 = NULL;
smartlist_t *l = NULL;
(void)arg;
/* Set up mocks */
mark_calls = 0;
MOCK(connection_mark_for_close_internal_, mark_for_close_oos_mock);
cfe_calls = 0;
MOCK(connection_or_close_for_error, close_for_error_mock);
/* Make fake conns */
or_c1 = tor_malloc_zero(sizeof(*or_c1));
or_c1->base_.magic = OR_CONNECTION_MAGIC;
or_c1->base_.type = CONN_TYPE_OR;
c1 = TO_CONN(or_c1);
dir_c2 = tor_malloc_zero(sizeof(*dir_c2));
dir_c2->base_.magic = DIR_CONNECTION_MAGIC;
dir_c2->base_.type = CONN_TYPE_DIR;
dir_c2->base_.state = DIR_CONN_STATE_MIN_;
dir_c2->base_.purpose = DIR_PURPOSE_MIN_;
c2 = TO_CONN(dir_c2);
tt_assert(c1 != NULL);
tt_assert(c2 != NULL);
/* Make list */
l = smartlist_new();
smartlist_add(l, c1);
smartlist_add(l, c2);
/* Run kill_conn_list_for_oos() */
kill_conn_list_for_oos(l);
/* Check call counters */
tt_int_op(mark_calls, OP_EQ, 1);
tt_int_op(cfe_calls, OP_EQ, 1);
done:
UNMOCK(connection_or_close_for_error);
UNMOCK(connection_mark_for_close_internal_);
if (l) smartlist_free(l);
tor_free(or_c1);
tor_free(dir_c2);
return;
}
示例14: 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;
}
示例15: test_pt_get_transport_options
static void
test_pt_get_transport_options(void *arg)
{
char **execve_args;
smartlist_t *transport_list = smartlist_new();
managed_proxy_t *mp;
or_options_t *options = get_options_mutable();
char *opt_str = NULL;
config_line_t *cl = NULL;
(void)arg;
execve_args = tor_malloc(sizeof(char*)*2);
execve_args[0] = tor_strdup("cheeseshop");
execve_args[1] = NULL;
mp = managed_proxy_create(transport_list, execve_args, 1);
tt_ptr_op(mp, OP_NE, NULL);
opt_str = get_transport_options_for_server_proxy(mp);
tt_ptr_op(opt_str, OP_EQ, NULL);
smartlist_add(mp->transports_to_launch, tor_strdup("gruyere"));
smartlist_add(mp->transports_to_launch, tor_strdup("roquefort"));
smartlist_add(mp->transports_to_launch, tor_strdup("stnectaire"));
tt_assert(options);
cl = tor_malloc_zero(sizeof(config_line_t));
cl->value = tor_strdup("gruyere melty=10 hardness=se;ven");
options->ServerTransportOptions = cl;
cl = tor_malloc_zero(sizeof(config_line_t));
cl->value = tor_strdup("stnectaire melty=4 hardness=three");
cl->next = options->ServerTransportOptions;
options->ServerTransportOptions = cl;
cl = tor_malloc_zero(sizeof(config_line_t));
cl->value = tor_strdup("pepperjack melty=12 hardness=five");
cl->next = options->ServerTransportOptions;
options->ServerTransportOptions = cl;
opt_str = get_transport_options_for_server_proxy(mp);
tt_str_op(opt_str, OP_EQ,
"gruyere:melty=10;gruyere:hardness=se\\;ven;"
"stnectaire:melty=4;stnectaire:hardness=three");
done:
tor_free(opt_str);
config_free_lines(cl);
managed_proxy_destroy(mp, 0);
smartlist_free(transport_list);
}