*
* @author Philip W. Davis
*/
public void testCharacterData(org.w3c.dom.Document document)
{
CharacterData charData;
String compareData, newData, resetData;
boolean OK = true;
// For debugging***** println("\n testCharacterData's outputs:\n");
charData = (CharacterData) document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // charData gets textNode11
compareData = "dBodyLevel31'sChildTextNode11";
if (!compareData.equals(charData.getData()))
{
System.out.println("Warning!!! CharacterData's 'getData' failed to work properly!\n This may corrupt other CharacterData tests!!!*****");
OK = false;
}
resetData = charData.getData();
// println("This node's original data is: " + charData.getData());
newData = " This is new data for this node";
compareData = charData.getData() + newData;
charData.appendData(newData);
if (!compareData.equals(charData.getData()))
{
System.out.println("Warning!!! CharacterData's 'appendData' failed to work properly!");
OK = false;
}
// println("This node's appended data is: " + charData.getData());
compareData = "dBodyLevel";
charData.deleteData(10, 100);
if (!compareData.equals(charData.getData()))
{
System.out.println("Warning!!! CharacterData's 'deleteData' failed to work properly!");
OK = false;
}
// println("This node's partially deleted data is: " + charData.getData());
int length = 10;
if (!(length == charData.getLength()))
{
System.out.println("Warning!!! CharacterData's 'getLength' failed to work properly!");
OK = false;
}
// println("This node's data length is: " + charData.getLength());
compareData = "dBody' This is data inserted into this node'Level";
charData.insertData(5, "' This is data inserted into this node'");
if (!compareData.equals(charData.getData()))
{
System.out.println("Warning!!! CharacterData's 'insertData' failed to work properly!");
OK = false;
}
// println("This node's updated with insert data is: " + charData.getData());
compareData = "dBody' This is ' replacement data'ted into this node'Level";
charData.replaceData(15, 10, "' replacement data'");
if (!compareData.equals(charData.getData()))
{
System.out.println("Warning!!! CharacterData's 'replaceData' failed to work properly!");
OK = false;
}
// println("This node's updated with replacement data is: " +charData.getData());
compareData = "New data A123456789B123456789C123456789D123456789E123456789";
charData.setData("New data A123456789B123456789C123456789D123456789E123456789");
if (!compareData.equals(charData.getData()))
{
System.out.println("Warning!!! CharacterData's 'setData' failed to work properly!");
OK = false;
}
// println("This node's new data via setData: " + charData.getData());
compareData = "123456789D123456789E123456789";
if (!compareData.equals(charData.substringData(30, 30)))
{
System.out.println("Warning!!! CharacterData's 'substringData' failed to work properly!");
OK = false;
}
// println("Using subString 30,30 you get:" + charData.substringData(30,30));
compareData = "New data A123456789B12345";
if (!compareData.equals(charData.substringData(0, 25)))
{
System.out.println("Warning!!! CharacterData's 'substringData' failed to work properly!");
OK = false;
}
// println("Using subString 0,25 you get:" + charData.substringData(0,25));
//************************************************* ERROR TESTS
DTest tests = new DTest();
//!! Throws INDEX_SIZE_ERR ********************
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "deleteData", new Class[]{int.class, int.class},
new Object[]{new Integer(-1),new Integer(5) }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "deleteData", new Class[]{int.class, int.class},
new Object[]{new Integer(2),new Integer(-1) }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "deleteData", new Class[]{int.class, int.class},
new Object[]{new Integer(100),new Integer(5) }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "insertData", new Class[]{int.class, String.class},
new Object[]{new Integer(-1),"Stuff inserted" }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "insertData", new Class[]{int.class, String.class},
new Object[]{new Integer(100),"Stuff inserted" }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "replaceData", new Class[]{int.class, int.class, String.class},
new Object[]{new Integer(-1),new Integer(5),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "replaceData", new Class[]{int.class, int.class, String.class},
new Object[]{new Integer(100),new Integer(5),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "replaceData", new Class[]{int.class, int.class, String.class},
new Object[]{new Integer(2),new Integer(-1),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "substringData", new Class[]{int.class, int.class},
new Object[]{new Integer(-1),new Integer(5) }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "substringData", new Class[]{int.class, int.class},
new Object[]{new Integer(100),new Integer(5) }, DOMException.INDEX_SIZE_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(charData, "substringData", new Class[]{int.class, int.class},
new Object[]{new Integer(2),new Integer(-1) }, DOMException.INDEX_SIZE_ERR ));
//!! Throws NO_MODIFICATION_ALLOWED_ERR ********
Node node = document.getDocumentElement().getElementsByTagName("dBodyLevel24").item(0).getFirstChild().getChildNodes().item(0); // node gets ourEntityReference node's child text
OK &= Assertion.verify(DTest.DOMExceptionsTest(node, "appendData", new Class[]{String.class},
new Object[]{"new data" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(node, "deleteData", new Class[]{int.class, int.class},
new Object[]{new Integer(5),new Integer(10) }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(node, "insertData", new Class[]{int.class, String.class},
new Object[]{new Integer(5),"Stuff inserted" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(node, "replaceData", new Class[]{int.class, int.class, String.class},
new Object[]{new Integer(5),new Integer(10),"Replacementstuff" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
OK &= Assertion.verify(DTest.DOMExceptionsTest(node, "setData", new Class[]{String.class},
new Object[]{"New setdata stuff"}, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
// For debugging***** println("All CharacterData method calls worked correctly.");
if (!OK)
System.out.println("\n*****The CharacterData method calls listed above failed, all others worked correctly.*****");
charData.setData(resetData); // reset node to original data
// println("");
}