Bug 1170932: Test handling of unmapped characters in unicode-to-codepage encoders
authorSimon Montagu <smontagu@smontagu.org>
Tue, 02 Jun 2015 23:53:25 +0300
changeset 247570 c5f6b5160c029c794e9dffe8e1833fa42a2b4501
parent 247569 10dfb6455e4f397eda9c75ca61106330fbedc964
child 247571 ee2d0bbca72c61e6355ca65d8f715357d9d76703
push id28870
push usercbook@mozilla.com
push dateMon, 08 Jun 2015 09:58:36 +0000
treeherdermozilla-central@4700d1cdf489 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1170932
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1170932: Test handling of unmapped characters in unicode-to-codepage encoders
intl/uconv/tests/unit/test_unmapped.js
intl/uconv/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/intl/uconv/tests/unit/test_unmapped.js
@@ -0,0 +1,77 @@
+// Tests encoding of unmapped characters
+load('CharsetConversionTests.js');
+
+const inString = "\u2764";
+const expectedString = "?";
+
+function run_test() {
+    var failures = false;
+    var encodingConverter = CreateScriptableConverter();
+
+    // this list excludes codepages that can represent all Unicode
+    var encoders = [
+        "Big5",
+        "Big5-HKSCS",
+        "EUC-JP",
+        "EUC-KR",
+        "gbk",
+        "IBM866",
+        "ISO-2022-JP",
+        "ISO-8859-3",
+        "ISO-8859-4",
+        "ISO-8859-5",
+        "ISO-8859-6",
+        "ISO-8859-7",
+        "ISO-8859-8",
+        "ISO-8859-8-I",
+        "ISO-8859-10",
+        "ISO-8859-13",
+        "ISO-8859-14",
+        "ISO-8859-15",
+        "ISO-8859-16",
+        "ISO-8859-2",
+        "KOI8-R",
+        "KOI8-U",
+        "Shift_JIS",
+        "windows-1250",
+        "windows-1251",
+        "windows-1252",
+        "windows-1253",
+        "windows-1254",
+        "windows-1255",
+        "windows-1256",
+        "windows-1257",
+        "windows-1258",
+        "windows-874",
+        "x-mac-cyrillic"
+    ];
+
+    var counter = 0;
+    while (counter < encoders.length) {
+        var charset = encoders[counter++];
+
+        dump("testing " + counter + " " + charset + "\n");
+        encodingConverter.charset = charset;
+        var codepageString = encodingConverter.ConvertFromUnicode(inString) +
+            encodingConverter.Finish();
+        if (codepageString != expectedString) {
+            dump(charset + " encoding failed\n");
+            for (var i = 0; i < expectedString.length; ++i) {
+                if (i >= codepageString.length) {
+                    dump("output length " + codepageString.length +
+                         " less than expected length " + expectedString.length + "\n");
+                    break;
+                }
+                if (codepageString.charAt(i) != expectedString.charAt(i)) {
+                    dump(i.toString(16) + ": 0x" +
+                         codepageString.charCodeAt(i).toString(16) + " != " +
+                         expectedString.charCodeAt(i).toString(16) + "\n");
+                }
+            }
+            failures = true;
+        }
+    }
+    if (failures) {
+        do_throw("test failed\n");
+    }
+}
--- a/intl/uconv/tests/unit/xpcshell.ini
+++ b/intl/uconv/tests/unit/xpcshell.ini
@@ -115,8 +115,9 @@ support-files =
 [test_encode_x_mac_hebrew.js]
 [test_encode_x_mac_icelandic.js]
 [test_encode_macintosh.js]
 [test_encode_x_mac_romanian.js]
 [test_encode_x_mac_turkish.js]
 [test_utf8_illegals.js]
 [test_input_stream.js]
 [test_bug1008832.js]
+[test_unmapped.js]