1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Test - client function |
4
|
|
|
* @package fwolflib |
5
|
|
|
* @subpackage func.test |
6
|
|
|
* @copyright Copyright 2004-2010, Fwolf |
7
|
|
|
* @author Fwolf <[email protected]> |
8
|
|
|
* @since 2008-05-08 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
// Define like this, so test can run both under eclipse and web alone. |
12
|
|
|
// {{{ |
13
|
|
|
if (! defined('SIMPLE_TEST')) { |
14
|
|
|
define('SIMPLE_TEST', 'simpletest/'); |
15
|
|
|
require_once(SIMPLE_TEST . 'autorun.php'); |
16
|
|
|
} |
17
|
|
|
// Then set output encoding |
18
|
|
|
//header('Content-Type: text/html; charset=utf-8'); |
19
|
|
|
// }}} |
20
|
|
|
|
21
|
|
|
// Require library define file which need test |
22
|
|
|
require_once('fwolflib/func/client.php'); |
23
|
|
|
require_once('fwolflib/func/request.php'); |
24
|
|
|
|
25
|
|
|
class TestFuncClient extends UnitTestCase { |
26
|
|
|
|
27
|
|
|
function TestClientIpFromToHex() { |
|
|
|
|
28
|
|
|
// Default value |
29
|
|
|
$this->assertEqual(ClientIpToHex('131.2.101.10'), '8302650a'); |
|
|
|
|
30
|
|
|
$this->assertEqual(ClientIpFromHex('8302650a'), '131.2.101.10'); |
|
|
|
|
31
|
|
|
// Loopback address |
32
|
|
|
$this->assertEqual(ClientIpToHex('127.0.0.1'), '7f000001'); |
|
|
|
|
33
|
|
|
$this->assertEqual(ClientIpFromHex('7f000001'), '127.0.0.1'); |
|
|
|
|
34
|
|
|
// Error format |
35
|
|
|
$this->assertEqual(ClientIpToHex('127.00.00.01'), ''); |
|
|
|
|
36
|
|
|
|
37
|
|
|
// Mask address |
38
|
|
|
$this->assertEqual(ClientIpToHex('255.255.255.255'), 'ffffffff'); |
|
|
|
|
39
|
|
|
$this->assertEqual(ClientIpFromHex('ffffffff'), '255.255.255.255'); |
|
|
|
|
40
|
|
|
// Normal address |
41
|
|
|
$this->assertEqual(ClientIpToHex('202.99.160.68'), 'ca63a044'); |
|
|
|
|
42
|
|
|
$this->assertEqual(ClientIpFromHex('ca63a044'), '202.99.160.68'); |
|
|
|
|
43
|
|
|
// Error parameters handel |
44
|
|
|
$this->assertEqual(ClientIpToHex('ABCD'), ''); |
|
|
|
|
45
|
|
|
$this->assertEqual(ClientIpFromHex('ABCD'), ''); |
|
|
|
|
46
|
|
|
} // end of func TestClientIpFromToHex |
47
|
|
|
|
48
|
|
|
} // end of class TestFuncClient |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
// Change output charset in this way. |
52
|
|
|
// {{{ |
53
|
|
|
$s_url = GetSelfUrl(false); |
|
|
|
|
54
|
|
|
$s_url = substr($s_url, strrpos($s_url, '/') + 1); |
55
|
|
|
if ('client.test.php' == $s_url) { |
56
|
|
|
$test = new TestFuncClient(); |
57
|
|
|
$test->run(new HtmlReporter('utf-8')); |
58
|
|
|
} |
59
|
|
|
// }}} |
60
|
|
|
?> |
|
|
|
|
61
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.