File: hasbits.t

package info (click to toggle)
libnetaddr-ip-perl 4.079%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 1,580 kB
  • ctags: 251
  • sloc: perl: 1,417; cpp: 67; sh: 51; makefile: 9
file content (147 lines) | stat: -rw-r--r-- 2,014 bytes parent folder | download | duplicates (6)
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
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
$| = 1;
END {print "1..1\nnot ok 1\n" unless $test;}

use NetAddr::IP::Util qw(
	ipv6_aton
	ipv6_n2x
	hasbits
);

$test = 1;

sub ok {
  print "ok $test\n";
  ++$test;
}

my @num = qw	# input
(
	::
	8000::
	4000::
	2000::
	1000::
	800::
	400::
	200::
	100::
	80::
	40::
	20::
	10::
	1::
	0:8000::
	0:4000::
	0:2000::
	0:1000::
	0:800::
	0:400::
	0:200::
	0:100::
	0:80::
	0:40::
	0:20::
	0:10::
	0:1::
	0:0:8000::
	0:0:4000::
	0:0:2000::
	0:0:1000::
	0:0:800::
	0:0:400::
	0:0:200::
	0:0:100::
	0:0:80::
	0:0:40::
	0:0:20::
	0:0:10::
	0:0:1::
	0:0:0:8000::
	0:0:0:4000::
	0:0:0:2000::
	0:0:0:1000::
	0:0:0:800::
	0:0:0:400::
	0:0:0:200::
	0:0:0:100::
	0:0:0:80::
	0:0:0:40::
	0:0:0:20::
	0:0:0:10::
	0:0:0:1::
	::8000:0:0:0
	::4000:0:0:0
	::2000:0:0:0
	::1000:0:0:0
	::800:0:0:0
	::400:0:0:0
	::200:0:0:0
	::100:0:0:0
	::80:0:0:0
	::40:0:0:0
	::20:0:0:0
	::10:0:0:0
	::1:0:0:0
	::8000:0:0
	::4000:0:0
	::2000:0:0
	::1000:0:0
	::800:0:0
	::400:0:0
	::200:0:0
	::100:0:0
	::80:0:0
	::40:0:0
	::20:0:0
	::10:0:0
	::1:0:0
	::8000:0
	::4000:0
	::2000:0
	::1000:0
	::800:0
	::400:0
	::200:0
	::100:0
	::80:0
	::40:0
	::20:0
	::10:0
	::1:0
	::8000
	::4000
	::2000
	::1000
	::800
	::400
	::200
	::100
	::80
	::40
	::20
	::10
	::1
	::8000:0:0:0:0
	::8000:0:0:0:0:0
	::8000:0:0:0:0:0:0
	8000:0:0:0:0:0:0:0
);
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
print '1..',(scalar @num), "\n";

foreach (@num) {
  my $bstr = ipv6_aton($_);
  my $rv = hasbits($bstr);
  my $exp = ($_ eq '::') ? 0:1;
  print "got: $rv, exp: $exp for ", ipv6_n2x($bstr), "\nnot "
	 unless $rv eq $exp;
  &ok;
}