1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Test - crypt func |
4
|
|
|
* @package fwolflib |
5
|
|
|
* @subpackage func-test |
6
|
|
|
* @copyright Copyright 2009, Fwolf |
7
|
|
|
* @author Fwolf <[email protected]> |
8
|
|
|
* @since 2009-10-22 |
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('fwlib/func/crypt.php'); |
24
|
|
|
require_once('fwlib/func/request.php'); |
25
|
|
|
|
26
|
|
|
class TestFuncCrypt extends UnitTestCase { |
27
|
|
|
|
28
|
|
|
function TestMcryptSmplIv() { |
|
|
|
|
29
|
|
|
$s_key = 'blahblahblah'; |
30
|
|
|
$s_data = '加密的东东'; |
31
|
|
|
$s_algo = 'xtea'; |
32
|
|
|
|
33
|
|
|
$s_data_encrypted = McryptSmplIvEncrypt($s_data, $s_key, $s_algo); |
|
|
|
|
34
|
|
|
$this->assertEqual(base64_encode($s_data_encrypted), |
35
|
|
|
'8vAJEMIdSmH3udoxZ3va'); |
36
|
|
|
|
37
|
|
|
$s_data_decrypted = McryptSmplIvDecrypt($s_data_encrypted, $s_key, $s_algo); |
|
|
|
|
38
|
|
|
$this->assertEqual($s_data_decrypted, $s_data); |
39
|
|
|
} // end of func TestMcryptSmplIv |
40
|
|
|
|
41
|
|
|
} // end of class TestFuncCrypt |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
// Change output charset in this way. |
45
|
|
|
// {{{ |
46
|
|
|
$s_url = GetSelfUrl(false); |
|
|
|
|
47
|
|
|
$s_url = substr($s_url, strrpos($s_url, '/') + 1); |
48
|
|
|
if ('crypt.test.php' == $s_url) { |
49
|
|
|
$test = new TestFuncCrypt(); |
50
|
|
|
$test->run(new HtmlReporter('utf-8')); |
51
|
|
|
} |
52
|
|
|
// }}} |
53
|
|
|
?> |
|
|
|
|
54
|
|
|
|
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.