summaryrefslogtreecommitdiff
path: root/src/or/test.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-04-07 16:28:34 +0000
committerNick Mathewson <nickm@torproject.org>2008-04-07 16:28:34 +0000
commit2d68487e7fda553ce1466047aec954936688083b (patch)
treeaaec7e96548c0c848a33b5b061384adfb630b5ec /src/or/test.c
parent85db675911d1b4bbba755266ebaa33404c40e5de (diff)
downloadtor-2d68487e7fda553ce1466047aec954936688083b.tar.gz
tor-2d68487e7fda553ce1466047aec954936688083b.zip
r19229@catbus: nickm | 2008-04-07 12:28:22 -0400
Add a new SMARTLIST_FOREACH_JOIN macro to iterate through two sorted lists in lockstep. This happens at least 3 times in the code so far, and is likely to happen more in the future. Previous attempts to do so proved touchy, tricky, and error-prone: now, we only need to get it right in one place. svn:r14309
Diffstat (limited to 'src/or/test.c')
-rw-r--r--src/or/test.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/or/test.c b/src/or/test.c
index c8f00b316f..c421523a3f 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1837,6 +1837,51 @@ test_util_smartlist(void)
smartlist_clear(sl);
}
+ {
+ smartlist_t *sl2 = smartlist_create(), *sl3 = smartlist_create(),
+ *sl4 = smartlist_create();
+ /* 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);
+
+ SMARTLIST_FOREACH(sl3, const char *, cp,
+ test_assert(smartlist_isin(sl2, cp) &&
+ !smartlist_string_isin(sl, cp)));
+ SMARTLIST_FOREACH(sl4, const char *, cp,
+ test_assert(smartlist_isin(sl, cp) &&
+ smartlist_string_isin(sl2, cp)));
+ cp = smartlist_join_strings(sl3, ",", 0, NULL);
+ test_streq(cp, "Anemias,Anemias,Crossbowmen,Work");
+ tor_free(cp);
+ cp = smartlist_join_strings(sl4, ",", 0, NULL);
+ test_streq(cp, "Ambush,Anchorman,Anchorman,Bacon,Inhumane,Insurance,"
+ "Knish,Know,Manners,Manners,Maraschinos,Wombats,Wombats");
+ tor_free(cp);
+
+ smartlist_free(sl4);
+ smartlist_free(sl3);
+ SMARTLIST_FOREACH(sl2, char *, cp, tor_free(cp));
+ smartlist_free(sl2);
+ SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
+ smartlist_clear(sl);
+ }
+
smartlist_free(sl);
}