~ubuntu-branches/ubuntu/edgy/libapache2-mod-perl2/edgy

« back to all changes in this revision

Viewing changes to t/response/TestAPR/flatten.pm

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2004-08-19 06:23:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040819062348-jxl4koqbtvgm8v2t
Tags: 1.99.14-4
Remove the LFS CFLAGS, and build-dep against apache2-*-dev (>= 2.0.50-10)
as we're backing out of the apache2/apr ABI transition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package TestAPR::flatten;
 
2
 
 
3
use strict;
 
4
use warnings FATAL => 'all';
 
5
 
 
6
use Apache::Test;
 
7
use Apache::TestUtil;
 
8
 
 
9
use Apache::RequestRec ();
 
10
use APR::Bucket ();
 
11
use APR::Brigade ();
 
12
 
 
13
use Apache::Const -compile => 'OK';
 
14
 
 
15
sub handler {
 
16
 
 
17
    my $r = shift;
 
18
 
 
19
    plan $r, tests => 14;
 
20
 
 
21
    # first, create a brigade
 
22
    my $pool = $r->pool;
 
23
    my $ba   = $r->connection->bucket_alloc;
 
24
 
 
25
    my $bb   = APR::Brigade->new($pool, $ba);
 
26
 
 
27
    # now, let's put several buckets in it
 
28
    for (1 .. 10) {
 
29
        my $data = 'x' x 20000;
 
30
        my $bucket = APR::Bucket->new($data);
 
31
        $bb->insert_tail($bucket);
 
32
    }
 
33
 
 
34
    # ok, that's 10 buckets of 20,000 = 200,000 characters
 
35
    ok t_cmp(200000,
 
36
             $bb->length,
 
37
             'APR::Brigade::length()');
 
38
 
 
39
    # syntax: require a $bb
 
40
    eval { APR::Brigade::flatten("") };
 
41
 
 
42
    ok t_cmp(qr!expecting an APR::Brigade derived object!,
 
43
             $@,
 
44
             'APR::Brigade::flatten() requires a brigade');
 
45
 
 
46
    # flatten() will slurp up the entire brigade
 
47
    # equivalent to calling apr_brigade_pflatten
 
48
    {
 
49
        my $data = $bb->flatten();
 
50
 
 
51
        ok t_cmp(200000,
 
52
                 length($data),
 
53
                 '$bb->flatten() returned all the data');
 
54
 
 
55
        # don't use t_cmp() here, else we get 200,000 characters
 
56
        # to look at in verbose mode
 
57
        t_debug("data all 'x' characters");
 
58
        ok ($data !~ m/[^x]/);
 
59
    }
 
60
 
 
61
    # flatten(0) returns 0 bytes
 
62
    {
 
63
        my $data = $bb->flatten(0);
 
64
 
 
65
        t_debug('$bb->flatten(0) returns a defined value');
 
66
        ok (defined $data);
 
67
    
 
68
        ok t_cmp(0,
 
69
                 length($data),
 
70
                 '$bb->flatten(0) returned no data');
 
71
    }
 
72
 
 
73
 
 
74
    # flatten($length) will return the first $length bytes
 
75
    # equivalent to calling apr_brigade_flatten
 
76
    {
 
77
        # small
 
78
        my $data = $bb->flatten(30);
 
79
 
 
80
        ok t_cmp(30,
 
81
                 length($data),
 
82
                 '$bb->flatten(30) returned 30 characters');
 
83
 
 
84
        t_debug("APR::Brigade::flatten() data all 'x' characters");
 
85
        ok ($data !~ m/[^x]/);
 
86
    }
 
87
 
 
88
    {
 
89
        # large 
 
90
        my $data = $bb->flatten(190000);
 
91
 
 
92
        ok t_cmp(190000,
 
93
                 length($data),
 
94
                 '$bb->flatten(190000) returned 19000 characters');
 
95
 
 
96
        t_debug("data all 'x' characters");
 
97
        ok ($data !~ m/[^x]/);
 
98
    }
 
99
 
 
100
    {
 
101
        # more than enough
 
102
        my $data = $bb->flatten(300000);
 
103
 
 
104
        ok t_cmp(200000,
 
105
                 length($data),
 
106
                 '$bb->flatten(300000) returned all 200000 characters');
 
107
 
 
108
        t_debug("data all 'x' characters");
 
109
        ok ($data !~ m/[^x]/);
 
110
    }
 
111
 
 
112
    # fetch from a brigade with no data in it
 
113
    {
 
114
        my $data = APR::Brigade->new($pool, $ba)->flatten();
 
115
 
 
116
        t_debug('empty brigade returns a defined value');
 
117
        ok (defined $data);
 
118
    
 
119
        ok t_cmp(0,
 
120
                 length($data),
 
121
                 'empty brigade returns data of 0 length');
 
122
    }
 
123
 
 
124
    Apache::OK;
 
125
}
 
126
 
 
127
1;