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