apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject svn commit: r290679 - /apr/apr-util/trunk/test/testbuckets.c
Date Wed, 21 Sep 2005 10:49:39 GMT
Author: jorton
Date: Wed Sep 21 03:49:34 2005
New Revision: 290679

URL: http://svn.apache.org/viewcvs?rev=290679&view=rev
Log:
* test/testbuckets.c (test_bucket_content): New function.
(test_partition): New test.

Modified:
    apr/apr-util/trunk/test/testbuckets.c

Modified: apr/apr-util/trunk/test/testbuckets.c
URL: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/testbuckets.c?rev=290679&r1=290678&r2=290679&view=diff
==============================================================================
--- apr/apr-util/trunk/test/testbuckets.c (original)
+++ apr/apr-util/trunk/test/testbuckets.c Wed Sep 21 03:49:34 2005
@@ -209,6 +209,22 @@
     apr_bucket_alloc_destroy(ba);
 }
 
+/* Test that bucket E has content EDATA of length ELEN. */
+static void test_bucket_content(abts_case *tc,
+                                apr_bucket *e,
+                                const char *edata,
+                                apr_size_t elen)
+{
+    const char *adata;
+    apr_size_t alen;
+
+    apr_assert_success(tc, "read from bucket",
+                       apr_bucket_read(e, &adata, &alen, 
+                                       APR_BLOCK_READ));
+
+    ABTS_ASSERT(tc, "read expected length", alen == elen);
+    ABTS_STR_NEQUAL(tc, edata, adata, elen);
+}
 
 static void test_splits(abts_case *tc, void *ctx)
 {
@@ -414,6 +430,36 @@
     apr_bucket_alloc_destroy(ba);
 }
 
+static const char hello[] = "hello, world";
+
+static void test_partition(abts_case *tc, void *data)
+{
+    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
+    apr_bucket_brigade *bb = apr_brigade_create(p, ba);
+    apr_bucket *e;
+
+    e = apr_bucket_immortal_create(hello, strlen(hello), ba);
+    APR_BRIGADE_INSERT_HEAD(bb, e);
+
+    apr_assert_success(tc, "partition brigade",
+                       apr_brigade_partition(bb, 5, &e));
+
+    test_bucket_content(tc, APR_BRIGADE_FIRST(bb),
+                        "hello", 5);
+
+    test_bucket_content(tc, APR_BRIGADE_LAST(bb),
+                        ", world", 7);
+
+    ABTS_ASSERT(tc, "partition returns APR_INCOMPLETE",
+                apr_brigade_partition(bb, 8192, &e));
+
+    ABTS_ASSERT(tc, "APR_INCOMPLETE partition returned sentinel",
+                e == APR_BRIGADE_SENTINEL(bb));
+
+    apr_brigade_destroy(bb);
+    apr_bucket_alloc_destroy(ba);
+}
+
 abts_suite *testbuckets(abts_suite *suite)
 {
     suite = ADD_SUITE(suite);
@@ -428,6 +474,7 @@
     abts_run_test(suite, test_insertfile, NULL);
     abts_run_test(suite, test_manyfile, NULL);
     abts_run_test(suite, test_truncfile, NULL);
+    abts_run_test(suite, test_partition, NULL);
 
     return suite;
 }



Mime
View raw message