]> granicus.if.org Git - php/commitdiff
Added test cases for iconv_strpos() and iconv_strrpos()
authorMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 3 Jan 2003 20:02:23 +0000 (20:02 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 3 Jan 2003 20:02:23 +0000 (20:02 +0000)
ext/iconv/tests/iconv_strpos.phpt [new file with mode: 0644]
ext/iconv/tests/iconv_strrpos.phpt [new file with mode: 0644]

diff --git a/ext/iconv/tests/iconv_strpos.phpt b/ext/iconv/tests/iconv_strpos.phpt
new file mode 100644 (file)
index 0000000..ccf4ea7
--- /dev/null
@@ -0,0 +1,52 @@
+--TEST--
+iconv_strpos()
+--SKIPIF--
+<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
+--INI--
+iconv.internal_charset=ISO-8859-1
+--FILE--
+<?php
+function my_error_handler($errno, $errmsg, $filename, $linenum, $vars)
+{
+       echo "$errno: $errmsg\n";
+}
+set_error_handler('my_error_handler');
+function foo($haystk, $needle, $offset, $to_charset = false, $from_charset = false)
+{
+       if ($from_charset !== false) {
+               $haystk = iconv($from_charset, $to_charset, $haystk);
+       }
+       var_dump(strpos($haystk, $needle, $offset));
+       if ($to_charset !== false) {
+               var_dump(iconv_strpos($haystk, $needle, $offset, $to_charset));
+       } else {
+               var_dump(iconv_strpos($haystk, $needle, $offset));
+       }
+}
+foo("abecdbcdabef", "bcd", -1);
+foo("abecdbcdabef", "bcd", 100000);
+foo("abcabcabcdabcababcdabc", "bcd", 0);
+foo("abcabcabcdabcababcdabc", "bcd", 10);
+foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd", 0);
+foo(str_repeat("¤¢¤¤¤¦¤¨¤ª", 30)."¤¤¤¦¤ª¤¨¤¢".str_repeat("¤¢¤¤¤¨¤ª¤¦", 30), "¤¦¤ª", 0, "EUC-JP");
+$str = str_repeat("¤¢¤¤¤¦¤¨¤ª", 60).'$'.str_repeat("¤¢¤¤¤¨¤ª¤¦", 60);
+foo($str, '$', 0, "ISO-2022-JP", "EUC-JP");
+?>
+--EXPECTF--
+2: %s
+bool(false)
+2: %s
+bool(false)
+2: %s
+bool(false)
+bool(false)
+int(7)
+int(7)
+int(16)
+int(16)
+int(300)
+int(300)
+int(302)
+int(151)
+int(1)
+int(300)
diff --git a/ext/iconv/tests/iconv_strrpos.phpt b/ext/iconv/tests/iconv_strrpos.phpt
new file mode 100644 (file)
index 0000000..f150f88
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--
+iconv_strrpos()
+--SKIPIF--
+<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
+--INI--
+iconv.internal_charset=ISO-8859-1
+--FILE--
+<?php
+function my_error_handler($errno, $errmsg, $filename, $linenum, $vars)
+{
+       echo "$errno: $errmsg\n";
+}
+set_error_handler('my_error_handler');
+function foo($haystk, $needle, $to_charset = false, $from_charset = false)
+{
+       if ($from_charset !== false) {
+               $haystk = iconv($from_charset, $to_charset, $haystk);
+       }
+       if ($to_charset !== false) {
+               var_dump(iconv_strlen($haystk, $to_charset));
+               var_dump(iconv_strrpos($haystk, $needle, $to_charset));
+       } else {
+               var_dump(iconv_strlen($haystk));
+               var_dump(iconv_strrpos($haystk, $needle));
+       }
+}
+foo("abecdbcdabcdef", "bcd");
+foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd");
+foo(str_repeat("¤¢¤¤¤¦¤¨¤ª", 30)."¤¤¤¦¤ª¤¨¤¢".str_repeat("¤¢¤¤¤¨¤ª¤¦", 30), "¤¦¤ª", "EUC-JP");
+
+for ($i = 0; $i <=6; ++$i) {
+       $str = str_repeat("¤¢¤¤¤¦¤¨¤ª", 60).str_repeat('$', $i).str_repeat("¤¢¤¤¤¨¤ª¤¦", 60);
+       foo($str, '$', "ISO-2022-JP", "EUC-JP");
+}
+?>
+--EXPECT--
+int(14)
+int(9)
+int(605)
+int(300)
+int(305)
+int(151)
+int(600)
+bool(false)
+int(601)
+int(300)
+int(602)
+int(301)
+int(603)
+int(302)
+int(604)
+int(303)
+int(605)
+int(304)
+int(606)
+int(305)