intl/uconv/tests/unit/test_bug399257.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 // Tests encoding of characters below U+0020
michael@0 2 load('CharsetConversionTests.js');
michael@0 3
michael@0 4 const inString = "Hello\u000aWorld";
michael@0 5 const expectedString = "Hello\nWorld";
michael@0 6
michael@0 7 function run_test() {
michael@0 8 var failures = false;
michael@0 9 var ccManager = Cc["@mozilla.org/charset-converter-manager;1"]
michael@0 10 .getService(Ci.nsICharsetConverterManager);
michael@0 11 var encodingConverter = CreateScriptableConverter();
michael@0 12
michael@0 13 var charsetList = ccManager.getDecoderList();
michael@0 14 var counter = 0;
michael@0 15 while (charsetList.hasMore()) {
michael@0 16 ++counter;
michael@0 17 var charset = charsetList.getNext();
michael@0 18
michael@0 19 // exclude known non-ASCII compatible charsets
michael@0 20 if (charset.substr(0, "UTF-16".length) == "UTF-16" ||
michael@0 21 charset == "x-imap4-modified-utf7") {
michael@0 22 dump("skipping " + counter + " " + charset + "\n");
michael@0 23 continue;
michael@0 24 }
michael@0 25 dump("testing " + counter + " " + charset + "\n");
michael@0 26
michael@0 27 try {
michael@0 28 encodingConverter.charset = charset;
michael@0 29 } catch(e) {
michael@0 30 dump("Warning: couldn't set encoder charset to " + charset + "\n");
michael@0 31 continue;
michael@0 32 }
michael@0 33 var codepageString = encodingConverter.ConvertFromUnicode(inString) +
michael@0 34 encodingConverter.Finish();
michael@0 35 if (codepageString != expectedString) {
michael@0 36 dump(charset + " encoding failed\n");
michael@0 37 for (var i = 0; i < expectedString.length; ++i) {
michael@0 38 if (codepageString.charAt(i) != expectedString.charAt(i)) {
michael@0 39 dump(i.toString(16) + ": 0x" +
michael@0 40 codepageString.charCodeAt(i).toString(16) + " != " +
michael@0 41 expectedString.charCodeAt(i).toString(16) + "\n");
michael@0 42 }
michael@0 43 }
michael@0 44 failures = true;
michael@0 45 }
michael@0 46 }
michael@0 47 if (failures) {
michael@0 48 do_throw("test failed\n");
michael@0 49 }
michael@0 50 }

mercurial