summaryrefslogtreecommitdiff
path: root/test/testskiplist.c
diff options
context:
space:
mode:
authorJim Jagielski <jim@apache.org>2015-03-07 19:53:46 +0000
committerJim Jagielski <jim@apache.org>2015-03-07 19:53:46 +0000
commitfb6be65a372c60e09a1a0b82c2c41136b67343b2 (patch)
tree70713869b862b3d2b7e1538c0701e9e194306f5d /test/testskiplist.c
parent13a0f7bd4832008f79069660d45486f914ab67d4 (diff)
downloadapr-fb6be65a372c60e09a1a0b82c2c41136b67343b2.tar.gz
Adj test to ensure that dups are entered AFTER existing ones
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1664900 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testskiplist.c')
-rw-r--r--test/testskiplist.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/testskiplist.c b/test/testskiplist.c
index e2571f2cd..57d3a59b4 100644
--- a/test/testskiplist.c
+++ b/test/testskiplist.c
@@ -240,6 +240,11 @@ static void skiplist_random_loop(abts_case *tc, void *data)
apr_pool_clear(ptmp);
}
+typedef struct elem {
+ int a;
+ int b;
+} elem;
+
static void add_int_to_skiplist(apr_skiplist *list, int n){
int* a = apr_skiplist_alloc(list, sizeof(int));
@@ -247,6 +252,12 @@ static void add_int_to_skiplist(apr_skiplist *list, int n){
apr_skiplist_insert(list, a);
}
+static void add_elem_to_skiplist(apr_skiplist *list, elem n){
+ elem* a = apr_skiplist_alloc(list, sizeof(elem));
+ *a = n;
+ apr_skiplist_insert(list, a);
+}
+
static int comp(void *a, void *b){
return *((int*) a) - *((int*) b);
}
@@ -255,13 +266,29 @@ static int compk(void *a, void *b){
return comp(a, b);
}
+static int scomp(void *a, void *b){
+ return ((elem*) a)->a - ((elem*) b)->a;
+}
+
+static int scompk(void *a, void *b){
+ return scomp(a, b);
+}
+
static void skiplist_test(abts_case *tc, void *data) {
int test_elems = 10;
int i = 0, j = 0;
int *val = NULL;
+ elem *val2 = NULL;
apr_skiplist * list = NULL;
+ apr_skiplist * list2 = NULL;
int first_forty_two = 42,
second_forty_two = 42;
+ elem t1, t2, t3, t4, t5;
+ t1.a = 1; t1.b = 1;
+ t2.a = 42; t2.b = 1;
+ t3.a = 42; t3.b = 2;
+ t4.a = 42; t4.b = 3;
+ t5.a = 142; t5.b = 1;
ABTS_INT_EQUAL(tc, APR_SUCCESS, apr_skiplist_init(&list, ptmp));
apr_skiplist_set_compare(list, comp, compk);
@@ -318,6 +345,34 @@ static void skiplist_test(abts_case *tc, void *data) {
val = apr_skiplist_peek(list);
ABTS_INT_EQUAL(tc, *val, 142);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, apr_skiplist_init(&list2, ptmp));
+ apr_skiplist_set_compare(list2, scomp, scompk);
+ add_elem_to_skiplist(list2, t2);
+ add_elem_to_skiplist(list2, t1);
+ add_elem_to_skiplist(list2, t3);
+ add_elem_to_skiplist(list2, t5);
+ add_elem_to_skiplist(list2, t4);
+ val2 = apr_skiplist_pop(list2, NULL);
+ printf("%d %d\n", val2->a, val2->b);
+ ABTS_INT_EQUAL(tc, val2->a, 1);
+ val2 = apr_skiplist_pop(list2, NULL);
+ printf("%d %d\n", val2->a, val2->b);
+ ABTS_INT_EQUAL(tc, val2->a, 42);
+ ABTS_INT_EQUAL(tc, val2->b, 1);
+ val2 = apr_skiplist_pop(list2, NULL);
+ printf("%d %d\n", val2->a, val2->b);
+ ABTS_INT_EQUAL(tc, val2->a, 42);
+ ABTS_INT_EQUAL(tc, val2->b, 2);
+ val2 = apr_skiplist_pop(list2, NULL);
+ printf("%d %d\n", val2->a, val2->b);
+ ABTS_INT_EQUAL(tc, val2->a, 42);
+ ABTS_INT_EQUAL(tc, val2->b, 1);
+ val2 = apr_skiplist_pop(list2, NULL);
+ printf("%d %d\n", val2->a, val2->b);
+ ABTS_INT_EQUAL(tc, val2->a, 142);
+ ABTS_INT_EQUAL(tc, val2->b, 1);
+
+
apr_pool_clear(ptmp);
}