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

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

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