]> granicus.if.org Git - php/commitdiff
- Committing new tests for MBString extension.
authorJosie Messa <jmessa@php.net>
Fri, 1 Feb 2008 15:27:57 +0000 (15:27 +0000)
committerJosie Messa <jmessa@php.net>
Fri, 1 Feb 2008 15:27:57 +0000 (15:27 +0000)
More details can be found here: http://news.php.net/php.qa/62382

75 files changed:
ext/mbstring/tests/mb_convert_encoding_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_encode_mimeheader_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_encode_mimeheader_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_encode_mimeheader_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_encode_mimeheader_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_encode_mimeheader_variation4.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_encode_mimeheader_variation5.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_encode_mimeheader_variation6.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_error.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_variation4.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_variation5.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_variation6.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_ereg_variation7.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_internal_encoding_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_internal_encoding_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_internal_encoding_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_internal_encoding_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_internal_encoding_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_regex_encoding_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_regex_encoding_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_regex_encoding_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_regex_encoding_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strlen_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strlen_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strlen_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strlen_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strlen_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strlen_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strpos_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strpos_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strpos_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strpos_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strpos_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strpos_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strpos_variation4.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strrpos_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strrpos_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strrpos_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strrpos_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strrpos_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strrpos_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strrpos_variation4.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strrpos_variation5.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtolower_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtolower_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtolower_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtolower_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtolower_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtolower_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtolower_variation4.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtoupper_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtoupper_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtoupper_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtoupper_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtoupper_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtoupper_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_strtoupper_variation4.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_count_basic.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_count_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_count_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_count_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_count_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_count_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_error1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_error2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_variation1.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_variation2.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_variation3.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_variation4.phpt [new file with mode: 0644]
ext/mbstring/tests/mb_substr_variation5.phpt [new file with mode: 0644]

