Annotation of embedaddon/php/ext/iconv/tests/iconv_set_encoding_variation.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test iconv_set_encoding() function : error functionality
                      3: --SKIPIF--
                      4: <?php
                      5: extension_loaded('iconv') or die('skip');
                      6: function_exists('iconv_set_encoding') or die("skip iconv_set_encoding() is not available in this build");
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: /* Prototype  : bool iconv_set_encoding(string type, string charset)
                     11:  * Description: Sets internal encoding and output encoding for ob_iconv_handler()
                     12:  * Source code: ext/iconv/iconv.c 
                     13:  */
                     14: 
                     15: /*
                     16:  * Test Error functionality of iconv_get_encoding
                     17:  */
                     18: 
                     19: echo "*** Testing iconv_set_encoding() : error functionality ***\n";
                     20: 
                     21: //get an unset variable
                     22: $unset_var = 10;
                     23: unset ($unset_var);
                     24: 
                     25: // get a class
                     26: class classA
                     27: {
                     28:   public function __toString() {
                     29:     return "UTF-8";
                     30:   }
                     31: }
                     32: 
                     33: // heredoc string
                     34: $heredoc = <<<EOT
                     35: Nothing
                     36: EOT;
                     37: 
                     38: // get a resource variable
                     39: $fp = fopen(__FILE__, "r");
                     40: 
                     41: // unexpected values to be passed to $encoding argument
                     42: $inputs = array(
                     43: 
                     44:        // int data
                     45: /*1*/  0,
                     46:        1,
                     47:        12345,
                     48:        -2345,
                     49: 
                     50:        // float data
                     51: /*5*/  10.5,
                     52:        -10.5,
                     53:        12.3456789000e10,
                     54:        12.3456789000E-10,
                     55:        .5,
                     56: 
                     57:        // null data
                     58: /*10*/ NULL,
                     59:        null,
                     60: 
                     61:        // boolean data
                     62: /*12*/ true,
                     63:        false,
                     64:        TRUE,
                     65:        FALSE,
                     66:        
                     67:        // empty data
                     68: /*16*/ "",
                     69:        '',
                     70: 
                     71:        // invalid string data
                     72: /*18*/ "Nothing",
                     73:        'Nothing',
                     74:        $heredoc,
                     75:        
                     76:        // object data
                     77: /*21*/ new classA(),
                     78: 
                     79:        // undefined data
                     80: /*22*/ @$undefined_var,
                     81: 
                     82:        // unset data
                     83: /*23*/ @$unset_var,
                     84: 
                     85:        // resource variable
                     86: /*24*/ $fp
                     87: );
                     88: 
                     89: // loop through each element of $inputs to check the behavior of mb_regex_encoding()
                     90: $iterator = 1;
                     91: foreach($inputs as $input) {
                     92:   echo "\n-- Iteration $iterator --\n";
                     93:   var_dump( iconv_set_encoding("internal_encoding", $input) );
                     94:   var_dump( iconv_set_encoding("input_encoding", $input) );
                     95:   var_dump( iconv_set_encoding("output_encoding", $input) );
                     96:   var_dump( iconv_get_encoding("internal_encoding") );
                     97:   var_dump( iconv_get_encoding("input_encoding") );
                     98:   var_dump( iconv_get_encoding("output_encoding") );
                     99: 
                    100:   $iterator++;
                    101: };
                    102: 
                    103: fclose($fp);
                    104: 
                    105: echo "Done";
                    106: ?>
                    107: --EXPECTF--
                    108: *** Testing iconv_set_encoding() : error functionality ***
                    109: 
                    110: -- Iteration 1 --
                    111: bool(true)
                    112: bool(true)
                    113: bool(true)
                    114: string(1) "0"
                    115: string(1) "0"
                    116: string(1) "0"
                    117: 
                    118: -- Iteration 2 --
                    119: bool(true)
                    120: bool(true)
                    121: bool(true)
                    122: string(1) "1"
                    123: string(1) "1"
                    124: string(1) "1"
                    125: 
                    126: -- Iteration 3 --
                    127: bool(true)
                    128: bool(true)
                    129: bool(true)
                    130: string(5) "12345"
                    131: string(5) "12345"
                    132: string(5) "12345"
                    133: 
                    134: -- Iteration 4 --
                    135: bool(true)
                    136: bool(true)
                    137: bool(true)
                    138: string(5) "-2345"
                    139: string(5) "-2345"
                    140: string(5) "-2345"
                    141: 
                    142: -- Iteration 5 --
                    143: bool(true)
                    144: bool(true)
                    145: bool(true)
                    146: string(4) "10.5"
                    147: string(4) "10.5"
                    148: string(4) "10.5"
                    149: 
                    150: -- Iteration 6 --
                    151: bool(true)
                    152: bool(true)
                    153: bool(true)
                    154: string(5) "-10.5"
                    155: string(5) "-10.5"
                    156: string(5) "-10.5"
                    157: 
                    158: -- Iteration 7 --
                    159: bool(true)
                    160: bool(true)
                    161: bool(true)
                    162: string(12) "123456789000"
                    163: string(12) "123456789000"
                    164: string(12) "123456789000"
                    165: 
                    166: -- Iteration 8 --
                    167: bool(true)
                    168: bool(true)
                    169: bool(true)
                    170: string(13) "1.23456789E-9"
                    171: string(13) "1.23456789E-9"
                    172: string(13) "1.23456789E-9"
                    173: 
                    174: -- Iteration 9 --
                    175: bool(true)
                    176: bool(true)
                    177: bool(true)
                    178: string(3) "0.5"
                    179: string(3) "0.5"
                    180: string(3) "0.5"
                    181: 
                    182: -- Iteration 10 --
                    183: bool(true)
                    184: bool(true)
                    185: bool(true)
                    186: string(0) ""
                    187: string(0) ""
                    188: string(0) ""
                    189: 
                    190: -- Iteration 11 --
                    191: bool(true)
                    192: bool(true)
                    193: bool(true)
                    194: string(0) ""
                    195: string(0) ""
                    196: string(0) ""
                    197: 
                    198: -- Iteration 12 --
                    199: bool(true)
                    200: bool(true)
                    201: bool(true)
                    202: string(1) "1"
                    203: string(1) "1"
                    204: string(1) "1"
                    205: 
                    206: -- Iteration 13 --
                    207: bool(true)
                    208: bool(true)
                    209: bool(true)
                    210: string(0) ""
                    211: string(0) ""
                    212: string(0) ""
                    213: 
                    214: -- Iteration 14 --
                    215: bool(true)
                    216: bool(true)
                    217: bool(true)
                    218: string(1) "1"
                    219: string(1) "1"
                    220: string(1) "1"
                    221: 
                    222: -- Iteration 15 --
                    223: bool(true)
                    224: bool(true)
                    225: bool(true)
                    226: string(0) ""
                    227: string(0) ""
                    228: string(0) ""
                    229: 
                    230: -- Iteration 16 --
                    231: bool(true)
                    232: bool(true)
                    233: bool(true)
                    234: string(0) ""
                    235: string(0) ""
                    236: string(0) ""
                    237: 
                    238: -- Iteration 17 --
                    239: bool(true)
                    240: bool(true)
                    241: bool(true)
                    242: string(0) ""
                    243: string(0) ""
                    244: string(0) ""
                    245: 
                    246: -- Iteration 18 --
                    247: bool(true)
                    248: bool(true)
                    249: bool(true)
                    250: string(7) "Nothing"
                    251: string(7) "Nothing"
                    252: string(7) "Nothing"
                    253: 
                    254: -- Iteration 19 --
                    255: bool(true)
                    256: bool(true)
                    257: bool(true)
                    258: string(7) "Nothing"
                    259: string(7) "Nothing"
                    260: string(7) "Nothing"
                    261: 
                    262: -- Iteration 20 --
                    263: bool(true)
                    264: bool(true)
                    265: bool(true)
                    266: string(7) "Nothing"
                    267: string(7) "Nothing"
                    268: string(7) "Nothing"
                    269: 
                    270: -- Iteration 21 --
                    271: bool(true)
                    272: bool(true)
                    273: bool(true)
                    274: string(5) "UTF-8"
                    275: string(5) "UTF-8"
                    276: string(5) "UTF-8"
                    277: 
                    278: -- Iteration 22 --
                    279: bool(true)
                    280: bool(true)
                    281: bool(true)
                    282: string(0) ""
                    283: string(0) ""
                    284: string(0) ""
                    285: 
                    286: -- Iteration 23 --
                    287: bool(true)
                    288: bool(true)
                    289: bool(true)
                    290: string(0) ""
                    291: string(0) ""
                    292: string(0) ""
                    293: 
                    294: -- Iteration 24 --
                    295: 
                    296: Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d
                    297: NULL
                    298: 
                    299: Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d
                    300: NULL
                    301: 
                    302: Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d
                    303: NULL
                    304: string(0) ""
                    305: string(0) ""
                    306: string(0) ""
                    307: Done

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