diff options
author | Lars Strojny <lstrojny@php.net> | 2008-09-11 18:21:37 +0000 |
---|---|---|
committer | Lars Strojny <lstrojny@php.net> | 2008-09-11 18:21:37 +0000 |
commit | fc9c3a17c6fe90220950f841858b16a4376bfefd (patch) | |
tree | 2de480800a7c49cb08f76cae5c2d88369a7e7f70 /ext | |
parent | c238cb8f848e574beeddf9ecaa6f9d49135fc518 (diff) | |
download | php-git-fc9c3a17c6fe90220950f841858b16a4376bfefd.tar.gz |
MFH: prev()-tests by Iain Lewis <ilewis@uk.ibm.com>
Diffstat (limited to 'ext')
-rwxr-xr-x | ext/standard/tests/array/prev_basic.phpt | 53 | ||||
-rwxr-xr-x | ext/standard/tests/array/prev_error1.phpt | 39 | ||||
-rwxr-xr-x | ext/standard/tests/array/prev_error2.phpt | 28 | ||||
-rwxr-xr-x | ext/standard/tests/array/prev_error3.phpt | 19 | ||||
-rwxr-xr-x | ext/standard/tests/array/prev_variation1.phpt | 221 | ||||
-rwxr-xr-x | ext/standard/tests/array/prev_variation2.phpt | 49 |
6 files changed, 409 insertions, 0 deletions
diff --git a/ext/standard/tests/array/prev_basic.phpt b/ext/standard/tests/array/prev_basic.phpt new file mode 100755 index 0000000000..8c1450dd3c --- /dev/null +++ b/ext/standard/tests/array/prev_basic.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test prev() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of prev() + */ + +echo "*** Testing prev() : basic functionality ***\n"; + +$array = array('zero', 'one', 'two'); +end($array); +echo key($array) . " => " . current($array) . "\n"; +var_dump(prev($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(prev($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(prev($array)); + +echo "\n*** Testing an array with differing values/keys ***\n"; +$array2 = array('one', 2 => "help", 3, false, 'stringkey2' => 'val2', 'stringkey1' => 'val1'); +end($array2); +$length = count($array2); +for ($i = $length; $i > 0; $i--) { + var_dump(prev($array2)); +} + +?> +===DONE=== +--EXPECTF-- +*** Testing prev() : basic functionality *** +2 => two +string(3) "one" +1 => one +string(4) "zero" +0 => zero +bool(false) + +*** Testing an array with differing values/keys *** +string(4) "val2" +bool(false) +int(3) +string(4) "help" +string(3) "one" +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/prev_error1.phpt b/ext/standard/tests/array/prev_error1.phpt new file mode 100755 index 0000000000..bea245196e --- /dev/null +++ b/ext/standard/tests/array/prev_error1.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test prev() function : error conditions - Pass incorrect number of arguments +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to prev() to test behaviour + */ + +echo "*** Testing prev() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing prev() function with Zero arguments --\n"; +var_dump( prev() ); + +//Test prev with one more than the expected number of arguments +echo "\n-- Testing prev() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( prev($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing prev() : error conditions *** + +-- Testing prev() function with Zero arguments -- + +Warning: prev() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing prev() function with more than expected no. of arguments -- + +Warning: prev() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/prev_error2.phpt b/ext/standard/tests/array/prev_error2.phpt new file mode 100755 index 0000000000..f26bdd0a41 --- /dev/null +++ b/ext/standard/tests/array/prev_error2.phpt @@ -0,0 +1,28 @@ +--TEST-- +prev - ensure warning is received when passing an indirect temporary. +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass temporary variables to prev() to test behaviour + */ + +function f() { + $array = array(1,2); + end($array); + return $array; +} + +echo "\n-- Passing an indirect temporary variable --\n"; +var_dump(prev(f())); + +?> +--EXPECTF-- +-- Passing an indirect temporary variable -- + +Strict Standards: Only variables should be passed by reference in %s on line %d +int(1) diff --git a/ext/standard/tests/array/prev_error3.phpt b/ext/standard/tests/array/prev_error3.phpt new file mode 100755 index 0000000000..dfac24eacb --- /dev/null +++ b/ext/standard/tests/array/prev_error3.phpt @@ -0,0 +1,19 @@ +--TEST-- +prev - ensure we cannot pass a temporary +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass temporary variables to prev() to test behaviour + */ + + +var_dump(prev(array(1, 2))); +?> +--EXPECTF-- + +Fatal error: Only variables can be passed by reference in %s on line %d
\ No newline at end of file diff --git a/ext/standard/tests/array/prev_variation1.phpt b/ext/standard/tests/array/prev_variation1.phpt new file mode 100755 index 0000000000..009469d98f --- /dev/null +++ b/ext/standard/tests/array/prev_variation1.phpt @@ -0,0 +1,221 @@ +--TEST-- +Test prev() function : usage variation - Pass different data types as $array_arg +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to prev() to test behaviour + */ + +echo "*** Testing prev() : variation ***\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 prev() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( prev($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing prev() : variation *** + +-- Iteration 1 -- + +Warning: prev() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: prev() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: prev() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: prev() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: prev() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: prev() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: prev() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: prev() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: prev() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: prev() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/prev_variation2.phpt b/ext/standard/tests/array/prev_variation2.phpt new file mode 100755 index 0000000000..0ce087781e --- /dev/null +++ b/ext/standard/tests/array/prev_variation2.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test prev() function : usage variation - Multi-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test prev() when passed: + * 1. a two-dimensional array + * 2. a sub-array + * as $array_arg argument. + */ + +echo "*** Testing prev() : usage variations ***\n"; + +$subarray = array(9,8,7); +end($subarray); + +$array_arg = array ($subarray, 'a' => 'z'); +end($array_arg); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(prev($array_arg)); +var_dump(prev($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(prev($array_arg[0])); +?> +===DONE=== +--EXPECTF-- +*** Testing prev() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} +bool(false) + +-- Pass a sub-array as $array_arg -- +int(8) +===DONE=== |