]> granicus.if.org Git - php/commitdiff
Fixed base64_decode variation tests and new base64_encode test. Tested on Windows...
authorandy wharmby <wharmby@php.net>
Wed, 14 Jan 2009 14:38:29 +0000 (14:38 +0000)
committerandy wharmby <wharmby@php.net>
Wed, 14 Jan 2009 14:38:29 +0000 (14:38 +0000)
ext/standard/tests/url/base64_decode_variation_001.phpt
ext/standard/tests/url/base64_decode_variation_002.phpt
ext/standard/tests/url/base64_encode_basic_002.phpt [new file with mode: 0644]

index ee817e5ac46fb2288310524a590e685c5d6eeff3..d12131c8eb5b29d84444be14edf932f7ce901750 100644 (file)
@@ -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ß\8ezï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
index 6697864a72a597bb250c37b5f9c000163762662b..20bf35746bcff88e7238e65957300dbf328f7afc 100644 (file)
@@ -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 (file)
index 0000000..47e1115
--- /dev/null
@@ -0,0 +1,59 @@
+--TEST--
+Test base64_encode() function : basic functionality - check algorithm round trips 
+--FILE--
+<?php
+/* Prototype  : proto string base64_encode(string str)
+ * Description: Encodes string using MIME base64 algorithm 
+ * Source code: ext/standard/base64.c
+ * Alias to functions: 
+ */
+
+/*
+ * Test base64_encode with single byte values.
+ */
+
+echo "*** Testing base64_encode() : basic functionality ***\n";
+
+$values = array(
+       b"Hello World",
+       b"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!%^&*(){}[]",
+       b"\n\t Line with control characters\r\n",
+       b"\xC1\xC2\xC3\xC4\xC5\xC6",
+       b"\75\76\77\78\79\80"
+);
+
+echo "\n--- Testing base64_encode() with binary string input ---\n";
+
+$counter = 1;
+foreach($values as $str) {
+       echo "-- Iteration $counter --\n";
+       
+       $enc = base64_encode($str);
+       $dec = base64_decode($enc);
+
+       if ($dec != $str) {
+               echo "TEST FAILED\n";
+       } else {
+               echo "TEST PASSED\n";
+       }       
+
+       $counter ++;
+}
+
+?>
+===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===