Annotation of embedaddon/php/ext/mcrypt/tests/mcrypt_ecb_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mcrypt_ecb() function : usage variation
3: --SKIPIF--
4: <?php
5: if (!extension_loaded("mcrypt")) {
6: print "skip - mcrypt extension not loaded";
7: }
8: ?>
9: --FILE--
10: <?php
11: /* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
12: * Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
13: * Source code: ext/mcrypt/mcrypt.c
14: * Alias to functions:
15: */
16:
17: echo "*** Testing mcrypt_ecb() : usage variation ***\n";
18:
19: // Define error handler
20: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
21: if (error_reporting() != 0) {
22: // report non-silenced errors
23: echo "Error: $err_no - $err_msg, $filename($linenum)\n";
24: }
25: }
26: set_error_handler('test_error_handler');
27:
28: // Initialise function arguments not being substituted (if any)
29: $key = b'string_val';
30: $data = b'string_val';
31: $mode = MCRYPT_ENCRYPT;
32: $iv = b'string_val';
33:
34: //get an unset variable
35: $unset_var = 10;
36: unset ($unset_var);
37:
38: // define some classes
39: class classWithToString
40: {
41: public function __toString() {
42: return "Class A object";
43: }
44: }
45:
46: class classWithoutToString
47: {
48: }
49:
50: // heredoc string
51: $heredoc = <<<EOT
52: hello world
53: EOT;
54:
55: // get a resource variable
56: $fp = fopen(__FILE__, "r");
57:
58: // add arrays
59: $index_array = array (1, 2, 3);
60: $assoc_array = array ('one' => 1, 'two' => 2);
61:
62: //array of values to iterate over
63: $inputs = array(
64:
65: // int data
66: 'int 0' => 0,
67: 'int 1' => 1,
68: 'int 12345' => 12345,
69: 'int -12345' => -2345,
70:
71: // float data
72: 'float 10.5' => 10.5,
73: 'float -10.5' => -10.5,
74: 'float 12.3456789000e10' => 12.3456789000e10,
75: 'float -12.3456789000e10' => -12.3456789000e10,
76: 'float .5' => .5,
77:
78: // array data
79: 'empty array' => array(),
80: 'int indexed array' => $index_array,
81: 'associative array' => $assoc_array,
82: 'nested arrays' => array('foo', $index_array, $assoc_array),
83:
84: // null data
85: 'uppercase NULL' => NULL,
86: 'lowercase null' => null,
87:
88: // boolean data
89: 'lowercase true' => true,
90: 'lowercase false' =>false,
91: 'uppercase TRUE' =>TRUE,
92: 'uppercase FALSE' =>FALSE,
93:
94: // empty data
95: 'empty string DQ' => "",
96: 'empty string SQ' => '',
97:
98: // object data
99: 'instance of classWithToString' => new classWithToString(),
100: 'instance of classWithoutToString' => new classWithoutToString(),
101:
102: // undefined data
103: 'undefined var' => @$undefined_var,
104:
105: // unset data
106: 'unset var' => @$unset_var,
107:
108: // resource variable
109: 'resource' => $fp
110: );
111:
112: // loop through each element of the array for cipher
113:
114: foreach($inputs as $valueType =>$value) {
115: echo "\n--$valueType--\n";
116: var_dump( mcrypt_ecb($value, $key, $data, $mode, $iv) );
117: };
118:
119: fclose($fp);
120:
121: ?>
122: ===DONE===
123: --EXPECTF--
124: *** Testing mcrypt_ecb() : usage variation ***
125:
126: --int 0--
127: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
128: bool(false)
129:
130: --int 1--
131: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
132: bool(false)
133:
134: --int 12345--
135: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
136: bool(false)
137:
138: --int -12345--
139: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
140: bool(false)
141:
142: --float 10.5--
143: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
144: bool(false)
145:
146: --float -10.5--
147: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
148: bool(false)
149:
150: --float 12.3456789000e10--
151: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
152: bool(false)
153:
154: --float -12.3456789000e10--
155: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
156: bool(false)
157:
158: --float .5--
159: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
160: bool(false)
161:
162: --empty array--
163: Error: 2 - mcrypt_ecb() expects parameter 1 to be string, array given, %s(%d)
164: NULL
165:
166: --int indexed array--
167: Error: 2 - mcrypt_ecb() expects parameter 1 to be string, array given, %s(%d)
168: NULL
169:
170: --associative array--
171: Error: 2 - mcrypt_ecb() expects parameter 1 to be string, array given, %s(%d)
172: NULL
173:
174: --nested arrays--
175: Error: 2 - mcrypt_ecb() expects parameter 1 to be string, array given, %s(%d)
176: NULL
177:
178: --uppercase NULL--
179: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
180: bool(false)
181:
182: --lowercase null--
183: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
184: bool(false)
185:
186: --lowercase true--
187: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
188: bool(false)
189:
190: --lowercase false--
191: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
192: bool(false)
193:
194: --uppercase TRUE--
195: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
196: bool(false)
197:
198: --uppercase FALSE--
199: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
200: bool(false)
201:
202: --empty string DQ--
203: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
204: bool(false)
205:
206: --empty string SQ--
207: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
208: bool(false)
209:
210: --instance of classWithToString--
211: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
212: bool(false)
213:
214: --instance of classWithoutToString--
215: Error: 2 - mcrypt_ecb() expects parameter 1 to be string, object given, %s(%d)
216: NULL
217:
218: --undefined var--
219: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
220: bool(false)
221:
222: --unset var--
223: Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
224: bool(false)
225:
226: --resource--
227: Error: 2 - mcrypt_ecb() expects parameter 1 to be string, resource given, %s(%d)
228: NULL
229: ===DONE===
230:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>