diff --git a/ext/mbstring/tests/mb_convert_encoding_basic.phpt b/ext/mbstring/tests/mb_convert_encoding_basic.phpt
new file mode 100644 (file)
index 0000000..d7f194e
--- /dev/null
@@ -0,0 +1,95 @@
+--TEST--
+Test mb_convert_encoding() function : basic functionality 
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_convert_encoding') or die("skip mb_convert_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_convert_encoding(string $str, string $to_encoding [, mixed $from_encoding])
+ * Description: Returns converted string in desired encoding 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test basic functionality of mb_convert_encoding()
+ */
+
+echo "*** Testing mb_convert_encoding() : basic functionality ***\n";
+
+//All strings are the same when displayed in their respective encodings
+$sjis_string = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
+$jis_string = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==');
+$euc_jp_string = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==');
+$utf8_string = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+echo "\n-- Convert to JIS --\n";
+echo "JIS encoded string in base64:\n";
+var_dump(base64_encode($jis_string));
+echo "Converted Strings:\n";
+var_dump(base64_encode(mb_convert_encoding($sjis_string, 'JIS', 'SJIS')));
+var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'JIS', 'EUC-JP')));
+var_dump(base64_encode(mb_convert_encoding($utf8_string, 'JIS', 'UTF-8')));
+
+echo "\n-- Convert to EUC-JP --\n";
+echo "EUC-JP encoded string in base64:\n";
+var_dump(base64_encode($euc_jp_string));
+echo "Converted Strings:\n";
+var_dump(base64_encode(mb_convert_encoding($sjis_string, 'EUC-JP', 'SJIS')));
+var_dump(base64_encode(mb_convert_encoding($jis_string, 'EUC-JP', 'JIS')));
+var_dump(base64_encode(mb_convert_encoding($utf8_string, 'EUC-JP', 'UTF-8')));
+
+echo "\n-- Convert to SJIS --\n";
+echo "SJIS encoded string in base64:\n";
+var_dump(base64_encode($sjis_string));
+echo "Converted Strings:\n";
+var_dump(base64_encode(mb_convert_encoding($jis_string, 'SJIS', 'JIS')));
+var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'SJIS', 'EUC-JP')));
+var_dump(base64_encode(mb_convert_encoding($utf8_string, 'SJIS', 'UTF-8')));
+
+echo "\n-- Convert to UTF-8 --\n";
+echo "UTF-8 encoded string in base64:\n";
+var_dump(base64_encode($utf8_string));
+echo "Converted Strings:\n";
+var_dump(base64_encode(mb_convert_encoding($sjis_string, 'UTF-8', 'SJIS')));
+var_dump(base64_encode(mb_convert_encoding($jis_string, 'UTF-8', 'JIS')));
+var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'UTF-8', 'EUC-JP')));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_convert_encoding() : basic functionality ***
+
+-- Convert to JIS --
+JIS encoded string in base64:
+string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
+Converted Strings:
+string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
+string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
+string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
+
+-- Convert to EUC-JP --
+EUC-JP encoded string in base64:
+string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
+Converted Strings:
+string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
+string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
+string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
+
+-- Convert to SJIS --
+SJIS encoded string in base64:
+string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
+Converted Strings:
+string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
+string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
+string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
+
+-- Convert to UTF-8 --
+UTF-8 encoded string in base64:
+string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+Converted Strings:
+string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_encode_mimeheader_basic.phpt b/ext/mbstring/tests/mb_encode_mimeheader_basic.phpt
new file mode 100644 (file)
index 0000000..fb0c281
--- /dev/null
@@ -0,0 +1,65 @@
+--TEST--
+Test mb_encode_mimeheader() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
+?>
+
+--FILE--
+<?php
+/* Prototype  : string mb_encode_mimeheader
+ * (string $str [, string $charset [, string $transfer-encoding [, string $linefeed [, int $indent]]]])
+ * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test basic functionality of mb_encode_mimeheader with different strings.
+ * For the below strings:
+ * 'English' is ASCII only, 'Japanese' has no ASCII characters and 'Greek' is mixed.
+ */
+
+echo "*** Testing mb_encode_mimeheader() : basic ***\n";
+mb_internal_encoding('utf-8');
+
+$inputs = array('English' => 'This is an English string. 0123456789',
+                'Japanese' => base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC'),
+                'Greek' => base64_decode('zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg=='));
+
+foreach ($inputs as $lang => $input) {
+       echo "\nLanguage: $lang\n";
+       echo "-- Base 64: --\n";
+       var_dump(mb_encode_mimeheader($input, 'UTF-8', 'B'));
+       echo "-- Quoted-Printable --\n";
+       var_dump(mb_encode_mimeheader($input, 'UTF-8', 'Q'));
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_encode_mimeheader() : basic ***
+
+Language: English
+-- Base 64: --
+string(37) "This is an English string. 0123456789"
+-- Quoted-Printable --
+string(37) "This is an English string. 0123456789"
+
+Language: Japanese
+-- Base 64: --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+-- Quoted-Printable --
+string(117) "=?UTF-8?Q?=E6=97=A5=E6=9C=AC=E8=AA=9E=E3=83=86=E3=82=AD=E3=82=B9=E3=83=88?=
+ =?UTF-8?Q?=E3=81=A7=E3=81=99=E3=80=82?="
+
+Language: Greek
+-- Base 64: --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+-- Quoted-Printable --
+string(249) "=?UTF-8?Q?=CE=91=CF=85=CF=84=CF=8C=20=CE=B5=CE=AF=CE=BD=CE=B1=CE=B9=20?=
+ =?UTF-8?Q?=CE=B5=CE=BB=CE=BB=CE=B7=CE=BD=CE=B9=CE=BA=CF=8C=20=CE=BA=CE=B5?=
+ =?UTF-8?Q?=CE=AF=CE=BC=CE=B5=CE=BD=CE=BF=2E=20=30=31=32=33=34=35=36=37=38?=
+ =?UTF-8?Q?=39=2E?="
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_encode_mimeheader_variation1.phpt b/ext/mbstring/tests/mb_encode_mimeheader_variation1.phpt
new file mode 100644 (file)
index 0000000..f440e1d
--- /dev/null
@@ -0,0 +1,186 @@
+--TEST--
+Test mb_encode_mimeheader() function : usage variations - Pass different data types to $str arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_encode_mimeheader
+ * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
+ * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types to $str argument to see how mb_encode_mimeheader() behaves
+ */
+
+echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
+
+mb_internal_encoding('utf-8');
+
+// Initialise function arguments not being substituted
+$charset = 'utf-8';
+$transfer_encoding = 'B';
+$linefeed = "\r\n";
+$indent = 2;
+
+//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 $str 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_encode_mimeheader()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_encode_mimeheader($input, $charset, $transfer_encoding, $linefeed, $indent));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_encode_mimeheader() : usage variations ***
+
+-- Iteration 1 --
+string(1) "0"
+
+-- Iteration 2 --
+string(1) "1"
+
+-- Iteration 3 --
+string(5) "12345"
+
+-- Iteration 4 --
+string(5) "-2345"
+
+-- Iteration 5 --
+string(4) "10.5"
+
+-- Iteration 6 --
+string(5) "-10.5"
+
+-- Iteration 7 --
+string(12) "123456789000"
+
+-- Iteration 8 --
+string(13) "1.23456789E-9"
+
+-- Iteration 9 --
+string(3) "0.5"
+
+-- Iteration 10 --
+string(0) ""
+
+-- Iteration 11 --
+string(0) ""
+
+-- Iteration 12 --
+string(1) "1"
+
+-- Iteration 13 --
+string(0) ""
+
+-- Iteration 14 --
+string(1) "1"
+
+-- Iteration 15 --
+string(0) ""
+
+-- Iteration 16 --
+string(0) ""
+
+-- Iteration 17 --
+string(0) ""
+
+-- Iteration 18 --
+string(6) "string"
+
+-- Iteration 19 --
+string(6) "string"
+
+-- Iteration 20 --
+string(11) "hello world"
+
+-- Iteration 21 --
+string(14) "Class A object"
+
+-- Iteration 22 --
+string(0) ""
+
+-- Iteration 23 --
+string(0) ""
+
+-- Iteration 24 --
+
+Warning: mb_encode_mimeheader() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_encode_mimeheader_variation2.phpt b/ext/mbstring/tests/mb_encode_mimeheader_variation2.phpt
new file mode 100644 (file)
index 0000000..855c3b3
--- /dev/null
@@ -0,0 +1,224 @@
+--TEST--
+Test mb_encode_mimeheader() function : usage variations - Pass different data types to $charset arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_encode_mimeheader
+ * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
+ * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types to $charset argument to see how mb_encode_mimeheader() behaves
+ */
+
+echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
+
+mb_internal_encoding('utf-8');
+
+// Initialise function arguments not being substituted
+$str = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC');
+$transfer_encoding = 'B';
+$linefeed = "\r\n";
+$indent = 2;
+
+//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 $charset 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_encode_mimeheader()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_encode_mimeheader($str, $input, $transfer_encoding, $linefeed, $indent));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_encode_mimeheader() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 19 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 20 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 21 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 22 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_encode_mimeheader() expects parameter 2 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_encode_mimeheader_variation3.phpt b/ext/mbstring/tests/mb_encode_mimeheader_variation3.phpt
new file mode 100644 (file)
index 0000000..8c6bf08
--- /dev/null
@@ -0,0 +1,186 @@
+--TEST--
+Test mb_encode_mimeheader() function : usage variations - Pass different data types to $transfer_encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_encode_mimeheader
+ * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
+ * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types to $transfer_encoding argument to see how mb_encode_mimeheader() behaves
+ */
+
+echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
+
+mb_internal_encoding('utf-8');
+
+// Initialise function arguments not being substituted
+$str = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC');
+$charset = 'utf-8';
+$linefeed = "\r\n";
+$indent = 2;
+
+//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 $transfer_encoding 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_encode_mimeheader()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_encode_mimeheader($str, $charset, $input, $linefeed, $indent));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_encode_mimeheader() : usage variations ***
+
+-- Iteration 1 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 2 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 3 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 4 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 5 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 6 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 7 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 8 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 9 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 10 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 11 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 12 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 13 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 14 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 15 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 16 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 17 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 18 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 19 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 20 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 21 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 22 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 23 --
+string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
+
+-- Iteration 24 --
+
+Warning: mb_encode_mimeheader() expects parameter 3 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_encode_mimeheader_variation4.phpt b/ext/mbstring/tests/mb_encode_mimeheader_variation4.phpt
new file mode 100644 (file)
index 0000000..64e236d
--- /dev/null
@@ -0,0 +1,187 @@
+--TEST--
+Test mb_encode_mimeheader() function : usage variations - Pass different data types to $linefeed arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_encode_mimeheader
+ * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
+ * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types to $linefeed argument to see how mb_encode_mimeheader() behaves
+ */
+
+echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
+mb_internal_encoding('utf-8');
+
+
+// Initialise function arguments not being substituted
+//longer $str to go over 1 line
+$str = base64_decode('zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg==');
+$charset = 'utf-8';
+$transfer_encoding = 'B';
+$indent = 2;
+
+//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 $linefeed 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_encode_mimeheader()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_encode_mimeheader($str, $charset, $transfer_encoding, $input, $indent));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_encode_mimeheader() : usage variations ***
+
+-- Iteration 1 --
+string(114) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=0 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 2 --
+string(114) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=1 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 3 --
+string(118) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=12345 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 4 --
+string(118) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=-2345 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 5 --
+string(117) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=10.5 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 6 --
+string(118) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=-10.5 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 7 --
+string(121) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=12345678 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 8 --
+string(121) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=1.234567 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 9 --
+string(116) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=0.5 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 10 --
+string(113) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 11 --
+string(113) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 12 --
+string(114) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=1 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 13 --
+string(113) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 14 --
+string(114) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=1 =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 15 --
+string(113) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 16 --
+string(113) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 17 --
+string(113) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 18 --
+string(119) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=string =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 19 --
+string(119) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=string =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 20 --
+string(121) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=hello wo =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 21 --
+string(121) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=Class A  =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 22 --
+string(113) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 23 --
+string(113) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?= =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 24 --
+
+Warning: mb_encode_mimeheader() expects parameter 4 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_encode_mimeheader_variation5.phpt b/ext/mbstring/tests/mb_encode_mimeheader_variation5.phpt
new file mode 100644 (file)
index 0000000..593b3c1
--- /dev/null
@@ -0,0 +1,215 @@
+--TEST--
+Test mb_encode_mimeheader() function : usage variations - Pass different data types to $indent arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_encode_mimeheader
+ * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
+ * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types to $indent argument to see how mb_encode_mimeheader() behaves
+ */
+
+echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
+
+mb_internal_encoding('utf-8');
+
+// Initialise function arguments not being substituted
+$str = base64_decode('zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg==');
+$charset = 'utf-8';
+$transfer_encoding = 'B';
+$linefeed = "\r\n";
+
+//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 $indent 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_encode_mimeheader()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_encode_mimeheader($str, $charset, $transfer_encoding, $linefeed, $input));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_encode_mimeheader() : usage variations ***
+
+-- Iteration 1 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 2 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 3 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 4 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 5 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66?=
+ =?UTF-8?B?zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 6 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 7 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 8 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 9 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 10 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 11 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 12 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 13 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 14 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 15 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 16 --
+
+Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 18 --
+
+Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 19 --
+
+Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 20 --
+
+Warning: mb_encode_mimeheader() expects parameter 5 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 21 --
+
+Warning: mb_encode_mimeheader() expects parameter 5 to be long, object given in %s on line %d
+NULL
+
+-- Iteration 22 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 23 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 24 --
+
+Warning: mb_encode_mimeheader() expects parameter 5 to be long, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_encode_mimeheader_variation6.phpt b/ext/mbstring/tests/mb_encode_mimeheader_variation6.phpt
new file mode 100644 (file)
index 0000000..20ba5c1
--- /dev/null
@@ -0,0 +1,53 @@
+--TEST--
+Test mb_encode_mimeheader() function : usage variations - Pass different strings to $linefeed arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_encode_mimeheader
+ * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
+ * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?= 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different strings to $linefeed argument
+ */
+
+echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
+
+mb_internal_encoding('utf-8');
+
+$linefeeds = array("\r\n",
+                   "\n",
+                   "---");
+$str = base64_decode('zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg==');
+
+$iterator = 1;
+foreach ($linefeeds as $linefeed) {
+       echo "\n-- Iteration $iterator --\n";
+       var_dump(mb_encode_mimeheader($str, 'utf-8', 'B', $linefeed));
+       $iterator++;
+}
+
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_encode_mimeheader() : usage variations ***
+
+-- Iteration 1 --
+string(115) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 2 --
+string(114) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=
+ =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+
+-- Iteration 3 --
+string(116) "=?UTF-8?B?zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868?=--- =?UTF-8?B?zrXOvc6/LiAwMTIzNDU2Nzg5Lg==?="
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_ereg_basic.phpt b/ext/mbstring/tests/mb_ereg_basic.phpt
new file mode 100644 (file)
index 0000000..0bdaf74
--- /dev/null
@@ -0,0 +1,117 @@
+--TEST--
+Test mb_ereg() function : basic functionality 
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Test basic functionality of mb_ereg
+ */
+
+echo "*** Testing mb_ereg() : basic functionality ***\n";
+
+if(mb_regex_encoding('utf-8') == true) {
+       echo "Regex encoding set to utf-8\n";
+} else {
+       echo "Could not set regex encoding to utf-8\n";
+}
+$string_ascii = 'This is an English string. 0123456789.';
+$regex_ascii1 = '(.*is)+.*\.[[:blank:]][0-9]{9}';
+$regex_ascii2 = '.*is+';
+
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+$regex_mb1 = base64_decode('KOaXpeacrOiqnikuKj8oWzEtOV0rKQ==');
+$regex_mb2 = base64_decode('5LiW55WM');
+
+echo "\n**-- ASCII String --**\n";
+echo "-- Without \$regs argument--\n";
+var_dump(mb_ereg($regex_ascii1, $string_ascii));
+var_dump(mb_ereg($regex_ascii2, $string_ascii));
+echo "--With \$regs argument --\n";
+var_dump(mb_ereg($regex_ascii1, $string_ascii, $regs_ascii1));
+var_dump($regs_ascii1);
+var_dump(mb_ereg($regex_ascii2, $string_ascii, $regs_ascii2));
+var_dump($regs_ascii2);
+
+echo "\n**-- Multibyte String --**\n";
+echo "-- Without \$regs argument --\n";
+var_dump(mb_ereg($regex_mb1, $string_mb));
+var_dump(mb_ereg($regex_mb2, $string_mb));
+echo "-- With \$regs argument --\n";
+var_dump(mb_ereg($regex_mb1, $string_mb, $regs_mb1));
+base64_encode_var_dump($regs_mb1);
+var_dump(mb_ereg($regex_mb2, $string_mb, $regs_mb2));
+var_dump($regs_mb2);
+
+echo "Done";
+
+/**
+ * replicate a var dump of an array but outputted string values are base64 encoded
+ *
+ * @param array $regs
+ */
+function base64_encode_var_dump($regs) {
+       if ($regs) {
+               echo "array(" . count($regs) . ") {\n";
+               foreach ($regs as $key => $value) {
+                       echo "  [$key]=>\n  ";
+                       if (is_string($value)) {
+                               var_dump(base64_encode($value));
+                       } else {
+                               var_dump($value);
+                       }
+               }
+               echo "}\n";
+       } else {
+               echo "NULL\n";
+       }
+}
+?>
+
+--EXPECTF--
+*** Testing mb_ereg() : basic functionality ***
+Regex encoding set to utf-8
+
+**-- ASCII String --**
+-- Without $regs argument--
+int(1)
+int(1)
+--With $regs argument --
+int(36)
+array(2) {
+  [0]=>
+  string(36) "This is an English string. 012345678"
+  [1]=>
+  string(17) "This is an Englis"
+}
+int(17)
+array(1) {
+  [0]=>
+  string(17) "This is an Englis"
+}
+
+**-- Multibyte String --**
+-- Without $regs argument --
+int(1)
+bool(false)
+-- With $regs argument --
+int(35)
+array(3) {
+  [0]=>
+  string(48) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzQ="
+  [1]=>
+  string(12) "5pel5pys6Kqe"
+  [2]=>
+  string(8) "MTIzNA=="
+}
+bool(false)
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_ereg_error.phpt b/ext/mbstring/tests/mb_ereg_error.phpt
new file mode 100644 (file)
index 0000000..2121625
--- /dev/null
@@ -0,0 +1,49 @@
+--TEST--
+Test mb_ereg() function : error conditions - pass incorrect number of arguments
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Test behaviour of mb_ereg() when passed an incorrcect number of arguments
+ */
+
+echo "*** Testing mb_ereg() : error conditions ***\n";
+
+
+//Test mb_ereg with one more than the expected number of arguments
+echo "\n-- Testing mb_ereg() function with more than expected no. of arguments --\n";
+$pattern = 'string_val';
+$string = 'string_val';
+$registers = array(1, 2);
+$extra_arg = 10;
+var_dump( mb_ereg($pattern, $string, $registers, $extra_arg) );
+
+// Testing mb_ereg with one less than the expected number of arguments
+echo "\n-- Testing mb_ereg() function with less than expected no. of arguments --\n";
+$pattern = 'string_val';
+var_dump( mb_ereg($pattern) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_ereg() : error conditions ***
+
+-- Testing mb_ereg() function with more than expected no. of arguments --
+
+Warning: mb_ereg() expects at most 3 parameters, 4 given in %s on line %d
+bool(false)
+
+-- Testing mb_ereg() function with less than expected no. of arguments --
+
+Warning: mb_ereg() expects at least 2 parameters, 1 given in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_ereg_variation1.phpt b/ext/mbstring/tests/mb_ereg_variation1.phpt
new file mode 100644 (file)
index 0000000..a8aa5d8
--- /dev/null
@@ -0,0 +1,165 @@
+--TEST--
+Test mb_ereg() function : usage variations - pass different data types to $pattern argument
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string 
+ * Source code: ext/mbstring/php_mbregex.c 
+ */
+
+/*
+ * Pass different data types to $pattern argument
+ */
+
+echo "*** Testing mb_ereg() : usage variations ***\n";
+
+// Initialise function arguments not being substituted (if any)
+$string = 'string value';
+
+//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 $pattern argument
+$inputs = array(
+
+// int data
+/*1*/  0,
+       1,
+       12345,
+       -2345,
+
+// float data
+/*5*/  10.5,
+       -10.5,
+       12.3456789000e10,
+       12.3456789000E-10,
+       .5,
+
+// boolean data
+/*10*/ true,
+       TRUE,
+
+// string data
+/*12*/ "string",
+       'string',
+       $heredoc,
+// object data
+/*15*/ new classA(),
+
+// resource variable
+/*16*/ $fp
+);
+
+// loop through each element of $inputs to check the behavior of mb_ereg()
+$iterator = 1;
+foreach($inputs as $input) {
+       if (@is_array($regs)){
+               $regs = null;
+       }
+       echo "\n-- Iteration $iterator --\n";
+       var_dump( mb_ereg($input, $string, $regs) );
+       var_dump($regs);
+       $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_ereg() : usage variations ***
+
+-- Iteration 1 --
+bool(false)
+NULL
+
+-- Iteration 2 --
+bool(false)
+NULL
+
+-- Iteration 3 --
+bool(false)
+NULL
+
+-- Iteration 4 --
+bool(false)
+NULL
+
+-- Iteration 5 --
+bool(false)
+NULL
+
+-- Iteration 6 --
+bool(false)
+NULL
+
+-- Iteration 7 --
+bool(false)
+NULL
+
+-- Iteration 8 --
+bool(false)
+NULL
+
+-- Iteration 9 --
+bool(false)
+NULL
+
+-- Iteration 10 --
+bool(false)
+NULL
+
+-- Iteration 11 --
+bool(false)
+NULL
+
+-- Iteration 12 --
+int(6)
+array(1) {
+  [0]=>
+  string(6) "string"
+}
+
+-- Iteration 13 --
+int(6)
+array(1) {
+  [0]=>
+  string(6) "string"
+}
+
+-- Iteration 14 --
+bool(false)
+NULL
+
+-- Iteration 15 --
+bool(false)
+NULL
+
+-- Iteration 16 --
+bool(false)
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_ereg_variation2.phpt b/ext/mbstring/tests/mb_ereg_variation2.phpt
new file mode 100644 (file)
index 0000000..d85c8bd
--- /dev/null
@@ -0,0 +1,216 @@
+--TEST--
+Test mb_ereg() function : usage variations - pass different data types to $string arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Test behaviour of mb_ereg() when passed different data types as $string arg
+ */
+
+echo "*** Testing mb_ereg() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$pattern = 'str';
+
+//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 $string 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_ereg()
+$iterator = 1;
+foreach($inputs as $input) {
+       if (@is_array($regs)){
+               $regs = null;
+       }
+       echo "\n-- Iteration $iterator --\n";
+       var_dump( mb_ereg($pattern, $input, $regs) );
+       var_dump($regs);
+       $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+
+?>
+
+--EXPECTF--
+*** Testing mb_ereg() : usage variations ***
+
+-- Iteration 1 --
+bool(false)
+NULL
+
+-- Iteration 2 --
+bool(false)
+NULL
+
+-- Iteration 3 --
+bool(false)
+NULL
+
+-- Iteration 4 --
+bool(false)
+NULL
+
+-- Iteration 5 --
+bool(false)
+NULL
+
+-- Iteration 6 --
+bool(false)
+NULL
+
+-- Iteration 7 --
+bool(false)
+NULL
+
+-- Iteration 8 --
+bool(false)
+NULL
+
+-- Iteration 9 --
+bool(false)
+NULL
+
+-- Iteration 10 --
+bool(false)
+NULL
+
+-- Iteration 11 --
+bool(false)
+NULL
+
+-- Iteration 12 --
+bool(false)
+NULL
+
+-- Iteration 13 --
+bool(false)
+NULL
+
+-- Iteration 14 --
+bool(false)
+NULL
+
+-- Iteration 15 --
+bool(false)
+NULL
+
+-- Iteration 16 --
+bool(false)
+NULL
+
+-- Iteration 17 --
+bool(false)
+NULL
+
+-- Iteration 18 --
+int(3)
+array(1) {
+  [0]=>
+  string(3) "str"
+}
+
+-- Iteration 19 --
+int(3)
+array(1) {
+  [0]=>
+  string(3) "str"
+}
+
+-- Iteration 20 --
+bool(false)
+NULL
+
+-- Iteration 21 --
+bool(false)
+NULL
+
+-- Iteration 22 --
+bool(false)
+NULL
+
+-- Iteration 23 --
+bool(false)
+NULL
+
+-- Iteration 24 --
+
+Warning: mb_ereg() expects parameter 2 to be string, resource given in %s on line %d
+bool(false)
+NULL
+Done
diff --git a/ext/mbstring/tests/mb_ereg_variation3.phpt b/ext/mbstring/tests/mb_ereg_variation3.phpt
new file mode 100644 (file)
index 0000000..0236e44
--- /dev/null
@@ -0,0 +1,163 @@
+--TEST--
+Test mb_ereg() function : usage variations - pass different character classes to see they match correctly
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * test that mb_ereg can match correctly when passed different character classes.
+ */
+
+echo "*** Testing mb_ereg() : variation ***\n";
+
+
+mb_regex_encoding('utf-8'); // have to set otherwise won't match $mb properly
+$mb = base64_decode('5pel5pys6Kqe');
+$character_classes = array ('aB1'    => '[[:alnum:]]+', /*1*/
+                            'aBcD'   => '[[:alpha:]]+',
+                            'ab/='   => '[[:ascii:]]+',
+                            " \t"    => '[[:blank:]]+',
+                            '234'    => '[[:digit:]]+', /*5*/
+                            "$mb"    => '[[:graph:]]+',
+                            'fjds'   => '[[:lower:]]+',
+                            "$mb\t"  => '[[:print:]]+',
+                            '.!"*@'  => '[[:punct:]]+',
+                            "\t"     => '[[:space:]]+', /*10*/
+                            'IDSJV'  => '[[:upper:]]+',
+                            '3b5D'   => '[[:xdigit:]]+'); /*12*/
+
+$iterator = 1;
+foreach($character_classes as $string => $pattern) {
+       if (is_array(@$regs)) {
+               $regs = null;
+       }
+       // make sure any multibyte output is in base 64
+       echo "\n-- Iteration $iterator --\n";
+       var_dump(mb_ereg($pattern, $string, $regs));
+       if (strpos($string, $mb) === FALSE) {
+               var_dump($regs);
+       } else {
+               base64_encode_var_dump($regs);
+       }
+       $iterator++;
+}
+/**
+ * replicate a var dump of an array but outputted string values are base64 encoded
+ *
+ * @param array $regs
+ */
+function base64_encode_var_dump($regs) {
+       if ($regs) {
+               echo "array(" . count($regs) . ") {\n";
+               foreach ($regs as $key => $value) {
+                       echo "  [$key]=>\n  ";
+                       if (is_string($value)) {
+                               var_dump(base64_encode($value));
+                       } else {
+                               var_dump($value);
+                       }
+               }
+               echo "}\n";
+       } else {
+               echo "NULL\n";
+       }
+}
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_ereg() : variation ***
+
+-- Iteration 1 --
+int(3)
+array(1) {
+  [0]=>
+  string(3) "aB1"
+}
+
+-- Iteration 2 --
+int(4)
+array(1) {
+  [0]=>
+  string(4) "aBcD"
+}
+
+-- Iteration 3 --
+int(4)
+array(1) {
+  [0]=>
+  string(4) "ab/="
+}
+
+-- Iteration 4 --
+int(2)
+array(1) {
+  [0]=>
+  string(2) "  "
+}
+
+-- Iteration 5 --
+int(3)
+array(1) {
+  [0]=>
+  string(3) "234"
+}
+
+-- Iteration 6 --
+int(9)
+array(1) {
+  [0]=>
+  string(12) "5pel5pys6Kqe"
+}
+
+-- Iteration 7 --
+int(4)
+array(1) {
+  [0]=>
+  string(4) "fjds"
+}
+
+-- Iteration 8 --
+int(10)
+array(1) {
+  [0]=>
+  string(16) "5pel5pys6KqeCQ=="
+}
+
+-- Iteration 9 --
+int(5)
+array(1) {
+  [0]=>
+  string(5) ".!"*@"
+}
+
+-- Iteration 10 --
+int(1)
+array(1) {
+  [0]=>
+  string(1) "  "
+}
+
+-- Iteration 11 --
+int(5)
+array(1) {
+  [0]=>
+  string(5) "IDSJV"
+}
+
+-- Iteration 12 --
+int(4)
+array(1) {
+  [0]=>
+  string(4) "3b5D"
+}
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_ereg_variation4.phpt b/ext/mbstring/tests/mb_ereg_variation4.phpt
new file mode 100644 (file)
index 0000000..7f7d6df
--- /dev/null
@@ -0,0 +1,149 @@
+--TEST--
+Test mb_ereg() function : usage variations - pass different character classes as pattern for multibyte string
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Test how character classes match a multibyte string
+ */
+
+echo "*** Testing mb_ereg() : usage variations ***\n";
+
+mb_regex_encoding('utf-8');
+
+//contains japanese characters, ASCII digits and different, UTF-8 encoded digits
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+$character_classes = array ('[[:alnum:]]+', /*1*/
+                            '[[:alpha:]]+',
+                            '[[:ascii:]]+',
+                            '[[:blank:]]+',
+                            '[[:cntrl:]]+',/*5*/
+                            '[[:digit:]]+',
+                            '[[:graph:]]+',
+                            '[[:lower:]]+',
+                            '[[:print:]]+',
+                            '[[:punct:]]+', /*10*/
+                            '[[:space:]]+',
+                            '[[:upper:]]+',
+                            '[[:xdigit:]]+'); /*13*/
+
+$iterator = 1;
+foreach ($character_classes as $pattern) {
+       if (is_array(@$regs)) {
+               $regs = null;
+       }
+       echo "\n-- Iteration $iterator --\n";
+       var_dump(mb_ereg($pattern, $string_mb, $regs));
+       if ($regs) {
+               base64_encode_var_dump($regs);
+       }
+       $iterator++;
+}
+/**
+ * replicate a var dump of an array but outputted string values are base64 encoded
+ *
+ * @param array $regs
+ */
+function base64_encode_var_dump($regs) {
+       if ($regs) {
+               echo "array(" . count($regs) . ") {\n";
+               foreach ($regs as $key => $value) {
+                       echo "  [$key]=>\n  ";
+                       if (is_string($value)) {
+                               var_dump(base64_encode($value));
+                       } else {
+                               var_dump($value);
+                       }
+               }
+               echo "}\n";
+       } else {
+               echo "NULL\n";
+       }
+}
+echo "Done";
+
+?>
+--EXPECTF--
+*** Testing mb_ereg() : usage variations ***
+
+-- Iteration 1 --
+int(47)
+array(1) {
+  [0]=>
+  string(64) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJk="
+}
+
+-- Iteration 2 --
+int(27)
+array(1) {
+  [0]=>
+  string(36) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ"
+}
+
+-- Iteration 3 --
+int(5)
+array(1) {
+  [0]=>
+  string(8) "MDEyMzQ="
+}
+
+-- Iteration 4 --
+bool(false)
+
+-- Iteration 5 --
+bool(false)
+
+-- Iteration 6 --
+int(20)
+array(1) {
+  [0]=>
+  string(28) "MDEyMzTvvJXvvJbvvJfvvJjvvJk="
+}
+
+-- Iteration 7 --
+int(50)
+array(1) {
+  [0]=>
+  string(68) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+}
+
+-- Iteration 8 --
+bool(false)
+
+-- Iteration 9 --
+int(50)
+array(1) {
+  [0]=>
+  string(68) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+}
+
+-- Iteration 10 --
+int(3)
+array(1) {
+  [0]=>
+  string(4) "44CC"
+}
+
+-- Iteration 11 --
+bool(false)
+
+-- Iteration 12 --
+bool(false)
+
+-- Iteration 13 --
+int(5)
+array(1) {
+  [0]=>
+  string(8) "MDEyMzQ="
+}
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_ereg_variation5.phpt b/ext/mbstring/tests/mb_ereg_variation5.phpt
new file mode 100644 (file)
index 0000000..95bc599
--- /dev/null
@@ -0,0 +1,82 @@
+--TEST--
+Test mb_ereg() function : usage variations - Test anchors in regex
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Test mb_ereg with anchors (start and end of string) in $pattern
+ */
+
+echo "*** Testing mb_ereg() : usage variations ***\n";
+
+mb_regex_encoding('utf-8');
+
+$string_ascii = 'This is an English string. 0123456789.';
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+$regex = '^.*?[[:blank:]]?[[:punct:][:digit:]]+\.?$';
+
+echo "\nASCII String without \$regs arg:\t\t";
+var_dump(mb_ereg($regex, $string_ascii));
+echo "ASCII String with \$regs arg:\n";
+var_dump(mb_ereg($regex, $string_ascii, $regs_ascii));
+var_dump($regs_ascii);
+
+echo "\nMultibyte String without \$regs arg:\t";
+var_dump(mb_ereg($regex, $string_mb));
+echo "Multubyte String with \$regs arg:\n";
+var_dump(mb_ereg($regex, $string_mb, $regs_mb));
+base64_encode_var_dump($regs_mb);
+
+echo "Done";
+
+/**
+ * replicate a var dump of an array but outputted string values are base64 encoded
+ *
+ * @param array $regs
+ */
+function base64_encode_var_dump($regs) {
+       if ($regs) {
+               echo "array(" . count($regs) . ") {\n";
+               foreach ($regs as $key => $value) {
+                       echo "  [$key]=>\n  ";
+                       if (is_string($value)) {
+                               var_dump(base64_encode($value));
+                       } else {
+                               var_dump($value);
+                       }
+               }
+               echo "}\n";
+       } else {
+               echo "NULL\n";
+       }
+}
+?>
+--EXPECTF--
+*** Testing mb_ereg() : usage variations ***
+
+ASCII String without $regs arg:                int(1)
+ASCII String with $regs arg:
+int(38)
+array(1) {
+  [0]=>
+  string(38) "This is an English string. 0123456789."
+}
+
+Multibyte String without $regs arg:    int(1)
+Multubyte String with $regs arg:
+int(53)
+array(1) {
+  [0]=>
+  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+}
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_ereg_variation6.phpt b/ext/mbstring/tests/mb_ereg_variation6.phpt
new file mode 100644 (file)
index 0000000..33d2ee5
--- /dev/null
@@ -0,0 +1,185 @@
+--TEST--
+Test mb_ereg() function : usage variations - match special characters
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Test how mb_ereg() matches special characters for $pattern
+ */
+
+echo "*** Testing mb_ereg() : usage variations ***\n";
+
+if(mb_regex_encoding('utf-8') == true) {
+       echo "Regex encoding set to utf-8\n";
+} else {
+       echo "Could not set regex encoding to utf-8\n";
+}
+
+$regex_char = array ('\w+', '\W+', '\s+', '\S+', '\d+', '\D+', '\b', '\B');
+
+$string_ascii = 'This is an English string. 0123456789.';
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+foreach ($regex_char as $char) {
+       echo "\n--** Pattern is: $char **--\n";
+       if (@$regs_ascii || @$regs_mb) {
+               $regs_ascii = null;
+               $regs_mb = null;
+       }
+       echo "-- ASCII String: --\n";
+       var_dump(mb_ereg($char, $string_ascii, $regs_ascii));
+       var_dump($regs_ascii);
+
+       echo "-- Multibyte String: --\n";
+       var_dump(mb_ereg($char, $string_mb, $regs_mb));
+       base64_encode_var_dump($regs_mb);
+
+}
+
+/**
+ * replicate a var dump of an array but outputted string values are base64 encoded
+ *
+ * @param array $regs
+ */
+function base64_encode_var_dump($regs) {
+       if ($regs) {
+               echo "array(" . count($regs) . ") {\n";
+               foreach ($regs as $key => $value) {
+                       echo "  [$key]=>\n  ";
+                       if (is_string($value)) {
+                               var_dump(base64_encode($value));
+                       } else {
+                               var_dump($value);
+                       }
+               }
+               echo "}\n";
+       } else {
+               echo "NULL\n";
+       }
+}
+
+echo "Done";
+
+?>
+--EXPECTF--
+*** Testing mb_ereg() : usage variations ***
+Regex encoding set to utf-8
+
+--** Pattern is: \w+ **--
+-- ASCII String: --
+int(4)
+array(1) {
+  [0]=>
+  string(4) "This"
+}
+-- Multibyte String: --
+int(27)
+array(1) {
+  [0]=>
+  string(36) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ"
+}
+
+--** Pattern is: \W+ **--
+-- ASCII String: --
+int(1)
+array(1) {
+  [0]=>
+  string(1) " "
+}
+-- Multibyte String: --
+int(3)
+array(1) {
+  [0]=>
+  string(4) "44CC"
+}
+
+--** Pattern is: \s+ **--
+-- ASCII String: --
+int(1)
+array(1) {
+  [0]=>
+  string(1) " "
+}
+-- Multibyte String: --
+bool(false)
+NULL
+
+--** Pattern is: \S+ **--
+-- ASCII String: --
+int(4)
+array(1) {
+  [0]=>
+  string(4) "This"
+}
+-- Multibyte String: --
+int(53)
+array(1) {
+  [0]=>
+  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+}
+
+--** Pattern is: \d+ **--
+-- ASCII String: --
+int(10)
+array(1) {
+  [0]=>
+  string(10) "0123456789"
+}
+-- Multibyte String: --
+int(20)
+array(1) {
+  [0]=>
+  string(28) "MDEyMzTvvJXvvJbvvJfvvJjvvJk="
+}
+
+--** Pattern is: \D+ **--
+-- ASCII String: --
+int(27)
+array(1) {
+  [0]=>
+  string(27) "This is an English string. "
+}
+-- Multibyte String: --
+int(30)
+array(1) {
+  [0]=>
+  string(40) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC"
+}
+
+--** Pattern is: \b **--
+-- ASCII String: --
+int(1)
+array(1) {
+  [0]=>
+  bool(false)
+}
+-- Multibyte String: --
+int(1)
+array(1) {
+  [0]=>
+  bool(false)
+}
+
+--** Pattern is: \B **--
+-- ASCII String: --
+int(1)
+array(1) {
+  [0]=>
+  bool(false)
+}
+-- Multibyte String: --
+int(1)
+array(1) {
+  [0]=>
+  bool(false)
+}
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_ereg_variation7.phpt b/ext/mbstring/tests/mb_ereg_variation7.phpt
new file mode 100644 (file)
index 0000000..81c9589
--- /dev/null
@@ -0,0 +1,94 @@
+--TEST--
+Test mb_ereg() function : usage variations - different regex features in $pattern
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
+ * Description: Regular expression match for multibyte string 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Testing the following regular expression features match correctly:
+ * 1. definite quantifiers
+ * 2. Alternation
+ * 3. subpatterns in parentheses
+ */
+
+echo "*** Testing mb_ereg() : usage variations ***\n";
+
+if(mb_regex_encoding('utf-8') == true) {
+       echo "Regex encoding set to utf-8\n";
+} else {
+       echo "Could not set regex encoding to utf-8\n";
+}
+
+$string_ascii = 'This is an English string. 0123456789.';
+$regex_ascii = '([A-Z]\w{1,4}is( [aeiou]|h)) ?.*\.\s[0-9]+(5([6-9][79]){2})[[:punct:]]$';
+var_dump(mb_ereg($regex_ascii, $string_ascii, $regs_ascii));
+var_dump($regs_ascii);
+
+$string_mb = base64_decode('zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg==');
+$regex_mb = base64_decode("W86RLc6pXShcdysgKSvOtVvOsS3PiVxzXSvOui4qKM+MfM6/KS4qXC5cc1swLTldKyg1KFs2LTldWzc5XSl7Mn0pW1s6cHVuY3Q6XV0k");
+var_dump(mb_ereg($regex_mb, $string_mb, $regs_mb));
+base64_encode_var_dump($regs_mb);
+
+/**
+ * replicate a var dump of an array but outputted string values are base64 encoded
+ *
+ * @param array $regs
+ */
+function base64_encode_var_dump($regs) {
+       if ($regs) {
+               echo "array(" . count($regs) . ") {\n";
+               foreach ($regs as $key => $value) {
+                       echo "  [$key]=>\n  ";
+                       if (is_string($value)) {
+                               var_dump(base64_encode($value));
+                       } else {
+                               var_dump($value);
+                       }
+               }
+               echo "}\n";
+       } else {
+               echo "NULL\n";
+       }
+}
+
+echo "Done";
+
+?>
+--EXPECTF--
+*** Testing mb_ereg() : usage variations ***
+Regex encoding set to utf-8
+int(38)
+array(5) {
+  [0]=>
+  string(38) "This is an English string. 0123456789."
+  [1]=>
+  string(6) "This i"
+  [2]=>
+  string(2) " i"
+  [3]=>
+  string(5) "56789"
+  [4]=>
+  string(2) "89"
+}
+int(64)
+array(5) {
+  [0]=>
+  string(88) "zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg=="
+  [1]=>
+  string(16) "zrXOr869zrHOuSA="
+  [2]=>
+  string(4) "zr8="
+  [3]=>
+  string(8) "NTY3ODk="
+  [4]=>
+  string(4) "ODk="
+}
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_internal_encoding_basic.phpt b/ext/mbstring/tests/mb_internal_encoding_basic.phpt
new file mode 100644 (file)
index 0000000..a289dcf
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Test mb_internal_encoding() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_internal_encoding') or die("skip mb_internal_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_internal_encoding([string $encoding])
+ * Description: Sets the current internal encoding or Returns 
+ * the current internal encoding as a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test basic functionality of mb_internal_encoding
+ */
+
+echo "*** Testing mb_internal_encoding() : basic functionality ***\n";
+
+var_dump(mb_internal_encoding());   //default internal encoding
+
+var_dump(mb_internal_encoding('UTF-8'));    //change internal encoding to UTF-8
+
+var_dump(mb_internal_encoding());    //check internal encoding is now set to UTF-8
+
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_internal_encoding() : basic functionality ***
+string(%d) "%s"
+bool(true)
+string(5) "UTF-8"
+Done
diff --git a/ext/mbstring/tests/mb_internal_encoding_error1.phpt b/ext/mbstring/tests/mb_internal_encoding_error1.phpt
new file mode 100644 (file)
index 0000000..61f133a
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Test mb_internal_encoding() function : error conditions - pass incorrect number of args
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_internal_encoding') or die("skip mb_internal_encoding() is not available in this build");
+?> 
+--FILE--
+<?php
+/* Prototype  : string mb_internal_encoding([string $encoding])
+ * Description: Sets the current internal encoding or 
+ * Returns the current internal encoding as a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test mb_internal_encoding with one more than the expected number of arguments
+ */
+
+echo "*** Testing mb_internal_encoding() : error conditions ***\n";
+
+echo "\n-- Testing mb_internal_encoding() function with more than expected no. of arguments --\n";
+$encoding = 'string_val';
+$extra_arg = 10;
+var_dump( mb_internal_encoding($encoding, $extra_arg) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_internal_encoding() : error conditions ***
+
+-- Testing mb_internal_encoding() function with more than expected no. of arguments --
+
+Warning: mb_internal_encoding() expects at most 1 parameter, 2 given in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_internal_encoding_error2.phpt b/ext/mbstring/tests/mb_internal_encoding_error2.phpt
new file mode 100644 (file)
index 0000000..d0a1653
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+Test mb_internal_encoding() function : error conditions - pass an unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_internal_encoding') or die("skip mb_internal_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_internal_encoding([string $encoding])
+ * Description: Sets the current internal encoding or 
+ * Returns the current internal encoding as a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass mb_internal_encoding an unknown encoding
+ */
+
+echo "*** Testing mb_internal_encoding() : error conditions ***\n";
+
+var_dump(mb_internal_encoding('unknown-encoding'));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_internal_encoding() : error conditions ***
+
+Warning: mb_internal_encoding(): Unknown encoding "unknown-encoding" in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_internal_encoding_variation1.phpt b/ext/mbstring/tests/mb_internal_encoding_variation1.phpt
new file mode 100644 (file)
index 0000000..3aa1784
--- /dev/null
@@ -0,0 +1,217 @@
+--TEST--
+Test mb_internal_encoding() function : usage variations - Pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_internal_encoding') or die("skip mb_internal_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_internal_encoding([string $encoding])
+ * Description: Sets the current internal encoding or Returns 
+ * the current internal encoding as a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types as $encoding to mb_internal_encoding() to test behaviour
+ * Where possible 'UTF-8' has been entered as a string value
+ */
+
+echo "*** Testing mb_internal_encoding() : usage variations ***\n";
+
+//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 $encoding 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_internal_encoding()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_internal_encoding($input) );
+  $iterator++;
+};
+
+fclose($fp);
+echo "Done";
+?>
+--EXPECTF--
+
+*** Testing mb_internal_encoding() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_internal_encoding(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_internal_encoding(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_internal_encoding(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_internal_encoding(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_internal_encoding(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_internal_encoding(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_internal_encoding(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_internal_encoding(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_internal_encoding(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: mb_internal_encoding(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: mb_internal_encoding(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+bool(true)
+
+-- Iteration 19 --
+bool(true)
+
+-- Iteration 20 --
+bool(true)
+
+-- Iteration 21 --
+bool(true)
+
+-- Iteration 22 --
+
+Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_internal_encoding() expects parameter 1 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_internal_encoding_variation2.phpt b/ext/mbstring/tests/mb_internal_encoding_variation2.phpt
new file mode 100644 (file)
index 0000000..3abf251
--- /dev/null
@@ -0,0 +1,374 @@
+--TEST--
+Test mb_internal_encoding() function : usage variations - Test different encodings
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_internal_encoding') or die("skip mb_internal_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_internal_encoding([string $encoding])
+ * Description: Sets the current internal encoding or Returns 
+ * the current internal encoding as a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test all listed encoding types from php.net to check all are known to function
+ * NB: The strings passed are *NOT* necessarily encoded in the encoding passed to the function.
+ * This test is purely to see whether the function recognises the encoding.
+ */
+
+echo "*** Testing mb_internal_encoding() : usage variations ***\n";
+
+$encoding = array('UCS-4',                     /*1*/
+                  'UCS-4BE',
+                  'UCS-4LE',
+                  'UCS-2',
+                  'UCS-2BE',           /*5*/
+                  'UCS-2LE',
+                  'UTF-32',
+                  'UTF-32BE',
+                  'UTF-32LE',
+                  'UTF-16',                    /*10*/
+                  'UTF-16BE',
+                  'UTF-16LE',
+                  'UTF-7',
+                  'UTF7-IMAP',
+                  'UTF-8',                     /*15*/
+                  'ASCII',
+                  'EUC-JP',
+                  'SJIS',
+                  'eucJP-win',
+                  'SJIS-win',          /*20*/
+                  'ISO-2022-JP',
+                  'JIS',
+                  'ISO-8859-1',
+                  'ISO-8859-2',
+                  'ISO-8859-3',                /*25*/
+                  'ISO-8859-4',
+                  'ISO-8859-5',
+                  'ISO-8859-6',
+                  'ISO-8859-7',
+                  'ISO-8859-8',                /*30*/
+                  'ISO-8859-9',
+                  'ISO-8859-10',
+                  'ISO-8859-13',
+                  'ISO-8859-14',
+                  'ISO-8859-15',       /*35*/
+                  'byte2be',
+                  'byte2le',
+                  'byte4be',
+                  'byte4le',
+                  'BASE64',                    /*40*/
+                  'HTML-ENTITIES',
+                  '7bit',
+                  '8bit',
+                  'EUC-CN',
+                  'CP936',                     /*45*/
+                  'HZ',
+                  'EUC-TW',
+                  'CP950',
+                  'BIG-5',
+                  'EUC-KR',                    /*50*/
+                  'UHC',
+                  'ISO-2022-KR',
+                  'Windows-1251',
+                  'Windows-1252',
+                  'CP866',                     /*55*/
+                  'KOI8-R');           /*56*/
+
+$iterator = 1;
+foreach($encoding as $enc) {
+       echo "\n-- Iteration $iterator --\n";
+       var_dump(mb_internal_encoding());
+       var_dump(mb_internal_encoding($enc));
+       var_dump(mb_internal_encoding());
+       $iterator++;
+}
+echo "Done";
+?>
+--EXPECTF--
+
+*** Testing mb_internal_encoding() : usage variations ***
+
+-- Iteration 1 --
+string(%d) "%s"
+bool(true)
+string(5) "UCS-4"
+
+-- Iteration 2 --
+string(5) "UCS-4"
+bool(true)
+string(7) "UCS-4BE"
+
+-- Iteration 3 --
+string(7) "UCS-4BE"
+bool(true)
+string(7) "UCS-4LE"
+
+-- Iteration 4 --
+string(7) "UCS-4LE"
+bool(true)
+string(5) "UCS-2"
+
+-- Iteration 5 --
+string(5) "UCS-2"
+bool(true)
+string(7) "UCS-2BE"
+
+-- Iteration 6 --
+string(7) "UCS-2BE"
+bool(true)
+string(7) "UCS-2LE"
+
+-- Iteration 7 --
+string(7) "UCS-2LE"
+bool(true)
+string(6) "UTF-32"
+
+-- Iteration 8 --
+string(6) "UTF-32"
+bool(true)
+string(8) "UTF-32BE"
+
+-- Iteration 9 --
+string(8) "UTF-32BE"
+bool(true)
+string(8) "UTF-32LE"
+
+-- Iteration 10 --
+string(8) "UTF-32LE"
+bool(true)
+string(6) "UTF-16"
+
+-- Iteration 11 --
+string(6) "UTF-16"
+bool(true)
+string(8) "UTF-16BE"
+
+-- Iteration 12 --
+string(8) "UTF-16BE"
+bool(true)
+string(8) "UTF-16LE"
+
+-- Iteration 13 --
+string(8) "UTF-16LE"
+bool(true)
+string(5) "UTF-7"
+
+-- Iteration 14 --
+string(5) "UTF-7"
+bool(true)
+string(9) "UTF7-IMAP"
+
+-- Iteration 15 --
+string(9) "UTF7-IMAP"
+bool(true)
+string(5) "UTF-8"
+
+-- Iteration 16 --
+string(5) "UTF-8"
+bool(true)
+string(5) "ASCII"
+
+-- Iteration 17 --
+string(5) "ASCII"
+bool(true)
+string(6) "EUC-JP"
+
+-- Iteration 18 --
+string(6) "EUC-JP"
+bool(true)
+string(4) "SJIS"
+
+-- Iteration 19 --
+string(4) "SJIS"
+bool(true)
+string(9) "eucJP-win"
+
+-- Iteration 20 --
+string(9) "eucJP-win"
+bool(true)
+string(8) "SJIS-win"
+
+-- Iteration 21 --
+string(8) "SJIS-win"
+bool(true)
+string(11) "ISO-2022-JP"
+
+-- Iteration 22 --
+string(11) "ISO-2022-JP"
+bool(true)
+string(3) "JIS"
+
+-- Iteration 23 --
+string(3) "JIS"
+bool(true)
+string(10) "ISO-8859-1"
+
+-- Iteration 24 --
+string(10) "ISO-8859-1"
+bool(true)
+string(10) "ISO-8859-2"
+
+-- Iteration 25 --
+string(10) "ISO-8859-2"
+bool(true)
+string(10) "ISO-8859-3"
+
+-- Iteration 26 --
+string(10) "ISO-8859-3"
+bool(true)
+string(10) "ISO-8859-4"
+
+-- Iteration 27 --
+string(10) "ISO-8859-4"
+bool(true)
+string(10) "ISO-8859-5"
+
+-- Iteration 28 --
+string(10) "ISO-8859-5"
+bool(true)
+string(10) "ISO-8859-6"
+
+-- Iteration 29 --
+string(10) "ISO-8859-6"
+bool(true)
+string(10) "ISO-8859-7"
+
+-- Iteration 30 --
+string(10) "ISO-8859-7"
+bool(true)
+string(10) "ISO-8859-8"
+
+-- Iteration 31 --
+string(10) "ISO-8859-8"
+bool(true)
+string(10) "ISO-8859-9"
+
+-- Iteration 32 --
+string(10) "ISO-8859-9"
+bool(true)
+string(11) "ISO-8859-10"
+
+-- Iteration 33 --
+string(11) "ISO-8859-10"
+bool(true)
+string(11) "ISO-8859-13"
+
+-- Iteration 34 --
+string(11) "ISO-8859-13"
+bool(true)
+string(11) "ISO-8859-14"
+
+-- Iteration 35 --
+string(11) "ISO-8859-14"
+bool(true)
+string(11) "ISO-8859-15"
+
+-- Iteration 36 --
+string(11) "ISO-8859-15"
+bool(true)
+string(7) "byte2be"
+
+-- Iteration 37 --
+string(7) "byte2be"
+bool(true)
+string(7) "byte2le"
+
+-- Iteration 38 --
+string(7) "byte2le"
+bool(true)
+string(7) "byte4be"
+
+-- Iteration 39 --
+string(7) "byte4be"
+bool(true)
+string(7) "byte4le"
+
+-- Iteration 40 --
+string(7) "byte4le"
+bool(true)
+string(6) "BASE64"
+
+-- Iteration 41 --
+string(6) "BASE64"
+bool(true)
+string(13) "HTML-ENTITIES"
+
+-- Iteration 42 --
+string(13) "HTML-ENTITIES"
+bool(true)
+string(4) "7bit"
+
+-- Iteration 43 --
+string(4) "7bit"
+bool(true)
+string(4) "8bit"
+
+-- Iteration 44 --
+string(4) "8bit"
+bool(true)
+string(6) "EUC-CN"
+
+-- Iteration 45 --
+string(6) "EUC-CN"
+bool(true)
+string(5) "CP936"
+
+-- Iteration 46 --
+string(5) "CP936"
+bool(true)
+string(2) "HZ"
+
+-- Iteration 47 --
+string(2) "HZ"
+bool(true)
+string(6) "EUC-TW"
+
+-- Iteration 48 --
+string(6) "EUC-TW"
+bool(true)
+string(5) "BIG-5"
+
+-- Iteration 49 --
+string(5) "BIG-5"
+bool(true)
+string(5) "BIG-5"
+
+-- Iteration 50 --
+string(5) "BIG-5"
+bool(true)
+string(6) "EUC-KR"
+
+-- Iteration 51 --
+string(6) "EUC-KR"
+bool(true)
+string(3) "UHC"
+
+-- Iteration 52 --
+string(3) "UHC"
+bool(true)
+string(11) "ISO-2022-KR"
+
+-- Iteration 53 --
+string(11) "ISO-2022-KR"
+bool(true)
+string(12) "Windows-1251"
+
+-- Iteration 54 --
+string(12) "Windows-1251"
+bool(true)
+string(12) "Windows-1252"
+
+-- Iteration 55 --
+string(12) "Windows-1252"
+bool(true)
+string(5) "CP866"
+
+-- Iteration 56 --
+string(5) "CP866"
+bool(true)
+string(6) "KOI8-R"
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_regex_encoding_basic.phpt b/ext/mbstring/tests/mb_regex_encoding_basic.phpt
new file mode 100644 (file)
index 0000000..a0a41e9
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Test mb_regex_encoding() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_regex_encoding') or die("skip mb_regex_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : proto string mb_regex_encoding([string encoding])
+ * Description: Returns the current encoding for regex as a string. 
+ * Source code: ext/mbstring/php_mbregex.c 
+ */
+
+/*
+ * Test Basic functionality of mb_regex_encoding
+ */
+
+echo "*** Testing mb_regex_encoding() : basic functionality ***\n";
+
+var_dump(mb_regex_encoding());
+
+var_dump(mb_regex_encoding('UTF-8'));
+
+var_dump(mb_regex_encoding());
+
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_regex_encoding() : basic functionality ***
+string(%d) "%s"
+bool(true)
+string(5) "UTF-8"
+Done
diff --git a/ext/mbstring/tests/mb_regex_encoding_error1.phpt b/ext/mbstring/tests/mb_regex_encoding_error1.phpt
new file mode 100644 (file)
index 0000000..6fe19aa
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Test mb_regex_encoding() function : error conditions - pass incorrect number of args
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_regex_encoding') or die("skip mb_regex_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_regex_encoding([string $encoding])
+ * Description: Returns the current encoding for regex as a string. 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Test mb_regex_encoding with one more than expected number of arguments
+ */
+
+echo "*** Testing mb_regex_encoding() : error conditions ***\n";
+
+
+echo "\n-- Testing mb_regex_encoding() function with more than expected no. of arguments --\n";
+$encoding = 'string_val';
+$extra_arg = 10;
+var_dump( mb_regex_encoding($encoding, $extra_arg) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_regex_encoding() : error conditions ***
+
+-- Testing mb_regex_encoding() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for mb_regex_encoding() in %s on line %d
+NULL
+Done
diff --git a/ext/mbstring/tests/mb_regex_encoding_error2.phpt b/ext/mbstring/tests/mb_regex_encoding_error2.phpt
new file mode 100644 (file)
index 0000000..c752609
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+Test mb_regex_encoding() function : error conditions - Pass an unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_regex_encoding') or die("skip mb_regex_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_regex_encoding([string $encoding])
+ * Description: Returns the current encoding for regex as a string. 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Pass mb_regex_encoding an unknown type of encoding
+ */
+
+echo "*** Testing mb_regex_encoding() : error conditions ***\n";
+
+var_dump(mb_regex_encoding('unknown'));
+
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_regex_encoding() : error conditions ***
+
+Warning: mb_regex_encoding(): Unknown encoding "unknown" in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_regex_encoding_variation1.phpt b/ext/mbstring/tests/mb_regex_encoding_variation1.phpt
new file mode 100644 (file)
index 0000000..0d2ff99
--- /dev/null
@@ -0,0 +1,215 @@
+--TEST--
+Test mb_regex_encoding() function : usage variations - Pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_regex_encoding') or die("skip mb_regex_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_regex_encoding([string $encoding])
+ * Description: Returns the current encoding for regex as a string. 
+ * Source code: ext/mbstring/php_mbregex.c
+ */
+
+/*
+ * Pass different data types as $encoding argument to mb_regex_encoding() to test behaviour
+ * Where possible, 'UTF-8' has been entered as a string value
+ */
+
+echo "*** Testing mb_regex_encoding() : usage variations ***\n";
+//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 $encoding 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_regex_encoding()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_regex_encoding($input) );
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_regex_encoding() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_regex_encoding(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_regex_encoding(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_regex_encoding(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_regex_encoding(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_regex_encoding(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_regex_encoding(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_regex_encoding(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_regex_encoding(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_regex_encoding(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: mb_regex_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_regex_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: mb_regex_encoding(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_regex_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: mb_regex_encoding(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_regex_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_regex_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_regex_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+bool(true)
+
+-- Iteration 19 --
+bool(true)
+
+-- Iteration 20 --
+bool(true)
+
+-- Iteration 21 --
+bool(true)
+
+-- Iteration 22 --
+
+Warning: mb_regex_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_regex_encoding(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_regex_encoding(): Unknown encoding "Resource id #%d" in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strlen_basic.phpt b/ext/mbstring/tests/mb_strlen_basic.phpt
new file mode 100644 (file)
index 0000000..6214f30
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+Test mb_strlen() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strlen') or die("skip mb_strlen() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strlen(string $str [, string $encoding])
+ * Description: Get character numbers of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test basic functionality of mb_strlen()
+ */
+
+echo "*** Testing mb_strlen() : basic functionality***\n";
+
+$string_ascii = 'abc def';
+//Japanese string in UTF-8
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+echo "\n-- ASCII String --\n";
+var_dump(mb_strlen($string_ascii));
+
+echo "\n-- Multibyte String --\n";
+var_dump(mb_strlen($string_mb, 'UTF-8'));
+
+echo "\nDone";
+?>
+
+--EXPECTF--
+*** Testing mb_strlen() : basic functionality***
+
+-- ASCII String --
+int(7)
+
+-- Multibyte String --
+int(21)
+
+Done
diff --git a/ext/mbstring/tests/mb_strlen_error1.phpt b/ext/mbstring/tests/mb_strlen_error1.phpt
new file mode 100644 (file)
index 0000000..8fcd87e
--- /dev/null
@@ -0,0 +1,46 @@
+--TEST--
+Test mb_strlen() function : error conditions - pass incorrect number of args
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strlen') or die("skip mb_strlen() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strlen(string $str [, string $encoding])
+ * Description: Get character numbers of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass mb_strlen an incorrect number of arguments to test behaviour
+ */
+
+echo "*** Testing mb_strlen() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing mb_strlen() function with Zero arguments --\n";
+var_dump( mb_strlen() );
+
+//Test mb_strlen with one more than the expected number of arguments
+echo "\n-- Testing mb_strlen() function with more than expected no. of arguments --\n";
+$str = 'string_val';
+$encoding = 'string_val';
+$extra_arg = 10;
+var_dump( mb_strlen($str, $encoding, $extra_arg) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strlen() : error conditions ***
+
+-- Testing mb_strlen() function with Zero arguments --
+
+Warning: mb_strlen() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+-- Testing mb_strlen() function with more than expected no. of arguments --
+
+Warning: mb_strlen() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_strlen_error2.phpt b/ext/mbstring/tests/mb_strlen_error2.phpt
new file mode 100644 (file)
index 0000000..a530a84
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+Test mb_strlen() function : error conditions - pass an unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strlen') or die("skip mb_strlen() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strlen(string $str [, string $encoding])
+ * Description: Get character numbers of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test mb_strlen when passed an unknown encoding
+ */
+
+echo "*** Testing mb_strlen() : error ***\n";
+
+$string = 'abcdef';
+
+$encoding = 'unknown-encoding';
+
+var_dump(mb_strlen($string, $encoding));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strlen() : error ***
+
+Warning: mb_strlen(): Unknown encoding "unknown-encoding" in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_strlen_variation1.phpt b/ext/mbstring/tests/mb_strlen_variation1.phpt
new file mode 100644 (file)
index 0000000..a64fad1
--- /dev/null
@@ -0,0 +1,180 @@
+--TEST--
+Test mb_strlen() function : usage variations - Pass different data types as $str arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strlen') or die("skip mb_strlen() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strlen(string $str [, string $encoding])
+ * Description: Get character numbers of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test mb_strlen by passing different data types as $str argument
+ */
+
+echo "*** Testing mb_strlen() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$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 $str 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_strlen()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strlen($input, $encoding));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strlen() : usage variations ***
+
+-- Iteration 1 --
+int(1)
+
+-- Iteration 2 --
+int(1)
+
+-- Iteration 3 --
+int(5)
+
+-- Iteration 4 --
+int(5)
+
+-- Iteration 5 --
+int(4)
+
+-- Iteration 6 --
+int(5)
+
+-- Iteration 7 --
+int(12)
+
+-- Iteration 8 --
+int(13)
+
+-- Iteration 9 --
+int(3)
+
+-- Iteration 10 --
+int(0)
+
+-- Iteration 11 --
+int(0)
+
+-- Iteration 12 --
+int(1)
+
+-- Iteration 13 --
+int(0)
+
+-- Iteration 14 --
+int(1)
+
+-- Iteration 15 --
+int(0)
+
+-- Iteration 16 --
+int(0)
+
+-- Iteration 17 --
+int(0)
+
+-- Iteration 18 --
+int(6)
+
+-- Iteration 19 --
+int(6)
+
+-- Iteration 20 --
+int(11)
+
+-- Iteration 21 --
+int(14)
+
+-- Iteration 22 --
+int(0)
+
+-- Iteration 23 --
+int(0)
+
+-- Iteration 24 --
+
+Warning: mb_strlen() expects parameter 1 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strlen_variation2.phpt b/ext/mbstring/tests/mb_strlen_variation2.phpt
new file mode 100644 (file)
index 0000000..d34f3cf
--- /dev/null
@@ -0,0 +1,220 @@
+--TEST--
+Test mb_strlen() function : usage variations - Pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strlen') or die("skip mb_strlen() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strlen(string $str [, string $encoding])
+ * Description: Get character numbers of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test mb_strlen() by passing different data types as $encoding argument.
+ * Where possible 'UTF-8' has been entered as a string value
+ */
+
+echo "*** Testing mb_strlen() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$str = 'string value';
+
+//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_strlen()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strlen($str, $input));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strlen() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_strlen(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_strlen(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_strlen(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_strlen(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_strlen(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_strlen(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_strlen(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_strlen(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_strlen(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: mb_strlen(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_strlen(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: mb_strlen(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_strlen(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: mb_strlen(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_strlen(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_strlen(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_strlen(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+int(12)
+
+-- Iteration 19 --
+int(12)
+
+-- Iteration 20 --
+int(12)
+
+-- Iteration 21 --
+int(12)
+
+-- Iteration 22 --
+
+Warning: mb_strlen(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_strlen(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_strlen() expects parameter 2 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strlen_variation3.phpt b/ext/mbstring/tests/mb_strlen_variation3.phpt
new file mode 100644 (file)
index 0000000..13dc909
--- /dev/null
@@ -0,0 +1,445 @@
+--TEST--
+Test mb_strlen() function : usage variations - Pass list of encodings
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strlen') or die("skip mb_strlen() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strlen(string $str [, string $encoding])
+ * Description: Get character numbers of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass all encodings listed on php.net to mb_strlen to test that function recognises them
+ * NB: The strings passed are *NOT* necessarily encoded in the encoding passed to the function.
+ * This test is purely to see whether the function recognises the encoding.
+ */
+
+echo "*** Testing mb_strlen() : usage variations ***\n";
+
+$encoding = array('UCS-4',                     /*1*/
+                  'UCS-4BE',
+                  'UCS-4LE',
+                  'UCS-2',
+                  'UCS-2BE',           /*5*/
+                  'UCS-2LE',
+                  'UTF-32',
+                  'UTF-32BE',
+                  'UTF-32LE',
+                  'UTF-16',                    /*10*/
+                  'UTF-16BE',
+                  'UTF-16LE',
+                  'UTF-7',
+                  'UTF7-IMAP',
+                  'UTF-8',                     /*15*/
+                  'ASCII',
+                  'EUC-JP',
+                  'SJIS',
+                  'eucJP-win',
+                  'SJIS-win',          /*20*/
+                  'ISO-2022-JP',
+                  'JIS',
+                  'ISO-8859-1',
+                  'ISO-8859-2',
+                  'ISO-8859-3',                /*25*/
+                  'ISO-8859-4',
+                  'ISO-8859-5',
+                  'ISO-8859-6',
+                  'ISO-8859-7',
+                  'ISO-8859-8',                /*30*/
+                  'ISO-8859-9',
+                  'ISO-8859-10',
+                  'ISO-8859-13',
+                  'ISO-8859-14',
+                  'ISO-8859-15',       /*35*/
+                  'byte2be',
+                  'byte2le',
+                  'byte4be',
+                  'byte4le',
+                  'BASE64',                    /*40*/
+                  'HTML-ENTITIES',
+                  '7bit',
+                  '8bit',
+                  'EUC-CN',
+                  'CP936',                     /*45*/
+                  'HZ',
+                  'EUC-TW',
+                  'CP950',
+                  'BIG-5',
+                  'EUC-KR',                    /*50*/
+                  'UHC',
+                  'ISO-2022-KR',
+                  'Windows-1251',
+                  'Windows-1252',
+                  'CP866',                     /*55*/
+                  'KOI8-R');           /*56*/
+
+
+
+$iterator = 1;
+$string_ascii = 'abc def';
+$string_mb = base64_decode('44K/44OT44Ol44Os44O844OG44Kj44Oz44Kw44O744Oe44K344O844Oz44O744Kr44Oz44OR44OL44O8');
+
+foreach($encoding as $enc) {
+       echo "\n-- Iteration $iterator: $enc --\n";
+
+       echo "-- ASCII String --\n";
+       if(mb_strlen($string_ascii, $enc)) {
+               echo "Encoding $enc recognised\n";
+       } else {
+               echo "Encoding $enc not recognised\n";
+       }
+
+       echo "-- Multibyte String --\n";
+       if(mb_strlen($string_mb, $enc)){
+               echo "Encoding $enc recognised\n";
+       } else {
+               echo "Encoding $enc not recognised\n";
+       }
+       $iterator++;
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strlen() : usage variations ***
+
+-- Iteration 1: UCS-4 --
+-- ASCII String --
+Encoding UCS-4 recognised
+-- Multibyte String --
+Encoding UCS-4 recognised
+
+-- Iteration 2: UCS-4BE --
+-- ASCII String --
+Encoding UCS-4BE recognised
+-- Multibyte String --
+Encoding UCS-4BE recognised
+
+-- Iteration 3: UCS-4LE --
+-- ASCII String --
+Encoding UCS-4LE recognised
+-- Multibyte String --
+Encoding UCS-4LE recognised
+
+-- Iteration 4: UCS-2 --
+-- ASCII String --
+Encoding UCS-2 recognised
+-- Multibyte String --
+Encoding UCS-2 recognised
+
+-- Iteration 5: UCS-2BE --
+-- ASCII String --
+Encoding UCS-2BE recognised
+-- Multibyte String --
+Encoding UCS-2BE recognised
+
+-- Iteration 6: UCS-2LE --
+-- ASCII String --
+Encoding UCS-2LE recognised
+-- Multibyte String --
+Encoding UCS-2LE recognised
+
+-- Iteration 7: UTF-32 --
+-- ASCII String --
+Encoding UTF-32 recognised
+-- Multibyte String --
+Encoding UTF-32 recognised
+
+-- Iteration 8: UTF-32BE --
+-- ASCII String --
+Encoding UTF-32BE recognised
+-- Multibyte String --
+Encoding UTF-32BE recognised
+
+-- Iteration 9: UTF-32LE --
+-- ASCII String --
+Encoding UTF-32LE recognised
+-- Multibyte String --
+Encoding UTF-32LE recognised
+
+-- Iteration 10: UTF-16 --
+-- ASCII String --
+Encoding UTF-16 recognised
+-- Multibyte String --
+Encoding UTF-16 recognised
+
+-- Iteration 11: UTF-16BE --
+-- ASCII String --
+Encoding UTF-16BE recognised
+-- Multibyte String --
+Encoding UTF-16BE recognised
+
+-- Iteration 12: UTF-16LE --
+-- ASCII String --
+Encoding UTF-16LE recognised
+-- Multibyte String --
+Encoding UTF-16LE recognised
+
+-- Iteration 13: UTF-7 --
+-- ASCII String --
+Encoding UTF-7 recognised
+-- Multibyte String --
+Encoding UTF-7 recognised
+
+-- Iteration 14: UTF7-IMAP --
+-- ASCII String --
+Encoding UTF7-IMAP recognised
+-- Multibyte String --
+Encoding UTF7-IMAP recognised
+
+-- Iteration 15: UTF-8 --
+-- ASCII String --
+Encoding UTF-8 recognised
+-- Multibyte String --
+Encoding UTF-8 recognised
+
+-- Iteration 16: ASCII --
+-- ASCII String --
+Encoding ASCII recognised
+-- Multibyte String --
+Encoding ASCII recognised
+
+-- Iteration 17: EUC-JP --
+-- ASCII String --
+Encoding EUC-JP recognised
+-- Multibyte String --
+Encoding EUC-JP recognised
+
+-- Iteration 18: SJIS --
+-- ASCII String --
+Encoding SJIS recognised
+-- Multibyte String --
+Encoding SJIS recognised
+
+-- Iteration 19: eucJP-win --
+-- ASCII String --
+Encoding eucJP-win recognised
+-- Multibyte String --
+Encoding eucJP-win recognised
+
+-- Iteration 20: SJIS-win --
+-- ASCII String --
+Encoding SJIS-win recognised
+-- Multibyte String --
+Encoding SJIS-win recognised
+
+-- Iteration 21: ISO-2022-JP --
+-- ASCII String --
+Encoding ISO-2022-JP recognised
+-- Multibyte String --
+Encoding ISO-2022-JP recognised
+
+-- Iteration 22: JIS --
+-- ASCII String --
+Encoding JIS recognised
+-- Multibyte String --
+Encoding JIS recognised
+
+-- Iteration 23: ISO-8859-1 --
+-- ASCII String --
+Encoding ISO-8859-1 recognised
+-- Multibyte String --
+Encoding ISO-8859-1 recognised
+
+-- Iteration 24: ISO-8859-2 --
+-- ASCII String --
+Encoding ISO-8859-2 recognised
+-- Multibyte String --
+Encoding ISO-8859-2 recognised
+
+-- Iteration 25: ISO-8859-3 --
+-- ASCII String --
+Encoding ISO-8859-3 recognised
+-- Multibyte String --
+Encoding ISO-8859-3 recognised
+
+-- Iteration 26: ISO-8859-4 --
+-- ASCII String --
+Encoding ISO-8859-4 recognised
+-- Multibyte String --
+Encoding ISO-8859-4 recognised
+
+-- Iteration 27: ISO-8859-5 --
+-- ASCII String --
+Encoding ISO-8859-5 recognised
+-- Multibyte String --
+Encoding ISO-8859-5 recognised
+
+-- Iteration 28: ISO-8859-6 --
+-- ASCII String --
+Encoding ISO-8859-6 recognised
+-- Multibyte String --
+Encoding ISO-8859-6 recognised
+
+-- Iteration 29: ISO-8859-7 --
+-- ASCII String --
+Encoding ISO-8859-7 recognised
+-- Multibyte String --
+Encoding ISO-8859-7 recognised
+
+-- Iteration 30: ISO-8859-8 --
+-- ASCII String --
+Encoding ISO-8859-8 recognised
+-- Multibyte String --
+Encoding ISO-8859-8 recognised
+
+-- Iteration 31: ISO-8859-9 --
+-- ASCII String --
+Encoding ISO-8859-9 recognised
+-- Multibyte String --
+Encoding ISO-8859-9 recognised
+
+-- Iteration 32: ISO-8859-10 --
+-- ASCII String --
+Encoding ISO-8859-10 recognised
+-- Multibyte String --
+Encoding ISO-8859-10 recognised
+
+-- Iteration 33: ISO-8859-13 --
+-- ASCII String --
+Encoding ISO-8859-13 recognised
+-- Multibyte String --
+Encoding ISO-8859-13 recognised
+
+-- Iteration 34: ISO-8859-14 --
+-- ASCII String --
+Encoding ISO-8859-14 recognised
+-- Multibyte String --
+Encoding ISO-8859-14 recognised
+
+-- Iteration 35: ISO-8859-15 --
+-- ASCII String --
+Encoding ISO-8859-15 recognised
+-- Multibyte String --
+Encoding ISO-8859-15 recognised
+
+-- Iteration 36: byte2be --
+-- ASCII String --
+Encoding byte2be recognised
+-- Multibyte String --
+Encoding byte2be recognised
+
+-- Iteration 37: byte2le --
+-- ASCII String --
+Encoding byte2le recognised
+-- Multibyte String --
+Encoding byte2le recognised
+
+-- Iteration 38: byte4be --
+-- ASCII String --
+Encoding byte4be recognised
+-- Multibyte String --
+Encoding byte4be recognised
+
+-- Iteration 39: byte4le --
+-- ASCII String --
+Encoding byte4le recognised
+-- Multibyte String --
+Encoding byte4le recognised
+
+-- Iteration 40: BASE64 --
+-- ASCII String --
+Encoding BASE64 recognised
+-- Multibyte String --
+Encoding BASE64 recognised
+
+-- Iteration 41: HTML-ENTITIES --
+-- ASCII String --
+Encoding HTML-ENTITIES recognised
+-- Multibyte String --
+Encoding HTML-ENTITIES recognised
+
+-- Iteration 42: 7bit --
+-- ASCII String --
+Encoding 7bit recognised
+-- Multibyte String --
+Encoding 7bit recognised
+
+-- Iteration 43: 8bit --
+-- ASCII String --
+Encoding 8bit recognised
+-- Multibyte String --
+Encoding 8bit recognised
+
+-- Iteration 44: EUC-CN --
+-- ASCII String --
+Encoding EUC-CN recognised
+-- Multibyte String --
+Encoding EUC-CN recognised
+
+-- Iteration 45: CP936 --
+-- ASCII String --
+Encoding CP936 recognised
+-- Multibyte String --
+Encoding CP936 recognised
+
+-- Iteration 46: HZ --
+-- ASCII String --
+Encoding HZ recognised
+-- Multibyte String --
+Encoding HZ recognised
+
+-- Iteration 47: EUC-TW --
+-- ASCII String --
+Encoding EUC-TW recognised
+-- Multibyte String --
+Encoding EUC-TW recognised
+
+-- Iteration 48: CP950 --
+-- ASCII String --
+Encoding CP950 recognised
+-- Multibyte String --
+Encoding CP950 recognised
+
+-- Iteration 49: BIG-5 --
+-- ASCII String --
+Encoding BIG-5 recognised
+-- Multibyte String --
+Encoding BIG-5 recognised
+
+-- Iteration 50: EUC-KR --
+-- ASCII String --
+Encoding EUC-KR recognised
+-- Multibyte String --
+Encoding EUC-KR recognised
+
+-- Iteration 51: UHC --
+-- ASCII String --
+Encoding UHC recognised
+-- Multibyte String --
+Encoding UHC recognised
+
+-- Iteration 52: ISO-2022-KR --
+-- ASCII String --
+Encoding ISO-2022-KR recognised
+-- Multibyte String --
+Encoding ISO-2022-KR recognised
+
+-- Iteration 53: Windows-1251 --
+-- ASCII String --
+Encoding Windows-1251 recognised
+-- Multibyte String --
+Encoding Windows-1251 recognised
+
+-- Iteration 54: Windows-1252 --
+-- ASCII String --
+Encoding Windows-1252 recognised
+-- Multibyte String --
+Encoding Windows-1252 recognised
+
+-- Iteration 55: CP866 --
+-- ASCII String --
+Encoding CP866 recognised
+-- Multibyte String --
+Encoding CP866 recognised
+
+-- Iteration 56: KOI8-R --
+-- ASCII String --
+Encoding KOI8-R recognised
+-- Multibyte String --
+Encoding KOI8-R recognised
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strpos_basic.phpt b/ext/mbstring/tests/mb_strpos_basic.phpt
new file mode 100644 (file)
index 0000000..4284ab8
--- /dev/null
@@ -0,0 +1,57 @@
+--TEST--
+Test mb_strpos() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strpos(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_strpos with ASCII and multibyte characters
+ */
+
+echo "*** Testing mb_strpos() : basic functionality***\n";
+
+mb_internal_encoding('UTF-8');
+
+$string_ascii = 'abc def';
+//Japanese string in UTF-8
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+echo "\n-- ASCII string 1 --\n";
+var_dump(mb_strpos($string_ascii, 'd', 2, 'ISO-8859-1'));
+
+echo "\n-- ASCII string 2 --\n";
+var_dump(mb_strpos($string_ascii, '123'));
+
+echo "\n-- Multibyte string 1 --\n";
+$needle1 = base64_decode('5pel5pys6Kqe');
+var_dump(mb_strpos($string_mb, $needle1));
+
+echo "\n-- Multibyte string 2 --\n";
+$needle2 = base64_decode("44GT44KT44Gr44Gh44Gv44CB5LiW55WM");
+var_dump(mb_strpos($string_mb, $needle2));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strpos() : basic functionality***
+
+-- ASCII string 1 --
+int(4)
+
+-- ASCII string 2 --
+bool(false)
+
+-- Multibyte string 1 --
+int(0)
+
+-- Multibyte string 2 --
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strpos_error1.phpt b/ext/mbstring/tests/mb_strpos_error1.phpt
new file mode 100644 (file)
index 0000000..8f5ba85
--- /dev/null
@@ -0,0 +1,50 @@
+--TEST--
+Test mb_strpos() function : error conditions - Pass incorrect number of args
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strpos(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_strpos behaves when passed an incorrect number of arguments
+ */
+
+echo "*** Testing mb_strpos() : error conditions ***\n";
+
+
+//Test mb_strpos with one more than the expected number of arguments
+echo "\n-- Testing mb_strpos() 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_strpos($haystack, $needle, $offset, $encoding, $extra_arg) );
+
+// Testing mb_strpos with one less than the expected number of arguments
+echo "\n-- Testing mb_strpos() function with less than expected no. of arguments --\n";
+$haystack = 'string_val';
+var_dump( mb_strpos($haystack) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strpos() : error conditions ***
+
+-- Testing mb_strpos() function with more than expected no. of arguments --
+
+Warning: mb_strpos() expects at most 4 parameters, 5 given in %s on line %d
+bool(false)
+
+-- Testing mb_strpos() function with less than expected no. of arguments --
+
+Warning: mb_strpos() expects at least 2 parameters, 1 given in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_strpos_error2.phpt b/ext/mbstring/tests/mb_strpos_error2.phpt
new file mode 100644 (file)
index 0000000..f75390f
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+Test mb_strpos() function : error conditions - Pass unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strpos(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_strpos() to test behaviour
+ */
+
+echo "*** Testing mb_strpos() : error conditions ***\n";
+$haystack = 'Hello, world';
+$needle = 'world';
+$offset = 2;
+$encoding = 'unknown-encoding';
+
+var_dump( mb_strpos($haystack, $needle, $offset, $encoding) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strpos() : error conditions ***
+
+Warning: mb_strpos(): Unknown encoding "unknown-encoding" in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_strpos_variation1.phpt b/ext/mbstring/tests/mb_strpos_variation1.phpt
new file mode 100644 (file)
index 0000000..61f5347
--- /dev/null
@@ -0,0 +1,182 @@
+--TEST--
+Test mb_strpos() function : usage variations - pass different data types to $haystack arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strpos(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_strpos different data types as $haystack arg to test behaviour
+ */
+
+echo "*** Testing mb_strpos() : 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_strpos()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strpos($input, $needle, $offset, $encoding));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strpos() : 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_strpos() expects parameter 1 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strpos_variation2.phpt b/ext/mbstring/tests/mb_strpos_variation2.phpt
new file mode 100644 (file)
index 0000000..ed62ea8
--- /dev/null
@@ -0,0 +1,198 @@
+--TEST--
+Test mb_strpos() function : usage variations - pass different data types as $needle arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strpos(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_strpos different data types as $needle arg to test behaviour
+ */
+
+echo "*** Testing mb_strpos() : 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_strpos()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strpos($haystack, $input, $offset, $encoding));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strpos() : 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_strpos(): Empty delimiter. in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_strpos(): Empty delimiter. in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_strpos(): Empty delimiter. in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_strpos(): Empty delimiter. in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_strpos(): Empty delimiter. in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_strpos(): 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_strpos(): Empty delimiter. in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_strpos(): Empty delimiter. in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_strpos() expects parameter 2 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strpos_variation3.phpt b/ext/mbstring/tests/mb_strpos_variation3.phpt
new file mode 100644 (file)
index 0000000..8f8540e
--- /dev/null
@@ -0,0 +1,202 @@
+--TEST--
+Test mb_strpos() function : usage variations - pass different data types as $offset arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strpos(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_strpos different data types as $offset arg to test behaviour
+ */
+
+echo "*** Testing mb_strpos() : 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_strpos()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strpos($haystack, $needle, $input, $encoding));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strpos() : usage variations ***
+
+-- Iteration 1 --
+int(8)
+
+-- Iteration 2 --
+int(8)
+
+-- Iteration 3 --
+
+Warning: mb_strpos(): Offset not contained in string. in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_strpos(): Offset not contained in string. in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_strpos(): Offset not contained in string. in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_strpos(): 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_strpos() expects parameter 3 to be long, string given in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+
+Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
+bool(false)
+
+-- Iteration 19 --
+
+Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
+bool(false)
+
+-- Iteration 20 --
+
+Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
+bool(false)
+
+-- Iteration 21 --
+
+Warning: mb_strpos() 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_strpos() expects parameter 3 to be long, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strpos_variation4.phpt b/ext/mbstring/tests/mb_strpos_variation4.phpt
new file mode 100644 (file)
index 0000000..ac818c6
--- /dev/null
@@ -0,0 +1,222 @@
+--TEST--
+Test mb_strpos() function : usage variations - pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strpos(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_strpos different data types as $encoding arg to test behaviour
+ * Where possible 'UTF-8' has been entered as a string value
+ */
+
+echo "*** Testing mb_strpos() : 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_strpos()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strpos($haystack, $needle, $offset, $input));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strpos() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_strpos(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_strpos(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_strpos(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_strpos(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_strpos(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_strpos(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_strpos(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_strpos(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_strpos(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: mb_strpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_strpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: mb_strpos(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_strpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: mb_strpos(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_strpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_strpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_strpos(): 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_strpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_strpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_strpos() expects parameter 4 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strrpos_basic.phpt b/ext/mbstring/tests/mb_strrpos_basic.phpt
new file mode 100644 (file)
index 0000000..9de0388
--- /dev/null
@@ -0,0 +1,58 @@
+--TEST--
+Test mb_strrpos() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
+ * Description: Find position of last occurrence of a string within another 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test basic functionality of mb_strrpos()
+ */
+
+echo "*** Testing mb_strrpos() : basic ***\n";
+
+mb_internal_encoding('UTF-8');
+
+$string_ascii = 'This is an English string. 0123456789.';
+//Japanese string in UTF-8
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+echo "\n-- ASCII string 1 --\n";
+var_dump(mb_strrpos($string_ascii, 'is', 4, 'ISO-8859-1'));
+
+echo "\n-- ASCII string 2 --\n";
+var_dump(mb_strrpos($string_ascii, 'hello, world'));
+
+echo "\n-- Multibyte string 1 --\n";
+$needle1 = base64_decode('44CC');
+var_dump(mb_strrpos($string_mb, $needle1));
+
+echo "\n-- Multibyte string 2 --\n";
+$needle2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
+var_dump(mb_strrpos($string_mb, $needle2));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strrpos() : basic ***
+
+-- ASCII string 1 --
+int(15)
+
+-- ASCII string 2 --
+bool(false)
+
+-- Multibyte string 1 --
+int(20)
+
+-- Multibyte string 2 --
+bool(false)
+Done
+
diff --git a/ext/mbstring/tests/mb_strrpos_error1.phpt b/ext/mbstring/tests/mb_strrpos_error1.phpt
new file mode 100644 (file)
index 0000000..727ef56
--- /dev/null
@@ -0,0 +1,50 @@
+--TEST--
+Test mb_strrpos() function : error conditions - pass incorrect number of args
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
+ * Description: Find position of last occurrence of a string within another 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass mb_strrpos() an incorrect number of arguments
+ */
+
+echo "*** Testing mb_strrpos() : error conditions ***\n";
+
+
+//Test mb_strrpos with one more than the expected number of arguments
+echo "\n-- Testing mb_strrpos() 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_strrpos($haystack, $needle, $offset, $encoding, $extra_arg) );
+
+// Testing mb_strrpos with one less than the expected number of arguments
+echo "\n-- Testing mb_strrpos() function with less than expected no. of arguments --\n";
+$haystack = 'string_val';
+var_dump( mb_strrpos($haystack) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strrpos() : error conditions ***
+
+-- Testing mb_strrpos() function with more than expected no. of arguments --
+
+Warning: mb_strrpos() expects at most 4 parameters, 5 given in %s on line %d
+bool(false)
+
+-- Testing mb_strrpos() function with less than expected no. of arguments --
+
+Warning: mb_strrpos() expects at least 2 parameters, 1 given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strrpos_error2.phpt b/ext/mbstring/tests/mb_strrpos_error2.phpt
new file mode 100644 (file)
index 0000000..8247d37
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Test mb_strrpos() function : error conditions - pass an unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
+ * Description: Find position of last occurrence of a string within another 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass mb_strrpos() an encoding that doesn't exist
+ */
+
+echo "*** Testing mb_strrpos() : error conditions ***\n";
+
+$haystack = 'This is an English string. 0123456789.';
+$needle = '123';
+$offset = 5;
+$encoding = 'unknown-encoding';
+
+var_dump(mb_strrpos($haystack, $needle , $offset, $encoding));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strrpos() : error conditions ***
+
+Warning: mb_strrpos(): Unknown encoding "unknown-encoding" in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strrpos_variation1.phpt b/ext/mbstring/tests/mb_strrpos_variation1.phpt
new file mode 100644 (file)
index 0000000..922cb73
--- /dev/null
@@ -0,0 +1,181 @@
+--TEST--
+Test mb_strrpos() function : usage variations - pass different data types to $haystack arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
+ * Description: Find position of last occurrence of a string within another 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass mb_strrpos() different data types as $haystack argument to test behaviour
+ */
+
+echo "*** Testing mb_strrpos() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$needle = 'world';
+$offset = 0;
+$encoding = 'utf-8';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+  public function __toString() {
+    return "hello, world";
+  }
+}
+
+// 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*/ "hello, world",
+       'hello, world',
+       $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_strrpos()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strrpos($input, $needle, $offset, $encoding));
+  $iterator++;
+};
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strrpos() : 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 --
+int(7)
+
+-- Iteration 19 --
+int(7)
+
+-- Iteration 20 --
+int(7)
+
+-- Iteration 21 --
+int(7)
+
+-- Iteration 22 --
+bool(false)
+
+-- Iteration 23 --
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_strrpos() expects parameter 1 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strrpos_variation2.phpt b/ext/mbstring/tests/mb_strrpos_variation2.phpt
new file mode 100644 (file)
index 0000000..4986096
--- /dev/null
@@ -0,0 +1,183 @@
+--TEST--
+Test mb_strrpos() function : usage variations - Pass different data types to $needle arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
+ * Description: Find position of last occurrence of a string within another 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass mb_strrpos() different data types as $needle argument to test behaviour
+ */
+
+echo "*** Testing mb_strrpos() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$haystack = 'hello, world';
+$offset = 0;
+$encoding = 'utf-8';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+  public function __toString() {
+    return "world";
+  }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+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*/ "world",
+       'world',
+       $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_strrpos()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strrpos($haystack, $input, $offset, $encoding));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strrpos() : 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 --
+int(7)
+
+-- Iteration 19 --
+int(7)
+
+-- Iteration 20 --
+int(7)
+
+-- Iteration 21 --
+int(7)
+
+-- Iteration 22 --
+bool(false)
+
+-- Iteration 23 --
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_strrpos() expects parameter 2 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strrpos_variation3.phpt b/ext/mbstring/tests/mb_strrpos_variation3.phpt
new file mode 100644 (file)
index 0000000..fbd0c68
--- /dev/null
@@ -0,0 +1,147 @@
+--TEST--
+Test mb_strrpos() function : usage variations - Pass different data types as $offset arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
+ * Description: Find position of last occurrence of a string within another 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass mb_strrpos() different data types as $offset argument to test behaviour
+ */
+
+echo "*** Testing mb_strrpos() : 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 "7";
+  }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// unexpected values to be passed to $offset 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,
+       
+       // object data
+/*16*/ new classA(),
+
+       // undefined data
+/*17*/ @$undefined_var,
+
+       // unset data
+/*18*/ @$unset_var
+);
+
+// loop through each element of $inputs to check the behavior of mb_strrpos()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strrpos($haystack, $needle, $input, $encoding));
+  $iterator++;
+};
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strrpos() : usage variations ***
+
+-- Iteration 1 --
+int(8)
+
+-- Iteration 2 --
+int(8)
+
+-- Iteration 3 --
+bool(false)
+
+-- Iteration 4 --
+bool(false)
+
+-- Iteration 5 --
+bool(false)
+
+-- Iteration 6 --
+bool(false)
+
+-- Iteration 7 --
+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 --
+
+Notice: Object of class classA could not be converted to int in %s on line %d
+int(8)
+
+-- Iteration 17 --
+int(8)
+
+-- Iteration 18 --
+int(8)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strrpos_variation4.phpt b/ext/mbstring/tests/mb_strrpos_variation4.phpt
new file mode 100644 (file)
index 0000000..e3d3d43
--- /dev/null
@@ -0,0 +1,222 @@
+--TEST--
+Test mb_strrpos() function : usage variations - pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
+ * Description: Find position of last occurrence of a string within another 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass mb_strrpos() different data types as $encoding argument to test behaviour
+ * Where possible 'UTF-8' has been entered as a string value
+ */
+
+echo "*** Testing mb_strrpos() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$haystack = 'hello, world';
+$needle = 'world';
+$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 $encoding 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_strrpos()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strrpos($haystack, $needle, $offset, $input));
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strrpos() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_strrpos(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_strrpos(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_strrpos(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_strrpos(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_strrpos(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_strrpos(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_strrpos(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_strrpos(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_strrpos(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: mb_strrpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_strrpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: mb_strrpos(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_strrpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: mb_strrpos(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_strrpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_strrpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_strrpos(): 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_strrpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_strrpos(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_strrpos() expects parameter 4 to be string, resource given in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strrpos_variation5.phpt b/ext/mbstring/tests/mb_strrpos_variation5.phpt
new file mode 100644 (file)
index 0000000..8fdd40d
--- /dev/null
@@ -0,0 +1,61 @@
+--TEST--
+Test mb_strrpos() function : usage variations - pass encoding as third argument (deprecated behaviour)
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
+ * Description: Find position of last occurrence of a string within another 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Testing deprecated behaviour where third argument can be $encoding
+ */
+
+echo "*** Testing mb_strrpos() : usage variations ***\n";
+
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+$needle_mb = base64_decode('44CC');
+
+$stringh = <<<END
+utf-8
+END;
+
+$inputs = array('Double Quoted String' => "utf-8",
+                'Single Quoted String' => 'utf-8',
+                'Heredoc' => $stringh);
+foreach ($inputs as $type => $input) {
+       echo "\n-- $type --\n";
+       echo "-- With fourth encoding argument --\n";
+       var_dump(mb_strrpos($string_mb, $needle_mb, $input, 'utf-8'));
+       echo "-- Without fourth encoding argument --\n";
+       var_dump(mb_strrpos($string_mb, $needle_mb, $input));
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strrpos() : usage variations ***
+
+-- Double Quoted String --
+-- With fourth encoding argument --
+int(20)
+-- Without fourth encoding argument --
+int(20)
+
+-- Single Quoted String --
+-- With fourth encoding argument --
+int(20)
+-- Without fourth encoding argument --
+int(20)
+
+-- Heredoc --
+-- With fourth encoding argument --
+int(20)
+-- Without fourth encoding argument --
+int(20)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtolower_basic.phpt b/ext/mbstring/tests/mb_strtolower_basic.phpt
new file mode 100644 (file)
index 0000000..b1d31e2
--- /dev/null
@@ -0,0 +1,58 @@
+--TEST--
+Test mb_strtolower() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtolower') or die("skip mb_strtolower() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtolower(string $sourcestring [, string $encoding])
+ * Description: Returns a lowercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test basic functionality of mb_strtolower
+ */
+
+echo "*** Testing mb_strtolower() : basic functionality***\n";
+
+$ascii_lower = 'abcdefghijklmnopqrstuvwxyz';
+$ascii_upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+$greek_lower = base64_decode('zrHOss6zzrTOtc62zrfOuM65zrrOu868zr3Ovs6/z4DPgc+Dz4TPhc+Gz4fPiM+J');
+$greek_upper = base64_decode('zpHOks6TzpTOlc6WzpfOmM6ZzprOm86czp3Ons6fzqDOoc6jzqTOpc6mzqfOqM6p');
+
+echo "\n-- ASCII String --\n";
+$ascii = mb_strtolower($ascii_upper);
+var_dump($ascii);
+
+if($ascii == $ascii_lower) {
+       echo "Correctly converted\n";
+} else {
+       echo "Incorrectly converted\n";
+}
+
+echo "\n-- Multibyte String --\n";
+$mb = mb_strtolower($greek_upper, 'UTF-8');
+var_dump(base64_encode($mb));
+
+if ($mb == $greek_lower) {
+       echo "Correctly converted\n";
+} else {
+       echo "Incorreclty converted\n";
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strtolower() : basic functionality***
+
+-- ASCII String --
+string(26) "abcdefghijklmnopqrstuvwxyz"
+Correctly converted
+
+-- Multibyte String --
+string(64) "zrHOss6zzrTOtc62zrfOuM65zrrOu868zr3Ovs6/z4DPgc+Dz4TPhc+Gz4fPiM+J"
+Correctly converted
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtolower_error1.phpt b/ext/mbstring/tests/mb_strtolower_error1.phpt
new file mode 100644 (file)
index 0000000..13cdd3c
--- /dev/null
@@ -0,0 +1,46 @@
+--TEST--
+Test mb_strtolower() function : error conditions - pass incorrect number of arguments
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtolower') or die("skip mb_strtolower() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtolower(string $sourcestring [, string $encoding])
+ * Description: Returns a lowercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to mb_strtolower() to test behaviour
+ */
+
+echo "*** Testing mb_strtolower() : error conditions***\n";
+
+//Test mb_strtolower with one more than the expected number of arguments
+echo "\n-- Testing mb_strtolower() function with more than expected no. of arguments --\n";
+$sourcestring = 'string_value';
+$encoding = 'UTF-8';
+$extra_arg = 10;
+var_dump( mb_strtolower($sourcestring, $encoding, $extra_arg) );
+
+//Test mb_strtolower with zero arguments
+echo "\n-- Testing mb_strtolower() function with zero arguments --\n";
+var_dump( mb_strtolower() );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strtolower() : error conditions***
+
+-- Testing mb_strtolower() function with more than expected no. of arguments --
+
+Warning: mb_strtolower() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+
+-- Testing mb_strtolower() function with zero arguments --
+
+Warning: mb_strtolower() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtolower_error2.phpt b/ext/mbstring/tests/mb_strtolower_error2.phpt
new file mode 100644 (file)
index 0000000..d048fef
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Test mb_strtolower() function : error conditions - pass an unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtolower') or die("skip mb_strtolower() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtolower(string $sourcestring [, string $encoding])
+ * Description: Returns a lowercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass an unknown encoding to mb_strtolower() to test behaviour
+ */
+
+echo "*** Testing mb_strtolower() : error conditions***\n";
+
+$sourcestring = 'hello, world';
+$encoding = 'unknown-encoding';
+
+var_dump( mb_strtolower($sourcestring, $encoding) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strtolower() : error conditions***
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "unknown-encoding" in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtolower_variation1.phpt b/ext/mbstring/tests/mb_strtolower_variation1.phpt
new file mode 100644 (file)
index 0000000..ac468ca
--- /dev/null
@@ -0,0 +1,180 @@
+--TEST--
+Test mb_strtolower() function : usage variations - pass different data types as $sourcestring arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtolower') or die("skip mb_strtolower() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtolower(string $sourcestring [, string $encoding])
+ * Description: Returns a lowercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types to $sourcestring argument to test behaviour of mb_strtolower()
+ */
+
+echo "*** Testing mb_strtolower() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$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 $sourcestring 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_strtolower()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strtolower($input, $encoding) );
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strtolower() : usage variations ***
+
+-- Iteration 1 --
+string(1) "0"
+
+-- Iteration 2 --
+string(1) "1"
+
+-- Iteration 3 --
+string(5) "12345"
+
+-- Iteration 4 --
+string(5) "-2345"
+
+-- Iteration 5 --
+string(4) "10.5"
+
+-- Iteration 6 --
+string(5) "-10.5"
+
+-- Iteration 7 --
+string(12) "123456789000"
+
+-- Iteration 8 --
+string(13) "1.23456789e-9"
+
+-- Iteration 9 --
+string(3) "0.5"
+
+-- Iteration 10 --
+string(0) ""
+
+-- Iteration 11 --
+string(0) ""
+
+-- Iteration 12 --
+string(1) "1"
+
+-- Iteration 13 --
+string(0) ""
+
+-- Iteration 14 --
+string(1) "1"
+
+-- Iteration 15 --
+string(0) ""
+
+-- Iteration 16 --
+string(0) ""
+
+-- Iteration 17 --
+string(0) ""
+
+-- Iteration 18 --
+string(6) "string"
+
+-- Iteration 19 --
+string(6) "string"
+
+-- Iteration 20 --
+string(11) "hello world"
+
+-- Iteration 21 --
+string(14) "class a object"
+
+-- Iteration 22 --
+string(0) ""
+
+-- Iteration 23 --
+string(0) ""
+
+-- Iteration 24 --
+
+Warning: mb_strtolower() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtolower_variation2.phpt b/ext/mbstring/tests/mb_strtolower_variation2.phpt
new file mode 100644 (file)
index 0000000..d9eee44
--- /dev/null
@@ -0,0 +1,233 @@
+--TEST--
+Test mb_strtolower() function : usage variations - pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtolower') or die("skip mb_strtolower() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtolower(string $sourcestring [, string $encoding])
+ * Description: Returns a lowercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types to $encoding argument to test behaviour of mb_strtolower()
+ * Where possible, 'UTF-8' has been entered as a string value
+ */
+
+echo "*** Testing mb_strtolower() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$sourcestring = 'Hello, World';
+
+//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 $encoding 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_strtolower()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strtolower($sourcestring, $input) );
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_strtolower() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+string(12) "hello, world"
+
+-- Iteration 11 --
+string(12) "hello, world"
+
+-- Iteration 12 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+string(12) "hello, world"
+
+-- Iteration 14 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtolower(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+string(12) "hello, world"
+
+-- Iteration 16 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+string(12) "hello, world"
+
+-- Iteration 17 --
+
+Warning: mb_strtolower(): Illegal character encoding specified in %s on line %d
+string(12) "hello, world"
+
+-- Iteration 18 --
+string(12) "hello, world"
+
+-- Iteration 19 --
+string(12) "hello, world"
+
+-- Iteration 20 --
+string(12) "hello, world"
+
+-- Iteration 21 --
+string(12) "hello, world"
+
+-- Iteration 22 --
+string(12) "hello, world"
+
+-- Iteration 23 --
+string(12) "hello, world"
+
+-- Iteration 24 --
+
+Warning: mb_strtolower() expects parameter 2 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtolower_variation3.phpt b/ext/mbstring/tests/mb_strtolower_variation3.phpt
new file mode 100644 (file)
index 0000000..7ff3cee
--- /dev/null
@@ -0,0 +1,57 @@
+--TEST--
+Test mb_strtolower() function : usage variations - pass mixed ASCII and non-ASCII strings
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtolower') or die("skip mb_strtolower() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtolower(string $sourcestring [, string $encoding])
+ * Description: Returns a lowercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass a Japanese string and a mixed Japanese and ASCII string to mb_strtolower
+ * to check correct conversion is occuring (Japanese characters should not be converted).
+ */
+
+echo "*** Testing mb_strtolower() : usage variations ***\n";
+
+$string_mixed = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCUEhQLiAwMTIzNO+8le+8lu+8l++8mO+8meOAgg==');
+$string_mixed_lower = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCcGhwLiAwMTIzNO+8le+8lu+8l++8mO+8meOAgg==');
+$string_all_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC');
+
+echo "\n-- Mixed string (mulitbyte and ASCII characters) --\n";
+$a = mb_strtolower($string_mixed, 'UTF-8');
+var_dump(base64_encode($a));
+if ($a == $string_mixed_lower) {
+       echo "Correctly Converted\n";
+} else {
+       echo "Incorrectly Converted\n";
+}
+
+echo "\n-- Multibyte Only String--\n";
+$b = mb_strtolower($string_all_mb, 'UTF-8');
+var_dump(base64_encode($b));
+if ($b == $string_all_mb) { // Japanese characters only - should not be any conversion
+       echo "Correctly Converted\n";
+} else {
+       echo "Incorrectly Converted\n";
+}
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtolower() : usage variations ***
+
+-- Mixed string (mulitbyte and ASCII characters) --
+string(80) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCcGhwLiAwMTIzNO+8le+8lu+8l++8mO+8meOAgg=="
+Correctly Converted
+
+-- Multibyte Only String--
+string(40) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC"
+Correctly Converted
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtolower_variation4.phpt b/ext/mbstring/tests/mb_strtolower_variation4.phpt
new file mode 100644 (file)
index 0000000..f08b508
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--
+Test mb_strtolower() function : usage variations - pass different characters to check conversion is correct
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtolower') or die("skip mb_strtolower() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtolower(string $sourcestring [, string $encoding])
+ * Description: Returns a lowercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass accented characters and Russian characters to check case conversion is correct
+ */
+
+echo "*** Testing mb_strtolower() :  usage variations ***\n";
+
+$uppers = array('Basic Latin' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
+                'Characters With Accents' => base64_decode('w4DDgcOCw4PDhMOFw4bDh8OIw4nDisOLw4zDjcOOw4/DkMORw5LDk8OUw5XDlg=='),
+                'Russian' => base64_decode('0JDQkdCS0JPQlNCV0JbQlw=='));
+$lowers = array('Basic Latin' => 'abcdefghijklmnopqrstuvwxyz',
+                'Characters With Accents' => base64_decode('w6DDocOiw6PDpMOlw6bDp8Oow6nDqsOrw6zDrcOuw6/DsMOxw7LDs8O0w7XDtg=='),
+                'Russian' => base64_decode('0LDQsdCy0LPQtNC10LbQtw=='));
+
+foreach ($uppers as $lang => $sourcestring) {
+       echo "\n-- $lang --\n";
+       $a = mb_strtolower($sourcestring, 'utf-8');
+       var_dump(base64_encode($a));
+       if ($a == $lowers[$lang]) {
+               echo "Correctly Converted\n";
+       } else {
+               echo "Incorrectly Converted\n";
+       }
+}
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtolower() :  usage variations ***
+
+-- Basic Latin --
+string(36) "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo="
+Correctly Converted
+
+-- Characters With Accents --
+string(64) "w6DDocOiw6PDpMOlw6bDp8Oow6nDqsOrw6zDrcOuw6/DsMOxw7LDs8O0w7XDtg=="
+Correctly Converted
+
+-- Russian --
+string(24) "0LDQsdCy0LPQtNC10LbQtw=="
+Correctly Converted
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtoupper_basic.phpt b/ext/mbstring/tests/mb_strtoupper_basic.phpt
new file mode 100644 (file)
index 0000000..b282647
--- /dev/null
@@ -0,0 +1,60 @@
+--TEST--
+Test mb_strtoupper() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
+ * Description: Returns a uppercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test basic functionality of mb_strtoupper
+ */
+
+echo "*** Testing mb_strtoupper() : basic functionality ***\n";
+
+mb_internal_encoding('utf-8');
+$ascii_lower = 'abcdefghijklmnopqrstuvwxyz';
+$ascii_upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+$greek_lower = base64_decode('zrHOss6zzrTOtc62zrfOuM65zrrOu868zr3Ovs6/z4DPgc+Dz4TPhc+Gz4fPiM+J');
+$greek_upper = base64_decode('zpHOks6TzpTOlc6WzpfOmM6ZzprOm86czp3Ons6fzqDOoc6jzqTOpc6mzqfOqM6p');
+
+echo "\n-- ASCII String --\n";
+$ascii = mb_strtoupper($ascii_lower);
+var_dump($ascii);
+
+if($ascii == $ascii_upper) {
+       echo "Correctly converted\n";
+} else {
+       echo "Incorrectly converted\n";
+}
+
+echo "\n-- Multibyte String --\n";
+$mb = mb_strtoupper($greek_lower, 'UTF-8');
+var_dump(base64_encode($mb));
+
+if ($mb == $greek_upper) {
+       echo "Correctly converted\n";
+} else {
+       echo "Incorreclty converted\n";
+}
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtoupper() : basic functionality ***
+
+-- ASCII String --
+string(26) "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+Correctly converted
+
+-- Multibyte String --
+string(64) "zpHOks6TzpTOlc6WzpfOmM6ZzprOm86czp3Ons6fzqDOoc6jzqTOpc6mzqfOqM6p"
+Correctly converted
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtoupper_error1.phpt b/ext/mbstring/tests/mb_strtoupper_error1.phpt
new file mode 100644 (file)
index 0000000..d61c389
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+Test mb_strtoupper() function : error conditions - pass incorrect number of args
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
+ * Description: Returns a uppercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to mb_strtoupper() to test behaviour
+ */
+
+echo "*** Testing mb_strtoupper() : error conditions ***\n";
+
+//Test mb_strtoupper with one more than the expected number of arguments
+echo "\n-- Testing mb_strtoupper() function with more than expected no. of arguments --\n";
+$sourcestring = 'string_value';
+$encoding = 'UTF-8';
+$extra_arg = 10;
+var_dump( mb_strtoupper($sourcestring, $encoding, $extra_arg) );
+
+//Test mb_strtoupper with zero arguments
+echo "\n-- Testing mb_strtoupper() function with zero arguments --\n";
+var_dump( mb_strtoupper() );
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtoupper() : error conditions ***
+
+-- Testing mb_strtoupper() function with more than expected no. of arguments --
+
+Warning: mb_strtoupper() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+
+-- Testing mb_strtoupper() function with zero arguments --
+
+Warning: mb_strtoupper() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtoupper_error2.phpt b/ext/mbstring/tests/mb_strtoupper_error2.phpt
new file mode 100644 (file)
index 0000000..69e4ecd
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Test mb_strtoupper() function : error conditions - pass an unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
+ * Description: Returns a uppercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass an unknown encoding as $encoding argument to check behaviour of mbstrtoupper()
+ */
+
+echo "*** Testing mb_strtoupper() : error conditions ***\n";
+
+$sourcestring = 'hello, world';
+$encoding = 'unknown-encoding';
+
+var_dump( mb_strtoupper($sourcestring, $encoding) );
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtoupper() : error conditions ***
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "unknown-encoding" in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtoupper_variation1.phpt b/ext/mbstring/tests/mb_strtoupper_variation1.phpt
new file mode 100644 (file)
index 0000000..b602f69
--- /dev/null
@@ -0,0 +1,182 @@
+--TEST--
+Test mb_strtoupper() function : usage varitations - pass different data types as $sourcestring arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
+ * Description: Returns a uppercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * 
+ * Pass different data types as $sourcestring argument to mb_strtoupper to test behaviour
+ */
+
+echo "*** Testing mb_strtoupper() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$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 $sourcestring 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_strtoupper()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strtoupper($input, $encoding) );
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtoupper() : usage variations ***
+
+-- Iteration 1 --
+string(1) "0"
+
+-- Iteration 2 --
+string(1) "1"
+
+-- Iteration 3 --
+string(5) "12345"
+
+-- Iteration 4 --
+string(5) "-2345"
+
+-- Iteration 5 --
+string(4) "10.5"
+
+-- Iteration 6 --
+string(5) "-10.5"
+
+-- Iteration 7 --
+string(12) "123456789000"
+
+-- Iteration 8 --
+string(13) "1.23456789E-9"
+
+-- Iteration 9 --
+string(3) "0.5"
+
+-- Iteration 10 --
+string(0) ""
+
+-- Iteration 11 --
+string(0) ""
+
+-- Iteration 12 --
+string(1) "1"
+
+-- Iteration 13 --
+string(0) ""
+
+-- Iteration 14 --
+string(1) "1"
+
+-- Iteration 15 --
+string(0) ""
+
+-- Iteration 16 --
+string(0) ""
+
+-- Iteration 17 --
+string(0) ""
+
+-- Iteration 18 --
+string(6) "STRING"
+
+-- Iteration 19 --
+string(6) "STRING"
+
+-- Iteration 20 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 21 --
+string(14) "CLASS A OBJECT"
+
+-- Iteration 22 --
+string(0) ""
+
+-- Iteration 23 --
+string(0) ""
+
+-- Iteration 24 --
+
+Warning: mb_strtoupper() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtoupper_variation2.phpt b/ext/mbstring/tests/mb_strtoupper_variation2.phpt
new file mode 100644 (file)
index 0000000..d28c995
--- /dev/null
@@ -0,0 +1,234 @@
+--TEST--
+Test mb_strtoupper() function : usage varitations - Pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
+ * Description: Returns a uppercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types as $encoding argument to mb_strtoupper() to test behaviour
+ * Where possible, 'UTF-8' is entered as string value
+ */
+
+echo "*** Testing mb_strtoupper() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$sourcestring = 'Hello, World';
+
+//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 $encoding 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_strtoupper()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_strtoupper($sourcestring, $input) );
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtoupper() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 11 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 12 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+string(12) "HELLO, WORLD"
+
+-- Iteration 14 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+
+Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+string(12) "HELLO, WORLD"
+
+-- Iteration 16 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+string(12) "HELLO, WORLD"
+
+-- Iteration 17 --
+
+Warning: mb_strtoupper(): Illegal character encoding specified in %s on line %d
+string(12) "HELLO, WORLD"
+
+-- Iteration 18 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 19 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 20 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 21 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 22 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 23 --
+string(12) "HELLO, WORLD"
+
+-- Iteration 24 --
+
+Warning: mb_strtoupper() expects parameter 2 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtoupper_variation3.phpt b/ext/mbstring/tests/mb_strtoupper_variation3.phpt
new file mode 100644 (file)
index 0000000..9b29569
--- /dev/null
@@ -0,0 +1,58 @@
+--TEST--
+Test mb_strtoupper() function : usage varitations - pass mixed ASCII and non-ASCII strings
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
+ * Description: Returns a uppercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass a Japanese string and a mixed Japanese and ASCII string to mb_strtolower
+ * to check correct conversion is occuring (Japanese characters should not be converted).
+ */
+
+echo "*** Testing mb_strtoupper() : usage variations ***\n";
+
+$string_mixed_upper = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCUEhQLiAwMTIzNO+8le+8lu+8l++8mO+8meOAgg==');
+$string_mixed_lower = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCcGhwLiAwMTIzNO+8le+8lu+8l++8mO+8meOAgg==');
+$string_all_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC');
+
+
+echo "\n-- Mixed string (mulitbyte and ASCII characters) --\n";
+$a = mb_strtoupper($string_mixed_lower, 'UTF-8');
+var_dump(base64_encode($a));
+if ($a == $string_mixed_upper) {
+       echo "Correctly Converted\n";
+} else {
+       echo "Incorrectly Converted\n";
+}
+
+echo "\n-- Multibyte Only String--\n";
+$b = mb_strtoupper($string_all_mb, 'UTF-8');
+var_dump(base64_encode($b));
+if ($b == $string_all_mb) { // Japanese characters only - should not be any conversion
+       echo "Correctly Converted\n";
+} else {
+       echo "Incorrectly Converted\n";
+}
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtoupper() : usage variations ***
+
+-- Mixed string (mulitbyte and ASCII characters) --
+string(80) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCUEhQLiAwMTIzNO+8le+8lu+8l++8mO+8meOAgg=="
+Correctly Converted
+
+-- Multibyte Only String--
+string(40) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC"
+Correctly Converted
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_strtoupper_variation4.phpt b/ext/mbstring/tests/mb_strtoupper_variation4.phpt
new file mode 100644 (file)
index 0000000..8f5abe7
--- /dev/null
@@ -0,0 +1,57 @@
+--TEST--
+Test mb_strtoupper() function : usage varitations - Pass different character types to check conversion is correct
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
+ * Description: Returns a uppercased version of $sourcestring
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass characters from different languages to check that mb_strtoupper is
+ * doing a correct case conversion
+ */
+
+echo "*** Testing mb_strtoupper() : usage variations ***\n";
+
+$uppers = array('Basic Latin' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
+                'Characters With Accents' => base64_decode('w4DDgcOCw4PDhMOFw4bDh8OIw4nDisOLw4zDjcOOw4/DkMORw5LDk8OUw5XDlg=='),
+                'Russian' => base64_decode('0JDQkdCS0JPQlNCV0JbQlw=='));
+$lowers = array('Basic Latin' => 'abcdefghijklmnopqrstuvwxyz',
+                'Characters With Accents' => base64_decode('w6DDocOiw6PDpMOlw6bDp8Oow6nDqsOrw6zDrcOuw6/DsMOxw7LDs8O0w7XDtg=='),
+                'Russian' => base64_decode('0LDQsdCy0LPQtNC10LbQtw=='));
+
+foreach ($lowers as $lang => $sourcestring) {
+       echo "\n-- $lang --\n";
+       $a = mb_strtoupper($sourcestring, 'UTF-8');
+       var_dump(base64_encode($a));
+       if ($a == $uppers[$lang]) {
+               echo "Correctly Converted\n";
+       } else {
+               echo "Incorrectly Converted\n";
+       }
+}
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_strtoupper() : usage variations ***
+
+-- Basic Latin --
+string(36) "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo="
+Correctly Converted
+
+-- Characters With Accents --
+string(64) "w4DDgcOCw4PDhMOFw4bDh8OIw4nDisOLw4zDjcOOw4/DkMORw5LDk8OUw5XDlg=="
+Correctly Converted
+
+-- Russian --
+string(24) "0JDQkdCS0JPQlNCV0JbQlw=="
+Correctly Converted
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_basic.phpt b/ext/mbstring/tests/mb_substr_basic.phpt
new file mode 100644 (file)
index 0000000..a43cf15
--- /dev/null
@@ -0,0 +1,55 @@
+--TEST--
+Test mb_substr() function : basic functionality 
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
+ * Description: Returns part of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test Basic Functionality of mb_substr with ASCII characters and multibyte strings.
+ */
+
+echo "*** Testing mb_substr() : basic functionality ***\n";
+
+$string_ascii = 'ABCDEF';
+//Japanese string in UTF-8
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+echo "\n-- ASCII string 1 --\n";
+var_dump(mb_substr($string_ascii, 3));
+
+echo "\n-- ASCII string 2 --\n";
+var_dump(mb_substr($string_ascii, 3, 5, 'ISO-8859-1'));
+
+echo "\n-- Multibyte string 1 --\n";
+$result_1 = mb_substr($string_mb, 2, 7);
+var_dump(base64_encode($result_1));
+
+echo "\n-- Multibyte string 2 --\n";
+$result_2 = mb_substr($string_mb, 2, 7, 'utf-8');
+var_dump(base64_encode($result_2));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr() : basic functionality ***
+
+-- ASCII string 1 --
+string(3) "DEF"
+
+-- ASCII string 2 --
+string(3) "DEF"
+
+-- Multibyte string 1 --
+string(12) "peacrOiqng=="
+
+-- Multibyte string 2 --
+string(28) "6Kqe44OG44Kt44K544OI44Gn44GZ"
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_count_basic.phpt b/ext/mbstring/tests/mb_substr_count_basic.phpt
new file mode 100644 (file)
index 0000000..4b87567
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+Test mb_substr_count() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr_count') or die("skip mb_substr_count() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_substr_count(string $haystack, string $needle [, string $encoding])
+ * Description: Count the number of substring occurrences 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test Basic functionality of mb_substr_count
+ */
+
+echo "*** Testing mb_substr_count() : basic functionality ***\n";
+
+$string_ascii = 'This is an English string. 0123456789.';
+
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+$needle_mb1 = base64_decode('44CC');
+$needle_mb2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
+
+echo "\n-- ASCII String --\n";
+var_dump(mb_substr_count($string_ascii, 'is'));
+var_dump(mb_substr_count($string_ascii, 'hello, world'));
+
+echo "\n-- Multibyte String --\n";
+var_dump(mb_substr_count($string_mb, $needle_mb1));
+var_dump(mb_substr_count($string_mb, $needle_mb2));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr_count() : basic functionality ***
+
+-- ASCII String --
+int(3)
+int(0)
+
+-- Multibyte String --
+int(2)
+int(0)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_count_error1.phpt b/ext/mbstring/tests/mb_substr_count_error1.phpt
new file mode 100644 (file)
index 0000000..8ddcaa6
--- /dev/null
@@ -0,0 +1,49 @@
+--TEST--
+Test mb_substr_count() function : error conditions - pass incorrect number of arguments
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr_count') or die("skip mb_substr_count() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_substr_count(string $haystack, string $needle [, string $encoding])
+ * Description: Count the number of substring occurrences 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to mb_substr_count() to test behaviour
+ */
+
+echo "*** Testing mb_substr_count() : error conditions ***\n";
+
+
+//Test mb_substr_count with one more than the expected number of arguments
+echo "\n-- Testing mb_substr_count() function with more than expected no. of arguments --\n";
+$haystack = 'string_val';
+$needle = 'val';
+$encoding = 'utf-8';
+$extra_arg = 10;
+var_dump( mb_substr_count($haystack, $needle, $encoding, $extra_arg) );
+
+// Testing mb_substr_count with one less than the expected number of arguments
+echo "\n-- Testing mb_substr_count() function with less than expected no. of arguments --\n";
+$haystack = 'string_val';
+var_dump( mb_substr_count($haystack) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr_count() : error conditions ***
+
+-- Testing mb_substr_count() function with more than expected no. of arguments --
+
+Warning: mb_substr_count() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+-- Testing mb_substr_count() function with less than expected no. of arguments --
+
+Warning: mb_substr_count() expects at least 2 parameters, 1 given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_count_error2.phpt b/ext/mbstring/tests/mb_substr_count_error2.phpt
new file mode 100644 (file)
index 0000000..e2572b0
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+Test mb_substr_count() function : error conditions - pass unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr_count') or die("skip mb_substr_count() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_substr_count(string $haystack, string $needle [, string $encoding])
+ * Description: Count the number of substring occurrences 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test behaviour of mb_substr_count() function when passed an unknown encoding
+ */
+
+echo "*** Testing mb_substr_count() : error conditions ***\n";
+
+$haystack = 'Hello, World!';
+$needle = 'Hello';
+$encoding = 'unknown-encoding';
+
+echo "\n-- Testing mb_substr_count() function with an unknown encoding --\n";
+var_dump(mb_substr_count($haystack, $needle, $encoding));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr_count() : error conditions ***
+
+-- Testing mb_substr_count() function with an unknown encoding --
+
+Warning: mb_substr_count(): Unknown encoding "unknown-encoding" in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_count_variation1.phpt b/ext/mbstring/tests/mb_substr_count_variation1.phpt
new file mode 100644 (file)
index 0000000..8121b48
--- /dev/null
@@ -0,0 +1,183 @@
+--TEST--
+Test mb_substr_count() function : usage variations - Pass different data types as $haystack arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr_count') or die("skip mb_substr_count() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  :int mb_substr_count(string $haystack, string $needle [, string $encoding])
+ * Description: Count the number of substring occurrences 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types as $haystack argument to mb_substr_count() to test behaviour
+ */
+
+echo "*** Testing mb_substr_count() : usage variations ***\n";
+
+
+// Initialise function arguments not being substituted
+$needle = 'world';
+$encoding = 'utf-8';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+  public function __toString() {
+    return "hello, world";
+  }
+}
+
+// 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*/ "hello, world",
+       'hello, world',
+       $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_substr_count()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_substr_count($input, $needle, $encoding) );
+  $iterator++;
+};
+
+fclose($fp);
+
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr_count() : usage variations ***
+
+-- Iteration 1 --
+int(0)
+
+-- Iteration 2 --
+int(0)
+
+-- Iteration 3 --
+int(0)
+
+-- Iteration 4 --
+int(0)
+
+-- Iteration 5 --
+int(0)
+
+-- Iteration 6 --
+int(0)
+
+-- Iteration 7 --
+int(0)
+
+-- Iteration 8 --
+int(0)
+
+-- Iteration 9 --
+int(0)
+
+-- Iteration 10 --
+int(0)
+
+-- Iteration 11 --
+int(0)
+
+-- Iteration 12 --
+int(0)
+
+-- Iteration 13 --
+int(0)
+
+-- Iteration 14 --
+int(0)
+
+-- Iteration 15 --
+int(0)
+
+-- Iteration 16 --
+int(0)
+
+-- Iteration 17 --
+int(0)
+
+-- Iteration 18 --
+int(1)
+
+-- Iteration 19 --
+int(1)
+
+-- Iteration 20 --
+int(1)
+
+-- Iteration 21 --
+int(1)
+
+-- Iteration 22 --
+int(0)
+
+-- Iteration 23 --
+int(0)
+
+-- Iteration 24 --
+
+Warning: mb_substr_count() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+Done
diff --git a/ext/mbstring/tests/mb_substr_count_variation2.phpt b/ext/mbstring/tests/mb_substr_count_variation2.phpt
new file mode 100644 (file)
index 0000000..dac48b5
--- /dev/null
@@ -0,0 +1,197 @@
+--TEST--
+Test mb_substr_count() function : usage variations - pass different data types as $needle arg 
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr_count') or die("skip mb_substr_count() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_substr_count(string $haystack, string $needle [, string $encoding])
+ * Description: Count the number of substring occurrences 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types as $needle to mb_substr_count() to test behaviour
+ */
+
+echo "*** Testing mb_substr_count() : usage variations ***\n";
+
+// Initialise function arguments not being substituted (if any)
+$haystack = 'hello, world';
+$encoding = 'utf-8';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+  public function __toString() {
+    return "world";
+  }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+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*/ "world",
+       'world',
+       $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_substr_count()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_substr_count($haystack, $input, $encoding) );
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr_count() : usage variations ***
+
+-- Iteration 1 --
+int(0)
+
+-- Iteration 2 --
+int(0)
+
+-- Iteration 3 --
+int(0)
+
+-- Iteration 4 --
+int(0)
+
+-- Iteration 5 --
+int(0)
+
+-- Iteration 6 --
+int(0)
+
+-- Iteration 7 --
+int(0)
+
+-- Iteration 8 --
+int(0)
+
+-- Iteration 9 --
+int(0)
+
+-- Iteration 10 --
+
+Warning: mb_substr_count(): Empty substring. in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_substr_count(): Empty substring. in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+int(0)
+
+-- Iteration 13 --
+
+Warning: mb_substr_count(): Empty substring. in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+int(0)
+
+-- Iteration 15 --
+
+Warning: mb_substr_count(): Empty substring. in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_substr_count(): Empty substring. in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_substr_count(): Empty substring. in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+int(1)
+
+-- Iteration 19 --
+int(1)
+
+-- Iteration 20 --
+int(1)
+
+-- Iteration 21 --
+int(1)
+
+-- Iteration 22 --
+
+Warning: mb_substr_count(): Empty substring. in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_substr_count(): Empty substring. in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_substr_count() expects parameter 2 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_count_variation3.phpt b/ext/mbstring/tests/mb_substr_count_variation3.phpt
new file mode 100644 (file)
index 0000000..d2e7a60
--- /dev/null
@@ -0,0 +1,220 @@
+--TEST--
+Test mb_substr_count() function :usage variations - pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr_count') or die("skip mb_substr_count() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : int mb_substr_count(string $haystack, string $needle [, string $encoding])
+ * Description: Count the number of substring occurrences 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types as $encoding argument to mb_substr_count() to test behaviour
+ * Where possible, 'UTF-8' is entered as string value
+ */
+
+echo "*** Testing mb_substr_count() : usage variations ***\n";
+
+// Initialise function arguments not being substituted (if any)
+$haystack = 'hello, world';
+$needle = 'world';
+
+//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 $encoding 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_substr_count()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_substr_count($haystack, $needle, $input) );
+  $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr_count() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_substr_count(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_substr_count(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_substr_count(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_substr_count(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_substr_count(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_substr_count(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_substr_count(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_substr_count(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_substr_count(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: mb_substr_count(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_substr_count(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: mb_substr_count(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_substr_count(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: mb_substr_count(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_substr_count(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_substr_count(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_substr_count(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+int(1)
+
+-- Iteration 19 --
+int(1)
+
+-- Iteration 20 --
+int(1)
+
+-- Iteration 21 --
+int(1)
+
+-- Iteration 22 --
+
+Warning: mb_substr_count(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_substr_count(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_substr_count() expects parameter 3 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_error1.phpt b/ext/mbstring/tests/mb_substr_error1.phpt
new file mode 100644 (file)
index 0000000..c2007c9
--- /dev/null
@@ -0,0 +1,49 @@
+--TEST--
+Test mb_substr() function : error conditions - Pass incorrect number of args
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
+ * Description: Returns part of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass incorrect number of arguments to mb_substr() to test behaviour
+ */
+
+echo "*** Testing mb_substr() : error conditions ***\n";
+
+//Test mb_substr with one more than the expected number of arguments
+echo "\n-- Testing mb_substr() function with more than expected no. of arguments --\n";
+$str = 'string_val';
+$start = 10;
+$length = 10;
+$encoding = 'string_val';
+$extra_arg = 10;
+var_dump( mb_substr($str, $start, $length, $encoding, $extra_arg) );
+
+// Testing mb_substr with one less than the expected number of arguments
+echo "\n-- Testing mb_substr() function with less than expected no. of arguments --\n";
+$str = 'string_val';
+var_dump( mb_substr($str) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr() : error conditions ***
+
+-- Testing mb_substr() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for mb_substr() in %s on line %d
+NULL
+
+-- Testing mb_substr() function with less than expected no. of arguments --
+
+Warning: Wrong parameter count for mb_substr() in %s on line %d
+NULL
+Done
diff --git a/ext/mbstring/tests/mb_substr_error2.phpt b/ext/mbstring/tests/mb_substr_error2.phpt
new file mode 100644 (file)
index 0000000..72be974
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Test mb_substr() function : error conditions - Pass an unknown encoding
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
+ * Description: Returns part of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass an unknown encoding to mb_substr() to test behaviour
+ */
+
+echo "*** Testing mb_substr() : error conditions ***\n";
+
+$str = 'Hello, world';
+$start = 1;
+$length = 5;
+$encoding = 'unknown-encoding';
+
+var_dump( mb_substr($str, $start, $length, $encoding));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr() : error conditions ***
+
+Warning: mb_substr(): Unknown encoding "unknown-encoding" in %s on line %d
+bool(false)
+Done
diff --git a/ext/mbstring/tests/mb_substr_variation1.phpt b/ext/mbstring/tests/mb_substr_variation1.phpt
new file mode 100644 (file)
index 0000000..fd9d0db
--- /dev/null
@@ -0,0 +1,179 @@
+--TEST--
+Test mb_substr() function : usage variations - pass unexpected arguments (including strings) in place of $str
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
+ * Description: Returns part of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types as $str to mb_substr() to test behaviour
+ */
+
+echo "*** Testing mb_substr() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$start = 0;
+$length = 5;
+$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 $str 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_substr()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_substr($input, $start, $length, $encoding));
+  $iterator++;
+};
+
+fclose($fp);
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr() : usage variations ***
+
+-- Iteration 1 --
+string(1) "0"
+
+-- Iteration 2 --
+string(1) "1"
+
+-- Iteration 3 --
+string(5) "12345"
+
+-- Iteration 4 --
+string(5) "-2345"
+
+-- Iteration 5 --
+string(4) "10.5"
+
+-- Iteration 6 --
+string(5) "-10.5"
+
+-- Iteration 7 --
+string(5) "12345"
+
+-- Iteration 8 --
+string(5) "1.234"
+
+-- Iteration 9 --
+string(3) "0.5"
+
+-- Iteration 10 --
+string(0) ""
+
+-- Iteration 11 --
+string(0) ""
+
+-- Iteration 12 --
+string(1) "1"
+
+-- Iteration 13 --
+string(0) ""
+
+-- Iteration 14 --
+string(1) "1"
+
+-- Iteration 15 --
+string(0) ""
+
+-- Iteration 16 --
+string(0) ""
+
+-- Iteration 17 --
+string(0) ""
+
+-- Iteration 18 --
+string(5) "strin"
+
+-- Iteration 19 --
+string(5) "strin"
+
+-- Iteration 20 --
+string(5) "hello"
+
+-- Iteration 21 --
+string(5) "Class"
+
+-- Iteration 22 --
+string(0) ""
+
+-- Iteration 23 --
+string(0) ""
+
+-- Iteration 24 --
+string(5) "Resou"
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_variation2.phpt b/ext/mbstring/tests/mb_substr_variation2.phpt
new file mode 100644 (file)
index 0000000..cb8a37a
--- /dev/null
@@ -0,0 +1,220 @@
+--TEST--
+Test mb_substr() function : usage variations - Pass different data types as $encoding arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
+ * Description: Returns part of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass different data types as $encoding argument to mb_substr() to test behaviour
+ * Where possible, 'UTF-8' is entered as string value
+ */
+
+echo "*** Testing mb_substr() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$str = 'string_val';
+$start = 1;
+$length = 5;
+
+//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_substr
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( mb_substr($str, $start, $length, $input));
+  $iterator++;
+};
+
+fclose($fp);
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: mb_substr(): Unknown encoding "0" in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: mb_substr(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: mb_substr(): Unknown encoding "12345" in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: mb_substr(): Unknown encoding "-2345" in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: mb_substr(): Unknown encoding "10.5" in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: mb_substr(): Unknown encoding "-10.5" in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: mb_substr(): Unknown encoding "123456789000" in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: mb_substr(): Unknown encoding "1.23456789E-9" in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: mb_substr(): Unknown encoding "0.5" in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: mb_substr(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: mb_substr(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: mb_substr(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: mb_substr(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: mb_substr(): Unknown encoding "1" in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: mb_substr(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: mb_substr(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: mb_substr(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+string(5) "tring"
+
+-- Iteration 19 --
+string(5) "tring"
+
+-- Iteration 20 --
+string(5) "tring"
+
+-- Iteration 21 --
+string(5) "tring"
+
+-- Iteration 22 --
+
+Warning: mb_substr(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: mb_substr(): Unknown encoding "" in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: mb_substr(): Unknown encoding "Resource id #%d" in %s on line %d
+bool(false)
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_variation3.phpt b/ext/mbstring/tests/mb_substr_variation3.phpt
new file mode 100644 (file)
index 0000000..bb930b4
--- /dev/null
@@ -0,0 +1,445 @@
+--TEST--
+Test mb_substr() function : usage variations - test different encodings
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
+ * Description: Returns part of a string
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Pass all encodings listed on php.net to test that function recognises them.
+ * NB: The strings passed are *NOT* necessarily encoded in the encoding passed to the function.
+ * This test is purely to see whether the function recognises the encoding.
+ */
+
+echo "*** Testing mb_substr() : usage variations ***\n";
+
+$encoding = array('UCS-4',                     /*1*/
+                  'UCS-4BE',
+                  'UCS-4LE',
+                  'UCS-2',
+                  'UCS-2BE',           /*5*/
+                  'UCS-2LE',
+                  'UTF-32',
+                  'UTF-32BE',
+                  'UTF-32LE',
+                  'UTF-16',                    /*10*/
+                  'UTF-16BE',
+                  'UTF-16LE',
+                  'UTF-7',
+                  'UTF7-IMAP',
+                  'UTF-8',                     /*15*/
+                  'ASCII',
+                  'EUC-JP',
+                  'SJIS',
+                  'eucJP-win',
+                  'SJIS-win',          /*20*/
+                  'ISO-2022-JP',
+                  'JIS',
+                  'ISO-8859-1',
+                  'ISO-8859-2',
+                  'ISO-8859-3',                /*25*/
+                  'ISO-8859-4',
+                  'ISO-8859-5',
+                  'ISO-8859-6',
+                  'ISO-8859-7',
+                  'ISO-8859-8',                /*30*/
+                  'ISO-8859-9',
+                  'ISO-8859-10',
+                  'ISO-8859-13',
+                  'ISO-8859-14',
+                  'ISO-8859-15',       /*35*/
+                  'byte2be',
+                  'byte2le',
+                  'byte4be',
+                  'byte4le',
+                  'BASE64',                    /*40*/
+                  'HTML-ENTITIES',
+                  '7bit',
+                  '8bit',
+                  'EUC-CN',
+                  'CP936',                     /*45*/
+                  'HZ',
+                  'EUC-TW',
+                  'CP950',
+                  'BIG-5',
+                  'EUC-KR',                    /*50*/
+                  'UHC',
+                  'ISO-2022-KR',
+                  'Windows-1251',
+                  'Windows-1252',
+                  'CP866',                     /*55*/
+                  'KOI8-R');           /*56*/
+
+
+
+$iterator = 1;
+$string_ascii = 'abc def';
+//Japanese string encoded in UTF-8
+$string_mb = base64_decode('44K/44OT44Ol44Os44O844OG44Kj44Oz44Kw44O744Oe44K344O844Oz44O744Kr44Oz44OR44OL44O8');
+
+foreach($encoding as $enc) {
+       echo "\n-- Iteration $iterator: $enc --\n";
+
+       echo "-- ASCII String --\n";
+       if (mb_substr($string_ascii, 1, 5, $enc)) {
+               echo "Encoding $enc recognised\n";
+       } else {
+               echo "Encoding $enc not recognised\n";
+       }
+
+       echo "-- Multibyte String --\n";
+       if (mb_substr($string_mb, 1, 5, $enc)) {
+               echo "Encoding $enc recognised\n";
+       } else {
+               echo "Encoding $enc not recognised\n";
+       }
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr() : usage variations ***
+
+-- Iteration 1: UCS-4 --
+-- ASCII String --
+Encoding UCS-4 recognised
+-- Multibyte String --
+Encoding UCS-4 recognised
+
+-- Iteration 1: UCS-4BE --
+-- ASCII String --
+Encoding UCS-4BE recognised
+-- Multibyte String --
+Encoding UCS-4BE recognised
+
+-- Iteration 1: UCS-4LE --
+-- ASCII String --
+Encoding UCS-4LE recognised
+-- Multibyte String --
+Encoding UCS-4LE recognised
+
+-- Iteration 1: UCS-2 --
+-- ASCII String --
+Encoding UCS-2 recognised
+-- Multibyte String --
+Encoding UCS-2 recognised
+
+-- Iteration 1: UCS-2BE --
+-- ASCII String --
+Encoding UCS-2BE recognised
+-- Multibyte String --
+Encoding UCS-2BE recognised
+
+-- Iteration 1: UCS-2LE --
+-- ASCII String --
+Encoding UCS-2LE recognised
+-- Multibyte String --
+Encoding UCS-2LE recognised
+
+-- Iteration 1: UTF-32 --
+-- ASCII String --
+Encoding UTF-32 recognised
+-- Multibyte String --
+Encoding UTF-32 recognised
+
+-- Iteration 1: UTF-32BE --
+-- ASCII String --
+Encoding UTF-32BE recognised
+-- Multibyte String --
+Encoding UTF-32BE recognised
+
+-- Iteration 1: UTF-32LE --
+-- ASCII String --
+Encoding UTF-32LE recognised
+-- Multibyte String --
+Encoding UTF-32LE recognised
+
+-- Iteration 1: UTF-16 --
+-- ASCII String --
+Encoding UTF-16 recognised
+-- Multibyte String --
+Encoding UTF-16 recognised
+
+-- Iteration 1: UTF-16BE --
+-- ASCII String --
+Encoding UTF-16BE recognised
+-- Multibyte String --
+Encoding UTF-16BE recognised
+
+-- Iteration 1: UTF-16LE --
+-- ASCII String --
+Encoding UTF-16LE recognised
+-- Multibyte String --
+Encoding UTF-16LE recognised
+
+-- Iteration 1: UTF-7 --
+-- ASCII String --
+Encoding UTF-7 recognised
+-- Multibyte String --
+Encoding UTF-7 recognised
+
+-- Iteration 1: UTF7-IMAP --
+-- ASCII String --
+Encoding UTF7-IMAP recognised
+-- Multibyte String --
+Encoding UTF7-IMAP recognised
+
+-- Iteration 1: UTF-8 --
+-- ASCII String --
+Encoding UTF-8 recognised
+-- Multibyte String --
+Encoding UTF-8 recognised
+
+-- Iteration 1: ASCII --
+-- ASCII String --
+Encoding ASCII recognised
+-- Multibyte String --
+Encoding ASCII recognised
+
+-- Iteration 1: EUC-JP --
+-- ASCII String --
+Encoding EUC-JP recognised
+-- Multibyte String --
+Encoding EUC-JP recognised
+
+-- Iteration 1: SJIS --
+-- ASCII String --
+Encoding SJIS recognised
+-- Multibyte String --
+Encoding SJIS recognised
+
+-- Iteration 1: eucJP-win --
+-- ASCII String --
+Encoding eucJP-win recognised
+-- Multibyte String --
+Encoding eucJP-win recognised
+
+-- Iteration 1: SJIS-win --
+-- ASCII String --
+Encoding SJIS-win recognised
+-- Multibyte String --
+Encoding SJIS-win recognised
+
+-- Iteration 1: ISO-2022-JP --
+-- ASCII String --
+Encoding ISO-2022-JP recognised
+-- Multibyte String --
+Encoding ISO-2022-JP recognised
+
+-- Iteration 1: JIS --
+-- ASCII String --
+Encoding JIS recognised
+-- Multibyte String --
+Encoding JIS recognised
+
+-- Iteration 1: ISO-8859-1 --
+-- ASCII String --
+Encoding ISO-8859-1 recognised
+-- Multibyte String --
+Encoding ISO-8859-1 recognised
+
+-- Iteration 1: ISO-8859-2 --
+-- ASCII String --
+Encoding ISO-8859-2 recognised
+-- Multibyte String --
+Encoding ISO-8859-2 recognised
+
+-- Iteration 1: ISO-8859-3 --
+-- ASCII String --
+Encoding ISO-8859-3 recognised
+-- Multibyte String --
+Encoding ISO-8859-3 recognised
+
+-- Iteration 1: ISO-8859-4 --
+-- ASCII String --
+Encoding ISO-8859-4 recognised
+-- Multibyte String --
+Encoding ISO-8859-4 recognised
+
+-- Iteration 1: ISO-8859-5 --
+-- ASCII String --
+Encoding ISO-8859-5 recognised
+-- Multibyte String --
+Encoding ISO-8859-5 recognised
+
+-- Iteration 1: ISO-8859-6 --
+-- ASCII String --
+Encoding ISO-8859-6 recognised
+-- Multibyte String --
+Encoding ISO-8859-6 recognised
+
+-- Iteration 1: ISO-8859-7 --
+-- ASCII String --
+Encoding ISO-8859-7 recognised
+-- Multibyte String --
+Encoding ISO-8859-7 recognised
+
+-- Iteration 1: ISO-8859-8 --
+-- ASCII String --
+Encoding ISO-8859-8 recognised
+-- Multibyte String --
+Encoding ISO-8859-8 recognised
+
+-- Iteration 1: ISO-8859-9 --
+-- ASCII String --
+Encoding ISO-8859-9 recognised
+-- Multibyte String --
+Encoding ISO-8859-9 recognised
+
+-- Iteration 1: ISO-8859-10 --
+-- ASCII String --
+Encoding ISO-8859-10 recognised
+-- Multibyte String --
+Encoding ISO-8859-10 recognised
+
+-- Iteration 1: ISO-8859-13 --
+-- ASCII String --
+Encoding ISO-8859-13 recognised
+-- Multibyte String --
+Encoding ISO-8859-13 recognised
+
+-- Iteration 1: ISO-8859-14 --
+-- ASCII String --
+Encoding ISO-8859-14 recognised
+-- Multibyte String --
+Encoding ISO-8859-14 recognised
+
+-- Iteration 1: ISO-8859-15 --
+-- ASCII String --
+Encoding ISO-8859-15 recognised
+-- Multibyte String --
+Encoding ISO-8859-15 recognised
+
+-- Iteration 1: byte2be --
+-- ASCII String --
+Encoding byte2be recognised
+-- Multibyte String --
+Encoding byte2be recognised
+
+-- Iteration 1: byte2le --
+-- ASCII String --
+Encoding byte2le recognised
+-- Multibyte String --
+Encoding byte2le recognised
+
+-- Iteration 1: byte4be --
+-- ASCII String --
+Encoding byte4be recognised
+-- Multibyte String --
+Encoding byte4be recognised
+
+-- Iteration 1: byte4le --
+-- ASCII String --
+Encoding byte4le recognised
+-- Multibyte String --
+Encoding byte4le recognised
+
+-- Iteration 1: BASE64 --
+-- ASCII String --
+Encoding BASE64 recognised
+-- Multibyte String --
+Encoding BASE64 recognised
+
+-- Iteration 1: HTML-ENTITIES --
+-- ASCII String --
+Encoding HTML-ENTITIES recognised
+-- Multibyte String --
+Encoding HTML-ENTITIES recognised
+
+-- Iteration 1: 7bit --
+-- ASCII String --
+Encoding 7bit recognised
+-- Multibyte String --
+Encoding 7bit recognised
+
+-- Iteration 1: 8bit --
+-- ASCII String --
+Encoding 8bit recognised
+-- Multibyte String --
+Encoding 8bit recognised
+
+-- Iteration 1: EUC-CN --
+-- ASCII String --
+Encoding EUC-CN recognised
+-- Multibyte String --
+Encoding EUC-CN recognised
+
+-- Iteration 1: CP936 --
+-- ASCII String --
+Encoding CP936 recognised
+-- Multibyte String --
+Encoding CP936 recognised
+
+-- Iteration 1: HZ --
+-- ASCII String --
+Encoding HZ recognised
+-- Multibyte String --
+Encoding HZ recognised
+
+-- Iteration 1: EUC-TW --
+-- ASCII String --
+Encoding EUC-TW recognised
+-- Multibyte String --
+Encoding EUC-TW recognised
+
+-- Iteration 1: CP950 --
+-- ASCII String --
+Encoding CP950 recognised
+-- Multibyte String --
+Encoding CP950 recognised
+
+-- Iteration 1: BIG-5 --
+-- ASCII String --
+Encoding BIG-5 recognised
+-- Multibyte String --
+Encoding BIG-5 recognised
+
+-- Iteration 1: EUC-KR --
+-- ASCII String --
+Encoding EUC-KR recognised
+-- Multibyte String --
+Encoding EUC-KR recognised
+
+-- Iteration 1: UHC --
+-- ASCII String --
+Encoding UHC recognised
+-- Multibyte String --
+Encoding UHC recognised
+
+-- Iteration 1: ISO-2022-KR --
+-- ASCII String --
+Encoding ISO-2022-KR recognised
+-- Multibyte String --
+Encoding ISO-2022-KR recognised
+
+-- Iteration 1: Windows-1251 --
+-- ASCII String --
+Encoding Windows-1251 recognised
+-- Multibyte String --
+Encoding Windows-1251 recognised
+
+-- Iteration 1: Windows-1252 --
+-- ASCII String --
+Encoding Windows-1252 recognised
+-- Multibyte String --
+Encoding Windows-1252 recognised
+
+-- Iteration 1: CP866 --
+-- ASCII String --
+Encoding CP866 recognised
+-- Multibyte String --
+Encoding CP866 recognised
+
+-- Iteration 1: KOI8-R --
+-- ASCII String --
+Encoding KOI8-R recognised
+-- Multibyte String --
+Encoding KOI8-R recognised
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_variation4.phpt b/ext/mbstring/tests/mb_substr_variation4.phpt
new file mode 100644 (file)
index 0000000..d2c4de3
--- /dev/null
@@ -0,0 +1,131 @@
+--TEST--
+Test mb_substr() function : usage variations - pass different integers to $start arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
+?>
+--FILE--
+<?php
+/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
+ * Description: Returns part of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test how mb_substr() behaves when passed a range of integers as $start argument
+ */
+
+echo "*** Testing mb_substr() : usage variations ***\n";
+
+mb_internal_encoding('UTF-8');
+
+$string_ascii = '+Is an English string'; //21 chars
+
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
+
+/*
+ * Loop through integers as multiples of ten for $offset argument
+ * 60 is larger than *BYTE* count for $string_mb
+ */
+for ($i = -60; $i <= 60; $i += 10) {
+       if (@$a || @$b) {
+               $a = null;
+               $b = null;
+       }
+       echo "\n**-- Offset is: $i --**\n";
+       echo "-- ASCII String --\n";
+       var_dump($a = mb_substr($string_ascii, $i, 4));
+       echo "--Multibyte String --\n";
+       $b = mb_substr($string_mb, $i, 4, 'UTF-8');
+       if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length
+               var_dump(base64_encode($b));
+       } else {
+               echo "Difference in length of ASCII string and multibyte string\n";
+       }
+       
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing mb_substr() : usage variations ***
+
+**-- Offset is: -60 --**
+-- ASCII String --
+string(4) "+Is "
+--Multibyte String --
+string(16) "5pel5pys6Kqe44OG"
+
+**-- Offset is: -50 --**
+-- ASCII String --
+string(4) "+Is "
+--Multibyte String --
+string(16) "5pel5pys6Kqe44OG"
+
+**-- Offset is: -40 --**
+-- ASCII String --
+string(4) "+Is "
+--Multibyte String --
+string(16) "5pel5pys6Kqe44OG"
+
+**-- Offset is: -30 --**
+-- ASCII String --
+string(4) "+Is "
+--Multibyte String --
+string(16) "5pel5pys6Kqe44OG"
+
+**-- Offset is: -20 --**
+-- ASCII String --
+string(4) "Is a"
+--Multibyte String --
+string(16) "5pys6Kqe44OG44Kt"
+
+**-- Offset is: -10 --**
+-- ASCII String --
+string(4) "ish "
+--Multibyte String --
+string(8) "MTIzNA=="
+
+**-- Offset is: 0 --**
+-- ASCII String --
+string(4) "+Is "
+--Multibyte String --
+string(16) "5pel5pys6Kqe44OG"
+
+**-- Offset is: 10 --**
+-- ASCII String --
+string(4) "lish"
+--Multibyte String --
+string(8) "MDEyMw=="
+
+**-- Offset is: 20 --**
+-- ASCII String --
+string(1) "g"
+--Multibyte String --
+string(4) "44CC"
+
+**-- Offset is: 30 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: 40 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: 50 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: 60 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+Done
\ No newline at end of file
diff --git a/ext/mbstring/tests/mb_substr_variation5.phpt b/ext/mbstring/tests/mb_substr_variation5.phpt
new file mode 100644 (file)
index 0000000..02ea6d3
--- /dev/null
@@ -0,0 +1,134 @@
+--TEST--
+Test mb_substr() function : usage variations - pass different integers to $length arg
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
+?>
+--FILE--
+
+<?php
+/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
+ * Description: Returns part of a string 
+ * Source code: ext/mbstring/mbstring.c
+ */
+
+/*
+ * Test how mb_substr() behaves when passed a range of integers as $length argument
+ */
+
+echo "*** Testing mb_substr() : usage variations ***\n";
+
+mb_internal_encoding('UTF-8');
+
+$string_ascii = '+Is an English string'; //21 chars
+
+//Japanese string, 21 characters
+$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
+
+/*
+ * Loop through integers as multiples of ten for $offset argument
+ * 60 is larger than *BYTE* count for $string_mb
+ */
+for ($i = -60; $i <= 60; $i += 10) {
+       if (@$a || @$b) {
+               $a = null;
+               $b = null;
+       }
+       echo "\n**-- Offset is: $i --**\n";
+       echo "-- ASCII String --\n";
+       var_dump($a = mb_substr($string_ascii, 1, $i));
+       echo "--Multibyte String --\n";
+       $b = mb_substr($string_mb, 1, $i, 'UTF-8');
+       if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length
+               var_dump(base64_encode($b));
+       } else {
+               echo "Difference in length of ASCII string and multibyte string\n";
+       }
+       
+}
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing mb_substr() : usage variations ***
+
+**-- Offset is: -60 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: -50 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: -40 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: -30 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: -20 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: -10 --**
+-- ASCII String --
+string(10) "Is an Engl"
+--Multibyte String --
+string(40) "5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMA=="
+
+**-- Offset is: 0 --**
+-- ASCII String --
+string(0) ""
+--Multibyte String --
+string(0) ""
+
+**-- Offset is: 10 --**
+-- ASCII String --
+string(10) "Is an Engl"
+--Multibyte String --
+string(40) "5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMA=="
+
+**-- Offset is: 20 --**
+-- ASCII String --
+string(20) "Is an English string"
+--Multibyte String --
+string(68) "5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+
+**-- Offset is: 30 --**
+-- ASCII String --
+string(20) "Is an English string"
+--Multibyte String --
+string(68) "5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+
+**-- Offset is: 40 --**
+-- ASCII String --
+string(20) "Is an English string"
+--Multibyte String --
+string(68) "5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+
+**-- Offset is: 50 --**
+-- ASCII String --
+string(20) "Is an English string"
+--Multibyte String --
+string(68) "5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+
+**-- Offset is: 60 --**
+-- ASCII String --
+string(20) "Is an English string"
+--Multibyte String --
+string(68) "5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
+Done
\ No newline at end of file