aboutsummaryrefslogtreecommitdiff
path: root/src/or/test.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-07-31 17:59:37 +0000
committerNick Mathewson <nickm@torproject.org>2006-07-31 17:59:37 +0000
commit2fe537c57a8dffd9568f27e5f1a872edc8211994 (patch)
tree60796031e11856dd72379771e65a5c31035aa77d /src/or/test.c
parent8ba913c6607f6bc9b82877b3060712165739d22f (diff)
downloadtor-2fe537c57a8dffd9568f27e5f1a872edc8211994.tar
tor-2fe537c57a8dffd9568f27e5f1a872edc8211994.tar.gz
r6958@Kushana: nickm | 2006-07-29 18:54:15 -0400
Looks like we might need a priority queue. svn:r6953
Diffstat (limited to 'src/or/test.c')
-rw-r--r--src/or/test.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/or/test.c b/src/or/test.c
index 3e18df9d3..4a258afb7 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -921,6 +921,66 @@ test_util(void)
smartlist_free(sl);
}
+static int
+_compare_strings_for_pqueue(const void *s1, const void *s2)
+{
+ return strcmp((const char*)s1, (const char*)s2);
+}
+
+static void
+test_pqueue(void)
+{
+ smartlist_t *sl;
+ int (*cmp)(const void *, const void*);
+#define OK() smartlist_pqueue_assert_ok(sl, cmp)
+
+ cmp = _compare_strings_for_pqueue;
+
+ sl = smartlist_create();
+ smartlist_pqueue_add(sl, cmp, "cows");
+ smartlist_pqueue_add(sl, cmp, "zebras");
+ smartlist_pqueue_add(sl, cmp, "fish");
+ smartlist_pqueue_add(sl, cmp, "frogs");
+ smartlist_pqueue_add(sl, cmp, "apples");
+ smartlist_pqueue_add(sl, cmp, "squid");//
+ smartlist_pqueue_add(sl, cmp, "daschunds");
+ smartlist_pqueue_add(sl, cmp, "eggplants");
+ smartlist_pqueue_add(sl, cmp, "weissbier");//
+ smartlist_pqueue_add(sl, cmp, "lobsters");
+ smartlist_pqueue_add(sl, cmp, "roquefort");//
+
+ OK();
+
+ test_eq(smartlist_len(sl), 11);
+ test_streq(smartlist_get(sl, 0), "apples");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "apples");
+ test_eq(smartlist_len(sl), 10);
+ OK();
+ test_streq(smartlist_pqueue_pop(sl, cmp), "cows");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "daschunds");
+ smartlist_pqueue_add(sl, cmp, "chinchillas");
+ OK();
+ smartlist_pqueue_add(sl, cmp, "fireflies");
+ OK();
+ test_streq(smartlist_pqueue_pop(sl, cmp), "chinchillas");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "eggplants");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "fireflies");
+ OK();
+ test_streq(smartlist_pqueue_pop(sl, cmp), "fish");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "frogs");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "lobsters");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "roquefort");
+ OK();
+ test_eq(smartlist_len(sl), 3);
+ test_streq(smartlist_pqueue_pop(sl, cmp), "squid");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "weissbier");
+ test_streq(smartlist_pqueue_pop(sl, cmp), "zebras");
+ test_eq(smartlist_len(sl), 0);
+ OK();
+#undef OK
+ smartlist_free(sl);
+}
+
static void
test_gzip(void)
{
@@ -1675,6 +1735,7 @@ main(int c, char**v)
test_util();
test_strmap();
test_control_formats();
+ test_pqueue();
puts("\n========================= Onion Skins =====================");
test_onion();
test_onion_handshake();