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

1.1       misho       1: --TEST--
                      2: Test iconv_strpos() function : usage variations - Pass different integers as $offset argument
                      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:  * Test how iconv_strpos() behaves when passed different integers as $offset argument
                     17:  * The character length of $string_ascii and $string_mb is the same, 
                     18:  * and the needle appears at the same positions in both strings
                     19:  */
                     20: 
                     21: iconv_set_encoding("internal_encoding", "UTF-8");
                     22: 
                     23: echo "*** Testing iconv_strpos() : usage variations ***\n";
                     24: 
                     25: $string_ascii = b'+Is an English string'; //21 chars
                     26: $needle_ascii = b'g';
                     27: 
                     28: $string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
                     29: $needle_mb = base64_decode(b'44CC');
                     30: 
                     31: /*
                     32:  * Loop through integers as multiples of ten for $offset argument
                     33:  * iconv_strpos should not be able to accept negative values as $offset.
                     34:  * 60 is larger than *BYTE* count for $string_mb
                     35:  */
                     36: for ($i = -10; $i <= 60; $i += 10) {
                     37:        echo "\n**-- Offset is: $i --**\n";
                     38:        echo "-- ASCII String --\n";
                     39:        var_dump(iconv_strpos($string_ascii, $needle_ascii, $i));
                     40:        echo "--Multibyte String --\n";
                     41:        var_dump(iconv_strpos($string_mb, $needle_mb, $i, 'UTF-8'));
                     42: }
                     43: 
                     44: echo "Done";
                     45: ?>
                     46: 
                     47: --EXPECTF--
                     48: *** Testing iconv_strpos() : usage variations ***
                     49: 
                     50: **-- Offset is: -10 --**
                     51: -- ASCII String --
                     52: 
                     53: Warning: iconv_strpos(): Offset not contained in string. in %s on line %d
                     54: bool(false)
                     55: --Multibyte String --
                     56: 
                     57: Warning: iconv_strpos(): Offset not contained in string. in %s on line %d
                     58: bool(false)
                     59: 
                     60: **-- Offset is: 0 --**
                     61: -- ASCII String --
                     62: int(9)
                     63: --Multibyte String --
                     64: int(9)
                     65: 
                     66: **-- Offset is: 10 --**
                     67: -- ASCII String --
                     68: int(20)
                     69: --Multibyte String --
                     70: int(20)
                     71: 
                     72: **-- Offset is: 20 --**
                     73: -- ASCII String --
                     74: int(20)
                     75: --Multibyte String --
                     76: int(20)
                     77: 
                     78: **-- Offset is: 30 --**
                     79: -- ASCII String --
                     80: bool(false)
                     81: --Multibyte String --
                     82: bool(false)
                     83: 
                     84: **-- Offset is: 40 --**
                     85: -- ASCII String --
                     86: bool(false)
                     87: --Multibyte String --
                     88: bool(false)
                     89: 
                     90: **-- Offset is: 50 --**
                     91: -- ASCII String --
                     92: bool(false)
                     93: --Multibyte String --
                     94: bool(false)
                     95: 
                     96: **-- Offset is: 60 --**
                     97: -- ASCII String --
                     98: bool(false)
                     99: --Multibyte String --
                    100: bool(false)
                    101: Done

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