Lite/t/v4-aton.t

filter: Statementstmt 100% 23 / 23 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 88.5% 31 / 35 CC 2 SCAR 3.8
CC
2
Cov
87%
l_inet_aton
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Lite/Util/t/inet_4map6.t ↑ Summary Lite/t/pathological.t »
1 1 ▶use Test::More tests => 19;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 1 my @addr = (
4 [ 'localhost', '127.0.0.1' ],
5 [ 'broadcast', '255.255.255.255' ],
6 [ '254.254.0.1', '254.254.0.1' ],
7 [ 'default', '0.0.0.0' ],
8 [ '10.0.0.1', '10.0.0.1' ],
9  
10 );
11 1 my %addr = (
12 localhost => pack('N',0x7f000001),
13 broadcast => pack('N',0xffffffff),
14 '254.254.0.1' => pack('N',0xfefe0001),
15 default => pack('N',0),
16 '10.0.0.1' => pack('N',0x0a000001),
17 '127.0.0.1' => pack('N',0x7f000001),
18 '255.255.255.255' => pack('N',0xffffffff),
19 '0.0.0.0' => pack('N',0),
20 );
21  
22 # local inet_aton, don't use perl's Socket
23  
24 15 ▶sub l_inet_aton {
Subroutine l_inet_aton: called CC=2 SCAR=7.6
25 15 ▶ my $rv = (exists $addr{$_[0]}) ? $addr{$_[0]} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $addr{$_[0]} ? : 15 0 15
26 }
27  
28  
29 # Verify that Accept_Binary_IP works...
30  
31 1 my $x;
32  
33 SKIP:
34 {
35 1 ▶ skip "Failed to load NetAddr::IP::Lite", 17
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless &use_ok("NetAddr::IP::Lite") 0 1 1
36 unless use_ok('NetAddr::IP::Lite');
37  
38 1 ▶ ok(! defined NetAddr::IP::Lite->new("\1\1\1\1"),
Branch: 1 branch
BranchTrueFalseTotal
$x ? : 0 1 1
39 "binary unrecognized by default ". ($x ? $x->addr :''));
40  
41 # This mimicks the actual use with :aton
42 1 NetAddr::IP::Lite::import(':aton');
43  
44 1 ok(defined ($x = NetAddr::IP::Lite->new("\1\1\1\1")),
45 "...but can be recognized ". $x->addr);
46  
47 1 ▶ ok(!defined ($x = NetAddr::IP::Lite->new('bad rfc-952 characters')),
Branch: 1 branch
BranchTrueFalseTotal
$x ? : 0 1 1
48 "bad rfc-952 characters ". ($x ? $x->addr :''));
49  
50 is(NetAddr::IP::Lite->new($_->[0])->aton, l_inet_aton($_->[1]), "->aton($_->[0])")
51 1 for @addr;
52  
53 ok(defined NetAddr::IP::Lite->new(l_inet_aton($_->[1])), "->new aton($_->[1])")
54 1 for @addr;
55  
56 is(NetAddr::IP::Lite->new(l_inet_aton($_->[1]))->addr, $_->[1],
57 "->new aton($_->[1])")
58 1 for @addr;
59 };
« Lite/Util/t/inet_4map6.t ↑ Summary Lite/t/pathological.t »