2009-09-23 01:01:23 -07:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const CC = Components.Constructor;
|
|
|
|
|
|
|
|
function CreateScriptableConverter()
|
|
|
|
{
|
|
|
|
var ScriptableUnicodeConverter =
|
|
|
|
CC("@mozilla.org/intl/scriptableunicodeconverter",
|
|
|
|
"nsIScriptableUnicodeConverter");
|
|
|
|
|
|
|
|
return new ScriptableUnicodeConverter();
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkDecode(converter, charset, inText, expectedText)
|
|
|
|
{
|
2010-11-08 02:27:40 -08:00
|
|
|
try {
|
|
|
|
converter.charset = charset;
|
|
|
|
} catch(e) {
|
|
|
|
converter.charset = "iso-8859-1";
|
|
|
|
}
|
2009-09-23 01:01:23 -07:00
|
|
|
|
|
|
|
dump("testing decoding from " + charset + " to Unicode.\n");
|
|
|
|
try {
|
|
|
|
var outText = converter.ConvertToUnicode(inText) + converter.Finish();
|
|
|
|
} catch(e) {
|
|
|
|
outText = "\ufffd";
|
|
|
|
}
|
|
|
|
do_check_eq(outText, expectedText);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkEncode(converter, charset, inText, expectedText)
|
|
|
|
{
|
2010-11-08 02:27:40 -08:00
|
|
|
try {
|
|
|
|
converter.charset = charset;
|
|
|
|
} catch(e) {
|
|
|
|
converter.charset = "iso-8859-1";
|
|
|
|
}
|
2009-09-23 01:01:23 -07:00
|
|
|
|
|
|
|
dump("testing encoding from Unicode to " + charset + "\n");
|
|
|
|
var outText = converter.ConvertFromUnicode(inText) + converter.Finish();
|
|
|
|
do_check_eq(outText, expectedText);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDecodeAliases()
|
|
|
|
{
|
|
|
|
var converter = CreateScriptableConverter();
|
|
|
|
for (var i = 0; i < aliases.length; ++i) {
|
|
|
|
checkDecode(converter, aliases[i], inString, expectedString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testEncodeAliases()
|
|
|
|
{
|
|
|
|
var converter = CreateScriptableConverter();
|
|
|
|
for (var i = 0; i < aliases.length; ++i) {
|
|
|
|
checkEncode(converter, aliases[i], inString, expectedString);
|
|
|
|
}
|
|
|
|
}
|
2010-11-08 02:27:40 -08:00
|
|
|
|
|
|
|
function testDecodeAliasesInternal()
|
|
|
|
{
|
|
|
|
var converter = CreateScriptableConverter();
|
|
|
|
converter.isInternal = true;
|
|
|
|
for (var i = 0; i < aliases.length; ++i) {
|
|
|
|
checkDecode(converter, aliases[i], inString, expectedString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testEncodeAliasesInternal()
|
|
|
|
{
|
|
|
|
var converter = CreateScriptableConverter();
|
|
|
|
converter.isInternal = true;
|
|
|
|
for (var i = 0; i < aliases.length; ++i) {
|
|
|
|
checkEncode(converter, aliases[i], inString, expectedString);
|
|
|
|
}
|
|
|
|
}
|