com php-src: Test cases for mbstring encodings are less repetitive: ext/mbstring/tests/cp1252_encoding.phpt ext/mbstr ing/tests/encoding_tests.inc
ext/mbstring/tests/iso88 59_encodings.phpt
| From: | Alex Dowad | Date: | Mon, 02 Nov 2020 19:31:05 +0000 |
| Subject: | com php-src: Test cases for mbstring encodings are less repetitive: ext/mbstring/tests/cp1252_encoding.phpt ext/mbstr ing/tests/encoding_tests.inc ext/mbstring/tests/iso88 59_encodings.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114036@lists.php.net to get a copy of this message | ||
Commit: b18b9c9ef6c815be63bf8018e92403cd28acf7c9
Author: Alex Dowad <alexinbeijing@gmail.com> Mon, 2 Nov 2020 13:11:16 +0200
Parents: a1dcbb2c8a56efcdddcf8ebe26a1e2f3c5626038
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b18b9c9ef6c815be63bf8018e92403cd28acf7c9
Log:
Test cases for mbstring encodings are less repetitive
Changed paths:
M ext/mbstring/tests/cp1252_encoding.phpt
M ext/mbstring/tests/encoding_tests.inc
M ext/mbstring/tests/iso8859_encodings.phpt
Diff:
diff --git a/ext/mbstring/tests/cp1252_encoding.phpt b/ext/mbstring/tests/cp1252_encoding.phpt
index e5fe2a7b565..cc2d81fdcdd 100644
--- a/ext/mbstring/tests/cp1252_encoding.phpt
+++ b/ext/mbstring/tests/cp1252_encoding.phpt
@@ -7,20 +7,9 @@ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php
-srand(789); // Make results consistent
include('encoding_tests.inc');
-mb_substitute_character(0x25); // '%'
-
-readConversionTable(realpath(__DIR__ . '/data/CP1252.txt'), $toUnicode, $fromUnicode);
-findInvalidChars($toUnicode, $invalid, $unused);
-testAllValidChars($toUnicode, 'CP1252', 'UTF-16BE');
-testAllInvalidChars($invalid, $toUnicode, 'CP1252', 'UTF-16BE',
"\x00%");
-
-findInvalidChars($fromUnicode, $invalid, $truncated, map(range(0,0xFF), 2));
-testAllInvalidChars($invalid, $fromUnicode, 'UTF-16BE', 'CP1252',
'%');
-testTruncatedChars($truncated, 'UTF-16BE', 'CP1252', '%');
-
-echo "All is fine and dandy for CP1252 text\n";
+testEncodingFromUTF16ConversionTable(__DIR__ . '/data/CP1252.txt', 'CP1252');
?>
--EXPECT--
-All is fine and dandy for CP1252 text
+Tested CP1252 -> UTF-16BE
+Tested UTF-16BE -> CP1252
diff --git a/ext/mbstring/tests/encoding_tests.inc b/ext/mbstring/tests/encoding_tests.inc
index e6b8f56d0f4..45e69085ece 100644
--- a/ext/mbstring/tests/encoding_tests..inc
+++ b/ext/mbstring/tests/encoding_tests.inc
@@ -198,4 +198,20 @@ function map($keys, $value, $array = array()) {
return $array;
}
+function testEncodingFromUTF16ConversionTable($path, $encoding, $replacement = '%',
$startBytes = array()) {
+ srand(1000); // Make results consistent
+ mb_substitute_character(0x25); // '%'
+ readConversionTable($path, $toUnicode, $fromUnicode);
+
+ findInvalidChars($toUnicode, $invalid, $truncated, $startBytes);
+ testAllValidChars($toUnicode, $encoding, 'UTF-16BE');
+ testAllInvalidChars($invalid, $toUnicode, $encoding, 'UTF-16BE', "\x00%");
+ testTruncatedChars($truncated, $encoding, 'UTF-16BE', "\x00%");
+ echo "Tested $encoding -> UTF-16BE\n";
+
+ findInvalidChars($fromUnicode, $invalid, $truncated, map(range(0,0xFF), 2));
+ testAllInvalidChars($invalid, $fromUnicode, 'UTF-16BE', $encoding, $replacement);
+ testTruncatedChars($truncated, 'UTF-16BE', $encoding, $replacement);
+ echo "Tested UTF-16BE -> $encoding\n";
+}
?>
diff --git a/ext/mbstring/tests/iso8859_encodings.phpt b/ext/mbstring/tests/iso8859_encodings.phpt
index 86e82d73152..bbc70dfe3d1 100644
--- a/ext/mbstring/tests/iso8859_encodings.phpt
+++ b/ext/mbstring/tests/iso8859_encodings.phpt
@@ -7,38 +7,40 @@ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php
-srand(678); // Make results consistent
include('encoding_tests.inc');
-mb_substitute_character(0x25); // '%'
for ($n = 1; $n <= 16; $n++) {
if ($n == 11 || $n == 12)
continue;
-
- readConversionTable(realpath(__DIR__ . "/data/8859-$n.txt"), $toUnicode,
$fromUnicode);
- findInvalidChars($toUnicode, $invalid, $unused);
- testAllValidChars($toUnicode, "ISO-8859-{$n}", 'UTF-16BE');
- testAllInvalidChars($invalid, $toUnicode, "ISO-8859-{$n}", 'UTF-16BE',
"\x00%");
-
- findInvalidChars($fromUnicode, $invalid, $truncated, map(range(0,0xFF), 2));
- testAllInvalidChars($invalid, $fromUnicode, 'UTF-16BE', "ISO-8859-{$n}",
'%');
- testTruncatedChars($truncated, 'UTF-16BE', "ISO-8859-{$n}", '%');
-
- echo "All is fine and dandy for ISO-8859-$n text\n";
+ testEncodingFromUTF16ConversionTable(__DIR__ . "/data/8859-$n.txt",
"ISO-8859-{$n}");
}
?>
--EXPECT--
-All is fine and dandy for ISO-8859-1 text
-All is fine and dandy for ISO-8859-2 text
-All is fine and dandy for ISO-8859-3 text
-All is fine and dandy for ISO-8859-4 text
-All is fine and dandy for ISO-8859-5 text
-All is fine and dandy for ISO-8859-6 text
-All is fine and dandy for ISO-8859-7 text
-All is fine and dandy for ISO-8859-8 text
-All is fine and dandy for ISO-8859-9 text
-All is fine and dandy for ISO-8859-10 text
-All is fine and dandy for ISO-8859-13 text
-All is fine and dandy for ISO-8859-14 text
-All is fine and dandy for ISO-8859-15 text
-All is fine and dandy for ISO-8859-16 text
+Tested ISO-8859-1 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-1
+Tested ISO-8859-2 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-2
+Tested ISO-8859-3 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-3
+Tested ISO-8859-4 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-4
+Tested ISO-8859-5 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-5
+Tested ISO-8859-6 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-6
+Tested ISO-8859-7 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-7
+Tested ISO-8859-8 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-8
+Tested ISO-8859-9 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-9
+Tested ISO-8859-10 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-10
+Tested ISO-8859-13 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-13
+Tested ISO-8859-14 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-14
+Tested ISO-8859-15 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-15
+Tested ISO-8859-16 -> UTF-16BE
+Tested UTF-16BE -> ISO-8859-16