Lite/Util/t/bin.t

filter: Statementstmt 95.1% 39 / 41 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 90.0% 54 / 60 CC 4 SCAR 5.7
CC
4
Cov
90%
dotest
3.0
END
2.1
numnum
2.0
CRAP 1.8
« Lite/t/v6-old-base.t ↑ Summary Lite/Util/t/badd.t »
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..25\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
BranchTrueFalseTotal
unless $loaded 0 1 1
10  
11 1 ▶use NetAddr::IP::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 ipv6_aton
13 bin2bcd
14 bin2bcdn
15 bcdn2txt
16 1 );
17  
18 1 $loaded = 1;
19 1 print "ok 1\n";
20 ######################### End of black magic.
21  
22 # Insert your test code below (better if it prints "ok 13"
23 # (correspondingly "not ok 13") depending on the success of chunk 13
24 # of the test code):
25  
26 1 $test = 2;
27  
28 24 ▶sub ok {
Subroutine ok: called CC=1 SCAR=0.0
29 24 print "ok $test\n";
30 24 ++$test;
31 }
32  
33 # input: array ref, value ref, number ref
34 #
35 8 ▶sub val {
Subroutine val: called CC=1 SCAR=0.0
36 8 my $bcd = shift;
37 8 my $rv = unpack("H*",$bcd);
38 8 $rv =~ s/^0+(\d)/$1/g;
39 8 return $rv;
40 }
41  
42 0 ▶sub numnum {
Subroutine numnum: not called CC=1 SCAR=6.9
43 0 my($ar,$i) = @_;
44 0 return sprintf("%.0f",$ar->[$i +1]);
45 }
46  
47 16 ▶sub numstr {
Subroutine numstr: called CC=1 SCAR=0.0
48 16 my($ar,$i) = @_;
49 16 return $ar->[$i+1];
50 }
51  
52 2 ▶sub dotest {
Subroutine dotest: called CC=3 SCAR=11.0
53 2 my($ar,$vr,$nr) = @_;
54 2 ▶ for(my $i=0;$i<@$ar;$i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$ar) 16 2 18
55 16 my $bstr = ipv6_aton($ar->[$i]);
56 16 my $bcd = bin2bcdn($bstr);
57 16 my $val = $vr->($bcd);
58 16 my $exp = $nr->($ar,$i);
59 16 print "\t\t$val\n";
60 16 ▶ print "got: $val\nexp: $exp\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $val eq $exp 0 16 16
61 unless $val eq $exp;
62 16 &ok;
63 }
64 }
65  
66 # setup only, can't depend on float to do it right on all systems
67 #my @num1 = # input expected
68 #(
69 # '::' => 0,
70 # '::8000:0' => 2**(15+16),
71 # '::8000:0:0' => 2**(15+(16*2)),
72 # '::8000:0:0:0' => 2**(15+(16*3)),
73 # '::8000:0:0:0:0' => 2**(15+(16*4)),
74 # '::8000:0:0:0:0:0' => 2**(15+(16*5)),
75 # '::8000:0:0:0:0:0:0' => 2**(15+(16*6)),
76 # '8000:0:0:0:0:0:0:0' => 2**(15+(16*7)),
77 #);
78  
79 1 my @num2 = qw(
80 :: 0
81 ::8000:0 2147483648
82 ::8000:0:0 140737488355328
83 ::8000:0:0:0 9223372036854775808
84 ::8000:0:0:0:0 604462909807314587353088
85 ::8000:0:0:0:0:0 39614081257132168796771975168
86 ::8000:0:0:0:0:0:0 2596148429267413814265248164610048
87 8000:0:0:0:0:0:0:0 170141183460469231731687303715884105728
88 );
89  
90 ## tests 2 - 9 bin2bcdn numeric unpack
91 #dotest(\@num1,\&val,\&numnum);
92  
93 ## tests 10 - 17 bin2bcdn string unpack TEST 2 - 9
94 1 dotest(\@num2,\&val,\&numstr);
95  
96 ## tests 18 - 25 bin2bcdn numeric bcdn2txt
97 #dotest(\@num1,\&bcdn2txt,\&numnum);
98  
99 ## tests 26 - 33 bin2bcdn string bcdn2txt TEST 10 - 17
100 1 dotest(\@num2,\&bcdn2txt,\&numstr);
101  
102 ## tests 34 - 41 bin2bcd TEST 18 - 25
103 1 ▶for(my $i=0;$i<@num2;$i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @num2) 8 1 9
104 8 my $bstr = ipv6_aton($num2[$i]);
105 8 my $bcd = bin2bcd($bstr);
106 8 my $exp = $num2[$i +1];
107 8 print "\t\t$bcd\n";
108 8 ▶ print "got: $bcd\nexp: $exp\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $bcd eq $exp 0 8 8
109 unless $bcd eq $exp;
110 8 &ok;
111 }
« Lite/t/v6-old-base.t ↑ Summary Lite/Util/t/badd.t »