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

« back to all changes in this revision

Viewing changes to t/response/TestAPI/request_rec.pm

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2005-08-12 01:40:38 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050812014038-gjigefs55pqx4qc8
Tags: 2.0.1-3
Grr.  Really include perl.conf file; it got lost due to diff not
wanting to add an empty file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
use Apache::TestUtil;
8
8
use Apache::TestRequest;
9
9
 
10
 
use Apache::RequestRec ();
11
 
use Apache::RequestUtil ();
12
 
 
13
 
use Apache::Const -compile => 'OK';
 
10
use Apache2::RequestRec ();
 
11
use Apache2::RequestUtil ();
 
12
 
 
13
use APR::Finfo ();
 
14
use APR::Pool ();
 
15
 
 
16
use Apache2::Const -compile => qw(OK M_GET M_PUT);
 
17
use APR::Const    -compile => qw(FINFO_NORM);
14
18
 
15
19
#this test module is only for testing fields in the request_rec
16
20
#listed in apache_structures.map
20
24
sub handler {
21
25
    my $r = shift;
22
26
 
23
 
    plan $r, tests => 42;
 
27
    plan $r, tests => 54;
24
28
 
25
 
    #Apache->request($r); #PerlOptions +GlobalRequest takes care
26
 
    my $gr = Apache->request;
 
29
    #Apache2::RequestUtil->request($r); #PerlOptions +GlobalRequest takes care
 
30
    my $gr = Apache2::RequestUtil->request;
27
31
 
28
32
    ok $$gr == $$r;
29
33
 
30
 
    my $newr = Apache::RequestRec->new($r->connection, $r->pool);
31
 
    Apache->request($newr);
32
 
    $gr = Apache->request;
 
34
    my $newr = Apache2::RequestRec->new($r->connection, $r->pool);
 
35
    Apache2::RequestUtil->request($newr);
 
36
    $gr = Apache2::RequestUtil->request;
33
37
 
34
38
    ok $$gr == $$newr;
35
39
 
36
 
    Apache->request($r);
 
40
    Apache2::RequestUtil->request($r);
37
41
 
38
42
    ok $r->pool->isa('APR::Pool');
39
43
 
40
 
    ok $r->connection->isa('Apache::Connection');
 
44
    ok $r->connection->isa('Apache2::Connection');
41
45
 
42
 
    ok $r->server->isa('Apache::Server');
 
46
    ok $r->server->isa('Apache2::ServerRec');
43
47
 
44
48
    for (qw(next prev main)) {
45
 
        ok (! $r->$_()) || $r->$_()->isa('Apache::RequestRec');
 
49
        ok (! $r->$_()) || $r->$_()->isa('Apache2::RequestRec');
46
50
    }
47
51
 
48
 
    ok $r->the_request || 1;
49
 
 
50
 
    ok $r->assbackwards || 1;
51
 
 
52
 
    ok $r->proxyreq || 1;
53
 
 
54
 
    ok $r->header_only || 1;
 
52
    ok !$r->assbackwards;
 
53
 
 
54
    ok !$r->proxyreq; # see also TestModules::proxy
 
55
 
 
56
    ok !$r->header_only;
55
57
 
56
58
    ok $r->protocol =~ /http/i;
57
59
 
58
 
    ok $r->proto_num;
59
 
 
60
 
    ok $r->hostname || 1;
 
60
    # HTTP 1.0
 
61
    ok t_cmp $r->proto_num, 1000, 't->proto_num';
 
62
 
 
63
    ok t_cmp lc($r->hostname), lc($r->get_server_name), '$r->hostname';
 
64
 
 
65
    {
 
66
        my $old_hostname = $r->hostname("other.hostname");
 
67
        ok t_cmp $r->hostname, "other.hostname", '$r->hostname rw';
 
68
        $r->hostname($old_hostname);
 
69
    }
61
70
 
62
71
    ok $r->request_time;
63
72
 
65
74
 
66
75
    ok $r->status || 1;
67
76
 
68
 
    ok $r->method;
69
 
 
70
 
    ok $r->method_number || 1;
71
 
 
72
 
    ok $r->allowed || 1;
73
 
 
74
 
    #allowed_xmethods
75
 
    #allow_methods
76
 
 
77
 
    ok $r->bytes_sent || 1;
78
 
 
79
 
    ok $r->mtime || 1;
 
77
    ok t_cmp $r->method, 'GET', '$r->method';
 
78
 
 
79
    ok t_cmp $r->method_number, Apache2::Const::M_GET, '$r->method_number';
80
80
 
81
81
    ok $r->headers_in;
82
82
 
83
83
    ok $r->headers_out;
84
84
 
 
85
    # tested in TestAPI::err_headers_out
85
86
    ok $r->err_headers_out;
86
87
 
87
88
    ok $r->subprocess_env;
92
93
 
93
94
    ok $r->handler;
94
95
 
95
 
    #content_encoding
96
 
    #content_language
97
 
    #content_languages
98
 
 
99
 
    #user
100
 
 
101
96
    ok $r->ap_auth_type || 1;
102
97
 
103
98
    ok $r->no_cache || 1;
104
99
 
 
100
    ok !$r->no_local_copy;
 
101
 
105
102
    {
106
103
        local $| = 0;
107
 
        ok 11  == $r->print("# buffered\n");
108
 
        ok 0  == $r->print();
 
104
        ok t_cmp $r->print("# buffered\n"), 11, "buffered print";
 
105
        ok t_cmp $r->print(), "0E0", "buffered print";
 
106
 
109
107
        local $| = 1;
110
 
        ok 15 == $r->print('#',' ','n','o','t',' ','b','u','f','f','e','r','e','d',"\n");
111
 
    }
112
 
 
113
 
    #no_local_copy
114
 
 
115
 
    ok $r->unparsed_uri;
116
 
 
117
 
    ok $r->uri;
118
 
 
119
 
    ok $r->filename;
120
 
 
121
 
    my $location = '/' . Apache::TestRequest::module2path(__PACKAGE__);
122
 
    ok t_cmp($location, $r->location, "location");
123
 
 
124
 
    my $mtime = (stat __FILE__)[9];
125
 
    $r->mtime($mtime);
126
 
 
127
 
    ok $r->mtime == $mtime;
128
 
 
129
 
    ok $r->path_info || 1;
130
 
 
131
 
    ok $r->args || 1;
132
 
 
133
 
    #finfo
134
 
    #parsed_uri
135
 
 
136
 
    #per_dir_config
137
 
    #request_config
138
 
 
139
 
    #output_filters
140
 
    #input_filers
141
 
 
142
 
    #eos_sent
143
 
 
144
 
    Apache::OK;
 
108
        my $string = "# not buffered\n";
 
109
        ok t_cmp $r->print(split //, $string), length($string),
 
110
            "unbuffered print";
 
111
    }
 
112
 
 
113
    # GET header components
 
114
    {
 
115
        my $args      = "my_args=3";
 
116
        my $path_info = "/my_path_info";
 
117
        my $base_uri  = "/TestAPI__request_rec";
 
118
 
 
119
        ok t_cmp $r->unparsed_uri, "$base_uri$path_info?$args";
 
120
 
 
121
        ok t_cmp $r->uri, "$base_uri$path_info", '$r->uri';
 
122
 
 
123
        ok t_cmp $r->path_info, $path_info, '$r->path_info';
 
124
 
 
125
        ok t_cmp $r->args, $args, '$r->args';
 
126
 
 
127
        ok t_cmp $r->the_request, "GET $base_uri$path_info?$args HTTP/1.0",
 
128
            '$r->the_request';
 
129
 
 
130
        ok $r->filename;
 
131
 
 
132
        my $location = '/' . Apache::TestRequest::module2path(__PACKAGE__);
 
133
        ok t_cmp $r->location, $location, '$r->location';
 
134
    }
 
135
 
 
136
    # bytes_sent
 
137
    {
 
138
        $r->rflush;
 
139
        my $sent = $r->bytes_sent;
 
140
        t_debug "sent so far: $sent bytes";
 
141
        # at least 100 chars were sent already
 
142
        ok $sent > 100;
 
143
    }
 
144
 
 
145
    # mtime
 
146
    {
 
147
        my $mtime = (stat __FILE__)[9];
 
148
        $r->mtime($mtime);
 
149
        ok t_cmp $r->mtime, $mtime, "mtime";
 
150
    }
 
151
 
 
152
    # finfo
 
153
    {
 
154
        my $finfo = APR::Finfo::stat(__FILE__, APR::Const::FINFO_NORM, $r->pool);
 
155
        $r->finfo($finfo);
 
156
        # just one field test, all accessors are fully tested in
 
157
        # TestAPR::finfo
 
158
        ok t_cmp($r->finfo->fname,
 
159
                 __FILE__,
 
160
                 '$r->finfo');
 
161
    }
 
162
 
 
163
    # allowed
 
164
    {
 
165
        $r->allowed(1 << Apache2::Const::M_GET);
 
166
 
 
167
        ok $r->allowed & (1 << Apache2::Const::M_GET);
 
168
        ok ! ($r->allowed & (1 << Apache2::Const::M_PUT));
 
169
 
 
170
        $r->allowed($r->allowed | (1 << Apache2::Const::M_PUT));
 
171
        ok $r->allowed & (1 << Apache2::Const::M_PUT);
 
172
    }
 
173
 
 
174
    # content_languages
 
175
    {
 
176
        my $def = [qw(fr)];       #default value
 
177
        my $l   = [qw(fr us cn)]; #new value
 
178
 
 
179
        if (have_module('mod_mime')) {
 
180
            ok t_cmp $r->content_languages, $def, '$r->content_languages';
 
181
        }
 
182
        else {
 
183
            skip "Need mod_mime", 0;
 
184
        }
 
185
 
 
186
        my $old = $r->content_languages($l);
 
187
        if (have_module('mod_mime')) {
 
188
            ok t_cmp $old, $def, '$r->content_languages';
 
189
        }
 
190
        else {
 
191
            skip "Need mod_mime", 0;
 
192
        }
 
193
 
 
194
        ok t_cmp $r->content_languages, $l, '$r->content_languages';
 
195
 
 
196
        eval { $r->content_languages({}) };
 
197
        ok t_cmp $@, qr/Not an array reference/,
 
198
                '$r->content_languages(invalid)';
 
199
    }
 
200
 
 
201
    ### invalid $r
 
202
    {
 
203
        my $r = bless {}, "Apache2::RequestRec";
 
204
        my $err = q[method `uri' invoked by a `Apache2::RequestRec' ] .
 
205
            q[object with no `r' key!];
 
206
        eval { $r->uri };
 
207
        ok t_cmp $@, qr/$err/, "invalid $r object";
 
208
    }
 
209
    {
 
210
        my $r = bless {}, "NonExisting";
 
211
        my $err = q[method `uri' invoked by a `NonExisting' ] .
 
212
            q[object with no `r' key!];
 
213
        eval { Apache2::RequestRec::uri($r) };
 
214
        ok t_cmp $@, qr/$err/, "invalid $r object";
 
215
    }
 
216
    {
 
217
        my $r = {};
 
218
        my $err = q[method `uri' invoked by a `unknown' ] .
 
219
            q[object with no `r' key!];
 
220
        eval { Apache2::RequestRec::uri($r) };
 
221
        ok t_cmp $@, qr/$err/, "invalid $r object";
 
222
    }
 
223
 
 
224
    # out-of-scope pools
 
225
    {
 
226
        my $newr = Apache2::RequestRec->new($r->connection, APR::Pool->new);
 
227
        {
 
228
            require APR::Table;
 
229
            # try to overwrite the pool
 
230
            my $table = APR::Table::make(APR::Pool->new, 50);
 
231
            $table->set($_ => $_) for 'aa'..'za';
 
232
        }
 
233
        # check if $newr is still OK
 
234
        ok $newr->connection->isa('Apache2::Connection');
 
235
    }
 
236
 
 
237
    # tested in other tests
 
238
    # - input_filters:    TestAPI::in_out_filters
 
239
    # - output_filters:   TestAPI::in_out_filters
 
240
    # - per_dir_config:   in several other tests
 
241
    # - content_encoding: TestAPI::content_encoding
 
242
    # - user:             TestHooks::authz / TestHooks::authen
 
243
 
 
244
    # XXX: untested
 
245
    # - request_config
 
246
    # - allowed_xmethods
 
247
    # - allowed_methods
 
248
 
 
249
    Apache2::Const::OK;
145
250
}
146
251
 
147
252
1;
148
253
__END__
149
 
PerlOptions +GlobalRequest
 
254
<NoAutoConfig>
 
255
<Location /TestAPI__request_rec>
 
256
    PerlOptions +GlobalRequest
 
257
    <IfModule mod_mime.c>
 
258
        DefaultLanguage fr
 
259
    </IfModule>
 
260
    SetHandler modperl
 
261
    PerlResponseHandler TestAPI::request_rec
 
262
</Location>
 
263
</NoAutoConfig>