1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Test - uuid function |
4
|
|
|
* @package fwolflib |
5
|
|
|
* @subpackage func-test |
6
|
|
|
* @copyright Copyright 2004-2008, Fwolf |
7
|
|
|
* @author Fwolf <[email protected]> |
8
|
|
|
* @since 2008-05-08 |
9
|
|
|
* @version $Id$ |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Define like this, so test can run both under eclipse and web alone. |
13
|
|
|
// {{{ |
14
|
|
|
if (! defined('SIMPLE_TEST')) { |
15
|
|
|
define('SIMPLE_TEST', 'simpletest/'); |
16
|
|
|
require_once(SIMPLE_TEST . 'autorun.php'); |
17
|
|
|
} |
18
|
|
|
// Then set output encoding |
19
|
|
|
//header('Content-Type: text/html; charset=utf-8'); |
20
|
|
|
// }}} |
21
|
|
|
|
22
|
|
|
// Require library define file which need test |
23
|
|
|
require_once('fwolflib/func/request.php'); |
24
|
|
|
require_once('fwolflib/func/uuid.php'); |
25
|
|
|
|
26
|
|
|
class TestFuncUuid extends UnitTestCase { |
27
|
|
|
|
28
|
|
|
function TestUuidParse() { |
|
|
|
|
29
|
|
|
// Generate and parse data back |
30
|
|
|
$ar = UuidParse(Uuid()); |
|
|
|
|
31
|
|
|
$this->assertIdentical($ar['custom_1'], '0000'); |
32
|
|
|
// Custom field |
33
|
|
|
$ar = UuidParse(Uuid('0001')); |
|
|
|
|
34
|
|
|
$this->assertIdentical($ar['custom_1'], '0001'); |
35
|
|
|
$ar = UuidParse(Uuid('0001', '1312.101')); |
|
|
|
|
36
|
|
|
$this->assertIdentical($ar['custom_2'], '1312.101'); |
37
|
|
|
// Parae data |
38
|
|
|
$ar = UuidParse('4822afd9-861b-0000-8302-650a25cda932'); |
|
|
|
|
39
|
|
|
$this->assertIdentical($ar['time_low'], 1210232793); |
40
|
|
|
$this->assertIdentical($ar['time_mid'], 34331); |
41
|
|
|
$this->assertIdentical($ar['custom_1'], '0000'); |
42
|
|
|
$this->assertIdentical($ar['custom_2'], '8302650a'); |
43
|
|
|
$this->assertIdentical($ar['ip'], '131.2.101.10'); |
44
|
|
|
|
45
|
|
|
// Speed test |
46
|
|
|
UuidSpeedTest(500); |
47
|
|
|
} // end of func |
48
|
|
|
|
49
|
|
|
} // end of class TestFuncString |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
// Change output charset in this way. |
53
|
|
|
// {{{ |
54
|
|
|
$s_url = GetSelfUrl(false); |
|
|
|
|
55
|
|
|
$s_url = substr($s_url, strrpos($s_url, '/') + 1); |
56
|
|
|
if ('uuid.test.php' == $s_url) { |
57
|
|
|
$test = new TestFuncUuid(); |
58
|
|
|
$test->run(new HtmlReporter('utf-8')); |
59
|
|
|
} |
60
|
|
|
// }}} |
61
|
|
|
?> |
|
|
|
|
62
|
|
|
|
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.