apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1664900 - /apr/apr/trunk/test/testskiplist.c
Date Sat, 07 Mar 2015 19:53:47 GMT
Author: jim
Date: Sat Mar  7 19:53:46 2015
New Revision: 1664900

URL: http://svn.apache.org/r1664900
Log:
Adj test to ensure that dups are entered AFTER existing ones

Modified:
    apr/apr/trunk/test/testskiplist.c

Modified: apr/apr/trunk/test/testskiplist.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testskiplist.c?rev=1664900&r1=1664899&r2=1664900&view=diff
==============================================================================
--- apr/apr/trunk/test/testskiplist.c (original)
+++ apr/apr/trunk/test/testskiplist.c Sat Mar  7 19:53:46 2015
@@ -240,6 +240,11 @@ static void skiplist_random_loop(abts_ca
     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_skip
     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,
     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);
 }
 



Mime
View raw message