diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-02-27 08:10:28 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-02-27 08:10:28 +0000 |
commit | d14f8f2547df35434547d8e3e2b4c1a6b7736597 (patch) | |
tree | 343bbb7f97529f51b222b770b127fffcaa88273b /src/or | |
parent | 5855ca92a3bdef2624a99c141dfd1884d461d09e (diff) | |
download | tor-d14f8f2547df35434547d8e3e2b4c1a6b7736597.tar tor-d14f8f2547df35434547d8e3e2b4c1a6b7736597.tar.gz |
r14516@tombo: nickm | 2008-02-27 03:10:26 -0500
Write some unit tests for a few functions and cases that needed them.
svn:r13751
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/test.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/or/test.c b/src/or/test.c index b0dcc2659..9a2e2fb97 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -1381,6 +1381,7 @@ test_util_smartlist(void) { smartlist_t *sl; char *cp; + size_t sz; /* XXXX test sort_digests, uniq_strings, uniq_digests */ @@ -1569,6 +1570,8 @@ test_util_smartlist(void) test_eq(smartlist_len(sl), 6); SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp)); smartlist_clear(sl); + cp = smartlist_pop_last(sl); + test_eq(cp, NULL); /* Test uniq() */ smartlist_split_string(sl, @@ -1603,8 +1606,9 @@ test_util_smartlist(void) test_streq(cp, "Some,say,the,Earth,fire,end,in,ice,and,some,in"); tor_free(cp); smartlist_string_remove(sl, "in"); - cp = smartlist_join_strings2(sl, "+XX", 1, 0, NULL); + cp = smartlist_join_strings2(sl, "+XX", 1, 0, &sz); test_streq(cp, "Some+say+the+Earth+fire+end+some+ice+and"); + test_eq((int)sz, 40); tor_free(cp); SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp)); @@ -1658,6 +1662,33 @@ test_util_smartlist(void) smartlist_clear(sl); } + { + /* digest_isin. */ + 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_digest_isin(NULL, "AAAAAAAAAAAAAAAAAAAA")); + test_assert(smartlist_digest_isin(sl, "AAAAAAAAAAAAAAAAAAAA")); + test_assert(smartlist_digest_isin(sl, "\00090AAB2AAAAaasdAAAAA")); + test_eq(0, smartlist_digest_isin(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); + + SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp)); + smartlist_clear(sl); + } + smartlist_free(sl); } @@ -2079,6 +2110,13 @@ test_util_mmap(void) tor_munmap_file(mapping); #endif + /* Now a zero-length file. */ + write_str_to_file(fname1, "", 1); + mapping = tor_mmap_file(fname1); + test_eq(mapping, NULL); + test_eq(ERANGE, errno); + unlink(fname1); + /* Make sure that we fail to map a no-longer-existent file. */ mapping = tor_mmap_file(fname1); test_assert(mapping == NULL); |