File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / url / base64_encode_variation_001.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:04 2012 UTC (12 years, 4 months ago) by misho
Branches: php, MAIN
CVS tags: v5_3_10, HEAD
php

    1: --TEST--
    2: Test base64_encode() function : usage variations - unexpected types for argument 1 
    3: --FILE--
    4: <?php
    5: /* Prototype  : proto string base64_encode(string str)
    6:  * Description: Encodes string using MIME base64 algorithm 
    7:  * Source code: ext/standard/base64.c
    8:  * Alias to functions: 
    9:  */
   10: 
   11: echo "*** Testing base64_encode() : usage variations ***\n";
   12: 
   13: 
   14: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
   15: 	echo "Error: $err_no - $err_msg, $filename($linenum)\n";
   16: }
   17: set_error_handler('test_error_handler');
   18: 
   19: // Initialise function arguments not being substituted (if any)
   20: 
   21: //get an unset variable
   22: $unset_var = 10;
   23: unset ($unset_var);
   24: 
   25: //array of values to iterate over
   26: $values = array(
   27: 
   28:       // int data
   29:       0,
   30:       1,
   31:       12345,
   32:       -2345,
   33: 
   34:       // float data
   35:       10.5,
   36:       -10.5,
   37:       10.1234567e10,
   38:       10.7654321E-10,
   39:       .5,
   40: 
   41:       // array data
   42:       array(),
   43:       array(0),
   44:       array(1),
   45:       array(1, 2),
   46:       array('color' => 'red', 'item' => 'pen'),
   47: 
   48:       // null data
   49:       NULL,
   50:       null,
   51: 
   52:       // boolean data
   53:       true,
   54:       false,
   55:       TRUE,
   56:       FALSE,
   57: 
   58:       // empty data
   59:       "",
   60:       '',
   61: 
   62:       // object data
   63:       new stdclass(),
   64: 
   65:       // undefined data
   66:       $undefined_var,
   67: 
   68:       // unset data
   69:       $unset_var,
   70: );
   71: 
   72: // loop through each element of the array for str
   73: 
   74: foreach($values as $value) {
   75:       echo "\nArg value $value \n";
   76:       var_dump( base64_encode($value) );
   77: };
   78: 
   79: echo "Done";
   80: ?>
   81: --EXPECTF--
   82: *** Testing base64_encode() : usage variations ***
   83: Error: 8 - Undefined variable: undefined_var, %s(63)
   84: Error: 8 - Undefined variable: unset_var, %s(66)
   85: 
   86: Arg value 0 
   87: string(4) "MA=="
   88: 
   89: Arg value 1 
   90: string(4) "MQ=="
   91: 
   92: Arg value 12345 
   93: string(8) "MTIzNDU="
   94: 
   95: Arg value -2345 
   96: string(8) "LTIzNDU="
   97: 
   98: Arg value 10.5 
   99: string(8) "MTAuNQ=="
  100: 
  101: Arg value -10.5 
  102: string(8) "LTEwLjU="
  103: 
  104: Arg value 101234567000 
  105: string(16) "MTAxMjM0NTY3MDAw"
  106: 
  107: Arg value 1.07654321E-9 
  108: string(20) "MS4wNzY1NDMyMUUtOQ=="
  109: 
  110: Arg value 0.5 
  111: string(4) "MC41"
  112: 
  113: Arg value Array 
  114: Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73)
  115: NULL
  116: 
  117: Arg value Array 
  118: Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73)
  119: NULL
  120: 
  121: Arg value Array 
  122: Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73)
  123: NULL
  124: 
  125: Arg value Array 
  126: Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73)
  127: NULL
  128: 
  129: Arg value Array 
  130: Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73)
  131: NULL
  132: 
  133: Arg value  
  134: string(0) ""
  135: 
  136: Arg value  
  137: string(0) ""
  138: 
  139: Arg value 1 
  140: string(4) "MQ=="
  141: 
  142: Arg value  
  143: string(0) ""
  144: 
  145: Arg value 1 
  146: string(4) "MQ=="
  147: 
  148: Arg value  
  149: string(0) ""
  150: 
  151: Arg value  
  152: string(0) ""
  153: 
  154: Arg value  
  155: string(0) ""
  156: Error: 4096 - Object of class stdClass could not be converted to string, %s(72)
  157: 
  158: Arg value  
  159: Error: 2 - base64_encode() expects parameter 1 to be string, object given, %s(73)
  160: NULL
  161: 
  162: Arg value  
  163: string(0) ""
  164: 
  165: Arg value  
  166: string(0) ""
  167: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>