Annotation of embedaddon/php/ext/standard/tests/strings/bin2hex_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test bin2hex() function : usage variations - test values for $str argument
3: --FILE--
4: <?php
5:
6: /* Prototype : string bin2hex ( string $str )
7: * Description: Convert binary data into hexadecimal representation
8: * Source code: ext/standard/string.c
9: */
10:
11: echo "*** Testing bin2hex() function: with unexpected inputs for 'str' argument ***\n";
12:
13: //get an unset variable
14: $unset_var = 'string_val';
15: unset($unset_var);
16:
17: //defining a class
18: class sample {
19: public function __toString() {
20: return "sample object";
21: }
22: }
23:
24: //getting the resource
25: $file_handle = fopen(__FILE__, "r");
26:
27: // array with different values for $input
28: $inputs = array (
29:
30: // integer values
31: /*1*/ 0,
32: 1,
33: 123456,
34:
35: // float values
36: /*4*/ 10.5,
37: -20.5,
38: 10.1234567e10,
39:
40: // array values
41: /*7*/ array(),
42: array(0),
43: array(1, 2),
44:
45: // boolean values
46: /*10*/true,
47: false,
48: TRUE,
49: FALSE,
50:
51: // null values
52: /*14*/NULL,
53: null,
54:
55: // objects
56: /*16*/new sample(),
57:
58: // resource
59: /*17*/$file_handle,
60:
61: // undefined variable
62: /*18*/@$undefined_var,
63:
64: // unset variable
65: /*19*/@$unset_var
66: );
67:
68: // loop through with each element of the $inputs array to test bin2hex() function
69: $count = 1;
70: foreach($inputs as $input) {
71: echo "-- Iteration $count --\n";
72: var_dump(bin2hex($input) );
73: $count ++;
74: }
75:
76: fclose($file_handle); //closing the file handle
77:
78: ?>
79: ===DONE===
80: --EXPECTF--
81: *** Testing bin2hex() function: with unexpected inputs for 'str' argument ***
82: -- Iteration 1 --
83: string(2) "30"
84: -- Iteration 2 --
85: string(2) "31"
86: -- Iteration 3 --
87: string(12) "313233343536"
88: -- Iteration 4 --
89: string(8) "31302e35"
90: -- Iteration 5 --
91: string(10) "2d32302e35"
92: -- Iteration 6 --
93: string(24) "313031323334353637303030"
94: -- Iteration 7 --
95:
96: Warning: bin2hex() expects parameter 1 to be string, array given in %s on line %d
97: NULL
98: -- Iteration 8 --
99:
100: Warning: bin2hex() expects parameter 1 to be string, array given in %s on line %d
101: NULL
102: -- Iteration 9 --
103:
104: Warning: bin2hex() expects parameter 1 to be string, array given in %s on line %d
105: NULL
106: -- Iteration 10 --
107: string(2) "31"
108: -- Iteration 11 --
109: string(0) ""
110: -- Iteration 12 --
111: string(2) "31"
112: -- Iteration 13 --
113: string(0) ""
114: -- Iteration 14 --
115: string(0) ""
116: -- Iteration 15 --
117: string(0) ""
118: -- Iteration 16 --
119: string(26) "73616d706c65206f626a656374"
120: -- Iteration 17 --
121:
122: Warning: bin2hex() expects parameter 1 to be string, resource given in %s on line %d
123: NULL
124: -- Iteration 18 --
125: string(0) ""
126: -- Iteration 19 --
127: string(0) ""
128: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>