jmessa Fri Feb 22 09:22:27 2008 UTC Modified files: /php-src/ext/standard/tests/array reset_basic.phpt reset_variation3.phpt reset_variation2.phpt reset_variation1.phpt reset_error.phpt Log: - New tests for reset() function
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/reset_basic.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/array/reset_basic.phpt diff -u /dev/null php-src/ext/standard/tests/array/reset_basic.phpt:1.2 --- /dev/null Fri Feb 22 09:22:27 2008 +++ php-src/ext/standard/tests/array/reset_basic.phpt Fri Feb 22 09:22:27 2008 @@ -0,0 +1,60 @@ +--TEST-- +Test reset() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of reset() + */ + +echo "*** Testing reset() : basic functionality ***\n"; + +$array = array('zero', 'one', 200 => 'two'); + +echo "\n-- Initial Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to next() --\n"; +var_dump(next($array)); + +echo "\n-- Current Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to reset() --\n"; +var_dump(reset($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : basic functionality *** + +-- Initial Position: -- +0 => zero + +-- Call to next() -- +string(3) "one" + +-- Current Position: -- +1 => one + +-- Call to reset() -- +string(4) "zero" +===DONE=== +--UEXPECTF-- +*** Testing reset() : basic functionality *** + +-- Initial Position: -- +0 => zero + +-- Call to next() -- +unicode(3) "one" + +-- Current Position: -- +1 => one + +-- Call to reset() -- +unicode(4) "zero" +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/reset_variation3.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/array/reset_variation3.phpt diff -u /dev/null php-src/ext/standard/tests/array/reset_variation3.phpt:1.2 --- /dev/null Fri Feb 22 09:22:27 2008 +++ php-src/ext/standard/tests/array/reset_variation3.phpt Fri Feb 22 09:22:27 2008 @@ -0,0 +1,71 @@ +--TEST-- +Test reset() function : usage variations - Referenced variables +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Reference two arrays to each other then call reset() to test position of + * internal pointer in both arrays + */ + +echo "*** Testing reset() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(current($array1)); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; + +next($array1); + +echo "\n-- Position after calling next() --\n"; +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); + +echo "\n-- Position after calling reset() --\n"; +var_dump(reset($array1)); +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling next() -- +$array1: string(3) "one" +$array2: string(3) "one" + +-- Position after calling reset() -- +string(4) "zero" +$array1: string(4) "zero" +$array2: string(4) "zero" +===DONE=== +--UEXPECTF-- +*** Testing reset() : usage variations *** + +-- Initial position of internal pointer -- +unicode(4) "zero" + +-- Position after calling next() -- +$array1: unicode(3) "one" +$array2: unicode(3) "one" + +-- Position after calling reset() -- +unicode(4) "zero" +$array1: unicode(4) "zero" +$array2: unicode(4) "zero" +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/reset_variation2.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/array/reset_variation2.phpt diff -u /dev/null php-src/ext/standard/tests/array/reset_variation2.phpt:1.2 --- /dev/null Fri Feb 22 09:22:27 2008 +++ php-src/ext/standard/tests/array/reset_variation2.phpt Fri Feb 22 09:22:27 2008 @@ -0,0 +1,43 @@ +--TEST-- +Test reset() function : usage variations - unset first element +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Unset first element of an array and test behaviour of reset() + */ + +echo "*** Testing reset() : usage variations ***\n"; + +$array = array('a', 'b', 'c'); + +echo "\n-- Initial Position: --\n"; +echo current($array) . " => " . key($array) . "\n"; + +echo "\n-- Unset First element in array and check reset() --\n"; +unset($array[0]); +var_dump(reset($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Initial Position: -- +a => 0 + +-- Unset First element in array and check reset() -- +string(1) "b" +===DONE=== +--UEXPECTF-- +*** Testing reset() : usage variations *** + +-- Initial Position: -- +a => 0 + +-- Unset First element in array and check reset() -- +unicode(1) "b" +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/reset_variation1.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/array/reset_variation1.phpt diff -u /dev/null php-src/ext/standard/tests/array/reset_variation1.phpt:1.2 --- /dev/null Fri Feb 22 09:22:27 2008 +++ php-src/ext/standard/tests/array/reset_variation1.phpt Fri Feb 22 09:22:27 2008 @@ -0,0 +1,347 @@ +--TEST-- +Test reset() function : usage variations - Pass different data types as $array_arg arg. +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to reset() to test behaviour + */ + +echo "*** Testing reset() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of reset() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( reset($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Iteration 1 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: reset() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: reset() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== +--UEXPECTF-- +*** Testing reset() : usage variations *** + +-- Iteration 1 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: reset() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: reset() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: reset() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: reset() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: reset() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: reset() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: reset() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/reset_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/array/reset_error.phpt diff -u /dev/null php-src/ext/standard/tests/array/reset_error.phpt:1.2 --- /dev/null Fri Feb 22 09:22:27 2008 +++ php-src/ext/standard/tests/array/reset_error.phpt Fri Feb 22 09:22:27 2008 @@ -0,0 +1,52 @@ +--TEST-- +Test reset() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to reset() to test behaviour + */ + +echo "*** Testing reset() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing reset() function with Zero arguments --\n"; +var_dump( reset() ); + +//Test reset with one more than the expected number of arguments +echo "\n-- Testing reset() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( reset($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : error conditions *** + +-- Testing reset() function with Zero arguments -- + +Warning: reset() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing reset() function with more than expected no. of arguments -- + +Warning: reset() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== +--UEXPECTF-- +*** Testing reset() : error conditions *** + +-- Testing reset() function with Zero arguments -- + +Warning: reset() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing reset() function with more than expected no. of arguments -- + +Warning: reset() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE===
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php