Integrate mainline (mostly) utf8.c does not compile.
[p5sagit/p5-mst-13.2.git] / lib / Net / t / config.t
CommitLineData
c8570720 1#!./perl -w
2
3BEGIN {
4 if ($ENV{PERL_CORE}) {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 }
1a8dcddb 8 if (!eval "require Socket") {
9 print "1..0 # no Socket\n"; exit 0;
10 }
cd556f37 11 undef *{Socket::inet_aton};
12 undef *{Socket::inet_ntoa};
8b14f033 13 if (ord('A') == 193 && !eval "require Convert::EBCDIC") {
14 print "1..0 # EBCDIC but no Convert::EBCDIC\n"; exit 0;
15 }
0d375cdb 16 $INC{'Socket.pm'} = 1;
c8570720 17}
18
0d375cdb 19package Socket;
20
21sub import {
22 my $pkg = caller();
23 no strict 'refs';
24 *{ $pkg . '::inet_aton' } = \&inet_aton;
25 *{ $pkg . '::inet_ntoa' } = \&inet_ntoa;
26}
27
28my $fail = 0;
29my %names;
30
31sub set_fail {
32 $fail = shift;
33}
34
35sub inet_aton {
36 return if $fail;
37 my $num = unpack('N', pack('C*', split(/\./, $_[0])));
38 $names{$num} = $_[0];
39 return $num;
40}
41
42sub inet_ntoa {
43 return if $fail;
44 return $names{$_[0]};
45}
46
47package main;
48
49
c8570720 50(my $libnet_t = __FILE__) =~ s/config.t/libnet_t.pl/;
51require $libnet_t;
52
53print "1..10\n";
54
55use Net::Config;
56ok( exists $INC{'Net/Config.pm'}, 'Net::Config should have been used' );
57ok( keys %NetConfig, '%NetConfig should be imported' );
58
0d375cdb 59Socket::set_fail(1);
c8570720 60undef $NetConfig{'ftp_firewall'};
61is( Net::Config->requires_firewall(), 0,
62 'requires_firewall() should return 0 without ftp_firewall defined' );
63
64$NetConfig{'ftp_firewall'} = 1;
0d375cdb 65is( Net::Config->requires_firewall('a.host.not.there'), -1,
c8570720 66 '... should return -1 without a valid hostname' );
67
0d375cdb 68Socket::set_fail(0);
c8570720 69delete $NetConfig{'local_netmask'};
70is( Net::Config->requires_firewall('127.0.0.1'), 0,
71 '... should return 0 without local_netmask defined' );
72
73$NetConfig{'local_netmask'} = '127.0.0.1/24';
74is( Net::Config->requires_firewall('127.0.0.1'), 0,
75 '... should return false if host is within netmask' );
76is( Net::Config->requires_firewall('192.168.10.0'), 1,
77 '... should return true if host is outside netmask' );
78
79# now try more netmasks
80$NetConfig{'local_netmask'} = [ '127.0.0.1/24', '10.0.0.0/8' ];
81is( Net::Config->requires_firewall('10.10.255.254'), 0,
82 '... should find success with mutiple local netmasks' );
83is( Net::Config->requires_firewall('192.168.10.0'), 1,
84 '... should handle failure with multiple local netmasks' );
85
86is( \&Net::Config::is_external, \&Net::Config::requires_firewall,
87 'is_external() should be an alias for requires_firewall()' );