Annotation of embedaddon/php/ext/mbstring/tests/mb_strtoupper_variation2.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test mb_strtoupper() function : usage varitations - Pass different data types as $encoding arg
                      3: --SKIPIF--
                      4: <?php
                      5: extension_loaded('mbstring') or die('skip');
                      6: function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: /* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
                     11:  * Description: Returns a uppercased version of $sourcestring
                     12:  * Source code: ext/mbstring/mbstring.c
                     13:  */
                     14: 
                     15: /*
                     16:  * Pass different data types as $encoding argument to mb_strtoupper() to test behaviour
                     17:  * Where possible, 'UTF-8' is entered as string value
                     18:  */
                     19: 
                     20: echo "*** Testing mb_strtoupper() : usage variations ***\n";
                     21: 
                     22: // Initialise function arguments not being substituted
                     23: $sourcestring = b'Hello, World';
                     24: 
                     25: //get an unset variable
                     26: $unset_var = 10;
                     27: unset ($unset_var);
                     28: 
                     29: // get a class
                     30: class classA
                     31: {
                     32:   public function __toString() {
                     33:     return "UTF-8";
                     34:   }
                     35: }
                     36: 
                     37: // heredoc string
                     38: $heredoc = <<<EOT
                     39: UTF-8
                     40: EOT;
                     41: 
                     42: // get a resource variable
                     43: $fp = fopen(__FILE__, "r");
                     44: 
                     45: // unexpected values to be passed to $encoding argument
                     46: $inputs = array(
                     47: 
                     48:        // int data
                     49: /*1*/  0,
                     50:        1,
                     51:        12345,
                     52:        -2345,
                     53: 
                     54:        // float data
                     55: /*5*/  10.5,
                     56:        -10.5,
                     57:        12.3456789000e10,
                     58:        12.3456789000E-10,
                     59:        .5,
                     60: 
                     61:        // null data
                     62: /*10*/ NULL,
                     63:        null,
                     64: 
                     65:        // boolean data
                     66: /*12*/ true,
                     67:        false,
                     68:        TRUE,
                     69:        FALSE,
                     70:        
                     71:        // empty data
                     72: /*16*/ "",
                     73:        '',
                     74: 
                     75:        // string data
                     76: /*18*/ "UTF-8",
                     77:        'UTF-8',
                     78:        $heredoc,
                     79:        
                     80:        // object data
                     81: /*21*/ new classA(),
                     82: 
                     83:        // undefined data
                     84: /*22*/ @$undefined_var,
                     85: 
                     86:        // unset data
                     87: /*23*/ @$unset_var,
                     88: 
                     89:        // resource variable
                     90: /*24*/ $fp
                     91: );
                     92: 
                     93: // loop through each element of $inputs to check the behavior of mb_strtoupper()
                     94: $iterator = 1;
                     95: foreach($inputs as $input) {
                     96:   echo "\n-- Iteration $iterator --\n";
                     97:   $res = mb_strtoupper($sourcestring, $input);
                     98:   if ($res === false || $res == NULL) {
                     99:      var_dump($res);
                    100:   }
                    101:   else {
                    102:      var_dump(bin2hex($res));
                    103:   }
                    104:   $iterator++;
                    105: };
                    106: 
                    107: fclose($fp);
                    108: 
                    109: echo "Done";
                    110: ?>
                    111: 
                    112: --EXPECTF--
                    113: *** Testing mb_strtoupper() : usage variations ***
                    114: 
                    115: -- Iteration 1 --
                    116: 
                    117: Warning: mb_strtoupper(): Unknown encoding "0" in %s on line %d
                    118: bool(false)
                    119: 
                    120: -- Iteration 2 --
                    121: 
                    122: Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
                    123: bool(false)
                    124: 
                    125: -- Iteration 3 --
                    126: 
                    127: Warning: mb_strtoupper(): Unknown encoding "12345" in %s on line %d
                    128: bool(false)
                    129: 
                    130: -- Iteration 4 --
                    131: 
                    132: Warning: mb_strtoupper(): Unknown encoding "-2345" in %s on line %d
                    133: bool(false)
                    134: 
                    135: -- Iteration 5 --
                    136: 
                    137: Warning: mb_strtoupper(): Unknown encoding "10.5" in %s on line %d
                    138: bool(false)
                    139: 
                    140: -- Iteration 6 --
                    141: 
                    142: Warning: mb_strtoupper(): Unknown encoding "-10.5" in %s on line %d
                    143: bool(false)
                    144: 
                    145: -- Iteration 7 --
                    146: 
                    147: Warning: mb_strtoupper(): Unknown encoding "123456789000" in %s on line %d
                    148: bool(false)
                    149: 
                    150: -- Iteration 8 --
                    151: 
                    152: Warning: mb_strtoupper(): Unknown encoding "1.23456789E-9" in %s on line %d
                    153: bool(false)
                    154: 
                    155: -- Iteration 9 --
                    156: 
                    157: Warning: mb_strtoupper(): Unknown encoding "0.5" in %s on line %d
                    158: bool(false)
                    159: 
                    160: -- Iteration 10 --
                    161: 
                    162: Warning: mb_strtoupper(): Unknown encoding "(null)" in %s on line %d
                    163: bool(false)
                    164: 
                    165: -- Iteration 11 --
                    166: 
                    167: Warning: mb_strtoupper(): Unknown encoding "(null)" in %s on line %d
                    168: bool(false)
                    169: 
                    170: -- Iteration 12 --
                    171: 
                    172: Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
                    173: bool(false)
                    174: 
                    175: -- Iteration 13 --
                    176: 
                    177: Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d
                    178: bool(false)
                    179: 
                    180: -- Iteration 14 --
                    181: 
                    182: Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
                    183: bool(false)
                    184: 
                    185: -- Iteration 15 --
                    186: 
                    187: Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d
                    188: bool(false)
                    189: 
                    190: -- Iteration 16 --
                    191: 
                    192: Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d
                    193: bool(false)
                    194: 
                    195: -- Iteration 17 --
                    196: 
                    197: Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d
                    198: bool(false)
                    199: 
                    200: -- Iteration 18 --
                    201: string(24) "48454c4c4f2c20574f524c44"
                    202: 
                    203: -- Iteration 19 --
                    204: string(24) "48454c4c4f2c20574f524c44"
                    205: 
                    206: -- Iteration 20 --
                    207: string(24) "48454c4c4f2c20574f524c44"
                    208: 
                    209: -- Iteration 21 --
                    210: string(24) "48454c4c4f2c20574f524c44"
                    211: 
                    212: -- Iteration 22 --
                    213: 
                    214: Warning: mb_strtoupper(): Unknown encoding "(null)" in %s on line %d
                    215: bool(false)
                    216: 
                    217: -- Iteration 23 --
                    218: 
                    219: Warning: mb_strtoupper(): Unknown encoding "(null)" in %s on line %d
                    220: bool(false)
                    221: 
                    222: -- Iteration 24 --
                    223: 
                    224: Warning: mb_strtoupper() expects parameter 2 to be string, resource given in %s on line %d
                    225: NULL
                    226: Done

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