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

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

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