3 no warnings qw(redefine once);
8 use Test::More tests => 39;
15 require './l7directord';
19 open *STDOUT, '>', '/dev/null';
21 open *STDERR, '>', '/dev/null';
23 #...............................................
27 my @got = command_wrapper();
28 is_deeply \@got, [$?, ''], 'command_wrapper - args is undef';
31 my @got = command_wrapper('ls');
32 is $got[0], 0, 'command_wrapper - ls is ok';
33 like $got[1], qr/Makefile.*l7directord.*t/s, 'command_wrapper - ls result';
36 my @got = command_wrapper('env LANG=C ls /proc/100000 2>&1');
37 if ( $Config{'use64bitint'} ) {
38 is_deeply \@got, [512, "ls: /proc/100000: No such file or directory\n"], 'command_wrapper - ls /proc/100000(string) is ok';
41 is_deeply \@got, [256, "ls: /proc/100000: No such file or directory\n"], 'command_wrapper - ls /proc/100000(string) is ok';
45 my @got = command_wrapper('/etc');
46 is_deeply \@got, [-1, undef], 'command_wrapper - no such command';
50 my $got = system_wrapper();
51 is $got, 65280, 'system_wrapper - args is undef';
54 my $got = system_wrapper('ls');
55 is $got, 0, 'system_wrapper - ls is ok';
58 my $got = system_wrapper('ls /proc/100000');
59 if ( $Config{'use64bitint'} ) {
60 is $got, 512, 'system_wrapper - ls /proc/100000(string) is ok';
63 is $got, 256, 'system_wrapper - ls /proc/100000(string) is ok';
67 my $got = system_wrapper('ls', '/proc/100000');
68 if ( $Config{'use64bitint'} ) {
69 is $got, 512, 'system_wrapper - ls /proc/100000(array) is ok';
72 is $got, 256, 'system_wrapper - ls /proc/100000(array) is ok';
76 my $got = system_wrapper('/etc');
77 is $got, -1, 'system_wrapper - no such command';
81 my $got = exec_wrapper();
82 is $got, 0, 'exec_wrapper - args is undef';
85 my $got = exec_wrapper('/etc');
86 is $got, 0, 'exec_wrapper - no such command';
90 my $got = ld_gethostbyname();
91 is $got, undef, 'ld_gethostbyname - name is undef';
94 my $got = ld_gethostbyname('localhost');
95 is $got, '127.0.0.1', 'ld_gethostbyname - resolve localhost';
98 my $got = ld_gethostbyname('0.0.0.0');
99 is $got, '0.0.0.0', 'ld_gethostbyname - already resolved';
102 my $got = ld_gethostbyname('any host name');
103 is $got, undef, 'ld_gethostbyname - cannot resolve';
108 my $protocol = 'tcp';
109 my $got = ld_getservbyname($name, $protocol);
110 is $got, undef, 'ld_getservbyname - name is undef';
114 my $protocol = undef;
115 my $got = ld_getservbyname($name, $protocol);
116 is $got, 80, 'ld_getservbyname - protocol is undef';
120 my $protocol = 'tcp';
121 my $got = ld_getservbyname($name, $protocol);
122 is $got, 0, 'ld_getservbyname - name is 0(min)';
126 my $protocol = 'tcp';
127 my $got = ld_getservbyname($name, $protocol);
128 is $got, 65535, 'ld_getservbyname - name is 65535(max)';
132 my $protocol = 'tcp';
133 my $got = ld_getservbyname($name, $protocol);
134 is $got, undef, 'ld_getservbyname - name is 65536(error)';
138 my $protocol = 'tcp';
139 my $got = ld_getservbyname($name, $protocol);
140 is $got, undef, 'ld_getservbyname - no such service name';
144 my $protocol = 'foo';
145 my $got = ld_getservbyname($name, $protocol);
146 is $got, undef, 'ld_getservbyname - no such protocol name';
150 my $protocol = 'tcp';
151 my $got = ld_getservbyname($name, $protocol);
152 is $got, 80, 'ld_getservbyname - resolve www tcp';
156 my $protocol = 'udp';
157 my $got = ld_getservbyname($name, $protocol);
158 is $got, 80, 'ld_getservbyname - resolve www udp';
160 # - ld_getservhostbyname
162 my $hostserv = '127.0.0.1:80';
163 my $protocol = 'tcp';
164 my $got = ld_gethostservbyname($hostserv, $protocol);
165 is_deeply $got, { ip => '127.0.0.1', port => 80 }, 'ld_getservhostbyname - resolve localhost:www tcp';
168 my $hostserv = 'localhost:www';
169 my $protocol = 'tcp';
170 my $got = ld_gethostservbyname($hostserv, $protocol);
171 is_deeply $got, { ip => '127.0.0.1', port => 80 }, 'ld_getservhostbyname - resolve localhost:www tcp';
174 my $hostserv = 'localhost:www';
175 my $protocol = 'udp';
176 my $got = ld_gethostservbyname($hostserv, $protocol);
177 is_deeply $got, { ip => '127.0.0.1', port => 80 }, 'ld_getservhostbyname - resolve localhost:www udp';
180 my $hostserv = 'localhost:www';
181 my $protocol = undef;
182 my $got = ld_gethostservbyname($hostserv, $protocol);
183 is_deeply $got, { ip => '127.0.0.1', port => 80 }, 'ld_getservhostbyname - protocol is undef';
186 my $hostserv = 'localhost:www';
187 my $protocol = 'foo';
188 my $got = ld_gethostservbyname($hostserv, $protocol);
189 is $got, undef, 'ld_getservhostbyname - no such protocol';
192 my $hostserv = 'foo-bar-host:www';
193 my $protocol = 'tcp';
194 my $got = ld_gethostservbyname($hostserv, $protocol);
195 is $got, undef, 'ld_getservhostbyname - invalid host address';
198 my $hostserv = 'localhost:foobar';
199 my $protocol = 'tcp';
200 my $got = ld_gethostservbyname($hostserv, $protocol);
201 is $got, undef, 'ld_getservhostbyname - invalid service name';
204 my $hostserv = undef;
205 my $protocol = 'tcp';
206 my $got = ld_gethostservbyname($hostserv, $protocol);
207 is $got, undef, 'ld_getservhostbyname - hostserv is undef';
210 my $hostserv = 'localhost';
211 my $protocol = 'tcp';
212 my $got = ld_gethostservbyname($hostserv, $protocol);
213 is $got, undef, 'ld_getservhostbyname - hostserv is invalid format';
215 ##########################################################
217 # - ld_getservhostbyname
219 my $hostserv = '[2001::11]:80';
220 my $protocol = 'tcp';
221 my $got = ld_gethostservbyname($hostserv, $protocol);
222 is_deeply $got, { ip => '2001::11', port => 80 }, 'ld_getservhostbyname - [2001::11]:80 tcp';
225 my $hostserv = '[2001::11]:www';
226 my $protocol = 'udp';
227 my $got = ld_gethostservbyname($hostserv, $protocol);
228 is_deeply $got, { ip => '2001::11', port => 80 }, 'ld_getservhostbyname - resolve localhost:www udp';
231 my $hostserv = 'um08eth1ipv6:www';
232 my $protocol = undef;
233 my $got = ld_gethostservbyname($hostserv, $protocol);
234 is_deeply $got, { ip => '2001::11', port => 80 }, 'ld_getservhostbyname - protocol is undef';
237 my $hostserv = '10.144.169.222:www';
238 my $protocol = 'foo';
239 my $got = ld_gethostservbyname($hostserv, $protocol);
240 is $got, undef, 'ld_getservhostbyname - no such protocol';
243 my $hostserv = 'localhost6:80';
244 my $protocol = 'tcp';
245 my $got = ld_gethostservbyname($hostserv, $protocol);
246 is_deeply $got, { ip => '::1' , port => 80 }, 'ld_getservhostbyname - invalid host address';
249 #...............................................
256 *ld_log = \&__ld_log;