Annotation of embedaddon/php/ext/iconv/tests/iconv_strlen_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test iconv_strlen() function : usage variations - Pass different data types as $encoding arg
3: --SKIPIF--
4: <?php
5: extension_loaded('iconv') or die('skip');
6: function_exists('iconv_strlen') or die("skip iconv_strlen() is not available in this build");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype : int iconv_strlen(string str [, string charset])
11: * Description: Get character numbers of a string
12: * Source code: ext/iconv/iconv.c
13: */
14:
15: /*
16: * Test iconv_strlen() by passing different data types as $encoding argument.
17: * Where possible 'UTF-8' has been entered as a string value
18: */
19:
20: echo "*** Testing iconv_strlen() : usage variations ***\n";
21:
22: // Initialise function arguments not being substituted
23: $str = 'string value';
24:
25: //get an unset variable
26: $unset_var = 10;
27: unset ($unset_var);
28:
29: // get a class
30: class classA
31: {
32: public function __toString() {
33: return "UTF-8";
34: }
35: }
36:
37: // heredoc string
38: $heredoc = <<<EOT
39: UTF-8
40: EOT;
41:
42: // get a resource variable
43: $fp = fopen(__FILE__, "r");
44:
45: // unexpected values to be passed to $input argument
46: $inputs = array(
47:
48: // int data
49: /*1*/ 0,
50: 1,
51: 12345,
52: -2345,
53:
54: // float data
55: /*5*/ 10.5,
56: -10.5,
57: 12.3456789000e10,
58: 12.3456789000E-10,
59: .5,
60:
61: // null data
62: /*10*/ NULL,
63: null,
64:
65: // boolean data
66: /*12*/ true,
67: false,
68: TRUE,
69: FALSE,
70:
71: // empty data
72: /*16*/ "",
73: '',
74:
75: // string data
76: /*18*/ "UTF-8",
77: 'UTF-8',
78: $heredoc,
79:
80: // object data
81: /*21*/ new classA(),
82:
83: // undefined data
84: /*22*/ @$undefined_var,
85:
86: // unset data
87: /*23*/ @$unset_var,
88:
89: // resource variable
90: /*24*/ $fp
91: );
92:
93: // loop through each element of $inputs to check the behavior of iconv_strlen()
94: $iterator = 1;
95: foreach($inputs as $input) {
96: echo "\n-- Iteration $iterator --\n";
97: var_dump( iconv_strlen($str, $input));
98: $iterator++;
99: };
100:
101: fclose($fp);
102:
103: echo "Done";
104: ?>
105:
106: --EXPECTF--
107: *** Testing iconv_strlen() : usage variations ***
108:
109: -- Iteration 1 --
110:
111: Notice: iconv_strlen(): Wrong charset, conversion from `0' to `UCS-4LE' is not allowed in %s on line %d
112: bool(false)
113:
114: -- Iteration 2 --
115:
116: Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
117: bool(false)
118:
119: -- Iteration 3 --
120:
121: Notice: iconv_strlen(): Wrong charset, conversion from `12345' to `UCS-4LE' is not allowed in %s on line %d
122: bool(false)
123:
124: -- Iteration 4 --
125:
126: Notice: iconv_strlen(): Wrong charset, conversion from `-2345' to `UCS-4LE' is not allowed in %s on line %d
127: bool(false)
128:
129: -- Iteration 5 --
130:
131: Notice: iconv_strlen(): Wrong charset, conversion from `10.5' to `UCS-4LE' is not allowed in %s on line %d
132: bool(false)
133:
134: -- Iteration 6 --
135:
136: Notice: iconv_strlen(): Wrong charset, conversion from `-10.5' to `UCS-4LE' is not allowed in %s on line %d
137: bool(false)
138:
139: -- Iteration 7 --
140:
141: Notice: iconv_strlen(): Wrong charset, conversion from `123456789000' to `UCS-4LE' is not allowed in %s on line %d
142: bool(false)
143:
144: -- Iteration 8 --
145:
146: Notice: iconv_strlen(): Wrong charset, conversion from `1.23456789E-9' to `UCS-4LE' is not allowed in %s on line %d
147: bool(false)
148:
149: -- Iteration 9 --
150:
151: Notice: iconv_strlen(): Wrong charset, conversion from `0.5' to `UCS-4LE' is not allowed in %s on line %d
152: bool(false)
153:
154: -- Iteration 10 --
155: int(12)
156:
157: -- Iteration 11 --
158: int(12)
159:
160: -- Iteration 12 --
161:
162: Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
163: bool(false)
164:
165: -- Iteration 13 --
166: int(12)
167:
168: -- Iteration 14 --
169:
170: Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
171: bool(false)
172:
173: -- Iteration 15 --
174: int(12)
175:
176: -- Iteration 16 --
177: int(12)
178:
179: -- Iteration 17 --
180: int(12)
181:
182: -- Iteration 18 --
183: int(12)
184:
185: -- Iteration 19 --
186: int(12)
187:
188: -- Iteration 20 --
189: int(12)
190:
191: -- Iteration 21 --
192: int(12)
193:
194: -- Iteration 22 --
195: int(12)
196:
197: -- Iteration 23 --
198: int(12)
199:
200: -- Iteration 24 --
201:
202: Warning: iconv_strlen() expects parameter 2 to be string, resource given in %s on line %d
203: bool(false)
204: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>