1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/tests/unit/test_bug90411.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* Test case for bug 90411 1.5 + * 1.6 + * Uses nsIConverterInputStream to decode GB_HK test. 1.7 + * 1.8 + * Sample text is: 1.9 + * 问他谁是傻瓜了5分钟。但是,他谁不要求仍然是一个傻瓜永远 1.10 + * 我听见 我忘记; 我看见 我记住; 我做 我了解。 1.11 + */ 1.12 + 1.13 +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~}"; 1.14 + 1.15 +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"; 1.16 + 1.17 +const charset="HZ-GB-2312"; 1.18 + 1.19 +function testCase(bufferLength) 1.20 +{ 1.21 + var dataURI = "data:text/plain;charset=" + charset + "," + sample; 1.22 + 1.23 + var IOService = Components.Constructor("@mozilla.org/network/io-service;1", 1.24 + "nsIIOService"); 1.25 + var ConverterInputStream = 1.26 + Components.Constructor("@mozilla.org/intl/converter-input-stream;1", 1.27 + "nsIConverterInputStream", 1.28 + "init"); 1.29 + 1.30 + var ios = new IOService(); 1.31 + var channel = ios.newChannel(dataURI, "", null); 1.32 + var testInputStream = channel.open(); 1.33 + var testConverter = new ConverterInputStream(testInputStream, 1.34 + charset, 1.35 + bufferLength, 1.36 + 0xFFFD); 1.37 + 1.38 + if (!(testConverter instanceof 1.39 + Components.interfaces.nsIUnicharLineInputStream)) 1.40 + throw "not line input stream"; 1.41 + 1.42 + var outStr = ""; 1.43 + var more; 1.44 + do { 1.45 + // read the line and check for eof 1.46 + var line = {}; 1.47 + more = testConverter.readLine(line); 1.48 + outStr += line.value; 1.49 + } while (more); 1.50 + 1.51 + if (outStr != expected) { 1.52 + dump("Failed with bufferLength = " + bufferLength + "\n"); 1.53 + if (outStr.length == expected.length) { 1.54 + for (i = 0; i < outStr.length; ++i) { 1.55 + if (outStr.charCodeAt(i) != expected.charCodeAt(i)) { 1.56 + dump(i + ": " + outStr.charCodeAt(i).toString(16) + " != " + expected.charCodeAt(i).toString(16) + "\n"); 1.57 + } 1.58 + } 1.59 + } 1.60 + } 1.61 + 1.62 + // escape the strings before comparing for better readability 1.63 + do_check_eq(escape(outStr), escape(expected)); 1.64 +} 1.65 + 1.66 +function run_test() 1.67 +{ 1.68 + testCase(32); 1.69 + testCase(33); 1.70 +}