Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Test case for bug 90411 |
michael@0 | 2 | * |
michael@0 | 3 | * Uses nsIConverterInputStream to decode GB_HK test. |
michael@0 | 4 | * |
michael@0 | 5 | * Sample text is: |
michael@0 | 6 | * 问他谁是傻瓜了5分钟。但是,他谁不要求仍然是一个傻瓜永远 |
michael@0 | 7 | * 我听见 我忘记; 我看见 我记住; 我做 我了解。 |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 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~}"; |
michael@0 | 11 | |
michael@0 | 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"; |
michael@0 | 13 | |
michael@0 | 14 | const charset="HZ-GB-2312"; |
michael@0 | 15 | |
michael@0 | 16 | function testCase(bufferLength) |
michael@0 | 17 | { |
michael@0 | 18 | var dataURI = "data:text/plain;charset=" + charset + "," + sample; |
michael@0 | 19 | |
michael@0 | 20 | var IOService = Components.Constructor("@mozilla.org/network/io-service;1", |
michael@0 | 21 | "nsIIOService"); |
michael@0 | 22 | var ConverterInputStream = |
michael@0 | 23 | Components.Constructor("@mozilla.org/intl/converter-input-stream;1", |
michael@0 | 24 | "nsIConverterInputStream", |
michael@0 | 25 | "init"); |
michael@0 | 26 | |
michael@0 | 27 | var ios = new IOService(); |
michael@0 | 28 | var channel = ios.newChannel(dataURI, "", null); |
michael@0 | 29 | var testInputStream = channel.open(); |
michael@0 | 30 | var testConverter = new ConverterInputStream(testInputStream, |
michael@0 | 31 | charset, |
michael@0 | 32 | bufferLength, |
michael@0 | 33 | 0xFFFD); |
michael@0 | 34 | |
michael@0 | 35 | if (!(testConverter instanceof |
michael@0 | 36 | Components.interfaces.nsIUnicharLineInputStream)) |
michael@0 | 37 | throw "not line input stream"; |
michael@0 | 38 | |
michael@0 | 39 | var outStr = ""; |
michael@0 | 40 | var more; |
michael@0 | 41 | do { |
michael@0 | 42 | // read the line and check for eof |
michael@0 | 43 | var line = {}; |
michael@0 | 44 | more = testConverter.readLine(line); |
michael@0 | 45 | outStr += line.value; |
michael@0 | 46 | } while (more); |
michael@0 | 47 | |
michael@0 | 48 | if (outStr != expected) { |
michael@0 | 49 | dump("Failed with bufferLength = " + bufferLength + "\n"); |
michael@0 | 50 | if (outStr.length == expected.length) { |
michael@0 | 51 | for (i = 0; i < outStr.length; ++i) { |
michael@0 | 52 | if (outStr.charCodeAt(i) != expected.charCodeAt(i)) { |
michael@0 | 53 | dump(i + ": " + outStr.charCodeAt(i).toString(16) + " != " + expected.charCodeAt(i).toString(16) + "\n"); |
michael@0 | 54 | } |
michael@0 | 55 | } |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | // escape the strings before comparing for better readability |
michael@0 | 60 | do_check_eq(escape(outStr), escape(expected)); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function run_test() |
michael@0 | 64 | { |
michael@0 | 65 | testCase(32); |
michael@0 | 66 | testCase(33); |
michael@0 | 67 | } |