apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject svn commit: r290680 - in /apr/apr-util/branches/1.2.x: include/apr_buckets.h test/testbuckets.c
Date Wed, 21 Sep 2005 10:53:23 GMT
Author: jorton
Date: Wed Sep 21 03:53:18 2005
New Revision: 290680

URL: http://svn.apache.org/viewcvs?rev=290680&view=rev
Log:
Merge r290556, r290679 from trunk:

* include/apr_buckets.h (apr_brigade_partition): Document the return
value semantics.

* test/testbuckets.c (test_bucket_content): New function.
(test_partition): New test.

Modified:
    apr/apr-util/branches/1.2.x/include/apr_buckets.h
    apr/apr-util/branches/1.2.x/test/testbuckets.c

Modified: apr/apr-util/branches/1.2.x/include/apr_buckets.h
URL: http://svn.apache.org/viewcvs/apr/apr-util/branches/1.2.x/include/apr_buckets.h?rev=290680&r1=290679&r2=290680&view=diff
==============================================================================
--- apr/apr-util/branches/1.2.x/include/apr_buckets.h (original)
+++ apr/apr-util/branches/1.2.x/include/apr_buckets.h Wed Sep 21 03:53:18 2005
@@ -697,6 +697,10 @@
  * @param b The brigade to partition
  * @param point The offset at which to partition the brigade
  * @param after_point Returns a pointer to the first bucket after the partition
+ * @return APR_SUCCESS on success, APR_INCOMPLETE if the contents of the
+ * brigade were shorter than @a point, or an error code.
+ * @remark if APR_INCOMPLETE is returned, @a after_point will be set to
+ * the brigade sentinel.
  */
 APU_DECLARE(apr_status_t) apr_brigade_partition(apr_bucket_brigade *b,
                                                 apr_off_t point,

Modified: apr/apr-util/branches/1.2.x/test/testbuckets.c
URL: http://svn.apache.org/viewcvs/apr/apr-util/branches/1.2.x/test/testbuckets.c?rev=290680&r1=290679&r2=290680&view=diff
==============================================================================
--- apr/apr-util/branches/1.2.x/test/testbuckets.c (original)
+++ apr/apr-util/branches/1.2.x/test/testbuckets.c Wed Sep 21 03:53:18 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