1--TEST--
2Test strtoupper() function
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) == 'WIN') {
6  if (!setlocale(LC_ALL, 'C')) {
7    die('skip need "C" locale (this windows is broken)');
8  }
9} else {
10  if (!setlocale(LC_ALL, 'en_US.UTF-8', 'en')) {
11    die('skip need "en_US.UTF-8" locale');
12  }
13}
14?>
15--FILE--
16<?php
17/* Prototype:
18     string strtoupper ( string $string );
19   Description:
20     Returns string with all alphabetic characters converted to uppercase
21*/
22if( substr(PHP_OS, 0, 3) == 'WIN') {
23  setlocale(LC_ALL, 'C');
24} else {
25  setlocale(LC_ALL, 'en_US.UTF-8');
26}
27
28echo "*** Testing strtoupper() with 128 chars ***\n";
29for ($i=0; $i<=127; $i++){
30  $char = chr($i);
31  print(bin2hex($char))." => ".(bin2hex(strtoupper("$char")))."\n";
32}
33
34echo "\n*** Testing strtoupper() with basic strings ***\n";
35$str = "Mary Had A liTTle LAmb and ShE loveD IT So\n";
36var_dump(strtoupper($str));
37
38echo "\n*** Testing strtoupper() with various strings ***";
39/* strings to pass strtoupper() */
40$strings = array (
41  "",
42  "string",
43  "stRINg0234",
44  "1.233.344StrinG12333",
45  "$$$$$$!!!!@@@@@@@ ABCDEF !!!***",
46  "ABCD\0abcdABCD",
47  NULL,
48  TRUE,
49  FALSE,
50  array()
51);
52
53$count = 0;
54/* loop through to check possible variations */
55foreach ($strings as $string) {
56  echo "\n-- Iteration $count --\n";
57  var_dump( strtoupper($string) );
58  $count++;
59}
60
61echo "\n*** Testing strtoupper() with two different case strings ***\n";
62if (strtoupper("HeLLo woRLd") === strtoupper("hEllo WORLD"))
63  echo "strings are same, with Case Insensitive\n";
64else
65  echo "strings are not same\n";
66
67echo "\n*** Testing error conditions ***";
68var_dump( strtoupper() ); /* Zero arguments */
69var_dump( strtoupper("a", "b") ); /* Arguments > Expected */
70
71echo "*** Done ***";
72?>
73--EXPECTF--
74*** Testing strtoupper() with 128 chars ***
7500 => 00
7601 => 01
7702 => 02
7803 => 03
7904 => 04
8005 => 05
8106 => 06
8207 => 07
8308 => 08
8409 => 09
850a => 0a
860b => 0b
870c => 0c
880d => 0d
890e => 0e
900f => 0f
9110 => 10
9211 => 11
9312 => 12
9413 => 13
9514 => 14
9615 => 15
9716 => 16
9817 => 17
9918 => 18
10019 => 19
1011a => 1a
1021b => 1b
1031c => 1c
1041d => 1d
1051e => 1e
1061f => 1f
10720 => 20
10821 => 21
10922 => 22
11023 => 23
11124 => 24
11225 => 25
11326 => 26
11427 => 27
11528 => 28
11629 => 29
1172a => 2a
1182b => 2b
1192c => 2c
1202d => 2d
1212e => 2e
1222f => 2f
12330 => 30
12431 => 31
12532 => 32
12633 => 33
12734 => 34
12835 => 35
12936 => 36
13037 => 37
13138 => 38
13239 => 39
1333a => 3a
1343b => 3b
1353c => 3c
1363d => 3d
1373e => 3e
1383f => 3f
13940 => 40
14041 => 41
14142 => 42
14243 => 43
14344 => 44
14445 => 45
14546 => 46
14647 => 47
14748 => 48
14849 => 49
1494a => 4a
1504b => 4b
1514c => 4c
1524d => 4d
1534e => 4e
1544f => 4f
15550 => 50
15651 => 51
15752 => 52
15853 => 53
15954 => 54
16055 => 55
16156 => 56
16257 => 57
16358 => 58
16459 => 59
1655a => 5a
1665b => 5b
1675c => 5c
1685d => 5d
1695e => 5e
1705f => 5f
17160 => 60
17261 => 41
17362 => 42
17463 => 43
17564 => 44
17665 => 45
17766 => 46
17867 => 47
17968 => 48
18069 => 49
1816a => 4a
1826b => 4b
1836c => 4c
1846d => 4d
1856e => 4e
1866f => 4f
18770 => 50
18871 => 51
18972 => 52
19073 => 53
19174 => 54
19275 => 55
19376 => 56
19477 => 57
19578 => 58
19679 => 59
1977a => 5a
1987b => 7b
1997c => 7c
2007d => 7d
2017e => 7e
2027f => 7f
203
204*** Testing strtoupper() with basic strings ***
205string(43) "MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
206"
207
208*** Testing strtoupper() with various strings ***
209-- Iteration 0 --
210string(0) ""
211
212-- Iteration 1 --
213string(6) "STRING"
214
215-- Iteration 2 --
216string(10) "STRING0234"
217
218-- Iteration 3 --
219string(20) "1.233.344STRING12333"
220
221-- Iteration 4 --
222string(31) "$$$$$$!!!!@@@@@@@ ABCDEF !!!***"
223
224-- Iteration 5 --
225string(13) "ABCD�ABCDABCD"
226
227-- Iteration 6 --
228string(0) ""
229
230-- Iteration 7 --
231string(1) "1"
232
233-- Iteration 8 --
234string(0) ""
235
236-- Iteration 9 --
237
238Warning: strtoupper() expects parameter 1 to be string, array given in %s on line %d
239NULL
240
241*** Testing strtoupper() with two different case strings ***
242strings are same, with Case Insensitive
243
244*** Testing error conditions ***
245Warning: strtoupper() expects exactly 1 parameter, 0 given in %s on line %d
246NULL
247
248Warning: strtoupper() expects exactly 1 parameter, 2 given in %s on line %d
249NULL
250*** Done ***
251