zoe Wed Apr 11 11:44:37 2007 UTC
Added files:
/php-src/ext/standard/tests/array array_merge.phpt array_push.phpt
/php-src/ext/standard/tests/strings fprintf.phpt
Modified files:
/php-src/ext/standard/tests/array count_recursive.phpt
/php-src/ext/standard/tests/strings md5.phpt
Log:
new tests: array_merge, array_push, fprintf. modified tests: count_recursive,
md5.
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/count_recursive.phpt?r1=1.4&r2=1.5&diff_format=u
Index: php-src/ext/standard/tests/array/count_recursive.phpt
diff -u php-src/ext/standard/tests/array/count_recursive.phpt:1.4
php-src/ext/standard/tests/array/count_recursive.phpt:1.5
--- php-src/ext/standard/tests/array/count_recursive.phpt:1.4 Sat Nov 16
17:26:52 2002
+++ php-src/ext/standard/tests/array/count_recursive.phpt Wed Apr 11
11:44:37 2007
@@ -1,52 +1,234 @@
--TEST--
-count
+Test count() function
--FILE--
<?php
-print "Testing NULL...\n";
+/* Prototype: int count ( mixed $var [, int $mode] );
+ Discription: Count elements in an array, or properties in an object
+*/
+
+echo "*** Testing basic functionality of count() function ***\n";
+print "-- Testing NULL --\n";
$arr = NULL;
print "COUNT_NORMAL: should be 0, is ".count($arr, COUNT_NORMAL)."\n";
print "COUNT_RECURSIVE: should be 0, is ".count($arr, COUNT_RECURSIVE)."\n";
-print "Testing arrays...\n";
+print "-- Testing arrays --\n";
$arr = array(1, array(3, 4, array(6, array(8))));
print "COUNT_NORMAL: should be 2, is ".count($arr, COUNT_NORMAL)."\n";
print "COUNT_RECURSIVE: should be 8, is ".count($arr, COUNT_RECURSIVE)."\n";
-print "Testing hashes...\n";
+print "-- Testing hashes --\n";
$arr = array("a" => 1, "b" => 2, array("c" => 3, array("d" => 5)));
print "COUNT_NORMAL: should be 3, is ".count($arr, COUNT_NORMAL)."\n";
print "COUNT_RECURSIVE: should be 6, is ".count($arr, COUNT_RECURSIVE)."\n";
-print "Testing strings...\n";
+print "-- Testing strings --\n";
print "COUNT_NORMAL: should be 1, is ".count("string", COUNT_NORMAL)."\n";
print "COUNT_RECURSIVE: should be 1, is ".count("string",
COUNT_RECURSIVE)."\n";
-print "Testing various types with no second argument.\n";
+print "-- Testing various types with no second argument --\n";
print "COUNT_NORMAL: should be 1, is ".count("string")."\n";
print "COUNT_NORMAL: should be 2, is ".count(array("a", array("b")))."\n";
$arr = array('a'=>array(NULL, NULL, NULL), 1=>array(NULL=>1, 1=>NULL),
array(array(array(array(array(NULL))))));
-print "Testing really cool arrays ;)\n";
+print "-- Testing really cool arrays --\n";
print "COUNT_NORMAL: should be 3, is ".count($arr, COUNT_NORMAL)."\n";
print "COUNT_RECURSIVE: should be 13, is ".count($arr, COUNT_RECURSIVE)."\n";
+
+echo "\n*** Testing possible variations of count() function on arrays ***";
+$count_array = array(
+ array(),
+ array( 1 => "string"),
+ array( "" => "string", 0 => "a", NULL => "b", -1.00 => "c",
+ array(array(array(NULL)))),
+ array( -2.44444 => 12, array(array(1, 2, array(array("0"))))),
+ array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344),
+ array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL,
+ 1 => -2.344, array()),
+ array( TRUE => TRUE, FALSE => FALSE, "" => "", " " => " ",
+ NULL => NULL, "\x000" => "\x000", "\000" => "\000"),
+ array( NULL, 1.23 => "Hi", "string" => "hello",
+ array("" => "World", "-2.34" => "a", "0" => "b"))
+);
+
+$i = 0;
+foreach ($count_array as $count_value) {
+ echo "\n-- Iteration $i --\n";
+ print "COUNT_NORMAL is ".count($count_value, COUNT_NORMAL)."\n";
+ print "COUNT_RECURSIVE is ".count($count_value, COUNT_RECURSIVE)."\n";
+ $i++;
+}
+
+
+/* Testing count() by passing constant with no second argument */
+print "\n-- Testing count() on constants with no second argument --\n";
+print "COUNT_NORMAL: should be 1, is ".count(100)."\n";
+print "COUNT_NORMAL: should be 1, is ".count(-23.45)."\n";
+
+print "\n-- Testing count() on NULL and Unset variables --\n";
+print "COUNT_NORMAL: should be 0, is ".count(NULL)."\n";
+print "COUNT_NORMAL: should be 1, is ".count("")."\n";
+print "COUNT_NORMAL: should be 0, is "[EMAIL PROTECTED]($a)."\n";
+
+
+print "\n-- Testing count() on an empty sub-array --\n";
+$arr = array(1, array(3, 4, array()));
+print "COUNT_NORMAL: should be 2, is ".count($arr, COUNT_NORMAL)."\n";
+print "COUNT_RECURSIVE: should be 5, is ".count($arr, COUNT_RECURSIVE)."\n";
+
+echo "\n-- Testing count() on objects with Countable interface --\n";
+class count_class implements Countable {
+ private $var_private;
+ public $var_public;
+ protected $var_protected;
+
+ public function count() {
+ return 3;
+ }
+}
+
+$obj = new count_class();
+print "COUNT_NORMAL: should be 3, is ".count($obj)."\n";
+
+
+echo "\n-- Testing count() on resource type --\n";
+$resource1 = fopen( __FILE__, "r" ); // Creating file(stream type) resource
+$resource2 = opendir( "." ); // Creating dir resource
+
+/* creating an array with resources as elements */
+$arr_resource = array("a" => $resource1, "b" => $resource2);
+var_dump(count($arr_resource));
+
+echo "\n-- Testing count() on arrays containing references --\n";
+$arr = array(1, array("a", "b", "c"));
+$arr[2] = &$arr[1];
+
+$mode_arr = array( COUNT_NORMAL, COUNT_RECURSIVE, 0, 1, -1, -1.45, 2, TRUE,
+ FALSE, NULL);
+for( $i =0; $i < count( $mode_arr ); $i++) {
+ echo "For mode '$mode_arr[$i]' count is => ";
+ var_dump(count($arr, $mode_arr[$i]));
+}
+
+
+echo "\n-- Testing error conditions --";
+var_dump( count() ); // No. of args = 0
+var_dump( count(array(), COUNT_NORMAL, 100) ); // No. of args > expected
+
+/* Testing Invalid type arguments */
+var_dump( count("string", ABCD) );
+var_dump( count(100, "string") );
+var_dump( count(array(), "") );
+
+echo "\nDone";
+
+--CLEAN--
+/* closing the resource handles */
+fclose( $resource1 );
+closedir( $resource2 );
?>
---EXPECT--
-Testing NULL...
+--EXPECTF--
+*** Testing basic functionality of count() function ***
+-- Testing NULL --
COUNT_NORMAL: should be 0, is 0
COUNT_RECURSIVE: should be 0, is 0
-Testing arrays...
+-- Testing arrays --
COUNT_NORMAL: should be 2, is 2
COUNT_RECURSIVE: should be 8, is 8
-Testing hashes...
+-- Testing hashes --
COUNT_NORMAL: should be 3, is 3
COUNT_RECURSIVE: should be 6, is 6
-Testing strings...
+-- Testing strings --
COUNT_NORMAL: should be 1, is 1
COUNT_RECURSIVE: should be 1, is 1
-Testing various types with no second argument.
+-- Testing various types with no second argument --
COUNT_NORMAL: should be 1, is 1
COUNT_NORMAL: should be 2, is 2
-Testing really cool arrays ;)
+-- Testing really cool arrays --
COUNT_NORMAL: should be 3, is 3
COUNT_RECURSIVE: should be 13, is 13
+
+*** Testing possible variations of count() function on arrays ***
+-- Iteration 0 --
+COUNT_NORMAL is 0
+COUNT_RECURSIVE is 0
+
+-- Iteration 1 --
+COUNT_NORMAL is 1
+COUNT_RECURSIVE is 1
+
+-- Iteration 2 --
+COUNT_NORMAL is 4
+COUNT_RECURSIVE is 7
+
+-- Iteration 3 --
+COUNT_NORMAL is 2
+COUNT_RECURSIVE is 8
+
+-- Iteration 4 --
+COUNT_NORMAL is 4
+COUNT_RECURSIVE is 4
+
+-- Iteration 5 --
+COUNT_NORMAL is 5
+COUNT_RECURSIVE is 5
+
+-- Iteration 6 --
+COUNT_NORMAL is 6
+COUNT_RECURSIVE is 6
+
+-- Iteration 7 --
+COUNT_NORMAL is 4
+COUNT_RECURSIVE is 7
+
+-- Testing count() on constants with no second argument --
+COUNT_NORMAL: should be 1, is 1
+COUNT_NORMAL: should be 1, is 1
+
+-- Testing count() on NULL and Unset variables --
+COUNT_NORMAL: should be 0, is 0
+COUNT_NORMAL: should be 1, is 1
+COUNT_NORMAL: should be 0, is 0
+
+-- Testing count() on an empty sub-array --
+COUNT_NORMAL: should be 2, is 2
+COUNT_RECURSIVE: should be 5, is 5
+
+-- Testing count() on objects with Countable interface --
+COUNT_NORMAL: should be 3, is 3
+
+-- Testing count() on resource type --
+int(2)
+
+-- Testing count() on arrays containing references --
+For mode '0' count is => int(3)
+For mode '1' count is => int(9)
+For mode '0' count is => int(3)
+For mode '1' count is => int(9)
+For mode '-1' count is => int(3)
+For mode '-1.45' count is => int(3)
+For mode '2' count is => int(3)
+For mode '1' count is => int(9)
+For mode '' count is => int(3)
+For mode '' count is => int(3)
+
+-- Testing error conditions --
+Warning: count() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: count() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+
+Notice: Use of undefined constant ABCD - assumed 'ABCD' in %s on line %d
+
+Warning: count() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: count() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: count() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/md5.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/md5.phpt
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_merge.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_merge.phpt
+++ php-src/ext/standard/tests/array/array_merge.phpt
--TEST--
Test array_merge() function
--FILE--
<?php
/* Prototype: array array_merge(array $array1 [, array $array2 [, array $...]]);
Description: Merge one or more arrays
*/
echo "\n*** Testing array_merge() basic functionality ***";
$begin_array = array(
array(),
array( 1 => "string"),
array( "" => "string"),
array( -2.44444 => 12),
array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344),
array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL,1 => -2.344),
array( NULL, 1.23 => "Hi", "string" => "hello",
array("" => "World", "-2.34" => "a", "0" => "b"))
);
$end_array = array(
array(),
array( 1 => "string"),
array( "" => "string"),
array( -2.44444 => 12),
array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344),
array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL, 1=> -2.344),
array( NULL, 1.23 => "Hi", "string" => "hello",
array("" => "World", "-2.34" => "a", "0" => "b"))
);
/* loop through to merge two arrays */
$count_outer = 0;
foreach($begin_array as $first) {
echo "\n\n--- Iteration $count_outer ---";
$count_inner = 0;
foreach($end_array as $second) {
echo "\n-- Inner iteration $count_inner of Iteration $count_outer --\n";
$result = array_merge($first, $second);
print_r($result);
$count_inner++;
}
$count_outer++;
}
echo "\n*** Testing array_merge() with three or more arrays ***\n";
var_dump( array_merge( $end_array[0],
$end_array[5],
$end_array[4],
$end_array[6]
)
);
var_dump( array_merge( $end_array[0],
$end_array[5],
array("array on fly"),
array("nullarray" => array())
)
);
echo "\n*** Testing single array argument ***\n";
/* Empty array */
var_dump(array_merge(array()));
/* associative array with string keys, which will not be re-indexed */
var_dump(array_merge($begin_array[4]));
/* associative array with numeric keys, which will be re-indexed */
var_dump(array_merge($begin_array[5]));
/* associative array with mixed keys and sub-array as element */
var_dump(array_merge($begin_array[6]));
echo "\n*** Testing array_merge() with typecasting non-array to array ***\n";
var_dump(array_merge($begin_array[4], (array)"type1", (array)10, (array)12.34));
echo "\n*** Testing error conditions ***";
/* Invalid argumens */
var_dump(array_merge());
var_dump(array_merge(100, 200));
var_dump(array_merge($begin_array[0], $begin_array[1], 100));
var_dump(array_merge($begin_array[0], $begin_array[1], $arr4));
echo "Done\n";
?>
--EXPECTF--
*** Testing array_merge() basic functionality ***
--- Iteration 0 ---
-- Inner iteration 0 of Iteration 0 --
Array
(
)
-- Inner iteration 1 of Iteration 0 --
Array
(
[0] => string
)
-- Inner iteration 2 of Iteration 0 --
Array
(
[] => string
)
-- Inner iteration 3 of Iteration 0 --
Array
(
[0] => 12
)
-- Inner iteration 4 of Iteration 0 --
Array
(
[a] => 1
[b] => string
[c] =>
[d] => -2.344
)
-- Inner iteration 5 of Iteration 0 --
Array
(
[0] => 1
[1] => string
[2] =>
[3] => -2.344
)
-- Inner iteration 6 of Iteration 0 --
Array
(
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
)
--- Iteration 1 ---
-- Inner iteration 0 of Iteration 1 --
Array
(
[0] => string
)
-- Inner iteration 1 of Iteration 1 --
Array
(
[0] => string
[1] => string
)
-- Inner iteration 2 of Iteration 1 --
Array
(
[0] => string
[] => string
)
-- Inner iteration 3 of Iteration 1 --
Array
(
[0] => string
[1] => 12
)
-- Inner iteration 4 of Iteration 1 --
Array
(
[0] => string
[a] => 1
[b] => string
[c] =>
[d] => -2.344
)
-- Inner iteration 5 of Iteration 1 --
Array
(
[0] => string
[1] => 1
[2] => string
[3] =>
[4] => -2.344
)
-- Inner iteration 6 of Iteration 1 --
Array
(
[0] => string
[1] =>
[2] => Hi
[string] => hello
[3] => Array
(
[] => World
[-2.34] => a
[0] => b
)
)
--- Iteration 2 ---
-- Inner iteration 0 of Iteration 2 --
Array
(
[] => string
)
-- Inner iteration 1 of Iteration 2 --
Array
(
[] => string
[0] => string
)
-- Inner iteration 2 of Iteration 2 --
Array
(
[] => string
)
-- Inner iteration 3 of Iteration 2 --
Array
(
[] => string
[0] => 12
)
-- Inner iteration 4 of Iteration 2 --
Array
(
[] => string
[a] => 1
[b] => string
[c] =>
[d] => -2.344
)
-- Inner iteration 5 of Iteration 2 --
Array
(
[] => string
[0] => 1
[1] => string
[2] =>
[3] => -2.344
)
-- Inner iteration 6 of Iteration 2 --
Array
(
[] => string
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
)
--- Iteration 3 ---
-- Inner iteration 0 of Iteration 3 --
Array
(
[0] => 12
)
-- Inner iteration 1 of Iteration 3 --
Array
(
[0] => 12
[1] => string
)
-- Inner iteration 2 of Iteration 3 --
Array
(
[0] => 12
[] => string
)
-- Inner iteration 3 of Iteration 3 --
Array
(
[0] => 12
[1] => 12
)
-- Inner iteration 4 of Iteration 3 --
Array
(
[0] => 12
[a] => 1
[b] => string
[c] =>
[d] => -2.344
)
-- Inner iteration 5 of Iteration 3 --
Array
(
[0] => 12
[1] => 1
[2] => string
[3] =>
[4] => -2.344
)
-- Inner iteration 6 of Iteration 3 --
Array
(
[0] => 12
[1] =>
[2] => Hi
[string] => hello
[3] => Array
(
[] => World
[-2.34] => a
[0] => b
)
)
--- Iteration 4 ---
-- Inner iteration 0 of Iteration 4 --
Array
(
[a] => 1
[b] => string
[c] =>
[d] => -2.344
)
-- Inner iteration 1 of Iteration 4 --
Array
(
[a] => 1
[b] => string
[c] =>
[d] => -2.344
[0] => string
)
-- Inner iteration 2 of Iteration 4 --
Array
(
[a] => 1
[b] => string
[c] =>
[d] => -2.344
[] => string
)
-- Inner iteration 3 of Iteration 4 --
Array
(
[a] => 1
[b] => string
[c] =>
[d] => -2.344
[0] => 12
)
-- Inner iteration 4 of Iteration 4 --
Array
(
[a] => 1
[b] => string
[c] =>
[d] => -2.344
)
-- Inner iteration 5 of Iteration 4 --
Array
(
[a] => 1
[b] => string
[c] =>
[d] => -2.344
[0] => 1
[1] => string
[2] =>
[3] => -2.344
)
-- Inner iteration 6 of Iteration 4 --
Array
(
[a] => 1
[b] => string
[c] =>
[d] => -2.344
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
)
--- Iteration 5 ---
-- Inner iteration 0 of Iteration 5 --
Array
(
[0] => 1
[1] => string
[2] =>
[3] => -2.344
)
-- Inner iteration 1 of Iteration 5 --
Array
(
[0] => 1
[1] => string
[2] =>
[3] => -2.344
[4] => string
)
-- Inner iteration 2 of Iteration 5 --
Array
(
[0] => 1
[1] => string
[2] =>
[3] => -2.344
[] => string
)
-- Inner iteration 3 of Iteration 5 --
Array
(
[0] => 1
[1] => string
[2] =>
[3] => -2.344
[4] => 12
)
-- Inner iteration 4 of Iteration 5 --
Array
(
[0] => 1
[1] => string
[2] =>
[3] => -2.344
[a] => 1
[b] => string
[c] =>
[d] => -2.344
)
-- Inner iteration 5 of Iteration 5 --
Array
(
[0] => 1
[1] => string
[2] =>
[3] => -2.344
[4] => 1
[5] => string
[6] =>
[7] => -2.344
)
-- Inner iteration 6 of Iteration 5 --
Array
(
[0] => 1
[1] => string
[2] =>
[3] => -2.344
[4] =>
[5] => Hi
[string] => hello
[6] => Array
(
[] => World
[-2.34] => a
[0] => b
)
)
--- Iteration 6 ---
-- Inner iteration 0 of Iteration 6 --
Array
(
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
)
-- Inner iteration 1 of Iteration 6 --
Array
(
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
[3] => string
)
-- Inner iteration 2 of Iteration 6 --
Array
(
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
[] => string
)
-- Inner iteration 3 of Iteration 6 --
Array
(
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
[3] => 12
)
-- Inner iteration 4 of Iteration 6 --
Array
(
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
[a] => 1
[b] => string
[c] =>
[d] => -2.344
)
-- Inner iteration 5 of Iteration 6 --
Array
(
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
[3] => 1
[4] => string
[5] =>
[6] => -2.344
)
-- Inner iteration 6 of Iteration 6 --
Array
(
[0] =>
[1] => Hi
[string] => hello
[2] => Array
(
[] => World
[-2.34] => a
[0] => b
)
[3] =>
[4] => Hi
[5] => Array
(
[] => World
[-2.34] => a
[0] => b
)
)
*** Testing array_merge() with three or more arrays ***
array(12) {
[0]=>
int(1)
[1]=>
string(6) "string"
[2]=>
NULL
[3]=>
float(-2.344)
["a"]=>
int(1)
["b"]=>
string(6) "string"
["c"]=>
NULL
["d"]=>
float(-2.344)
[4]=>
NULL
[5]=>
string(2) "Hi"
["string"]=>
string(5) "hello"
[6]=>
array(3) {
[""]=>
string(5) "World"
["-2.34"]=>
string(1) "a"
[0]=>
string(1) "b"
}
}
array(6) {
[0]=>
int(1)
[1]=>
string(6) "string"
[2]=>
NULL
[3]=>
float(-2.344)
[4]=>
string(12) "array on fly"
["nullarray"]=>
array(0) {
}
}
*** Testing single array argument ***
array(0) {
}
array(4) {
["a"]=>
int(1)
["b"]=>
string(6) "string"
["c"]=>
NULL
["d"]=>
float(-2.344)
}
array(4) {
[0]=>
int(1)
[1]=>
string(6) "string"
[2]=>
NULL
[3]=>
float(-2.344)
}
array(4) {
[0]=>
NULL
[1]=>
string(2) "Hi"
["string"]=>
string(5) "hello"
[2]=>
array(3) {
[""]=>
string(5) "World"
["-2.34"]=>
string(1) "a"
[0]=>
string(1) "b"
}
}
*** Testing array_merge() with typecasting non-array to array ***
array(7) {
["a"]=>
int(1)
["b"]=>
string(6) "string"
["c"]=>
NULL
["d"]=>
float(-2.344)
[0]=>
string(5) "type1"
[1]=>
int(10)
[2]=>
float(12.34)
}
*** Testing error conditions ***
Warning: Wrong parameter count for array_merge() in %s on line %d
NULL
Warning: array_merge(): Argument #1 is not an array in %s on line %d
Warning: array_merge(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_merge(): Argument #3 is not an array in %s on line %d
NULL
Notice: Undefined variable: arr4 in %s on line %d
Warning: array_merge(): Argument #3 is not an array in %s on line %d
NULL
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_push.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_push.phpt
+++ php-src/ext/standard/tests/array/array_push.phpt
--TEST--
Test array_push() function
--FILE--
<?php
/* Prototype: int array_push( array &array );
* Description: Push one or more elements onto the end of array
and returns the new number of elements in the array.
*/
$empty_array = array();
$number = 5;
$str = "abc";
/* Various combinations of arrays to be used for the test */
$mixed_array = array(
array(),
array( 1,2,3,4,5,6,7,8,9 ),
array( "One", "_Two", "Three", "Four", "Five" ),
array( 6, "six", 7, "seven", 8, "eight", 9, "nine" ),
array( "a" => "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ),
array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" =>
"five" ),
array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ),
array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F"
=> "FFF",
"blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name"
=> "jonny", "a" => NULL, NULL => 3 ),
array( 12, "name", 'age', '45' ),
array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ),
array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6,
5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 )
);
/* Error Conditions */
echo "\n*** Testing Error Conditions ***\n";
/* Zero argument */
var_dump( array_push() );
/* Scalar argument */
var_dump( array_push($number, 22) );
/* String argument */
var_dump( array_push($str, 22) );
/* Invalid Number of arguments */
var_dump( array_push($mixed_array[1],1,2) );
/* Empty Array as argument */
var_dump( array_push($empty_array, 2) );
/* Loop to test normal functionality with different arrays inputs */
echo "\n*** Testing with various array inputs ***\n";
$counter = 1;
foreach( $mixed_array as $sub_array )
{
echo "\n-- Input Array for Iteration $counter is --\n";
print_r( $sub_array );
echo "\nOutput after push is :\n";
var_dump( array_push($sub_array, 22, "abc") );
$counter++;
}
/* Checking for return value and the new array formed from push operation */
echo "\n*** Checking for return value and the new array formed from push
operation ***\n";
var_dump( array_push($mixed_array[2], 22, 33, "44") );
var_dump( $mixed_array[2] );
echo"\nDone";
?>
--EXPECTF--
*** Testing Error Conditions ***
Warning: Wrong parameter count for array_push() in %s on line %d
NULL
Warning: array_push(): First argument should be an array in %s on line %d
bool(false)
Warning: array_push(): First argument should be an array in %s on line %d
bool(false)
int(11)
int(1)
*** Testing with various array inputs ***
-- Input Array for Iteration 1 is --
Array
(
)
Output after push is :
int(2)
-- Input Array for Iteration 2 is --
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 1
[10] => 2
)
Output after push is :
int(13)
-- Input Array for Iteration 3 is --
Array
(
[0] => One
[1] => _Two
[2] => Three
[3] => Four
[4] => Five
)
Output after push is :
int(7)
-- Input Array for Iteration 4 is --
Array
(
[0] => 6
[1] => six
[2] => 7
[3] => seven
[4] => 8
[5] => eight
[6] => 9
[7] => nine
)
Output after push is :
int(10)
-- Input Array for Iteration 5 is --
Array
(
[a] => aaa
[A] => AAA
[c] => ccc
[d] => ddd
[e] => eee
)
Output after push is :
int(7)
-- Input Array for Iteration 6 is --
Array
(
[1] => one
[2] => two
[3] => three
[4] => four
[5] => five
)
Output after push is :
int(7)
-- Input Array for Iteration 7 is --
Array
(
[1] => one
[2] => two
[3] => 7
[4] => four
[5] => five
)
Output after push is :
int(7)
-- Input Array for Iteration 8 is --
Array
(
[f] => fff
[1] => one
[4] => 6
[] => 3
[2] => float
[F] => FFF
[blank] =>
[3] => 3.7
[5] => Five
[6] => 8.6
[4name] => jonny
[a] =>
)
Output after push is :
int(14)
-- Input Array for Iteration 9 is --
Array
(
[0] => 12
[1] => name
[2] => age
[3] => 45
)
Output after push is :
int(6)
-- Input Array for Iteration 10 is --
Array
(
[0] => Array
(
[0] => oNe
[1] => tWo
[2] => 4
)
[1] => Array
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
)
[2] => Array
(
)
)
Output after push is :
int(5)
-- Input Array for Iteration 11 is --
Array
(
[one] => 2
[three] => 3
[0] => 3
[1] => 4
[3] => 33
[4] => 44
[5] => 57
[6] => 6
[5.4] => 554
[5.7] => 557
)
Output after push is :
int(12)
*** Checking for return value and the new array formed from push operation ***
int(8)
array(8) {
[0]=>
string(3) "One"
[1]=>
string(4) "_Two"
[2]=>
string(5) "Three"
[3]=>
string(4) "Four"
[4]=>
string(4) "Five"
[5]=>
int(22)
[6]=>
int(33)
[7]=>
string(2) "44"
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/fprintf.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/strings/fprintf.phpt
+++ php-src/ext/standard/tests/strings/fprintf.phpt
--TEST--
Test fprintf() function
--SKIPIF--
<?php
$path = dirname(__FILE__);
$data_file = "$path/dump.xt";
if !($fp = fopen($data_file, 'w')) {
echo "File dump.txt could not be created ,hence exiting from testcase due to
pre-requisite failure\n";
}
?>
--FILE--
<?php
/* Prototype: int fprintf( resource handle, string format[, mixed args [, mixed
...]] )
* Description: Write a formatted string to a stream
*/
$float_variation = array( "%f","%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f",
"%-07.2f", "%'#7.2f" );
$float_numbers = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54 );
$int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d",
"%-07.2d", "%'#7.2d" );
$int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );
$char_variation = array( 'a', "a", 67, -67, 99 );
$string_variation = array( "%5s", "%-5s", "%05s", "%'#5s" );
$strings = array( NULL, "abc", 'aaa' );
/* creating dumping file */
if (!($fp = fopen('dump.txt', 'w')))
return;
/* Testing Error Conditions */
echo "*** Testing Error Conditions ***\n";
/* zero argument */
var_dump( fprintf() );
/* scalar argument */
var_dump( fprintf(3) );
/* NULL argument */
var_dump( fprintf(NULL) );
$counter = 1;
/* float type variations */
fprintf($fp, "\n*** Testing fprintf() with floats ***\n");
foreach( $float_variation as $float_var ) {
fprintf( $fp, "\n-- Iteration %d --\n",$counter);
foreach( $float_numbers as $float_num ) {
fprintf( $fp, "\n");
fprintf( $fp, $float_var, $float_num );
}
$counter++;
}
$counter = 1;
/* integer type variations */
fprintf($fp, "\n*** Testing fprintf() with integers ***\n");
foreach( $int_variation as $int_var ) {
fprintf( $fp, "\n-- Iteration %d --\n",$counter);
foreach( $int_numbers as $int_num ) {
fprintf( $fp, "\n");
fprintf( $fp, $int_var, $int_num );
}
$counter++;
}
/* binary type variations */
fprintf($fp, "\n*** Testing fprintf() with binary ***\n");
foreach( $int_numbers as $bin_num ) {
fprintf( $fp, "\n");
fprintf( $fp, "%b", $bin_num );
}
/* char type variations */
fprintf($fp, "\n*** Testing fprintf() for chars ***\n");
foreach( $char_variation as $char ) {
fprintf( $fp, "\n");
fprintf( $fp,"%c", $char );
}
/* %e type variations */
fprintf($fp, "\n*** Testing fprintf() for scientific type ***\n");
foreach( $int_numbers as $num ) {
fprintf( $fp, "\n");
fprintf( $fp, "%e", $num );
}
/* unsigned int type variation */
fprintf($fp, "\n*** Testing fprintf() for unsigned integers ***\n");
foreach( $int_numbers as $unsig_num ) {
fprintf( $fp, "\n");
fprintf( $fp, "%u", $unsig_num );
}
/* octal type variations */
fprintf($fp, "\n*** Testing fprintf() for octals ***\n");
foreach( $int_numbers as $octal_num ) {
fprintf( $fp, "\n");
fprintf( $fp, "%o", $octal_num );
}
/* hexadecimal type variations */
fprintf($fp, "\n*** Testing fprintf() for hexadecimals ***\n");
foreach( $int_numbers as $hexa_num ) {
fprintf( $fp, "\n");
fprintf( $fp, "%x", $hexa_num );
}
$counter = 1;
/* string type variations */
fprintf($fp, "\n*** Testing fprintf() for string types ***\n");
foreach( $string_variation as $string_var ) {
fprintf( $fp, "\n-- Iteration %d --\n",$counter);
foreach( $strings as $str ) {
fprintf( $fp, "\n");
fprintf( $fp, $string_var, $str );
}
$counter++;
}
print_r( file_get_contents("dump.txt") );
echo "\nDone";
fclose($fp);
?>
--EXPECTF--
*** Testing Error Conditions ***
Warning: Wrong parameter count for fprintf() in %s on line %d
NULL
Warning: Wrong parameter count for fprintf() in %s on line %d
NULL
Warning: Wrong parameter count for fprintf() in %s on line %d
NULL
*** Testing fprintf() with floats ***
-- Iteration 1 --
0.000000
1.000000
-1.000000
0.320000
-0.320000
3.400000
2.540000
-2.540000
-- Iteration 2 --
0.000000
1.000000
-1.000000
0.320000
-0.320000
3.400000
2.540000
-2.540000
-- Iteration 3 --
+0.000000
+1.000000
-1.000000
+0.320000
-0.320000
+3.400000
+2.540000
-2.540000
-- Iteration 4 --
0.00
1.00
-1.00
0.32
-0.32
3.40
2.54
-2.54
-- Iteration 5 --
0.00
1.00
-1.00
0.32
-0.32
3.40
2.54
-2.54
-- Iteration 6 --
0000.00
0001.00
-001.00
0000.32
-000.32
0003.40
0002.54
-002.54
-- Iteration 7 --
0.00000
1.00000
-1.0000
0.32000
-0.3200
3.40000
2.54000
-2.5400
-- Iteration 8 --
###0.00
###1.00
##-1.00
###0.32
##-0.32
###3.40
###2.54
##-2.54
*** Testing fprintf() with integers ***
-- Iteration 1 --
0
1
-1
2
-2
23333333
-23333333
1234
-- Iteration 2 --
0
1
-1
2
-2
23333333
-23333333
1234
-- Iteration 3 --
+0
+1
-1
+2
-2
+23333333
-23333333
+1234
-- Iteration 4 --
0
1
-1
2
-2
23333333
-23333333
1234
-- Iteration 5 --
0
1
-1
2
-2
23333333
-23333333
1234
-- Iteration 6 --
0000000
0000001
-000001
0000002
-000002
23333333
-23333333
0001234
-- Iteration 7 --
0
1
-1
2
-2
23333333
-23333333
1234
-- Iteration 8 --
######0
######1
#####-1
######2
#####-2
23333333
-23333333
###1234
*** Testing fprintf() with binary ***
0
1
11111111111111111111111111111111
10
11111111111111111111111111111110
1011001000000100111010101
11111110100110111111011000101011
10011010010
*** Testing fprintf() for chars ***
C
½
c
*** Testing fprintf() for scientific type ***
0.000000e+0
1.000000e+0
-1.000000e+0
2.700000e+0
-2.700000e+0
2.333333e+7
-2.333333e+7
1.234000e+3
*** Testing fprintf() for unsigned integers ***
0
1
4294967295
2
4294967294
23333333
4271633963
1234
*** Testing fprintf() for octals ***
0
1
37777777777
2
37777777776
131004725
37646773053
2322
*** Testing fprintf() for hexadecimals ***
0
1
ffffffff
2
fffffffe
16409d5
fe9bf62b
4d2
*** Testing fprintf() for string types ***
-- Iteration 1 --
abc
aaa
-- Iteration 2 --
abc
aaa
-- Iteration 3 --
00000
00abc
00aaa
-- Iteration 4 --
#####
##abc
##aaa
Done
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php