| 1 | # Before `make install' is performed this script should be runnable with | ||||||||||||||||||||||||||||
| 2 | # `make test'. After `make install' it should work as `perl test.pl' | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | ######################### We start with some black magic to print on failure. | ||||||||||||||||||||||||||||
| 5 | # Change 1..1 below to 1..last_test_to_print . | ||||||||||||||||||||||||||||
| 6 | # (It may become useful if the test is moved to ./t subdirectory.) | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | BEGIN { $| = 1; print "1..32\n"; } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | END {print "not ok 1\n" unless $loaded;} | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | #use diagnostics; | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use NetAddr::IP::InetBase qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | :upper | ||||||||||||||||||||||||||||
| 14 | :ipv6 | ||||||||||||||||||||||||||||
| 15 | AF_INET | ||||||||||||||||||||||||||||
| 16 | AF_INET6 | ||||||||||||||||||||||||||||
| 17 | 1 | ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | $loaded = 1; | |||||||||||||||||||||||||||
| 20 | 1 | print "ok 1\n"; | |||||||||||||||||||||||||||
| 21 | ######################### End of black magic. | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # Insert your test code below (better if it prints "ok 13" | ||||||||||||||||||||||||||||
| 24 | # (correspondingly "not ok 13") depending on the success of chunk 13 | ||||||||||||||||||||||||||||
| 25 | # of the test code): | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | $test = 2; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 31 | ▶ | sub ok { | ||||||||||||||||||||||||||
|
Subroutine
ok: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 31 | print "ok $test\n"; | |||||||||||||||||||||||||||
| 31 | 31 | ++$test; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | ## test 2 - 13 add stuff to buffer | ||||||||||||||||||||||||||||
| 35 | 1 | my @num = # addr | |||||||||||||||||||||||||||
| 36 | qw( | ||||||||||||||||||||||||||||
| 37 | 0.0.0.0 | ||||||||||||||||||||||||||||
| 38 | 255.255.255.255 | ||||||||||||||||||||||||||||
| 39 | 1.2.3.4 | ||||||||||||||||||||||||||||
| 40 | 10.253.230.9 | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | foreach (@num) { | |||||||||||||||||||||||||||
| 44 | 4 | my @digs = split(/\./,$_); | |||||||||||||||||||||||||||
| 45 | 4 | my $pkd = pack('C4',@digs); | |||||||||||||||||||||||||||
| 46 | 4 | my $naddr = inet_pton(AF_INET(),$_); | |||||||||||||||||||||||||||
| 47 | 4 | my $addr = join('.',unpack('C4',$naddr)); | |||||||||||||||||||||||||||
| 48 | 4 | my $num = inet_ntop(AF_INET(),$pkd); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | ▶ | print "bits do not match\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | unless $naddr eq $pkd; | ||||||||||||||||||||||||||||
| 52 | 4 | &ok; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | print "inet_pton: $addr, exp: $_\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | unless $addr eq $_; | ||||||||||||||||||||||||||||
| 56 | 4 | &ok; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 4 | ▶ | print "inet_ntop: $num, exp: $_\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | unless $num eq $_; | ||||||||||||||||||||||||||||
| 60 | 4 | &ok; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | ## test 14 - 31 | ||||||||||||||||||||||||||||
| 64 | @num = # in exphex | ||||||||||||||||||||||||||||
| 65 | 1 | qw( | |||||||||||||||||||||||||||
| 66 | :: :: | ||||||||||||||||||||||||||||
| 67 | 43:: 43:: | ||||||||||||||||||||||||||||
| 68 | ::21 ::21 | ||||||||||||||||||||||||||||
| 69 | ::1:2:3:4:5:6:7 0:1:2:3:4:5:6:7 | ||||||||||||||||||||||||||||
| 70 | 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:0 | ||||||||||||||||||||||||||||
| 71 | 1::8 1::8 | ||||||||||||||||||||||||||||
| 72 | FF00::FFFF ff00::ffff | ||||||||||||||||||||||||||||
| 73 | FFFF::FFFF:FFFF ffff::ffff:ffff | ||||||||||||||||||||||||||||
| 74 | A1B2:C3D4:E5D6:F7E8:08F9:190A:1.2.3.4 a1b2:c3d4:e5d6:f7e8:8f9:190a:102:304 | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | for (my $i=0;$i<@num;$i+=2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 9 | my $bits = inet_pton(AF_INET6(),$num[$i]); | |||||||||||||||||||||||||||
| 79 | 9 | my $len = length($bits); | |||||||||||||||||||||||||||
| 80 | 9 | ▶ | print "bad len = $len, exp: 16\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | unless $len == 16; # 16 bytes x 8 bits | ||||||||||||||||||||||||||||
| 82 | 9 | &ok; | |||||||||||||||||||||||||||
| 83 | 9 | my $ipv6x = inet_ntop(AF_INET6(),$bits); | |||||||||||||||||||||||||||
| 84 | 9 | ▶ | print "got: $ipv6x\nexp: $num[$i +1]\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | unless $ipv6x eq $num[$i +1]; | ||||||||||||||||||||||||||||
| 86 | 9 | &ok; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | ## test 32 check bad length ntop | ||||||||||||||||||||||||||||
| 90 | 1 | my $try = '1234'; | |||||||||||||||||||||||||||
| 91 | 1 | my $notempty = eval { | |||||||||||||||||||||||||||
| 92 | 1 | inet_ntop(AF_INET6(),$try); | |||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||
| 94 | 1 | ▶ | print "failed bad argument length test for inet_ntop\nnot " | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ and $@ =~ /Bad arg/
MC/DC0%0/2
$@ and $@ =~ /Bad arg/
$@
$@ =~ /Bad arg/
Truth table33%1/3
A and B
A= $@B= $@ =~ /Bad arg/
| |||||||||||||||||||||||||||||
| 95 | unless $@ && $@ =~ /Bad arg/; | ||||||||||||||||||||||||||||
| 96 | 1 | &ok; | |||||||||||||||||||||||||||