From: Raghubansh Kumar Date: Wed, 14 Nov 2007 17:21:09 +0000 (+0000) Subject: New testcases for uasort() function X-Git-Tag: RELEASE_2_0_0a1~1370 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=185411fd0daad6de3a76b801c58c38f3cd32d7a3;p=php New testcases for uasort() function --- diff --git a/ext/standard/tests/array/uasort_basic1.phpt b/ext/standard/tests/array/uasort_basic1.phpt new file mode 100644 index 0000000000..4fdd7a7147 --- /dev/null +++ b/ext/standard/tests/array/uasort_basic1.phpt @@ -0,0 +1,175 @@ +--TEST-- +Test uasort() function : basic functionality +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +// Int array with default keys +$int_values = array(1, 8, 9, 3, 2, 6, 7); +echo "-- Numeric array with default keys --\n"; +var_dump( uasort($int_values, 'cmp') ); +var_dump($int_values); + +// String array with default keys +$string_values = array("This", "is", 'a', "test"); +echo "-- String array with default keys --\n"; +var_dump( uasort($string_values, 'cmp') ); +var_dump($string_values); + +// Associative array with numeric keys +$numeric_key_arg = array(1=> 1, 2 => 2, 3 => 7, 5 => 4, 4 => 9); +echo "-- Associative array with numeric keys --\n"; +var_dump( uasort($numeric_key_arg, 'cmp') ); +var_dump($numeric_key_arg); + +// Associative array with string keys +$string_key_arg = array('one' => 4, 'two' => 2, 'three' => 1, 'four' => 10); +echo "-- Associative array with string keys --\n"; +var_dump( uasort($string_key_arg, 'cmp') ); +var_dump($string_key_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : basic functionality *** +-- Numeric array with default keys -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- String array with default keys -- +bool(true) +array(4) { + [0]=> + string(4) "This" + [2]=> + string(1) "a" + [1]=> + string(2) "is" + [3]=> + string(4) "test" +} +-- Associative array with numeric keys -- +bool(true) +array(5) { + [1]=> + int(1) + [2]=> + int(2) + [5]=> + int(4) + [3]=> + int(7) + [4]=> + int(9) +} +-- Associative array with string keys -- +bool(true) +array(4) { + ["three"]=> + int(1) + ["two"]=> + int(2) + ["one"]=> + int(4) + ["four"]=> + int(10) +} +Done +--UEXPECTF-- +*** Testing uasort() : basic functionality *** +-- Numeric array with default keys -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- String array with default keys -- +bool(true) +array(4) { + [0]=> + unicode(4) "This" + [2]=> + unicode(1) "a" + [1]=> + unicode(2) "is" + [3]=> + unicode(4) "test" +} +-- Associative array with numeric keys -- +bool(true) +array(5) { + [1]=> + int(1) + [2]=> + int(2) + [5]=> + int(4) + [3]=> + int(7) + [4]=> + int(9) +} +-- Associative array with string keys -- +bool(true) +array(4) { + [u"three"]=> + int(1) + [u"two"]=> + int(2) + [u"one"]=> + int(4) + [u"four"]=> + int(10) +} +Done diff --git a/ext/standard/tests/array/uasort_basic2.phpt b/ext/standard/tests/array/uasort_basic2.phpt new file mode 100644 index 0000000000..9c42b1f9e7 --- /dev/null +++ b/ext/standard/tests/array/uasort_basic2.phpt @@ -0,0 +1,153 @@ +--TEST-- +Test uasort() function : basic functionality - duplicate values +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +// increasing values +$int_values1 = array(1, 1, 2, 2, 3, 3); +echo "-- Numeric array with increasing values --\n"; +var_dump( uasort($int_values1, 'cmp') ); +var_dump($int_values1); + +// decreasing values +$int_values2 = array(3, 3, 2, 2, 1, 1); +echo "-- Numeric array with decreasing values --\n"; +var_dump( uasort($int_values2, 'cmp') ); +var_dump($int_values2); + +// increasing and decreasing values +$int_values3 = array(1, 2, 3, 3, 2, 1); +echo "-- Numeric array with increasing and decreasing values --\n"; +var_dump( uasort($int_values3, 'cmp') ); +var_dump($int_values3); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : basic functionality with duplicate values *** +-- Numeric array with increasing values -- +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(2) + [2]=> + int(2) + [5]=> + int(3) + [4]=> + int(3) +} +-- Numeric array with decreasing values -- +bool(true) +array(6) { + [4]=> + int(1) + [5]=> + int(1) + [3]=> + int(2) + [2]=> + int(2) + [1]=> + int(3) + [0]=> + int(3) +} +-- Numeric array with increasing and decreasing values -- +bool(true) +array(6) { + [5]=> + int(1) + [0]=> + int(1) + [1]=> + int(2) + [4]=> + int(2) + [2]=> + int(3) + [3]=> + int(3) +} +Done +--UEXPECTF-- +*** Testing uasort() : basic functionality with duplicate values *** +-- Numeric array with increasing values -- +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(2) + [2]=> + int(2) + [5]=> + int(3) + [4]=> + int(3) +} +-- Numeric array with decreasing values -- +bool(true) +array(6) { + [4]=> + int(1) + [5]=> + int(1) + [3]=> + int(2) + [2]=> + int(2) + [1]=> + int(3) + [0]=> + int(3) +} +-- Numeric array with increasing and decreasing values -- +bool(true) +array(6) { + [5]=> + int(1) + [0]=> + int(1) + [1]=> + int(2) + [4]=> + int(2) + [2]=> + int(3) + [3]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/uasort_error.phpt b/ext/standard/tests/array/uasort_error.phpt new file mode 100644 index 0000000000..8f24b77ec1 --- /dev/null +++ b/ext/standard/tests/array/uasort_error.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test uasort() function : error conditions +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +// Initialize 'array_arg' +$array_arg = array(0 => 1, 1 => 10, 2 => 'string', 3 => 3, 4 => 2, 5 => 100, 6 => 25); + +// With zero arguments +echo "-- Testing uasort() function with Zero argument --\n"; +var_dump( uasort() ); + +// With one more than the expected number of arguments +echo "-- Testing uasort() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( uasort($array_arg, 'cmp', $extra_arg) ); + +// With one less than the expected number of arguments +echo "-- Testing uasort() function with less than expected no. of arguments --\n"; +var_dump( uasort($array_arg) ); + +// With non existent comparison function +echo "-- Testing uasort() function with non-existent compare function --\n"; +var_dump( uasort($array_arg, 'non_existent') ); + +// With non existent comparison function and extra arguemnt +echo "-- Testing uasort() function with non-existent compare function and extra argument --\n"; +var_dump( uasort($array_arg, 'non_existent', $extra_arg) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : error conditions *** +-- Testing uasort() function with Zero argument -- + +Warning: uasort() expects exactly 2 parameters, 0 given in %s on line %d +NULL +-- Testing uasort() function with more than expected no. of arguments -- + +Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d +NULL +-- Testing uasort() function with less than expected no. of arguments -- + +Warning: uasort() expects exactly 2 parameters, 1 given in %s on line %d +NULL +-- Testing uasort() function with non-existent compare function -- + +Warning: uasort() expects parameter 2 to be valid callback, string given in %s on line %d +NULL +-- Testing uasort() function with non-existent compare function and extra argument -- + +Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing uasort() : error conditions *** +-- Testing uasort() function with Zero argument -- + +Warning: uasort() expects exactly 2 parameters, 0 given in %s on line %d +NULL +-- Testing uasort() function with more than expected no. of arguments -- + +Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d +NULL +-- Testing uasort() function with less than expected no. of arguments -- + +Warning: uasort() expects exactly 2 parameters, 1 given in %s on line %d +NULL +-- Testing uasort() function with non-existent compare function -- + +Warning: uasort() expects parameter 2 to be valid callback, Unicode string given in %s on line %d +NULL +-- Testing uasort() function with non-existent compare function and extra argument -- + +Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_object1.phpt b/ext/standard/tests/array/uasort_object1.phpt new file mode 100644 index 0000000000..9ebd495c50 --- /dev/null +++ b/ext/standard/tests/array/uasort_object1.phpt @@ -0,0 +1,206 @@ +--TEST-- +Test uasort() function : object functionality +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +// comparison function for SimpleClass2 objects which has more than one members +function multiple_cmp($value1, $value2) +{ + if($value1->getValue() == $value2->getValue()) + return 0; + else if($value1->getValue() > $value2->getValue()) + return 1; + else + return -1; +} + +// Simple class with single member variable +class SimpleClass1 +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } +} + +// Simple class with more than one member variables +class SimpleClass2 +{ + private $int_value; + protected $float_value; + public $string_value; + public function __construct($int, $float, $str) { + $this->int_value = $int; + $this->float_value = $float; + $this->string_value = $str; + } + public function getValue() { + return $this->int_value; + } +} + +// array of SimpleClass objects with only one member +$array_arg = array( + 0 => new SimpleClass1(10), + 1 => new SimpleClass1(1), + 2 => new SimpleClass1(100), + 3 => new SimpleClass1(50) +); +var_dump( uasort($array_arg, 'simple_cmp') ); +var_dump($array_arg); + +// array of SimpleClass objects having more than one members +$array_arg = array( + 0 => new SimpleClass2(2, 3.4, "mango"), + 1 => new SimpleClass2(10, 1.2, "apple"), + 2 => new SimpleClass2(5, 2.5, "orange"), +); +var_dump( uasort($array_arg, 'multiple_cmp') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : object functionality *** +bool(true) +array(4) { + [1]=> + object(SimpleClass1)#2 (1) { + ["int_value":"SimpleClass1":private]=> + int(1) + } + [0]=> + object(SimpleClass1)#1 (1) { + ["int_value":"SimpleClass1":private]=> + int(10) + } + [3]=> + object(SimpleClass1)#4 (1) { + ["int_value":"SimpleClass1":private]=> + int(50) + } + [2]=> + object(SimpleClass1)#3 (1) { + ["int_value":"SimpleClass1":private]=> + int(100) + } +} +bool(true) +array(3) { + [0]=> + object(SimpleClass2)#5 (3) { + ["int_value":"SimpleClass2":private]=> + int(2) + ["float_value":protected]=> + float(3.4) + ["string_value"]=> + string(5) "mango" + } + [2]=> + object(SimpleClass2)#7 (3) { + ["int_value":"SimpleClass2":private]=> + int(5) + ["float_value":protected]=> + float(2.5) + ["string_value"]=> + string(6) "orange" + } + [1]=> + object(SimpleClass2)#6 (3) { + ["int_value":"SimpleClass2":private]=> + int(10) + ["float_value":protected]=> + float(1.2) + ["string_value"]=> + string(5) "apple" + } +} +Done +--UEXPECTF-- +*** Testing uasort() : object functionality *** +bool(true) +array(4) { + [1]=> + object(SimpleClass1)#2 (1) { + [u"int_value":u"SimpleClass1":private]=> + int(1) + } + [0]=> + object(SimpleClass1)#1 (1) { + [u"int_value":u"SimpleClass1":private]=> + int(10) + } + [3]=> + object(SimpleClass1)#4 (1) { + [u"int_value":u"SimpleClass1":private]=> + int(50) + } + [2]=> + object(SimpleClass1)#3 (1) { + [u"int_value":u"SimpleClass1":private]=> + int(100) + } +} +bool(true) +array(3) { + [0]=> + object(SimpleClass2)#5 (3) { + [u"int_value":u"SimpleClass2":private]=> + int(2) + [u"float_value":protected]=> + float(3.4) + [u"string_value"]=> + unicode(5) "mango" + } + [2]=> + object(SimpleClass2)#7 (3) { + [u"int_value":u"SimpleClass2":private]=> + int(5) + [u"float_value":protected]=> + float(2.5) + [u"string_value"]=> + unicode(6) "orange" + } + [1]=> + object(SimpleClass2)#6 (3) { + [u"int_value":u"SimpleClass2":private]=> + int(10) + [u"float_value":protected]=> + float(1.2) + [u"string_value"]=> + unicode(5) "apple" + } +} +Done diff --git a/ext/standard/tests/array/uasort_object2.phpt b/ext/standard/tests/array/uasort_object2.phpt new file mode 100644 index 0000000000..704129e0ed --- /dev/null +++ b/ext/standard/tests/array/uasort_object2.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test uasort() function : object functionality - sort diff. objects +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + + +// Simple class with single member variable +class SimpleClass +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } + +} + +// Class without any member +class EmptyClass +{ +} + +// Class with static member +class StaticClass +{ + public static $static_value; + public function __construct($value) { + StaticClass::$static_value = $value; + } +} + +// Abstract class +abstract class AbstractClass +{ + public $pub_value; + public abstract function abstractMethod(); +} + +// Child class extending abstract class +class ChildClass extends AbstractClass +{ + public $child_value = 100; + public function abstractMethod() { + $pub_value = 5; + } + public function __construct($value) { + $this->child_value = $value; + } +} + +// Testing uasort with StaticClass objects as elements of 'array_arg' +echo "-- Testing uasort() with StaticClass objects --\n"; +$array_arg = array( + 0 => new StaticClass(20), + 1 => new StaticClass(50), + 2 => new StaticClass(15), + 3 => new StaticClass(70), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with EmptyClass objects as elements of 'array_arg' +echo "-- Testing uasort() with EmptyClass objects --\n"; +$array_arg = array( + 0 => new EmptyClass(), + 1 => new EmptyClass(), + 2 => new EmptyClass(), + 3 => new EmptyClass(), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with ChildClass objects as elements of 'array_arg' +echo "-- Testing uasort() with ChildClass objects --\n"; +$array_arg = array( + 0 => new ChildClass(20), + 1 => new ChildClass(500), + 2 => new ChildClass(15), + 3 => new ChildClass(700), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : object functionality *** +-- Testing uasort() with StaticClass objects -- +bool(true) +array(4) { + [3]=> + object(StaticClass)#%d (0) { + } + [2]=> + object(StaticClass)#%d (0) { + } + [1]=> + object(StaticClass)#%d (0) { + } + [0]=> + object(StaticClass)#%d (0) { + } +} +-- Testing uasort() with EmptyClass objects -- +bool(true) +array(4) { + [3]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(EmptyClass)#%d (0) { + } + [1]=> + object(EmptyClass)#%d (0) { + } + [0]=> + object(EmptyClass)#%d (0) { + } +} +-- Testing uasort() with ChildClass objects -- +bool(true) +array(4) { + [2]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(15) + ["pub_value"]=> + NULL + } + [0]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(20) + ["pub_value"]=> + NULL + } + [1]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(500) + ["pub_value"]=> + NULL + } + [3]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(700) + ["pub_value"]=> + NULL + } +} +Done +--UEXPECTF-- +*** Testing uasort() : object functionality *** +-- Testing uasort() with StaticClass objects -- +bool(true) +array(4) { + [3]=> + object(StaticClass)#4 (0) { + } + [2]=> + object(StaticClass)#3 (0) { + } + [1]=> + object(StaticClass)#2 (0) { + } + [0]=> + object(StaticClass)#1 (0) { + } +} +-- Testing uasort() with EmptyClass objects -- +bool(true) +array(4) { + [3]=> + object(EmptyClass)#8 (0) { + } + [2]=> + object(EmptyClass)#7 (0) { + } + [1]=> + object(EmptyClass)#6 (0) { + } + [0]=> + object(EmptyClass)#5 (0) { + } +} +-- Testing uasort() with ChildClass objects -- +bool(true) +array(4) { + [2]=> + object(ChildClass)#3 (2) { + [u"child_value"]=> + int(15) + [u"pub_value"]=> + NULL + } + [0]=> + object(ChildClass)#1 (2) { + [u"child_value"]=> + int(20) + [u"pub_value"]=> + NULL + } + [1]=> + object(ChildClass)#2 (2) { + [u"child_value"]=> + int(500) + [u"pub_value"]=> + NULL + } + [3]=> + object(ChildClass)#4 (2) { + [u"child_value"]=> + int(700) + [u"pub_value"]=> + NULL + } +} +Done diff --git a/ext/standard/tests/array/uasort_variation1.phpt b/ext/standard/tests/array/uasort_variation1.phpt new file mode 100644 index 0000000000..f2a6ea9d71 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation1.phpt @@ -0,0 +1,279 @@ +--TEST-- +Test uasort() function : usage variations - unexpected values for 'array_arg' +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get resource variable +$fp = fopen(__FILE__,'r'); + +//array of values to iterate over +$input_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // resource data +/*20*/ $fp, + + // undefined data + @$undefined_var, + + // unset data +/*22*/ @$unset_var, +); + +// loop through each value of input_values +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( uasort($input_values[$count], 'cmp_function') ); +}; + +//closing resource +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : unexpected values for 'array_arg' *** +-- Iteration 1 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: uasort() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: uasort() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: uasort() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: uasort() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: uasort() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing uasort() : unexpected values for 'array_arg' *** +-- Iteration 1 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: uasort() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: uasort() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: uasort() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: uasort() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: uasort() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_variation10.phpt b/ext/standard/tests/array/uasort_variation10.phpt new file mode 100644 index 0000000000..0c6bebac63 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation10.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test uasort() function : usage variations - sort array with reference variables +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : 'array_arg' with elements as reference ***\n"; + +// different variables which are used as elements of 'array_arg' +$value1 = -5; +$value2 = 100; +$value3 = 0; +$value4 = &$value1; + +// array_args an array containing elements with reference variables +$array_arg = array( + 0 => 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +echo "-- Sorting 'array_arg' containing different references --\n"; +var_dump( uasort($array_arg, 'cmp_function') ); // expecting: bool(true) +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : 'array_arg' with elements as reference *** +-- Sorting 'array_arg' containing different references -- +bool(true) +array(5) { + [1]=> + &int(-5) + [4]=> + &int(0) + [0]=> + int(10) + [2]=> + &int(100) + [3]=> + int(200) +} +Done +--UEXPECTF-- +*** Testing uasort() : 'array_arg' with elements as reference *** +-- Sorting 'array_arg' containing different references -- +bool(true) +array(5) { + [1]=> + &int(-5) + [4]=> + &int(0) + [0]=> + int(10) + [2]=> + &int(100) + [3]=> + int(200) +} +Done diff --git a/ext/standard/tests/array/uasort_variation11.phpt b/ext/standard/tests/array/uasort_variation11.phpt new file mode 100644 index 0000000000..1fbe5b8eb7 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation11.phpt @@ -0,0 +1,115 @@ +--TEST-- +Test uasort() function : usage variations - different associative arrays +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +// Array with duplicate string and integer keys +$array_arg = array(0 => 2, "a" => 8, "d" => 9, 3 => 3, 5 => 2, "o" => 6, "z" => -99, 0 => 1, "z" => 3); +echo "-- Array with duplicate keys --\n"; +var_dump( uasort($array_arg, 'cmp') ); +var_dump($array_arg); + +// Array with default and assigned keys +$array_arg = array(0 => "Banana", 1 => "Mango", "Orange", 2 => "Apple", "Pineapple"); +echo "-- Array with default/assigned keys --\n"; +var_dump( uasort($array_arg, 'cmp') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : Sorting different associative arrays *** +-- Array with duplicate keys -- +bool(true) +array(7) { + [0]=> + int(1) + [5]=> + int(2) + ["z"]=> + int(3) + [3]=> + int(3) + ["o"]=> + int(6) + ["a"]=> + int(8) + ["d"]=> + int(9) +} +-- Array with default/assigned keys -- +bool(true) +array(4) { + [2]=> + string(5) "Apple" + [0]=> + string(6) "Banana" + [1]=> + string(5) "Mango" + [3]=> + string(9) "Pineapple" +} +Done +--UEXPECTF-- +*** Testing uasort() : Sorting different associative arrays *** +-- Array with duplicate keys -- +bool(true) +array(7) { + [0]=> + int(1) + [5]=> + int(2) + [u"z"]=> + int(3) + [3]=> + int(3) + [u"o"]=> + int(6) + [u"a"]=> + int(8) + [u"d"]=> + int(9) +} +-- Array with default/assigned keys -- +bool(true) +array(4) { + [2]=> + unicode(5) "Apple" + [0]=> + unicode(6) "Banana" + [1]=> + unicode(5) "Mango" + [3]=> + unicode(9) "Pineapple" +} +Done diff --git a/ext/standard/tests/array/uasort_variation2.phpt b/ext/standard/tests/array/uasort_variation2.phpt new file mode 100644 index 0000000000..c7e8025f59 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation2.phpt @@ -0,0 +1,328 @@ +--TEST-- +Test uasort() function : usage variations - unexpected values for 'cmp_function' +--FILE-- + 1, 1 => -1, 2 => 3, 3 => 10, 4 => 4, 5 => 2, 6 => 8, 7 => 5); + +// Get an unset variable +$unset_var = 10; +unset ($unset_var); + +// Get resource variable +$fp = fopen(__FILE__,'r'); + +// different values for 'cmp_function' +$cmp_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data + "string", + 'string', + + // object data +/*25*/ new MyClass(), + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/*28*/ @$unset_var, +); + +// loop through each element of the cmp_values for 'cmp_function' +for($count = 0; $count < count($cmp_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( uasort($array_arg, $cmp_values[$count]) ); +}; + +//closing resource +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : Unexpected values in place of comparison function *** +-- Iteration 1 -- + +Warning: uasort() expects parameter 2 to be valid callback, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: uasort() expects parameter 2 to be valid callback, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: uasort() expects parameter 2 to be valid callback, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: uasort() expects parameter 2 to be valid callback, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: uasort() expects parameter 2 to be valid callback, null given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: uasort() expects parameter 2 to be valid callback, null given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: uasort() expects parameter 2 to be valid callback, boolean given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: uasort() expects parameter 2 to be valid callback, boolean given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: uasort() expects parameter 2 to be valid callback, boolean given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: uasort() expects parameter 2 to be valid callback, boolean given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: uasort() expects parameter 2 to be valid callback, string given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: uasort() expects parameter 2 to be valid callback, string given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: uasort() expects parameter 2 to be valid callback, string given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: uasort() expects parameter 2 to be valid callback, string given in %s on line %d +NULL +-- Iteration 25 -- + +Warning: uasort() expects parameter 2 to be valid callback, object given in %s on line %d +NULL +-- Iteration 26 -- + +Warning: uasort() expects parameter 2 to be valid callback, resource given in %s on line %d +NULL +-- Iteration 27 -- + +Warning: uasort() expects parameter 2 to be valid callback, null given in %s on line %d +NULL +-- Iteration 28 -- + +Warning: uasort() expects parameter 2 to be valid callback, null given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing uasort() : Unexpected values in place of comparison function *** +-- Iteration 1 -- + +Warning: uasort() expects parameter 2 to be valid callback, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: uasort() expects parameter 2 to be valid callback, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: uasort() expects parameter 2 to be valid callback, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: uasort() expects parameter 2 to be valid callback, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: uasort() expects parameter 2 to be valid callback, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: uasort() expects parameter 2 to be valid callback, array given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: uasort() expects parameter 2 to be valid callback, null given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: uasort() expects parameter 2 to be valid callback, null given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: uasort() expects parameter 2 to be valid callback, boolean given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: uasort() expects parameter 2 to be valid callback, boolean given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: uasort() expects parameter 2 to be valid callback, boolean given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: uasort() expects parameter 2 to be valid callback, boolean given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: uasort() expects parameter 2 to be valid callback, Unicode string given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: uasort() expects parameter 2 to be valid callback, Unicode string given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: uasort() expects parameter 2 to be valid callback, Unicode string given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: uasort() expects parameter 2 to be valid callback, Unicode string given in %s on line %d +NULL +-- Iteration 25 -- + +Warning: uasort() expects parameter 2 to be valid callback, object given in %s on line %d +NULL +-- Iteration 26 -- + +Warning: uasort() expects parameter 2 to be valid callback, resource given in %s on line %d +NULL +-- Iteration 27 -- + +Warning: uasort() expects parameter 2 to be valid callback, null given in %s on line %d +NULL +-- Iteration 28 -- + +Warning: uasort() expects parameter 2 to be valid callback, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_variation3.phpt b/ext/standard/tests/array/uasort_variation3.phpt new file mode 100644 index 0000000000..93724fb0df Binary files /dev/null and b/ext/standard/tests/array/uasort_variation3.phpt differ diff --git a/ext/standard/tests/array/uasort_variation4.phpt b/ext/standard/tests/array/uasort_variation4.phpt new file mode 100644 index 0000000000..93f53b25a6 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation4.phpt @@ -0,0 +1,231 @@ +--TEST-- +Test uasort() function : usage variations - sort different numeric values +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : different numeric arrays as 'array_arg' ***\n"; + +// Int array +$int_values = array(0 => 3, 1 => 2, 3 => 100, 4 => 150, 5 => 25, 6 => 350, 7 => 0, 8 => -3, 9 => -1200); +echo "-- Sorting Integer array --\n"; +var_dump( uasort($int_values, 'cmp_function') ); // expecting: bool(true) +var_dump($int_values); + +// Octal array +$octal_values = array(0 => 056, 1 => 023, 2 => 090, 3 => 015, 4 => -045, 5 => 01, 6 => -078); +echo "-- Sorting Octal array --\n"; +var_dump( uasort($octal_values, 'cmp_function') ); // expecting: bool(true) +var_dump($octal_values); + +// Hexadecimal array +$hex_values = array(0 => 0xAE, 1 => 0x2B, 2 => 0X10, 3 => -0xCF, 4 => 0X12, 5 => -0XF2); +echo "-- Sorting Hex array --\n"; +var_dump( uasort($hex_values, 'cmp_function') ); // expecting: bool(true) +var_dump($hex_values); + +// Float array +$float_values = array( 0 => 10.2, 1 => 2.4, 2 => -3.4, 3 => 0, 4 => 0.5, 5 => 7.3e3, 6 => -9.34E-2); +echo "-- Sorting Float array --\n"; +var_dump( uasort($float_values, 'cmp_function') ); // expecting: bool(true) +var_dump($float_values); + +// empty array +$empty_array = array(); +echo "-- Sorting empty array --\n"; +var_dump( uasort($empty_array, 'cmp_function') ); // expecting: bool(true) +var_dump($empty_array); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : different numeric arrays as 'array_arg' *** +-- Sorting Integer array -- +bool(true) +array(9) { + [9]=> + int(-1200) + [8]=> + int(-3) + [7]=> + int(0) + [1]=> + int(2) + [0]=> + int(3) + [5]=> + int(25) + [3]=> + int(100) + [4]=> + int(150) + [6]=> + int(350) +} +-- Sorting Octal array -- +bool(true) +array(7) { + [4]=> + int(-37) + [6]=> + int(-7) + [2]=> + int(0) + [5]=> + int(1) + [3]=> + int(13) + [1]=> + int(19) + [0]=> + int(46) +} +-- Sorting Hex array -- +bool(true) +array(6) { + [5]=> + int(-242) + [3]=> + int(-207) + [2]=> + int(16) + [4]=> + int(18) + [1]=> + int(43) + [0]=> + int(174) +} +-- Sorting Float array -- +bool(true) +array(7) { + [2]=> + float(-3.4) + [6]=> + float(-0.0934) + [3]=> + int(0) + [4]=> + float(0.5) + [1]=> + float(2.4) + [0]=> + float(10.2) + [5]=> + float(7300) +} +-- Sorting empty array -- +bool(true) +array(0) { +} +Done +--UEXPECTF-- +*** Testing uasort() : different numeric arrays as 'array_arg' *** +-- Sorting Integer array -- +bool(true) +array(9) { + [9]=> + int(-1200) + [8]=> + int(-3) + [7]=> + int(0) + [1]=> + int(2) + [0]=> + int(3) + [5]=> + int(25) + [3]=> + int(100) + [4]=> + int(150) + [6]=> + int(350) +} +-- Sorting Octal array -- +bool(true) +array(7) { + [4]=> + int(-37) + [6]=> + int(-7) + [2]=> + int(0) + [5]=> + int(1) + [3]=> + int(13) + [1]=> + int(19) + [0]=> + int(46) +} +-- Sorting Hex array -- +bool(true) +array(6) { + [5]=> + int(-242) + [3]=> + int(-207) + [2]=> + int(16) + [4]=> + int(18) + [1]=> + int(43) + [0]=> + int(174) +} +-- Sorting Float array -- +bool(true) +array(7) { + [2]=> + float(-3.4) + [6]=> + float(-0.0934) + [3]=> + int(0) + [4]=> + float(0.5) + [1]=> + float(2.4) + [0]=> + float(10.2) + [5]=> + float(7300) +} +-- Sorting empty array -- +bool(true) +array(0) { +} +Done diff --git a/ext/standard/tests/array/uasort_variation5.phpt b/ext/standard/tests/array/uasort_variation5.phpt new file mode 100644 index 0000000000..ed5e0c40f9 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation5.phpt @@ -0,0 +1,209 @@ +--TEST-- +Test uasort() function : usage variations - sort diff. strings +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +// Different heredoc strings +$empty_heredoc =<< ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO', + 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', 9 => '\'', 10 => '@#$%' +); +echo "-- Sorting Single Quoted String values --\n"; +var_dump( uasort($single_quoted_values, 'cmp_function') ); // expecting: bool(true) +var_dump($single_quoted_values); + +// Double quoted strings +$double_quoted_values = array( + 0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO", + 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", 9 => "\"", 10 => "@#$%" +); +echo "-- Sorting Double Quoted String values --\n"; +var_dump( uasort($double_quoted_values, 'cmp_function') ); // expecting: bool(true) +var_dump($double_quoted_values); + +// Heredoc strings +$heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, 2 => $simple_heredoc2, 3 => $multiline_heredoc); +echo "-- Sorting Heredoc String values --\n"; +var_dump( uasort($heredoc_values, 'cmp_function') ); // expecting: bool(true) +var_dump($heredoc_values); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : different string arrays as 'array_arg' *** +-- Sorting Single Quoted String values -- +bool(true) +array(10) { + [5]=> + string(0) "" + [0]=> + string(1) " " + [9]=> + string(1) "'" + [7]=> + string(1) "0" + [8]=> + string(8) "123Hello" + [10]=> + string(4) "@#$%" + [4]=> + string(5) "HELLO" + [3]=> + string(5) "Hello" + [6]=> + string(2) "\t" + [1]=> + string(4) "test" +} +-- Sorting Double Quoted String values -- +bool(true) +array(10) { + [5]=> + string(0) "" + [6]=> + string(1) " " + [0]=> + string(1) " " + [9]=> + string(1) """ + [7]=> + string(1) "0" + [8]=> + string(8) "123Hello" + [10]=> + string(4) "@#$%" + [4]=> + string(5) "HELLO" + [3]=> + string(5) "Hello" + [1]=> + string(4) "test" +} +-- Sorting Heredoc String values -- +bool(true) +array(4) { + [0]=> + string(0) "" + [2]=> + string(7) "HEREDOC" + [1]=> + string(7) "Heredoc" + [3]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} +Done +--UEXPECTF-- +*** Testing uasort() : different string arrays as 'array_arg' *** +-- Sorting Single Quoted String values -- +bool(true) +array(10) { + [5]=> + unicode(0) "" + [0]=> + unicode(1) " " + [9]=> + unicode(1) "'" + [7]=> + unicode(1) "0" + [8]=> + unicode(8) "123Hello" + [10]=> + unicode(4) "@#$%" + [4]=> + unicode(5) "HELLO" + [3]=> + unicode(5) "Hello" + [6]=> + unicode(2) "\t" + [1]=> + unicode(4) "test" +} +-- Sorting Double Quoted String values -- +bool(true) +array(10) { + [5]=> + unicode(0) "" + [6]=> + unicode(1) " " + [0]=> + unicode(1) " " + [9]=> + unicode(1) """ + [7]=> + unicode(1) "0" + [8]=> + unicode(8) "123Hello" + [10]=> + unicode(4) "@#$%" + [4]=> + unicode(5) "HELLO" + [3]=> + unicode(5) "Hello" + [1]=> + unicode(4) "test" +} +-- Sorting Heredoc String values -- +bool(true) +array(4) { + [0]=> + unicode(0) "" + [2]=> + unicode(7) "HEREDOC" + [1]=> + unicode(7) "Heredoc" + [3]=> + unicode(43) "heredoc string with!@# and 123 +Test this!!!" +} +Done diff --git a/ext/standard/tests/array/uasort_variation6.phpt b/ext/standard/tests/array/uasort_variation6.phpt new file mode 100644 index 0000000000..22b8179c56 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation6.phpt @@ -0,0 +1,181 @@ +--TEST-- +Test uasort() function : usage variations - sort array having subarrays +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : Array with different subarrays ***\n"; + +$array_args = array( + 0 => array(2, 10, -1), + 1 => array(100), + 2 => array(), + 3 => array(0), + 4 => array(-1), + 5 => array(-9, 34, 54, 0, 20), + 6 => array(''), + 7 => array("apple", "Apple", "APPLE", "aPPle", "aPpLe") +); +$temp_array = $array_args; +// sorting array_arg as whole array +var_dump( uasort($temp_array, 'cmp_function') ); // expecting: bool(true) +var_dump($temp_array); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : Array with different subarrays *** +bool(true) +array(8) { + [2]=> + array(0) { + } + [4]=> + array(1) { + [0]=> + int(-1) + } + [6]=> + array(1) { + [0]=> + string(0) "" + } + [3]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(100) + } + [0]=> + array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(-1) + } + [5]=> + array(5) { + [0]=> + int(-9) + [1]=> + int(34) + [2]=> + int(54) + [3]=> + int(0) + [4]=> + int(20) + } + [7]=> + array(5) { + [0]=> + string(5) "apple" + [1]=> + string(5) "Apple" + [2]=> + string(5) "APPLE" + [3]=> + string(5) "aPPle" + [4]=> + string(5) "aPpLe" + } +} +Done +--UEXPECTF-- +*** Testing uasort() : Array with different subarrays *** +bool(true) +array(8) { + [2]=> + array(0) { + } + [4]=> + array(1) { + [0]=> + int(-1) + } + [6]=> + array(1) { + [0]=> + unicode(0) "" + } + [3]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(100) + } + [0]=> + array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(-1) + } + [5]=> + array(5) { + [0]=> + int(-9) + [1]=> + int(34) + [2]=> + int(54) + [3]=> + int(0) + [4]=> + int(20) + } + [7]=> + array(5) { + [0]=> + unicode(5) "apple" + [1]=> + unicode(5) "Apple" + [2]=> + unicode(5) "APPLE" + [3]=> + unicode(5) "aPPle" + [4]=> + unicode(5) "aPpLe" + } +} +Done diff --git a/ext/standard/tests/array/uasort_variation7.phpt b/ext/standard/tests/array/uasort_variation7.phpt new file mode 100644 index 0000000000..f4a4660337 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation7.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test uasort() function : usage variations - anonymous function as 'cmp_function' +--FILE-- + $value2) {return 1;} else {return -1;}'; + +$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90); +echo "-- Anonymous 'cmp_function' with parameters passed by value --\n"; +var_dump( uasort($array_arg, create_function('$value1, $value2',$cmp_function) ) ); +var_dump($array_arg); + +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple"); +echo "-- Anonymous 'cmp_function' with parameters passed by reference --\n"; +var_dump( uasort($array_arg, create_function('&$value1, &$value2', $cmp_function) ) ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : anonymous function as 'cmp_function' *** +-- Anonymous 'cmp_function' with parameters passed by value -- +bool(true) +array(5) { + [2]=> + int(-70) + [1]=> + int(3) + [3]=> + int(24) + [4]=> + int(90) + [0]=> + int(100) +} +-- Anonymous 'cmp_function' with parameters passed by reference -- +bool(true) +array(4) { + ["a"]=> + string(5) "Apple" + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["p"]=> + string(9) "Pineapple" +} +Done +--UEXPECTF-- +*** Testing uasort() : anonymous function as 'cmp_function' *** +-- Anonymous 'cmp_function' with parameters passed by value -- +bool(true) +array(5) { + [2]=> + int(-70) + [1]=> + int(3) + [3]=> + int(24) + [4]=> + int(90) + [0]=> + int(100) +} +-- Anonymous 'cmp_function' with parameters passed by reference -- +bool(true) +array(4) { + [u"a"]=> + unicode(5) "Apple" + [u"b"]=> + unicode(6) "Banana" + [u"m"]=> + unicode(5) "Mango" + [u"p"]=> + unicode(9) "Pineapple" +} +Done diff --git a/ext/standard/tests/array/uasort_variation8.phpt b/ext/standard/tests/array/uasort_variation8.phpt new file mode 100644 index 0000000000..82fc1533a6 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation8.phpt @@ -0,0 +1,117 @@ +--TEST-- +Test uasort() function : usage variations - built-in function as 'cmp_function' +--FILE-- + "Banana", "m" => "Mango", "a" => "apple", "p" => "Pineapple", "o" => "orange"); +$builtin_fun_arg = $array_arg; +$languageConstruct_fun_arg = $array_arg; + +// Testing library functions as comparison function +echo "-- Testing uasort() with built-in 'cmp_function': strcasecmp() --\n"; +var_dump( uasort($builtin_fun_arg, 'strcasecmp') ); // expecting: bool(true) +var_dump($builtin_fun_arg); + +echo "-- Testing uasort() with built-in 'cmp_function': strcmp() --\n"; +var_dump( uasort($array_arg, 'strcmp') ); // expecting: bool(true) +var_dump($array_arg); + +// Testing with language construct as comparison function +echo "-- Testing uasort() with language construct as 'cmp_function' --\n"; +var_dump( uasort($languageConstruct_fun_arg, 'echo') ); // expecting: bool(false) + +echo "-- Testing uasort() with language construct as 'cmp_function' --\n"; +var_dump( uasort($languageConstruct_fun_arg, 'exit') ); // expecting: bool(false) + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : built in function as 'cmp_function' *** +-- Testing uasort() with built-in 'cmp_function': strcasecmp() -- +bool(true) +array(5) { + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["o"]=> + string(6) "orange" + ["p"]=> + string(9) "Pineapple" +} +-- Testing uasort() with built-in 'cmp_function': strcmp() -- +bool(true) +array(5) { + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["p"]=> + string(9) "Pineapple" + ["a"]=> + string(5) "apple" + ["o"]=> + string(6) "orange" +} +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort() expects parameter 2 to be valid callback, string given in %s on line %d +NULL +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort() expects parameter 2 to be valid callback, string given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing uasort() : built in function as 'cmp_function' *** +-- Testing uasort() with built-in 'cmp_function': strcasecmp() -- +bool(true) +array(5) { + [u"a"]=> + unicode(5) "apple" + [u"b"]=> + unicode(6) "Banana" + [u"m"]=> + unicode(5) "Mango" + [u"o"]=> + unicode(6) "orange" + [u"p"]=> + unicode(9) "Pineapple" +} +-- Testing uasort() with built-in 'cmp_function': strcmp() -- +bool(true) +array(5) { + [u"b"]=> + unicode(6) "Banana" + [u"m"]=> + unicode(5) "Mango" + [u"p"]=> + unicode(9) "Pineapple" + [u"a"]=> + unicode(5) "apple" + [u"o"]=> + unicode(6) "orange" +} +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort() expects parameter 2 to be valid callback, Unicode string given in %s on line %d +NULL +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort() expects parameter 2 to be valid callback, Unicode string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_variation9.phpt b/ext/standard/tests/array/uasort_variation9.phpt new file mode 100644 index 0000000000..70e518365f --- /dev/null +++ b/ext/standard/tests/array/uasort_variation9.phpt @@ -0,0 +1,115 @@ +--TEST-- +Test uasort() function : usage variations - 'cmp_function' with reference argument +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +// Int array with default keys +$int_values = array(1, 8, 9, 3, 2, 6, 7); +echo "-- Passing integer values to 'cmp_function' --\n"; +var_dump( uasort($int_values, 'cmp') ); +var_dump($int_values); + +// String array with default keys +$string_values = array("Mango", "Apple", "Orange", "Banana"); +echo "-- Passing string values to 'cmp_function' --\n"; +var_dump( uasort($string_values, 'cmp') ); +var_dump($string_values); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : 'cmp_function' with reference arguments *** +-- Passing integer values to 'cmp_function' -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- Passing string values to 'cmp_function' -- +bool(true) +array(4) { + [1]=> + string(5) "Apple" + [3]=> + string(6) "Banana" + [0]=> + string(5) "Mango" + [2]=> + string(6) "Orange" +} +Done +--UEXPECTF-- +*** Testing uasort() : 'cmp_function' with reference arguments *** +-- Passing integer values to 'cmp_function' -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- Passing string values to 'cmp_function' -- +bool(true) +array(4) { + [1]=> + unicode(5) "Apple" + [3]=> + unicode(6) "Banana" + [0]=> + unicode(5) "Mango" + [2]=> + unicode(6) "Orange" +} +Done