* Test cases for some includes/ stuff
[lhc/web/wiklou.git] / t / inc / IP.t
1 #!/usr/bin/env php
2 <?php
3
4 require 'Test.php';
5
6 plan( 'no_plan' );
7
8 require_ok( 'includes/IP.php' );
9
10 # some of this test data was taken from Data::Validate::IP
11
12 #
13 # isValid()
14 #
15
16 foreach ( range( 0, 255 ) as $i ) {
17 $a = sprintf( "%03d", $i );
18 $b = sprintf( "%02d", $i );
19 $c = sprintf( "%01d", $i );
20 foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
21 $ip = "$f.$f.$f.$f";
22 ok( IP::isValid( $ip ), "$ip is a valid IPv4 address" );
23 }
24 }
25
26 $valid = array( '216.17.184.1', '0.0.0.0', '000.000.000.000' );
27
28 foreach ( $valid as $v ) {
29 ok( IP::isValid( $v ), "$v is a valid IPv4 address" );
30 }
31
32 $invalid = array(
33 'www.xn--var-xla.net',
34 '216.17.184.G',
35 '216.17.184.1.',
36 '216.17.184',
37 '216.17.184.',
38 '256.17.184.1'
39 );
40
41 foreach ( $invalid as $i ) {
42 ok( ! IP::isValid( $i ), "$i is an invalid IPv4 address" );
43 }
44
45 #
46 # isPublic()
47 #
48
49 $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
50
51 foreach ( $private as $p ) {
52 ok( ! IP::isPublic( $p ), "$p is not a public IP address" );
53 }
54
55 #is ('127.0.0.1', is_loopback_ipv4('127.0.0.1'), 'is_loopback_ipv4 127.0.0.1');
56 #is ('192.0.2.9', is_testnet_ipv4('192.0.2.9'), 'is_testnet_ipv4 192.0.2.9');
57 #is ('216.17.184.1', is_public_ipv4('216.17.184.1'), 'is_public_ipv4 216.17.184.1');
58 #isnt ('192.168.0.1', is_public_ipv4('192.168.0.1'), 'is_public_ipv4 192.168.0.1');
59 #
60 ?>