root/psad/tags/psad-2.1.2/Net-IPv4Addr/test.pl

Revision 640, 2.6 kB (checked in by mbr, 6 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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 use strict;
5 use Test;
6
7 # Change 1..1 below to 1..last_test_to_print .
8 # (It may become useful if the test is moved to ./t subdirectory.)
9
10 BEGIN { plan tests => 37 }
11 use Net::IPv4Addr qw(/^ipv4/);
12
13
14 # ipv4_parse
15 ok( scalar ipv4_parse( "127.0.0.1" ), "127.0.0.1" );
16 ok( scalar ipv4_parse( "192.168.100.1 / 24" ), "192.168.100.1/24" );
17 ok( scalar ipv4_parse( "130.10.2.10", "255.255.255.0"), "130.10.2.10/24");
18 ok( scalar ipv4_parse( "130.10.2.10", "255.255.255.240"), "130.10.2.10/28");
19 ok( scalar ipv4_parse( "130.10.2.10/28"), "130.10.2.10/28");
20
21 # ipv4_dftl_netmask
22 ok( ipv4_dflt_netmask( "127.0.0.1" ), "255.0.0.0" );
23 ok( ipv4_dflt_netmask( "172.0.0.01" ), "255.255.0.0" );
24 ok( ipv4_dflt_netmask( "198.0.0.20" ), "255.255.255.0" );
25
26 # ipv4_network
27 ok( scalar ipv4_network( "127.0.0.1"), "127.0.0.0/8" );
28 ok( scalar ipv4_network( "192.168.100.10" ), "192.168.100.0/24" );
29 ok( scalar ipv4_network( "192.168.100.100/255.255.255.192"), "192.168.100.64/26" );
30
31 # ipv4_broadcast
32 ok( ipv4_broadcast( "127.0.0.1"), "127.255.255.255" );
33 ok( ipv4_broadcast( "192.168.100.10/24" ), "192.168.100.255" );
34 ok( ipv4_broadcast( "192.168.100.100/255.255.255.192"), "192.168.100.127" );
35
36 # ipv4_in_network
37 ok( ipv4_in_network( "127.0.0.1", "127.0.0.1" ) );
38 ok( not ipv4_in_network( "127.0.0.0/8", "192.168.30.1" ));
39 ok( not ipv4_in_network( "192.168.100.10", "192.168.100.30"));
40 ok( ipv4_in_network( "192.168.100.10/24", "192.168.100.255"));
41 ok( ipv4_in_network( "192.168.100.0/24", "192.168.100.0"));
42 ok( not ipv4_in_network( "192.16.100.63/26", "192.168.100.65"));
43 ok( ipv4_in_network( "192.168.100.0/24", "0.0.0.0" ) );
44 ok( ipv4_in_network( "192.168.100.0/24", "255.255.255.255" ) );
45 ok( ipv4_in_network( "0.0.0.0", "192.168.1.1" ) );
46 ok( ipv4_in_network( "255.255.255.255", "192.176.1.8" ) );
47 ok( ipv4_in_network( "192.168.199.0/30", "192.168.199.1" ) );
48 ok( ipv4_in_network( "212.117.64.0/19", "212.117.65.42/28" ) );
49 ok( !ipv4_in_network( "21.10.0.4/24", "0.0.0.0/0" ) );
50
51 # ipv4_cidr2msk
52 ok( ipv4_cidr2msk( 24 ), "255.255.255.0" );
53 ok( ipv4_cidr2msk( 16 ), "255.255.0.0" );
54 ok( ipv4_cidr2msk( 8  ), "255.0.0.0" );
55 ok( ipv4_cidr2msk( 26 ), "255.255.255.192" );
56 ok( ipv4_cidr2msk( 0 ), "0.0.0.0" );
57 ok( ipv4_cidr2msk( 32 ), "255.255.255.255" );
58
59 # ipv4_msk2cidr
60 ok( ipv4_msk2cidr( "255.255.255.0" ),  24);
61 ok( ipv4_msk2cidr( "255.255.0.0" ), 16 );
62 ok( ipv4_msk2cidr( "255.0.0.0" ), 8 );
63 ok( ipv4_msk2cidr( "255.255.255.192" ), 26 );
64 ok( ipv4_msk2cidr( "0.0.0.0" ), 0 );
65 ok( ipv4_msk2cidr( "255.255.255.255" ), 32 );
66
67
68
Note: See TracBrowser for help on using the browser.