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

« back to all changes in this revision

Viewing changes to t/response/TestAPI/request_util.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:
 
1
package TestAPI::request_util;
 
2
 
 
3
use strict;
 
4
use warnings FATAL => 'all';
 
5
 
 
6
use Apache::Test;
 
7
use Apache::TestUtil;
 
8
 
 
9
use Apache2::RequestUtil ();
 
10
use Apache2::MPM ();
 
11
use Apache2::Log ();
 
12
use APR::Pool ();
 
13
 
 
14
use Apache2::Const -compile => 'OK';
 
15
 
 
16
my %status_lines = (
 
17
   200 => '200 OK',
 
18
   400 => '400 Bad Request',
 
19
   500 => '500 Internal Server Error',
 
20
);
 
21
 
 
22
sub handler {
 
23
    my $r = shift;
 
24
 
 
25
    plan $r, tests => (scalar keys %status_lines) + 11;
 
26
 
 
27
    ok $r->default_type;
 
28
 
 
29
    my $document_root = $r->document_root;
 
30
 
 
31
    ok $document_root;
 
32
 
 
33
    if (!Apache2::MPM->is_threaded) {
 
34
        my $path_orig = my $path = '/tmp/foo';
 
35
        ok t_cmp($document_root, $r->document_root($path));
 
36
        # make sure that the new docroot string is copied internally,
 
37
        # and later manipulations of the passed scalar don't affect it
 
38
        $path .= "suffix";
 
39
        ok t_cmp($path_orig, $r->document_root($document_root));
 
40
    }
 
41
    else {
 
42
        eval { $r->document_root('/tmp/foo') };
 
43
        ok t_cmp($@, qr/Can't run.*in the threaded env/, 
 
44
                 "document_root is read-only under threads");
 
45
        ok 1;
 
46
    }
 
47
 
 
48
    ok $r->get_server_name;
 
49
 
 
50
    ok $r->get_server_port;
 
51
 
 
52
    ok $r->get_limit_req_body || 1;
 
53
 
 
54
    ok $r->is_initial_req;
 
55
 
 
56
    my $sig = $r->psignature("Here is the sig: ");
 
57
    t_debug $sig;
 
58
    ok $sig;
 
59
 
 
60
    my $pattern =
 
61
        qr!(?s)GET /TestAPI__request_util.*Host:.*200 OK.*Content-Type:!;
 
62
 
 
63
    ok t_cmp($r->as_string,
 
64
             $pattern,
 
65
             "test for the request_line, host, status, and few " .
 
66
             "headers that should always be there");
 
67
 
 
68
    while (my($code, $line) = each %status_lines) {
 
69
        ok t_cmp(Apache2::RequestUtil::get_status_line($code),
 
70
                 $line,
 
71
                 "Apache2::RequestUtil::get_status_line($code)");
 
72
    }
 
73
 
 
74
    if (Apache2::MPM->is_threaded) {
 
75
        eval { $r->child_terminate() };
 
76
        ok t_cmp($@, qr/Can't run.*in a threaded mpm/, "child_terminate");
 
77
    }
 
78
    else {
 
79
        t_server_log_error_is_expected();
 
80
        ok $r->child_terminate() || 1;
 
81
        $r->pool->cleanup_register(
 
82
            sub {
 
83
                my $r = shift;
 
84
                $r->log_error("Process $$ terminates itself\n");
 
85
            }, $r);
 
86
    }
 
87
 
 
88
    Apache2::Const::OK;
 
89
}
 
90
 
 
91
1;