diff options
-rw-r--r-- | ext/mbstring/mbstring.c | 7 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_stripos.phpt | 175 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_stripos_basic.phpt | 153 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_stripos_error1.phpt | 50 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_stripos_error2.phpt | 34 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_stripos_variation1.phpt | 182 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_stripos_variation2.phpt | 198 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_stripos_variation3.phpt | 202 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_stripos_variation4.phpt | 222 |
9 files changed, 1221 insertions, 2 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 5b35c8cea9..6e2fd9fe37 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -2392,10 +2392,13 @@ PHP_FUNCTION(mb_stripos) n = -1; offset = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", (char **)&haystack.val, (int *)&haystack.len, (char **)needle.val, (int *)&needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", (char **)&haystack.val, (int *)&haystack.len, (char **)&needle.val, (int *)&needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) { + RETURN_FALSE; + } + if (needle.len == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter."); RETURN_FALSE; } - n = php_mb_stripos(0, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, offset, from_encoding TSRMLS_CC); if (n >= 0) { diff --git a/ext/mbstring/tests/mb_stripos.phpt b/ext/mbstring/tests/mb_stripos.phpt new file mode 100644 index 0000000000..330ad409b4 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos.phpt @@ -0,0 +1,175 @@ +--TEST-- +mb_stripos() +--SKIPIF-- +<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?> +--FILE-- +<?php +// TODO: Add more encodings + +//$debug=true; +ini_set('include_path', dirname(__FILE__)); +include_once('common.inc'); + + +// Test string +$euc_jp = '0123この文字列は日本語です。EUC-JPを使っています。0123日本語は面倒臭い。'; + +// EUC-JP - With encoding parameter +mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n"); + +echo "== POSITIVE OFFSET ==\n"; +print mb_stripos($euc_jp,'日本語', 0, 'EUC-JP') . "\n"; +print mb_stripos($euc_jp, '0', 0, 'EUC-JP') . "\n"; +print mb_stripos($euc_jp, 3, 0, 'EUC-JP') . "\n"; +print mb_stripos($euc_jp, 0, 0, 'EUC-JP') . "\n"; +print mb_stripos($euc_jp,'日本語', 15, 'EUC-JP') . "\n"; +print mb_stripos($euc_jp, '0', 15, 'EUC-JP') . "\n"; +print mb_stripos($euc_jp, 3, 15, 'EUC-JP') . "\n"; +print mb_stripos($euc_jp, 0, 15, 'EUC-JP') . "\n"; + +// Negative offset +// Note: PHP Warning - offset is negative. +// Note: For offset(-15). It does not return position of latter string. (ie the same result as -50) +echo "== NEGATIVE OFFSET ==\n"; +$r = mb_stripos($euc_jp,'日本語', -15, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_stripos($euc_jp, '0', -15, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_stripos($euc_jp, 3, -15, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_stripos($euc_jp, 0, -15, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_stripos($euc_jp,'日本語', -50, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_stripos($euc_jp, '0', -50, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_stripos($euc_jp, 3, -50, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; +$r = mb_stripos($euc_jp, 0, -50, 'EUC-JP'); +($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; + +// Out of range - should return false +print ("== OUT OF RANGE ==\n"); +$r = mb_stripos($euc_jp,'日本語', 40, 'EUC-JP'); +($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; +$r = mb_stripos($euc_jp, '0', 40, 'EUC-JP'); +($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; +$r = mb_stripos($euc_jp, 3, 40, 'EUC-JP'); +($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; +$r = mb_stripos($euc_jp, 0, 40, 'EUC-JP'); +($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; +// Note: Returned NULL string +// echo gettype($r). ' val '. $r ."\n"; + + +// Non-existent +echo "== NON-EXISTENT ==\n"; +$r = mb_stripos($euc_jp, '韓国語', 0, 'EUC-JP'); +($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; +$r = mb_stripos($euc_jp, "\n", 0, 'EUC-JP'); +($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; + + +// EUC-JP - No encoding parameter +echo "== NO ENCODING PARAMETER ==\n"; +mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n"); + +print mb_stripos($euc_jp,'日本語', 0) . "\n"; +print mb_stripos($euc_jp, '0', 0) . "\n"; +print mb_stripos($euc_jp, 3, 0) . "\n"; +print mb_stripos($euc_jp, 0, 0) . "\n"; + +$r = mb_stripos($euc_jp,'韓国語', 0); +($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; +$r = mb_stripos($euc_jp,"\n", 0); +($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; + +// EUC-JP - No offset and encoding parameter +echo "== NO OFFSET AND ENCODING PARAMETER ==\n"; +mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n"); + +print mb_stripos($euc_jp,'日本語') . "\n"; +print mb_stripos($euc_jp, '0') . "\n"; +print mb_stripos($euc_jp, 3) . "\n"; +print mb_stripos($euc_jp, 0) . "\n"; + +$r = mb_stripos($euc_jp,'韓国語'); +($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; +$r = mb_stripos($euc_jp,"\n"); +($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; + + +// Invalid Parameters +echo "== INVALID PARAMETER TEST ==\n"; + +$r = mb_stripos($euc_jp,'','EUC-JP'); +($r === FALSE) ? print("OK_NULL\n") : print("NG_NULL\n"); +$r = mb_stripos($euc_jp, $t_ary, 'EUC-JP'); +($r === FALSE) ? print("OK_ARRAY\n") : print("NG_ARRAY\n"); +$r = mb_stripos($euc_jp, $t_obj, 'EUC-JP'); +($r === FALSE) ? print("OK_OBJECT\n") : print("NG_OBJECT\n"); +$r = mb_stripos($euc_jp, $t_obj, 'BAD_ENCODING'); +($r === FALSE) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n"); + + +?> + +--EXPECT-- +== POSITIVE OFFSET == +10 +0 +3 +0 +34 +30 +33 +30 +== NEGATIVE OFFSET == +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +ERR: Warning +OK_NEGATIVE_OFFSET +== OUT OF RANGE == +OK_OUT_RANGE +OK_OUT_RANGE +OK_OUT_RANGE +OK_OUT_RANGE +== NON-EXISTENT == +OK_STR +OK_NEWLINE +== NO ENCODING PARAMETER == +10 +0 +3 +0 +OK_STR +OK_NEWLINE +== NO OFFSET AND ENCODING PARAMETER == +10 +0 +3 +0 +OK_STR +OK_NEWLINE +== INVALID PARAMETER TEST == +ERR: Warning +OK_NULL +ERR: Warning +OK_ARRAY +ERR: Warning +OK_OBJECT +ERR: Warning +OK_BAD_ENCODING + diff --git a/ext/mbstring/tests/mb_stripos_basic.phpt b/ext/mbstring/tests/mb_stripos_basic.phpt new file mode 100644 index 0000000000..ee62df7dcc --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_basic.phpt @@ -0,0 +1,153 @@ +--TEST-- +Test mb_stripos() function : basic functionality +--SKIPIF-- +<?php +extension_loaded('mbstring') or die('skip'); +function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int mb_stripos(string $haystack, string $needle [, int $offset [, string $encoding]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/mbstring/mbstring.c + */ + +/* + * Test basic functionality of mb_stripos with ASCII and multibyte characters + */ + +echo "*** Testing mb_stripos() : basic functionality***\n"; + +mb_internal_encoding('UTF-8'); + +$string_ascii = 'abc def ABC DEF'; +//Japanese string in UTF-8 +$string_mb = 'ユ茯鴻с01234鐚鐚鐚鐚鐚'; + +echo "\n-- ISO-8859-1 string 1 --\n"; +var_dump(mb_stripos($string_ascii, 'd', 0, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 2 --\n"; +var_dump(mb_stripos($string_ascii, 'D', 0, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 3 --\n"; +var_dump(mb_stripos($string_ascii, 'd', 1, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 4 --\n"; +var_dump(mb_stripos($string_ascii, 'D', 1, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 5 --\n"; +var_dump(mb_stripos($string_ascii, 'c', 4, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 6 --\n"; +var_dump(mb_stripos($string_ascii, 'c D', 0, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 7 --\n"; +var_dump(mb_stripos($string_ascii, 'C d', 0, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 8 --\n"; +var_dump(mb_stripos($string_ascii, 'deF', 0, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 9 --\n"; +var_dump(mb_stripos($string_ascii, '123', 0, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 10 --\n"; +var_dump(mb_stripos($string_ascii, 'c D', 1, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 11 --\n"; +var_dump(mb_stripos($string_ascii, 'C d', 1, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 12 --\n"; +var_dump(mb_stripos($string_ascii, 'deF', 1, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 13 --\n"; +var_dump(mb_stripos($string_ascii, '123', 1, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 14 --\n"; +var_dump(mb_stripos($string_ascii, 'c D', 4, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 15 --\n"; +var_dump(mb_stripos($string_ascii, 'C d', 4, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 16 --\n"; +var_dump(mb_stripos($string_ascii, 'deF', 4, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 17 --\n"; +var_dump(mb_stripos($string_ascii, 'deF', 5, 'ISO-8859-1')); + +echo "\n-- ISO-8859-1 string 18 --\n"; +var_dump(mb_stripos($string_ascii, '123', 4, 'ISO-8859-1')); + +echo "\n-- Multibyte string 1 --\n"; +$needle1 = 'ユ茯'; +var_dump(mb_stripos($string_mb, $needle1)); + +echo "\n-- Multibyte string 2 --\n"; +$needle2 = '<筝'; +var_dump(mb_stripos($string_mb, $needle2)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing mb_stripos() : basic functionality*** + +-- ISO-8859-1 string 1 -- +int(4) + +-- ISO-8859-1 string 2 -- +int(4) + +-- ISO-8859-1 string 3 -- +int(4) + +-- ISO-8859-1 string 4 -- +int(4) + +-- ISO-8859-1 string 5 -- +int(10) + +-- ISO-8859-1 string 6 -- +int(2) + +-- ISO-8859-1 string 7 -- +int(2) + +-- ISO-8859-1 string 8 -- +int(4) + +-- ISO-8859-1 string 9 -- +bool(false) + +-- ISO-8859-1 string 10 -- +int(2) + +-- ISO-8859-1 string 11 -- +int(2) + +-- ISO-8859-1 string 12 -- +int(4) + +-- ISO-8859-1 string 13 -- +bool(false) + +-- ISO-8859-1 string 14 -- +int(10) + +-- ISO-8859-1 string 15 -- +int(10) + +-- ISO-8859-1 string 16 -- +int(4) + +-- ISO-8859-1 string 17 -- +int(12) + +-- ISO-8859-1 string 18 -- +bool(false) + +-- Multibyte string 1 -- +int(0) + +-- Multibyte string 2 -- +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_error1.phpt b/ext/mbstring/tests/mb_stripos_error1.phpt new file mode 100644 index 0000000000..cad623366f --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_error1.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test mb_stripos() function : error conditions - Pass incorrect number of args +--SKIPIF-- +<?php +extension_loaded('mbstring') or die('skip'); +function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int mb_stripos(string $haystack, string $needle [, int $offset [, string $encoding]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/mbstring/mbstring.c + */ + +/* + * Test how mb_stripos behaves when passed an incorrect number of arguments + */ + +echo "*** Testing mb_stripos() : error conditions ***\n"; + + +//Test mb_stripos with one more than the expected number of arguments +echo "\n-- Testing mb_stripos() function with more than expected no. of arguments --\n"; +$haystack = 'string_val'; +$needle = 'string_val'; +$offset = 10; +$encoding = 'string_val'; +$extra_arg = 10; +var_dump( mb_stripos($haystack, $needle, $offset, $encoding, $extra_arg) ); + +// Testing mb_stripos with one less than the expected number of arguments +echo "\n-- Testing mb_stripos() function with less than expected no. of arguments --\n"; +$haystack = 'string_val'; +var_dump( mb_stripos($haystack) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing mb_stripos() : error conditions *** + +-- Testing mb_stripos() function with more than expected no. of arguments -- + +Warning: mb_stripos() expects at most 4 parameters, 5 given in %s on line %d +bool(false) + +-- Testing mb_stripos() function with less than expected no. of arguments -- + +Warning: mb_stripos() expects at least 2 parameters, 1 given in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_error2.phpt b/ext/mbstring/tests/mb_stripos_error2.phpt new file mode 100644 index 0000000000..75e0e6d556 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_error2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test mb_stripos() function : error conditions - Pass unknown encoding +--SKIPIF-- +<?php +extension_loaded('mbstring') or die('skip'); +function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int mb_stripos(string $haystack, string $needle [, int $offset [, string $encoding]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/mbstring/mbstring.c + */ + +/* + * Pass an unknown encoding to mb_stripos() to test behaviour + */ + +echo "*** Testing mb_stripos() : error conditions ***\n"; +$haystack = 'Hello, world'; +$needle = 'world'; +$offset = 2; +$encoding = 'unknown-encoding'; + +var_dump( mb_stripos($haystack, $needle, $offset, $encoding) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing mb_stripos() : error conditions *** + +Warning: mb_stripos(): Unknown encoding "unknown-encoding" in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_variation1.phpt b/ext/mbstring/tests/mb_stripos_variation1.phpt new file mode 100644 index 0000000000..411a939694 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_variation1.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test mb_stripos() function : usage variations - pass different data types to $haystack arg +--SKIPIF-- +<?php +extension_loaded('mbstring') or die('skip'); +function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int mb_stripos(string $haystack, string $needle [, int $offset [, string $encoding]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/mbstring/mbstring.c + */ + +/* + * Pass mb_stripos different data types as $haystack arg to test behaviour + */ + +echo "*** Testing mb_stripos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$needle = 'string_val'; +$offset = 0; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $haystack argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of mb_stripos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( mb_stripos($input, $needle, $offset, $encoding)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing mb_stripos() : usage variations *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- +bool(false) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- + +Warning: mb_stripos() expects parameter 1 to be string, resource given in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_variation2.phpt b/ext/mbstring/tests/mb_stripos_variation2.phpt new file mode 100644 index 0000000000..630ba2ed85 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_variation2.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test mb_stripos() function : usage variations - pass different data types as $needle arg +--SKIPIF-- +<?php +extension_loaded('mbstring') or die('skip'); +function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int mb_stripos(string $haystack, string $needle [, int $offset [, string $encoding]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/mbstring/mbstring.c + */ + +/* + * Pass mb_stripos different data types as $needle arg to test behaviour + */ + +echo "*** Testing mb_stripos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$haystack = 'string_val'; +$offset = 0; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $needle argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of mb_stripos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( mb_stripos($haystack, $input, $offset, $encoding)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing mb_stripos() : usage variations *** + +-- Iteration 1 -- +bool(false) + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 18 -- +int(0) + +-- Iteration 19 -- +int(0) + +-- Iteration 20 -- +bool(false) + +-- Iteration 21 -- +bool(false) + +-- Iteration 22 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: mb_stripos(): Empty delimiter. in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: mb_stripos() expects parameter 2 to be string, resource given in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_variation3.phpt b/ext/mbstring/tests/mb_stripos_variation3.phpt new file mode 100644 index 0000000000..0aada9ee70 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_variation3.phpt @@ -0,0 +1,202 @@ +--TEST-- +Test mb_stripos() function : usage variations - pass different data types as $offset arg +--SKIPIF-- +<?php +extension_loaded('mbstring') or die('skip'); +function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int mb_stripos(string $haystack, string $needle [, int $offset [, string $encoding]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/mbstring/mbstring.c + */ + +/* + * Pass mb_stripos different data types as $offset arg to test behaviour + */ + +echo "*** Testing mb_stripos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$needle = 'a'; +$haystack = 'string_val'; +$encoding = 'utf-8'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $offest argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of mb_stripos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( mb_stripos($haystack, $needle, $input, $encoding)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing mb_stripos() : usage variations *** + +-- Iteration 1 -- +int(8) + +-- Iteration 2 -- +int(8) + +-- Iteration 3 -- + +Warning: mb_stripos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: mb_stripos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- + +Warning: mb_stripos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: mb_stripos(): Offset not contained in string. in %s on line %d +bool(false) + +-- Iteration 8 -- +int(8) + +-- Iteration 9 -- +int(8) + +-- Iteration 10 -- +int(8) + +-- Iteration 11 -- +int(8) + +-- Iteration 12 -- +int(8) + +-- Iteration 13 -- +int(8) + +-- Iteration 14 -- +int(8) + +-- Iteration 15 -- +int(8) + +-- Iteration 16 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: mb_stripos() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- Iteration 22 -- +int(8) + +-- Iteration 23 -- +int(8) + +-- Iteration 24 -- + +Warning: mb_stripos() expects parameter 3 to be long, resource given in %s on line %d +bool(false) +Done diff --git a/ext/mbstring/tests/mb_stripos_variation4.phpt b/ext/mbstring/tests/mb_stripos_variation4.phpt new file mode 100644 index 0000000000..c62b2c3ff5 --- /dev/null +++ b/ext/mbstring/tests/mb_stripos_variation4.phpt @@ -0,0 +1,222 @@ +--TEST-- +Test mb_stripos() function : usage variations - pass different data types as $encoding arg +--SKIPIF-- +<?php +extension_loaded('mbstring') or die('skip'); +function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); +?> +--FILE-- +<?php +/* Prototype : int mb_stripos(string $haystack, string $needle [, int $offset [, string $encoding]]) + * Description: Find position of first occurrence of a string within another + * Source code: ext/mbstring/mbstring.c + */ + +/* + * Pass mb_stripos different data types as $encoding arg to test behaviour + * Where possible 'UTF-8' has been entered as a string value + */ + +echo "*** Testing mb_stripos() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$haystack = 'string_val'; +$needle = 'val'; +$offset = 0; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "UTF-8"; + } +} + +// heredoc string +$heredoc = <<<EOT +UTF-8 +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "UTF-8", + 'UTF-8', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of mb_stripos() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( mb_stripos($haystack, $needle, $offset, $input)); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing mb_stripos() : usage variations *** + +-- Iteration 1 -- + +Warning: mb_stripos(): Unknown encoding "0" in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: mb_stripos(): Unknown encoding "1" in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: mb_stripos(): Unknown encoding "12345" in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: mb_stripos(): Unknown encoding "-2345" in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: mb_stripos(): Unknown encoding "10.5" in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: mb_stripos(): Unknown encoding "-10.5" in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: mb_stripos(): Unknown encoding "123456789000" in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: mb_stripos(): Unknown encoding "1.23456789E-9" in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: mb_stripos(): Unknown encoding "0.5" in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: mb_stripos(): Unknown encoding "1" in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: mb_stripos(): Unknown encoding "1" in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 18 -- +int(7) + +-- Iteration 19 -- +int(7) + +-- Iteration 20 -- +int(7) + +-- Iteration 21 -- +int(7) + +-- Iteration 22 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: mb_stripos(): Unknown encoding "" in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: mb_stripos() expects parameter 4 to be string, resource given in %s on line %d +bool(false) +Done |