File: query.pm

package info (click to toggle)
libapache2-mod-perl2 2.0.9~1624218-2%2Bdeb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,912 kB
  • ctags: 4,588
  • sloc: perl: 95,064; ansic: 14,527; makefile: 49; sh: 18
file content (152 lines) | stat: -rw-r--r-- 4,551 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
package TestAPI::query;

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;
use Apache::TestTrace;

use Apache2::MPM ();

use Apache2::Const -compile => qw(OK :mpmq);

sub handler {

    my $r = shift;

    plan $r, tests => 5;

    # ok, this isn't particularly pretty, but I can't think
    # of a better way to do it
    # all of these attributes I pulled right from the C sources
    # so if, say, leader all of a sudden changes its properties,
    # these tests will fail

    my $mpm = lc Apache2::MPM->show;

    if ($mpm eq 'prefork') {

        {
            my $query = Apache2::MPM->query(Apache2::Const::MPMQ_IS_THREADED);

            ok t_cmp($query,
                     Apache2::Const::MPMQ_NOT_SUPPORTED,
                     "MPMQ_IS_THREADED ($mpm)");

            # is_threaded() is just a constsub set to the result from
            # ap_mpm_query(AP_MPMQ_IS_THREADED)

            ok t_cmp($query,
                     Apache2::MPM->is_threaded,
                     "Apache2::MPM->is_threaded() equivalent to query(MPMQ_IS_THREADED)");

            t_debug('Apache2::MPM->is_threaded returned ' . Apache2::MPM->is_threaded);
            ok (! Apache2::MPM->is_threaded);
        }

        {
            my $query = Apache2::MPM->query(Apache2::Const::MPMQ_IS_FORKED);

            ok t_cmp($query,
                     Apache2::Const::MPMQ_DYNAMIC,
                     "MPMQ_IS_FORKED ($mpm)");
        }

    }
    elsif ($mpm eq 'worker') {

        {
            my $query = Apache2::MPM->query(Apache2::Const::MPMQ_IS_THREADED);

            ok t_cmp($query,
                     Apache2::Const::MPMQ_STATIC,
                     "MPMQ_IS_THREADED ($mpm)");

            ok t_cmp($query,
                     Apache2::MPM->is_threaded,
                     "Apache2::MPM->is_threaded() equivalent to query(MPMQ_IS_THREADED)");

            t_debug('Apache2::MPM->is_threaded returned ' . Apache2::MPM->is_threaded);
            ok (Apache2::MPM->is_threaded);
        }

        {
            my $query = Apache2::MPM->query(Apache2::Const::MPMQ_IS_FORKED);

            ok t_cmp($query,
                     Apache2::Const::MPMQ_DYNAMIC,
                     "MPMQ_IS_FORKED ($mpm)");
        }
    }
    elsif ($mpm eq 'leader') {

        {
            my $query = Apache2::MPM->query(Apache2::Const::MPMQ_IS_THREADED);

            ok t_cmp($query,
                     Apache2::Const::MPMQ_STATIC,
                     "MPMQ_IS_THREADED ($mpm)");

            ok t_cmp($query,
                     Apache2::MPM->is_threaded,
                     "Apache2::MPM->is_threaded() equivalent to query(MPMQ_IS_THREADED)");

            t_debug('Apache2::MPM->is_threaded returned ' . Apache2::MPM->is_threaded);
            ok (Apache2::MPM->is_threaded);
        }

        {
            my $query = Apache2::MPM->query(Apache2::Const::MPMQ_IS_FORKED);

            ok t_cmp($query,
                     Apache2::Const::MPMQ_DYNAMIC,
                     "MPMQ_IS_FORKED ($mpm)");
        }
    }
    elsif ($mpm eq 'winnt') {

        {
            my $query = Apache2::MPM->query(Apache2::Const::MPMQ_IS_THREADED);

            ok t_cmp($query,
                     Apache2::Const::MPMQ_STATIC,
                     "MPMQ_IS_THREADED ($mpm)");

            ok t_cmp($query,
                     Apache2::MPM->is_threaded,
                     "Apache2::MPM->is_threaded() equivalent to query(MPMQ_IS_THREADED)");

            t_debug('Apache2::MPM->is_threaded returned ' . Apache2::MPM->is_threaded);
            ok (Apache2::MPM->is_threaded);
        }

        {
            my $query = Apache2::MPM->query(Apache2::Const::MPMQ_IS_FORKED);

            ok t_cmp($query,
                     Apache2::Const::MPMQ_NOT_SUPPORTED,
                     "MPMQ_IS_FORKED ($mpm)");
        }
    }
    else {
        skip "skipping MPMQ_IS_THREADED test for $mpm MPM", 0;
        skip "skipping Apache2::MPM->is_threaded equivalence test for $mpm MPM", 0;
        skip "skipping MPMQ_IS_FORKED test for $mpm MPM", 0;
        skip "skipping Apache2::MPM->is_threaded test for $mpm MPM", 0;
    }

    # make sure that an undefined MPMQ constant yields undef
    {
        my $query = Apache2::MPM->query(72);

        ok t_cmp($query,
                 undef,
                 "unknown MPMQ value returns undef");
    }

    Apache2::Const::OK;
}

1;