diff options
author | Jesse Wilson <jessewilson@google.com> | 2011-01-10 18:17:07 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2011-01-10 18:17:07 -0800 |
commit | 9c075bb3e84c6eaafd016cbc1bf69a6e989eedf3 (patch) | |
tree | 56795a72498b26c7df1082ee8266b63c34c537a8 /luni/src/test/java/tests/xml/DomTest.java | |
parent | 5c0408af32a2b1c78b2d5a93cca60b0fffddd7da (diff) | |
download | libcore-9c075bb3e84c6eaafd016cbc1bf69a6e989eedf3.zip libcore-9c075bb3e84c6eaafd016cbc1bf69a6e989eedf3.tar.gz libcore-9c075bb3e84c6eaafd016cbc1bf69a6e989eedf3.tar.bz2 |
Fix cloneNode to work when no namespace is set.
Change-Id: I0bcbc79832f06613c82f93c0f8805a43a1cf2094
http://code.google.com/p/android/issues/detail?id=2735
Diffstat (limited to 'luni/src/test/java/tests/xml/DomTest.java')
-rw-r--r-- | luni/src/test/java/tests/xml/DomTest.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/luni/src/test/java/tests/xml/DomTest.java b/luni/src/test/java/tests/xml/DomTest.java index 8477676..3f68d7c 100644 --- a/luni/src/test/java/tests/xml/DomTest.java +++ b/luni/src/test/java/tests/xml/DomTest.java @@ -805,6 +805,60 @@ public class DomTest extends TestCase { } } + public void testValueOfNewAttributesIsEmptyString() { + assertEquals("", document.createAttribute("bar").getValue()); + assertEquals("", document.createAttributeNS("http://foo", "bar").getValue()); + } + + public void testCloneNode() throws Exception { + document = builder.parse(new InputSource(new StringReader("<menu " + + "xmlns:f=\"http://food\" xmlns:a=\"http://addons\">" + + "<f:item a:standard=\"strawberry\" deluxe=\"yes\">Waffles</f:item></menu>"))); + name = (Element) document.getFirstChild().getFirstChild(); + + Element clonedName = (Element) name.cloneNode(true); + assertNull(clonedName.getParentNode()); + assertNull(clonedName.getNextSibling()); + assertNull(clonedName.getPreviousSibling()); + assertEquals("http://food", clonedName.getNamespaceURI()); + assertEquals("f:item", clonedName.getNodeName()); + assertEquals("item", clonedName.getLocalName()); + assertEquals("http://food", clonedName.getNamespaceURI()); + assertEquals("yes", clonedName.getAttribute("deluxe")); + assertEquals("strawberry", clonedName.getAttribute("a:standard")); + assertEquals("strawberry", clonedName.getAttributeNS("http://addons", "standard")); + assertEquals(1, name.getChildNodes().getLength()); + + Text clonedChild = (Text) clonedName.getFirstChild(); + assertSame(clonedName, clonedChild.getParentNode()); + assertNull(clonedChild.getNextSibling()); + assertNull(clonedChild.getPreviousSibling()); + assertEquals("Waffles", clonedChild.getTextContent()); + } + + /** + * We can't use the namespace-aware factory method for non-namespace-aware + * nodes. http://code.google.com/p/android/issues/detail?id=2735 + */ + public void testCloneNodeNotNamespaceAware() throws Exception { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(false); + builder = factory.newDocumentBuilder(); + document = builder.parse(new InputSource(new StringReader("<menu " + + "xmlns:f=\"http://food\" xmlns:a=\"http://addons\">" + + "<f:item a:standard=\"strawberry\" deluxe=\"yes\">Waffles</f:item></menu>"))); + name = (Element) document.getFirstChild().getFirstChild(); + + Element clonedName = (Element) name.cloneNode(true); + assertNull(clonedName.getNamespaceURI()); + assertEquals("f:item", clonedName.getNodeName()); + assertNull(clonedName.getLocalName()); + assertNull(clonedName.getNamespaceURI()); + assertEquals("yes", clonedName.getAttribute("deluxe")); + assertEquals("strawberry", clonedName.getAttribute("a:standard")); + assertEquals("", clonedName.getAttributeNS("http://addons", "standard")); + } + /** * A shallow clone requires cloning the attributes but not the child nodes. */ |