summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-05-19 20:17:37 +0000
committerNick Mathewson <nickm@torproject.org>2007-05-19 20:17:37 +0000
commit5f58bee0b0d39ef59d99ece2b044e4c20a577889 (patch)
treead5f0ba5503f45b979125e92a10eba08bc4814b6 /src/or
parent6f8866a817ad96494d84d3d05b68ee3b0b72545f (diff)
downloadtor-5f58bee0b0d39ef59d99ece2b044e4c20a577889.tar.gz
tor-5f58bee0b0d39ef59d99ece2b044e4c20a577889.zip
r12812@catbus: nickm | 2007-05-19 16:17:36 -0400
Fix compilation with -O0; add unit tests for swap and shuffle. svn:r10223
Diffstat (limited to 'src/or')
-rw-r--r--src/or/test.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/or/test.c b/src/or/test.c
index ba5f2a45a2..5c4d349c82 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1085,19 +1085,37 @@ test_smartlist(void)
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
smartlist_clear(sl);
- /* Test smartlist sorting. */
+ /* Test swapping, shuffling, and sorting. */
smartlist_split_string(sl, "the,onion,router,by,arma,and,nickm", ",", 0, 0);
test_eq(7, smartlist_len(sl));
smartlist_sort(sl, _compare_strs);
cp = smartlist_join_strings(sl, ",", 0, NULL);
test_streq(cp,"and,arma,by,nickm,onion,router,the");
tor_free(cp);
+ smartlist_swap(sl, 1, 5);
+ cp = smartlist_join_strings(sl, ",", 0, NULL);
+ test_streq(cp,"and,router,by,nickm,onion,arma,the");
+ tor_free(cp);
+ smartlist_shuffle(sl);
+ test_eq(7, smartlist_len(sl));
+ test_assert(smartlist_string_isin(sl, "and"));
+ test_assert(smartlist_string_isin(sl, "router"));
+ test_assert(smartlist_string_isin(sl, "by"));
+ test_assert(smartlist_string_isin(sl, "nickm"));
+ test_assert(smartlist_string_isin(sl, "onion"));
+ test_assert(smartlist_string_isin(sl, "arma"));
+ test_assert(smartlist_string_isin(sl, "the"));
+
+ /* Test bsearch. */
+ smartlist_sort(sl, _compare_strs);
test_streq("nickm", smartlist_bsearch(sl, "zNicKM",
_compare_without_first_ch));
test_streq("and", smartlist_bsearch(sl, " AND", _compare_without_first_ch));
test_eq_ptr(NULL, smartlist_bsearch(sl, " ANz", _compare_without_first_ch));
+
+
/* Test reverse() and pop_last() */
smartlist_reverse(sl);
cp = smartlist_join_strings(sl, ",", 0, NULL);