jmessa          Wed Feb 20 14:21:36 2008 UTC

  Modified files:              
    /php-src/ext/standard/tests/array   current_error.phpt 
                                        current_variation1.phpt 
                                        current_variation4.phpt 
                                        current_variation2.phpt 
                                        current_basic.phpt 
                                        current_variation3.phpt 
  Log:
  - New tests for current() function
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/current_error.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/array/current_error.phpt
diff -u /dev/null php-src/ext/standard/tests/array/current_error.phpt:1.2
--- /dev/null   Wed Feb 20 14:21:36 2008
+++ php-src/ext/standard/tests/array/current_error.phpt Wed Feb 20 14:21:36 2008
@@ -0,0 +1,53 @@
+--TEST--
+Test current() function : error conditions - Pass incorrect number of args
+--FILE--
+<?php
+/* Prototype  : mixed current(array $array_arg)
+ * Description: Return the element currently pointed to by the internal array 
pointer
+ * Source code: ext/standard/array.c
+ * Alias to functions: pos
+ */
+
+/*
+ * Pass incorrect number of arguments to current() to test behaviour
+ */
+
+echo "*** Testing current() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing current() function with Zero arguments --\n";
+var_dump( current() );
+
+//Test current with one more than the expected number of arguments
+echo "\n-- Testing current() function with more than expected no. of arguments 
--\n";
+$array_arg = array(1, 2);
+$extra_arg = 10;
+var_dump( current($array_arg, $extra_arg) );
+?>
+===DONE===
+--EXPECTF--
+*** Testing current() : error conditions ***
+
+-- Testing current() function with Zero arguments --
+
+Warning: current() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing current() function with more than expected no. of arguments --
+
+Warning: current() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+===DONE===
+--UEXPECTF--
+*** Testing current() : error conditions ***
+
+-- Testing current() function with Zero arguments --
+
+Warning: current() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing current() function with more than expected no. of arguments --
+
+Warning: current() expects exactly 1 parameter, 2 given in %s on line %d
+NULL
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/current_variation1.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/array/current_variation1.phpt
diff -u /dev/null php-src/ext/standard/tests/array/current_variation1.phpt:1.2
--- /dev/null   Wed Feb 20 14:21:36 2008
+++ php-src/ext/standard/tests/array/current_variation1.phpt    Wed Feb 20 
14:21:36 2008
@@ -0,0 +1,342 @@
+--TEST--
+Test current() function : usage variations - Pass different data types as 
$array_arg arg
+--FILE--
+<?php
+/* Prototype  : mixed current(array $array_arg)
+ * Description: Return the element currently pointed to by the internal array 
pointer
+ * Source code: ext/standard/array.c
+ * Alias to functions: pos
+ */
+
+/*
+ * Pass different data types as $array_arg argument to current() to test 
behaviour
+ */
+
+echo "*** Testing current() : usage variations ***\n";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+       var $var1;
+  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*/ "",
+       '',
+
+       // string data
+/*18*/ "string",
+       'string',
+       $heredoc,
+       
+       // object data
+/*21*/ new classA(),
+
+       // undefined data
+/*22*/ @$undefined_var,
+
+       // unset data
+/*23*/ @$unset_var,
+
+       // resource variable
+/*24*/ $fp
+);
+
+// loop through each element of $inputs to check the behavior of current()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( current($input) );
+  $iterator++;
+};
+
+fclose($fp);
+?>
+===DONE===
+--EXPECTF--
+*** Testing current() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: current() expects parameter 1 to be array, integer given in %s on 
line %d
+NULL
+
+-- Iteration 2 --
+
+Warning: current() expects parameter 1 to be array, integer given in %s on 
line %d
+NULL
+
+-- Iteration 3 --
+
+Warning: current() expects parameter 1 to be array, integer given in %s on 
line %d
+NULL
+
+-- Iteration 4 --
+
+Warning: current() expects parameter 1 to be array, integer given in %s on 
line %d
+NULL
+
+-- Iteration 5 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 6 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 7 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 8 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 9 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 10 --
+
+Warning: current() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 11 --
+
+Warning: current() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 12 --
+
+Warning: current() expects parameter 1 to be array, boolean given in %s on 
line %d
+NULL
+
+-- Iteration 13 --
+
+Warning: current() expects parameter 1 to be array, boolean given in %s on 
line %d
+NULL
+
+-- Iteration 14 --
+
+Warning: current() expects parameter 1 to be array, boolean given in %s on 
line %d
+NULL
+
+-- Iteration 15 --
+
+Warning: current() expects parameter 1 to be array, boolean given in %s on 
line %d
+NULL
+
+-- Iteration 16 --
+
+Warning: current() expects parameter 1 to be array, string given in %s on line 
%d
+NULL
+
+-- Iteration 17 --
+
+Warning: current() expects parameter 1 to be array, string given in %s on line 
%d
+NULL
+
+-- Iteration 18 --
+
+Warning: current() expects parameter 1 to be array, string given in %s on line 
%d
+NULL
+
+-- Iteration 19 --
+
+Warning: current() expects parameter 1 to be array, string given in %s on line 
%d
+NULL
+
+-- Iteration 20 --
+
+Warning: current() expects parameter 1 to be array, string given in %s on line 
%d
+NULL
+
+-- Iteration 21 --
+
+Warning: current() expects parameter 1 to be array, object given in %s on line 
%d
+NULL
+
+-- Iteration 22 --
+
+Warning: current() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 23 --
+
+Warning: current() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 24 --
+
+Warning: current() expects parameter 1 to be array, resource given in %s on 
line %d
+NULL
+===DONE===
+--UEXPECTF--
+*** Testing current() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: current() expects parameter 1 to be array, integer given in %s on 
line %d
+NULL
+
+-- Iteration 2 --
+
+Warning: current() expects parameter 1 to be array, integer given in %s on 
line %d
+NULL
+
+-- Iteration 3 --
+
+Warning: current() expects parameter 1 to be array, integer given in %s on 
line %d
+NULL
+
+-- Iteration 4 --
+
+Warning: current() expects parameter 1 to be array, integer given in %s on 
line %d
+NULL
+
+-- Iteration 5 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 6 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 7 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 8 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 9 --
+
+Warning: current() expects parameter 1 to be array, double given in %s on line 
%d
+NULL
+
+-- Iteration 10 --
+
+Warning: current() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 11 --
+
+Warning: current() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 12 --
+
+Warning: current() expects parameter 1 to be array, boolean given in %s on 
line %d
+NULL
+
+-- Iteration 13 --
+
+Warning: current() expects parameter 1 to be array, boolean given in %s on 
line %d
+NULL
+
+-- Iteration 14 --
+
+Warning: current() expects parameter 1 to be array, boolean given in %s on 
line %d
+NULL
+
+-- Iteration 15 --
+
+Warning: current() expects parameter 1 to be array, boolean given in %s on 
line %d
+NULL
+
+-- Iteration 16 --
+
+Warning: current() expects parameter 1 to be array, Unicode string given in %s 
on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: current() expects parameter 1 to be array, Unicode string given in %s 
on line %d
+NULL
+
+-- Iteration 18 --
+
+Warning: current() expects parameter 1 to be array, Unicode string given in %s 
on line %d
+NULL
+
+-- Iteration 19 --
+
+Warning: current() expects parameter 1 to be array, Unicode string given in %s 
on line %d
+NULL
+
+-- Iteration 20 --
+
+Warning: current() expects parameter 1 to be array, Unicode string given in %s 
on line %d
+NULL
+
+-- Iteration 21 --
+
+Warning: current() expects parameter 1 to be array, object given in %s on line 
%d
+NULL
+
+-- Iteration 22 --
+
+Warning: current() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 23 --
+
+Warning: current() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 24 --
+
+Warning: current() 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/current_variation4.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/array/current_variation4.phpt
diff -u /dev/null php-src/ext/standard/tests/array/current_variation4.phpt:1.2
--- /dev/null   Wed Feb 20 14:21:36 2008
+++ php-src/ext/standard/tests/array/current_variation4.phpt    Wed Feb 20 
14:21:36 2008
@@ -0,0 +1,94 @@
+--TEST--
+Test current() function : usage variations - multi-dimensional arrays
+--FILE--
+<?php
+/* Prototype  : mixed current(array $array_arg)
+ * Description: Return the element currently pointed to by the internal array 
pointer
+ * Source code: ext/standard/array.c
+ * Alias to functions: pos
+ */
+
+/*
+ * Test how current() behaves with muti-dimensional and recursive arrays
+ */
+
+echo "*** Testing current() : usage variations ***\n";
+
+echo "\n-- Two Dimensional Array --\n";
+$multi_array = array ('zero', array (1, 2, 3), 'two');
+echo "Initial Position: ";
+var_dump(current($multi_array));
+
+echo "Next Position:    ";
+next($multi_array);
+var_dump(current($multi_array));
+
+echo "End Position:     ";
+end($multi_array);
+var_dump(current($multi_array));
+
+echo "\n-- Access an Array Within an Array --\n";
+//accessing an array within an array
+echo "Initial Position: ";
+var_dump(current($multi_array[1]));
+
+echo "\n-- Recursive, Multidimensional Array --\n";
+//create a recursive array
+$multi_array[] = &$multi_array;
+
+//See where internal pointer is after adding more elements
+echo "Current Position: ";
+var_dump(current($multi_array));
+
+//see if internal pointer is in same position as referenced array
+var_dump(current($multi_array[3][3][3]));
+// see if internal pointer is in the same position from when accessing this 
inner array
+var_dump(current($multi_array[3][3][3][1]));
+?>
+===DONE===
+--EXPECTF--
+*** Testing current() : usage variations ***
+
+-- Two Dimensional Array --
+Initial Position: string(4) "zero"
+Next Position:    array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+End Position:     string(3) "two"
+
+-- Access an Array Within an Array --
+Initial Position: int(1)
+
+-- Recursive, Multidimensional Array --
+Current Position: string(3) "two"
+string(3) "two"
+int(1)
+===DONE===
+--UEXPECTF--
+*** Testing current() : usage variations ***
+
+-- Two Dimensional Array --
+Initial Position: unicode(4) "zero"
+Next Position:    array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+End Position:     unicode(3) "two"
+
+-- Access an Array Within an Array --
+Initial Position: int(1)
+
+-- Recursive, Multidimensional Array --
+Current Position: unicode(3) "two"
+unicode(3) "two"
+int(1)
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/current_variation2.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/array/current_variation2.phpt
diff -u /dev/null php-src/ext/standard/tests/array/current_variation2.phpt:1.2
--- /dev/null   Wed Feb 20 14:21:36 2008
+++ php-src/ext/standard/tests/array/current_variation2.phpt    Wed Feb 20 
14:21:36 2008
@@ -0,0 +1,192 @@
+--TEST--
+Test current() function : usage variations - arrays containing different data 
types
+--FILE--
+<?php
+/* Prototype  : mixed current(array $array_arg)
+ * Description: Return the element currently pointed to by the internal array 
pointer
+ * Source code: ext/standard/array.c
+ * Alias to functions: pos
+ */
+
+/*
+ * Pass arrays of different data types as $array_arg to current() to test 
behaviour
+ */
+
+echo "*** Testing current() : 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");
+
+// arrays of different data types to be passed to $array_arg argument
+$inputs = array(
+
+       // int data
+/*1*/  'int' => array(
+          0,
+       1,
+       12345,
+       -2345,
+       ),
+
+       // float data
+/*2*/  'float' => array(
+       10.5,
+       -10.5,
+       12.3456789000e10,
+       12.3456789000E-10,
+       .5,
+       ),
+
+       // null data
+/*3*/ 'null' => array(
+       NULL,
+       null,
+       ),
+
+       // boolean data
+/*4*/ 'bool' => array(
+       true,
+       false,
+       TRUE,
+       FALSE,
+       ),
+       
+       // empty data
+/*5*/ 'empty string' => array(
+       "",
+       '',
+       ),
+       
+/*6*/ 'empty array' => array(
+       ),
+
+       // string data
+/*7*/ 'string' => array(
+       "string",
+       'string',
+       $heredoc,
+       ),
+       
+       // object data
+/*8*/ 'object' => array(
+       new classA(),
+       ),
+
+       // undefined data
+/*9*/ 'undefined' => array(
+       @$undefined_var,
+       ),
+
+       // unset data
+/*10*/ 'unset' => array(
+       @$unset_var,
+       ),
+
+       // resource variable
+/*11*/ 'resource' => array(
+       $fp
+       ),
+);
+
+// loop through each element of $inputs to check the behavior of current()
+$iterator = 1;
+foreach($inputs as $key => $input) {
+  echo "\n-- Iteration $iterator : $key data --\n";
+  var_dump( current($input) );
+  $iterator++;
+};
+
+fclose($fp);
+?>
+===DONE===
+--EXPECTF--
+*** Testing current() : usage variations ***
+
+-- Iteration 1 : int data --
+int(0)
+
+-- Iteration 2 : float data --
+float(10.5)
+
+-- Iteration 3 : null data --
+NULL
+
+-- Iteration 4 : bool data --
+bool(true)
+
+-- Iteration 5 : empty string data --
+string(0) ""
+
+-- Iteration 6 : empty array data --
+bool(false)
+
+-- Iteration 7 : string data --
+string(6) "string"
+
+-- Iteration 8 : object data --
+object(classA)#%d (0) {
+}
+
+-- Iteration 9 : undefined data --
+NULL
+
+-- Iteration 10 : unset data --
+NULL
+
+-- Iteration 11 : resource data --
+resource(%d) of type (stream)
+===DONE===
+--UEXPECTF--
+*** Testing current() : usage variations ***
+
+-- Iteration 1 : int data --
+int(0)
+
+-- Iteration 2 : float data --
+float(10.5)
+
+-- Iteration 3 : null data --
+NULL
+
+-- Iteration 4 : bool data --
+bool(true)
+
+-- Iteration 5 : empty string data --
+unicode(0) ""
+
+-- Iteration 6 : empty array data --
+bool(false)
+
+-- Iteration 7 : string data --
+unicode(6) "string"
+
+-- Iteration 8 : object data --
+object(classA)#%d (0) {
+}
+
+-- Iteration 9 : undefined data --
+NULL
+
+-- Iteration 10 : unset data --
+NULL
+
+-- Iteration 11 : resource data --
+resource(%d) of type (stream)
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/current_basic.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/array/current_basic.phpt
diff -u /dev/null php-src/ext/standard/tests/array/current_basic.phpt:1.2
--- /dev/null   Wed Feb 20 14:21:36 2008
+++ php-src/ext/standard/tests/array/current_basic.phpt Wed Feb 20 14:21:36 2008
@@ -0,0 +1,39 @@
+--TEST--
+Test current() function : basic functionality 
+--FILE--
+<?php
+/* Prototype  : mixed current(array $array_arg)
+ * Description: Return the element currently pointed to by the internal array 
pointer 
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test basic functionality of current()
+ */
+
+echo "*** Testing current() : basic functionality ***\n";
+
+$array = array ('zero', 'one', 'two', 'three' => 3);
+var_dump(current($array));
+next($array);
+var_dump(current($array));
+end($array);
+var_dump(current($array));
+next($array);
+var_dump(current($array));
+?>
+===DONE===
+--EXPECTF--
+*** Testing current() : basic functionality ***
+string(4) "zero"
+string(3) "one"
+int(3)
+bool(false)
+===DONE===
+--UEXPECTF--
+*** Testing current() : basic functionality ***
+unicode(4) "zero"
+unicode(3) "one"
+int(3)
+bool(false)
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/current_variation3.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/array/current_variation3.phpt
diff -u /dev/null php-src/ext/standard/tests/array/current_variation3.phpt:1.2
--- /dev/null   Wed Feb 20 14:21:36 2008
+++ php-src/ext/standard/tests/array/current_variation3.phpt    Wed Feb 20 
14:21:36 2008
@@ -0,0 +1,52 @@
+--TEST--
+Test current() function : usage variations - referenced variables
+--FILE--
+<?php
+/* Prototype  : mixed current(array $array_arg)
+ * Description: Return the element currently pointed to by the internal array 
pointer
+ * Source code: ext/standard/array.c
+ * Alias to functions: pos
+ */
+
+/*
+ * Test how the internal pointer is affected when two variables are referenced 
to each other
+ */
+
+echo "*** Testing current() : usage variations ***\n";
+
+$array1 = array ('zero', 'one', 'two');
+
+echo "\n-- Initial position of internal pointer --\n";
+var_dump(current($array1));
+next($array1);
+
+// Test that when two variables are referenced to one another
+// the internal pointer is the same for both
+$array2 = &$array1;
+echo "\n-- Position after calling next() --\n";
+echo "\$array1: ";
+var_dump(current($array1));
+echo "\$array2: ";
+var_dump(current($array2));
+?>
+===DONE===
+--EXPECTF--
+*** Testing current() : usage variations ***
+
+-- Initial position of internal pointer --
+string(4) "zero"
+
+-- Position after calling next() --
+$array1: string(3) "one"
+$array2: string(3) "one"
+===DONE===
+--UEXPECTF--
+*** Testing current() : usage variations ***
+
+-- Initial position of internal pointer --
+unicode(4) "zero"
+
+-- Position after calling next() --
+$array1: unicode(3) "one"
+$array2: unicode(3) "one"
+===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to