xref: /PHP-5.4/ext/standard/tests/network/ip.phpt (revision 2bc631fb)
1--TEST--
2ip2long() & long2ip() tests
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6?>
7--FILE--
8<?php
9
10$array = array(
11	"127.0.0.1",
12	"10.0.0.1",
13	"255.255.255.255",
14	"255.255.255.0",
15	"0.0.0.0",
16	"66.163.161.116",
17);
18
19foreach ($array as $ip) {
20	var_dump($long = ip2long($ip));
21	var_dump(long2ip($long));
22}
23
24var_dump(ip2long());
25var_dump(ip2long(""));
26var_dump(ip2long("777.777.777.777"));
27var_dump(ip2long("111.111.111.111"));
28var_dump(ip2long(array()));
29
30var_dump(long2ip());
31var_dump(long2ip(-110000));
32var_dump(long2ip(""));
33var_dump(long2ip(array()));
34
35echo "Done\n";
36?>
37--EXPECTF--
38int(2130706433)
39string(9) "127.0.0.1"
40int(167772161)
41string(8) "10.0.0.1"
42int(-1)
43string(15) "255.255.255.255"
44int(-256)
45string(13) "255.255.255.0"
46int(0)
47string(7) "0.0.0.0"
48int(1118019956)
49string(14) "66.163.161.116"
50
51Warning: ip2long() expects exactly 1 parameter, 0 given in %s on line %d
52NULL
53bool(false)
54bool(false)
55int(1869573999)
56
57Warning: ip2long() expects parameter 1 to be string, array given in %s on line %d
58NULL
59
60Warning: long2ip() expects exactly 1 parameter, 0 given in %s on line %d
61NULL
62string(13) "255.254.82.80"
63string(7) "0.0.0.0"
64
65Warning: long2ip() expects parameter 1 to be string, array given in %s on line %d
66NULL
67Done
68