summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/intl/test
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mailnews/intl/test')
-rw-r--r--comm/mailnews/intl/test/moz.build6
-rw-r--r--comm/mailnews/intl/test/unit/head_CharsetConversionTests.js46
-rw-r--r--comm/mailnews/intl/test/unit/test_decode_utf-7.js23
-rw-r--r--comm/mailnews/intl/test/unit/test_decode_utf-7_internal.js30
-rw-r--r--comm/mailnews/intl/test/unit/test_encode_utf-7.js22
-rw-r--r--comm/mailnews/intl/test/unit/test_encode_utf-7_internal.js24
-rw-r--r--comm/mailnews/intl/test/unit/xpcshell.ini10
7 files changed, 161 insertions, 0 deletions
diff --git a/comm/mailnews/intl/test/moz.build b/comm/mailnews/intl/test/moz.build
new file mode 100644
index 0000000000..6b37fdbe09
--- /dev/null
+++ b/comm/mailnews/intl/test/moz.build
@@ -0,0 +1,6 @@
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+XPCSHELL_TESTS_MANIFESTS += ["unit/xpcshell.ini"]
diff --git a/comm/mailnews/intl/test/unit/head_CharsetConversionTests.js b/comm/mailnews/intl/test/unit/head_CharsetConversionTests.js
new file mode 100644
index 0000000000..f1ae6c7155
--- /dev/null
+++ b/comm/mailnews/intl/test/unit/head_CharsetConversionTests.js
@@ -0,0 +1,46 @@
+var CC = Components.Constructor;
+
+function CreateScriptableConverter() {
+ var ScriptableUnicodeConverter = CC(
+ "@mozilla.org/intl/scriptableunicodeconverter",
+ "nsIScriptableUnicodeConverter"
+ );
+
+ return new ScriptableUnicodeConverter();
+}
+
+function checkDecode(converter, charset, inText, expectedText) {
+ let manager = Cc["@mozilla.org/charset-converter-manager;1"].getService(
+ Ci.nsICharsetConverterManager
+ );
+
+ try {
+ converter.charset = manager.getCharsetAlias(charset);
+ } catch (e) {
+ converter.charset = "iso-8859-1";
+ }
+
+ dump("testing decoding from " + charset + " to Unicode.\n");
+ try {
+ var outText = converter.ConvertToUnicode(inText) + converter.Finish();
+ } catch (e) {
+ outText = "\ufffd";
+ }
+ Assert.equal(outText, expectedText);
+}
+
+function checkEncode(converter, charset, inText, expectedText) {
+ let manager = Cc["@mozilla.org/charset-converter-manager;1"].getService(
+ Ci.nsICharsetConverterManager
+ );
+
+ try {
+ converter.charset = manager.getCharsetAlias(charset);
+ } catch (e) {
+ converter.charset = "iso-8859-1";
+ }
+
+ dump("testing encoding from Unicode to " + charset + "\n");
+ var outText = converter.ConvertFromUnicode(inText) + converter.Finish();
+ Assert.equal(outText, expectedText);
+}
diff --git a/comm/mailnews/intl/test/unit/test_decode_utf-7.js b/comm/mailnews/intl/test/unit/test_decode_utf-7.js
new file mode 100644
index 0000000000..e81dd137e6
--- /dev/null
+++ b/comm/mailnews/intl/test/unit/test_decode_utf-7.js
@@ -0,0 +1,23 @@
+// Tests conversion from UTF-7 to Unicode. The conversion should fail!
+
+var inString =
+ "+LGI--+ITIipSIp- +AocCeQ-oddns +Ad0CjQ- s+ATECZQKH- p+AlAB3QJ5- u+AlACVA- no+Ao4- +Al8-I";
+
+var expectedString =
+ "+LGI--+ITIipSIp- +AocCeQ-oddns +Ad0CjQ- s+ATECZQKH- p+AlAB3QJ5- u+AlACVA- no+Ao4- +Al8-I";
+
+var aliases = [
+ "UTF-7",
+ "utf-7",
+ "x-unicode-2-0-utf-7",
+ "unicode-2-0-utf-7",
+ "unicode-1-1-utf-7",
+ "csunicode11utf7",
+];
+
+function run_test() {
+ let converter = CreateScriptableConverter();
+ for (let i = 0; i < aliases.length; ++i) {
+ checkDecode(converter, aliases[i], inString, expectedString);
+ }
+}
diff --git a/comm/mailnews/intl/test/unit/test_decode_utf-7_internal.js b/comm/mailnews/intl/test/unit/test_decode_utf-7_internal.js
new file mode 100644
index 0000000000..e31f0f8840
--- /dev/null
+++ b/comm/mailnews/intl/test/unit/test_decode_utf-7_internal.js
@@ -0,0 +1,30 @@
+// Tests conversion from UTF-7 to Unicode.
+
+var inString =
+ "+LGI--+ITIipSIp- +AocCeQ-oddns +Ad0CjQ- s+ATECZQKH- p+AlAB3QJ5- u+AlACVA- no+Ao4- +Al8-I";
+
+var expectedString =
+ "\u2C62-\u2132\u22A5\u2229 \u0287\u0279oddns \u01DD\u028D s\u0131\u0265\u0287 p\u0250\u01DD\u0279 u\u0250\u0254 no\u028E \u025FI";
+
+var aliases = [
+ "UTF-7",
+ "utf-7",
+ "x-unicode-2-0-utf-7",
+ "unicode-2-0-utf-7",
+ "unicode-1-1-utf-7",
+ "csunicode11utf7",
+];
+function run_test() {
+ let manager = Cc["@mozilla.org/charset-converter-manager;1"].getService(
+ Ci.nsICharsetConverterManager
+ );
+ let converter = CreateScriptableConverter();
+ converter.isInternal = true;
+ for (let i = 0; i < aliases.length; ++i) {
+ if (manager.getCharsetAlias(aliases[i]).toLowerCase() == "utf-7") {
+ Assert.equal(manager.utf7ToUnicode(inString), expectedString);
+ } else {
+ checkDecode(converter, aliases[i], inString, expectedString);
+ }
+ }
+}
diff --git a/comm/mailnews/intl/test/unit/test_encode_utf-7.js b/comm/mailnews/intl/test/unit/test_encode_utf-7.js
new file mode 100644
index 0000000000..1acc8957bd
--- /dev/null
+++ b/comm/mailnews/intl/test/unit/test_encode_utf-7.js
@@ -0,0 +1,22 @@
+// Tests conversion from Unicode to UTF-7. The conversion should fail!
+
+var inString =
+ "\u2C62-\u2132\u22A5\u2229 \u0287\u0279oddns \u01DD\u028D s\u0131\u0265\u0287 p\u0250\u01DD\u0279 u\u0250\u0254 no\u028E \u025FI";
+
+var expectedString = "?-??? ??oddns ?? s??? p??? u?? no? ?I";
+
+var aliases = [
+ "UTF-7",
+ "utf-7",
+ "x-unicode-2-0-utf-7",
+ "unicode-2-0-utf-7",
+ "unicode-1-1-utf-7",
+ "csunicode11utf7",
+];
+
+function run_test() {
+ let converter = CreateScriptableConverter();
+ for (let i = 0; i < aliases.length; ++i) {
+ checkEncode(converter, aliases[i], inString, expectedString);
+ }
+}
diff --git a/comm/mailnews/intl/test/unit/test_encode_utf-7_internal.js b/comm/mailnews/intl/test/unit/test_encode_utf-7_internal.js
new file mode 100644
index 0000000000..31af29c30b
--- /dev/null
+++ b/comm/mailnews/intl/test/unit/test_encode_utf-7_internal.js
@@ -0,0 +1,24 @@
+// Tests conversion from Unicode to UTF-7.
+
+var inString =
+ "\u2C62-\u2132\u22A5\u2229 \u0287\u0279oddns \u01DD\u028D s\u0131\u0265\u0287 p\u0250\u01DD\u0279 u\u0250\u0254 no\u028E \u025FI";
+
+var expectedString =
+ "+LGI--+ITIipSIp- +AocCeQ-oddns +Ad0CjQ- s+ATECZQKH- p+AlAB3QJ5- u+AlACVA- no+Ao4- +Al8-I";
+
+var aliases = [
+ "UTF-7",
+ "utf-7",
+ "x-unicode-2-0-utf-7",
+ "unicode-2-0-utf-7",
+ "unicode-1-1-utf-7",
+ "csunicode11utf7",
+];
+
+function run_test() {
+ let converter = CreateScriptableConverter();
+ converter.isInternal = true;
+ for (let i = 0; i < aliases.length; ++i) {
+ checkEncode(converter, aliases[i], inString, expectedString);
+ }
+}
diff --git a/comm/mailnews/intl/test/unit/xpcshell.ini b/comm/mailnews/intl/test/unit/xpcshell.ini
new file mode 100644
index 0000000000..cbc671669c
--- /dev/null
+++ b/comm/mailnews/intl/test/unit/xpcshell.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+head = head_CharsetConversionTests.js
+tail =
+
+[test_decode_utf-7.js]
+[test_decode_utf-7_internal.js]
+[test_encode_utf-7.js]
+[test_encode_utf-7_internal.js]
+# Disabled per bug 1363281: No scriptable converter for UTF-7 exists any more.
+skip-if = true