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.

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

mercurial