diff options
Diffstat (limited to 'comm/mailnews/intl/test/unit/head_CharsetConversionTests.js')
-rw-r--r-- | comm/mailnews/intl/test/unit/head_CharsetConversionTests.js | 46 |
1 files changed, 46 insertions, 0 deletions
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); +} |