Assertion.verify(((NodeImpl) dt).getTextContent() == null);
// no-ops:
((NodeImpl) doc).setTextContent("foo");
((NodeImpl) dt).setTextContent("foo");
NodeImpl el = (NodeImpl) doc.getDocumentElement();
Assertion.equals(((NodeImpl) el).getTextContent(), "");
el.setTextContent("yo!");
Node t = el.getFirstChild();
Assertion.verify(t != null && t.getNodeType() == Node.TEXT_NODE &&
t.getNodeValue().equals("yo!"));
Assertion.equals(el.getTextContent(), "yo!");
Comment c = doc.createComment("dummy");
el.appendChild(c);
NodeImpl el2 = (NodeImpl) doc.createElement("bar");
el2.setTextContent("bye now");
el.appendChild(el2);
Assertion.equals(el.getTextContent(), "yo!bye now");
// check that empty element does not produce null value
NodeImpl el3 = (NodeImpl) doc.createElement("test");
el.appendChild(el3);
NodeImpl empty = (NodeImpl) doc.createElement("empty");
el3.appendChild(empty);
Assertion.verify(el3.getTextContent() != null);
empty.setTextContent("hello");
Assertion.verify(empty.getChildNodes().getLength() == 1);
// check that setting to empty string or null, does not produce
// any text node
empty.setTextContent(null);
Assertion.verify(empty.getChildNodes().getLength() == 0);
empty.setTextContent("");
Assertion.verify(empty.getChildNodes().getLength() == 0);
class MyHandler implements UserDataHandler {
boolean fCalled;
Node fNode;
String fKey;
Object fData;
MyHandler(String key, Object data, Node node) {
fCalled = false;
fKey = key;
fData = data;
fNode = node;
}
public void handle(short operation, String key,
Object data, Node src, Node dst) {
Assertion.verify(operation == UserDataHandler.NODE_CLONED);
Assertion.verify(key == fKey && data == fData && src == fNode);
Assertion.verify(dst != null &&
dst.getNodeType() == fNode.getNodeType());
fCalled = true;
}
}
el.setUserData("mykey", c, null);
el.setUserData("mykey2", el2, null);
Assertion.verify(el.getUserData("mykey") == c);
Assertion.verify(el.getUserData("mykey2") == el2);
el.setUserData("mykey", null, null);
Assertion.verify(el.getUserData("mykey") == null);
el.setUserData("mykey2", null, null);
Assertion.verify(el.getUserData("mykey2") == null);
MyHandler h = new MyHandler("mykey", c, el);
el.setUserData("mykey", c, h);
MyHandler h2 = new MyHandler("mykey2", el2, el);
el.setUserData("mykey2", el2, h2);
Node cl = el.cloneNode(false);
Assertion.verify(h.fCalled == true);
Assertion.verify(h2.fCalled == true);
el.setTextContent("zapped!");
Node t2 = el.getFirstChild();
Assertion.verify(t2.getNodeValue().equals("zapped!"));
Assertion.verify(t2.getNextSibling() == null);
}
//
// isEqualNode
// Note: we rely on setTextContent to work properly, in case of errors
// make sure it is the case first.
{
DOMImplementation impl = DOMImplementationImpl.getDOMImplementation();
Document doc = impl.createDocument(null, "root", null);
NodeImpl root = (NodeImpl) doc.getDocumentElement();
NodeImpl n1 = (NodeImpl) doc.createElement("el");
n1.setTextContent("yo!");
NodeImpl n2 = (NodeImpl) doc.createElement("el");
n2.setTextContent("yo!");
Assertion.verify(n1.isEqualNode(n2) == true);
n2.setTextContent("yoyo!");
Assertion.verify(n1.isEqualNode(n2) == false);
n1.setTextContent("yoyo!");
((Element) n1).setAttribute("a1", "v1");
((Element) n1).setAttributeNS("uri", "a2", "v2");
((Element) n2).setAttribute("a1", "v1");
((Element) n2).setAttributeNS("uri", "a2", "v2");
Assertion.verify(n1.isEqualNode(n2) == true);
Element elem = doc.createElementNS(null, "e2");
root.appendChild(elem);
Attr attr = doc.createAttributeNS("http://attr", "attr1");
elem.setAttributeNode(attr);
// check that setAttribute sets both name and value
elem.setAttributeNS("http://attr","p:attr1","v2");
Attr attr2 = elem.getAttributeNodeNS("http://attr", "attr1");
Assertion.verify(attr2.getNodeName().equals("p:attr1"), "p:attr1");
Assertion.verify(attr2.getNodeValue().equals("v2"), "value v2");
// check that prefix is not null
elem.setAttributeNS("http://attr","attr1","v2");
attr2 = elem.getAttributeNodeNS("http://attr", "attr1");
Assertion.verify(attr2.getNodeName().equals("attr1"), "attr1");
((Element) n2).setAttribute("a1", "v2");
Assertion.verify(n1.isEqualNode(n2) == false);
root.appendChild(n1);
root.appendChild(n2);
NodeImpl clone = (NodeImpl) root.cloneNode(true);
Assertion.verify(clone.isEqualNode(root) == true);
}
System.out.println("done.");
};