1 /* $Id: DTest.java,v 1.1.1.1 2000/10/07 00:26:16 markd Exp $ */ 2 /* 3 * The Apache Software License, Version 1.1 4 * 5 * Copyright (c) 1999 The Apache Software Foundation. All rights 6 * reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The end-user documentation included with the redistribution, 21 * if any, must include the following acknowledgment: 22 * "This product includes software developed by the 23 * Apache Software Foundation (http://www.apache.org/)." 24 * Alternately, this acknowledgment may appear in the software itself, 25 * if and wherever such third-party acknowledgments normally appear. 26 * 27 * 4. The names "Xerces" and "Apache Software Foundation" must 28 * not be used to endorse or promote products derived from this 29 * software without prior written permission. For written 30 * permission, please contact apache\@apache.org. 31 * 32 * 5. Products derived from this software may not be called "Apache", 33 * nor may "Apache" appear in their name, without prior written 34 * permission of the Apache Software Foundation. 35 * 36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 39 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 43 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 46 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47 * SUCH DAMAGE. 48 * ==================================================================== 49 * 50 * This software consists of voluntary contributions made by many 51 * individuals on behalf of the Apache Software Foundation, and was 52 * originally based on software copyright (c) 1999, International 53 * Business Machines, Inc., http://www.ibm.com . For more information 54 * on the Apache Software Foundation, please see 55 * <http://www.apache.org/>. 56 */ 57 58 package dom; 59 60 import org.w3c.dom; 61 import java.lang.reflect; 62 import java.io.StringWriter; 63 import java.io.PrintWriter; 64 import dom.util.Assertion; 65 66 /** 67 * This class tests methods for XML DOM implementation 68 * version 2.0 10/12/98 69 * 70 * DOMException errors are tested by calls to DOMExceptionsTest from: Main, docBuilder... 71 * 72 * @author Philip W. Davis 73 */ 74 75 public class DTest { 76 77 public static Element testElementNode; 78 public static Attr testAttributeNode; 79 public static Text testTextNode; 80 public static CDATASection testCDATASectionNode; 81 public static EntityReference testEntityReferenceNode; 82 public static Entity testEntityNode; 83 public static ProcessingInstruction testProcessingInstructionNode; 84 public static Comment testCommentNode; 85 public static Document testDocumentNode; 86 public static DocumentType testDocumentTypeNode; 87 public static DocumentFragment testDocumentFragmentNode; 88 public static Notation testNotationNode; 89 90 /** 91 * 92 * version 2.0 10/12/98 93 * 94 * @author Philip W. Davis 95 */ 96 public DTest() { 97 super(); 98 99 } 100 /** 101 * version 3.0 01/25/99 102 * 103 * @return org.w3c.dom.Document 104 * 105 * @author Philip W. Davis 106 */ 107 public Document createDocument() { 108 return new org.apache.xerces.dom.DocumentImpl(); //Replace with a Document creator 109 } 110 /** 111 * version 3.0 01/25/99 112 * 113 * @return org.w3c.dom.DocumentType 114 * @param name java.lang.String 115 * 116 * @author Philip W. Davis 117 */ 118 public DocumentType createDocumentType(Document doc, String name) { 119 return ((org.apache.xerces.dom.DocumentImpl) doc).createDocumentType(name, null, null); //Replace with a DocumentType creator 120 } 121 /** 122 * version 3.0 01/25/99 123 * 124 * @return org.w3c.dom.Entity 125 * @param doc org.w3c.dom.Document 126 * @param name java.lang.String 127 * 128 * @author Philip W. Davis 129 */ 130 public Entity createEntity(Document doc, String name) { 131 return new org.apache.xerces.dom.EntityImpl((org.apache.xerces.dom.DocumentImpl)doc, name); //Replace with an Entity creator 132 } 133 /** 134 * version 3.0 01/25/99 135 * 136 * @return org.w3c.dom.Notation 137 * @param doc org.w3c.dom.Document 138 * @param name java.lang.String 139 * 140 * @author Philip W. Davis 141 */ 142 public Notation createNotation(Document doc, String name) { 143 return new org.apache.xerces.dom.NotationImpl((org.apache.xerces.dom.DocumentImpl) doc, name); // Replace with a Notation creator 144 } 145 /** 146 * This method builds test documents for the XML DOM implementation 147 * version 2.0 10/12/98 148 * @param document org.w3c.dom.Document 149 * @param name document's name 150 * @param type document's type 151 * 152 * @author Philip W. Davis 153 */ 154 public void docBuilder(org.w3c.dom.Document document, String name) 155 { 156 Document doc = document; 157 boolean OK = true; 158 159 Element docFirstElement = doc.createElement(name + "FirstElement"); 160 doc.appendChild(docFirstElement); 161 docFirstElement.setAttribute(name + "FirstElement", name + "firstElement"); 162 163 ProcessingInstruction docProcessingInstruction = doc.createProcessingInstruction(name + 164 "TargetProcessorChannel", "This is " + doc + "'s processing instruction"); 165 docFirstElement.appendChild(docProcessingInstruction); 166 167 Element docBody = doc.createElement(name + "TestBody"); 168 docFirstElement.appendChild(docBody); 169 170 Element docBodyLevel21 = doc.createElement(name + "BodyLevel21"); 171 Element docBodyLevel22 = doc.createElement(name + "BodyLevel22"); 172 Element docBodyLevel23 = doc.createElement(name + "BodyLevel23"); 173 Element docBodyLevel24 = doc.createElement(name + "BodyLevel24"); 174 docBody.appendChild(docBodyLevel21); 175 docBody.appendChild(docBodyLevel22); 176 docBody.appendChild(docBodyLevel23); 177 docBody.appendChild(docBodyLevel24); 178 179 Element docBodyLevel31 = doc.createElement(name + "BodyLevel31"); 180 Element docBodyLevel32 = doc.createElement(name + "BodyLevel32"); 181 Element docBodyLevel33 = doc.createElement(name + "BodyLevel33"); 182 Element docBodyLevel34 = doc.createElement(name + "BodyLevel34"); 183 docBodyLevel21.appendChild(docBodyLevel31); 184 docBodyLevel21.appendChild(docBodyLevel32); 185 docBodyLevel22.appendChild(docBodyLevel33); 186 docBodyLevel22.appendChild(docBodyLevel34); 187 188 Text docTextNode11 = doc.createTextNode(name + "BodyLevel31'sChildTextNode11"); 189 Text docTextNode12 = doc.createTextNode(name + "BodyLevel31'sChildTextNode12"); 190 Text docTextNode13 = doc.createTextNode(name + "BodyLevel31'sChildTextNode13"); 191 Text docTextNode2 = doc.createTextNode(name + "TextNode2"); 192 Text docTextNode3 = doc.createTextNode(name + "TextNode3"); 193 Text docTextNode4 = doc.createTextNode(name + "TextNode4"); 194 docBodyLevel31.appendChild(docTextNode11); 195 docBodyLevel31.appendChild(docTextNode12); 196 docBodyLevel31.appendChild(docTextNode13); 197 docBodyLevel32.appendChild(docTextNode2); 198 docBodyLevel33.appendChild(docTextNode3); 199 docBodyLevel34.appendChild(docTextNode4); 200 201 CDATASection docCDATASection = doc.createCDATASection("<![CDATA[<greeting>Hello, world!</greeting>]]>"); 202 docBodyLevel23.appendChild(docCDATASection); 203 204 Comment docComment = doc.createComment("This should be a comment of some kind "); 205 docBodyLevel23.appendChild(docComment); 206 207 EntityReference docReferenceEntity = doc.createEntityReference("ourEntityNode"); 208 docBodyLevel24.appendChild(docReferenceEntity); 209 210 DTest make = new DTest(); 211 Notation docNotation = make.createNotation(doc, "ourNotationNode"); 212 // NotationImpl docNotation = new NotationImpl((DocumentImpl) doc, "ourNotationNode");//*****? 213 DocumentType docType = (DocumentType)doc.getFirstChild(); 214 docType.getNotations().setNamedItem(docNotation); 215 216 DocumentFragment docDocFragment = doc.createDocumentFragment(); 217 218 // System.out.println("This document's first element name is " + docFirstElement.getTagName() + "\n"); 219 220 221 //***********Following are for errorTests 222 Text docNode3 = doc.createTextNode(name + "docTextNode3"); 223 Text docNode4 = doc.createTextNode(name + "docTextNode4"); 224 225 Entity docEntity = (Entity) doc.getDoctype().getEntities().getNamedItem("ourEntityNode"); // Get the Entity node 226 DocumentType docDocType = (DocumentType) doc.getFirstChild(); // Get the DocumentType node 227 EntityReference entityReferenceText = (EntityReference) doc.getLastChild().getLastChild().getLastChild().getFirstChild(); 228 Text entityReferenceText2 = doc.createTextNode("entityReferenceText information"); 229 //************************************************* ERROR TESTS 230 DTest tests = new DTest(); 231 232 OK &= Assertion.assert(tests.DOMExceptionsTest(document, "appendChild", new Class[]{Node.class}, new Object[]{docBody}, DOMException.HIERARCHY_REQUEST_ERR )); 233 OK &= Assertion.assert(tests.DOMExceptionsTest(docNode3, "appendChild", new Class[]{Node.class}, new Object[]{docNode4}, DOMException.HIERARCHY_REQUEST_ERR )); 234 OK &= Assertion.assert(tests.DOMExceptionsTest(doc, "insertBefore", new Class[]{Node.class, Node.class}, new Object[]{docEntity, docFirstElement}, DOMException.HIERARCHY_REQUEST_ERR )); 235 OK &= Assertion.assert(tests.DOMExceptionsTest(doc, "replaceChild", new Class[]{Node.class, Node.class}, new Object[]{docCDATASection, docFirstElement}, DOMException.HIERARCHY_REQUEST_ERR )); 236 237 docFirstElement.setNodeValue("This shouldn't do anything!"); 238 OK &= Assertion.assert(docFirstElement.getNodeValue() == null); 239 docReferenceEntity.setNodeValue("This shouldn't do anything!"); 240 OK &= Assertion.assert(docReferenceEntity.getNodeValue() == null); 241 docEntity.setNodeValue("This shouldn't do anything!"); 242 OK &= Assertion.assert(docEntity.getNodeValue() == null); 243 doc.setNodeValue("This shouldn't do anything!"); 244 OK &= Assertion.assert(doc.getNodeValue() == null); 245 docType.setNodeValue("This shouldn't do anything!"); 246 OK &= Assertion.assert(docType.getNodeValue() == null); 247 docDocFragment.setNodeValue("This shouldn't do anything!"); 248 OK &= Assertion.assert(docDocFragment.getNodeValue() == null); 249 docNotation.setNodeValue("This shouldn't do anything!"); 250 OK &= Assertion.assert(docNotation.getNodeValue() == null); 251 252 OK &= Assertion.assert(tests.DOMExceptionsTest(docReferenceEntity, "appendChild", new Class[]{Node.class}, new Object[]{entityReferenceText2 }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 253 OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "insertBefore", new Class[]{Node.class, Node.class}, new Object[]{docTextNode11,docBody }, DOMException.NOT_FOUND_ERR )); 254 OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "removeChild", new Class[]{Node.class}, new Object[]{docFirstElement}, DOMException.NOT_FOUND_ERR )); 255 OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "replaceChild", new Class[]{Node.class, Node.class}, new Object[]{docTextNode11,docFirstElement }, DOMException.NOT_FOUND_ERR )); 256 257 258 //!! Throws a NOT_FOUND_ERR ******** 259 260 // docBodyLevel32.getAttributes().removeNamedItem(testAttribute.getName()); 16 // To test removeNamedItem 261 262 }//END OF DOCBUILDER 263 /** 264 * version 3.0 01/25/99 265 * 266 * @return boolean 267 * @param node java.lang.Object 268 * @param mNameIndex int 269 * @param signatureIndex int 270 * @param parameters java.lang.Object[] 271 * @param code short 272 * 273 * @author Philip W. Davis 274 */ 275 public static boolean DOMExceptionsTest(Object node, String methodName, Class[] methodSignature, Object[] parameters, short code) { 276 277 278 boolean asExpected = false; 279 Method method; 280 281 try 282 { 283 method = node.getClass().getMethod(methodName,methodSignature); 284 method.invoke(node, parameters); 285 }catch(InvocationTargetException exc) 286 { 287 Throwable realE = exc.getTargetException(); 288 if(realE instanceof DOMException) 289 { 290 asExpected = (((DOMException)realE).code== code); 291 if(!asExpected) 292 System.out.println("Wrong DOMException(" + ((DOMException)realE).code + ")"); 293 } 294 else 295 System.out.println("Wrong Exception (" + code + ")"); 296 297 if(!asExpected) 298 { 299 System.out.println("Expected DOMException (" + code + ") not thrown"); 300 } 301 }catch(Exception exc) 302 { 303 System.out.println("test invocation failure (" + exc + ")"); 304 } 305 306 307 return (asExpected); 308 } 309 310 /** 311 * @author Philip W. Davis 312 * @param document org.w3c.dom.Document 313 */ 314 public void findTestNodes(Document document) { 315 316 317 318 319 Node node = document; 320 int nodeCount = 0; 321 322 // Walk the tree until you find and assign all node types needed that exist. 323 while (node != null && nodeCount < 12) 324 { 325 326 switch (node.getNodeType()) 327 { 328 case org.w3c.dom.Node.ELEMENT_NODE : 329 if (testElementNode == null) {testElementNode = (Element)node; nodeCount++;} 330 break; 331 case org.w3c.dom.Node.ATTRIBUTE_NODE : 332 if (testAttributeNode == null) {testAttributeNode = (Attr)node; nodeCount++;} 333 break; 334 case org.w3c.dom.Node.TEXT_NODE : 335 if (testTextNode == null) {testTextNode = (Text)node; nodeCount++;} 336 break; 337 case org.w3c.dom.Node.CDATA_SECTION_NODE : 338 if (testCDATASectionNode == null) {testCDATASectionNode = (CDATASection)node; nodeCount++;} 339 break; 340 case org.w3c.dom.Node.ENTITY_REFERENCE_NODE : 341 if (testEntityReferenceNode == null) {testEntityReferenceNode = (EntityReference)node; nodeCount++;} 342 break; 343 case org.w3c.dom.Node.ENTITY_NODE : 344 if (testEntityNode == null) {testEntityNode = (Entity)node; nodeCount++;} 345 break; 346 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE : 347 if (testProcessingInstructionNode == null) {testProcessingInstructionNode = (ProcessingInstruction)node; nodeCount++;} 348 break; 349 case org.w3c.dom.Node.COMMENT_NODE : 350 if (testCommentNode == null) {testCommentNode = (Comment)node; nodeCount++;} 351 break; 352 case org.w3c.dom.Node.DOCUMENT_TYPE_NODE : 353 if (testDocumentTypeNode == null) {testDocumentTypeNode = (DocumentType)node; nodeCount++;} 354 break; 355 case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE : 356 if (testDocumentFragmentNode == null) {testDocumentFragmentNode = (DocumentFragment)node; nodeCount++;} 357 break; 358 case org.w3c.dom.Node.NOTATION_NODE : 359 if (testNotationNode == null) {testNotationNode = (Notation)node; nodeCount++;} 360 break; 361 case org.w3c.dom.Node.DOCUMENT_NODE : 362 if (testDocumentNode == null) {testDocumentNode = (Document)node; nodeCount++;} 363 break; 364 default: 365 }// End of switch 366 367 368 369 370 }// End of while 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 } 387 388 /** 389 * @author Philip W. Davis 390 * @param document org.w3c.dom.Document 391 */ 392 public void findTestNodes(Node node) { 393 394 DTest test = new DTest(); 395 Node kid; 396 // Walk the tree until you find and assign all node types needed that exist. 397 398 399 if (node.getFirstChild() != null) 400 { 401 kid = node.getFirstChild(); 402 test.findTestNodes(kid); 403 } 404 405 406 if (node.getNextSibling() != null) 407 { 408 kid = node.getNextSibling(); 409 test.findTestNodes(kid); 410 } 411 412 413 switch (node.getNodeType()) 414 { 415 case org.w3c.dom.Node.ELEMENT_NODE : 416 if (testElementNode == null) {testElementNode = (Element)node; } 417 break; 418 case org.w3c.dom.Node.ATTRIBUTE_NODE : 419 if (testAttributeNode == null) {testAttributeNode = (Attr)node; } 420 break; 421 case org.w3c.dom.Node.TEXT_NODE : 422 if (testTextNode == null) {testTextNode = (Text)node; } 423 break; 424 case org.w3c.dom.Node.CDATA_SECTION_NODE : 425 if (testCDATASectionNode == null) {testCDATASectionNode = (CDATASection)node; } 426 break; 427 case org.w3c.dom.Node.ENTITY_REFERENCE_NODE : 428 if (testEntityReferenceNode == null) {testEntityReferenceNode = (EntityReference)node;} 429 break; 430 case org.w3c.dom.Node.ENTITY_NODE : 431 if (testEntityNode == null) {testEntityNode = (Entity)node;} 432 break; 433 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE : 434 if (testProcessingInstructionNode == null) {testProcessingInstructionNode = (ProcessingInstruction)node;} 435 break; 436 case org.w3c.dom.Node.COMMENT_NODE : 437 if (testCommentNode == null) {testCommentNode = (Comment)node;} 438 break; 439 case org.w3c.dom.Node.DOCUMENT_TYPE_NODE : 440 if (testDocumentTypeNode == null) {testDocumentTypeNode = (DocumentType)node; } 441 break; 442 case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE : 443 if (testDocumentFragmentNode == null) {testDocumentFragmentNode = (DocumentFragment)node;} 444 break; 445 case org.w3c.dom.Node.NOTATION_NODE : 446 if (testNotationNode == null) {testNotationNode = (Notation)node;} 447 break; 448 case org.w3c.dom.Node.DOCUMENT_NODE : 449 if (testDocumentNode == null) {testDocumentNode = (Document)node;} 450 break; 451 default: 452 }// End of switch 453 454 455 } 456 457 /** 458 * 459 * version 2.0 10/12/98 460 * 461 * @author Philip W. Davis 462 */ 463 464 public static void main(String args[]) { 465 System.out.println("# main()"); 466 467 DTest test = new DTest(); 468 469 long avgTime = 0; 470 boolean OK = true; 471 long startTime = 0;//****************Time the whole thing for efficiency of DOM implementation 472 473 // for (int i=0; i< 1000; i++) 474 // { 475 startTime = System.currentTimeMillis(); 476 // if(!OK) 477 // break; 478 479 Document d = test.createDocument(); 480 // Document z = test.createDocument(); 481 482 DocumentType docDocType = test.createDocumentType(d,"testDocument1"); 483 d.appendChild(docDocType); 484 485 Entity docEntity = test.createEntity( d, "ourEntityNode"); 486 Text entityChildText = d.createTextNode("entityChildText information"); // Build a branch for entityReference tests 487 ((org.apache.xerces.dom.NodeImpl)docEntity).setReadOnly(false, true); 488 docEntity.appendChild(entityChildText); // & for READONLY_ERR tests 489 ((org.apache.xerces.dom.NodeImpl)docEntity).setReadOnly(true, true); 490 docDocType.getEntities().setNamedItem(docEntity); 491 492 test.docBuilder(d, "d"); 493 494 test.findTestNodes((Node)d); 495 // test.docBuilder(z, "z"); 496 try { 497 /**/ test.testAttr(d); 498 test.testCDATASection(d); 499 test.testCharacterData(d); 500 test.testChildNodeList(d); 501 test.testComment(d); 502 test.testDeepNodeList(d); 503 test.testDocument(d); 504 test.testDocumentFragment(d); 505 test.testDocumentType(d); 506 test.testDOMImplementation(d); 507 test.testElement(d); 508 test.testEntity(d); 509 test.testEntityReference(d); 510 test.testNode(d); 511 test.testNotation(d); 512 test.testPI(d); 513 test.testText(d); 514 /**/ test.testDOMerrors(d); 515 516 //!! Throws WRONG_DOCUMENT_ERR ********** 517 518 // z.appendChild(d.createComment("Test doc d comment"));// Tries to append z document with document d comment 519 // d.getDocumentElement().appendChild(z.createElement("newZdocElement"));// Tries to append d document with document z Element 520 // d.getLastChild().getLastChild().insertBefore(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild());// Tries to insert into d document with document z Element 521 // d.replaceChild(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild()); // Tries to replace in d document with document z Element 522 523 /* Attribute newAttribute = d.createAttribute("newAttribute"); 524 d.getDocumentElement().setAttributeNode(newAttribute); 525 d.getDocumentElement().getAttributes().setNamedItem(z.createAttribute("newzAttribute")); 526 */ 527 528 //!! Throws INVALID_CHARACTER_ERR ********** 529 // ******This just gets us through each method. JKess has a comprehensive test of Invalid Names****** 530 // d.createAttribute("Invalid Name"); // Name with blank space 531 // d.createElement("5InvalidName"); // Name starts with numeric 532 // d.createProcessingInstruction("This is the target processor channel","InvalidName>");// Name ends with > 533 // d.getDocumentElement().setAttribute("Invalid%Name",""); // Name contains % 534 535 536 //!! ******** NO_DATA_ALLOWED_ERR ********No cases to test as of 9/15 537 538 539 //!! ******** NO_MODIFICATION_ALLOWED_ERR ******** When read only exists 540 /* 541 542 543 544 //**** FOR Element when read only exists******** 545 .removeAttribute("aString"); //***** Not until read only exists. 546 .removeAttributeNode(Attribute); //***** Not until read only exists. 547 .setAttribute("aString", "anotherString"); //***** Not until read only exists. 548 549 550 //**** FOR Node when read only exists******** 551 .appendChild(aNode); //***** Not until read only exists. 552 .insertBefore(aNode, AnotherNode); //***** Not until read only exists. 553 .removeChild(aNode); //***** Not until read only exists. 554 .replaceChild(aNode); //***** Not until read only exists. 555 556 .splitText(2); //***** Not until read only exists. 557 558 .setNamedItem(Node); //***** Not until read only exists. 559 */ 560 561 562 //!!******** NOT_SUPPORTED_ERR ********For HTML when implemented 563 /* 564 .createCDATASection("String stuff"); 565 .createEntityReference("String stuff"); 566 .createProcessingInstruction("String stuff", "Some more String stuff"); 567 */ 568 569 } catch (Exception e) { 570 System.out.println("Exception is: "); 571 e.printStackTrace(); 572 OK = false; 573 574 } 575 //System.err.println("Elapsed time (measured in seconds): " + ((System.currentTimeMillis() - startTime) / 1000.0)); 576 avgTime += System.currentTimeMillis() - startTime; 577 // }//END OF FOR 578 579 580 // System.err.println("Elapsed time (measured in seconds): " + 581 // ((System.currentTimeMillis() - startTime) / 1000.0)); 582 // System.err.println("Elapsed time (measured in mili-seconds): " + 583 // ((System.currentTimeMillis() - startTime))); 584 585 586 // System.err.println("Average Elapsed time (measured in seconds): " + (avgTime/10000000.0) ); 587 588 } 589 /** 590 * This method tests Attr methods for the XML DOM implementation 591 * version 2.0 10/12/98 592 * @param document org.w3c.dom.Document 593 * 594 * @author Philip W. Davis 595 */ 596 public void testAttr(org.w3c.dom.Document document) 597 { 598 599 Node node; 600 Attr attributeNode, attribute2; 601 String compare; 602 boolean T = true; 603 boolean F = false; 604 boolean OK = true; 605 // For debugging***** println("\n testAttr's outputs:\n"); 606 607 Attr testAttribute = document.createAttribute("testAttribute"); 608 testAttribute.setValue("testAttribute's value"); 609 node = document.getDocumentElement(); // node gets first element 610 ((Element)node).setAttributeNode(testAttribute); 611 attributeNode = ((Element)node).getAttributeNode("testAttribute"); 612 613 compare = "testAttribute"; 614 if (!compare.equals(attributeNode.getName())) 615 { 616 System.out.println("Warning!!! Attr's 'getName' method failed to work properly!"); 617 OK = false; 618 } 619 compare = "testAttribute's value"; 620 if (!compare.equals(attributeNode.getNodeValue())) 621 { 622 System.out.println("Warning!!! Attr's 'getNodeValue' method failed to work properly!"); 623 OK = false; 624 } 625 if (! T ==attributeNode.getSpecified()) 626 { 627 System.out.println("Warning!!! Attr's 'getSpecified' method failed to work properly!"); 628 OK = false; 629 } 630 631 if (!compare.equals(attributeNode.getValue())) 632 { 633 System.out.println("Warning!!! Attr's 'getValue' method failed to work properly!"); 634 OK = false; 635 } 636 637 attributeNode.setNodeValue("Reset Value"); 638 compare = "Reset Value"; 639 if (!compare.equals(attributeNode.getNodeValue())) 640 { 641 System.out.println("Warning!!! Attr's 'setNodeValue' method failed to work properly!"); 642 OK = false; 643 } 644 ((org.apache.xerces.dom.AttrImpl)attributeNode).setSpecified(F);//***** How do we change this for external use?? 645 if (! F ==attributeNode.getSpecified()) 646 { 647 System.out.println("Warning!!! Attr's 'setSpecified' method failed to work properly!"); 648 OK = false; 649 } 650 651 attributeNode.setValue(null); 652 if (! attributeNode.getValue().equals("")) 653 { 654 System.out.println("Warning!!! Attr's 'setValue' to 'null' method failed to work properly!"); 655 OK = false; 656 } 657 658 attributeNode.setValue("Another value "); 659 compare = "Another value "; 660 if (!compare.equals(attributeNode.getValue())) 661 { 662 System.out.println("Warning!!! Attr's 'setValue' method failed to work properly!"); 663 OK = false; 664 } 665 666 node = attributeNode.cloneNode(T);//*****? 667 // Check nodes for equality, both their name and value or lack thereof 668 if (! (node.getNodeName().equals(attributeNode.getNodeName()) && // Compares node names for equality 669 (node.getNodeValue() != null && attributeNode.getNodeValue() != null) // Checks to make sure each node has a value node 670 ? node.getNodeValue().equals(attributeNode.getNodeValue()) // If both have value nodes test those value nodes for equality 671 : (node.getNodeValue() == null && attributeNode.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't 672 { 673 System.out.println("'cloneNode' did not clone the Attribute node correctly"); 674 OK = false; 675 } 676 // Deep clone test comparison is in testNode & testDocument 677 678 //************************************************* ERROR TESTS 679 DTest tests = new DTest(); 680 Assertion.assert( 681 tests.DOMExceptionsTest(document.getDocumentElement(), 682 "appendChild", 683 new Class[]{Node.class}, 684 new Object[]{attributeNode}, 685 DOMException.HIERARCHY_REQUEST_ERR)); 686 687 attribute2 = document.createAttribute("testAttribute2"); 688 Assertion.assert( 689 tests.DOMExceptionsTest(document.getDocumentElement(), 690 "removeAttributeNode", 691 new Class[]{Attr.class}, 692 new Object[]{attribute2}, 693 DOMException.NOT_FOUND_ERR)); 694 695 Element element = (Element)document.getLastChild().getLastChild(); 696 // Tests setNamedItem 697 Assertion.assert( 698 tests.DOMExceptionsTest(element, 699 "setAttributeNode", 700 new Class[]{Attr.class}, 701 new Object[]{testAttribute}, 702 DOMException.INUSE_ATTRIBUTE_ERR)); 703 704 if (! OK) 705 System.out.println("\n*****The Attr method calls listed above failed, all others worked correctly.*****"); 706 // println(""); 707 } 708 /** 709 * This method tests CDATASection methods for the XML DOM implementation 710 * version 2.0 10/12/98 711 * @param document org.w3c.dom.Document 712 * 713 * @author Philip W. Davis 714 */ 715 public void testCDATASection(org.w3c.dom.Document document) 716 { 717 718 Node node, node2; 719 boolean T = true; 720 boolean OK = true; 721 // For debugging***** println("\n testCDATASection's outputs:\n"); 722 node = document.getDocumentElement().getElementsByTagName("dBodyLevel23").item(0).getFirstChild(); // node gets CDATASection node 723 724 node2 = node.cloneNode(T);//*****? 725 // Check nodes for equality, both their name and value or lack thereof 726 if (! (node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 727 (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node 728 ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality 729 : (node.getNodeValue() == null && node2.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't 730 { 731 System.out.println("'cloneNode' did not clone the CDATASection node correctly"); 732 OK = false; 733 } 734 // Deep clone test comparison is in testNode & testDocument 735 736 // For debugging***** println("All CDATASection method calls worked correctly."); 737 738 if (! OK) 739 System.out.println("\n*****The CDATASection method calls listed above failed, all others worked correctly.*****"); 740 // println(""); 741 } 742 /** 743 * This method tests CharacterData methods for the XML DOM implementation 744 * version 2.0 10/12/98 745 * @param document org.w3c.dom.Document 746 * 747 * @author Philip W. Davis 748 */ 749 public void testCharacterData(org.w3c.dom.Document document) 750 { 751 CharacterData charData; 752 String compareData, newData, resetData; 753 boolean OK = true; 754 // For debugging***** println("\n testCharacterData's outputs:\n"); 755 charData = (CharacterData) document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // charData gets textNode11 756 compareData = "dBodyLevel31'sChildTextNode11"; 757 if (!compareData.equals(charData.getData())) 758 { 759 System.out.println("Warning!!! CharacterData's 'getData' failed to work properly!\n This may corrupt other CharacterData tests!!!*****"); 760 OK = false; 761 } 762 763 resetData = charData.getData(); 764 // println("This node's original data is: " + charData.getData()); 765 766 newData = " This is new data for this node"; 767 compareData = charData.getData() + newData; 768 charData.appendData(newData); 769 if (!compareData.equals(charData.getData())) 770 { 771 System.out.println("Warning!!! CharacterData's 'appendData' failed to work properly!"); 772 OK = false; 773 } 774 // println("This node's appended data is: " + charData.getData()); 775 776 compareData = "dBodyLevel"; 777 charData.deleteData(10, 100); 778 if (!compareData.equals(charData.getData())) 779 { 780 System.out.println("Warning!!! CharacterData's 'deleteData' failed to work properly!"); 781 OK = false; 782 } 783 // println("This node's partially deleted data is: " + charData.getData()); 784 785 int length = 10; 786 if (!(length == charData.getLength())) 787 { 788 System.out.println("Warning!!! CharacterData's 'getLength' failed to work properly!"); 789 OK = false; 790 } 791 // println("This node's data length is: " + charData.getLength()); 792 793 compareData = "dBody' This is data inserted into this node'Level"; 794 charData.insertData(5, "' This is data inserted into this node'"); 795 if (!compareData.equals(charData.getData())) 796 { 797 System.out.println("Warning!!! CharacterData's 'insertData' failed to work properly!"); 798 OK = false; 799 } 800 // println("This node's updated with insert data is: " + charData.getData()); 801 802 compareData = "dBody' This is ' replacement data'ted into this node'Level"; 803 charData.replaceData(15, 10, "' replacement data'"); 804 if (!compareData.equals(charData.getData())) 805 { 806 System.out.println("Warning!!! CharacterData's 'replaceData' failed to work properly!"); 807 OK = false; 808 } 809 // println("This node's updated with replacement data is: " +charData.getData()); 810 811 compareData = "New data A123456789B123456789C123456789D123456789E123456789"; 812 charData.setData("New data A123456789B123456789C123456789D123456789E123456789"); 813 if (!compareData.equals(charData.getData())) 814 { 815 System.out.println("Warning!!! CharacterData's 'setData' failed to work properly!"); 816 OK = false; 817 } 818 // println("This node's new data via setData: " + charData.getData()); 819 820 compareData = "123456789D123456789E123456789"; 821 if (!compareData.equals(charData.substringData(30, 30))) 822 { 823 System.out.println("Warning!!! CharacterData's 'substringData' failed to work properly!"); 824 OK = false; 825 } 826 // println("Using subString 30,30 you get:" + charData.substringData(30,30)); 827 828 compareData = "New data A123456789B12345"; 829 if (!compareData.equals(charData.substringData(0, 25))) 830 { 831 System.out.println("Warning!!! CharacterData's 'substringData' failed to work properly!"); 832 OK = false; 833 } 834 // println("Using subString 0,25 you get:" + charData.substringData(0,25)); 835 836 //************************************************* ERROR TESTS 837 DTest tests = new DTest(); 838 839 //!! Throws INDEX_SIZE_ERR ******************** 840 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "deleteData", new Class[]{int.class, int.class}, 841 new Object[]{new Integer(-1),new Integer(5) }, DOMException.INDEX_SIZE_ERR )); 842 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "deleteData", new Class[]{int.class, int.class}, 843 new Object[]{new Integer(2),new Integer(-1) }, DOMException.INDEX_SIZE_ERR )); 844 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "deleteData", new Class[]{int.class, int.class}, 845 new Object[]{new Integer(100),new Integer(5) }, DOMException.INDEX_SIZE_ERR )); 846 847 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "insertData", new Class[]{int.class, String.class}, 848 new Object[]{new Integer(-1),"Stuff inserted" }, DOMException.INDEX_SIZE_ERR )); 849 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "insertData", new Class[]{int.class, String.class}, 850 new Object[]{new Integer(100),"Stuff inserted" }, DOMException.INDEX_SIZE_ERR )); 851 852 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "replaceData", new Class[]{int.class, int.class, String.class}, 853 new Object[]{new Integer(-1),new Integer(5),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR )); 854 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "replaceData", new Class[]{int.class, int.class, String.class}, 855 new Object[]{new Integer(100),new Integer(5),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR )); 856 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "replaceData", new Class[]{int.class, int.class, String.class}, 857 new Object[]{new Integer(2),new Integer(-1),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR )); 858 859 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "substringData", new Class[]{int.class, int.class}, 860 new Object[]{new Integer(-1),new Integer(5) }, DOMException.INDEX_SIZE_ERR )); 861 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "substringData", new Class[]{int.class, int.class}, 862 new Object[]{new Integer(100),new Integer(5) }, DOMException.INDEX_SIZE_ERR )); 863 OK &= Assertion.assert(tests.DOMExceptionsTest(charData, "substringData", new Class[]{int.class, int.class}, 864 new Object[]{new Integer(2),new Integer(-1) }, DOMException.INDEX_SIZE_ERR )); 865 866 867 //!! Throws NO_MODIFICATION_ALLOWED_ERR ******** 868 Node node = document.getDocumentElement().getElementsByTagName("dBodyLevel24").item(0).getFirstChild().getChildNodes().item(0); // node gets ourEntityReference node's child text 869 870 OK &= Assertion.assert(tests.DOMExceptionsTest(node, "appendData", new Class[]{String.class}, 871 new Object[]{"new data" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 872 OK &= Assertion.assert(tests.DOMExceptionsTest(node, "deleteData", new Class[]{int.class, int.class}, 873 new Object[]{new Integer(5),new Integer(10) }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 874 OK &= Assertion.assert(tests.DOMExceptionsTest(node, "insertData", new Class[]{int.class, String.class}, 875 new Object[]{new Integer(5),"Stuff inserted" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 876 OK &= Assertion.assert(tests.DOMExceptionsTest(node, "replaceData", new Class[]{int.class, int.class, String.class}, 877 new Object[]{new Integer(5),new Integer(10),"Replacementstuff" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 878 OK &= Assertion.assert(tests.DOMExceptionsTest(node, "setData", new Class[]{String.class}, 879 new Object[]{"New setdata stuff"}, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 880 881 882 // For debugging***** println("All CharacterData method calls worked correctly."); 883 if (!OK) 884 System.out.println("\n*****The CharacterData method calls listed above failed, all others worked correctly.*****"); 885 charData.setData(resetData); // reset node to original data 886 // println(""); 887 } 888 /** 889 * This method tests ChildNodeList methods for the XML DOM implementation 890 * version 2.0 10/12/98 891 * @param document org.w3c.dom.Document 892 * 893 * @author Philip W. Davis 894 */ 895 public void testChildNodeList(org.w3c.dom.Document document) 896 { 897 898 Node node, node2; 899 boolean OK = true; 900 // For debugging***** println("\n testChildNodeList's outputs:\n"); 901 node = document.getDocumentElement().getLastChild(); // node gets doc's testBody element 902 903 if (!(node.getChildNodes().getLength()== 4)) 904 OK = false; 905 node2 = node.getChildNodes().item(2); 906 if (! node2.getNodeName().equals("dBodyLevel23")) 907 OK = false; 908 909 // For debugging***** println("All ChildNodeList method calls worked correctly."); 910 if (!OK) 911 System.out.println("\n*****The ChildNodeList method calls listed above failed, all others worked correctly.*****"); 912 // println(""); 913 } 914 /** 915 * This method tests Comment methods for the XML DOM implementation 916 * version 1.0 10/12/98 917 * @param document org.w3c.dom.Document 918 * 919 * @author Philip W. Davis 920 */ 921 public void testComment(org.w3c.dom.Document document) 922 { 923 Node node, node2; 924 boolean T = true; 925 boolean OK = true; 926 // For debugging***** println("\n testComment's outputs:\n"); 927 node = document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // node gets textNode11 928 node2 = node.cloneNode(T); 929 // Check nodes for equality, both their name and value or lack thereof 930 if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 931 (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node 932 ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality 933 : (node.getNodeValue() == null && node2.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't 934 //println("'cloneNode' did not clone the Comment node correctly"); 935 OK = false; 936 // Deep clone test comparison is in testNode & testDocument 937 if (OK) 938 // For debugging***** println("All Comment method calls worked correctly."); 939 if (!OK) 940 System.out.println("\n*****The Comment method calls listed above failed, all others worked correctly.*****"); 941 // println(""); 942 } 943 /** 944 * This method tests DeepNodeList methods for the XML DOM implementation 945 * version 2.0 10/12/98 946 * @param document org.w3c.dom.Document 947 * 948 * @author Philip W. Davis 949 */ 950 public void testDeepNodeList(org.w3c.dom.Document document) 951 { 952 953 Node node, node2; 954 boolean OK = true; 955 // For debugging***** println("\n testDeepNodeList's outputs:\n"); 956 node = document.getLastChild().getLastChild(); // node gets docBody element 957 if (!(8 == ((Element) node).getElementsByTagName("*").getLength())) 958 { 959 System.out.println ("Warning!!! DeepNodeList's 'getLength' failed to work properly!"); 960 OK = false; 961 } 962 node2 = ((Element) node).getElementsByTagName("*").item(2); //This also runs through 'nextMatchingElementAfter" 963 if (! node2.getNodeName().equals("dBodyLevel32")) 964 { 965 System.out.println ("Warning!!! DeepNodeList's 'item' (or Element's 'getElementsBy TagName)failed to work properly!"); 966 OK = false; 967 } 968 node2 = document.getLastChild(); 969 if (! ((Element) node2).getElementsByTagName("dTestBody").item(0).getNodeName().equals("dTestBody"))//This also runs through 'nextMatchingElementAfter" 970 { 971 System.out.println ("Warning!!! DeepNodeList's 'item' (or Element's 'getElementsBy TagName)failed to work properly!"); 972 OK = false; 973 } 974 975 976 // For debugging***** println("All DeepNodeList method calls worked correctly."); 977 if (!OK) 978 System.out.println("\n*****The DeepNodeList method calls listed above failed, all others worked correctly.*****"); 979 // println(""); 980 } 981 /** 982 * This method tests Document methods for the XML DOM implementation 983 * version 2.0 10/12/98 984 * @param document org.w3c.dom.Document 985 * 986 * @author Philip W. Davis 987 * 988 **** ALL Document create methods are run in docBuilder except createAttribute which is in testAttribute** 989 */ 990 public void testDocument(org.w3c.dom.Document document) 991 { 992 DTest make = new DTest(); 993 DocumentFragment docFragment, docFragment2; 994 Element newElement; 995 Node node, node2; 996 String[] elementNames = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32", 997 "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"}; 998 String[] newElementNames = {"dFirstElement", "dTestBody", "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23"}; 999 boolean result; 1000 boolean OK = true; 1001 // For debugging***** println("\n testDocument's outputs:\n "); 1002 1003 DocumentType checkDocType = make.createDocumentType(document,"testDocument1"); 1004 DocumentType docType = document.getDoctype(); 1005 if (! (checkDocType.getNodeName().equals(docType.getNodeName()) && // Compares node names for equality 1006 (checkDocType.getNodeValue() != null && docType.getNodeValue() != null) // Checks to make sure each node has a value node 1007 ? checkDocType.getNodeValue().equals(docType.getNodeValue()) // If both have value nodes test those value nodes for equality 1008 : (checkDocType.getNodeValue() == null && docType.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't 1009 { 1010 System.out.println("Warning!!! Document's 'getDocType method failed!" ); 1011 OK = false; 1012 } 1013 1014 Node rootElement = document.getLastChild(); 1015 if (! (rootElement.getNodeName().equals(document.getDocumentElement().getNodeName()) && // Compares node names for equality 1016 (rootElement.getNodeValue() != null && document.getDocumentElement().getNodeValue() != null) // Checks to make sure each node has a value node 1017 ? rootElement.getNodeValue().equals(document.getDocumentElement().getNodeValue()) // If both have value nodes test those value nodes for equality 1018 : (rootElement.getNodeValue() == null && document.getDocumentElement().getNodeValue() == null))) // If one node doesn't have a value node make sure both don't 1019 { 1020 System.out.println("Warning!!! Document's 'getDocumentElement' method failed!" ); 1021 OK = false; 1022 } 1023 1024 NodeList docElements = document.getElementsByTagName("*"); 1025 int docSize = docElements.getLength(); 1026 int i; 1027 for (i = 0; i < docSize; i++) 1028 { 1029 Node n = (Node) docElements.item(i); 1030 if (! (elementNames[i].equals(n.getNodeName()))) 1031 { 1032 System.out.println("Comparison of this document's elements failed at element number " + i + " : " + n.getNodeName()); 1033 OK = false; 1034 break; 1035 } 1036 } 1037 if (document.equals(document.getImplementation())) 1038 { 1039 System.out.println("Warning!!! Document's 'getImplementation' method failed!" ); 1040 OK = false; 1041 } 1042 1043 newElement = document.createElement("NewElementTestsInsertBefore"); 1044 // doc.insertBefore(newElement,null);//!! Throws a HIERARCHY_REQUEST_ERR ******* 1045 // doc.removeChild(docElements.item(9));//!! Throws a NOT_FOUND_ERR ******** 1046 1047 docFragment = document.createDocumentFragment(); 1048 //Tests removeChild and stores removed branch for tree reconstruction 1049 docFragment.appendChild(docElements.item(1).removeChild(docElements.item(9))); 1050 docFragment2 = document.createDocumentFragment(); 1051 //Tests removeChild and stores removed branch for tree reconstruction 1052 docFragment2.appendChild(docElements.item(1).removeChild(docElements.item(2))); 1053 docSize = docElements.getLength(); 1054 for (i = 0; i < docSize; i++) 1055 { 1056 Node n = (Node) docElements.item(i); 1057 if (! (newElementNames[i].equals(n.getNodeName()))) 1058 { 1059 System.out.println("Comparison of new document's elements failed at element number " + i + " : " + n.getNodeName()); 1060 OK = false; 1061 break; 1062 } 1063 } 1064 docElements.item(1).insertBefore(docFragment, null); //Reattaches removed branch to restore tree to the original 1065 docElements.item(1).insertBefore(docFragment2, docElements.item(2)); //Reattaches removed branch to restore tree to the original 1066 1067 // println(docElements.item(2).getNodeName()); 1068 1069 docSize = docElements.getLength(); 1070 for (i = 0; i < docSize; i++) 1071 { 1072 Node n = (Node) docElements.item(i); 1073 if (! (elementNames[i].equals(n.getNodeName()))) 1074 { 1075 System.out.println("Comparison of restored document's elements failed at element number " + i + " : " + n.getNodeName()); 1076 OK = false; 1077 break; 1078 } 1079 } 1080 1081 DTest tests = new DTest(); 1082 1083 1084 // Document z = tests.createDocument(); 1085 // tests.docBuilder(z, "z"); 1086 1087 //!! Throws WRONG_DOCUMENT_ERR ********** 1088 // OK &= Assertion.assert(tests.DOMExceptionsTest(z, "appendChild", new Class[]{Node.class}, new Object[]{doc.createComment("Test doc d comment")}, DOMException.HIERARCHY_REQUEST_ERR )); 1089 1090 // z.appendChild(d.createComment("Test doc d comment"));// Tries to append z document with document d comment 1091 // d.getDocumentElement().appendChild(z.createElement("newZdocElement"));// Tries to append d document with document z Element 1092 // d.getLastChild().getLastChild().insertBefore(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild());// Tries to insert into d document with document z Element 1093 // d.replaceChild(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild()); // Tries to replace in d document with document z Element 1094 1095 // doc.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** 1096 1097 node = document; 1098 node2 = document.cloneNode(true); 1099 result = treeCompare(node, node2); // Deep clone test comparison of document cloneNode 1100 if (!result) 1101 { 1102 System.out.println("Warning!!! Deep clone of the document failed!"); 1103 OK = false; 1104 } 1105 1106 // check on the ownerDocument of the cloned nodes 1107 Document doc2 = (Document) node2; 1108 Assertion.assert(doc2.getDocumentElement().getOwnerDocument() == doc2); 1109 1110 // Deep clone test comparison is also in testNode 1111 1112 // try adding a new element to the cloned document 1113 node2 = doc2.createElement("foo"); 1114 doc2.getDocumentElement().appendChild(node2); 1115 1116 // For debugging***** println("All Document method calls worked correctly."); 1117 if (!OK) 1118 System.out.println("\n*****The Document method calls listed above failed, all others worked correctly.*****"); 1119 // println(""); 1120 } 1121 /** 1122 * This method tests DocumentFragment methods for the XML DOM implementation 1123 * version 2.0 10/12/98 1124 * @param document org.w3c.dom.Document 1125 * 1126 * @author Philip W. Davis 1127 * 1128 * 1129 ********This really isn't needed, only exists to throw NO_MODIFICATION_ALLOWED_ERR ******** 1130 */ 1131 public void testDocumentFragment(org.w3c.dom.Document document) 1132 { 1133 boolean OK = true; 1134 // For debugging***** println("\n testDocumentFragment's outputs:\n"); 1135 DocumentFragment testDocFragment = document.createDocumentFragment(); 1136 1137 // testDocFragment.setNodeValue("This is a document fragment!");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** 1138 1139 // For debugging***** println("All DocumentFragment method calls worked correctly."); 1140 if (!OK) 1141 System.out.println("\n*****The DocumentFragment method calls listed above failed, all others worked correctly.*****"); 1142 // println(""); 1143 } 1144 /** 1145 * This method tests DocumentType methods for the XML DOM implementation 1146 * version 2.0 10/12/98 1147 * @param document org.w3c.dom.Document 1148 * 1149 * @author Philip W. Davis 1150 */ 1151 public void testDocumentType(org.w3c.dom.Document document) 1152 { 1153 DTest test = new DTest(); 1154 DocumentType docType, holdDocType; 1155 NamedNodeMap docEntityMap, docNotationMap; 1156 Node node, node2; 1157 String compare; 1158 boolean OK = true; 1159 // For debugging***** println("\n testDocumentType's outputs:\n"); 1160 DocumentType newDocumentType = test.createDocumentType(document, "TestDocument"); 1161 node = document.getFirstChild(); // node gets doc's docType node 1162 node2 = node.cloneNode(true); 1163 // Check nodes for equality, both their name and value or lack thereof 1164 if (! (node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 1165 (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node 1166 ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality 1167 : (node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't 1168 { 1169 System.out.println("'cloneNode' did not clone the DocumentType node correctly"); 1170 OK = false; 1171 } 1172 // Deep clone test comparison is in testNode & testDocument 1173 1174 docType = (DocumentType) document.getFirstChild(); 1175 compare = "ourEntityNode"; 1176 docEntityMap = docType.getEntities(); 1177 if (! compare.equals(docEntityMap.item(0).getNodeName())) 1178 { 1179 System.out.println("Warning!!! DocumentType's 'getEntities' failed!" ); 1180 OK = false; 1181 } 1182 docNotationMap = docType.getNotations(); 1183 compare = "ourNotationNode"; 1184 if (! compare.equals(docNotationMap.item(0).getNodeName())) 1185 { 1186 System.out.println("Warning!!! DocumentType's 'getNotations' failed!"); 1187 OK = false; 1188 } 1189 // doc.appendChild(newDocumentTypeImpl);//!! Throws a HIERARCHY_REQUEST_ERR ******* 1190 holdDocType = (DocumentType) document.removeChild(document.getFirstChild()); //Tests removeChild and stores removed branch for tree reconstruction 1191 document.insertBefore(newDocumentType, document.getDocumentElement()); 1192 //** Other aspects of insertBefore are tested in docBuilder through appendChild* 1193 1194 document.removeChild(document.getFirstChild()); //Removes newDocumentType for tree restoral 1195 document.insertBefore(holdDocType, document.getFirstChild()); //Reattaches removed branch to restore tree to the original 1196 1197 1198 // For debugging***** println("All DocumentType method calls worked correctly."); 1199 if (!OK) 1200 System.out.println("\n*****The DocumentType method calls listed above failed, all others worked correctly.*****"); 1201 // println(""); 1202 } 1203 /** 1204 * @author Philip W. Davis 1205 * @param document org.w3c.dom.Document 1206 */ 1207 public void testDOMerrors(Document document) { 1208 1209 boolean OK = true; 1210 1211 DTest tests = new DTest(); 1212 1213 OK &= Assertion.assert(tests.DOMExceptionsTest(document, "appendChild", new Class[]{Node.class}, new Object[]{testElementNode}, DOMException.HIERARCHY_REQUEST_ERR )); 1214 OK &= Assertion.assert(tests.DOMExceptionsTest(testTextNode, "appendChild", new Class[]{Node.class}, new Object[]{testTextNode}, DOMException.HIERARCHY_REQUEST_ERR )); 1215 // OK &= Assertion.assert(tests.DOMExceptionsTest(document, "insertBefore", new Class[]{Node.class, Node.class}, new Object[]{document.getElementsByTagName("docEntity").item(0), document.getElementsByTagName("docFirstElement").item(0)}, DOMException.HIERARCHY_REQUEST_ERR )); 1216 // OK &= Assertion.assert(tests.DOMExceptionsTest(document, "replaceChild", new Class[]{Node.class, Node.class}, new Object[]{document.getElementsByTagName("docCDATASection").item(0), document.getElementsByTagName("docFirstElement").item(0)}, DOMException.HIERARCHY_REQUEST_ERR )); 1217 1218 // OK &= Assertion.assert(tests.DOMExceptionsTest(document.getElementsByTagName("docFirstElement").item(0), "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 1219 /* OK &= Assertion.assert(tests.DOMExceptionsTest(docReferenceEntity, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 1220 OK &= Assertion.assert(tests.DOMExceptionsTest(docEntity, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 1221 OK &= Assertion.assert(tests.DOMExceptionsTest(document, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 1222 OK &= Assertion.assert(tests.DOMExceptionsTest(docDocType, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 1223 OK &= Assertion.assert(tests.DOMExceptionsTest(docDocFragment, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 1224 OK &= Assertion.assert(tests.DOMExceptionsTest(docNotation, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 1225 OK &= Assertion.assert(tests.DOMExceptionsTest(docReferenceEntity, "appendChild", new Class[]{Node.class}, new Object[]{entityReferenceText2 }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 1226 1227 1228 OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "insertBefore", new Class[]{Node.class, Node.class}, new Object[]{docTextNode11,docBody }, DOMException.NOT_FOUND_ERR )); 1229 OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "removeChild", new Class[]{Node.class}, new Object[]{docFirstElement}, DOMException.NOT_FOUND_ERR )); 1230 OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "replaceChild", new Class[]{Node.class, Node.class}, new Object[]{docTextNode11,docFirstElement }, DOMException.NOT_FOUND_ERR )); 1231 */ 1232 1233 //!! Throws a NOT_FOUND_ERR ******** 1234 1235 // docBodyLevel32.getAttributes().removeNamedItem(testAttribute.getName()); 16 // To test removeNamedItem 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 } 1250 /** 1251 * This method tests DOMImplementation methods for the XML DOM implementation 1252 * version 2.0 10/12/98 1253 * @param document org.w3c.dom.Document 1254 * 1255 * @author Philip W. Davis 1256 */ 1257 public void testDOMImplementation(org.w3c.dom.Document document) 1258 { 1259 1260 DOMImplementation implementation; 1261 boolean result = false; 1262 boolean OK = true; 1263 // For debugging***** println("\n testDOMImplementation's outputs:\n"); 1264 implementation = document.getImplementation(); //Uses getDOMImplementation to obtain implementation 1265 1266 result = implementation.hasFeature("XML", "1.0"); 1267 if(!result) 1268 { 1269 System.out.println("Warning!!! DOMImplementation's 'hasFeature' that should be 'true' failed!"); 1270 OK = false; 1271 } 1272 1273 result = implementation.hasFeature("HTML", "4.0"); 1274 if(result) 1275 { 1276 System.out.println("Warning!!! DOMImplementation's 'hasFeature' that should be 'false' failed!"); 1277 OK = false; 1278 } 1279 1280 1281 // For debugging***** println("All DOMImplementation method calls worked correctly."); 1282 if (!OK) 1283 System.out.println("\n*****The DOMImplementation method calls listed above failed, all others worked correctly.*****"); 1284 // println(""); 1285 } 1286 /** 1287 * This method tests Element methods for the XML DOM implementation 1288 * version 2.0 10/12/98 1289 * @param document org.w3c.dom.Document 1290 * 1291 * @author Philip W. Davis 1292 */ 1293 public void testElement(org.w3c.dom.Document document) 1294 { 1295 Attr attributeNode, newAttributeNode; 1296 Element element, element2; 1297 Node node, node2; 1298 String attribute, compare; 1299 String[] attributeCompare = {"AnotherFirstElementAttribute", "dFirstElement", "testAttribute"}; 1300 String[] elementNames = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32", 1301 "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"}; 1302 String[] textCompare = {"dBodyLevel31'sChildTextNode11", "dBodyLevel31'sChildTextNode12", "dBodyLevel31'sChildTextNode13"}; 1303 NamedNodeMap nodeMap; 1304 boolean OK = true; 1305 // For debugging***** println("\n testElement's outputs:\n"); 1306 node = document.getDocumentElement(); // node gets doc's firstElement 1307 node2 = node.cloneNode(true); 1308 // Check nodes for equality, both their name and value or lack thereof 1309 if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 1310 (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node 1311 ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality 1312 :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't 1313 { 1314 System.out.println("'cloneNode' did not clone the Element node correctly"); 1315 OK = false; 1316 } 1317 // Deep clone test comparison is in testNode & testDocument 1318 1319 element = document.getDocumentElement(); // element gets doc's firstElement 1320 compare = ""; 1321 attribute = element.getAttribute(document + "'s test attribute"); 1322 if (! compare.equals(element.getAttribute(document + "'s test attribute"))) 1323 { 1324 System.out.println("Warning!!! Element's 'getAttribute' failed!"); 1325 OK = false; 1326 } 1327 1328 attributeNode = element.getAttributeNode(document + "FirstElement"); 1329 if(! (attributeNode == null)) 1330 { 1331 System.out.println("Warning!!! Element's 'getAttributeNode' failed! It should have returned 'null' here!"); 1332 OK = false; 1333 } 1334 1335 newAttributeNode = document.createAttribute("AnotherFirstElementAttribute"); 1336 newAttributeNode.setValue("A new attribute which helps test calls in Element"); 1337 element.setAttributeNode(newAttributeNode); 1338 nodeMap = element.getAttributes(); 1339 int size = nodeMap.getLength(); 1340 int k; 1341 for (k = 0; k < size; k++) 1342 { 1343 Node n = (Node) nodeMap.item(k); 1344 if (! (attributeCompare[k].equals(n.getNodeName()))) 1345 { 1346 System.out.println("Warning!!! Comparison of firstElement's attributes failed at attribute #"+ (k+1) +" " + n.getNodeValue()); 1347 System.out.println("This failure can be a result of Element's 'setValue' and/or 'setAttributeNode' and/or 'getAttributes' failing."); 1348 OK = false; 1349 break; 1350 } 1351 // println("firstElement's attribute number " + k + " : " + n.getNodeName()); 1352 } 1353 NodeList docElements = document.getElementsByTagName("*"); 1354 int docSize = docElements.getLength(); 1355 int i; 1356 for (i = 0; i < docSize; i++) 1357 { 1358 Node n = (Node) docElements.item(i); 1359 if (! (elementNames[i].equals(n.getNodeName()))) 1360 { 1361 System.out.println("Warning!!! Comparison of Element's 'getElementsByTagName' and/or 'item' failed at element number " 1362 + i + " : " + n.getNodeName()); 1363 OK = false; 1364 break; 1365 } 1366 // println("docElement's number " + i + " is: " + n.getNodeName()); 1367 } 1368 element = (Element) document.getElementsByTagName("dBodyLevel21").item(0); // element gets Element test BodyLevel21 1369 element2 = (Element) document.getElementsByTagName("dBodyLevel31").item(0); // element2 gets Element test BodyLevel31 1370 NodeList text = ((Node) element2).getChildNodes(); 1371 int textSize = text.getLength(); 1372 int j; 1373 for (j = 0; j < textSize; j++) 1374 { 1375 Node n = (Node) text.item(j); 1376 if (! (textCompare[j].equals(n.getNodeValue()))) 1377 { 1378 System.out.println("Warning!!! Comparison of original text nodes via Node 'getChildNodes' & NodeList 'item'" 1379 + "failed at text node: #" + j +" " + n.getNodeValue()); 1380 OK = false; 1381 break; 1382 } 1383 // println("Element testBodyLevel31's child text node " + j + " is: " + n.getNodeValue()); 1384 } 1385 element = document.getDocumentElement(); // element gets doc's firstElement 1386 element.normalize(); // Concatenates all adjacent text nodes in this element's subtree 1387 NodeList text2 = ((Node) element2).getChildNodes(); 1388 compare = "dBodyLevel31'sChildTextNode11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13"; 1389 Node n = (Node) text2.item(0); 1390 if (! (compare.equals(n.getNodeValue()))) 1391 { 1392 System.out.println("Warning!!! Comparison of concatenated text nodes created by Element's 'normalize' failed!"); 1393 OK = false; 1394 } 1395 1396 element.setAttribute("FirstElementLastAttribute", "More attribute stuff for firstElement!!"); 1397 element.removeAttribute("FirstElementLastAttribute"); 1398 element.removeAttributeNode(newAttributeNode); 1399 1400 // doc.getLastChild().setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR*** 1401 1402 // For debugging***** println("All Element method calls worked correctly."); 1403 if (!OK) 1404 System.out.println("\n*****The Element method calls listed above failed, all others worked correctly.*****"); 1405 // println(""); 1406 } 1407 /** 1408 * This method tests Entity methods for the XML DOM implementation 1409 * version 2.0 10/12/98 1410 * @param document org.w3c.dom.Document 1411 * 1412 * @author Philip W. Davis 1413 */ 1414 public void testEntity(org.w3c.dom.Document document) 1415 { 1416 Entity entity; 1417 Node node, node2; 1418 boolean OK = true; 1419 String compare; 1420 // For debugging***** println("\n testEntity's outputs:\n"); 1421 entity = (Entity) document.getDoctype().getEntities().getNamedItem("ourEntityNode"); 1422 node = entity; 1423 node2 = entity.cloneNode(true); 1424 // Check nodes for equality, both their name and value or lack thereof 1425 if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 1426 (node.getNodeValue() != null && node2.getNodeValue() != null) ? // Checks to make sure each node has a value node 1427 node.getNodeValue().equals(node2.getNodeValue()) : // If both have value nodes test those value nodes for equality 1428 (node.getNodeValue() == null && node2.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't 1429 { 1430 System.out.println("Warning!!! 'cloneNode' did not clone the Entity node correctly"); 1431 OK = false; 1432 } 1433 // Deep clone test comparison is in testNode & testDocument 1434 1435 ((org.apache.xerces.dom.EntityImpl) entity).setNotationName("testNotationName"); 1436 compare = "testNotationName"; 1437 if(! compare.equals(entity.getNotationName())) 1438 { 1439 System.out.println("Warning!!! Entity's 'setNotationName' and/or getNotationName' failed!"); 1440 OK = false; 1441 } 1442 ((org.apache.xerces.dom.EntityImpl) entity).setPublicId("testPublicId"); 1443 compare = "testPublicId"; 1444 if(! compare.equals(entity.getPublicId())) 1445 { 1446 System.out.println("Warning!!! Entity's 'setPublicId' and/or getPublicId' failed!"); 1447 OK = false; 1448 } 1449 ((org.apache.xerces.dom.EntityImpl) entity).setSystemId("testSystemId"); 1450 compare = "testSystemId"; 1451 if(! compare.equals(entity.getSystemId())) 1452 { 1453 System.out.println("Warning!!! Entity's 'setSystemId' and/or getSystemId' failed!"); 1454 OK = false; 1455 } 1456 // entity.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** 1457 1458 // For debugging***** println("All Entity method calls worked correctly."); 1459 if (!OK) 1460 System.out.println("\n*****The Entity method calls listed above failed, all others worked correctly.*****"); 1461 // println(""); 1462 } 1463 /** 1464 * This method tests EntityReference methods for the XML DOM implementation 1465 * version 2.0 10/12/98 1466 * @param document org.w3c.dom.Document 1467 * 1468 * @author Philip W. Davis 1469 */ 1470 public void testEntityReference(org.w3c.dom.Document document) 1471 { 1472 EntityReference entityReference; 1473 Node node, node2; 1474 boolean OK = true; 1475 // For debugging***** println("\n testEntityReference's outputs:\n"); 1476 entityReference = (EntityReference) document.getLastChild().getLastChild().getLastChild().getFirstChild(); 1477 node = entityReference; 1478 node2 = node.cloneNode(true); 1479 // Check nodes for equality, both their name and value or lack thereof 1480 if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 1481 (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node 1482 ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality 1483 :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't 1484 { 1485 System.out.println("'cloneNode' did not clone the EntityReference node correctly"); 1486 OK = false; 1487 } 1488 // Deep clone test comparison is in testNode & testDocument 1489 1490 // entityReference.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** 1491 1492 // For debugging***** println("All EntityReference method calls worked correctly."); 1493 if (!OK) 1494 System.out.println("\n*****The EntityReference method calls listed above failed, all others worked correctly.*****"); 1495 // println(""); 1496 } 1497 /** 1498 * This method tests Node methods for the XML DOM implementation 1499 * version 2.0 10/12/98 1500 * @param document org.w3c.dom.Document 1501 * 1502 * @author Philip W. Davis 1503 * 1504 * 1505 ********* This is only for a test of cloneNode "deep"******* 1506 ********* And for error tests********* 1507 */ 1508 public void testNode(org.w3c.dom.Document document) 1509 { 1510 Node node, node2; 1511 boolean result; 1512 boolean OK = true; 1513 // For debugging***** println("\n testNode's outputs:\n"); 1514 node = document.getDocumentElement(); 1515 node2 = node.cloneNode(true); 1516 result = treeCompare(node, node2); // Deep clone test of cloneNode 1517 if (result) 1518 { 1519 //println("'cloneNode' successfully cloned this whole node tree (deep)!"); 1520 } 1521 else 1522 { 1523 System.out.println("'cloneNode' did not successfully clone this whole node tree (deep)!"); 1524 OK = false; 1525 } 1526 //!! The following gives a did not clone successfully message********* 1527 node = document.getDocumentElement(); 1528 node2 = node.getFirstChild(); 1529 result = treeCompare(node, node2); 1530 if (!result) 1531 { 1532 //println("'cloneNode' did not successfully clone this whole node tree (deep)!"); 1533 } 1534 else 1535 { 1536 System.out.println("'cloneNode' was supposed to fail here, either it or 'treeCompare' failed!!!"); 1537 OK = false; 1538 } 1539 // Deep clone test also in testDocument 1540 1541 // For debugging***** println("All Node method calls worked correctly."); 1542 if (!OK) 1543 System.out.println("\n*****The Node method calls listed above failed, all others worked correctly.*****"); 1544 // println(""); 1545 } 1546 /** 1547 * This method tests Notation methods for the XML DOM implementation 1548 * version 2.0 10/12/98 1549 * @param document org.w3c.dom.Document 1550 * 1551 * @author Philip W. Davis 1552 */ 1553 public void testNotation(org.w3c.dom.Document document) 1554 { 1555 Node node, node2; 1556 Notation notation; 1557 boolean OK = true; 1558 String compare; 1559 // For debugging***** println("\n testNotation's outputs:\n"); 1560 notation = (Notation) document.getDoctype().getNotations().getNamedItem("ourNotationNode"); 1561 node = notation; 1562 node2 = notation.cloneNode(true);//*****? 1563 // Check nodes for equality, both their name and value or lack thereof 1564 if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 1565 (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node 1566 ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality 1567 :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't 1568 { 1569 System.out.println("'cloneNode' did not clone the Notation node correctly"); 1570 OK = false; 1571 } 1572 // Deep clone test comparison is in testNode & testDocument 1573 1574 ((org.apache.xerces.dom.NotationImpl) notation).setPublicId("testPublicId");//*****? 1575 compare = "testPublicId"; 1576 if (!compare.equals(notation.getPublicId())) 1577 { 1578 System.out.println("Warning!!! Notation's 'getPublicId' failed!"); 1579 OK = false; 1580 } 1581 ((org.apache.xerces.dom.NotationImpl) notation).setSystemId("testSystemId");//*****? 1582 compare = "testSystemId"; 1583 if (! compare.equals(notation.getSystemId())) 1584 { 1585 System.out.println("Warning!!! Notation's 'getSystemId' failed!"); 1586 OK = false; 1587 } 1588 // notation.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** 1589 1590 // For debugging***** println("All Notation method calls worked correctly."); 1591 if (!OK) 1592 System.out.println("\n*****The Notation method calls listed above failed, all others worked correctly.*****"); 1593 // println(""); 1594 } 1595 /** 1596 * This method tests ProcessingInstruction methods for the XML DOM implementation 1597 * version 2.0 10/12/98 1598 * @param document org.w3c.dom.Document 1599 * 1600 * @author Philip W. Davis 1601 */ 1602 public void testPI(org.w3c.dom.Document document) 1603 { 1604 Node node, node2; 1605 ProcessingInstruction pI, pI2; 1606 String compare; 1607 boolean OK = true; 1608 // For debugging***** println("\n testPI's outputs:\n"); 1609 pI = (ProcessingInstruction) document.getDocumentElement().getFirstChild();// Get doc's ProcessingInstruction 1610 pI2 = (org.apache.xerces.dom.ProcessingInstructionImpl) pI.cloneNode(true);//*****? 1611 // Check nodes for equality, both their name and value or lack thereof 1612 if (!(pI.getNodeName().equals(pI2.getNodeName()) && // Compares node names for equality 1613 (pI.getNodeValue() != null && pI2.getNodeValue() != null) // Checks to make sure each node has a value node 1614 ? pI.getNodeValue().equals(pI2.getNodeValue()) // If both have value nodes test those value nodes for equality 1615 :(pI.getNodeValue() == null && pI2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't 1616 { 1617 System.out.println("'cloneNode' did not clone the Entity node correctly"); 1618 OK = false; 1619 } 1620 // Deep clone test comparison is in testNode & testDocument 1621 compare = "This is [#document: null]'s processing instruction"; 1622 if (! compare.equals(pI.getData())) 1623 { 1624 System.out.println("Warning!!! PI's 'getData' failed!"); 1625 OK = false; 1626 } 1627 1628 pI.setData("PI's reset data"); 1629 compare = "PI's reset data"; 1630 if (! compare.equals(pI.getData())) 1631 { 1632 System.out.println("Warning!!! PI's 'setData' failed!"); 1633 OK = false; 1634 } 1635 compare = "dTargetProcessorChannel"; 1636 if (! compare.equals(pI.getTarget())) 1637 { 1638 System.out.println("Warning!!! PI's 'getTarget' failed!"); 1639 OK = false; 1640 } 1641 1642 // For debugging***** println("All PI method calls worked correctly."); 1643 if (!OK) 1644 System.out.println("\n*****The PI method calls listed above failed, all others worked correctly.*****"); 1645 1646 // println(""); 1647 } 1648 /** 1649 * This method tests Text methods for the XML DOM implementation 1650 * version 2.0 10/12/98 1651 * @param document org.w3c.dom.Document 1652 * 1653 * @author Philip W. Davis 1654 */ 1655 public void testText(org.w3c.dom.Document document) 1656 { 1657 Node node, node2; 1658 Text text; 1659 String compare; 1660 boolean OK = true; 1661 // For debugging***** println("\n testText's outputs:\n"); 1662 node = document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // charData gets textNode11 1663 text = (Text) node; 1664 node2 = node.cloneNode(true);//*****? 1665 // Check nodes for equality, both their name and value or lack thereof 1666 if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 1667 (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node 1668 ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality 1669 :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't 1670 { 1671 System.out.println("'cloneNode' did not clone the Text node correctly"); 1672 OK = false; 1673 } 1674 // Deep clone test comparison is in testNode & testDocument 1675 text.splitText(25); 1676 compare = "dBodyLevel31'sChildTextNo"; // Three original text nodes were concatenated by 'normalize' in testElement 1677 if (! compare.equals(text.getNodeValue())) 1678 { 1679 System.out.println("First part of Text's split text failed!" ); 1680 OK = false; 1681 } 1682 compare = "de11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13";// Three original text nodes were concatenated by 'normalize' in testElement 1683 if (! compare.equals(text.getNextSibling().getNodeValue())) 1684 { 1685 System.out.println("The second part of Text's split text failed!") ; 1686 OK = false; 1687 } 1688 1689 1690 1691 1692 //************************************************* ERROR TESTS 1693 DTest tests = new DTest(); 1694 //!! Throws INDEX_SIZE_ERR ******************** 1695 // text.splitText(-1); 1696 // text.splitText(100); 1697 1698 // For debugging***** println("All Text method calls worked correctly."); 1699 if (!OK) 1700 System.out.println("\n*****The Text method calls listed above failed, all others worked correctly.*****"); 1701 1702 // println(""); 1703 } 1704 /** 1705 * 1706 * @param node org.w3c.dom.Node 1707 * @param node2 org.w3c.dom.Node 1708 * 1709 * @author Philip W. Davis 1710 */ 1711 public boolean treeCompare(Node node, Node node2) 1712 { 1713 boolean answer = true; 1714 1715 Node kid, kid2; // Check the subtree for equality 1716 kid = node.getFirstChild(); 1717 kid2 = node2.getFirstChild(); 1718 if (kid != null && kid2 != null) 1719 { 1720 answer = treeCompare(kid, kid2); 1721 if (!answer) 1722 return answer; 1723 else 1724 if (kid.getNextSibling() != null && kid2.getNextSibling() != null) 1725 { 1726 while (kid.getNextSibling() != null && kid2.getNextSibling() != null) 1727 { 1728 answer = treeCompare(kid.getNextSibling(), kid2.getNextSibling()); 1729 if (!answer) 1730 return answer; 1731 else 1732 { 1733 kid = kid.getNextSibling(); 1734 kid2 = kid2.getNextSibling(); 1735 } 1736 } 1737 } else 1738 if (!(kid.getNextSibling() == null && kid2.getNextSibling() == null)) 1739 { 1740 return false; 1741 } 1742 } else 1743 if (kid != kid2) 1744 { 1745 return false; 1746 } 1747 1748 // Check nodes for equality, both their name and value or lack thereof 1749 if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality 1750 (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node 1751 ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality 1752 :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't 1753 { 1754 return false; // Return false if "any" of the above conditions are false 1755 } 1756 return answer; 1757 } 1758 }