michael@0: /* Tests conversion from ISO-2022-KR to Unicode (bug 449578) michael@0: */ michael@0: michael@0: // designator sequence at beginning of line - legal michael@0: const in1 = "%1B$)C%0E0!3*4Y6s%0F 1234"; michael@0: // empty non-ASCII sequence -- illegal michael@0: const in2 = "%1B$)Cab%0E%0Fcd"; michael@0: // designator sequence not at beginning of line - illegal michael@0: const in3 = "abc %1B$)C%0E0!3*4Y6s%0F 1234"; michael@0: michael@0: const expected1 = "\uAC00\uB098\uB2E4\uB77C 1234"; michael@0: const expected2 = "ab\uFFFD\cd"; michael@0: const expected3 = "abc \u001B$)C\uAC00\uB098\uB2E4\uB77C 1234"; michael@0: michael@0: function testCase(inStr, expected) michael@0: { michael@0: var dataURI = "data:text/plain;charset=ISO-2022-KR," + inStr; michael@0: michael@0: var IOService = Components.Constructor("@mozilla.org/network/io-service;1", michael@0: "nsIIOService"); michael@0: var ConverterInputStream = michael@0: Components.Constructor("@mozilla.org/intl/converter-input-stream;1", michael@0: "nsIConverterInputStream", michael@0: "init"); michael@0: michael@0: var ios = new IOService(); michael@0: var channel = ios.newChannel(dataURI, "", null); michael@0: var testInputStream = channel.open(); michael@0: var testConverter = new ConverterInputStream(testInputStream, michael@0: "ISO-2022-KR", michael@0: 8192, michael@0: 0xFFFD); michael@0: michael@0: if (!(testConverter instanceof michael@0: Components.interfaces.nsIUnicharLineInputStream)) michael@0: throw "not line input stream"; michael@0: michael@0: var outStr = ""; michael@0: var more; michael@0: do { michael@0: // read the line and check for eof michael@0: var line = {}; michael@0: more = testConverter.readLine(line); michael@0: outStr += line.value; michael@0: } while (more); michael@0: michael@0: do_check_eq(outStr, expected); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: testCase(in1, expected1); michael@0: testCase(in2, expected2); michael@0: testCase(in3, expected3); michael@0: }