Return-Path: X-Original-To: apmail-apr-commits-archive@www.apache.org Delivered-To: apmail-apr-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A366310C82 for ; Sat, 7 Mar 2015 19:55:50 +0000 (UTC) Received: (qmail 872 invoked by uid 500); 7 Mar 2015 19:55:50 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 817 invoked by uid 500); 7 Mar 2015 19:55:50 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 808 invoked by uid 99); 7 Mar 2015 19:55:50 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Mar 2015 19:55:50 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 6C878AC006E for ; Sat, 7 Mar 2015 19:55:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1664903 - /apr/apr/branches/1.5.x/test/testskiplist.c Date: Sat, 07 Mar 2015 19:55:50 -0000 To: commits@apr.apache.org From: jim@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150307195550.6C878AC006E@hades.apache.org> Author: jim Date: Sat Mar 7 19:55:50 2015 New Revision: 1664903 URL: http://svn.apache.org/r1664903 Log: Add test to ensure elems are added AFTER dups Modified: apr/apr/branches/1.5.x/test/testskiplist.c Modified: apr/apr/branches/1.5.x/test/testskiplist.c URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/test/testskiplist.c?rev=1664903&r1=1664902&r2=1664903&view=diff ============================================================================== --- apr/apr/branches/1.5.x/test/testskiplist.c (original) +++ apr/apr/branches/1.5.x/test/testskiplist.c Sat Mar 7 19:55:50 2015 @@ -212,6 +212,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)); @@ -219,6 +224,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); } @@ -227,13 +238,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); @@ -290,6 +317,29 @@ 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); + ABTS_INT_EQUAL(tc, val2->a, 1); + val2 = apr_skiplist_pop(list2, NULL); + ABTS_INT_EQUAL(tc, val2->a, 42); + ABTS_INT_EQUAL(tc, val2->b, 1); + val2 = apr_skiplist_pop(list2, NULL); + ABTS_INT_EQUAL(tc, val2->a, 42); + ABTS_INT_EQUAL(tc, val2->b, 2); + val2 = apr_skiplist_pop(list2, NULL); + ABTS_INT_EQUAL(tc, val2->a, 42); + ABTS_INT_EQUAL(tc, val2->b, 1); + val2 = apr_skiplist_pop(list2, NULL); + ABTS_INT_EQUAL(tc, val2->a, 142); + ABTS_INT_EQUAL(tc, val2->b, 1); + + apr_pool_clear(ptmp); }