summaryrefslogtreecommitdiff
path: root/test/testbuckets.c
diff options
context:
space:
mode:
authorGraham Leggett <minfrin@apache.org>2021-10-19 14:30:37 +0000
committerGraham Leggett <minfrin@apache.org>2021-10-19 14:30:37 +0000
commitf65813689e5a0061e65eca5d626ebe11d088b87a (patch)
treef9d88d1e5f251da447c3c9404d21aabb8ac28ed7 /test/testbuckets.c
parent424e4ecebab9e3df6fe25c1507cc4093bc00f715 (diff)
downloadapr-f65813689e5a0061e65eca5d626ebe11d088b87a.tar.gz
apr_brigades: Add apr_brigade_split_boundary(), allowing us to split
brigades on boundaries of arbitrary length. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1894380 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testbuckets.c')
-rw-r--r--test/testbuckets.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/testbuckets.c b/test/testbuckets.c
index 31bed0c1b..2b789f1a0 100644
--- a/test/testbuckets.c
+++ b/test/testbuckets.c
@@ -209,6 +209,62 @@ static void test_splitline(abts_case *tc, void *data)
apr_bucket_alloc_destroy(ba);
}
+static void test_splitboundary(abts_case *tc, void *data)
+{
+ apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
+ apr_bucket_brigade *bin, *bout;
+
+ /* fast path */
+ bin = make_simple_brigade(ba, "quick brown fox",
+ " jumped over the lazy dog");
+ bout = apr_brigade_create(p, ba);
+
+ APR_ASSERT_SUCCESS(tc, "split boundary",
+ apr_brigade_split_boundary(bout, bin,
+ APR_BLOCK_READ, "brown",
+ APR_BUCKETS_STRING, 100));
+
+ flatten_match(tc, "split boundary", bout, "quick ");
+ flatten_match(tc, "remainder", bin, " fox jumped over the lazy dog");
+
+ apr_brigade_destroy(bout);
+ apr_brigade_destroy(bin);
+
+ /* slow path */
+ bin = make_simple_brigade(ba, "quick brown fox jum",
+ "ped over the lazy dog");
+ bout = apr_brigade_create(p, ba);
+
+ APR_ASSERT_SUCCESS(tc, "split boundary",
+ apr_brigade_split_boundary(bout, bin,
+ APR_BLOCK_READ, "jumped",
+ APR_BUCKETS_STRING, 100));
+
+ flatten_match(tc, "split boundary", bout, "quick brown fox ");
+ flatten_match(tc, "remainder", bin, " over the lazy dog");
+
+ apr_brigade_destroy(bout);
+ apr_brigade_destroy(bin);
+
+ /* not found */
+ bin = make_simple_brigade(ba, "quick brown fox jum",
+ "ped over the lazy dog");
+ bout = apr_brigade_create(p, ba);
+
+ ABTS_ASSERT(tc, "split boundary",
+ apr_brigade_split_boundary(bout, bin,
+ APR_BLOCK_READ, "jumping",
+ APR_BUCKETS_STRING, 100) == APR_INCOMPLETE);
+
+ flatten_match(tc, "split boundary", bout, "quick brown fox jumped over the lazy dog");
+ flatten_match(tc, "remainder", bin, "");
+
+ apr_brigade_destroy(bout);
+ apr_brigade_destroy(bin);
+
+ 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,
@@ -521,6 +577,7 @@ abts_suite *testbuckets(abts_suite *suite)
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_splitboundary, NULL);
abts_run_test(suite, test_splits, NULL);
abts_run_test(suite, test_insertfile, NULL);
abts_run_test(suite, test_manyfile, NULL);