本文整理汇总了C++中smartlist_len函数的典型用法代码示例。如果您正苦于以下问题:C++ smartlist_len函数的具体用法?C++ smartlist_len怎么用?C++ smartlist_len使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了smartlist_len函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_md_corrupt_desc
static void
test_md_corrupt_desc(void *arg)
{
char *cp = NULL;
smartlist_t *sl = NULL;
(void) arg;
sl = microdescs_add_to_cache(get_microdesc_cache(),
"@last-listed 2015-06-22 10:00:00\n"
"onion-k\n",
NULL, SAVED_IN_JOURNAL, 0, time(NULL), NULL);
tt_int_op(smartlist_len(sl), OP_EQ, 0);
smartlist_free(sl);
sl = microdescs_add_to_cache(get_microdesc_cache(),
"@last-listed 2015-06-22 10:00:00\n"
"wiggly\n",
NULL, SAVED_IN_JOURNAL, 0, time(NULL), NULL);
tt_int_op(smartlist_len(sl), OP_EQ, 0);
smartlist_free(sl);
tor_asprintf(&cp, "%s\n%s", test_md1, "@foobar\nonion-wobble\n");
sl = microdescs_add_to_cache(get_microdesc_cache(),
cp, cp+strlen(cp),
SAVED_IN_JOURNAL, 0, time(NULL), NULL);
tt_int_op(smartlist_len(sl), OP_EQ, 0);
done:
tor_free(cp);
smartlist_free(sl);
}
示例2: test_address_get_if_addrs_list_internal
static void
test_address_get_if_addrs_list_internal(void *arg)
{
smartlist_t *results = NULL;
(void)arg;
results = get_interface_address_list(LOG_ERR, 1);
tt_ptr_op(results, OP_NE, NULL);
/* When the network is down, a system might not have any non-local
* non-multicast addresseses, not even internal ones.
* Unit tests shouldn't fail because of this. */
tt_int_op(smartlist_len(results),OP_GE,0);
tt_assert(!smartlist_contains_localhost_tor_addr(results));
tt_assert(!smartlist_contains_multicast_tor_addr(results));
/* The list may or may not contain internal addresses */
tt_assert(!smartlist_contains_null_tor_addr(results));
/* if there are any addresses, they must be IPv4 */
if (smartlist_len(results) > 0) {
tt_assert(smartlist_contains_ipv4_tor_addr(results));
}
tt_assert(!smartlist_contains_ipv6_tor_addr(results));
done:
interface_address_list_free(results);
return;
}
示例3: test_address_get_if_addrs_win32
static void
test_address_get_if_addrs_win32(void *arg)
{
smartlist_t *results = NULL;
(void)arg;
results = get_interface_addresses_win32(LOG_ERR, AF_UNSPEC);
tt_int_op(smartlist_len(results),OP_GE,1);
tt_assert(smartlist_contains_localhost_tor_addr(results));
tt_assert(!smartlist_contains_null_tor_addr(results));
/* If there are addresses, they must be IPv4 or IPv6 */
if (smartlist_len(results) > 0) {
tt_assert(smartlist_contains_ipv4_tor_addr(results)
|| smartlist_contains_ipv6_tor_addr(results));
}
done:
SMARTLIST_FOREACH(results, tor_addr_t *, t, tor_free(t));
tor_free(results);
return;
}
示例4: test_address_get_if_addrs_list_no_internal
static void
test_address_get_if_addrs_list_no_internal(void *arg)
{
smartlist_t *results = NULL;
(void)arg;
results = get_interface_address_list(LOG_ERR, 0);
tt_ptr_op(results, OP_NE, NULL);
/* Work even on systems with only internal IPv4 addresses */
tt_int_op(smartlist_len(results),OP_GE,0);
tt_assert(!smartlist_contains_localhost_tor_addr(results));
tt_assert(!smartlist_contains_multicast_tor_addr(results));
tt_assert(!smartlist_contains_internal_tor_addr(results));
tt_assert(!smartlist_contains_null_tor_addr(results));
/* if there are any addresses, they must be IPv4 */
if (smartlist_len(results) > 0) {
tt_assert(smartlist_contains_ipv4_tor_addr(results));
}
tt_assert(!smartlist_contains_ipv6_tor_addr(results));
done:
interface_address_list_free(results);
return;
}
示例5: setup_fake_routerlist
/** Parse a file containing router descriptors and load them to our
routerlist. This function is used to setup an artificial network
so that we can conduct entry guard tests. */
static void
setup_fake_routerlist(void)
{
int retval;
routerlist_t *our_routerlist = NULL;
smartlist_t *our_nodelist = NULL;
/* Read the file that contains our test descriptors. */
/* We need to mock this function otherwise the descriptors will not
accepted as they are too old. */
MOCK(router_descriptor_is_older_than,
router_descriptor_is_older_than_replacement);
/* Load all the test descriptors to the routerlist. */
retval = router_load_routers_from_string(TEST_DESCRIPTORS,
NULL, SAVED_IN_JOURNAL,
NULL, 0, NULL);
tt_int_op(retval, OP_EQ, NUMBER_OF_DESCRIPTORS);
/* Sanity checking of routerlist and nodelist. */
our_routerlist = router_get_routerlist();
tt_int_op(smartlist_len(our_routerlist->routers), OP_EQ,
NUMBER_OF_DESCRIPTORS);
routerlist_assert_ok(our_routerlist);
our_nodelist = nodelist_get_list();
tt_int_op(smartlist_len(our_nodelist), OP_EQ, NUMBER_OF_DESCRIPTORS);
/* Mark all routers as non-guards but up and running! */
SMARTLIST_FOREACH_BEGIN(our_nodelist, node_t *, node) {
node->is_running = 1;
node->is_valid = 1;
node->is_possible_guard = 0;
} SMARTLIST_FOREACH_END(node);
示例6: test_storagedir_empty
static void
test_storagedir_empty(void *arg)
{
char *dirname = tor_strdup(get_fname_rnd("store_dir"));
storage_dir_t *d = NULL;
(void)arg;
tt_int_op(FN_NOENT, OP_EQ, file_status(dirname));
d = storage_dir_new(dirname, 10);
tt_assert(d);
tt_int_op(FN_DIR, OP_EQ, file_status(dirname));
tt_int_op(0, OP_EQ, smartlist_len(storage_dir_list(d)));
tt_u64_op(0, OP_EQ, storage_dir_get_usage(d));
storage_dir_free(d);
d = storage_dir_new(dirname, 10);
tt_assert(d);
tt_int_op(FN_DIR, OP_EQ, file_status(dirname));
tt_int_op(0, OP_EQ, smartlist_len(storage_dir_list(d)));
tt_u64_op(0, OP_EQ, storage_dir_get_usage(d));
done:
storage_dir_free(d);
tor_free(dirname);
}
示例7: test_address_get_if_addrs_no_internal_fail
static void
test_address_get_if_addrs_no_internal_fail(void *arg)
{
smartlist_t *results1 = NULL, *results2 = NULL;
(void)arg;
MOCK(get_interface_addresses_raw,
mock_get_interface_addresses_raw_fail);
MOCK(get_interface_address6_via_udp_socket_hack,
mock_get_interface_address6_via_udp_socket_hack_fail);
results1 = get_interface_address6_list(LOG_ERR, AF_INET6, 0);
tt_ptr_op(results1, OP_NE, NULL);
tt_int_op(smartlist_len(results1),OP_EQ,0);
results2 = get_interface_address_list(LOG_ERR, 0);
tt_ptr_op(results2, OP_NE, NULL);
tt_int_op(smartlist_len(results2),OP_EQ,0);
done:
UNMOCK(get_interface_addresses_raw);
UNMOCK(get_interface_address6_via_udp_socket_hack);
interface_address6_list_free(results1);
interface_address6_list_free(results2);
return;
}
示例8: 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);
}
示例9: smartlist_bsearch_idx
/** Assuming the members of <b>sl</b> are in order, return the index of the
* member that matches <b>key</b>. If no member matches, return the index of
* the first member greater than <b>key</b>, or smartlist_len(sl) if no member
* is greater than <b>key</b>. Set <b>found_out</b> to true on a match, to
* false otherwise. Ordering and matching are defined by a <b>compare</b>
* function that returns 0 on a match; less than 0 if key is less than member,
* and greater than 0 if key is greater then member.
*/
int
smartlist_bsearch_idx(const smartlist_t *sl, const void *key,
int (*compare)(const void *key, const void **member),
int *found_out)
{
int hi = smartlist_len(sl) - 1, lo = 0, cmp, mid;
while (lo <= hi) {
mid = (lo + hi) / 2;
cmp = compare(key, (const void**) &(sl->list[mid]));
if (cmp>0) { /* key > sl[mid] */
lo = mid+1;
} else if (cmp<0) { /* key < sl[mid] */
hi = mid-1;
} else { /* key == sl[mid] */
*found_out = 1;
return mid;
}
}
/* lo > hi. */
{
tor_assert(lo >= 0);
if (lo < smartlist_len(sl)) {
cmp = compare(key, (const void**) &(sl->list[lo]));
tor_assert(cmp < 0);
} else if (smartlist_len(sl)) {
cmp = compare(key, (const void**) &(sl->list[smartlist_len(sl)-1]));
tor_assert(cmp > 0);
}
}
*found_out = 0;
return lo;
}
示例10: NS
static void
NS(test_main)(void *arg)
{
routerset_t *set = routerset_new();
smartlist_t *list = smartlist_new();
const char *nickname = "foo";
routerinfo_t ri;
node_t mock_node;
(void)arg;
strmap_set_lc(set->names, nickname, (void *)1);
ri.nickname = (char *)nickname;
mock_node.rs = NULL;
mock_node.ri = &ri;
smartlist_add(list, (void *)&mock_node);
tt_int_op(smartlist_len(list), OP_NE, 0);
routerset_subtract_nodes(list, set);
tt_int_op(smartlist_len(list), OP_EQ, 0);
done:
routerset_free(set);
smartlist_free(list);
}
示例11: test_halfstream_wrap
static void
test_halfstream_wrap(void *arg)
{
origin_circuit_t *circ =
helper_create_origin_circuit(CIRCUIT_PURPOSE_C_GENERAL, 0);
edge_connection_t *edgeconn;
entry_connection_t *entryconn;
circ->cpath->state = CPATH_STATE_AWAITING_KEYS;
circ->cpath->deliver_window = CIRCWINDOW_START;
entryconn = fake_entry_conn(circ, 23);
edgeconn = ENTRY_TO_EDGE_CONN(entryconn);
(void)arg;
/* Suppress the WARN message we generate in this test */
setup_full_capture_of_logs(LOG_WARN);
MOCK(connection_mark_for_close_internal_, mock_mark_for_close);
/* Verify that get_unique_stream_id_by_circ() can wrap uint16_t */
circ->next_stream_id = 65530;
halfstream_insert(circ, edgeconn, NULL, 7, 0);
tt_int_op(circ->next_stream_id, OP_EQ, 2);
tt_int_op(smartlist_len(circ->half_streams), OP_EQ, 7);
/* Insert full-1 */
halfstream_insert(circ, edgeconn, NULL,
65534-smartlist_len(circ->half_streams), 0);
tt_int_op(smartlist_len(circ->half_streams), OP_EQ, 65534);
/* Verify that we can get_unique_stream_id_by_circ() successfully */
edgeconn->stream_id = get_unique_stream_id_by_circ(circ);
tt_int_op(edgeconn->stream_id, OP_NE, 0); /* 0 is failure */
/* Insert an opened stream on the circ with that id */
ENTRY_TO_CONN(entryconn)->marked_for_close = 0;
ENTRY_TO_CONN(entryconn)->outbuf_flushlen = 0;
edgeconn->base_.state = AP_CONN_STATE_CONNECT_WAIT;
circ->p_streams = edgeconn;
/* Verify that get_unique_stream_id_by_circ() fails */
tt_int_op(get_unique_stream_id_by_circ(circ), OP_EQ, 0); /* 0 is failure */
/* eof the one opened stream. Verify it is now in half-closed */
tt_int_op(smartlist_len(circ->half_streams), OP_EQ, 65534);
connection_edge_reached_eof(edgeconn);
tt_int_op(smartlist_len(circ->half_streams), OP_EQ, 65535);
/* Verify get_unique_stream_id_by_circ() fails due to full half-closed */
circ->p_streams = NULL;
tt_int_op(get_unique_stream_id_by_circ(circ), OP_EQ, 0); /* 0 is failure */
done:
circuit_free_(TO_CIRCUIT(circ));
connection_free_minimal(ENTRY_TO_CONN(entryconn));
UNMOCK(connection_mark_for_close_internal_);
}
示例12: test_storagedir_deletion
static void
test_storagedir_deletion(void *arg)
{
(void)arg;
char *dirname = tor_strdup(get_fname_rnd("store_dir"));
storage_dir_t *d = NULL;
char *fn1 = NULL, *fn2 = NULL;
char *bytes = NULL;
int r;
const char str1[] = "There are nine and sixty ways to disguise communiques";
const char str2[] = "And rather more than one of them is right";
// Make sure the directory is there. */
d = storage_dir_new(dirname, 10);
storage_dir_free(d);
d = NULL;
tor_asprintf(&fn1, "%s/1007", dirname);
r = write_str_to_file(fn1, str1, 0);
tt_int_op(r, OP_EQ, 0);
tor_asprintf(&fn2, "%s/1003.tmp", dirname);
r = write_str_to_file(fn2, str2, 0);
tt_int_op(r, OP_EQ, 0);
// The tempfile should be deleted the next time we list the directory.
d = storage_dir_new(dirname, 10);
tt_int_op(1, OP_EQ, smartlist_len(storage_dir_list(d)));
tt_u64_op(strlen(str1), OP_EQ, storage_dir_get_usage(d));
tt_int_op(FN_FILE, OP_EQ, file_status(fn1));
tt_int_op(FN_NOENT, OP_EQ, file_status(fn2));
bytes = (char*) storage_dir_read(d, "1007", 1, NULL);
tt_str_op(bytes, OP_EQ, str1);
// Should have no effect; file already gone.
storage_dir_remove_file(d, "1003.tmp");
tt_int_op(1, OP_EQ, smartlist_len(storage_dir_list(d)));
tt_u64_op(strlen(str1), OP_EQ, storage_dir_get_usage(d));
// Actually remove a file.
storage_dir_remove_file(d, "1007");
tt_int_op(FN_NOENT, OP_EQ, file_status(fn1));
tt_int_op(0, OP_EQ, smartlist_len(storage_dir_list(d)));
tt_u64_op(0, OP_EQ, storage_dir_get_usage(d));
done:
tor_free(dirname);
tor_free(fn1);
tor_free(fn2);
storage_dir_free(d);
tor_free(bytes);
}
示例13: test_cntev_append_cell_stats
static void
test_cntev_append_cell_stats(void *arg)
{
smartlist_t *event_parts;
char *cp = NULL;
const char *key = "Z";
uint64_t include_if_non_zero[CELL_COMMAND_MAX_ + 1],
number_to_include[CELL_COMMAND_MAX_ + 1];
(void)arg;
event_parts = smartlist_new();
memset(include_if_non_zero, 0,
(CELL_COMMAND_MAX_ + 1) * sizeof(uint64_t));
memset(number_to_include, 0,
(CELL_COMMAND_MAX_ + 1) * sizeof(uint64_t));
/* All array entries empty. */
append_cell_stats_by_command(event_parts, key,
include_if_non_zero,
number_to_include);
tt_int_op(0, OP_EQ, smartlist_len(event_parts));
/* There's a RELAY cell to include, but the corresponding field in
* include_if_non_zero is still zero. */
number_to_include[CELL_RELAY] = 1;
append_cell_stats_by_command(event_parts, key,
include_if_non_zero,
number_to_include);
tt_int_op(0, OP_EQ, smartlist_len(event_parts));
/* Now include single RELAY cell. */
include_if_non_zero[CELL_RELAY] = 2;
append_cell_stats_by_command(event_parts, key,
include_if_non_zero,
number_to_include);
cp = smartlist_pop_last(event_parts);
tt_str_op("Z=relay:1", OP_EQ, cp);
tor_free(cp);
/* Add four CREATE cells. */
include_if_non_zero[CELL_CREATE] = 3;
number_to_include[CELL_CREATE] = 4;
append_cell_stats_by_command(event_parts, key,
include_if_non_zero,
number_to_include);
cp = smartlist_pop_last(event_parts);
tt_str_op("Z=create:4,relay:1", OP_EQ, cp);
done:
tor_free(cp);
smartlist_free(event_parts);
}
示例14: 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);
}
示例15: smartlist_strings_eq
/** Return true iff the two lists contain the same strings in the same
* order, or if they are both NULL. */
int
smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2)
{
if (sl1 == NULL)
return sl2 == NULL;
if (sl2 == NULL)
return 0;
if (smartlist_len(sl1) != smartlist_len(sl2))
return 0;
SMARTLIST_FOREACH(sl1, const char *, cp1, {
const char *cp2 = smartlist_get(sl2, cp1_sl_idx);
if (strcmp(cp1, cp2))
return 0;
});