Template/t/Template.t

filter: Statementstmt 92.3% 48 / 52 Branchbran 50.0% 8 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 84.0% 63 / 75 CC 2 SCAR 2.5
CC
2
Cov
82%
END
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Net/DNS/ToolKit/Utilities.pm ↑ Summary xs_include/dn_expand.inc »
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..8\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 #use diagnostics;
12 1 ▶use Net::DNS::ToolKit qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 get16
14 put16
15 getIPv4
16 inet_ntoa
17 inet_aton
18 get1char
19 parse_char
20 1 );
21 1 ▶use Net::DNS::Codes qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Net::DNS::ToolKit::RR::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 $loaded = 1;
25 1 print "ok 1\n";
26 ######################### End of black magic.
27  
28 # Insert your test code below (better if it prints "ok 13"
29 # (correspondingly "not ok 13") depending on the success of chunk 13
30 # of the test code):
31  
32 1 $test = 2;
33  
34 7 ▶sub ok {
Subroutine ok: called CC=1 SCAR=0.0
35 7 print "ok $test\n";
36 7 ++$test;
37 }
38  
39 ## This is what we must test
40  
41 # ($newoff,$name,$type,$class,$ttl,$rdlength,
42 # $rdata,...) = $get->XYZ(\$buffer,$offset);
43 #
44 # ($newoff,@dnptrs)=$put->XYZ(\$buffer,$offset,\@dnptrs,
45 # $name,$type,$class,$ttl,$rdlength,$rdata,...);
46 #
47 # $name,$TYPE,$CLASS,$TTL,$rdlength,$IPaddr)
48 # = $parse->XYZ($name,$type,$class,$ttl,$rdlength,
49 # $rdata,...);
50  
51 ## test 2 add stuff to buffer
52 1 my $buffer = '';
53 1 my @array = (5,4,3,2,1);
54  
55 1 my $module = 'Net::DNS::ToolKit::RR::Template';
56  
57 1 my $expoff = &NS_INADDRSZ + &NS_INT16SZ;
58 1 my $IPaddr = '172.16.54.32';
59 1 my $netaddr = inet_aton($IPaddr);
60 1 my ($rv,@retary) = $module->put(\$buffer,0,\@array,$netaddr);
61 1 ▶print "offset is: $rv, exp: $expoff\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $rv == $expoff 0 1 1
62 unless $rv == $expoff;
63 1 &ok;
64  
65 ## test 3 verify that array came back
66 1 ▶print "array is wrong size\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless @array == @retary 0 1 1
67 unless @array == @retary;
68 1 &ok;
69  
70 ## test 4 check that this is really the array we sent
71 1 foreach(0..$#array) {
72 5 ▶ next if $array[$_] == $retary[$_];
Branch: 1 branch
BranchTrueFalseTotal
if $array[$_] == $retary[$_] 5 0 5
73 0 print "array contents are different\nnot ";
74 0 last;
75 }
76 1 &ok;
77  
78 ## test 5 verify buffer contents the hard way
79 1 my @exp = (0,4,172,16,54,32);
80  
81 # 00 0000_0000 0x00 0 16 bit int
82 # 01 0000_0100 0x04 4 rdlength
83 # 02 1010_1100 0xAC 172
84 # 03 0001_0000 0x10 16 32 bit netaddr
85 # 04 0011_0110 0x36 54 6 172.16.54.32
86 # 05 0010_0000 0x20 32
87  
88 1 foreach(0..$expoff -1) {
89 6 my $char = get1char(\$buffer,$_);
90 # @_ = parse_char($char); printf "%02d %s %s %s %s\n",$_,$_[0],$_[1],$_[2],$_[3];
91 6 ▶ if ($char != $exp[$_]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char != $exp[$_]) 0 6 6
92 0 printf "exp: %02X, got: %02X\nnot ",$exp[$_],$char;
93 0 last;
94 }
95 }
96 1 &ok;
97  
98 ## test 6 get IPaddr back
99 1 ($rv, my $taddr) = $module->get(\$buffer,0);
100 1 my $Taddr = inet_ntoa($taddr);
101 1 ▶print "got: $Taddr, exp: $IPaddr\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $Taddr eq $IPaddr 0 1 1
102 unless $Taddr eq $IPaddr;
103 1 &ok;
104  
105 ## test 7 check offset returned
106 1 ▶print "offset got: $rv, exp: $expoff\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $rv == $expoff 0 1 1
107 unless $rv == $expoff;
108 1 &ok;
109  
110 ## test 8 check parse
111 1 my $prv = $module->parse($taddr);
112 1 ▶print "parse failed .. got: $prv, exp: $IPaddr\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $prv eq $IPaddr 0 1 1
113 unless $prv eq $IPaddr;
114 1 &ok
« blib/lib/Net/DNS/ToolKit/Utilities.pm ↑ Summary xs_include/dn_expand.inc »