apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject cvs commit: apr-util/test testbuckets.c
Date Tue, 22 Jun 2004 19:56:20 GMT
jorton      2004/06/22 12:56:20

  Modified:    test     testbuckets.c
  Log:
  * test/testbuckets.c (test_flatten, test_split, test_bwrite,
  test_splitline): Add more tests.
  
  Revision  Changes    Path
  1.2       +146 -0    apr-util/test/testbuckets.c
  
  Index: testbuckets.c
  ===================================================================
  RCS file: /home/cvs/apr-util/test/testbuckets.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -d -w -u -r1.1 -r1.2
  --- testbuckets.c	22 Jun 2004 16:26:45 -0000	1.1
  +++ testbuckets.c	22 Jun 2004 19:56:20 -0000	1.2
  @@ -61,17 +61,163 @@
                   APR_BUCKET_PREV(fb) == tb);
       ABTS_ASSERT(tc, "bucket after transient is flush",
                   APR_BUCKET_NEXT(tb) == fb);
  +    ABTS_ASSERT(tc, "bucket before transient is sentinel",
  +                APR_BUCKET_PREV(tb) == APR_BRIGADE_SENTINEL(bb));
  +
  +    apr_brigade_cleanup(bb);
  +
  +    ABTS_ASSERT(tc, "cleaned up brigade was empty", APR_BRIGADE_EMPTY(bb));
  +
  +    apr_brigade_destroy(bb);
  +    apr_bucket_alloc_destroy(ba);
  +}
  +
  +static apr_bucket_brigade *make_simple_brigade(apr_bucket_alloc_t *ba,
  +                                               const char *first, 
  +                                               const char *second)
  +{
  +    apr_bucket_brigade *bb = apr_brigade_create(p, ba);
  +    apr_bucket *e;
  + 
  +    e = apr_bucket_transient_create(first, strlen(first), ba);
  +    APR_BRIGADE_INSERT_TAIL(bb, e);
  +
  +    e = apr_bucket_transient_create(second, strlen(second), ba);
  +    APR_BRIGADE_INSERT_TAIL(bb, e);
  +
  +    return bb;
  +}
  +
  +/* tests that 'bb' flattens to string 'expect'. */
  +static void flatten_match(abts_case *tc, const char *ctx,
  +                          apr_bucket_brigade *bb,
  +                          const char *expect)
  +{
  +    apr_size_t elen = strlen(expect);
  +    char *buf = malloc(elen);
  +    apr_size_t len = elen;
  +    char msg[200];
  +
  +    sprintf(msg, "%s: flatten brigade", ctx);
  +    apr_assert_success(tc, msg, apr_brigade_flatten(bb, buf, &len));
  +    sprintf(msg, "%s: length match (%ld not %ld)", ctx,
  +            (long)len, (long)elen);
  +    ABTS_ASSERT(tc, msg, len == elen);
  +    sprintf(msg, "%s: result match", msg);
  +    ABTS_STR_NEQUAL(tc, expect, buf, len);
  +    free(buf);
  +}
  +
  +static void test_flatten(abts_case *tc, void *data)
  +{
  +    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
  +    apr_bucket_brigade *bb;
  +
  +    bb = make_simple_brigade(ba, "hello, ", "world");
  +
  +    flatten_match(tc, "flatten brigade", bb, "hello, world");
  +
  +    apr_brigade_destroy(bb);
  +    apr_bucket_alloc_destroy(ba);    
  +}
  +
  +static int count_buckets(apr_bucket_brigade *bb)
  +{
  +    apr_bucket *e;
  +    int count = 0;
  +
  +    for (e = APR_BRIGADE_FIRST(bb); 
  +         e != APR_BRIGADE_SENTINEL(bb);
  +         e = APR_BUCKET_NEXT(e)) {
  +        count++;
  +    }
  +    
  +    return count;
  +}
   
  +static void test_split(abts_case *tc, void *data)
  +{
  +    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
  +    apr_bucket_brigade *bb, *bb2;
  +    apr_bucket *e;
  +
  +    bb = make_simple_brigade(ba, "hello, ", "world");
  +
  +    /* split at the "world" bucket */
  +    e = APR_BRIGADE_LAST(bb);
  +    bb2 = apr_brigade_split(bb, e);
  +
  +    ABTS_ASSERT(tc, "split brigade contains one bucket",
  +                count_buckets(bb2) == 1);
  +    ABTS_ASSERT(tc, "original brigade contains one bucket",
  +                count_buckets(bb) == 1);
  +
  +    flatten_match(tc, "match original brigade", bb, "hello, ");
  +    flatten_match(tc, "match split brigade", bb2, "world");
  +
  +    apr_brigade_destroy(bb2);
       apr_brigade_destroy(bb);
       apr_bucket_alloc_destroy(ba);
   }
   
  +#define COUNT 3000
  +#define THESTR "hello"
  +
  +static void test_bwrite(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_off_t length;
  +    int n;
  +
  +    for (n = 0; n < COUNT; n++) {
  +        apr_assert_success(tc, "brigade_write", 
  +                           apr_brigade_write(bb, NULL, NULL,
  +                                             THESTR, sizeof THESTR));
  +    }
  +
  +    apr_assert_success(tc, "determine brigade length",
  +                       apr_brigade_length(bb, 1, &length));
  +
  +    ABTS_ASSERT(tc, "brigade has correct length",
  +                length == (COUNT * sizeof THESTR));
  +    
  +    apr_brigade_destroy(bb);
  +    apr_bucket_alloc_destroy(ba);
  +}
  +
  +static void test_splitline(abts_case *tc, void *data)
  +{
  +    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
  +    apr_bucket_brigade *bin, *bout;
  +
  +    bin = make_simple_brigade(ba, "blah blah blah-",
  +                              "end of line.\nfoo foo foo");
  +    bout = apr_brigade_create(p, ba);
  +
  +    apr_assert_success(tc, "split line",
  +                       apr_brigade_split_line(bout, bin,
  +                                              APR_BLOCK_READ, 100));
  +
  +    flatten_match(tc, "split line", bout, "blah blah blah-end of line.\n");
  +    flatten_match(tc, "remainder", bin, "foo foo foo");
  +
  +    apr_brigade_destroy(bout);
  +    apr_brigade_destroy(bin);
  +    apr_bucket_alloc_destroy(ba);
  +}
  +
  +
   abts_suite *testbuckets(abts_suite *suite)
   {
       suite = ADD_SUITE(suite);
   
       abts_run_test(suite, test_create, NULL);
       abts_run_test(suite, test_simple, NULL);
  +    abts_run_test(suite, test_flatten, NULL);
  +    abts_run_test(suite, test_split, NULL);
  +    abts_run_test(suite, test_bwrite, NULL);
  +    abts_run_test(suite, test_splitline, NULL);
   
       return suite;
   }
  
  
  

Mime
View raw message