intl/uconv/tests/unit/test_bug449578.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 conversion from ISO-2022-KR to Unicode (bug 449578)
michael@0 2 */
michael@0 3
michael@0 4 // designator sequence at beginning of line - legal
michael@0 5 const in1 = "%1B$)C%0E0!3*4Y6s%0F 1234";
michael@0 6 // empty non-ASCII sequence -- illegal
michael@0 7 const in2 = "%1B$)Cab%0E%0Fcd";
michael@0 8 // designator sequence not at beginning of line - illegal
michael@0 9 const in3 = "abc %1B$)C%0E0!3*4Y6s%0F 1234";
michael@0 10
michael@0 11 const expected1 = "\uAC00\uB098\uB2E4\uB77C 1234";
michael@0 12 const expected2 = "ab\uFFFD\cd";
michael@0 13 const expected3 = "abc \u001B$)C\uAC00\uB098\uB2E4\uB77C 1234";
michael@0 14
michael@0 15 function testCase(inStr, expected)
michael@0 16 {
michael@0 17 var dataURI = "data:text/plain;charset=ISO-2022-KR," + inStr;
michael@0 18
michael@0 19 var IOService = Components.Constructor("@mozilla.org/network/io-service;1",
michael@0 20 "nsIIOService");
michael@0 21 var ConverterInputStream =
michael@0 22 Components.Constructor("@mozilla.org/intl/converter-input-stream;1",
michael@0 23 "nsIConverterInputStream",
michael@0 24 "init");
michael@0 25
michael@0 26 var ios = new IOService();
michael@0 27 var channel = ios.newChannel(dataURI, "", null);
michael@0 28 var testInputStream = channel.open();
michael@0 29 var testConverter = new ConverterInputStream(testInputStream,
michael@0 30 "ISO-2022-KR",
michael@0 31 8192,
michael@0 32 0xFFFD);
michael@0 33
michael@0 34 if (!(testConverter instanceof
michael@0 35 Components.interfaces.nsIUnicharLineInputStream))
michael@0 36 throw "not line input stream";
michael@0 37
michael@0 38 var outStr = "";
michael@0 39 var more;
michael@0 40 do {
michael@0 41 // read the line and check for eof
michael@0 42 var line = {};
michael@0 43 more = testConverter.readLine(line);
michael@0 44 outStr += line.value;
michael@0 45 } while (more);
michael@0 46
michael@0 47 do_check_eq(outStr, expected);
michael@0 48 }
michael@0 49
michael@0 50 function run_test()
michael@0 51 {
michael@0 52 testCase(in1, expected1);
michael@0 53 testCase(in2, expected2);
michael@0 54 testCase(in3, expected3);
michael@0 55 }

mercurial