KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dom > DTest


1 /* $Id: DTest.java,v 1.2 2005/01/26 08:28:45 jkjome 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 java.lang.reflect.InvocationTargetException JavaDoc;
61 import java.lang.reflect.Method JavaDoc;
62
63 import org.w3c.dom.Attr JavaDoc;
64 import org.w3c.dom.CDATASection JavaDoc;
65 import org.w3c.dom.CharacterData JavaDoc;
66 import org.w3c.dom.Comment JavaDoc;
67 import org.w3c.dom.DOMException JavaDoc;
68 import org.w3c.dom.DOMImplementation JavaDoc;
69 import org.w3c.dom.Document JavaDoc;
70 import org.w3c.dom.DocumentFragment JavaDoc;
71 import org.w3c.dom.DocumentType JavaDoc;
72 import org.w3c.dom.Element JavaDoc;
73 import org.w3c.dom.Entity JavaDoc;
74 import org.w3c.dom.EntityReference JavaDoc;
75 import org.w3c.dom.NamedNodeMap JavaDoc;
76 import org.w3c.dom.Node JavaDoc;
77 import org.w3c.dom.NodeList JavaDoc;
78 import org.w3c.dom.Notation JavaDoc;
79 import org.w3c.dom.ProcessingInstruction JavaDoc;
80 import org.w3c.dom.Text JavaDoc;
81
82 import dom.util.Assertion;
83
84 /**
85  * This class tests methods for XML DOM implementation
86  * version 2.0 10/12/98
87  *
88  * DOMException errors are tested by calls to DOMExceptionsTest from: Main, docBuilder...
89  *
90  * @author Philip W. Davis
91  */

