[ticket/9746] Adding unit tests for inet_ntop() and inet_pton().

PHPBB3-9746
This commit is contained in:
Andreas Fischer 2010-07-22 12:03:57 +02:00
parent 6a32724400
commit fdb5c2c990
2 changed files with 44 additions and 0 deletions

View file

@ -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;

View file

@ -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)));
}
}