kraghuba Sat Sep 22 07:41:14 2007 UTC Modified files: /php-src/ext/standard/tests/strings strtok_basic.phpt strtok_variation1.phpt strtok_variation2.phpt strtok_variation3.phpt strtok_variation4.phpt strtok_variation5.phpt strtok_error.phpt strtok_variation6.phpt strtok_variation7.phpt Log: New testcases for strtok() function
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_basic.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_basic.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_basic.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_basic.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,94 @@ +--TEST-- +Test strtok() function : basic functionality +--FILE-- +<?php +/* Prototype : string strtok ( str $str, str $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() : basic functionality +*/ + +echo "*** Testing strtok() : basic functionality ***\n"; + +// Initialize all required variables +$str = 'This testcase test strtok() function.'; +$token = ' ().'; + +echo "\nThe Input string is:\n\"$str\"\n"; +echo "\nThe token string is:\n\"$token\"\n"; + +// using strtok() with $str argument +echo "\n--- Token 1 ---\n"; +var_dump( strtok($str, $token) ); + +for( $i = 2; $i <=7; $i++ ) { + echo "\n--- Token $i ---\n"; + var_dump( strtok($token) ); +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : basic functionality *** + +The Input string is: +"This testcase test strtok() function." + +The token string is: +" ()." + +--- Token 1 --- +string(4) "This" + +--- Token 2 --- +string(8) "testcase" + +--- Token 3 --- +string(4) "test" + +--- Token 4 --- +string(6) "strtok" + +--- Token 5 --- +string(8) "function" + +--- Token 6 --- +bool(false) + +--- Token 7 --- +bool(false) +Done + +--UEXPECTF-- +*** Testing strtok() : basic functionality *** + +The Input string is: +"This testcase test strtok() function." + +The token string is: +" ()." + +--- Token 1 --- +unicode(4) "This" + +--- Token 2 --- +unicode(8) "testcase" + +--- Token 3 --- +unicode(4) "test" + +--- Token 4 --- +unicode(6) "strtok" + +--- Token 5 --- +unicode(8) "function" + +--- Token 6 --- +bool(false) + +--- Token 7 --- +bool(false) +Done \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation1.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation1.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_variation1.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_variation1.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,248 @@ +--TEST-- +Test strtok() function : usage variations - first argument as non-string +--FILE-- +<?php +/* Prototype : string strtok ( string $str, string $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() : with first argument as non-string +*/ + +echo "*** Testing strtok() : with first argument as non-string ***\n"; +// initialize all required variables +$token = '-'; + +// get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +// declaring a class +class sample { + public function __toString() { + return "obj-ect"; + } +} + +// Defining resource +$file_handle = fopen(__FILE__, 'r'); + +// array with different values +$values = array ( + + // integer values + 0, + 1, + 12345, + -2345, + + // float values + 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // array values + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red-color', 'item' => 'pen-color'), + + // boolean values + true, + false, + TRUE, + FALSE, + + // objects + new sample(), + + // empty string + "", + '', + + // null vlaues + NULL, + null, + + // undefined variable + $undefined_var, + + // unset variable + $unset_var, + + // resource + $file_handle +); + + +// loop through each element of the array and check the working of strtok() +// when $str arugment is supplied with different values + +echo "\n--- Testing strtok() by supplying different values for 'str' argument ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) { + echo "-- Iteration $counter --\n"; + $str = $values [$index]; + + var_dump( strtok($str, $token) ); + + $counter ++; +} + +//closing the resource +fclose($file_handle); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with first argument as non-string *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +--- Testing strtok() by supplying different values for 'str' argument --- +-- Iteration 1 -- +string(1) "0" +-- Iteration 2 -- +string(1) "1" +-- Iteration 3 -- +string(5) "12345" +-- Iteration 4 -- +string(4) "2345" +-- Iteration 5 -- +string(4) "10.5" +-- Iteration 6 -- +string(4) "10.5" +-- Iteration 7 -- +string(12) "105000000000" +-- Iteration 8 -- +string(5) "1.06E" +-- Iteration 9 -- +string(3) "0.5" +-- Iteration 10 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 15 -- +string(1) "1" +-- Iteration 16 -- +bool(false) +-- Iteration 17 -- +string(1) "1" +-- Iteration 18 -- +bool(false) +-- Iteration 19 -- +string(3) "obj" +-- Iteration 20 -- +bool(false) +-- Iteration 21 -- +bool(false) +-- Iteration 22 -- +bool(false) +-- Iteration 23 -- +bool(false) +-- Iteration 24 -- +bool(false) +-- Iteration 25 -- +bool(false) +-- Iteration 26 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d +NULL +Done + +--UEXPECTF-- +*** Testing strtok() : with first argument as non-string *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +--- Testing strtok() by supplying different values for 'str' argument --- +-- Iteration 1 -- +unicode(1) "0" +-- Iteration 2 -- +unicode(1) "1" +-- Iteration 3 -- +unicode(5) "12345" +-- Iteration 4 -- +unicode(4) "2345" +-- Iteration 5 -- +unicode(4) "10.5" +-- Iteration 6 -- +unicode(4) "10.5" +-- Iteration 7 -- +unicode(12) "105000000000" +-- Iteration 8 -- +unicode(5) "1.06E" +-- Iteration 9 -- +unicode(3) "0.5" +-- Iteration 10 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 15 -- +unicode(1) "1" +-- Iteration 16 -- +bool(false) +-- Iteration 17 -- +unicode(1) "1" +-- Iteration 18 -- +bool(false) +-- Iteration 19 -- +unicode(3) "obj" +-- Iteration 20 -- +bool(false) +-- Iteration 21 -- +bool(false) +-- Iteration 22 -- +bool(false) +-- Iteration 23 -- +bool(false) +-- Iteration 24 -- +bool(false) +-- Iteration 25 -- +bool(false) +-- Iteration 26 -- + +Warning: strtok() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d +NULL +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation2.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation2.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_variation2.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_variation2.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,248 @@ +--TEST-- +Test strtok() function : usage variations - with different token strings +--FILE-- +<?php +/* Prototype : string strtok ( str $str, str $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() : with different token strings +*/ + +echo "*** Testing strtok() : with different token strings ***\n"; +// initialize all required variables +$str = 'this testcase test strtok() function '; + +// get an unset variable +$unset_var = 'string_val'; +unset($unset_var); + +// declaring a class +class sample { + public function __toString() { + return "obj-ect"; + } +} + +// Defining resource +$file_handle = fopen(__FILE__, 'r'); + +// array with different values +$values = array ( + + // integer values + 0, + 1, + 12345, + -2345, + + // float values + 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // array values + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // boolean values + true, + false, + TRUE, + FALSE, + + // objects + new sample(), + + // empty string + "", + '', + + // null vlaues + NULL, + null, + + // undefined variable + $undefined_var, + + // unset variable + $unset_var, + + // resource + $file_handle +); + + +// loop through each element of the array and check the working of strtok() +// when $token arugment is supplied with different values + +echo "\n--- Testing strtok() by supplying different values for 'token' argument ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) { + echo "-- Iteration $counter --\n"; + $token = $values [$index]; + + var_dump( strtok($str, $token) ); + + $counter ++; +} + +// closing the resource +fclose($file_handle); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with different token strings *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +--- Testing strtok() by supplying different values for 'token' argument --- +-- Iteration 1 -- +string(37) "this testcase test strtok() function " +-- Iteration 2 -- +string(37) "this testcase test strtok() function " +-- Iteration 3 -- +string(37) "this testcase test strtok() function " +-- Iteration 4 -- +string(37) "this testcase test strtok() function " +-- Iteration 5 -- +string(37) "this testcase test strtok() function " +-- Iteration 6 -- +string(37) "this testcase test strtok() function " +-- Iteration 7 -- +string(37) "this testcase test strtok() function " +-- Iteration 8 -- +string(37) "this testcase test strtok() function " +-- Iteration 9 -- +string(37) "this testcase test strtok() function " +-- Iteration 10 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 15 -- +string(37) "this testcase test strtok() function " +-- Iteration 16 -- +string(37) "this testcase test strtok() function " +-- Iteration 17 -- +string(37) "this testcase test strtok() function " +-- Iteration 18 -- +string(37) "this testcase test strtok() function " +-- Iteration 19 -- +string(4) "his " +-- Iteration 20 -- +string(37) "this testcase test strtok() function " +-- Iteration 21 -- +string(37) "this testcase test strtok() function " +-- Iteration 22 -- +string(37) "this testcase test strtok() function " +-- Iteration 23 -- +string(37) "this testcase test strtok() function " +-- Iteration 24 -- +string(37) "this testcase test strtok() function " +-- Iteration 25 -- +string(37) "this testcase test strtok() function " +-- Iteration 26 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), resource given in %s on line %d +NULL +Done + +--UEXPECTF-- +*** Testing strtok() : with different token strings *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +--- Testing strtok() by supplying different values for 'token' argument --- +-- Iteration 1 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 2 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 3 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 4 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 5 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 6 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 7 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 8 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 9 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 10 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL +-- Iteration 15 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 16 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 17 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 18 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 19 -- +unicode(4) "his " +-- Iteration 20 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 21 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 22 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 23 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 24 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 25 -- +unicode(37) "this testcase test strtok() function " +-- Iteration 26 -- + +Warning: strtok() expects parameter 2 to be string (Unicode or binary), resource given in %s on line %d +NULL +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation3.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation3.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_variation3.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_variation3.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,232 @@ +--TEST-- +Test strtok() function : usage variations - with heredoc strings +--FILE-- +<?php +/* Prototype : string strtok ( str $str, str $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() : with heredoc strings +*/ + +echo "*** Testing strtok() : with heredoc strings ***\n"; + +// defining different heredoc strings +$empty_heredoc = <<<EOT +EOT; + +$heredoc_with_newline = <<<EOT +\n + +EOT; + +$heredoc_with_characters = <<<EOT +first line of heredoc string +second line of heredoc string +third line of heredocstring +EOT; + +$heredoc_with_newline_and_tabs = <<<EOT +hello\tworld\nhello\nworld\n +EOT; + +$heredoc_with_alphanumerics = <<<EOT +hello123world456 +1234hello\t1234 +EOT; + +$heredoc_with_embedded_nulls = <<<EOT +hello\0world\0hello +\0hello\0 +EOT; + +$heredoc_strings = array( + $empty_heredoc, + $heredoc_with_newline, + $heredoc_with_characters, + $heredoc_with_newline_and_tabs, + $heredoc_with_alphanumerics, + $heredoc_with_embedded_nulls + ); + +// loop through each element of the array and check the working of strtok() +// when supplied with different string values + +$count = 1; +foreach($heredoc_strings as $string) { + echo "\n--- Iteration $count ---\n"; + var_dump( strtok($string, "5o\0\n\t") ); + for($counter = 1; $counter <= 10; $counter++) { + var_dump( strtok("5o\0\n\t") ); + } + $count++; +} + + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with heredoc strings *** + +--- Iteration 1 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +string(11) "first line " +string(7) "f hered" +string(8) "c string" +string(3) "sec" +string(8) "nd line " +string(7) "f hered" +string(8) "c string" +string(11) "third line " +string(7) "f hered" +string(7) "cstring" +bool(false) + +--- Iteration 4 --- +string(4) "hell" +string(1) "w" +string(3) "rld" +string(4) "hell" +string(1) "w" +string(3) "rld" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +string(4) "hell" +string(4) "123w" +string(4) "rld4" +string(1) "6" +string(8) "1234hell" +string(4) "1234" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +string(4) "hell" +string(1) "w" +string(3) "rld" +string(4) "hell" +string(4) "hell" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done + +--UEXPECTF-- +*** Testing strtok() : with heredoc strings *** + +--- Iteration 1 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +unicode(11) "first line " +unicode(7) "f hered" +unicode(8) "c string" +unicode(3) "sec" +unicode(8) "nd line " +unicode(7) "f hered" +unicode(8) "c string" +unicode(11) "third line " +unicode(7) "f hered" +unicode(7) "cstring" +bool(false) + +--- Iteration 4 --- +unicode(4) "hell" +unicode(1) "w" +unicode(3) "rld" +unicode(4) "hell" +unicode(1) "w" +unicode(3) "rld" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +unicode(4) "hell" +unicode(4) "123w" +unicode(4) "rld4" +unicode(1) "6" +unicode(8) "1234hell" +unicode(4) "1234" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +unicode(4) "hell" +unicode(1) "w" +unicode(3) "rld" +unicode(4) "hell" +unicode(4) "hell" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation4.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation4.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_variation4.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_variation4.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,178 @@ +--TEST-- +Test strtok() function : usage variations - with embedded nulls in the strings +--FILE-- +<?php +/* Prototype : string strtok ( str $str, str $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() : with embedded nulls in the strings +*/ + +echo "*** Testing strtok() : with embedded nulls in the strings ***\n"; + +// defining varous strings with embedded nulls +$strings_with_nulls = array( + "\0", + '\0', + "hello\0world", + "\0hel\0lo", + "hello\0", + "\0\0hello\tworld\0\0", + "\\0he\0llo\\0", + 'hello\0\0' + ); + +// loop through each element of the array and check the working of strtok() +// when supplied with different string values + +$counter = 1; +foreach( $strings_with_nulls as $string ) { + echo "\n--- Iteration $counter ---\n"; + var_dump( strtok($string, "\0") ); + for($count = 1; $count <= 5; $count++) { + var_dump( strtok("\0") ); + } + $counter++; +} + + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with embedded nulls in the strings *** + +--- Iteration 1 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +string(2) "\0" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +string(5) "hello" +string(5) "world" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 4 --- +string(3) "hel" +string(2) "lo" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +string(5) "hello" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +string(11) "hello world" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 7 --- +string(4) "\0he" +string(5) "llo\0" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 8 --- +string(9) "hello\0\0" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done + +--UEXPECTF-- +*** Testing strtok() : with embedded nulls in the strings *** + +--- Iteration 1 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +unicode(2) "\0" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +unicode(5) "hello" +unicode(5) "world" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 4 --- +unicode(3) "hel" +unicode(2) "lo" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +unicode(5) "hello" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +unicode(11) "hello world" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 7 --- +unicode(4) "\0he" +unicode(5) "llo\0" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 8 --- +unicode(9) "hello\0\0" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation5.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation5.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_variation5.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_variation5.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,242 @@ +--TEST-- +Test strtok() function : usage variations - miscellaneous inputs +--FILE-- +<?php +/* Prototype : string strtok ( str $str, str $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() : with miscellaneous combinations of string and token +*/ + +echo "*** Testing strtok() : with miscellaneous inputs ***\n"; + +// defining arrays for input strings and tokens +$string_array = array( + "HELLO WORLD", + "hello world", + "_HELLO_WORLD_", + "/thello/t/wor/ttld", + "hel/lo/t/world", + "one:$:two:!:three:#:four", + "\rhello/r/wor\rrld", + chr(0), + chr(0).chr(0), + chr(0).'hello'.chr(0), + 'hello'.chr(0).'world' + ); +$token_array = array( + "wr", + "hello world", + "__", + "t/", + '/t', + ":", + "\r", + "\0", + "\0", + "\0", + "\0" + ); + +// loop through each element of the array and check the working of strtok() +// when supplied with different string and token values + +$counter =1; +foreach( $string_array as $string ) { + echo "\n--- Iteration $counter ---\n"; + var_dump( strtok($string, $token_array[$counter-1]) ); + for( $count = 1; $count <=5; $count++ ) { + var_dump( strtok($token_array[$counter-1]) ); + } + $counter++; +} + + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with miscellaneous inputs *** + +--- Iteration 1 --- +string(11) "HELLO WORLD" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +string(5) "HELLO" +string(5) "WORLD" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 4 --- +string(5) "hello" +string(3) "wor" +string(2) "ld" +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +string(3) "hel" +string(2) "lo" +string(5) "world" +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +string(3) "one" +string(1) "$" +string(3) "two" +string(1) "!" +string(5) "three" +string(1) "#" + +--- Iteration 7 --- +string(11) "hello/r/wor" +string(3) "rld" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 8 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 9 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 10 --- +string(5) "hello" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 11 --- +string(5) "hello" +string(5) "world" +bool(false) +bool(false) +bool(false) +bool(false) +Done + +--UEXPECTF-- +*** Testing strtok() : with miscellaneous inputs *** + +--- Iteration 1 --- +unicode(11) "HELLO WORLD" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +unicode(5) "HELLO" +unicode(5) "WORLD" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 4 --- +unicode(5) "hello" +unicode(3) "wor" +unicode(2) "ld" +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +unicode(3) "hel" +unicode(2) "lo" +unicode(5) "world" +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +unicode(3) "one" +unicode(1) "$" +unicode(3) "two" +unicode(1) "!" +unicode(5) "three" +unicode(1) "#" + +--- Iteration 7 --- +unicode(11) "hello/r/wor" +unicode(3) "rld" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 8 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 9 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 10 --- +unicode(5) "hello" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 11 --- +unicode(5) "hello" +unicode(5) "world" +bool(false) +bool(false) +bool(false) +bool(false) +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_error.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_error.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_error.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,74 @@ +--TEST-- +Test strtok() function : error conditions +--FILE-- +<?php +/* Prototype : string strtok ( string $str, string $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() for error conditions +*/ + +echo "*** Testing strtok() : error conditions ***\n"; + +// Zero argument +echo "\n-- Testing strtok() function with Zero arguments --\n"; +var_dump( strtok() ); + +// More than expected number of arguments +echo "\n-- Testing strtok() function with more than expected no. of arguments --\n"; +$str = 'sample string'; +$token = ' '; +$extra_arg = 10; + +var_dump( strtok($str, $token, $extra_arg) ); +var_dump( $str ); + +// Less than expected number of arguments +echo "\n-- Testing strtok() with less than expected no. of arguments --\n"; +$str = 'string val'; + +var_dump( strtok($str)); +var_dump( $str ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : error conditions *** + +-- Testing strtok() function with Zero arguments -- + +Warning: strtok() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing strtok() function with more than expected no. of arguments -- + +Warning: strtok() expects at most 2 parameters, 3 given in %s on line %d +NULL +string(13) "sample string" + +-- Testing strtok() with less than expected no. of arguments -- +bool(false) +string(10) "string val" +Done + +--UEXPECTF-- +*** Testing strtok() : error conditions *** + +-- Testing strtok() function with Zero arguments -- + +Warning: strtok() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing strtok() function with more than expected no. of arguments -- + +Warning: strtok() expects at most 2 parameters, 3 given in %s on line %d +NULL +unicode(13) "sample string" + +-- Testing strtok() with less than expected no. of arguments -- +bool(false) +unicode(10) "string val" +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation6.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation6.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_variation6.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_variation6.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,272 @@ +--TEST-- +Test strtok() function : usage variations - invalid escape sequences as tokens +--FILE-- +<?php +/* Prototype : string strtok ( str $str, str $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() : with invalid escape sequences in token +*/ + +echo "*** Testing strtok() : with invalid escape sequences in token ***\n"; + +// defining arrays for input strings and tokens +$string_array = array( + "khellok worldk", + "\khello\k world\k", + "/khello\k world/k", + "/hellok/ world" + ); +$token_array = array( + "k", + "/ ", + "/k", + "\k", + "\\\\\\\k\h\e\l\o\w\r\l\d" + ); + +// loop through each element of the array and check the working of strtok() +// when supplied with different string and token values + +$counter =1; +foreach( $string_array as $string ) { + echo "\n--- Iteration $counter ---\n"; + foreach( $token_array as $token ) { + var_dump( strtok($string, $token) ); + for( $count = 1; $count <=3; $count++ ) { + var_dump( strtok($token) ); + } + echo "\n"; + } + $counter++; +} + + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with invalid escape sequences in token *** + +--- Iteration 1 --- +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(7) "khellok" +string(6) "worldk" +bool(false) +bool(false) + +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(1) " " +string(1) "r" +bool(false) +bool(false) + + +--- Iteration 2 --- +string(1) "\" +string(6) "hello\" +string(7) " world\" +bool(false) + +string(9) "\khello\k" +string(7) "world\k" +bool(false) +bool(false) + +string(1) "\" +string(6) "hello\" +string(7) " world\" +bool(false) + +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(1) " " +string(1) "r" +bool(false) +bool(false) + + +--- Iteration 3 --- +string(1) "/" +string(6) "hello\" +string(7) " world/" +bool(false) + +string(8) "khello\k" +string(5) "world" +string(1) "k" +bool(false) + +string(6) "hello\" +string(6) " world" +bool(false) +bool(false) + +string(1) "/" +string(5) "hello" +string(7) " world/" +bool(false) + +string(1) "/" +string(1) " " +string(1) "r" +string(1) "/" + + +--- Iteration 4 --- +string(6) "/hello" +string(7) "/ world" +bool(false) +bool(false) + +string(6) "hellok" +string(5) "world" +bool(false) +bool(false) + +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(6) "/hello" +string(7) "/ world" +bool(false) +bool(false) + +string(1) "/" +string(2) "/ " +string(1) "r" +bool(false) + +Done + +--UEXPECTF-- +*** Testing strtok() : with invalid escape sequences in token *** + +--- Iteration 1 --- +unicode(5) "hello" +unicode(6) " world" +bool(false) +bool(false) + +unicode(7) "khellok" +unicode(6) "worldk" +bool(false) +bool(false) + +unicode(5) "hello" +unicode(6) " world" +bool(false) +bool(false) + +unicode(5) "hello" +unicode(6) " world" +bool(false) +bool(false) + +unicode(1) " " +unicode(1) "r" +bool(false) +bool(false) + + +--- Iteration 2 --- +unicode(1) "\" +unicode(6) "hello\" +unicode(7) " world\" +bool(false) + +unicode(9) "\khello\k" +unicode(7) "world\k" +bool(false) +bool(false) + +unicode(1) "\" +unicode(6) "hello\" +unicode(7) " world\" +bool(false) + +unicode(5) "hello" +unicode(6) " world" +bool(false) +bool(false) + +unicode(1) " " +unicode(1) "r" +bool(false) +bool(false) + + +--- Iteration 3 --- +unicode(1) "/" +unicode(6) "hello\" +unicode(7) " world/" +bool(false) + +unicode(8) "khello\k" +unicode(5) "world" +unicode(1) "k" +bool(false) + +unicode(6) "hello\" +unicode(6) " world" +bool(false) +bool(false) + +unicode(1) "/" +unicode(5) "hello" +unicode(7) " world/" +bool(false) + +unicode(1) "/" +unicode(1) " " +unicode(1) "r" +unicode(1) "/" + + +--- Iteration 4 --- +unicode(6) "/hello" +unicode(7) "/ world" +bool(false) +bool(false) + +unicode(6) "hellok" +unicode(5) "world" +bool(false) +bool(false) + +unicode(5) "hello" +unicode(6) " world" +bool(false) +bool(false) + +unicode(6) "/hello" +unicode(7) "/ world" +bool(false) +bool(false) + +unicode(1) "/" +unicode(2) "/ " +unicode(1) "r" +bool(false) + +Done \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation7.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation7.phpt diff -u /dev/null php-src/ext/standard/tests/strings/strtok_variation7.phpt:1.2 --- /dev/null Sat Sep 22 07:41:14 2007 +++ php-src/ext/standard/tests/strings/strtok_variation7.phpt Sat Sep 22 07:41:14 2007 @@ -0,0 +1,178 @@ +--TEST-- +Test strtok() function : usage variations - modifying the input string while tokenising +--FILE-- +<?php +/* Prototype : string strtok ( str $str, str $token ) + * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token + * Source code: ext/standard/string.c +*/ + +/* + * Testing strtok() : modifying the input string while it is getting tokenised +*/ + +echo "*** Testing strtok() : with modification of input string in between tokenising ***\n"; + +$str = "this is a sample string"; +$token = " "; + +echo "\n*** Testing strtok() when string being tokenised is prefixed with another string in between the process ***\n"; +var_dump( strtok($str, $token) ); +// adding a string to the input string which is being tokenised +$str = "extra string ".$str; +for( $count = 1; $count <=6; $count++ ) { + echo "\n-- Token $count is --\n"; + var_dump( strtok($token) ); + echo "\n-- Input str is \"$str\" --\n"; +} + +echo "\n*** Testing strtok() when string being tokenised is suffixed with another string in between the process ***\n"; +var_dump( strtok($str, $token) ); +// adding a string to the input string which is being tokenised +$str = $str." extra string"; +for( $count = 1; $count <=10; $count++ ) { + echo "\n-- Token $count is --\n"; + var_dump( strtok($token) ); +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with modification of input string in between tokenising *** + +*** Testing strtok() when string being tokenised is prefixed with another string in between the process *** +string(4) "this" + +-- Token 1 is -- +string(2) "is" + +-- Input str is "extra string this is a sample string" -- + +-- Token 2 is -- +string(1) "a" + +-- Input str is "extra string this is a sample string" -- + +-- Token 3 is -- +string(6) "sample" + +-- Input str is "extra string this is a sample string" -- + +-- Token 4 is -- +string(6) "string" + +-- Input str is "extra string this is a sample string" -- + +-- Token 5 is -- +bool(false) + +-- Input str is "extra string this is a sample string" -- + +-- Token 6 is -- +bool(false) + +-- Input str is "extra string this is a sample string" -- + +*** Testing strtok() when string being tokenised is suffixed with another string in between the process *** +string(5) "extra" + +-- Token 1 is -- +string(6) "string" + +-- Token 2 is -- +string(4) "this" + +-- Token 3 is -- +string(2) "is" + +-- Token 4 is -- +string(1) "a" + +-- Token 5 is -- +string(6) "sample" + +-- Token 6 is -- +string(6) "string" + +-- Token 7 is -- +bool(false) + +-- Token 8 is -- +bool(false) + +-- Token 9 is -- +bool(false) + +-- Token 10 is -- +bool(false) +Done + +--UEXPECTF-- +*** Testing strtok() : with modification of input string in between tokenising *** + +*** Testing strtok() when string being tokenised is prefixed with another string in between the process *** +unicode(4) "this" + +-- Token 1 is -- +unicode(2) "is" + +-- Input str is "extra string this is a sample string" -- + +-- Token 2 is -- +unicode(1) "a" + +-- Input str is "extra string this is a sample string" -- + +-- Token 3 is -- +unicode(6) "sample" + +-- Input str is "extra string this is a sample string" -- + +-- Token 4 is -- +unicode(6) "string" + +-- Input str is "extra string this is a sample string" -- + +-- Token 5 is -- +bool(false) + +-- Input str is "extra string this is a sample string" -- + +-- Token 6 is -- +bool(false) + +-- Input str is "extra string this is a sample string" -- + +*** Testing strtok() when string being tokenised is suffixed with another string in between the process *** +unicode(5) "extra" + +-- Token 1 is -- +unicode(6) "string" + +-- Token 2 is -- +unicode(4) "this" + +-- Token 3 is -- +unicode(2) "is" + +-- Token 4 is -- +unicode(1) "a" + +-- Token 5 is -- +unicode(6) "sample" + +-- Token 6 is -- +unicode(6) "string" + +-- Token 7 is -- +bool(false) + +-- Token 8 is -- +bool(false) + +-- Token 9 is -- +bool(false) + +-- Token 10 is -- +bool(false) +Done \ No newline at end of file
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php