92  
93 public class DTest {
94     
95     public static Element JavaDoc testElementNode;
96     public static Attr JavaDoc testAttributeNode;
97     public static Text JavaDoc testTextNode;
98     public static CDATASection JavaDoc testCDATASectionNode;
99     public static EntityReference JavaDoc testEntityReferenceNode;
100     public static Entity JavaDoc testEntityNode;
101     public static ProcessingInstruction JavaDoc testProcessingInstructionNode;
102     public static Comment JavaDoc testCommentNode;
103     public static Document JavaDoc testDocumentNode;
104     public static DocumentType JavaDoc testDocumentTypeNode;
105     public static DocumentFragment JavaDoc testDocumentFragmentNode;
106     public static Notation JavaDoc testNotationNode;
107
108 /**
109  *
110  * version 2.0 10/12/98
111  *
112  * @author Philip W. Davis
113  */

114 public DTest() {
115     super();
116     
117 }
118 /**
119  * version 3.0 01/25/99
120  *
121  * @return org.w3c.dom.Document
122  *
123  * @author Philip W. Davis
124  */

125 public Document JavaDoc createDocument() {
126     return new org.enhydra.apache.xerces.dom.DocumentImpl(); //Replace with a Document creator
127
}
128 /**
129  * version 3.0 01/25/99
130  *
131  * @return org.w3c.dom.DocumentType
132  * @param name java.lang.String
133  *
134  * @author Philip W. Davis
135  */

136 public DocumentType JavaDoc createDocumentType(Document JavaDoc doc, String JavaDoc name) {
137     return ((org.enhydra.apache.xerces.dom.DocumentImpl) doc).createDocumentType(name, null, null); //Replace with a DocumentType creator
138
}
139 /**
140  * version 3.0 01/25/99
141  *
142  * @return org.w3c.dom.Entity
143  * @param doc org.w3c.dom.Document
144  * @param name java.lang.String
145  *
146  * @author Philip W. Davis
147  */

148 public Entity JavaDoc createEntity(Document JavaDoc doc, String JavaDoc name) {
149     return new org.enhydra.apache.xerces.dom.EntityImpl((org.enhydra.apache.xerces.dom.DocumentImpl)doc, name); //Replace with an Entity creator
150
}
151 /**
152  * version 3.0 01/25/99
153  *
154  * @return org.w3c.dom.Notation
155  * @param doc org.w3c.dom.Document
156  * @param name java.lang.String
157  *
158  * @author Philip W. Davis
159  */

160 public Notation JavaDoc createNotation(Document JavaDoc doc, String JavaDoc name) {
161     return new org.enhydra.apache.xerces.dom.NotationImpl((org.enhydra.apache.xerces.dom.DocumentImpl) doc, name); // Replace with a Notation creator
162
}
163 /**
164  * This method builds test documents for the XML DOM implementation
165  * version 2.0 10/12/98
166  * @param document org.w3c.dom.Document
167  * @param name document's name
168  * @param type document's type
169  *
170  * @author Philip W. Davis
171  */

172 public void docBuilder(org.w3c.dom.Document JavaDoc document, String JavaDoc name)
173 {
174     Document JavaDoc doc = document;
175     boolean OK = true;
176         
177     Element JavaDoc docFirstElement = doc.createElement(name + "FirstElement");
178     doc.appendChild(docFirstElement);
179     docFirstElement.setAttribute(name + "FirstElement", name + "firstElement");
180     
181     ProcessingInstruction JavaDoc docProcessingInstruction = doc.createProcessingInstruction(name +
182                     "TargetProcessorChannel", "This is " + doc + "'s processing instruction");
183     docFirstElement.appendChild(docProcessingInstruction);
184     
185     Element JavaDoc docBody = doc.createElement(name + "TestBody");
186     docFirstElement.appendChild(docBody);
187     
188     Element JavaDoc docBodyLevel21 = doc.createElement(name + "BodyLevel21");
189     Element JavaDoc docBodyLevel22 = doc.createElement(name + "BodyLevel22");
190     Element JavaDoc docBodyLevel23 = doc.createElement(name + "BodyLevel23");
191     Element JavaDoc docBodyLevel24 = doc.createElement(name + "BodyLevel24");
192     docBody.appendChild(docBodyLevel21);
193     docBody.appendChild(docBodyLevel22);
194     docBody.appendChild(docBodyLevel23);
195     docBody.appendChild(docBodyLevel24);
196     
197     Element JavaDoc docBodyLevel31 = doc.createElement(name + "BodyLevel31");
198     Element JavaDoc docBodyLevel32 = doc.createElement(name + "BodyLevel32");
199     Element JavaDoc docBodyLevel33 = doc.createElement(name + "BodyLevel33");
200     Element JavaDoc docBodyLevel34 = doc.createElement(name + "BodyLevel34");
201     docBodyLevel21.appendChild(docBodyLevel31);
202     docBodyLevel21.appendChild(docBodyLevel32);
203     docBodyLevel22.appendChild(docBodyLevel33);
204     docBodyLevel22.appendChild(docBodyLevel34);
205     
206     Text JavaDoc docTextNode11 = doc.createTextNode(name + "BodyLevel31'sChildTextNode11");
207     Text JavaDoc docTextNode12 = doc.createTextNode(name + "BodyLevel31'sChildTextNode12");
208     Text JavaDoc docTextNode13 = doc.createTextNode(name + "BodyLevel31'sChildTextNode13");
209     Text JavaDoc docTextNode2 = doc.createTextNode(name + "TextNode2");
210     Text JavaDoc docTextNode3 = doc.createTextNode(name + "TextNode3");
211     Text JavaDoc docTextNode4 = doc.createTextNode(name + "TextNode4");
212     docBodyLevel31.appendChild(docTextNode11);
213     docBodyLevel31.appendChild(docTextNode12);
214     docBodyLevel31.appendChild(docTextNode13);
215     docBodyLevel32.appendChild(docTextNode2);
216     docBodyLevel33.appendChild(docTextNode3);
217     docBodyLevel34.appendChild(docTextNode4);
218     
219     CDATASection JavaDoc docCDATASection = doc.createCDATASection("<![CDATA[<greeting>Hello, world!</greeting>]]>");
220     docBodyLevel23.appendChild(docCDATASection);
221     
222     Comment JavaDoc docComment = doc.createComment("This should be a comment of some kind ");
223     docBodyLevel23.appendChild(docComment);
224     
225     EntityReference JavaDoc docReferenceEntity = doc.createEntityReference("ourEntityNode");
226     docBodyLevel24.appendChild(docReferenceEntity);
227
228     DTest make = new DTest();
229     Notation JavaDoc docNotation = make.createNotation(doc, "ourNotationNode");
230 // NotationImpl docNotation = new NotationImpl((DocumentImpl) doc, "ourNotationNode");//*****?
231
DocumentType JavaDoc docType = (DocumentType JavaDoc)doc.getFirstChild();
232     docType.getNotations().setNamedItem(docNotation);
233     
234     DocumentFragment JavaDoc docDocFragment = doc.createDocumentFragment();
235     
236 // System.out.println("This document's first element name is " + docFirstElement.getTagName() + "\n");
237

238
239 //***********Following are for errorTests
240
Text JavaDoc docNode3 = doc.createTextNode(name + "docTextNode3");
241     Text JavaDoc docNode4 = doc.createTextNode(name + "docTextNode4");
242     
243     Entity JavaDoc docEntity = (Entity JavaDoc) doc.getDoctype().getEntities().getNamedItem("ourEntityNode"); // Get the Entity node
244
DocumentType JavaDoc docDocType = (DocumentType JavaDoc) doc.getFirstChild(); // Get the DocumentType node
245
EntityReference JavaDoc entityReferenceText = (EntityReference JavaDoc) doc.getLastChild().getLastChild().getLastChild().getFirstChild();
246     Text JavaDoc entityReferenceText2 = doc.createTextNode("entityReferenceText information");
247 //************************************************* ERROR TESTS
248

249     OK &= Assertion.assertTrue(DOMExceptionsTest(document, "appendChild", new Class JavaDoc[]{Node JavaDoc.class}, new Object JavaDoc[]{docBody}, DOMException.HIERARCHY_REQUEST_ERR ));
250     OK &= Assertion.assertTrue(DOMExceptionsTest(docNode3, "appendChild", new Class JavaDoc[]{Node JavaDoc.class}, new Object JavaDoc[]{docNode4}, DOMException.HIERARCHY_REQUEST_ERR ));
251     OK &= Assertion.assertTrue(DOMExceptionsTest(doc, "insertBefore", new Class JavaDoc[]{Node JavaDoc.class, Node JavaDoc.class}, new Object JavaDoc[]{docEntity, docFirstElement}, DOMException.HIERARCHY_REQUEST_ERR ));
252     OK &= Assertion.assertTrue(DOMExceptionsTest(doc, "replaceChild", new Class JavaDoc[]{Node JavaDoc.class, Node JavaDoc.class}, new Object JavaDoc[]{docCDATASection, docFirstElement}, DOMException.HIERARCHY_REQUEST_ERR ));
253
254         docFirstElement.setNodeValue("This shouldn't do anything!");
255     OK &= Assertion.assertTrue(docFirstElement.getNodeValue() == null);
256         docReferenceEntity.setNodeValue("This shouldn't do anything!");
257     OK &= Assertion.assertTrue(docReferenceEntity.getNodeValue() == null);
258         docEntity.setNodeValue("This shouldn't do anything!");
259     OK &= Assertion.assertTrue(docEntity.getNodeValue() == null);
260         doc.setNodeValue("This shouldn't do anything!");
261     OK &= Assertion.assertTrue(doc.getNodeValue() == null);
262         docType.setNodeValue("This shouldn't do anything!");
263     OK &= Assertion.assertTrue(docType.getNodeValue() == null);
264         docDocFragment.setNodeValue("This shouldn't do anything!");
265     OK &= Assertion.assertTrue(docDocFragment.getNodeValue() == null);
266         docNotation.setNodeValue("This shouldn't do anything!");
267     OK &= Assertion.assertTrue(docNotation.getNodeValue() == null);
268
269     OK &= Assertion.assertTrue(DOMExceptionsTest(docReferenceEntity, "appendChild", new Class JavaDoc[]{Node JavaDoc.class}, new Object JavaDoc[]{entityReferenceText2 }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
270     OK &= Assertion.assertTrue(DOMExceptionsTest(docBodyLevel32, "insertBefore", new Class JavaDoc[]{Node JavaDoc.class, Node JavaDoc.class}, new Object JavaDoc[]{docTextNode11,docBody }, DOMException.NOT_FOUND_ERR ));
271     OK &= Assertion.assertTrue(DOMExceptionsTest(docBodyLevel32, "removeChild", new Class JavaDoc[]{Node JavaDoc.class}, new Object JavaDoc[]{docFirstElement}, DOMException.NOT_FOUND_ERR ));
272     OK &= Assertion.assertTrue(DOMExceptionsTest(docBodyLevel32, "replaceChild", new Class JavaDoc[]{Node JavaDoc.class, Node JavaDoc.class}, new Object JavaDoc[]{docTextNode11,docFirstElement }, DOMException.NOT_FOUND_ERR ));
273
274
275 //!! Throws a NOT_FOUND_ERR ********
276

277      // docBodyLevel32.getAttributes().removeNamedItem(testAttribute.getName()); 16 // To test removeNamedItem
278

279 }//END OF DOCBUILDER
280
/**
281  * version 3.0 01/25/99
282  *
283  * @return boolean
284  * @param node java.lang.Object
285  * @param mNameIndex int
286  * @param signatureIndex int
287  * @param parameters java.lang.Object[]
288  * @param code short
289  *
290  * @author Philip W. Davis
291  */

292 public static boolean DOMExceptionsTest(Object JavaDoc node, String JavaDoc methodName, Class JavaDoc[] methodSignature, Object JavaDoc[] parameters, short code) {
293
294     boolean asExpected = false;
295     Method JavaDoc method;
296
297     try
298     {
299         method = node.getClass().getMethod(methodName,methodSignature);
300         method.invoke(node, parameters);
301     }catch(InvocationTargetException JavaDoc exc)
302     {
303         Throwable JavaDoc realE = exc.getTargetException();
304         if(realE instanceof DOMException JavaDoc)
305         {
306             asExpected = (((DOMException JavaDoc)realE).code== code);
307             if(!asExpected)
308                 System.out.println("Wrong DOMException(" + ((DOMException JavaDoc)realE).code + ")");
309         }
310         else
311             System.out.println("Wrong Exception (" + code + ")");
312
313         if(!asExpected)
314         {
315             System.out.println("Expected DOMException (" + code + ") not thrown");
316         }
317     }catch(Exception JavaDoc exc)
318     {
319         System.out.println("test invocation failure (" + exc + ")");
320     }
321
322     return (asExpected);
323 }
324
325 /**
326  * @author Philip W. Davis
327  * @param document org.w3c.dom.Document
328  */

329 public void findTestNodes(Document JavaDoc document) {
330     Node JavaDoc node = document;
331     int nodeCount = 0;
332
333     // Walk the tree until you find and assign all node types needed that exist.
334
while (node != null && nodeCount < 12)
335     {
336
337         switch (node.getNodeType())
338         {
339         case org.w3c.dom.Node.ELEMENT_NODE :
340             if (testElementNode == null) {testElementNode = (Element JavaDoc)node; nodeCount++;}
341             break;
342         case org.w3c.dom.Node.ATTRIBUTE_NODE :
343             if (testAttributeNode == null) {testAttributeNode = (Attr JavaDoc)node; nodeCount++;}
344             break;
345         case org.w3c.dom.Node.TEXT_NODE :
346             if (testTextNode == null) {testTextNode = (Text JavaDoc)node; nodeCount++;}
347             break;
348         case org.w3c.dom.Node.CDATA_SECTION_NODE :
349             if (testCDATASectionNode == null) {testCDATASectionNode = (CDATASection JavaDoc)node; nodeCount++;}
350             break;
351         case org.w3c.dom.Node.ENTITY_REFERENCE_NODE :
352             if (testEntityReferenceNode == null) {testEntityReferenceNode = (EntityReference JavaDoc)node; nodeCount++;}
353             break;
354         case org.w3c.dom.Node.ENTITY_NODE :
355             if (testEntityNode == null) {testEntityNode = (Entity JavaDoc)node; nodeCount++;}
356             break;
357         case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE :
358             if (testProcessingInstructionNode == null) {testProcessingInstructionNode = (ProcessingInstruction JavaDoc)node; nodeCount++;}
359             break;
360         case org.w3c.dom.Node.COMMENT_NODE :
361             if (testCommentNode == null) {testCommentNode = (Comment JavaDoc)node; nodeCount++;}
362             break;
363         case org.w3c.dom.Node.DOCUMENT_TYPE_NODE :
364             if (testDocumentTypeNode == null) {testDocumentTypeNode = (DocumentType JavaDoc)node; nodeCount++;}
365             break;
366         case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE :
367             if (testDocumentFragmentNode == null) {testDocumentFragmentNode = (DocumentFragment JavaDoc)node; nodeCount++;}
368             break;
369         case org.w3c.dom.Node.NOTATION_NODE :
370             if (testNotationNode == null) {testNotationNode = (Notation JavaDoc)node; nodeCount++;}
371             break;
372         case org.w3c.dom.Node.DOCUMENT_NODE :
373             if (testDocumentNode == null) {testDocumentNode = (Document JavaDoc)node; nodeCount++;}
374             break;
375         default:
376         }// End of switch
377
}// End of while
378
}
379
380 /**
381  * @author Philip W. Davis
382  * @param document org.w3c.dom.Document
383  */

384 public void findTestNodes(Node JavaDoc node) {
385
386     DTest test = new DTest();
387     Node JavaDoc kid;
388     // Walk the tree until you find and assign all node types needed that exist.
389

390         
391     if (node.getFirstChild() != null)
392     {
393         kid = node.getFirstChild();
394         test.findTestNodes(kid);
395     }
396             
397                 
398     if (node.getNextSibling() != null)
399     {
400         kid = node.getNextSibling();
401         test.findTestNodes(kid);
402     }
403
404     switch (node.getNodeType())
405     {
406         case org.w3c.dom.Node.ELEMENT_NODE :
407             if (testElementNode == null) {testElementNode = (Element JavaDoc)node; }
408             break;
409         case org.w3c.dom.Node.ATTRIBUTE_NODE :
410             if (testAttributeNode == null) {testAttributeNode = (Attr JavaDoc)node; }
411             break;
412         case org.w3c.dom.Node.TEXT_NODE :
413             if (testTextNode == null) {testTextNode = (Text JavaDoc)node; }
414             break;
415         case org.w3c.dom.Node.CDATA_SECTION_NODE :
416             if (testCDATASectionNode == null) {testCDATASectionNode = (CDATASection JavaDoc)node; }
417             break;
418         case org.w3c.dom.Node.ENTITY_REFERENCE_NODE :
419             if (testEntityReferenceNode == null) {testEntityReferenceNode = (EntityReference JavaDoc)node;}
420             break;
421         case org.w3c.dom.Node.ENTITY_NODE :
422             if (testEntityNode == null) {testEntityNode = (Entity JavaDoc)node;}
423             break;
424         case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE :
425             if (testProcessingInstructionNode == null) {testProcessingInstructionNode = (ProcessingInstruction JavaDoc)node;}
426             break;
427         case org.w3c.dom.Node.COMMENT_NODE :
428             if (testCommentNode == null) {testCommentNode = (Comment JavaDoc)node;}
429             break;
430         case org.w3c.dom.Node.DOCUMENT_TYPE_NODE :
431             if (testDocumentTypeNode == null) {testDocumentTypeNode = (DocumentType JavaDoc)node; }
432             break;
433         case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE :
434             if (testDocumentFragmentNode == null) {testDocumentFragmentNode = (DocumentFragment JavaDoc)node;}
435             break;
436         case org.w3c.dom.Node.NOTATION_NODE :
437             if (testNotationNode == null) {testNotationNode = (Notation JavaDoc)node;}
438             break;
439         case org.w3c.dom.Node.DOCUMENT_NODE :
440             if (testDocumentNode == null) {testDocumentNode = (Document JavaDoc)node;}
441             break;
442         default:
443     }// End of switch
444
}
445     
446 /**
447  *
448  * version 2.0 10/12/98
449  *
450  * @author Philip W. Davis
451  */

452
453 public static void main(String JavaDoc args[]) {
454     System.out.println("# main()");
455     
456     DTest test = new DTest();
457
458     long avgTime = 0;
459     boolean OK = true;
460     long startTime = 0;//****************Time the whole thing for efficiency of DOM implementation
461

462 // for (int i=0; i< 1000; i++)
463
// {
464
startTime = System.currentTimeMillis();
465 // if(!OK)
466
// break;
467

468     Document JavaDoc d = test.createDocument();
469 // Document z = test.createDocument();
470

471     DocumentType JavaDoc docDocType = test.createDocumentType(d,"testDocument1");
472     d.appendChild(docDocType);
473
474     Entity JavaDoc docEntity = test.createEntity( d, "ourEntityNode");
475     Text JavaDoc entityChildText = d.createTextNode("entityChildText information"); // Build a branch for entityReference tests
476
((org.enhydra.apache.xerces.dom.NodeImpl)docEntity).setReadOnly(false, true);
477     docEntity.appendChild(entityChildText); // & for READONLY_ERR tests
478
((org.enhydra.apache.xerces.dom.NodeImpl)docEntity).setReadOnly(true, true);
479     docDocType.getEntities().setNamedItem(docEntity);
480     
481     test.docBuilder(d, "d");
482
483     test.findTestNodes((Node JavaDoc)d);
484 // test.docBuilder(z, "z");
485
try {
486 /**/ test.testAttr(d);
487         test.testCDATASection(d);
488         test.testCharacterData(d);
489         test.testChildNodeList(d);
490         test.testComment(d);
491         test.testDeepNodeList(d);
492         test.testDocument(d);
493         test.testDocumentFragment(d);
494         test.testDocumentType(d);
495         test.testDOMImplementation(d);
496         test.testElement(d);
497         test.testEntity(d);
498         test.testEntityReference(d);
499         test.testNode(d);
500         test.testNotation(d);
501         test.testPI(d);
502         test.testText(d);
503 /**/ test.testDOMerrors(d);
504     
505 //!! Throws WRONG_DOCUMENT_ERR **********
506

507     // z.appendChild(d.createComment("Test doc d comment"));// Tries to append z document with document d comment
508
// d.getDocumentElement().appendChild(z.createElement("newZdocElement"));// Tries to append d document with document z Element
509
// d.getLastChild().getLastChild().insertBefore(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild());// Tries to insert into d document with document z Element
510
// d.replaceChild(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild()); // Tries to replace in d document with document z Element
511

512     /* Attribute newAttribute = d.createAttribute("newAttribute");
513         d.getDocumentElement().setAttributeNode(newAttribute);
514         d.getDocumentElement().getAttributes().setNamedItem(z.createAttribute("newzAttribute"));
515     */

516         
517 //!! Throws INVALID_CHARACTER_ERR **********
518
// ******This just gets us through each method. JKess has a comprehensive test of Invalid Names******
519
// d.createAttribute("Invalid Name"); // Name with blank space
520
// d.createElement("5InvalidName"); // Name starts with numeric
521
// d.createProcessingInstruction("This is the target processor channel","InvalidName>");// Name ends with >
522
// d.getDocumentElement().setAttribute("Invalid%Name",""); // Name contains %
523

524
525 //!! ******** NO_DATA_ALLOWED_ERR ********No cases to test as of 9/15
526

527
528 //!! ******** NO_MODIFICATION_ALLOWED_ERR ******** When read only exists
529
/*
530         
531
532         
533         //**** FOR Element when read only exists********
534         .removeAttribute("aString"); //***** Not until read only exists.
535         .removeAttributeNode(Attribute); //***** Not until read only exists.
536         .setAttribute("aString", "anotherString"); //***** Not until read only exists.
537         
538         
539         //**** FOR Node when read only exists********
540         .appendChild(aNode); //***** Not until read only exists.
541         .insertBefore(aNode, AnotherNode); //***** Not until read only exists.
542         .removeChild(aNode); //***** Not until read only exists.
543         .replaceChild(aNode); //***** Not until read only exists.
544         
545         .splitText(2); //***** Not until read only exists.
546         
547         .setNamedItem(Node); //***** Not until read only exists.
548     */

549     
550
551 //!!******** NOT_SUPPORTED_ERR ********For HTML when implemented
552
/*
553         .createCDATASection("String stuff");
554         .createEntityReference("String stuff");
555         .createProcessingInstruction("String stuff", "Some more String stuff");
556     */

557
558     } catch (Exception JavaDoc e) {
559         System.out.println("Exception is: ");
560         e.printStackTrace();
561         OK = false;
562         
563     }
564 //System.err.println("Elapsed time (measured in seconds): " + ((System.currentTimeMillis() - startTime) / 1000.0));
565
avgTime += System.currentTimeMillis() - startTime;
566 // }//END OF FOR
567

568     
569 // System.err.println("Elapsed time (measured in seconds): " +
570
// ((System.currentTimeMillis() - startTime) / 1000.0));
571
// System.err.println("Elapsed time (measured in mili-seconds): " +
572
// ((System.currentTimeMillis() - startTime)));
573

574
575 // System.err.println("Average Elapsed time (measured in seconds): " + (avgTime/10000000.0) );
576

577 }
578 /**
579  * This method tests Attr methods for the XML DOM implementation
580  * version 2.0 10/12/98
581  * @param document org.w3c.dom.Document
582  *
583  * @author Philip W. Davis
584  */

585 public void testAttr(org.w3c.dom.Document JavaDoc document)
586 {
587     
588     Node JavaDoc node;
589     Attr JavaDoc attributeNode, attribute2;
590     String JavaDoc compare;
591     boolean T = true;
592     boolean F = false;
593     boolean OK = true;
594 // For debugging***** println("\n testAttr's outputs:\n");
595

596     Attr JavaDoc testAttribute = document.createAttribute("testAttribute");
597     testAttribute.setValue("testAttribute's value");
598     node = document.getDocumentElement(); // node gets first element
599
((Element JavaDoc)node).setAttributeNode(testAttribute);
600     attributeNode = ((Element JavaDoc)node).getAttributeNode("testAttribute");
601
602     compare = "testAttribute";
603     if (!compare.equals(attributeNode.getName()))
604     {
605         System.out.println("Warning!!! Attr's 'getName' method failed to work properly!");
606         OK = false;
607     }
608     compare = "testAttribute's value";
609     if (!compare.equals(attributeNode.getNodeValue()))
610     {
611         System.out.println("Warning!!! Attr's 'getNodeValue' method failed to work properly!");
612         OK = false;
613     }
614     if (! T ==attributeNode.getSpecified())
615     {
616         System.out.println("Warning!!! Attr's 'getSpecified' method failed to work properly!");
617         OK = false;
618     }
619     
620     if (!compare.equals(attributeNode.getValue()))
621     {
622         System.out.println("Warning!!! Attr's 'getValue' method failed to work properly!");
623         OK = false;
624     }
625     
626     attributeNode.setNodeValue("Reset Value");
627     compare = "Reset Value";
628     if (!compare.equals(attributeNode.getNodeValue()))
629     {
630         System.out.println("Warning!!! Attr's 'setNodeValue' method failed to work properly!");
631         OK = false;
632     }
633     ((org.enhydra.apache.xerces.dom.AttrImpl)attributeNode).setSpecified(F);//***** How do we change this for external use??
634
if (! F ==attributeNode.getSpecified())
635     {
636         System.out.println("Warning!!! Attr's 'setSpecified' method failed to work properly!");
637         OK = false;
638     }
639     
640     attributeNode.setValue(null);
641     if (! attributeNode.getValue().equals(""))
642     {
643         System.out.println("Warning!!! Attr's 'setValue' to 'null' method failed to work properly!");
644         OK = false;
645     }
646     
647     attributeNode.setValue("Another value ");
648     compare = "Another value ";
649     if (!compare.equals(attributeNode.getValue()))
650     {
651         System.out.println("Warning!!! Attr's 'setValue' method failed to work properly!");
652         OK = false;
653     }
654
655     node = attributeNode.cloneNode(T);//*****?
656
// Check nodes for equality, both their name and value or lack thereof
657
if (! (node.getNodeName().equals(attributeNode.getNodeName()) && // Compares node names for equality
658
(node.getNodeValue() != null && attributeNode.getNodeValue() != null) // Checks to make sure each node has a value node
659
? node.getNodeValue().equals(attributeNode.getNodeValue()) // If both have value nodes test those value nodes for equality
660
: (node.getNodeValue() == null && attributeNode.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't
661
{
662             System.out.println("'cloneNode' did not clone the Attribute node correctly");
663             OK = false;
664         }
665         // Deep clone test comparison is in testNode & testDocument
666

667 //************************************************* ERROR TESTS
668
Assertion.assertTrue(
669           DOMExceptionsTest(document.getDocumentElement(),
670                                   "appendChild",
671                                   new Class JavaDoc[]{Node JavaDoc.class},
672                                   new Object JavaDoc[]{attributeNode},
673                                   DOMException.HIERARCHY_REQUEST_ERR));
674
675     attribute2 = document.createAttribute("testAttribute2");
676         Assertion.assertTrue(
677           DOMExceptionsTest(document.getDocumentElement(),
678                                   "removeAttributeNode",
679                                   new Class JavaDoc[]{Attr JavaDoc.class},
680                                   new Object JavaDoc[]{attribute2},
681                                   DOMException.NOT_FOUND_ERR));
682
683         Element JavaDoc element = (Element JavaDoc)document.getLastChild().getLastChild();
684         // Tests setNamedItem
685
Assertion.assertTrue(
686           DOMExceptionsTest(element,
687                                   "setAttributeNode",
688                                   new Class JavaDoc[]{Attr JavaDoc.class},
689                                   new Object JavaDoc[]{testAttribute},
690                                   DOMException.INUSE_ATTRIBUTE_ERR));
691     
692     if (! OK)
693         System.out.println("\n*****The Attr method calls listed above failed, all others worked correctly.*****");
694 // println("");
695
}
696 /**
697  * This method tests CDATASection methods for the XML DOM implementation
698  * version 2.0 10/12/98
699  * @param document org.w3c.dom.Document
700  *
701  * @author Philip W. Davis
702  */

703 public void testCDATASection(org.w3c.dom.Document JavaDoc document)
704 {
705     
706     Node JavaDoc node, node2;
707     boolean T = true;
708     boolean OK = true;
709 // For debugging***** println("\n testCDATASection's outputs:\n");
710
node = document.getDocumentElement().getElementsByTagName("dBodyLevel23").item(0).getFirstChild(); // node gets CDATASection node
711

712     node2 = node.cloneNode(T);//*****?
713
// Check nodes for equality, both their name and value or lack thereof
714
if (! (node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
715
(node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node
716
? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality
717
: (node.getNodeValue() == null && node2.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't
718
{
719         System.out.println("'cloneNode' did not clone the CDATASection node correctly");
720         OK = false;
721     }
722     // Deep clone test comparison is in testNode & testDocument
723

724 // For debugging***** println("All CDATASection method calls worked correctly.");
725

726     if (! OK)
727         System.out.println("\n*****The CDATASection method calls listed above failed, all others worked correctly.*****");
728 // println("");
729
}
730 /**
731  * This method tests CharacterData methods for the XML DOM implementation
732  * version 2.0 10/12/98
733  * @param document org.w3c.dom.Document
734  *
735  * @author Philip W. Davis
736  */

737 public void testCharacterData(org.w3c.dom.Document JavaDoc document)
738 {
739     CharacterData JavaDoc charData;
740     String JavaDoc compareData, newData, resetData;
741     boolean OK = true;
742 // For debugging***** println("\n testCharacterData's outputs:\n");
743
charData = (CharacterData JavaDoc) document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // charData gets textNode11
744
compareData = "dBodyLevel31'sChildTextNode11";
745     if (!compareData.equals(charData.getData()))
746     {
747         System.out.println("Warning!!! CharacterData's 'getData' failed to work properly!\n This may corrupt other CharacterData tests!!!*****");
748         OK = false;
749     }
750     
751     resetData = charData.getData();
752     // println("This node's original data is: " + charData.getData());
753

754     newData = " This is new data for this node";
755     compareData = charData.getData() + newData;
756     charData.appendData(newData);
757     if (!compareData.equals(charData.getData()))
758     {
759         System.out.println("Warning!!! CharacterData's 'appendData' failed to work properly!");
760         OK = false;
761     }
762     // println("This node's appended data is: " + charData.getData());
763

764     compareData = "dBodyLevel";
765     charData.deleteData(10, 100);
766     if (!compareData.equals(charData.getData()))
767     {
768         System.out.println("Warning!!! CharacterData's 'deleteData' failed to work properly!");
769         OK = false;
770     }
771     // println("This node's partially deleted data is: " + charData.getData());
772

773     int length = 10;
774     if (!(length == charData.getLength()))
775     {
776         System.out.println("Warning!!! CharacterData's 'getLength' failed to work properly!");
777         OK = false;
778     }
779     // println("This node's data length is: " + charData.getLength());
780

781     compareData = "dBody' This is data inserted into this node'Level";
782     charData.insertData(5, "' This is data inserted into this node'");
783     if (!compareData.equals(charData.getData()))
784     {
785         System.out.println("Warning!!! CharacterData's 'insertData' failed to work properly!");
786         OK = false;
787     }
788     // println("This node's updated with insert data is: " + charData.getData());
789

790     compareData = "dBody' This is ' replacement data'ted into this node'Level";
791     charData.replaceData(15, 10, "' replacement data'");
792     if (!compareData.equals(charData.getData()))
793     {
794         System.out.println("Warning!!! CharacterData's 'replaceData' failed to work properly!");
795         OK = false;
796     }
797     // println("This node's updated with replacement data is: " +charData.getData());
798

799     compareData = "New data A123456789B123456789C123456789D123456789E123456789";
800     charData.setData("New data A123456789B123456789C123456789D123456789E123456789");
801     if (!compareData.equals(charData.getData()))
802     {
803         System.out.println("Warning!!! CharacterData's 'setData' failed to work properly!");
804         OK = false;
805     }
806     // println("This node's new data via setData: " + charData.getData());
807

808     compareData = "123456789D123456789E123456789";
809     if (!compareData.equals(charData.substringData(30, 30)))
810     {
811         System.out.println("Warning!!! CharacterData's 'substringData' failed to work properly!");
812         OK = false;
813     }
814     // println("Using subString 30,30 you get:" + charData.substringData(30,30));
815

816     compareData = "New data A123456789B12345";
817     if (!compareData.equals(charData.substringData(0, 25)))
818     {
819         System.out.println("Warning!!! CharacterData's 'substringData' failed to work properly!");
820         OK = false;
821     }
822     // println("Using subString 0,25 you get:" + charData.substringData(0,25));
823

824 //************************************************* ERROR TESTS
825

826 //!! Throws INDEX_SIZE_ERR ********************
827
OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "deleteData", new Class JavaDoc[]{int.class, int.class},
828             new Object JavaDoc[]{new Integer JavaDoc(-1),new Integer JavaDoc(5) }, DOMException.INDEX_SIZE_ERR ));
829     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "deleteData", new Class JavaDoc[]{int.class, int.class},
830             new Object JavaDoc[]{new Integer JavaDoc(2),new Integer JavaDoc(-1) }, DOMException.INDEX_SIZE_ERR ));
831     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "deleteData", new Class JavaDoc[]{int.class, int.class},
832             new Object JavaDoc[]{new Integer JavaDoc(100),new Integer JavaDoc(5) }, DOMException.INDEX_SIZE_ERR ));
833     
834     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "insertData", new Class JavaDoc[]{int.class, String JavaDoc.class},
835             new Object JavaDoc[]{new Integer JavaDoc(-1),"Stuff inserted" }, DOMException.INDEX_SIZE_ERR ));
836     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "insertData", new Class JavaDoc[]{int.class, String JavaDoc.class},
837             new Object JavaDoc[]{new Integer JavaDoc(100),"Stuff inserted" }, DOMException.INDEX_SIZE_ERR ));
838     
839     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "replaceData", new Class JavaDoc[]{int.class, int.class, String JavaDoc.class},
840             new Object JavaDoc[]{new Integer JavaDoc(-1),new Integer JavaDoc(5),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR ));
841     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "replaceData", new Class JavaDoc[]{int.class, int.class, String JavaDoc.class},
842             new Object JavaDoc[]{new Integer JavaDoc(100),new Integer JavaDoc(5),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR ));
843     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "replaceData", new Class JavaDoc[]{int.class, int.class, String JavaDoc.class},
844             new Object JavaDoc[]{new Integer JavaDoc(2),new Integer JavaDoc(-1),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR ));
845     
846     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "substringData", new Class JavaDoc[]{int.class, int.class},
847             new Object JavaDoc[]{new Integer JavaDoc(-1),new Integer JavaDoc(5) }, DOMException.INDEX_SIZE_ERR ));
848     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "substringData", new Class JavaDoc[]{int.class, int.class},
849             new Object JavaDoc[]{new Integer JavaDoc(100),new Integer JavaDoc(5) }, DOMException.INDEX_SIZE_ERR ));
850     OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "substringData", new Class JavaDoc[]{int.class, int.class},
851             new Object JavaDoc[]{new Integer JavaDoc(2),new Integer JavaDoc(-1) }, DOMException.INDEX_SIZE_ERR ));
852     
853
854 //!! Throws NO_MODIFICATION_ALLOWED_ERR ********
855
Node JavaDoc node = document.getDocumentElement().getElementsByTagName("dBodyLevel24").item(0).getFirstChild().getChildNodes().item(0); // node gets ourEntityReference node's child text
856

