diff options
author | Josie Messa <jmessa@php.net> | 2008-02-22 09:18:25 +0000 |
---|---|---|
committer | Josie Messa <jmessa@php.net> | 2008-02-22 09:18:25 +0000 |
commit | 6dc4795a662d297e3796ea347bedc92307552b00 (patch) | |
tree | 7c9525daf8378dfb948d24c58762a14f6557805e | |
parent | 6c7fe8df9fc1f2a4ca87c1c8c7ba17127d90dde4 (diff) | |
download | php-git-6dc4795a662d297e3796ea347bedc92307552b00.tar.gz |
- New tests for reset() function
-rw-r--r-- | ext/standard/tests/array/reset_basic.phpt | 45 | ||||
-rw-r--r-- | ext/standard/tests/array/reset_error.phpt | 39 | ||||
-rw-r--r-- | ext/standard/tests/array/reset_variation1.phpt | 219 | ||||
-rw-r--r-- | ext/standard/tests/array/reset_variation2.phpt | 34 | ||||
-rw-r--r-- | ext/standard/tests/array/reset_variation3.phpt | 56 |
5 files changed, 393 insertions, 0 deletions
diff --git a/ext/standard/tests/array/reset_basic.phpt b/ext/standard/tests/array/reset_basic.phpt new file mode 100644 index 0000000000..d376e68a21 --- /dev/null +++ b/ext/standard/tests/array/reset_basic.phpt @@ -0,0 +1,45 @@ +--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=== diff --git a/ext/standard/tests/array/reset_error.phpt b/ext/standard/tests/array/reset_error.phpt new file mode 100644 index 0000000000..1bf0f96137 --- /dev/null +++ b/ext/standard/tests/array/reset_error.phpt @@ -0,0 +1,39 @@ +--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: Wrong parameter count for reset() in %s on line %d +NULL + +-- Testing reset() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for reset() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/reset_variation1.phpt b/ext/standard/tests/array/reset_variation1.phpt new file mode 100644 index 0000000000..0dc99512e9 --- /dev/null +++ b/ext/standard/tests/array/reset_variation1.phpt @@ -0,0 +1,219 @@ +--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(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 2 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 3 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 4 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 5 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 6 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 7 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 8 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 9 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 10 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 11 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 12 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 13 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 14 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 15 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 16 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 17 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 20 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 21 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 24 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 25 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/reset_variation2.phpt b/ext/standard/tests/array/reset_variation2.phpt new file mode 100644 index 0000000000..1384affa94 --- /dev/null +++ b/ext/standard/tests/array/reset_variation2.phpt @@ -0,0 +1,34 @@ +--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=== diff --git a/ext/standard/tests/array/reset_variation3.phpt b/ext/standard/tests/array/reset_variation3.phpt new file mode 100644 index 0000000000..29f965abe1 --- /dev/null +++ b/ext/standard/tests/array/reset_variation3.phpt @@ -0,0 +1,56 @@ +--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=== |