OSDN Git Service

Fix Node.getNextSibling bounds checking.
authorElliott Hughes <enh@google.com>
Thu, 24 Sep 2009 00:01:24 +0000 (17:01 -0700)
committerElliott Hughes <enh@google.com>
Fri, 25 Sep 2009 18:03:05 +0000 (11:03 -0700)
Obvious copy & paste error in InnerNodeImpl compared to LeafNodeImpl, plus
new test.

I've also fixed a typo that annoys me whenever I look at the XML test results,
and removed a KnownFailure for a test that passes (and has been passing for
some time).

Bug: 779

libcore/xml/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java
libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java
libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTestSupport.java
libcore/xml/src/test/java/tests/xml/AllTests.java
libcore/xml/src/test/java/tests/xml/NodeTests.java [new file with mode: 0644]

index f71d289..2fd16d0 100644 (file)
@@ -69,7 +69,7 @@ public abstract class InnerNodeImpl extends LeafNodeImpl {
     }
 
     public Node getNextSibling() {
-        if (parent == null || index >= parent.children.size()) {
+        if (parent == null || index + 1 >= parent.children.size()) {
             return null;
         }
 
index c515d20..292c2f1 100644 (file)
@@ -278,7 +278,6 @@ public class DocumentBuilderTest extends TestCase {
         method = "parse",
         args = {java.io.File.class}
     )
-    @KnownFailure("d.getChildNodes returns an unexpected/strange #Text node")
     public void test_parseLjava_io_File() throws IOException {
         File f = resourceToTmpFile("/simple.xml");
 
index bc5e6a1..a1627ba 100644 (file)
@@ -54,7 +54,7 @@ class SAXParserTestSupport {
     public static final String KEY_ERROR = "error";
     public static final String KEY_FATAL_ERROR = "fatalError";
     public static final String KEY_WARNING = "warning";
-    public static final String KEY_END_ELEMENT = "endEement";
+    public static final String KEY_END_ELEMENT = "endElement";
     public static final String KEY_END_PREFIX_MAPPING = "endPrefixMapping";
     public static final String KEY_IGNORABLE_WHITE_SPACE = 
         "ignorableWhitespace";
index eefae50..8c089e3 100644 (file)
@@ -26,6 +26,7 @@ public class AllTests {
 
         suite.addTestSuite(SimpleParserTest.class);
         suite.addTestSuite(SimpleBuilderTest.class);
+        suite.addTestSuite(NodeTests.class);
         
         //suite.addTest(tests.org.w3c.dom.AllTests.suite());
         suite.addTest(tests.api.javax.xml.parsers.AllTests.suite());
diff --git a/libcore/xml/src/test/java/tests/xml/NodeTests.java b/libcore/xml/src/test/java/tests/xml/NodeTests.java
new file mode 100644 (file)
index 0000000..e46e216
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.xml;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import java.io.ByteArrayInputStream;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+@TestTargetClass(Node.class)
+public class NodeTests extends TestCase {
+    @TestTargetNew(
+        level = TestLevel.PARTIAL,
+        notes = "Issue #779: org.w3c.dom.Node#getNextSibling throws IndexOutOfBoundsException.",
+        method = "getNextSibling",
+        args = {}
+    )
+    public void test_getNextSibling() throws Exception {
+        // Calling getNextSibling when there is no next sibling should return null.
+        // From http://code.google.com/p/android/issues/detail?id=779.
+        ByteArrayInputStream bis = new ByteArrayInputStream("<root/>".getBytes());
+        Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bis);
+        Node root = document.getDocumentElement();
+        assertNull(root.getNextSibling());
+    }
+}