diff options
author | Andreas Fischer <bantu@phpbb.com> | 2010-07-22 12:03:57 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2011-01-03 00:09:51 +0100 |
commit | fdb5c2c9902557f0a3a006c7f62f2465c98513a7 (patch) | |
tree | 716ba003e949195b531019a7801352d0f3cb52ae /tests/network | |
parent | [ticket/9746] Adding calls to phpbb_ip_normalise() from session management. (diff) | |
download | phpbb-fdb5c2c9902557f0a3a006c7f62f2465c98513a7.tar.gz phpbb-fdb5c2c9902557f0a3a006c7f62f2465c98513a7.tar.bz2 phpbb-fdb5c2c9902557f0a3a006c7f62f2465c98513a7.zip |
[ticket/9746] Adding unit tests for inet_ntop() and inet_pton().
PHPBB3-9746
Diffstat (limited to 'tests/network')
-rw-r--r-- | tests/network/all_tests.php | 2 | ||||
-rw-r--r-- | tests/network/inet_ntop_pton.php | 42 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/network/all_tests.php b/tests/network/all_tests.php index 6305aae5b8..fd36009f4c 100644 --- a/tests/network/all_tests.php +++ b/tests/network/all_tests.php @@ -16,6 +16,7 @@ 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 @@ -30,6 +31,7 @@ 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..47fa0552da --- /dev/null +++ b/tests/network/inet_ntop_pton.php @@ -0,0 +1,42 @@ +<?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('::1', '00000000000000000000000000000001'), + array('2001:280:0:10::5', '20010280000000100000000000000005'), + array('fe80::200:4cff:fefe:172f', 'fe8000000000000002004cfffefe172f'), + ); + } + + /** + * @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))); + } +} |