Tests for bug 563618
authorSimon Montagu <smontagu@smontagu.org>
Tue, 11 May 2010 17:38:25 +0300
changeset 42129 93874cf6d6ba752200d0b4821a720058aaa2ca86
parent 42128 96edff6785272e6279a34136f382dbaf1b60990a
child 42130 0841ec7eec87b7a462cd8fa7a44d33cebe0aae79
push idunknown
push userunknown
push dateunknown
bugs563618
milestone1.9.3a5pre
Tests for bug 563618
intl/uconv/crashtests/563618.html
intl/uconv/crashtests/crashtests.list
intl/uconv/tests/unit/test_bug563618.js
testing/crashtest/crashtests.list
new file mode 100644
--- /dev/null
+++ b/intl/uconv/crashtests/563618.html
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+  <meta content="text/html; charset=euc-jp"
+ http-equiv="content-type">
+  <title>Serbian Glyph Test</title>
+</head>
+<body>
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
+  <p style="font-size: 20pt;"></p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/intl/uconv/crashtests/crashtests.list
@@ -0,0 +1,1 @@
+load 563618.html
new file mode 100644
--- /dev/null
+++ b/intl/uconv/tests/unit/test_bug563618.js
@@ -0,0 +1,79 @@
+/* Test case for bug 563618
+ *
+ * Uses nsIConverterInputStream to decode invalid EUC-JP text
+ *
+ */
+
+const test = [
+// 0: 0x8e followed by hi byte, not valid JIS X 0201
+	      ["abcdefghijklmnopqrstuvwxyz12test00%8e%80foobar",
+//    expected: one replacement character, invalid byte eaten
+               "abcdefghijklmnopqrstuvwxyz12test00\uFFFDfoobar"],
+// 1: 0x8e followed by ASCII
+	      ["abcdefghijklmnopqrstuvwxyz12test01%8efoobar",
+//    expected: one replacement character, invalid byte not eaten
+               "abcdefghijklmnopqrstuvwxyz12test01\uFFFDfoobar"],
+// 2: JIS X 0208 lead byte followed by invalid hi byte
+              ["abcdefghijklmnopqrstuvwxyz12test02%bf%80foobar",
+//    expected: one replacement character, invalid byte eaten
+	       "abcdefghijklmnopqrstuvwxyz12test02\uFFFDfoobar"],
+// 3: JIS X 0208 lead byte followed by ASCII
+              ["abcdefghijklmnopqrstuvwxyz12test03%bffoobar",
+//    expected: one replacement character, invalid byte not eaten
+	       "abcdefghijklmnopqrstuvwxyz12test03\uFFFDfoobar"]];
+
+const IOService = Components.Constructor("@mozilla.org/network/io-service;1",
+                                         "nsIIOService");
+const ConverterInputStream =
+      Components.Constructor("@mozilla.org/intl/converter-input-stream;1",
+                             "nsIConverterInputStream",
+                             "init");
+const ios = new IOService();
+
+function testCase(testText, expectedText, bufferLength, charset)
+{
+  var dataURI = "data:text/plain;charset=" + charset + "," + testText;
+
+  var channel = ios.newChannel(dataURI, "", null);
+  var testInputStream = channel.open();
+  var testConverter = new ConverterInputStream(testInputStream,
+                                               charset,
+                                               bufferLength,
+                                               0xFFFD);
+
+  if (!(testConverter instanceof
+        Components.interfaces.nsIUnicharLineInputStream))
+    throw "not line input stream";
+
+  var outStr = "";
+  var more;
+  do {
+    // read the line and check for eof
+    var line = {};
+    more = testConverter.readLine(line);
+    outStr += line.value;
+  } while (more);
+
+  if (outStr != expectedText) {
+    dump("Failed with bufferLength = " + bufferLength + "\n");
+    if (outStr.length == expectedText.length) {
+      for (i = 0; i < outStr.length; ++i) {
+	if (outStr.charCodeAt(i) != expectedText.charCodeAt(i)) {
+	  dump(i + ": " + outStr.charCodeAt(i).toString(16) + " != " + expectedText.charCodeAt(i).toString(16) + "\n");
+	}
+      }
+    }
+  }
+
+  // escape the strings before comparing for better readability
+  do_check_eq(escape(outStr), escape(expectedText));
+}
+
+function run_test()
+{
+  for (var i = 0; i < test.length; ++i) {
+    for (var bufferLength = 32; bufferLength < 40; ++ bufferLength) {
+      testCase(test[i][0], test[i][1], bufferLength, "EUC-JP");
+    }
+  }
+}
--- a/testing/crashtest/crashtests.list
+++ b/testing/crashtest/crashtests.list
@@ -28,16 +28,17 @@ include ../../dom/src/jsurl/crashtests/c
 
 include ../../editor/libeditor/html/crashtests/crashtests.list
 include ../../editor/libeditor/base/crashtests/crashtests.list
 include ../../editor/libeditor/text/crashtests/crashtests.list
 include ../../editor/composer/src/crashtests/crashtests.list
 include ../../editor/txmgr/tests/crashtests/crashtests.list
 
 include ../../intl/lwbrk/src/crashtests/crashtests.list
+include ../../intl/uconv/crashtests/crashtests.list
 
 include ../../js/src/xpconnect/crashtests/crashtests.list
 
 include ../../layout/base/crashtests/crashtests.list
 include ../../layout/forms/crashtests/crashtests.list
 include ../../layout/generic/crashtests/crashtests.list
 include ../../layout/mathml/crashtests/crashtests.list
 include ../../layout/style/crashtests/crashtests.list