summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/p5-net-fastcgi/t/020_protocol/065_record_type.t
blob: 5836a05bce90c18031b6ef6eee80dc35f4bc4d62 (plain)
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
#!perl

use strict;
use warnings;

use lib 't/lib', 'lib';
use myconfig;

use Test::More tests => 55;
use Test::Exception;

BEGIN {
    use_ok('Net::FastCGI::Constant', qw[ :type ] );
    use_ok('Net::FastCGI::Protocol', qw[ is_discrete_type
                                         is_known_type
                                         is_management_type
                                         is_stream_type ] );
}

sub TRUE  () { !!1 }
sub FALSE () { !!0 }

{
    my @known = (
        FCGI_BEGIN_REQUEST,
        FCGI_ABORT_REQUEST,
        FCGI_END_REQUEST,
        FCGI_PARAMS,
        FCGI_STDIN,
        FCGI_STDOUT,
        FCGI_STDERR,
        FCGI_DATA,
        FCGI_GET_VALUES,
        FCGI_GET_VALUES_RESULT,
        FCGI_UNKNOWN_TYPE,
        FCGI_MAXTYPE,
    );

    foreach my $type (@known) {
        is( is_known_type($type), TRUE, qq/is_known_type($type) = true/ );
    }
}

{
    my @discrete = (
        FCGI_BEGIN_REQUEST,
        FCGI_ABORT_REQUEST,
        FCGI_END_REQUEST,
        FCGI_GET_VALUES,
        FCGI_GET_VALUES_RESULT,
        FCGI_UNKNOWN_TYPE,
    );

    foreach my $type ( @discrete ) {
        is( is_stream_type($type),   FALSE, qq/is_stream_type($type) = false/ );
        is( is_discrete_type($type), TRUE, qq/is_discrete_type($type) = true/ );
    }
}

{
    my @management = (
        FCGI_GET_VALUES,
        FCGI_GET_VALUES_RESULT,
        FCGI_UNKNOWN_TYPE,
    );

    foreach my $type (@management) {
        is( is_management_type($type), TRUE, qq/is_management_type($type) = true/ );
    }
}

{
    my @stream = (
        FCGI_PARAMS,
        FCGI_STDIN,
        FCGI_STDOUT,
        FCGI_STDERR,
        FCGI_DATA,
    );

    foreach my $type (@stream) {
        is( is_stream_type($type),   TRUE, qq/is_stream_type($type) = true/    );
        is( is_discrete_type($type), FALSE, qq/is_discrete_type($type) = false/ );
    }
}

{
    my @subnames = qw(
        is_known_type
        is_discrete_type
        is_management_type
        is_stream_type
    );

    foreach my $name (@subnames) {
        my $sub = __PACKAGE__->can($name);
        is($sub->($_), FALSE, qq/$name($_) = false/) for (-10, 0, 12);
    }
}

throws_ok { is_known_type()      } qr/^Usage: /;
throws_ok { is_discrete_type()   } qr/^Usage: /;
throws_ok { is_management_type() } qr/^Usage: /;
throws_ok { is_stream_type()     } qr/^Usage: /;