File: 30-net-dhcp-constants-coverage.t

package info (click to toggle)
libnet-dhcp-perl 0.693%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 368 kB
  • ctags: 111
  • sloc: perl: 1,974; sh: 51; makefile: 8
file content (198 lines) | stat: -rwxr-xr-x 5,219 bytes parent folder | download | duplicates (4)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/perl

use Test::More tests => 207;

BEGIN { use_ok('Net::DHCP::Constants'); }

use Net::DHCP::Constants
  qw(%DHO_CODES %DHCP_MESSAGE %NWIP_CODES %CCC_CODES %GEOCONF_CODES %RELAYAGENT_CODES);

use strict;
use warnings;

# load in the iana definitions
my %iana;
eval {
    our $VAR1;
    for my $file (qw(  ./.iana.pl ../t/.iana.pl t/.iana.pl  )) {
        require $file if -f $file;
    }
    die "couldnt load iana file"
      unless ref $VAR1;
    %iana = %$VAR1;
};

SKIP: {
    skip( q|Couldn't load iana details, skipping coverage|, 206 ) if $@;

    # check that all iana codes are included

    # DHO CODES - bootp-dhcp-parameters-1
    {
        my @val = values %DHO_CODES;

        my $codes =
          $iana{registry}->{'bootp-dhcp-parameters-1'}
          ->{record};    # this is mildy nasty

        for my $k (
            sort { int $codes->{$a}->{value} <=> int $codes->{$b}->{value} }
            grep { $_ !~ m/unassigned|private use/i }
            keys %$codes
          )
        {

            my $name = $k;
            $name =~ s/\n+//;
            my $value = int $codes->{$k}->{value};
            ok(
                ( grep { $value == $_ } @val ),
                "\%DHO_CODES has $value aka $name"
            );

        }

    }

## MESSAGE TYPES - bootp-dhcp-parameters-2
    {
        my $codes =
          $iana{registry}->{'bootp-dhcp-parameters-1'}->{registry}
          ->{'bootp-dhcp-parameters-2'}->{record};    # this is mildy nasty
        for my $k (
            sort { int $codes->{$a}->{value} <=> int $codes->{$b}->{value} }
            keys %$codes
          )
        {
            ok( $DHCP_MESSAGE{$k}, "\%DHCP_MESSAGE has $k" );
            ok(
                $DHCP_MESSAGE{$k} == int $codes->{$k}->{value},
                "...and $k is " . $codes->{$k}->{value}
            );
        }
    }

## NWIP CODES - bootp-dhcp-parameters-3
    {

        my @val = values %NWIP_CODES;

        my $codes =
          $iana{registry}->{'bootp-dhcp-parameters-1'}->{registry}
          ->{'bootp-dhcp-parameters-3'}->{record};    # this is mildy nasty

        for my $k (
            sort { int $codes->{$a}->{value} <=> int $codes->{$b}->{value} }
            grep { $_ !~ m/unassigned|private use/i }
            keys %$codes
          )
        {

            my $name = $k;
            $name =~ s/\n+//;
            my $value = int $codes->{$k}->{value};
            ok(
                ( grep { $value == $_ } @val ),
                "\%NWIP_CODES has $value aka $name"
            );

            #die unless (grep {$value == $_} @val);

        }
    }

## CCC CODES - bootp-dhcp-parameters-4
    {

        my @val = values %CCC_CODES;

        my $codes =
          $iana{registry}->{'bootp-dhcp-parameters-1'}->{registry}
          ->{'bootp-dhcp-parameters-4'}->{record};    # this is mildy nasty

        for my $k (
            sort { int $a->{value} <=> int $b->{value} }
            grep { $_->{description} !~ m/unassigned|private use/i } @$codes
          )
        {

            my $name = $k->{description};
            $name =~ s/\n+//;
            my $value = $k->{value};
            ok(
                ( grep { $value == $_ } @val ),
                "\%CCC_CODES has $value aka $name"
            );

            #die unless (grep {$value == $_} @val);

        }
    }

## GEOCONF CODES - bootp-dhcp-parameters-5
    {

        my @val = values %CCC_CODES;

        my $codes =
          $iana{registry}->{'bootp-dhcp-parameters-1'}->{registry}
          ->{'bootp-dhcp-parameters-5'}->{record};    # this is mildy nasty

        for my $k (
            sort { int $a->{value} <=> int $b->{value} }
            grep { $_->{description} !~ m/unassigned|private use/i } @$codes
          )
        {

            my $name = $k->{description};
            $name =~ s/\n+//;
            my $value = $k->{value};
            ok(
                ( grep { $value == $_ } @val ),
                "\%GEOCONF_CODES has $value aka $name"
            );

            #die unless (grep {$value == $_} @val);

        }
    }
## GEOCONF CODES - bootp-dhcp-parameters-6

    # im not quite sure what to do with geoconf

## CCC PacketCable mask bits. also not sure - bootp-dhcp-parameters-7

## DHCP RELAY SUB OPTIONS CODES - bootp-dhcp-parameters-8
    {

        my @val = values %RELAYAGENT_CODES;

        my $codes =
          $iana{registry}->{'bootp-dhcp-parameters-8'}
          ->{record};    # this is mildy nasty

        for my $k (
            sort { int $a->{value} <=> int $b->{value} }
            grep { $_->{description} !~ m/unassigned|private use|reserved/i }
            @$codes
          )
        {

            my $name = $k->{description};
            $name =~ s/\n+//;
            my $value = $k->{value};
            ok( ( grep { $value == $_ } @val ),
                "\%RELAYAGENT_CODES has $value aka $name" );

            #die unless (grep {$value == $_} @val);

        }
    }

## DHCP RELAY SUB OPTIONS CODES - suboptions are defined in - bootp-dhcp-parameters-9
## DHCP RELAY SUB OPTIONS CODES - suboptions are defined in - bootp-dhcp-parameters-10
    # neither of which i have any idea what to do with yet

}

1;