apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject svn commit: rev 76131 - apr/apr-util/trunk/test
Date Wed, 17 Nov 2004 13:56:19 GMT
Author: jorton
Date: Wed Nov 17 05:56:17 2004
New Revision: 76131

Modified:
   apr/apr-util/trunk/test/testbuckets.c
Log:
Test apr_bucket_split for various bucket types:

* test/testbuckets.c (test_splits): New function.


Modified: apr/apr-util/trunk/test/testbuckets.c
==============================================================================
--- apr/apr-util/trunk/test/testbuckets.c	(original)
+++ apr/apr-util/trunk/test/testbuckets.c	Wed Nov 17 05:56:17 2004
@@ -16,6 +16,7 @@
 #include "abts.h"
 #include "testutil.h"
 #include "apr_buckets.h"
+#include "apr_strings.h"
 
 static void test_create(abts_case *tc, void *data)
 {
@@ -208,6 +209,82 @@
 }
 
 
+static void test_splits(abts_case *tc, void *ctx)
+{
+    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
+    apr_bucket_brigade *bb;
+    apr_bucket *e;
+    char *str = "alphabeta";
+    int n;
+
+    bb = apr_brigade_create(p, ba);
+
+    APR_BRIGADE_INSERT_TAIL(bb,
+                            apr_bucket_immortal_create(str, 9, ba));
+    APR_BRIGADE_INSERT_TAIL(bb, 
+                            apr_bucket_transient_create(str, 9, ba));
+    APR_BRIGADE_INSERT_TAIL(bb, 
+                            apr_bucket_heap_create(strdup(str), 9, free, ba));
+    APR_BRIGADE_INSERT_TAIL(bb, 
+                            apr_bucket_pool_create(apr_pstrdup(p, str), 9, p, 
+                                                   ba));
+
+    ABTS_ASSERT(tc, "four buckets inserted", count_buckets(bb) == 4);
+    
+    /* now split each of the buckets after byte 5 */
+    for (n = 0, e = APR_BRIGADE_FIRST(bb); n < 4; n++) {
+        ABTS_ASSERT(tc, "reached end of brigade", 
+                    e != APR_BRIGADE_SENTINEL(bb));
+        ABTS_ASSERT(tc, "split bucket OK",
+                    apr_bucket_split(e, 5) == APR_SUCCESS);
+        e = APR_BUCKET_NEXT(e);
+        ABTS_ASSERT(tc, "split OK", e != APR_BRIGADE_SENTINEL(bb));
+        e = APR_BUCKET_NEXT(e);
+    }
+    
+    ABTS_ASSERT(tc, "four buckets split into eight", 
+                count_buckets(bb) == 8);
+
+    for (n = 0, e = APR_BRIGADE_FIRST(bb); n < 4; n++) {
+        const char *data;
+        apr_size_t len;
+        
+        apr_assert_success(tc, "read alpha from bucket",
+                           apr_bucket_read(e, &data, &len, APR_BLOCK_READ));
+        ABTS_ASSERT(tc, "read 5 bytes", len == 5);
+        ABTS_STR_NEQUAL(tc, "alpha", data, 5);
+
+        e = APR_BUCKET_NEXT(e);
+
+        apr_assert_success(tc, "read beta from bucket",
+                           apr_bucket_read(e, &data, &len, APR_BLOCK_READ));
+        ABTS_ASSERT(tc, "read 4 bytes", len == 4);
+        ABTS_STR_NEQUAL(tc, "beta", data, 5);
+
+        e = APR_BUCKET_NEXT(e);
+    }
+
+    /* now delete the "alpha" buckets */
+    for (n = 0, e = APR_BRIGADE_FIRST(bb); n < 4; n++) {
+        apr_bucket *f;
+
+        ABTS_ASSERT(tc, "reached end of brigade",
+                    e != APR_BRIGADE_SENTINEL(bb));
+        f = APR_BUCKET_NEXT(e);
+        apr_bucket_delete(e);
+        e = APR_BUCKET_NEXT(f);
+    }    
+    
+    ABTS_ASSERT(tc, "eight buckets reduced to four", 
+                count_buckets(bb) == 4);
+
+    flatten_match(tc, "flatten beta brigade", bb,
+                  "beta" "beta" "beta" "beta");
+
+    apr_brigade_destroy(bb);
+    apr_bucket_alloc_destroy(ba);
+}
+
 abts_suite *testbuckets(abts_suite *suite)
 {
     suite = ADD_SUITE(suite);
@@ -218,6 +295,7 @@
     abts_run_test(suite, test_split, NULL);
     abts_run_test(suite, test_bwrite, NULL);
     abts_run_test(suite, test_splitline, NULL);
+    abts_run_test(suite, test_splits, NULL);
 
     return suite;
 }

Mime
View raw message