|
1 /* Test case for bug 90411 |
|
2 * |
|
3 * Uses nsIConverterInputStream to decode GB_HK test. |
|
4 * |
|
5 * Sample text is: |
|
6 * 问他谁是傻瓜了5分钟。但是,他谁不要求仍然是一个傻瓜永远 |
|
7 * 我听见 我忘记; 我看见 我记住; 我做 我了解。 |
|
8 */ |
|
9 |
|
10 const sample = "~{NJK{K-JGI59OAK~}5~{7VVS!%235+JG%23,K{K-2;R*GsHTH;JGR;8vI59OS@T6!%23~} ~{NRL}<{~} ~{NRM|<G~}; ~{NR?4<{~} ~{NR<GW!~}; ~{NRWv~} ~{NRAK=b!%23~}"; |
|
11 |
|
12 const expected = "\u95EE\u4ED6\u8C01\u662F\u50BB\u74DC\u4E865\u5206\u949F\u3002\u4F46\u662F\uFF0C\u4ED6\u8C01\u4E0D\u8981\u6C42\u4ECD\u7136\u662F\u4E00\u4E2A\u50BB\u74DC\u6C38\u8FDC\u3002 \u6211\u542C\u89C1 \u6211\u5FD8\u8BB0; \u6211\u770B\u89C1 \u6211\u8BB0\u4F4F; \u6211\u505A \u6211\u4E86\u89E3\u3002"; |
|
13 |
|
14 const charset="HZ-GB-2312"; |
|
15 |
|
16 function testCase(bufferLength) |
|
17 { |
|
18 var dataURI = "data:text/plain;charset=" + charset + "," + sample; |
|
19 |
|
20 var IOService = Components.Constructor("@mozilla.org/network/io-service;1", |
|
21 "nsIIOService"); |
|
22 var ConverterInputStream = |
|
23 Components.Constructor("@mozilla.org/intl/converter-input-stream;1", |
|
24 "nsIConverterInputStream", |
|
25 "init"); |
|
26 |
|
27 var ios = new IOService(); |
|
28 var channel = ios.newChannel(dataURI, "", null); |
|
29 var testInputStream = channel.open(); |
|
30 var testConverter = new ConverterInputStream(testInputStream, |
|
31 charset, |
|
32 bufferLength, |
|
33 0xFFFD); |
|
34 |
|
35 if (!(testConverter instanceof |
|
36 Components.interfaces.nsIUnicharLineInputStream)) |
|
37 throw "not line input stream"; |
|
38 |
|
39 var outStr = ""; |
|
40 var more; |
|
41 do { |
|
42 // read the line and check for eof |
|
43 var line = {}; |
|
44 more = testConverter.readLine(line); |
|
45 outStr += line.value; |
|
46 } while (more); |
|
47 |
|
48 if (outStr != expected) { |
|
49 dump("Failed with bufferLength = " + bufferLength + "\n"); |
|
50 if (outStr.length == expected.length) { |
|
51 for (i = 0; i < outStr.length; ++i) { |
|
52 if (outStr.charCodeAt(i) != expected.charCodeAt(i)) { |
|
53 dump(i + ": " + outStr.charCodeAt(i).toString(16) + " != " + expected.charCodeAt(i).toString(16) + "\n"); |
|
54 } |
|
55 } |
|
56 } |
|
57 } |
|
58 |
|
59 // escape the strings before comparing for better readability |
|
60 do_check_eq(escape(outStr), escape(expected)); |
|
61 } |
|
62 |
|
63 function run_test() |
|
64 { |
|
65 testCase(32); |
|
66 testCase(33); |
|
67 } |