Annotation of embedaddon/php/ext/standard/tests/strings/sha1_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test sha1() function : usage variations - unexpected values for 'raw' argument
3: --FILE--
4: <?php
5:
6: /* Prototype: string sha1 ( string $str [, bool $raw_output ] )
7: * Description: Calculate the sha1 hash of a string
8: */
9:
10: echo "*** Testing sha1() : unexpected values for 'raw' ***\n";
11:
12: $string = "Hello World";
13:
14: //get an unset variable
15: $unset_var = 10;
16: unset ($unset_var);
17:
18: //defining class for object variable
19: class MyClass
20: {
21: public function __toString()
22: {
23: return "object";
24: }
25: }
26:
27: //resource variable
28: $fp = fopen(__FILE__, 'r');
29:
30: //different values for 'str' argument
31: $values = array(
32:
33: // int data
34: /*1*/ 0,
35: 1,
36: 12345,
37: -2345,
38:
39: // float data
40: /*5*/ 10.5,
41: -10.5,
42: 10.1234567e10,
43: 10.1234567E-10,
44: .5,
45:
46: // array data
47: /*10*/ array(),
48: array(0),
49: array(1),
50: array(1, 2),
51: array('color' => 'red', 'item' => 'pen'),
52:
53: // null data
54: /*15*/ NULL,
55: null,
56:
57: // string data
58: /*17*/ "ABC",
59: 'abc',
60: "0abc",
61: "123abc",
62:
63: // empty data
64: /*21*/ "",
65: '',
66:
67: // object data
68: /*23*/ new MyClass(),
69:
70: // undefined data
71: /*24*/ @$undefined_var,
72:
73: // unset data
74: /*25*/ @$unset_var,
75:
76: //resource data
77: /*26*/ $fp
78: );
79:
80: // loop through each element of $values for 'raw' argument
81: for($count = 0; $count < count($values); $count++) {
82: echo "-- Iteration ".($count+1)." --\n";
83: // use bin2hex to catch those cases were raw is true
84: var_dump( bin2hex(sha1($string, $values[$count])) );
85: }
86:
87: //closing resource
88: fclose($fp);
89:
90: ?>
91: ===DONE===
92: --EXPECTF--
93: *** Testing sha1() : unexpected values for 'raw' ***
94: -- Iteration 1 --
95: string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430"
96: -- Iteration 2 --
97: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
98: -- Iteration 3 --
99: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
100: -- Iteration 4 --
101: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
102: -- Iteration 5 --
103: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
104: -- Iteration 6 --
105: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
106: -- Iteration 7 --
107: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
108: -- Iteration 8 --
109: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
110: -- Iteration 9 --
111: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
112: -- Iteration 10 --
113:
114: Warning: sha1() expects parameter 2 to be boolean, array given in %s on line %d
115: string(0) ""
116: -- Iteration 11 --
117:
118: Warning: sha1() expects parameter 2 to be boolean, array given in %s on line %d
119: string(0) ""
120: -- Iteration 12 --
121:
122: Warning: sha1() expects parameter 2 to be boolean, array given in %s on line %d
123: string(0) ""
124: -- Iteration 13 --
125:
126: Warning: sha1() expects parameter 2 to be boolean, array given in %s on line %d
127: string(0) ""
128: -- Iteration 14 --
129:
130: Warning: sha1() expects parameter 2 to be boolean, array given in %s on line %d
131: string(0) ""
132: -- Iteration 15 --
133: string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430"
134: -- Iteration 16 --
135: string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430"
136: -- Iteration 17 --
137: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
138: -- Iteration 18 --
139: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
140: -- Iteration 19 --
141: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
142: -- Iteration 20 --
143: string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0"
144: -- Iteration 21 --
145: string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430"
146: -- Iteration 22 --
147: string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430"
148: -- Iteration 23 --
149:
150: Warning: sha1() expects parameter 2 to be boolean, object given in %s on line %d
151: string(0) ""
152: -- Iteration 24 --
153: string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430"
154: -- Iteration 25 --
155: string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430"
156: -- Iteration 26 --
157:
158: Warning: sha1() expects parameter 2 to be boolean, resource given in %s on line %d
159: string(0) ""
160: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>