apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cove...@apache.org
Subject svn commit: r1604596 - in /apr/apr/trunk/test: Makefile.in abts_tests.h testskiplist.c testutil.h
Date Sun, 22 Jun 2014 14:56:29 GMT
Author: covener
Date: Sun Jun 22 14:56:29 2014
New Revision: 1604596

URL: http://svn.apache.org/r1604596
Log:
Add a basic skiplist test.  Based on test program posted to PR 56654 by Takashi Sato.

Submitted By: Takashi Sato, covener
Committed By: covener


Added:
    apr/apr/trunk/test/testskiplist.c
Modified:
    apr/apr/trunk/test/Makefile.in
    apr/apr/trunk/test/abts_tests.h
    apr/apr/trunk/test/testutil.h

Modified: apr/apr/trunk/test/Makefile.in
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/Makefile.in?rev=1604596&r1=1604595&r2=1604596&view=diff
==============================================================================
--- apr/apr/trunk/test/Makefile.in (original)
+++ apr/apr/trunk/test/Makefile.in Sun Jun 22 14:56:29 2014
@@ -36,7 +36,7 @@ TESTS = testtime.lo teststr.lo testvsn.l
 	teststrmatch.lo testpass.lo testcrypto.lo testqueue.lo		\
 	testbuckets.lo testxml.lo testdbm.lo testuuid.lo testmd5.lo	\
 	testreslist.lo testbase64.lo testhooks.lo testlfsabi.lo         \
-	testlfsabi32.lo testlfsabi64.lo testescape.lo
+	testlfsabi32.lo testlfsabi64.lo testescape.lo testtable.lo
 
 OTHER_PROGRAMS = \
 	echod@EXEEXT@ \

Modified: apr/apr/trunk/test/abts_tests.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/abts_tests.h?rev=1604596&r1=1604595&r2=1604596&view=diff
==============================================================================
--- apr/apr/trunk/test/abts_tests.h (original)
+++ apr/apr/trunk/test/abts_tests.h Sun Jun 22 14:56:29 2014
@@ -87,7 +87,8 @@ const struct testlist {
     {testdbm},
     {testqueue},
     {testreslist},
-    {testlfsabi}
+    {testlfsabi},
+    {testskiplist}
 };
 
 #endif /* APR_TEST_INCLUDES */

Added: apr/apr/trunk/test/testskiplist.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testskiplist.c?rev=1604596&view=auto
==============================================================================
--- apr/apr/trunk/test/testskiplist.c (added)
+++ apr/apr/trunk/test/testskiplist.c Sun Jun 22 14:56:29 2014
@@ -0,0 +1,100 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "testutil.h"
+#include "apr.h"
+#include "apr_strings.h"
+#include "apr_general.h"
+#include "apr_pools.h"
+#include "apr_skiplist.h"
+#if APR_HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#if APR_HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#if APR_HAVE_STRING_H
+#include <string.h>
+#endif
+
+static void add_int_to_skiplist(apr_skiplist *list, int n){
+    int* a = apr_skiplist_alloc(list, sizeof(int));
+    *a = n;
+    apr_skiplist_insert(list, a);
+}
+
+static int comp(void *a, void *b){
+    return *((int*) a) - *((int*) b);
+}
+
+
+static int compk(void *a, void *b){
+    return comp(a, b);
+}
+
+static void skiplist_test(abts_case *tc, void *data) {
+    int test_elems = 10;
+    int i = 0, j = 0;
+    int *val = NULL;
+    apr_skiplist * list = NULL;
+    apr_pool_t *p;
+
+    apr_pool_create(&p, NULL);
+    apr_skiplist_init(&list, p);
+    apr_skiplist_set_compare(list, comp, compk);
+    
+    /* insert 10 objects */
+    for (i = 0; i < test_elems; ++i){
+        add_int_to_skiplist(list, i);
+    }
+
+    /* remove all objects */
+    while (val = apr_skiplist_pop(list, NULL)){
+        ABTS_INT_EQUAL(tc, *val, j++);
+    }
+
+    /* insert 10 objects again */
+    for (i = test_elems; i < test_elems+test_elems; ++i){
+        add_int_to_skiplist(list, i);
+    }
+
+    j = test_elems;
+    while (val = apr_skiplist_pop(list, NULL)){
+        ABTS_INT_EQUAL(tc, *val, j++);
+    }
+
+    /* empty */
+    val = apr_skiplist_pop(list, NULL);
+    ABTS_PTR_EQUAL(tc, val, NULL);
+
+    add_int_to_skiplist(list, 42);
+    val = apr_skiplist_pop(list, NULL);
+    ABTS_INT_EQUAL(tc, *val, 42); 
+
+    /* empty */
+    val = apr_skiplist_pop(list, NULL);
+    ABTS_PTR_EQUAL(tc, val, NULL);
+}
+
+abts_suite *testskiplist(abts_suite *suite)
+{
+    suite = ADD_SUITE(suite)
+
+    abts_run_test(suite, skiplist_test, NULL);
+
+    return suite;
+}
+

Modified: apr/apr/trunk/test/testutil.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testutil.h?rev=1604596&r1=1604595&r2=1604596&view=diff
==============================================================================
--- apr/apr/trunk/test/testutil.h (original)
+++ apr/apr/trunk/test/testutil.h Sun Jun 22 14:56:29 2014
@@ -130,5 +130,6 @@ abts_suite *testxlate(abts_suite *suite)
 abts_suite *testrmm(abts_suite *suite);
 abts_suite *testdbm(abts_suite *suite);
 abts_suite *testlfsabi(abts_suite *suite);
+abts_suite *testskiplist(abts_suite *suite);
 
 #endif /* APR_TEST_INCLUDES */



Mime
View raw message