aboutsummaryrefslogtreecommitdiffstats
path: root/tests/network
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2011-01-03 00:24:55 +0100
committerIgor Wiedler <igor@wiedler.ch>2011-01-03 00:24:55 +0100
commitda4617b14b11ade6f664b8c1ab94e3aeb5b7428d (patch)
treee22342e6ff9ff74b6a1d3286b31985ca25fbc1e3 /tests/network
parent979158f0a2e1ab88685f608e8756ff40248b86cf (diff)
parent3c713b5e7d883d7414538de0557c68195cd73018 (diff)
downloadforums-da4617b14b11ade6f664b8c1ab94e3aeb5b7428d.tar
forums-da4617b14b11ade6f664b8c1ab94e3aeb5b7428d.tar.gz
forums-da4617b14b11ade6f664b8c1ab94e3aeb5b7428d.tar.bz2
forums-da4617b14b11ade6f664b8c1ab94e3aeb5b7428d.tar.xz
forums-da4617b14b11ade6f664b8c1ab94e3aeb5b7428d.zip
Merge branch 'ticket/bantu/9746' into develop
Diffstat (limited to 'tests/network')
-rw-r--r--tests/network/all_tests.php4
-rw-r--r--tests/network/inet_ntop_pton.php55
-rw-r--r--tests/network/ip_normalise.php65
3 files changed, 124 insertions, 0 deletions
diff --git a/tests/network/all_tests.php b/tests/network/all_tests.php
index b500647f81..fd36009f4c 100644
--- a/tests/network/all_tests.php
+++ b/tests/network/all_tests.php
@@ -16,6 +16,8 @@ require_once 'test_framework/framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'network/checkdnsrr.php';
+require_once 'network/inet_ntop_pton.php';
+require_once 'network/ip_normalise.php';
class phpbb_network_all_tests
{
@@ -29,6 +31,8 @@ class phpbb_network_all_tests
$suite = new PHPUnit_Framework_TestSuite('phpBB Network Functions');
$suite->addTestSuite('phpbb_network_checkdnsrr_test');
+ $suite->addTestSuite('phpbb_network_inet_ntop_pton_test');
+ $suite->addTestSuite('phpbb_network_ip_normalise_test');
return $suite;
}
diff --git a/tests/network/inet_ntop_pton.php b/tests/network/inet_ntop_pton.php
new file mode 100644
index 0000000000..4cea6cfa3a
--- /dev/null
+++ b/tests/network/inet_ntop_pton.php
@@ -0,0 +1,55 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once 'test_framework/framework.php';
+require_once '../phpBB/includes/functions.php';
+
+class phpbb_network_inet_ntop_pton_test extends phpbb_test_case
+{
+ public function data_provider()
+ {
+ return array(
+ array('127.0.0.1', '7f000001'),
+ array('192.232.131.223', 'c0e883df'),
+ array('13.1.68.3', '0d014403'),
+ array('129.144.52.38', '81903426'),
+
+ array('2001:280:0:10::5', '20010280000000100000000000000005'),
+ array('fe80::200:4cff:fefe:172f', 'fe8000000000000002004cfffefe172f'),
+
+ array('::', '00000000000000000000000000000000'),
+ array('::1', '00000000000000000000000000000001'),
+ array('1::', '00010000000000000000000000000000'),
+
+ array('1:1:0:0:1::', '00010001000000000001000000000000'),
+
+ array('0:2:3:4:5:6:7:8', '00000002000300040005000600070008'),
+ array('1:2:0:4:5:6:7:8', '00010002000000040005000600070008'),
+ array('1:2:3:4:5:6:7:0', '00010002000300040005000600070000'),
+
+ array('2001:0:0:1::1', '20010000000000010000000000000001'),
+ );
+ }
+
+ /**
+ * @dataProvider data_provider
+ */
+ public function test_inet_ntop($address, $hex)
+ {
+ $this->assertEquals($address, phpbb_inet_ntop(pack('H*', $hex)));
+ }
+
+ /**
+ * @dataProvider data_provider
+ */
+ public function test_inet_pton($address, $hex)
+ {
+ $this->assertEquals($hex, bin2hex(phpbb_inet_pton($address)));
+ }
+}
diff --git a/tests/network/ip_normalise.php b/tests/network/ip_normalise.php
new file mode 100644
index 0000000000..53d41e9371
--- /dev/null
+++ b/tests/network/ip_normalise.php
@@ -0,0 +1,65 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once 'test_framework/framework.php';
+require_once '../phpBB/includes/functions.php';
+
+class phpbb_network_ip_normalise_test extends phpbb_test_case
+{
+ public function data_provider()
+ {
+ return array(
+ // From: A Recommendation for IPv6 Address Text Representation
+ // http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
+
+ // Section 4: A Recommendation for IPv6 Text Representation
+ // Section 4.1: Handling Leading Zeros in a 16 Bit Field
+ array('2001:0db8::0001', '2001:db8::1'),
+
+ // Section 4.2: "::" Usage
+ // Section 4.2.1: Shorten As Much As Possible
+ array('2001:db8::0:1', '2001:db8::1'),
+
+ // Section 4.2.2: Handling One 16 Bit 0 Field
+ array('2001:db8::1:1:1:1:1', '2001:db8:0:1:1:1:1:1'),
+
+ // Section 4.2.3: Choice in Placement of "::"
+ array('2001:db8:0:0:1:0:0:1', '2001:db8::1:0:0:1'),
+
+ // Section 4.3: Lower Case
+ array('2001:DB8::1', '2001:db8::1'),
+
+ // Section 5: Text Representation of Special Addresses
+ // We want to show IPv4-mapped addresses as plain IPv4 addresses, though.
+ array('::ffff:192.168.0.1', '192.168.0.1'),
+ array('0000::0000:ffff:c000:0280', '192.0.2.128'),
+
+ // IPv6 addresses with the last 32-bit written in dotted-quad notation
+ // should be converted to hex-only IPv6 addresses.
+ array('2001:db8::192.0.2.128', '2001:db8::c000:280'),
+
+ // Any string not passing the IPv4 or IPv6 regular expression
+ // is supposed to result in false being returned.
+ // Valid and invalid IP addresses are tested in
+ // tests/regex/ipv4.php and tests/regex/ipv6.php.
+ array('', false),
+ array('192.168.1.256', false),
+ array('::ffff:192.168.255.256', false),
+ array('::1111:2222:3333:4444:5555:6666::', false),
+ );
+ }
+
+ /**
+ * @dataProvider data_provider
+ */
+ public function test_ip_normalise($ip_address, $expected)
+ {
+ $this->assertEquals($expected, phpbb_ip_normalise($ip_address));
+ }
+}