857     OK &= Assertion.assertTrue(DOMExceptionsTest(node, "appendData", new Class JavaDoc[]{String JavaDoc.class},
858             new Object JavaDoc[]{"new data" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
859     OK &= Assertion.assertTrue(DOMExceptionsTest(node, "deleteData", new Class JavaDoc[]{int.class, int.class},
860             new Object JavaDoc[]{new Integer JavaDoc(5),new Integer JavaDoc(10) }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
861     OK &= Assertion.assertTrue(DOMExceptionsTest(node, "insertData", new Class JavaDoc[]{int.class, String JavaDoc.class},
862             new Object JavaDoc[]{new Integer JavaDoc(5),"Stuff inserted" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
863     OK &= Assertion.assertTrue(DOMExceptionsTest(node, "replaceData", new Class JavaDoc[]{int.class, int.class, String JavaDoc.class},
864             new Object JavaDoc[]{new Integer JavaDoc(5),new Integer JavaDoc(10),"Replacementstuff" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
865     OK &= Assertion.assertTrue(DOMExceptionsTest(node, "setData", new Class JavaDoc[]{String JavaDoc.class},
866             new Object JavaDoc[]{"New setdata stuff"}, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
867     
868         
869 // For debugging***** println("All CharacterData method calls worked correctly.");
870
if (!OK)
871         System.out.println("\n*****The CharacterData method calls listed above failed, all others worked correctly.*****");
872     charData.setData(resetData); // reset node to original data
873
// println("");
874
}
875 /**
876  * This method tests ChildNodeList methods for the XML DOM implementation
877  * version 2.0 10/12/98
878  * @param document org.w3c.dom.Document
879  *
880  * @author Philip W. Davis
881  */

882 public void testChildNodeList(org.w3c.dom.Document JavaDoc document)
883 {
884     
885     Node JavaDoc node, node2;
886     boolean OK = true;
887 // For debugging***** println("\n testChildNodeList's outputs:\n");
888
node = document.getDocumentElement().getLastChild(); // node gets doc's testBody element
889

890     if (!(node.getChildNodes().getLength()== 4))
891         OK = false;
892     node2 = node.getChildNodes().item(2);
893     if (! node2.getNodeName().equals("dBodyLevel23"))
894         OK = false;
895     
896 // For debugging***** println("All ChildNodeList method calls worked correctly.");
897
if (!OK)
898         System.out.println("\n*****The ChildNodeList method calls listed above failed, all others worked correctly.*****");
899 // println("");
900
}
901 /**
902  * This method tests Comment methods for the XML DOM implementation
903  * version 1.0 10/12/98
904  * @param document org.w3c.dom.Document
905  *
906  * @author Philip W. Davis
907  */

908 public void testComment(org.w3c.dom.Document JavaDoc document)
909 {
910     Node JavaDoc node, node2;
911     boolean T = true;
912     boolean OK = true;
913 // For debugging***** println("\n testComment's outputs:\n");
914
node = document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // node gets textNode11
915
node2 = node.cloneNode(T);
916     // Check nodes for equality, both their name and value or lack thereof
917
if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
918
(node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node
919
? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality
920
: (node.getNodeValue() == null && node2.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't
921
//println("'cloneNode' did not clone the Comment node correctly");
922
OK = false;
923     // Deep clone test comparison is in testNode & testDocument
924
if (OK)
925 // For debugging***** println("All Comment method calls worked correctly.");
926
if (!OK)
927         System.out.println("\n*****The Comment method calls listed above failed, all others worked correctly.*****");
928 // println("");
929
}
930 /**
931  * This method tests DeepNodeList methods for the XML DOM implementation
932  * version 2.0 10/12/98
933  * @param document org.w3c.dom.Document
934  *
935  * @author Philip W. Davis
936  */

937 public void testDeepNodeList(org.w3c.dom.Document JavaDoc document)
938 {
939     
940     Node JavaDoc node, node2;
941     boolean OK = true;
942 // For debugging***** println("\n testDeepNodeList's outputs:\n");
943
node = document.getLastChild().getLastChild(); // node gets docBody element
944
if (!(8 == ((Element JavaDoc) node).getElementsByTagName("*").getLength()))
945         {
946             System.out.println ("Warning!!! DeepNodeList's 'getLength' failed to work properly!");
947             OK = false;
948         }
949     node2 = ((Element JavaDoc) node).getElementsByTagName("*").item(2); //This also runs through 'nextMatchingElementAfter"
950
if (! node2.getNodeName().equals("dBodyLevel32"))
951         {
952             System.out.println ("Warning!!! DeepNodeList's 'item' (or Element's 'getElementsBy TagName)failed to work properly!");
953             OK = false;
954         }
955     node2 = document.getLastChild();
956     if (! ((Element JavaDoc) node2).getElementsByTagName("dTestBody").item(0).getNodeName().equals("dTestBody"))//This also runs through 'nextMatchingElementAfter"
957
{
958             System.out.println ("Warning!!! DeepNodeList's 'item' (or Element's 'getElementsBy TagName)failed to work properly!");
959             OK = false;
960         }
961         
962     
963 // For debugging***** println("All DeepNodeList method calls worked correctly.");
964
if (!OK)
965         System.out.println("\n*****The DeepNodeList method calls listed above failed, all others worked correctly.*****");
966 // println("");
967
}
968 /**
969  * This method tests Document methods for the XML DOM implementation
970  * version 2.0 10/12/98
971  * @param document org.w3c.dom.Document
972  *
973  * @author Philip W. Davis
974  *
975  **** ALL Document create methods are run in docBuilder except createAttribute which is in testAttribute**
976  */

977 public void testDocument(org.w3c.dom.Document JavaDoc document)
978 {
979     DTest make = new DTest();
980     DocumentFragment JavaDoc docFragment, docFragment2;
981     Element JavaDoc newElement;
982     Node JavaDoc node, node2;
983     String JavaDoc[] elementNames = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32",
984                    "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"};
985     String JavaDoc[] newElementNames = {"dFirstElement", "dTestBody", "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23"};
986     boolean result;
987     boolean OK = true;
988 // For debugging***** println("\n testDocument's outputs:\n ");
989

990     DocumentType JavaDoc checkDocType = make.createDocumentType(document,"testDocument1");
991     DocumentType JavaDoc docType = document.getDoctype();
992     if (! (checkDocType.getNodeName().equals(docType.getNodeName()) && // Compares node names for equality
993
(checkDocType.getNodeValue() != null && docType.getNodeValue() != null) // Checks to make sure each node has a value node
994
? checkDocType.getNodeValue().equals(docType.getNodeValue()) // If both have value nodes test those value nodes for equality
995
: (checkDocType.getNodeValue() == null && docType.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't
996
{
997         System.out.println("Warning!!! Document's 'getDocType method failed!" );
998         OK = false;
999     }
1000        
1001    Node JavaDoc rootElement = document.getLastChild();
1002    if (! (rootElement.getNodeName().equals(document.getDocumentElement().getNodeName()) && // Compares node names for equality
1003
(rootElement.getNodeValue() != null && document.getDocumentElement().getNodeValue() != null) // Checks to make sure each node has a value node
1004
? rootElement.getNodeValue().equals(document.getDocumentElement().getNodeValue()) // If both have value nodes test those value nodes for equality
1005
: (rootElement.getNodeValue() == null && document.getDocumentElement().getNodeValue() == null))) // If one node doesn't have a value node make sure both don't
1006
{
1007        System.out.println("Warning!!! Document's 'getDocumentElement' method failed!" );
1008        OK = false;
1009    }
1010    
1011    NodeList JavaDoc docElements = document.getElementsByTagName("*");
1012    int docSize = docElements.getLength();
1013    int i;
1014    for (i = 0; i < docSize; i++)
1015    {
1016        Node JavaDoc n = (Node JavaDoc) docElements.item(i);
1017        if (! (elementNames[i].equals(n.getNodeName())))
1018        {
1019            System.out.println("Comparison of this document's elements failed at element number " + i + " : " + n.getNodeName());
1020            OK = false;
1021            break;
1022        }
1023    }
1024    if (document.equals(document.getImplementation()))
1025    {
1026        System.out.println("Warning!!! Document's 'getImplementation' method failed!" );
1027        OK = false;
1028    }
1029        
1030    newElement = document.createElement("NewElementTestsInsertBefore");
1031    // doc.insertBefore(newElement,null);//!! Throws a HIERARCHY_REQUEST_ERR *******
1032
// doc.removeChild(docElements.item(9));//!! Throws a NOT_FOUND_ERR ********
1033

1034    docFragment = document.createDocumentFragment();
1035    //Tests removeChild and stores removed branch for tree reconstruction
1036
docFragment.appendChild(docElements.item(1).removeChild(docElements.item(9)));
1037    docFragment2 = document.createDocumentFragment();
1038    //Tests removeChild and stores removed branch for tree reconstruction
1039
docFragment2.appendChild(docElements.item(1).removeChild(docElements.item(2)));
1040    docSize = docElements.getLength();
1041    for (i = 0; i < docSize; i++)
1042    {
1043        Node JavaDoc n = (Node JavaDoc) docElements.item(i);
1044        if (! (newElementNames[i].equals(n.getNodeName())))
1045        {
1046            System.out.println("Comparison of new document's elements failed at element number " + i + " : " + n.getNodeName());
1047            OK = false;
1048            break;
1049        }
1050    }
1051    docElements.item(1).insertBefore(docFragment, null); //Reattaches removed branch to restore tree to the original
1052
docElements.item(1).insertBefore(docFragment2, docElements.item(2)); //Reattaches removed branch to restore tree to the original
1053

1054    // println(docElements.item(2).getNodeName());
1055

1056    docSize = docElements.getLength();
1057    for (i = 0; i < docSize; i++)
1058    {
1059        Node JavaDoc n = (Node JavaDoc) docElements.item(i);
1060        if (! (elementNames[i].equals(n.getNodeName())))
1061        {
1062            System.out.println("Comparison of restored document's elements failed at element number " + i + " : " + n.getNodeName());
1063            OK = false;
1064            break;
1065        }
1066    }
1067
1068    
1069// Document z = tests.createDocument();
1070
// tests.docBuilder(z, "z");
1071

1072//!! Throws WRONG_DOCUMENT_ERR **********
1073
// OK &= Assertion.assert(tests.DOMExceptionsTest(z, "appendChild", new Class[]{Node.class}, new Object[]{doc.createComment("Test doc d comment")}, DOMException.HIERARCHY_REQUEST_ERR ));
1074

1075    // z.appendChild(d.createComment("Test doc d comment"));// Tries to append z document with document d comment
1076
// d.getDocumentElement().appendChild(z.createElement("newZdocElement"));// Tries to append d document with document z Element
1077
// d.getLastChild().getLastChild().insertBefore(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild());// Tries to insert into d document with document z Element
1078
// d.replaceChild(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild()); // Tries to replace in d document with document z Element
1079

1080    // doc.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ********
1081

1082    node = document;
1083    node2 = document.cloneNode(true);
1084    result = treeCompare(node, node2); // Deep clone test comparison of document cloneNode
1085
if (!result)
1086    {
1087        System.out.println("Warning!!! Deep clone of the document failed!");
1088        OK = false;
1089    }
1090
1091    // check on the ownerDocument of the cloned nodes
1092
Document JavaDoc doc2 = (Document JavaDoc) node2;
1093    Assertion.assertTrue(doc2.getDocumentElement().getOwnerDocument() == doc2);
1094
1095    // Deep clone test comparison is also in testNode
1096

1097    // try adding a new element to the cloned document
1098
node2 = doc2.createElement("foo");
1099    doc2.getDocumentElement().appendChild(node2);
1100    
1101// For debugging***** println("All Document method calls worked correctly.");
1102
if (!OK)
1103        System.out.println("\n*****The Document method calls listed above failed, all others worked correctly.*****");
1104// println("");
1105
}
1106/**
1107 * This method tests DocumentFragment methods for the XML DOM implementation
1108 * version 2.0 10/12/98
1109 * @param document org.w3c.dom.Document
1110 *
1111 * @author Philip W. Davis
1112 *
1113 *
1114 ********This really isn't needed, only exists to throw NO_MODIFICATION_ALLOWED_ERR ********
1115 */

1116public void testDocumentFragment(org.w3c.dom.Document JavaDoc document)
1117{
1118    boolean OK = true;
1119// For debugging***** println("\n testDocumentFragment's outputs:\n");
1120
DocumentFragment JavaDoc testDocFragment = document.createDocumentFragment();
1121        
1122    // testDocFragment.setNodeValue("This is a document fragment!");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ********
1123

1124// For debugging***** println("All DocumentFragment method calls worked correctly.");
1125
if (!OK)
1126        System.out.println("\n*****The DocumentFragment method calls listed above failed, all others worked correctly.*****");
1127// println("");
1128
}
1129/**
1130 * This method tests DocumentType methods for the XML DOM implementation
1131 * version 2.0 10/12/98
1132 * @param document org.w3c.dom.Document
1133 *
1134 * @author Philip W. Davis
1135 */

1136public void testDocumentType(org.w3c.dom.Document JavaDoc document)
1137{
1138    DTest test = new DTest();
1139    DocumentType JavaDoc docType, holdDocType;
1140    NamedNodeMap JavaDoc docEntityMap, docNotationMap;
1141    Node JavaDoc node, node2;
1142    String JavaDoc compare;
1143    boolean OK = true;
1144// For debugging***** println("\n testDocumentType's outputs:\n");
1145
DocumentType JavaDoc newDocumentType = test.createDocumentType(document, "TestDocument");
1146    node = document.getFirstChild(); // node gets doc's docType node
1147
node2 = node.cloneNode(true);
1148    // Check nodes for equality, both their name and value or lack thereof
1149
if (! (node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
1150
(node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node
1151
? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality
1152
: (node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't
1153
{
1154        System.out.println("'cloneNode' did not clone the DocumentType node correctly");
1155        OK = false;
1156    }
1157     // Deep clone test comparison is in testNode & testDocument
1158

1159    docType = (DocumentType JavaDoc) document.getFirstChild();
1160    compare = "ourEntityNode";
1161    docEntityMap = docType.getEntities();
1162    if (! compare.equals(docEntityMap.item(0).getNodeName()))
1163    {
1164        System.out.println("Warning!!! DocumentType's 'getEntities' failed!" );
1165        OK = false;
1166    }
1167    docNotationMap = docType.getNotations();
1168    compare = "ourNotationNode";
1169    if (! compare.equals(docNotationMap.item(0).getNodeName()))
1170    {
1171        System.out.println("Warning!!! DocumentType's 'getNotations' failed!");
1172        OK = false;
1173    }
1174    // doc.appendChild(newDocumentTypeImpl);//!! Throws a HIERARCHY_REQUEST_ERR *******
1175
holdDocType = (DocumentType JavaDoc) document.removeChild(document.getFirstChild()); //Tests removeChild and stores removed branch for tree reconstruction
1176
document.insertBefore(newDocumentType, document.getDocumentElement());
1177    //** Other aspects of insertBefore are tested in docBuilder through appendChild*
1178

1179    document.removeChild(document.getFirstChild()); //Removes newDocumentType for tree restoral
1180
document.insertBefore(holdDocType, document.getFirstChild()); //Reattaches removed branch to restore tree to the original
1181

1182    
1183// For debugging***** println("All DocumentType method calls worked correctly.");
1184
if (!OK)
1185        System.out.println("\n*****The DocumentType method calls listed above failed, all others worked correctly.*****");
1186// println("");
1187
}
1188/**
1189 * @author Philip W. Davis
1190 * @param document org.w3c.dom.Document
1191 */

1192public void testDOMerrors(Document JavaDoc document) {
1193
1194    boolean OK = true;
1195
1196    OK &= Assertion.assertTrue(DOMExceptionsTest(document, "appendChild", new Class JavaDoc[]{Node JavaDoc.class}, new Object JavaDoc[]{testElementNode}, DOMException.HIERARCHY_REQUEST_ERR ));
1197    OK &= Assertion.assertTrue(DOMExceptionsTest(testTextNode, "appendChild", new Class JavaDoc[]{Node JavaDoc.class}, new Object JavaDoc[]{testTextNode}, DOMException.HIERARCHY_REQUEST_ERR ));
1198// 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 ));
1199
// 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 ));
1200

1201// 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 ));
1202
/* OK &= Assertion.assert(tests.DOMExceptionsTest(docReferenceEntity, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
1203    OK &= Assertion.assert(tests.DOMExceptionsTest(docEntity, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
1204    OK &= Assertion.assert(tests.DOMExceptionsTest(document, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
1205    OK &= Assertion.assert(tests.DOMExceptionsTest(docDocType, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
1206    OK &= Assertion.assert(tests.DOMExceptionsTest(docDocFragment, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
1207    OK &= Assertion.assert(tests.DOMExceptionsTest(docNotation, "setNodeValue", new Class[]{String.class}, new Object[]{"This shouldn't work!" }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
1208    OK &= Assertion.assert(tests.DOMExceptionsTest(docReferenceEntity, "appendChild", new Class[]{Node.class}, new Object[]{entityReferenceText2 }, DOMException.NO_MODIFICATION_ALLOWED_ERR ));
1209
1210
1211    OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "insertBefore", new Class[]{Node.class, Node.class}, new Object[]{docTextNode11,docBody }, DOMException.NOT_FOUND_ERR ));
1212    OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "removeChild", new Class[]{Node.class}, new Object[]{docFirstElement}, DOMException.NOT_FOUND_ERR ));
1213    OK &= Assertion.assert(tests.DOMExceptionsTest(docBodyLevel32, "replaceChild", new Class[]{Node.class, Node.class}, new Object[]{docTextNode11,docFirstElement }, DOMException.NOT_FOUND_ERR ));
1214*/

1215
1216//!! Throws a NOT_FOUND_ERR ********
1217

1218     // docBodyLevel32.getAttributes().removeNamedItem(testAttribute.getName()); 16 // To test removeNamedItem
1219

1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231    
1232}
1233/**
1234 * This method tests DOMImplementation methods for the XML DOM implementation
1235 * version 2.0 10/12/98
1236 * @param document org.w3c.dom.Document
1237 *
1238 * @author Philip W. Davis
1239 */

1240public void testDOMImplementation(org.w3c.dom.Document JavaDoc document)
1241{
1242    
1243    DOMImplementation JavaDoc implementation;
1244    boolean result = false;
1245    boolean OK = true;
1246// For debugging***** println("\n testDOMImplementation's outputs:\n");
1247
implementation = document.getImplementation(); //Uses getDOMImplementation to obtain implementation
1248

1249    result = implementation.hasFeature("XML", "1.0");
1250    if(!result)
1251    {
1252        System.out.println("Warning!!! DOMImplementation's 'hasFeature' that should be 'true' failed!");
1253        OK = false;
1254    }
1255    
1256    result = implementation.hasFeature("HTML", "4.0");
1257    if(result)
1258    {
1259        System.out.println("Warning!!! DOMImplementation's 'hasFeature' that should be 'false' failed!");
1260        OK = false;
1261    }
1262    
1263    
1264// For debugging***** println("All DOMImplementation method calls worked correctly.");
1265
if (!OK)
1266        System.out.println("\n*****The DOMImplementation method calls listed above failed, all others worked correctly.*****");
1267// println("");
1268
}
1269/**
1270 * This method tests Element methods for the XML DOM implementation
1271 * version 2.0 10/12/98
1272 * @param document org.w3c.dom.Document
1273 *
1274 * @author Philip W. Davis
1275 */

1276public void testElement(org.w3c.dom.Document JavaDoc document)
1277{
1278    Attr JavaDoc attributeNode, newAttributeNode;
1279    Element JavaDoc element, element2;
1280    Node JavaDoc node, node2;
1281    String JavaDoc attribute, compare;
1282    String JavaDoc[] attributeCompare = {"AnotherFirstElementAttribute", "dFirstElement", "testAttribute"};
1283    String JavaDoc[] elementNames = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32",
1284                   "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"};
1285    String JavaDoc[] textCompare = {"dBodyLevel31'sChildTextNode11", "dBodyLevel31'sChildTextNode12", "dBodyLevel31'sChildTextNode13"};
1286    NamedNodeMap JavaDoc nodeMap;
1287    boolean OK = true;
1288// For debugging***** println("\n testElement's outputs:\n");
1289
node = document.getDocumentElement(); // node gets doc's firstElement
1290
node2 = node.cloneNode(true);
1291    // Check nodes for equality, both their name and value or lack thereof
1292
if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
1293
(node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node
1294
? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality
1295
:(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't
1296
{
1297        System.out.println("'cloneNode' did not clone the Element node correctly");
1298        OK = false;
1299    }
1300    // Deep clone test comparison is in testNode & testDocument
1301

1302    element = document.getDocumentElement(); // element gets doc's firstElement
1303
compare = "";
1304    attribute = element.getAttribute(document + "'s test attribute");
1305    if (! compare.equals(element.getAttribute(document + "'s test attribute")))
1306    {
1307        System.out.println("Warning!!! Element's 'getAttribute' failed!");
1308        OK = false;
1309    }
1310    
1311    attributeNode = element.getAttributeNode(document + "FirstElement");
1312    if(! (attributeNode == null))
1313    {
1314        System.out.println("Warning!!! Element's 'getAttributeNode' failed! It should have returned 'null' here!");
1315        OK = false;
1316    }
1317    
1318    newAttributeNode = document.createAttribute("AnotherFirstElementAttribute");
1319    newAttributeNode.setValue("A new attribute which helps test calls in Element");
1320    element.setAttributeNode(newAttributeNode);
1321    nodeMap = element.getAttributes();
1322    int size = nodeMap.getLength();
1323    int k;
1324    for (k = 0; k < size; k++)
1325    {
1326        Node JavaDoc n = (Node JavaDoc) nodeMap.item(k);
1327        if (! (attributeCompare[k].equals(n.getNodeName())))
1328        {
1329            System.out.println("Warning!!! Comparison of firstElement's attributes failed at attribute #"+ (k+1) +" " + n.getNodeValue());
1330            System.out.println("This failure can be a result of Element's 'setValue' and/or 'setAttributeNode' and/or 'getAttributes' failing.");
1331            OK = false;
1332            break;
1333        }
1334    // println("firstElement's attribute number " + k + " : " + n.getNodeName());
1335
}
1336    NodeList JavaDoc docElements = document.getElementsByTagName("*");
1337    int docSize = docElements.getLength();
1338    int i;
1339    for (i = 0; i < docSize; i++)
1340    {
1341        Node JavaDoc n = (Node JavaDoc) docElements.item(i);
1342        if (! (elementNames[i].equals(n.getNodeName())))
1343        {
1344            System.out.println("Warning!!! Comparison of Element's 'getElementsByTagName' and/or 'item' failed at element number "
1345                        + i + " : " + n.getNodeName());
1346            OK = false;
1347            break;
1348        }
1349    // println("docElement's number " + i + " is: " + n.getNodeName());
1350
}
1351    element = (Element JavaDoc) document.getElementsByTagName("dBodyLevel21").item(0); // element gets Element test BodyLevel21
1352
element2 = (Element JavaDoc) document.getElementsByTagName("dBodyLevel31").item(0); // element2 gets Element test BodyLevel31
1353
NodeList JavaDoc text = ((Node JavaDoc) element2).getChildNodes();
1354    int textSize = text.getLength();
1355    int j;
1356    for (j = 0; j < textSize; j++)
1357    {
1358        Node JavaDoc n = (Node JavaDoc) text.item(j);
1359        if (! (textCompare[j].equals(n.getNodeValue())))
1360        {
1361            System.out.println("Warning!!! Comparison of original text nodes via Node 'getChildNodes' & NodeList 'item'"
1362                        + "failed at text node: #" + j +" " + n.getNodeValue());
1363            OK = false;
1364            break;
1365        }
1366    // println("Element testBodyLevel31's child text node " + j + " is: " + n.getNodeValue());
1367
}
1368    element = document.getDocumentElement(); // element gets doc's firstElement
1369
element.normalize(); // Concatenates all adjacent text nodes in this element's subtree
1370
NodeList JavaDoc text2 = ((Node JavaDoc) element2).getChildNodes();
1371    compare = "dBodyLevel31'sChildTextNode11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13";
1372    Node JavaDoc n = (Node JavaDoc) text2.item(0);
1373        if (! (compare.equals(n.getNodeValue())))
1374        {
1375            System.out.println("Warning!!! Comparison of concatenated text nodes created by Element's 'normalize' failed!");
1376            OK = false;
1377        }
1378    
1379    element.setAttribute("FirstElementLastAttribute", "More attribute stuff for firstElement!!");
1380    element.removeAttribute("FirstElementLastAttribute");
1381    element.removeAttributeNode(newAttributeNode);
1382
1383    // doc.getLastChild().setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR***
1384

1385// For debugging***** println("All Element method calls worked correctly.");
1386
if (!OK)
1387        System.out.println("\n*****The Element method calls listed above failed, all others worked correctly.*****");
1388// println("");
1389
}
1390/**
1391 * This method tests Entity methods for the XML DOM implementation
1392 * version 2.0 10/12/98
1393 * @param document org.w3c.dom.Document
1394 *
1395 * @author Philip W. Davis
1396 */

1397public void testEntity(org.w3c.dom.Document JavaDoc document)
1398{
1399    Entity JavaDoc entity;
1400    Node JavaDoc node, node2;
1401    boolean OK = true;
1402    String JavaDoc compare;
1403// For debugging***** println("\n testEntity's outputs:\n");
1404
entity = (Entity JavaDoc) document.getDoctype().getEntities().getNamedItem("ourEntityNode");
1405    node = entity;
1406    node2 = entity.cloneNode(true);
1407    // Check nodes for equality, both their name and value or lack thereof
1408
if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
1409
(node.getNodeValue() != null && node2.getNodeValue() != null) ? // Checks to make sure each node has a value node
1410
node.getNodeValue().equals(node2.getNodeValue()) : // If both have value nodes test those value nodes for equality
1411
(node.getNodeValue() == null && node2.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't
1412
{
1413        System.out.println("Warning!!! 'cloneNode' did not clone the Entity node correctly");
1414        OK = false;
1415    }
1416    // Deep clone test comparison is in testNode & testDocument
1417

1418    ((org.enhydra.apache.xerces.dom.EntityImpl) entity).setNotationName("testNotationName");
1419    compare = "testNotationName";
1420    if(! compare.equals(entity.getNotationName()))
1421    {
1422        System.out.println("Warning!!! Entity's 'setNotationName' and/or getNotationName' failed!");
1423        OK = false;
1424    }
1425    ((org.enhydra.apache.xerces.dom.EntityImpl) entity).setPublicId("testPublicId");
1426    compare = "testPublicId";
1427    if(! compare.equals(entity.getPublicId()))
1428    {
1429        System.out.println("Warning!!! Entity's 'setPublicId' and/or getPublicId' failed!");
1430        OK = false;
1431    }
1432    ((org.enhydra.apache.xerces.dom.EntityImpl) entity).setSystemId("testSystemId");
1433    compare = "testSystemId";
1434    if(! compare.equals(entity.getSystemId()))
1435    {
1436        System.out.println("Warning!!! Entity's 'setSystemId' and/or getSystemId' failed!");
1437        OK = false;
1438    }
1439    // entity.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ********
1440

1441// For debugging***** println("All Entity method calls worked correctly.");
1442
if (!OK)
1443        System.out.println("\n*****The Entity method calls listed above failed, all others worked correctly.*****");
1444// println("");
1445
}
1446/**
1447 * This method tests EntityReference methods for the XML DOM implementation
1448 * version 2.0 10/12/98
1449 * @param document org.w3c.dom.Document
1450 *
1451 * @author Philip W. Davis
1452 */

1453public void testEntityReference(org.w3c.dom.Document JavaDoc document)
1454{
1455    EntityReference JavaDoc entityReference;
1456    Node JavaDoc node, node2;
1457    boolean OK = true;
1458// For debugging***** println("\n testEntityReference's outputs:\n");
1459
entityReference = (EntityReference JavaDoc) document.getLastChild().getLastChild().getLastChild().getFirstChild();
1460    node = entityReference;
1461    node2 = node.cloneNode(true);
1462    // Check nodes for equality, both their name and value or lack thereof
1463
if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
1464
(node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node
1465
? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality
1466
:(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't
1467
{
1468        System.out.println("'cloneNode' did not clone the EntityReference node correctly");
1469        OK = false;
1470    }
1471    // Deep clone test comparison is in testNode & testDocument
1472

1473    // entityReference.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ********
1474

1475// For debugging***** println("All EntityReference method calls worked correctly.");
1476
if (!OK)
1477        System.out.println("\n*****The EntityReference method calls listed above failed, all others worked correctly.*****");
1478// println("");
1479
}
1480/**
1481 * This method tests Node methods for the XML DOM implementation
1482 * version 2.0 10/12/98
1483 * @param document org.w3c.dom.Document
1484 *
1485 * @author Philip W. Davis
1486 *
1487 *
1488 ********* This is only for a test of cloneNode "deep"*******
1489 ********* And for error tests*********
1490 */

1491public void testNode(org.w3c.dom.Document JavaDoc document)
1492{
1493    Node JavaDoc node, node2;
1494    boolean result;
1495    boolean OK = true;
1496// For debugging***** println("\n testNode's outputs:\n");
1497
node = document.getDocumentElement();
1498    node2 = node.cloneNode(true);
1499    result = treeCompare(node, node2); // Deep clone test of cloneNode
1500
if (result)
1501    {
1502        //println("'cloneNode' successfully cloned this whole node tree (deep)!");
1503
}
1504    else
1505    {
1506        System.out.println("'cloneNode' did not successfully clone this whole node tree (deep)!");
1507        OK = false;
1508    }
1509    //!! The following gives a did not clone successfully message*********
1510
node = document.getDocumentElement();
1511    node2 = node.getFirstChild();
1512    result = treeCompare(node, node2);
1513    if (!result)
1514    {
1515        //println("'cloneNode' did not successfully clone this whole node tree (deep)!");
1516
}
1517    else
1518    {
1519        System.out.println("'cloneNode' was supposed to fail here, either it or 'treeCompare' failed!!!");
1520        OK = false;
1521    }
1522    // Deep clone test also in testDocument
1523

1524// For debugging***** println("All Node method calls worked correctly.");
1525
if (!OK)
1526        System.out.println("\n*****The Node method calls listed above failed, all others worked correctly.*****");
1527// println("");
1528
}
1529/**
1530 * This method tests Notation methods for the XML DOM implementation
1531 * version 2.0 10/12/98
1532 * @param document org.w3c.dom.Document
1533 *
1534 * @author Philip W. Davis
1535 */

1536public void testNotation(org.w3c.dom.Document JavaDoc document)
1537{
1538    Node JavaDoc node, node2;
1539    Notation JavaDoc notation;
1540    boolean OK = true;
1541    String JavaDoc compare;
1542// For debugging***** println("\n testNotation's outputs:\n");
1543
notation = (Notation JavaDoc) document.getDoctype().getNotations().getNamedItem("ourNotationNode");
1544    node = notation;
1545    node2 = notation.cloneNode(true);//*****?
1546
// Check nodes for equality, both their name and value or lack thereof
1547
if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
1548
(node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node
1549
? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality
1550
:(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't
1551
{
1552        System.out.println("'cloneNode' did not clone the Notation node correctly");
1553        OK = false;
1554    }
1555    // Deep clone test comparison is in testNode & testDocument
1556

1557    ((org.enhydra.apache.xerces.dom.NotationImpl) notation).setPublicId("testPublicId");//*****?
1558
compare = "testPublicId";
1559    if (!compare.equals(notation.getPublicId()))
1560    {
1561        System.out.println("Warning!!! Notation's 'getPublicId' failed!");
1562        OK = false;
1563    }
1564    ((org.enhydra.apache.xerces.dom.NotationImpl) notation).setSystemId("testSystemId");//*****?
1565
compare = "testSystemId";
1566    if (! compare.equals(notation.getSystemId()))
1567    {
1568        System.out.println("Warning!!! Notation's 'getSystemId' failed!");
1569        OK = false;
1570    }
1571    // notation.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ********
1572

1573// For debugging***** println("All Notation method calls worked correctly.");
1574
if (!OK)
1575        System.out.println("\n*****The Notation method calls listed above failed, all others worked correctly.*****");
1576// println("");
1577
}
1578/**
1579 * This method tests ProcessingInstruction methods for the XML DOM implementation
1580 * version 2.0 10/12/98
1581 * @param document org.w3c.dom.Document
1582 *
1583 * @author Philip W. Davis
1584 */

1585public void testPI(org.w3c.dom.Document JavaDoc document)
1586{
1587    Node JavaDoc node, node2;
1588    ProcessingInstruction JavaDoc pI, pI2;
1589    String JavaDoc compare;
1590    boolean OK = true;
1591// For debugging***** println("\n testPI's outputs:\n");
1592
pI = (ProcessingInstruction JavaDoc) document.getDocumentElement().getFirstChild();// Get doc's ProcessingInstruction
1593
pI2 = (org.enhydra.apache.xerces.dom.ProcessingInstructionImpl) pI.cloneNode(true);//*****?
1594
// Check nodes for equality, both their name and value or lack thereof
1595
if (!(pI.getNodeName().equals(pI2.getNodeName()) && // Compares node names for equality
1596
(pI.getNodeValue() != null && pI2.getNodeValue() != null) // Checks to make sure each node has a value node
1597
? pI.getNodeValue().equals(pI2.getNodeValue()) // If both have value nodes test those value nodes for equality
1598
:(pI.getNodeValue() == null && pI2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't
1599
{
1600        System.out.println("'cloneNode' did not clone the Entity node correctly");
1601        OK = false;
1602    }
1603    // Deep clone test comparison is in testNode & testDocument
1604
compare = "This is [#document: null]'s processing instruction";
1605    if (! compare.equals(pI.getData()))
1606    {
1607        System.out.println("Warning!!! PI's 'getData' failed!");
1608        OK = false;
1609    }
1610    
1611    pI.setData("PI's reset data");
1612    compare = "PI's reset data";
1613    if (! compare.equals(pI.getData()))
1614    {
1615        System.out.println("Warning!!! PI's 'setData' failed!");
1616        OK = false;
1617    }
1618    compare = "dTargetProcessorChannel";
1619    if (! compare.equals(pI.getTarget()))
1620    {
1621        System.out.println("Warning!!! PI's 'getTarget' failed!");
1622        OK = false;
1623    }
1624    
1625// For debugging***** println("All PI method calls worked correctly.");
1626
if (!OK)
1627        System.out.println("\n*****The PI method calls listed above failed, all others worked correctly.*****");
1628    
1629// println("");
1630
}
1631/**
1632 * This method tests Text methods for the XML DOM implementation
1633 * version 2.0 10/12/98
1634 * @param document org.w3c.dom.Document
1635 *
1636 * @author Philip W. Davis
1637 */

1638public void testText(org.w3c.dom.Document JavaDoc document)
1639{
1640    Node JavaDoc node, node2;
1641    Text JavaDoc text;
1642    String JavaDoc compare;
1643    boolean OK = true;
1644// For debugging***** println("\n testText's outputs:\n");
1645
node = document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // charData gets textNode11
1646
text = (Text JavaDoc) node;
1647    node2 = node.cloneNode(true);//*****?
1648
// Check nodes for equality, both their name and value or lack thereof
1649
if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
1650
(node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node
1651
? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality
1652
:(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't
1653
{
1654        System.out.println("'cloneNode' did not clone the Text node correctly");
1655        OK = false;
1656    }
1657    // Deep clone test comparison is in testNode & testDocument
1658
text.splitText(25);
1659    compare = "dBodyLevel31'sChildTextNo"; // Three original text nodes were concatenated by 'normalize' in testElement
1660
if (! compare.equals(text.getNodeValue()))
1661        {
1662            System.out.println("First part of Text's split text failed!" );
1663            OK = false;
1664        }
1665    compare = "de11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13";// Three original text nodes were concatenated by 'normalize' in testElement
1666
if (! compare.equals(text.getNextSibling().getNodeValue()))
1667        {
1668            System.out.println("The second part of Text's split text failed!") ;
1669            OK = false;
1670        }
1671
1672
1673
1674
1675//************************************************* ERROR TESTS
1676

1677    //!! Throws INDEX_SIZE_ERR ********************
1678
// text.splitText(-1);
1679
// text.splitText(100);
1680

1681// For debugging***** println("All Text method calls worked correctly.");
1682
if (!OK)
1683        System.out.println("\n*****The Text method calls listed above failed, all others worked correctly.*****");
1684    
1685// println("");
1686
}
1687/**
1688 *
1689 * @param node org.w3c.dom.Node
1690 * @param node2 org.w3c.dom.Node
1691 *
1692 * @author Philip W. Davis
1693 */

1694public boolean treeCompare(Node JavaDoc node, Node JavaDoc node2)
1695{
1696    boolean answer = true;
1697        
1698    Node JavaDoc kid, kid2; // Check the subtree for equality
1699
kid = node.getFirstChild();
1700    kid2 = node2.getFirstChild();
1701    if (kid != null && kid2 != null)
1702    {
1703        answer = treeCompare(kid, kid2);
1704        if (!answer)
1705            return answer;
1706        else
1707            if (kid.getNextSibling() != null && kid2.getNextSibling() != null)
1708            {
1709                while (kid.getNextSibling() != null && kid2.getNextSibling() != null)
1710                {
1711                    answer = treeCompare(kid.getNextSibling(), kid2.getNextSibling());
1712                    if (!answer)
1713                        return answer;
1714                    else
1715                    {
1716                        kid = kid.getNextSibling();
1717                        kid2 = kid2.getNextSibling();
1718                    }
1719                }
1720            } else
1721                if (!(kid.getNextSibling() == null && kid2.getNextSibling() == null))
1722                {
1723                    return false;
1724                }
1725    } else
1726        if (kid != kid2)
1727        {
1728            return false;
1729        }
1730
1731    // Check nodes for equality, both their name and value or lack thereof
1732
if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality
1733
(node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node
1734
? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality
1735
:(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't
1736
{
1737        return false; // Return false if "any" of the above conditions are false
1738
}
1739    return answer;
1740}
1741}
1742
Popular Tags