From: andy wharmby Date: Wed, 14 Jan 2009 14:38:29 +0000 (+0000) Subject: Fixed base64_decode variation tests and new base64_encode test. Tested on Windows... X-Git-Tag: php-5.4.0alpha1~191^2~4520 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3064e1140585a1512bd4aa721bc8c56e8eb6df7;p=php Fixed base64_decode variation tests and new base64_encode test. Tested on Windows, Linux and Linux64 bit --- diff --git a/ext/standard/tests/url/base64_decode_variation_001.phpt b/ext/standard/tests/url/base64_decode_variation_001.phpt index ee817e5ac4..d12131c8eb 100644 --- a/ext/standard/tests/url/base64_decode_variation_001.phpt +++ b/ext/standard/tests/url/base64_decode_variation_001.phpt @@ -18,155 +18,164 @@ echo "*** Testing base64_decode() : usage variations ***\n"; // Initialise function arguments not being substituted (if any) $strict = true; +//getting the resource +$file_handle = fopen(__FILE__, "r"); + //get an unset variable $unset_var = 10; unset ($unset_var); //array of values to iterate over -$values = array( - - // int data - 0, - 1, - 12345, - -2345, - - // float data - 10.5, - -10.5, - 10.1234567e10, - 10.7654321E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // object data - new stdclass(), - - // undefined data - $undefined_var, - - // unset data - $unset_var, +$values = array ( + // int data + "0" => 0, + "1" => 1, + "12345" => 12345, + "-2345" => -2345, + + // float data + "10.5" => 10.5, + "-10.5" => -10.5, + "10.1234567e10" => 10.1234567e10, + "10.7654321E-10" => 10.7654321E-10, + ".5" => .5, + + // array data + "array()" => array(), + "array(0)" => array(0), + "array(1)" => array(1), + "array(1, 2)" => array(1, 2), + "array('color' => 'red', 'item' => 'pen'" => array('color' => 'red', 'item' => 'pen'), + + // null data + "NULL" => NULL, + "null" => null, + + // boolean data + "true" => true, + "false" => false, + "TRUE" => TRUE, + "FALSE" => FALSE, + + // empty data + "\"\"" => "", + "''" => '', + + // object data + "stdClass object" => new stdclass(), + + // undefined data + "undefined variable" => $undefined_var, + + // unset data + "unset variable" => $unset_var, + + // resource data + "resource" => $file_handle ); -// loop through each element of the array for str - -foreach($values as $value) { - echo "\nArg value $value \n"; - var_dump( base64_decode($value, $strict) ); +// loop through each element of the array for str argument + +foreach($values as $key=>$value) { + echo "\n-- Arg value $key --\n"; + $output = base64_decode($value, $strict); + + if (is_string($output)) { + var_dump(bin2hex($output)); + } else { + var_dump($output); + } }; -echo "Done"; ?> +===Done=== --EXPECTF-- *** Testing base64_decode() : usage variations *** -Error: 8 - Undefined variable: undefined_var, %s(63) -Error: 8 - Undefined variable: unset_var, %s(66) +Error: 8 - Undefined variable: undefined_var, %s(%d) +Error: 8 - Undefined variable: unset_var, %s(%d) -Arg value 0 -string(0) "" +-- Arg value 0 -- +unicode(0) "" -Arg value 1 -string(0) "" +-- Arg value 1 -- +unicode(0) "" -Arg value 12345 -string(3) "×mø" +-- Arg value 12345 -- +unicode(6) "d76df8" -Arg value -2345 +-- Arg value -2345 -- bool(false) -Arg value 10.5 +-- Arg value 10.5 -- bool(false) -Arg value -10.5 +-- Arg value -10.5 -- bool(false) -Arg value 101234567000 -string(9) "×MvߎzïM4" +-- Arg value 10.1234567e10 -- +unicode(18) "d74d76df8e7aef4d34" -Arg value 1.07654321E-9 +-- Arg value 10.7654321E-10 -- bool(false) -Arg value 0.5 +-- Arg value .5 -- bool(false) -Error: 8 - Array to string conversion, %s(72) -Arg value Array -Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(73) +-- Arg value array() -- +Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(%d) NULL -Error: 8 - Array to string conversion, %s(72) -Arg value Array -Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(73) +-- Arg value array(0) -- +Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(%d) NULL -Error: 8 - Array to string conversion, %s(72) -Arg value Array -Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(73) +-- Arg value array(1) -- +Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(%d) NULL -Error: 8 - Array to string conversion, %s(72) -Arg value Array -Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(73) +-- Arg value array(1, 2) -- +Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(%d) NULL -Error: 8 - Array to string conversion, %s(72) -Arg value Array -Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(73) +-- Arg value array('color' => 'red', 'item' => 'pen' -- +Error: 2 - base64_decode() expects parameter 1 to be binary string, array given, %s(%d) NULL -Arg value -string(0) "" +-- Arg value NULL -- +unicode(0) "" -Arg value -string(0) "" +-- Arg value null -- +unicode(0) "" -Arg value 1 -string(0) "" +-- Arg value true -- +unicode(0) "" -Arg value -string(0) "" +-- Arg value false -- +unicode(0) "" -Arg value 1 -string(0) "" +-- Arg value TRUE -- +unicode(0) "" -Arg value -string(0) "" +-- Arg value FALSE -- +unicode(0) "" -Arg value -string(0) "" +-- Arg value "" -- +unicode(0) "" -Arg value -string(0) "" -Error: 4096 - Object of class stdClass could not be converted to string, %s(72) +-- Arg value '' -- +unicode(0) "" -Arg value -Error: 2 - base64_decode() expects parameter 1 to be binary string, object given, %s(73) +-- Arg value stdClass object -- +Error: 2 - base64_decode() expects parameter 1 to be binary string, object given, %s(%d) NULL -Arg value -string(0) "" +-- Arg value undefined variable -- +unicode(0) "" -Arg value -string(0) "" -Done +-- Arg value unset variable -- +unicode(0) "" + +-- Arg value resource -- +Error: 2 - base64_decode() expects parameter 1 to be binary string, resource given, %s(%d) +NULL +===Done=== \ No newline at end of file diff --git a/ext/standard/tests/url/base64_decode_variation_002.phpt b/ext/standard/tests/url/base64_decode_variation_002.phpt index 6697864a72..20bf35746b 100644 --- a/ext/standard/tests/url/base64_decode_variation_002.phpt +++ b/ext/standard/tests/url/base64_decode_variation_002.phpt @@ -18,165 +18,158 @@ echo "*** Testing base64_decode() : usage variations ***\n"; // Initialise function arguments not being substituted (if any) $str = 'aGVsbG8gd29ybGQh!'; +//getting the resource +$file_handle = fopen(__FILE__, "r"); + //get an unset variable $unset_var = 10; unset ($unset_var); //array of values to iterate over -$values = array( - - // int data - 0, - 1, - 12345, - -2345, - - // float data - 10.5, - -10.5, - 10.1234567e10, - 10.7654321E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // string data - "string", - 'string', - - // object data - new stdclass(), - - // undefined data - $undefined_var, - - // unset data - $unset_var, +$values = array ( + // int data + "0" => 0, + "1" => 1, + "12345" => 12345, + "-2345" => -2345, + + // float data + "10.5" => 10.5, + "-10.5" => -10.5, + "10.1234567e10" => 10.1234567e10, + "10.7654321E-10" => 10.7654321E-10, + ".5" => .5, + + // array data + "array()" => array(), + "array(0)" => array(0), + "array(1)" => array(1), + "array(1, 2)" => array(1, 2), + "array('color' => 'red', 'item' => 'pen'" => array('color' => 'red', 'item' => 'pen'), + + // null data + "NULL" => NULL, + "null" => null, + + // boolean data + "true" => true, + "false" => false, + "TRUE" => TRUE, + "FALSE" => FALSE, + + // empty data + "\"\"" => "", + "''" => '', + + // object data + "stdClass object" => new stdclass(), + + // undefined data + "undefined variable" => $undefined_var, + + // unset data + "unset variable" => $unset_var, + + // resource data + "resource" => $file_handle ); -// loop through each element of the array for strict +// loop through each element of the array for strict argument -foreach($values as $value) { - echo "\nArg value $value \n"; - var_dump( base64_decode($str, $value) ); +foreach($values as $key=>$value) { + echo "\n-- Arg value $key --\n"; + var_dump(base64_decode($str, $value)); }; -echo "Done"; ?> +===Done=== --EXPECTF-- *** Testing base64_decode() : usage variations *** -Error: 8 - Undefined variable: undefined_var, %s(67) -Error: 8 - Undefined variable: unset_var, %s(70) +Error: 8 - Undefined variable: undefined_var, %s(%d) +Error: 8 - Undefined variable: unset_var, %s(%d) -Arg value 0 +-- Arg value 0 -- string(12) "hello world!" -Arg value 1 +-- Arg value 1 -- bool(false) -Arg value 12345 +-- Arg value 12345 -- bool(false) -Arg value -2345 +-- Arg value -2345 -- bool(false) -Arg value 10.5 +-- Arg value 10.5 -- bool(false) -Arg value -10.5 +-- Arg value -10.5 -- bool(false) -Arg value 101234567000 +-- Arg value 10.1234567e10 -- bool(false) -Arg value 1.07654321E-9 +-- Arg value 10.7654321E-10 -- bool(false) -Arg value 0.5 +-- Arg value .5 -- bool(false) -Error: 8 - Array to string conversion, %s(76) -Arg value Array -Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +-- Arg value array() -- +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d) NULL -Error: 8 - Array to string conversion, %s(76) -Arg value Array -Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +-- Arg value array(0) -- +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d) NULL -Error: 8 - Array to string conversion, %s(76) -Arg value Array -Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +-- Arg value array(1) -- +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d) NULL -Error: 8 - Array to string conversion, %s(76) -Arg value Array -Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +-- Arg value array(1, 2) -- +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d) NULL -Error: 8 - Array to string conversion, %s(76) -Arg value Array -Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +-- Arg value array('color' => 'red', 'item' => 'pen' -- +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d) NULL -Arg value +-- Arg value NULL -- string(12) "hello world!" -Arg value +-- Arg value null -- string(12) "hello world!" -Arg value 1 +-- Arg value true -- bool(false) -Arg value +-- Arg value false -- string(12) "hello world!" -Arg value 1 +-- Arg value TRUE -- bool(false) -Arg value +-- Arg value FALSE -- string(12) "hello world!" -Arg value +-- Arg value "" -- string(12) "hello world!" -Arg value +-- Arg value '' -- string(12) "hello world!" -Arg value string -bool(false) - -Arg value string -bool(false) -Error: 4096 - Object of class stdClass could not be converted to string, %s(76) - -Arg value -Error: 2 - base64_decode() expects parameter 2 to be boolean, object given, %s(77) +-- Arg value stdClass object -- +Error: 2 - base64_decode() expects parameter 2 to be boolean, object given, %s(%d) NULL -Arg value +-- Arg value undefined variable -- string(12) "hello world!" -Arg value +-- Arg value unset variable -- string(12) "hello world!" -Done + +-- Arg value resource -- +Error: 2 - base64_decode() expects parameter 2 to be boolean, resource given, %s(%d) +NULL +===Done=== \ No newline at end of file diff --git a/ext/standard/tests/url/base64_encode_basic_002.phpt b/ext/standard/tests/url/base64_encode_basic_002.phpt new file mode 100644 index 0000000000..47e1115c06 --- /dev/null +++ b/ext/standard/tests/url/base64_encode_basic_002.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test base64_encode() function : basic functionality - check algorithm round trips +--FILE-- + +===Done=== +--EXPECTF-- +*** Testing base64_encode() : basic functionality *** + +--- Testing base64_encode() with binary string input --- +-- Iteration 1 -- +TEST PASSED +-- Iteration 2 -- +TEST PASSED +-- Iteration 3 -- +TEST PASSED +-- Iteration 4 -- +TEST PASSED +-- Iteration 5 -- +TEST PASSED +===Done===