diff options
author | andy wharmby <wharmby@php.net> | 2009-01-19 15:46:41 +0000 |
---|---|---|
committer | andy wharmby <wharmby@php.net> | 2009-01-19 15:46:41 +0000 |
commit | 68b5346285de07fe2c08cf0c02a4af6a2d43d70a (patch) | |
tree | e664a613a822fca86409ef3298e122c96884bf4e /ext/standard/tests | |
parent | c422d15d0e97335c6d7e9cc8b0f5c48f46c55b6d (diff) | |
download | php-git-68b5346285de07fe2c08cf0c02a4af6a2d43d70a.tar.gz |
New tests for str_pad(), str_shuffle(), stristr() and strlen(). Tested on WIndows, Linux and Linux 64 bit
Diffstat (limited to 'ext/standard/tests')
19 files changed, 1564 insertions, 159 deletions
diff --git a/ext/standard/tests/strings/str_pad_variation1.phpt b/ext/standard/tests/strings/str_pad_variation1.phpt new file mode 100644 index 0000000000..aff89f598a --- /dev/null +++ b/ext/standard/tests/strings/str_pad_variation1.phpt @@ -0,0 +1,140 @@ +--TEST-- +Test str_pad() function : usage variations - unexpected inputs for '$input' argument +--FILE-- +<?php +/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] ) + * Description: Pad a string to a certain length with another string + * Source code: ext/standard/string.c +*/ + +/* Test str_pad() function: with unexpected inputs for '$input' + * and expected type for '$pad_length' +*/ + +echo "*** Testing str_pad() function: with unexpected inputs for 'input' 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 ( + + // integer values +/*1*/ 0, + 1, + -2, + 2147483647, + -2147483648, + + // float values +/*6*/ 10.5, + -20.5, + 10.1234567e10, + + // 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 '$pad_length' argument +$pad_length = "20"; + +// loop through with each element of the $inputs array to test str_pad() function +$count = 1; +foreach($inputs as $input) { + echo "-- Iteration $count --\n"; + var_dump( str_pad($input, $pad_length) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing str_pad() function: with unexpected inputs for 'input' argument *** +-- Iteration 1 -- +string(20) "0 " +-- Iteration 2 -- +string(20) "1 " +-- Iteration 3 -- +string(20) "-2 " +-- Iteration 4 -- +string(20) "2147483647 " +-- Iteration 5 -- +string(20) "-2147483648 " +-- Iteration 6 -- +string(20) "10.5 " +-- Iteration 7 -- +string(20) "-20.5 " +-- Iteration 8 -- +string(20) "101234567000 " +-- Iteration 9 -- + +Warning: str_pad() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: str_pad() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: str_pad() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 12 -- +string(20) "1 " +-- Iteration 13 -- +string(20) " " +-- Iteration 14 -- +string(20) "1 " +-- Iteration 15 -- +string(20) " " +-- Iteration 16 -- +string(20) " " +-- Iteration 17 -- +string(20) " " +-- Iteration 18 -- +string(20) "sample object " +-- Iteration 19 -- + +Warning: str_pad() expects parameter 1 to be string, resource given in %s on line %d +NULL +-- Iteration 20 -- +string(20) " " +-- Iteration 21 -- +string(20) " " +===DONE=== diff --git a/ext/standard/tests/strings/str_pad_variation2.phpt b/ext/standard/tests/strings/str_pad_variation2.phpt new file mode 100644 index 0000000000..2bc699069b --- /dev/null +++ b/ext/standard/tests/strings/str_pad_variation2.phpt @@ -0,0 +1,139 @@ +--TEST-- +Test str_pad() function : usage variations - unexpected inputs for '$pad_length' argument +--FILE-- +<?php +/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] ) + * Description: Pad a string to a certain length with another string + * Source code: ext/standard/string.c +*/ + +/* Test str_pad() function: with unexpected inputs for '$pad_length' + * and expected type for '$input' +*/ + +echo "*** Testing str_pad() function: with unexpected inputs for 'pad_length' 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 +$pad_lengths = array ( + + // integer values +/*1*/ 0, + 1, + -2, + 255, + + // float values +/*5*/ 10.5, + -20.5, + 10.12345e2, + + // array values +/*8*/ array(), + array(0), + array(1, 2), + + // boolean values +/*11*/ true, + false, + TRUE, + FALSE, + + // null vlaues +/*15*/ NULL, + null, + + // objects +/*17*/ new sample(), + + // resource +/*18*/ $file_handle, + + // undefined variable +/*19*/ @$undefined_var, + + // unset variable +/*20*/ @$unset_var +); + +//defining '$input' argument +$input = "Test string"; + +// loop through with each element of the $pad_lengths array to test str_pad() function +$count = 1; +foreach($pad_lengths as $pad_length) { + echo "-- Iteration $count --\n"; + var_dump( str_pad($input, $pad_length) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing str_pad() function: with unexpected inputs for 'pad_length' argument *** +-- Iteration 1 -- +string(11) "Test string" +-- Iteration 2 -- +string(11) "Test string" +-- Iteration 3 -- +string(11) "Test string" +-- Iteration 4 -- +string(255) "Test string " +-- Iteration 5 -- +string(11) "Test string" +-- Iteration 6 -- +string(11) "Test string" +-- Iteration 7 -- +string(1012) "Test string " +-- Iteration 8 -- + +Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 11 -- +string(11) "Test string" +-- Iteration 12 -- +string(11) "Test string" +-- Iteration 13 -- +string(11) "Test string" +-- Iteration 14 -- +string(11) "Test string" +-- Iteration 15 -- +string(11) "Test string" +-- Iteration 16 -- +string(11) "Test string" +-- Iteration 17 -- + +Warning: str_pad() expects parameter 2 to be long, object given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: str_pad() expects parameter 2 to be long, resource given in %s on line %d +NULL +-- Iteration 19 -- +string(11) "Test string" +-- Iteration 20 -- +string(11) "Test string" +===DONE=== diff --git a/ext/standard/tests/strings/str_pad_variation3.phpt b/ext/standard/tests/strings/str_pad_variation3.phpt new file mode 100644 index 0000000000..c277eb756b --- /dev/null +++ b/ext/standard/tests/strings/str_pad_variation3.phpt @@ -0,0 +1,153 @@ +--TEST-- +Test str_pad() function : usage variations - unexpected inputs for '$pad_string' argument +--FILE-- +<?php +/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] ) + * Description: Pad a string to a certain length with another string + * Source code: ext/standard/string.c +*/ + +/* Test str_pad() function: with unexpected inputs for '$pad_string' + * and expected type for '$input' and '$pad_length' +*/ + +echo "*** Testing str_pad() function: with unexpected inputs for 'pad_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 +$pad_strings = array ( + + // integer values +/*1*/ 0, + 1, + -2, + 2147483647, + -2147483648, + + // float values +/*6*/ 10.5, + -20.5, + 10.1234567e10, + + // 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"; +$pad_length = 20; + +// loop through with each element of the $pad_strings array to test str_pad() function +$count = 1; +foreach($pad_strings as $pad_string) { + echo "-- Iteration $count --\n"; + var_dump( str_pad($input, $pad_length, $pad_string) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing str_pad() function: with unexpected inputs for 'pad_string' argument *** +-- Iteration 1 -- +string(20) "Test string000000000" +-- Iteration 2 -- +string(20) "Test string111111111" +-- Iteration 3 -- +string(20) "Test string-2-2-2-2-" +-- Iteration 4 -- +string(20) "Test string214748364" +-- Iteration 5 -- +string(20) "Test string-21474836" +-- Iteration 6 -- +string(20) "Test string10.510.51" +-- Iteration 7 -- +string(20) "Test string-20.5-20." +-- Iteration 8 -- +string(20) "Test string101234567" +-- Iteration 9 -- + +Warning: str_pad() expects parameter 3 to be string, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: str_pad() expects parameter 3 to be string, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: str_pad() expects parameter 3 to be string, array given in %s on line %d +NULL +-- Iteration 12 -- +string(20) "Test string111111111" +-- Iteration 13 -- + +Warning: str_pad(): Padding string cannot be empty in %s on line %d +NULL +-- Iteration 14 -- +string(20) "Test string111111111" +-- Iteration 15 -- + +Warning: str_pad(): Padding string cannot be empty in %s on line %d +NULL +-- Iteration 16 -- + +Warning: str_pad(): Padding string cannot be empty in %s on line %d +NULL +-- Iteration 17 -- + +Warning: str_pad(): Padding string cannot be empty in %s on line %d +NULL +-- Iteration 18 -- +string(20) "Test stringsample ob" +-- Iteration 19 -- + +Warning: str_pad() expects parameter 3 to be string, resource given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: str_pad(): Padding string cannot be empty in %s on line %d +NULL +-- Iteration 21 -- + +Warning: str_pad(): Padding string cannot be empty in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/strings/str_pad_variation4.phpt b/ext/standard/tests/strings/str_pad_variation4.phpt new file mode 100644 index 0000000000..a622304c82 --- /dev/null +++ b/ext/standard/tests/strings/str_pad_variation4.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test str_pad() function : usage variations - unexpected inputs for '$pad_type' argument +--FILE-- +<?php +/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] ) + * Description: Pad a string to a certain length with another string + * Source code: ext/standard/string.c +*/ + +/* Test str_pad() function: with unexpected inputs for '$pad_type' + * and expected type for '$input', '$pad_length' and '$pad_string' +*/ + +echo "*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***\n"; + +//get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +//defining a class +class sample { + public function __toString() { + return "sample object"; + } +} + +// array with different values for $input +$pad_types = array ( + + // integer values +/*1*/ 0, // == STR_PAD_LEFT + 1, // == STR_PAD_RIGHT + 2, // == STR_PAD_BOTH + -2, + 2147483647, + -2147483648, + + // float values +/*7*/ 10.5, + -20.5, + 10.1234567e10, + + // string data +/*10*/ "abc", + "STR_PAD_LEFT", + "2", + "0x2", + "02", + + // array values +/*15*/ array(), + array(0), + array(1, 2), + + // boolean values +/*18*/ true, + false, + TRUE, + FALSE, + + // null vlaues +/*22*/ NULL, + null, + + // objects +/*24*/ new sample(), + + // undefined variable +/*25*/ @$undefined_var, + + // unset variable +/*26*/ @$unset_var +); + +//defining '$input' argument +$input = "Test string"; +$pad_length = 20; +$pad_string = "*"; + +// loop through with each element of the $pad_types array to test str_pad() function +$count = 1; +foreach($pad_types as $pad_type) { + echo "-- Iteration $count --\n"; + var_dump( str_pad($input, $pad_length, $pad_string, $pad_type) ); + $count ++; +} + +?> +===DONE=== +--EXPECTF-- +*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument *** +-- Iteration 1 -- +string(20) "*********Test string" +-- Iteration 2 -- +string(20) "Test string*********" +-- Iteration 3 -- +string(20) "****Test string*****" +-- Iteration 4 -- + +Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d +NULL +-- Iteration 5 -- + +Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d +NULL +-- Iteration 6 -- + +Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d +NULL +-- Iteration 7 -- + +Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d +NULL +-- Iteration 8 -- + +Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d +NULL +-- Iteration 9 -- + +Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d +NULL +-- Iteration 10 -- + +Warning: str_pad() expects parameter 4 to be long, string given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: str_pad() expects parameter 4 to be long, string given in %s on line %d +NULL +-- Iteration 12 -- +string(20) "****Test string*****" +-- Iteration 13 -- +string(20) "****Test string*****" +-- Iteration 14 -- +string(20) "****Test string*****" +-- Iteration 15 -- + +Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d +NULL +-- Iteration 18 -- +string(20) "Test string*********" +-- Iteration 19 -- +string(20) "*********Test string" +-- Iteration 20 -- +string(20) "Test string*********" +-- Iteration 21 -- +string(20) "*********Test string" +-- Iteration 22 -- +string(20) "*********Test string" +-- Iteration 23 -- +string(20) "*********Test string" +-- Iteration 24 -- + +Warning: str_pad() expects parameter 4 to be long, object given in %s on line %d +NULL +-- Iteration 25 -- +string(20) "*********Test string" +-- Iteration 26 -- +string(20) "*********Test string" +===DONE=== diff --git a/ext/standard/tests/strings/str_pad_variation5.phpt b/ext/standard/tests/strings/str_pad_variation5.phpt new file mode 100644 index 0000000000..3db2393e84 --- /dev/null +++ b/ext/standard/tests/strings/str_pad_variation5.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test str_pad() function : usage variations - unexpected large value for '$pad_length' argument +--INI-- +memory_limit=128M +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] ) + * Description: Pad a string to a certain length with another string + * Source code: ext/standard/string.c +*/ + +/* Test str_pad() function: with unexpected inputs for '$pad_length' + * and expected type for '$input' +*/ + +echo "*** Testing str_pad() function: with large value for for 'pad_length' argument ***\n"; + +//defining '$input' argument +$input = "Test string"; +$pad_length = PHP_INT_MAX; +var_dump( str_pad($input, $pad_length) ); + +?> +--EXPECTF-- +*** Testing str_pad() function: with large value for for 'pad_length' argument *** + +Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2147483648 bytes) in %s on line %d
\ No newline at end of file diff --git a/ext/standard/tests/strings/str_shuffle_basic.phpt b/ext/standard/tests/strings/str_shuffle_basic.phpt new file mode 100644 index 0000000000..b60a35f560 --- /dev/null +++ b/ext/standard/tests/strings/str_shuffle_basic.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test str_shuffle() function : basic functionality +--FILE-- +<?php +/* Prototype : string str_shuffle ( string $str ) + * Description: Randomly shuffles a string + * Source code: ext/standard/string.c +*/ + +/* + * Testing str_shuffle() : basic functionality +*/ + +echo "*** Testing str_shuffle() : basic functionality ***\n"; + +// Initialize all required variables +$str = 'This testcase tests the str_shuffle() function.'; +var_dump(str_shuffle($str)); + + +// For a given i/p string ensure that all combinations are +// generated given a reasonable sample of calls +$a = array(); +$trys = 1000; +$ip = 'abcd'; +$len_ip = strlen($ip); + +for ($i = 0; $i < $trys; $i++) { + $op = str_shuffle($ip); + + if (!is_string($op) || strlen($op) != $len_ip) { + echo "TEST FAILED\n"; + } + + // Combination already hit ? + if (empty($a[$op])) { + // No first time init + $a[$op] = 0; + } + + // Increment count for this combination + $a[$op]++; +} + +$combinations = count($a); + +if ($combinations != 24) { + echo "TEST FAILED.. Only $combinations out of a possible 24 combinations used\n"; +} else { + echo "TEST PASSED\n"; +} + +?> +===DONE=== +--EXPECTF-- +*** Testing str_shuffle() : basic functionality *** +string(47) "%s" +TEST PASSED +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/strings/str_shuffle_error.phpt b/ext/standard/tests/strings/str_shuffle_error.phpt new file mode 100644 index 0000000000..d8024290e0 --- /dev/null +++ b/ext/standard/tests/strings/str_shuffle_error.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test str_shuffle() function : error conditions +--FILE-- +<?php + +/* Prototype : string str_shuffle ( string $str ) + * Description: Randomly shuffles a string + * Source code: ext/standard/string.c +*/ +echo "*** Testing str_shuffle() : error conditions ***\n"; + +echo "\n-- Testing str_shuffle() function with no arguments --\n"; +var_dump( str_shuffle() ); + +echo "\n-- Testing str_shuffle() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( str_shuffle("Hello World", $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing str_shuffle() : error conditions *** + +-- Testing str_shuffle() function with no arguments -- + +Warning: str_shuffle() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing str_shuffle() function with more than expected no. of arguments -- + +Warning: str_shuffle() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/strings/str_shuffle_variation1.phpt b/ext/standard/tests/strings/str_shuffle_variation1.phpt new file mode 100644 index 0000000000..a6b663d0aa --- /dev/null +++ b/ext/standard/tests/strings/str_shuffle_variation1.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test str_shuffle() function : usage variations - test values for $haystack argument +--FILE-- +<?php + +/* Prototype : string str_shuffle ( string $str ) + * Description: Randomly shuffles a string + * Source code: ext/standard/string.c +*/ + +echo "*** Testing str_shuffle() 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 ( + + // integer values +/*1*/ 0, + 1, + -2, + 2147483647, + -2147483648, + + // float values +/*6*/ 10.5, + -20.5, + 10.1234567e10, + + // 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 +); + + +// loop through with each element of the $inputs array to test str_shuffle() function +$count = 1; +foreach($inputs as $input) { + echo "-- Iteration $count --\n"; + var_dump( str_shuffle($input) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing str_shuffle() function: with unexpected inputs for 'string' argument *** +-- Iteration 1 -- +string(1) "0" +-- Iteration 2 -- +string(1) "1" +-- Iteration 3 -- +string(2) "%s" +-- Iteration 4 -- +string(10) "%s" +-- Iteration 5 -- +string(11) "%s" +-- Iteration 6 -- +string(4) "%s" +-- Iteration 7 -- +string(5) "%s" +-- Iteration 8 -- +string(12) "%s" +-- Iteration 9 -- + +Warning: str_shuffle() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: str_shuffle() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: str_shuffle() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 12 -- +string(1) "1" +-- Iteration 13 -- +string(0) "" +-- Iteration 14 -- +string(1) "1" +-- Iteration 15 -- +string(0) "" +-- Iteration 16 -- +string(0) "" +-- Iteration 17 -- +string(0) "" +-- Iteration 18 -- +string(13) "%s" +-- Iteration 19 -- + +Warning: str_shuffle() expects parameter 1 to be string, resource given in %s on line %d +NULL +-- Iteration 20 -- +string(0) "" +-- Iteration 21 -- +string(0) "" +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/strings/stristr_basic.phpt b/ext/standard/tests/strings/stristr_basic.phpt new file mode 100644 index 0000000000..f0a863cee9 --- /dev/null +++ b/ext/standard/tests/strings/stristr_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test stristr() function : basic functionality +--FILE-- +<?php +/* Prototype: string stristr ( string $haystack , mixed $needle [, bool $before_needle ] ) + Description: Case-insensitive strstr(). +*/ + +echo "*** Testing stristr() : basic functionality ***\n"; + +var_dump( stristr("Test string", "teSt") ); +var_dump( stristr("test stRIng", "striNG") ); +var_dump( stristr("teST StrinG", "stRIn") ); +var_dump( stristr("tesT string", "t S") ); +var_dump( stristr("test strinG", "g") ); +var_dump( bin2hex(stristr(b"te".chr(0).b"St", chr(0))) ); +var_dump( stristr("tEst", "test") ); +var_dump( stristr("teSt", "test") ); + +var_dump( stristr("Test String", "String", false) ); +var_dump( stristr("Test String", "String", true) ); +?> +===DONE=== +--EXPECTF-- +*** Testing stristr() : basic functionality *** +string(11) "Test string" +string(6) "stRIng" +string(6) "StrinG" +string(8) "T string" +string(1) "G" +string(6) "005374" +string(4) "tEst" +string(4) "teSt" +string(6) "String" +string(5) "Test " +===DONE=== diff --git a/ext/standard/tests/strings/stristr_error.phpt b/ext/standard/tests/strings/stristr_error.phpt new file mode 100644 index 0000000000..831d93f4ec --- /dev/null +++ b/ext/standard/tests/strings/stristr_error.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test stristr() function : error conditions +--FILE-- +<?php + +/* Prototype: string stristr ( string $haystack , mixed $needle [, bool $before_needle ] ) + Description: Case-insensitive strstr() +*/ +echo "*** Testing stristr() : error conditions ***\n"; + +echo "\n-- Testing stristr() function with no arguments --\n"; +var_dump( stristr() ); +var_dump( stristr("") ); + +echo "\n-- Testing stristr() function with no needle --\n"; +var_dump( stristr("Hello World") ); // without "needle" + +echo "\n-- Testing stristr() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( stristr("Hello World", "World", true, $extra_arg) ); + +echo "\n-- Testing stristr() function with empty haystack --\n"; +var_dump( stristr(NULL, "") ); + +echo "\n-- Testing stristr() function with empty needle --\n"; +var_dump( stristr("Hello World", "") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing stristr() : error conditions *** + +-- Testing stristr() function with no arguments -- + +Warning: stristr() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: stristr() expects at least 2 parameters, 1 given in %s on line %d +NULL + +-- Testing stristr() function with no needle -- + +Warning: stristr() expects at least 2 parameters, 1 given in %s on line %d +NULL + +-- Testing stristr() function with more than expected no. of arguments -- + +Warning: stristr() expects at most 3 parameters, 4 given in %s on line %d +NULL + +-- Testing stristr() function with empty haystack -- + +Warning: stristr(): Empty delimiter in %s on line %d +bool(false) + +-- Testing stristr() function with empty needle -- + +Warning: stristr(): Empty delimiter in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/strings/stristr_variation1.phpt b/ext/standard/tests/strings/stristr_variation1.phpt new file mode 100644 index 0000000000..b50c937266 --- /dev/null +++ b/ext/standard/tests/strings/stristr_variation1.phpt @@ -0,0 +1,131 @@ +--TEST-- +Test stristr() function : usage variations - test values for $haystack argument +--FILE-- +<?php + +/* Prototype: string stristr ( string $haystack, string $needle ); + Description: Case-insensitive strstr(). +*/ + +echo "*** Testing stristr() 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 ( + + // integer values +/*1*/ 0, + 1, + -2, + -PHP_INT_MAX, + + // float values +/*5*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*8*/ array(), + array(0), + array(1, 2), + + // boolean values +/*11*/ true, + false, + TRUE, + FALSE, + + // null vlaues +/*15*/ NULL, + null, + + // objects +/*17*/ new sample(), + + // resource +/*18*/ $file_handle, + + // undefined variable +/*19*/ @$undefined_var, + + // unset variable +/*20*/ @$unset_var +); + +//defining '$pad_length' argument +$pad_length = "20"; + +// loop through with each element of the $inputs array to test stristr() function +$count = 1; +foreach($inputs as $input) { + echo "-- Iteration $count --\n"; + var_dump( stristr($input, " ") ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing stristr() function: with unexpected inputs for 'string' argument *** +-- Iteration 1 -- +bool(false) +-- Iteration 2 -- +bool(false) +-- Iteration 3 -- +bool(false) +-- Iteration 4 -- +bool(false) +-- Iteration 5 -- +bool(false) +-- Iteration 6 -- +bool(false) +-- Iteration 7 -- +bool(false) +-- Iteration 8 -- + +Notice: Array to string conversion in %s on line %d2 +bool(false) +-- Iteration 9 -- + +Notice: Array to string conversion in %s on line %d2 +bool(false) +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d2 +bool(false) +-- Iteration 11 -- +bool(false) +-- Iteration 12 -- +bool(false) +-- Iteration 13 -- +bool(false) +-- Iteration 14 -- +bool(false) +-- Iteration 15 -- +bool(false) +-- Iteration 16 -- +bool(false) +-- Iteration 17 -- +string(7) " object" +-- Iteration 18 -- +string(%d) " id #%d" +-- Iteration 19 -- +bool(false) +-- Iteration 20 -- +bool(false) +===DONE=== diff --git a/ext/standard/tests/strings/stristr_variation2.phpt b/ext/standard/tests/strings/stristr_variation2.phpt new file mode 100644 index 0000000000..7d1d2feb21 --- /dev/null +++ b/ext/standard/tests/strings/stristr_variation2.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test stristr() function : usage variations - test values for $needle argument +--FILE-- +<?php + +/* Prototype: string stristr ( string $haystack, string $needle ); + Description: Case-insensitive strstr(). +*/ + +echo "*** Testing stristr() function: with unexpected inputs for 'needle' 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 ( + + // integer values +/*1*/ 0, + 1, + -2, + -PHP_INT_MAX, + + // float values +/*5*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*8*/ array(), + array(0), + array(1, 2), + + // boolean values +/*11*/ true, + false, + TRUE, + FALSE, + + // null vlaues +/*15*/ NULL, + null, + + // objects +/*17*/ new sample(), + + // resource +/*18*/ $file_handle, + + // undefined variable +/*19*/ @$undefined_var, + + // unset variable +/*20*/ @$unset_var +); + +//defining '$pad_length' argument +$pad_length = "20"; + +// loop through with each element of the $inputs array to test stristr() function +$count = 1; +foreach($inputs as $input) { + echo "-- Iteration $count --\n"; + var_dump( stristr("Hello World", $input) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing stristr() function: with unexpected inputs for 'needle' argument *** +-- Iteration 1 -- +bool(false) +-- Iteration 2 -- +bool(false) +-- Iteration 3 -- +bool(false) +-- Iteration 4 -- +bool(false) +-- Iteration 5 -- +bool(false) +-- Iteration 6 -- +bool(false) +-- Iteration 7 -- +bool(false) +-- Iteration 8 -- +bool(false) +-- Iteration 9 -- +bool(false) +-- Iteration 10 -- +bool(false) +-- Iteration 11 -- +bool(false) +-- Iteration 12 -- +bool(false) +-- Iteration 13 -- +bool(false) +-- Iteration 14 -- +bool(false) +-- Iteration 15 -- +bool(false) +-- Iteration 16 -- +bool(false) +-- Iteration 17 -- + +Notice: Object of class sample could not be converted to int in %s on line %d +bool(false) +-- Iteration 18 -- +%s +-- Iteration 19 -- +bool(false) +-- Iteration 20 -- +bool(false) +===DONE=== diff --git a/ext/standard/tests/strings/strlen_basic.phpt b/ext/standard/tests/strings/strlen_basic.phpt new file mode 100644 index 0000000000..3ed2b97e56 --- /dev/null +++ b/ext/standard/tests/strings/strlen_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test strlen() function : basic functionality +--FILE-- +<?php + +/* Prototype : int strlen ( string $string ) + * Description: Get string length + * Source code: ext/standard/string.c +*/ + +echo "*** Testing strlen() : basic functionality ***\n"; +var_dump(strlen("abcdef")); +var_dump(strlen(" ab de ")); +var_dump(strlen("")); +var_dump(strlen("\x90\x91\x00\x93\x94\x90\x91\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f")); +?> +===DONE=== +--EXPECTF-- +*** Testing strlen() : basic functionality *** +int(6) +int(7) +int(0) +int(18) +===DONE=== diff --git a/ext/standard/tests/strings/strlen_error.phpt b/ext/standard/tests/strings/strlen_error.phpt new file mode 100644 index 0000000000..552e7c1ca6 --- /dev/null +++ b/ext/standard/tests/strings/strlen_error.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test strlen() function : error conditions +--FILE-- +<?php + +/* Prototype : int strlen ( string $string ) + * Description: Get string length + * Source code: ext/standard/string.c +*/ + +echo "*** Testing strlen() : unexpected number of arguments ***"; + + +echo "\n-- Testing strlen() function with no arguments --\n"; +var_dump( strlen() ); + +echo "\n-- Testing strlen() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( strlen("abc def", $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing strlen() : unexpected number of arguments *** +-- Testing strlen() function with no arguments -- + +Warning: strlen() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing strlen() function with more than expected no. of arguments -- + +Warning: strlen() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/strings/strlen_variation1.phpt b/ext/standard/tests/strings/strlen_variation1.phpt new file mode 100644 index 0000000000..9ba138e57c --- /dev/null +++ b/ext/standard/tests/strings/strlen_variation1.phpt @@ -0,0 +1,137 @@ +--TEST-- +Test strlen() function : usage variations - unexpected input for '$string' argument +--FILE-- +<?php + +/* Prototype : int strlen ( string $string ) + * Description: Get string length + * Source code: ext/standard/string.c +*/ + +echo "*** Testing strlen() : with unexpected input 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 ( + + // integer values +/*1*/ 0, + 1, + -2, + 2147483647, + -2147483648, + + // float values +/*6*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*9*/ array(), + array(0), + array(1, 2), + + // boolean values +/*12*/ true, + false, + TRUE, + FALSE, + + // null values +/*16*/ NULL, + null, + + // objects +/*18*/ new sample(), + + // resource +/*19*/ $file_handle, + + // undefined variable +/*20*/ @$undefined_var, + + // unset variable +/*21*/ @$unset_var +); + +//defining '$pad_length' argument +$pad_length = "20"; + +// loop through with each element of the $inputs array to test strlen() function +$count = 1; +foreach($inputs as $input) { + echo "-- Iteration $count --\n"; + var_dump( strlen($input) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +?> +===DONE=== +--EXPECTF-- +*** Testing strlen() : with unexpected input for 'string' argument *** +-- Iteration 1 -- +int(1) +-- Iteration 2 -- +int(1) +-- Iteration 3 -- +int(2) +-- Iteration 4 -- +int(10) +-- Iteration 5 -- +int(11) +-- Iteration 6 -- +int(4) +-- Iteration 7 -- +int(5) +-- Iteration 8 -- +int(12) +-- Iteration 9 -- + +Warning: strlen() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: strlen() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: strlen() expects parameter 1 to be string, array given in %s on line %d +NULL +-- Iteration 12 -- +int(1) +-- Iteration 13 -- +int(0) +-- Iteration 14 -- +int(1) +-- Iteration 15 -- +int(0) +-- Iteration 16 -- +int(0) +-- Iteration 17 -- +int(0) +-- Iteration 18 -- +int(13) +-- Iteration 19 -- + +Warning: strlen() expects parameter 1 to be string, resource given in %s on line %d +NULL +-- Iteration 20 -- +int(0) +-- Iteration 21 -- +int(0) +===DONE=== diff --git a/ext/standard/tests/strings/strtr_variation5.phpt b/ext/standard/tests/strings/strtr_variation5.phpt index 7c99e5b9ee..c90e028069 100644 --- a/ext/standard/tests/strings/strtr_variation5.phpt +++ b/ext/standard/tests/strings/strtr_variation5.phpt @@ -31,42 +31,42 @@ $file_handle = fopen(__FILE__, "r"); // array with different values $strings = array ( - // integer values - 0, - 1, - -2, - - // float values - 10.5, - -20.5, - 10.5e10, - - // array values - array(), - array(0), - array(1, 2), - - // boolean values - true, - false, - TRUE, - FALSE, - - // null vlaues - NULL, - null, - - // objects - new sample(), - - // resource - $file_handle, - - // undefined variable - @$undefined_var, - - // unset variable - @$unset_var + // integer values +/*1*/ 0, + 1, + -2, + + // float values +/*4*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*7*/ array(), + array(0), + array(1, 2), + + // boolean values +/*10*/ true, + false, + TRUE, + FALSE, + + // null vlaues +/*14*/ NULL, + null, + + // objects +/*16*/ new sample(), + + // resource +/*17*/ $file_handle, + + // undefined variable +/*18*/ @$undefined_var, + + // unset variable +/*19*/ @$unset_var ); //defining 'from' argument @@ -86,8 +86,8 @@ for($index = 0; $index < count($strings); $index++) { fclose($file_handle); //closing the file handle -echo "*** Done ***"; ?> +===DONE=== --EXPECTF-- *** Testing strtr() function: with unexpected inputs for 'str' *** -- Iteration 1 -- @@ -101,7 +101,7 @@ string(4) "ta.5" -- Iteration 5 -- string(5) "-ma.5" -- Iteration 6 -- -string(12) "ta5aaaaaaaaa" +string(12) "tatm34567aaa" -- Iteration 7 -- Warning: strtr() expects parameter 1 to be string, array given in %s on line %d @@ -136,4 +136,4 @@ NULL string(0) "" -- Iteration 19 -- string(0) "" -*** Done *** +===DONE=== diff --git a/ext/standard/tests/strings/strtr_variation6.phpt b/ext/standard/tests/strings/strtr_variation6.phpt index 2d8ab71831..46f9e78c72 100644 --- a/ext/standard/tests/strings/strtr_variation6.phpt +++ b/ext/standard/tests/strings/strtr_variation6.phpt @@ -34,42 +34,42 @@ $str = "012atm"; // array of values for 'from' $from_arr = array ( - // integer values - 0, - 1, - -2, - - // float values - 10.5, - -20.5, - 10.5e10, - - // array values - array(), - array(0), - array(1, 2), - - // boolean values - true, - false, - TRUE, - FALSE, - - // null vlaues - NULL, - null, - - // objects - new sample(), - - // resource - $file_handle, - - // undefined variable - @$undefined_var, - - // unset variable - @$unset_var + // integer values +/*1*/ 0, + 1, + -2, + + // float values +/*4*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*7*/ array(), + array(0), + array(1, 2), + + // boolean values +/*10*/ true, + false, + TRUE, + FALSE, + + // null vlaues +/*14*/ NULL, + null, + + // objects +/*16*/ new sample(), + + // resource +/*17*/ $file_handle, + + // undefined variable +/*18*/ @$undefined_var, + + // unset variable +/*19*/ @$unset_var ); //defining 'to' argument @@ -85,9 +85,8 @@ for($index = 0; $index < count($from_arr); $index++) { } fclose($file_handle); //closing the file handle - -echo "*** Done ***"; ?> +===DONE=== --EXPECTF-- *** Testing strtr() function: with unexpected inputs for 'from' *** -- Iteration 1 -- @@ -101,7 +100,7 @@ string(6) "ta2atm" -- Iteration 5 -- string(6) "m1tatm" -- Iteration 6 -- -string(6) "2a2atm" +string(6) "tm0atm" -- Iteration 7 -- Notice: Array to string conversion in %s on line %d @@ -134,4 +133,4 @@ string(6) "012atm" string(6) "012atm" -- Iteration 19 -- string(6) "012atm" -*** Done *** +===DONE=== diff --git a/ext/standard/tests/strings/strtr_variation7.phpt b/ext/standard/tests/strings/strtr_variation7.phpt index cf7e777cee..fa2a5eb3c3 100644 --- a/ext/standard/tests/strings/strtr_variation7.phpt +++ b/ext/standard/tests/strings/strtr_variation7.phpt @@ -37,42 +37,42 @@ $from = "atm012"; // array of values for 'to' argument $to_arr = array ( - // integer values - 0, - 1, - -2, - - // float values - 10.5, - -20.5, - 10.5e10, - - // array values - array(), - array(0), - array(1, 2), - - // boolean values - true, - false, - TRUE, - FALSE, - - // null vlaues - NULL, - null, - - // objects - new sample(), - - // resource - $file_handle, - - // undefined variable - @$undefined_var, - - // unset variable - @$unset_var + // integer values +/*1*/ 0, + 1, + -2, + + // float values +/*4*/ 10.5, + -20.5, + 10.12345675e10, + + // array values +/*7*/ array(), + array(0), + array(1, 2), + + // boolean values +/*10*/ true, + false, + TRUE, + FALSE, + + // null vlaues +/*14*/ NULL, + null, + + // objects +/*16*/ new sample(), + + // resource +/*17*/ $file_handle, + + // undefined variable +/*18*/ @$undefined_var, + + // unset variable +/*19*/ @$unset_var ); // loop through with each element of the $to array to test strtr() function @@ -86,8 +86,8 @@ for($index = 0; $index < count($to_arr); $index++) { fclose($file_handle); //closing the file handle -echo "*** Done ***"; ?> +===DONE=== --EXPECTF-- *** Testing strtr() function: with unexpected inputs for 'to' *** @@ -107,7 +107,7 @@ string(6) "51210." string(6) ".52-20" -- Iteration 6 -- -string(6) "000105" +string(6) "234101" -- Iteration 7 -- @@ -155,4 +155,4 @@ string(6) "012atm" -- Iteration 19 -- string(6) "012atm" -*** Done *** +===DONE=== diff --git a/ext/standard/tests/strings/strtr_variation9.phpt b/ext/standard/tests/strings/strtr_variation9.phpt index 835b8b3fa7..c7d4d99581 100644 --- a/ext/standard/tests/strings/strtr_variation9.phpt +++ b/ext/standard/tests/strings/strtr_variation9.phpt @@ -29,44 +29,44 @@ $file_handle = fopen(__FILE__, "r"); // array with different values $values = array ( - // integer values - 0, - 1, - -2, - - // float values - 10.5, - -20.5, - 10.5e10, - - // array values - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // boolean values - true, - false, - TRUE, - FALSE, - - // null vlaues - NULL, - null, - - // objects - new sample(), - - // resource - $file_handle, - - // undefined variable - @$undefined_var, - - // unset variable - @$unset_var + // integer values +/*1*/ 0, + 1, + -2, + + // float values +/*4*/ 10.5, + -20.5, + 10.1234567e10, + + // array values +/*7*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // 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 ); // loop through with each element of the $values array to test strtr() function @@ -80,8 +80,8 @@ for($index = 0; $index < count($values); $index++) { fclose($file_handle); //closing the file handle -echo "*** Done ***"; ?> +===DONE=== --EXPECTF-- *** Testing strtr() function: with unexpected inputs for all arguments *** @@ -116,7 +116,7 @@ Warning: strtr(): The second argument is not an array in %s on line %d bool(false) -- Iteration 6 -- -string(12) "105000000000" +string(12) "101234567000" Warning: strtr(): The second argument is not an array in %s on line %d bool(false) @@ -222,4 +222,4 @@ string(0) "" Warning: strtr(): The second argument is not an array in %s on line %d bool(false) -*** Done *** +===DONE=== |