intl/uconv/tests/unit/test_bug449578.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Tests conversion from ISO-2022-KR to Unicode (bug 449578)
     2  */
     4 // designator sequence at beginning of line - legal
     5 const in1 = "%1B$)C%0E0!3*4Y6s%0F 1234";     
     6 // empty non-ASCII sequence -- illegal
     7 const in2 = "%1B$)Cab%0E%0Fcd";
     8 // designator sequence not at beginning of line - illegal
     9 const in3 = "abc %1B$)C%0E0!3*4Y6s%0F 1234";
    11 const expected1 = "\uAC00\uB098\uB2E4\uB77C 1234";
    12 const expected2 = "ab\uFFFD\cd";
    13 const expected3 = "abc \u001B$)C\uAC00\uB098\uB2E4\uB77C 1234";
    15 function testCase(inStr, expected)
    16 {
    17     var dataURI = "data:text/plain;charset=ISO-2022-KR," + inStr;
    19     var IOService = Components.Constructor("@mozilla.org/network/io-service;1",
    20 					 "nsIIOService");
    21     var ConverterInputStream =
    22 	Components.Constructor("@mozilla.org/intl/converter-input-stream;1",
    23 			       "nsIConverterInputStream",
    24 			       "init");
    26     var ios = new IOService();
    27     var channel = ios.newChannel(dataURI, "", null);
    28     var testInputStream = channel.open();
    29     var testConverter = new ConverterInputStream(testInputStream,
    30 						 "ISO-2022-KR",
    31 						 8192,
    32 						 0xFFFD);
    34     if (!(testConverter instanceof
    35 	  Components.interfaces.nsIUnicharLineInputStream))
    36 	throw "not line input stream";
    38     var outStr = "";
    39     var more;
    40     do {
    41 	// read the line and check for eof
    42 	var line = {};
    43 	more = testConverter.readLine(line);
    44 	outStr += line.value;
    45     } while (more);
    47     do_check_eq(outStr, expected);
    48 }
    50 function run_test()
    51 {
    52     testCase(in1, expected1);
    53     testCase(in2, expected2);
    54     testCase(in3, expected3);
    55 }

mercurial