|
1 /* Test case for ISO-2022-KR |
|
2 * |
|
3 * Uses nsIConverterInputStream to decode ISO-2022-KR text. |
|
4 * |
|
5 * Sample text is: |
|
6 * 1: 소 잃고 외양간 고친다 |
|
7 * 2: 빈 수레가 요란하다 |
|
8 * 3: 하늘의 별 따기 |
|
9 * 4: 아는 길도 물어가라 |
|
10 * |
|
11 * (From http://en.wikiquote.org/wiki/Korean_proverbs) |
|
12 */ |
|
13 |
|
14 const sample = "%1B%24%29C1%3A%20%0E%3CR%0F%20%0E%40R0m%0F%20%0E%3F%5C%3Eg0%23%0F%20%0E0mD%234Y%0A2%3A%20%0E%3As%0F%20%0E%3Cv790%21%0F%20%0E%3Fd6uGO4Y%0A3%3A%20%0EGO4C%40G%0F%20%0E%3A0%0F%20%0E5%7B1b%0A4%3A%20%0E%3EF4B%0F%20%0E1f55%0F%20%0E90%3En0%216s"; |
|
15 |
|
16 const expected = "1: \uC18C \uC783\uACE0 \uC678\uC591\uAC04 \uACE0\uCE5C\uB2E4\n2: \uBE48 \uC218\uB808\uAC00 \uC694\uB780\uD558\uB2E4\n3: \uD558\uB298\uC758 \uBCC4 \uB530\uAE30\n4: \uC544\uB294 \uAE38\uB3C4 \uBB3C\uC5B4\uAC00\uB77C\n"; |
|
17 |
|
18 const charset="ISO-2022-KR"; |
|
19 |
|
20 function testCase(bufferLength) |
|
21 { |
|
22 var dataURI = "data:text/plain;charset=" + charset + "," + sample; |
|
23 |
|
24 var IOService = Components.Constructor("@mozilla.org/network/io-service;1", |
|
25 "nsIIOService"); |
|
26 var ConverterInputStream = |
|
27 Components.Constructor("@mozilla.org/intl/converter-input-stream;1", |
|
28 "nsIConverterInputStream", |
|
29 "init"); |
|
30 |
|
31 var ios = new IOService(); |
|
32 var channel = ios.newChannel(dataURI, "", null); |
|
33 var testInputStream = channel.open(); |
|
34 var testConverter = new ConverterInputStream(testInputStream, |
|
35 charset, |
|
36 bufferLength, |
|
37 0xFFFD); |
|
38 |
|
39 if (!(testConverter instanceof |
|
40 Components.interfaces.nsIUnicharLineInputStream)) |
|
41 throw "not line input stream"; |
|
42 |
|
43 var outStr = ""; |
|
44 var more; |
|
45 do { |
|
46 // read the line and check for eof |
|
47 var line = {}; |
|
48 more = testConverter.readLine(line); |
|
49 outStr += line.value + "\n"; |
|
50 } while (more); |
|
51 |
|
52 if (outStr != expected) { |
|
53 dump("Failed with bufferLength = " + bufferLength + "\n"); |
|
54 if (outStr.length == expected.length) { |
|
55 for (i = 0; i < outStr.length; ++i) { |
|
56 if (outStr.charCodeAt(i) != expected.charCodeAt(i)) { |
|
57 dump(i + ": " + outStr.charCodeAt(i).toString(16) + " != " + expected.charCodeAt(i).toString(16) + "\n"); |
|
58 } |
|
59 } |
|
60 } |
|
61 } |
|
62 |
|
63 // escape the strings before comparing for better readability |
|
64 do_check_eq(escape(outStr), escape(expected)); |
|
65 } |
|
66 |
|
67 function run_test() |
|
68 { |
|
69 testCase(34); |
|
70 testCase(35); |
|
71 } |