intl/uconv/tests/unit/test_iso2022KR.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* Test case for ISO-2022-KR
michael@0 2 *
michael@0 3 * Uses nsIConverterInputStream to decode ISO-2022-KR text.
michael@0 4 *
michael@0 5 * Sample text is:
michael@0 6 * 1: 소 잃고 외양간 고친다
michael@0 7 * 2: 빈 수레가 요란하다
michael@0 8 * 3: 하늘의 별 따기
michael@0 9 * 4: 아는 길도 물어가라
michael@0 10 *
michael@0 11 * (From http://en.wikiquote.org/wiki/Korean_proverbs)
michael@0 12 */
michael@0 13
michael@0 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";
michael@0 15
michael@0 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";
michael@0 17
michael@0 18 const charset="ISO-2022-KR";
michael@0 19
michael@0 20 function testCase(bufferLength)
michael@0 21 {
michael@0 22 var dataURI = "data:text/plain;charset=" + charset + "," + sample;
michael@0 23
michael@0 24 var IOService = Components.Constructor("@mozilla.org/network/io-service;1",
michael@0 25 "nsIIOService");
michael@0 26 var ConverterInputStream =
michael@0 27 Components.Constructor("@mozilla.org/intl/converter-input-stream;1",
michael@0 28 "nsIConverterInputStream",
michael@0 29 "init");
michael@0 30
michael@0 31 var ios = new IOService();
michael@0 32 var channel = ios.newChannel(dataURI, "", null);
michael@0 33 var testInputStream = channel.open();
michael@0 34 var testConverter = new ConverterInputStream(testInputStream,
michael@0 35 charset,
michael@0 36 bufferLength,
michael@0 37 0xFFFD);
michael@0 38
michael@0 39 if (!(testConverter instanceof
michael@0 40 Components.interfaces.nsIUnicharLineInputStream))
michael@0 41 throw "not line input stream";
michael@0 42
michael@0 43 var outStr = "";
michael@0 44 var more;
michael@0 45 do {
michael@0 46 // read the line and check for eof
michael@0 47 var line = {};
michael@0 48 more = testConverter.readLine(line);
michael@0 49 outStr += line.value + "\n";
michael@0 50 } while (more);
michael@0 51
michael@0 52 if (outStr != expected) {
michael@0 53 dump("Failed with bufferLength = " + bufferLength + "\n");
michael@0 54 if (outStr.length == expected.length) {
michael@0 55 for (i = 0; i < outStr.length; ++i) {
michael@0 56 if (outStr.charCodeAt(i) != expected.charCodeAt(i)) {
michael@0 57 dump(i + ": " + outStr.charCodeAt(i).toString(16) + " != " + expected.charCodeAt(i).toString(16) + "\n");
michael@0 58 }
michael@0 59 }
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 // escape the strings before comparing for better readability
michael@0 64 do_check_eq(escape(outStr), escape(expected));
michael@0 65 }
michael@0 66
michael@0 67 function run_test()
michael@0 68 {
michael@0 69 testCase(34);
michael@0 70 testCase(35);
michael@0 71 }

mercurial