diff options
| author | andy wharmby <wharmby@php.net> | 2009-01-18 22:51:02 +0000 |
|---|---|---|
| committer | andy wharmby <wharmby@php.net> | 2009-01-18 22:51:02 +0000 |
| commit | b83859120df49078dc5bef1b7e3b0bea60c47dec (patch) | |
| tree | e51c1761d8ddf511eb66f33164a44a7fff242762 | |
| parent | 571650e64d37b0bf0373f907f8074ff9188fa9ab (diff) | |
| download | php-git-b83859120df49078dc5bef1b7e3b0bea60c47dec.tar.gz | |
New nl_langinfo(), number_format() and ord() tests. Tested on Windows. Linux and Linux 64 bit
| -rw-r--r-- | ext/standard/tests/strings/nl_langinfo_basic.phpt | 37 | ||||
| -rw-r--r-- | ext/standard/tests/strings/nl_langinfo_error1.phpt | 40 | ||||
| -rw-r--r-- | ext/standard/tests/strings/nl_langinfo_variation1.phpt | 180 | ||||
| -rw-r--r-- | ext/standard/tests/strings/number_format_basic.phpt | 109 | ||||
| -rw-r--r-- | ext/standard/tests/strings/number_format_error.phpt | 38 | ||||
| -rw-r--r-- | ext/standard/tests/strings/ord_basic.phpt | 47 | ||||
| -rw-r--r-- | ext/standard/tests/strings/ord_error.phpt | 34 | ||||
| -rw-r--r-- | ext/standard/tests/strings/ord_variation1.phpt | 136 |
8 files changed, 621 insertions, 0 deletions
diff --git a/ext/standard/tests/strings/nl_langinfo_basic.phpt b/ext/standard/tests/strings/nl_langinfo_basic.phpt new file mode 100644 index 0000000000..370177ba8a --- /dev/null +++ b/ext/standard/tests/strings/nl_langinfo_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test nl_langinfo() function : basic functionality +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN'){ + die('skip Not for Windows'); +} +?> +--FILE-- +<?php + +/* Prototype : string nl_langinfo ( int $item ) + * Description: Query language and locale information + * Source code: ext/standard/string.c +*/ + +echo "*** Testing nl_langinfo() : basic functionality ***\n"; + +$original = setlocale(LC_ALL, 'C'); + +var_dump(nl_langinfo(ABDAY_2)); +var_dump(nl_langinfo(DAY_4)); +var_dump(nl_langinfo(ABMON_7)); +var_dump(nl_langinfo(MON_4)); +var_dump(nl_langinfo(RADIXCHAR)); + +setlocale(LC_ALL, $original); +?> +===DONE=== +--EXPECTF-- +*** Testing nl_langinfo() : basic functionality *** +string(3) "Mon" +string(9) "Wednesday" +string(3) "Jul" +string(5) "April" +string(1) "." +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/strings/nl_langinfo_error1.phpt b/ext/standard/tests/strings/nl_langinfo_error1.phpt new file mode 100644 index 0000000000..7702b012e9 --- /dev/null +++ b/ext/standard/tests/strings/nl_langinfo_error1.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test nl_langinfo() function : error conditions +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN'){ + die('skip Not for Windows'); +} +?> +--FILE-- +<?php + +/* Prototype : string nl_langinfo ( int $item ) + * Description: Query language and locale information + * Source code: ext/standard/string.c +*/ + +echo "*** Testing nl_langinfo() : error conditions ***\n"; + +echo "\n-- Testing nl_langinfo() function with no arguments --\n"; +var_dump( nl_langinfo() ); + +echo "\n-- Testing nl_langinfo() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( nl_langinfo(ABDAY_2, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing nl_langinfo() : error conditions *** + +-- Testing nl_langinfo() function with no arguments -- + +Warning: nl_langinfo() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing nl_langinfo() function with more than expected no. of arguments -- + +Warning: nl_langinfo() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/strings/nl_langinfo_variation1.phpt b/ext/standard/tests/strings/nl_langinfo_variation1.phpt new file mode 100644 index 0000000000..41844697f1 --- /dev/null +++ b/ext/standard/tests/strings/nl_langinfo_variation1.phpt @@ -0,0 +1,180 @@ +--TEST-- +Test nl_langinfo() function : unexpected inputs for '$tem' argument +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN'){ + die('skip Not for Windows'); +} +?> +--FILE-- +<?php + +/* Prototype : string nl_langinfo ( int $item ) + * Description: Query language and locale information + * Source code: ext/standard/string.c +*/ + +echo "*** Testing nl_langinfo() : with unexpected inputs for 'item' argument ***\n"; + +$original = setlocale(LC_ALL, 'C'); + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +// array with different values for $input +$items = array ( + + // integer values +/*1*/ 0, + 10, + 2147483647, + -2147483648, + + // float values +/*5*/ 10.5, + 20.3, + -20.5, + 10.1234567e5, + + // array values +/*9*/ array(), + array(0), + array(1, 2), + + // boolean values +/*12*/ true, + false, + TRUE, + FALSE, + + // null vlaues +/*16*/ NULL, + null, + + // objects +/*18*/ new sample(), + + // resource +/*19*/ $file_handle, + + // undefined variable +/*20*/ @$undefined_var, + + // unset variable +/*21*/ @$unset_var +); + +//defining '$input' argument +$input = "Test string"; + +// loop through with each element of the $items array to test nl_langinfo() function +$count = 1; +foreach($items as $item) { + echo "-- Iteration $count --\n"; + var_dump( nl_langinfo($item) ); + $count ++; +} + +fclose($file_handle); //closing the file handle +setlocale(LC_ALL, $original); + +?> +===DONE=== +--EXPECTF-- +*** Testing nl_langinfo() : with unexpected inputs for 'item' argument *** +-- Iteration 1 -- + +Warning: nl_langinfo(): Item '0' is not valid in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: nl_langinfo(): Item '10' is not valid in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: nl_langinfo(): Item '2147483647' is not valid in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: nl_langinfo(): Item '-2147483648' is not valid in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: nl_langinfo(): Item '10' is not valid in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: nl_langinfo(): Item '20' is not valid in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: nl_langinfo(): Item '-20' is not valid in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: nl_langinfo(): Item '1012345' is not valid in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: nl_langinfo() expects parameter 1 to be long, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: nl_langinfo() expects parameter 1 to be long, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: nl_langinfo() expects parameter 1 to be long, array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: nl_langinfo(): Item '1' is not valid in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: nl_langinfo(): Item '0' is not valid in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: nl_langinfo(): Item '1' is not valid in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: nl_langinfo(): Item '0' is not valid in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: nl_langinfo(): Item '0' is not valid in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: nl_langinfo(): Item '0' is not valid in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: nl_langinfo() expects parameter 1 to be long, object given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: nl_langinfo() expects parameter 1 to be long, resource given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: nl_langinfo(): Item '0' is not valid in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: nl_langinfo(): Item '0' is not valid in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/strings/number_format_basic.phpt b/ext/standard/tests/strings/number_format_basic.phpt new file mode 100644 index 0000000000..94b8482eef --- /dev/null +++ b/ext/standard/tests/strings/number_format_basic.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test number_format() - basic function test number_format() +--FILE-- +<?php +/* Prototype : string number_format ( float $number [, int $decimals ] ) + * string number_format ( float $number , int $decimals , string $dec_point , string $thousands_sep ) + * Description: Format a number with grouped thousands + * Source code: ext/standard/string.c + */ + +echo "*** Testing number_format() : basic functionality ***\n"; + +$values = array(1234.5678, + -1234.5678, + 1234.6578e4, + -1234.56789e4, + 0x1234CDEF, + 02777777777, + "123456789", + "123.456789", + "12.3456789e1", + null, + true, + false); + +echo "\n-- number_format tests.....default --\n"; +for ($i = 0; $i < count($values); $i++) { + $res = number_format($values[$i]); + var_dump($res); +} + +echo "\n-- number_format tests.....with two dp --\n"; +for ($i = 0; $i < count($values); $i++) { + $res = number_format($values[$i], 2); + var_dump($res); +} + +echo "\n-- number_format tests.....English format --\n"; +for ($i = 0; $i < count($values); $i++) { + $res = number_format($values[$i], 2, '.', ' '); + var_dump($res); +} + +echo "\n-- number_format tests.....French format --\n"; +for ($i = 0; $i < count($values); $i++) { + $res = number_format($values[$i], 2, ',' , ' '); + var_dump($res); +} +?> +===DONE=== +--EXPECTF-- +*** Testing number_format() : basic functionality *** + +-- number_format tests.....default -- +string(5) "1,235" +string(6) "-1,235" +string(10) "12,346,578" +string(11) "-12,345,679" +string(11) "305,450,479" +string(11) "402,653,183" +string(11) "123,456,789" +string(3) "123" +string(3) "123" +string(1) "0" +string(1) "1" +string(1) "0" + +-- number_format tests.....with two dp -- +string(8) "1,234.57" +string(9) "-1,234.57" +string(13) "12,346,578.00" +string(14) "-12,345,678.90" +string(14) "305,450,479.00" +string(14) "402,653,183.00" +string(14) "123,456,789.00" +string(6) "123.46" +string(6) "123.46" +string(4) "0.00" +string(4) "1.00" +string(4) "0.00" + +-- number_format tests.....English format -- +string(8) "1 234.57" +string(9) "-1 234.57" +string(13) "12 346 578.00" +string(14) "-12 345 678.90" +string(14) "305 450 479.00" +string(14) "402 653 183.00" +string(14) "123 456 789.00" +string(6) "123.46" +string(6) "123.46" +string(4) "0.00" +string(4) "1.00" +string(4) "0.00" + +-- number_format tests.....French format -- +string(8) "1 234,57" +string(9) "-1 234,57" +string(13) "12 346 578,00" +string(14) "-12 345 678,90" +string(14) "305 450 479,00" +string(14) "402 653 183,00" +string(14) "123 456 789,00" +string(6) "123,46" +string(6) "123,46" +string(4) "0,00" +string(4) "1,00" +string(4) "0,00" +===DONE=== diff --git a/ext/standard/tests/strings/number_format_error.phpt b/ext/standard/tests/strings/number_format_error.phpt new file mode 100644 index 0000000000..334b63eacc --- /dev/null +++ b/ext/standard/tests/strings/number_format_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test number_format() - wrong params test number_format() +--FILE-- +<?php +/* Prototype : string number_format ( float $number [, int $decimals ] ) + * string number_format ( float $number , int $decimals , string $dec_point , string $thousands_sep ) + * Description: Format a number with grouped thousands + * Source code: ext/standard/string.c + */ + +echo "*** Testing number_format() : error conditions ***\n"; + +echo "\n-- Testing number_format() function with less than expected no. of arguments --\n"; +number_format(); + +echo "\n-- Testing number_format() function with 3 arguments --\n"; +number_format(23,2,true); + +echo "\n-- Testing number_format() function with more than 4 arguments --\n"; +number_format(23,2,true,false,36); + +?> +===DONE=== +--EXPECTF-- +*** Testing number_format() : error conditions *** + +-- Testing number_format() function with less than expected no. of arguments -- + +Warning: number_format() expects at least 1 parameter, 0 given in %s on line %d + +-- Testing number_format() function with 3 arguments -- + +Warning: Wrong parameter count for number_format() in %s on line %d + +-- Testing number_format() function with more than 4 arguments -- + +Warning: number_format() expects at most 4 parameters, 5 given in %s on line %d +===DONE=== diff --git a/ext/standard/tests/strings/ord_basic.phpt b/ext/standard/tests/strings/ord_basic.phpt new file mode 100644 index 0000000000..19f3ea28d6 --- /dev/null +++ b/ext/standard/tests/strings/ord_basic.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test ord() function : basic functionality +--FILE-- +<?php + +/* Prototype : int ord ( string $string ) + * Description: Return ASCII value of character + * Source code: ext/standard/string.c +*/ + +echo "*** Testing ord() : basic functionality ***\n"; + +var_dump(ord("a")); +var_dump(ord("z")); +var_dump(ord("0")); +var_dump(ord("9")); +var_dump(ord("!")); +var_dump(ord("*")); +var_dump(ord("@")); +var_dump(ord("\n")); +var_dump(ord("\x0A")); +var_dump(ord("\xFF")); +var_dump(ord("Hello")); + +// Make sure all valid ascii chars round trip +for ($i = 0; $i < 255; $i++) { + if (ord(chr($i)) != $i) { + exit("TEST FAILED: $i does not round trip\n"); + } +} + +?> +===DONE=== +--EXPECT-- +*** Testing ord() : basic functionality *** +int(97) +int(122) +int(48) +int(57) +int(33) +int(42) +int(64) +int(10) +int(10) +int(255) +int(72) +===DONE=== diff --git a/ext/standard/tests/strings/ord_error.phpt b/ext/standard/tests/strings/ord_error.phpt new file mode 100644 index 0000000000..455fb38972 --- /dev/null +++ b/ext/standard/tests/strings/ord_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test ord() function : error conditions +--FILE-- +<?php + +/* Prototype : int ord ( string $string ) + * Description: Return ASCII value of character + * Source code: ext/standard/string.c +*/ + +echo "*** Testing ord() : error conditions ***\n"; + +echo "\n-- Testing ord() function with no arguments --\n"; +var_dump( ord() ); + +echo "\n-- Testing ord() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( ord(72, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing ord() : error conditions *** + +-- Testing ord() function with no arguments -- + +Warning: ord() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing ord() function with more than expected no. of arguments -- + +Warning: ord() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/strings/ord_variation1.phpt b/ext/standard/tests/strings/ord_variation1.phpt new file mode 100644 index 0000000000..06d9364a08 --- /dev/null +++ b/ext/standard/tests/strings/ord_variation1.phpt @@ -0,0 +1,136 @@ +--TEST-- +Test ord() function : usage variations - test values for $string argument +--FILE-- +<?php + +/* Prototype : int ord ( string $string ) + * Description: Return ASCII value of character + * Source code: ext/standard/string.c +*/ + +echo "*** Testing ord() function: with unexpected inputs for 'string' argument ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +//getting the resource +$file_handle = fopen(__FILE__, "r"); + +// array with different values for $input +$inputs = array ( + +/*1*/ 0, + 1, + 255, + 256, + 2147483647, + -2147483648, + + // float values +/*7*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*10*/ array(), + array(0), + array(1, 2), + + // boolean values +/*13*/ true, + false, + TRUE, + FALSE, + + // null values +/*17*/ NULL, + null, + + // objects +/*19*/ new sample(), + + // resource +/*20*/ $file_handle, + + // undefined variable +/*21*/ @$undefined_var, + + // unset variable +/*22*/ @$unset_var +); + +// loop through with each element of the $string array to test ord() function +$count = 1; +foreach($inputs as $input) { + echo "-- Iteration $count --\n"; + var_dump( ord($input) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing ord() function: with unexpected inputs for 'string' argument *** +-- Iteration 1 -- +int(48) +-- Iteration 2 -- +int(49) +-- Iteration 3 -- +int(50) +-- Iteration 4 -- +int(50) +-- Iteration 5 -- +int(50) +-- Iteration 6 -- +int(45) +-- Iteration 7 -- +int(49) +-- Iteration 8 -- +int(45) +-- Iteration 9 -- +int(49) +-- Iteration 10 -- + +Warning: ord() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: ord() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: ord() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 13 -- +int(49) +-- Iteration 14 -- +int(0) +-- Iteration 15 -- +int(49) +-- Iteration 16 -- +int(0) +-- Iteration 17 -- +int(0) +-- Iteration 18 -- +int(0) +-- Iteration 19 -- +int(115) +-- Iteration 20 -- + +Warning: ord() expects parameter 1 to be string, resource given in %s on line %d +NULL +-- Iteration 21 -- +int(0) +-- Iteration 22 -- +int(0) +===DONE=== |
