1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /*
19  * $Id$
20  */
21 
22 
23 /**
24  * This class tests methods for XML DOM implementation
25  *
26  * DOMException errors are tested by calls to DOMExceptionsTest from: Main, docBuilder...
27  *
28  */
29 
30 #include <xercesc/dom/DOM.hpp>
31 
32 //  define null for compatibility with original Java source code.
33 #define null 0
34 
35 XERCES_CPP_NAMESPACE_USE
36 
37 XERCES_CPP_NAMESPACE_BEGIN
38 class XercesDOMParser;
39 XERCES_CPP_NAMESPACE_END
40 
41 
42 class DOMTest {
43 public:
44 	static DOMElement           *testElementNode;
45 	static DOMAttr              *testAttributeNode;
46 	static DOMText              *testTextNode;
47 	static DOMCDATASection      *testCDATASectionNode;
48 	static DOMEntityReference   *testEntityReferenceNode;
49 	static DOMEntity            *testEntityNode;
50 	static DOMProcessingInstruction *testProcessingInstructionNode;
51 	static DOMComment           *testCommentNode;
52 	static DOMDocument          *testDocumentNode;
53 	static DOMDocumentType      *testDocumentTypeNode;
54 	static DOMDocumentFragment  *testDocumentFragmentNode;
55 	static DOMNotation          *testNotationNode;
56 
57 
58 DOMTest();
59 
60 DOMDocument* createDocument();
61 DOMDocumentType* createDocumentType(DOMDocument* doc, XMLCh* name);
62 DOMEntity* createEntity(DOMDocument* doc, XMLCh* name);
63 DOMNotation* createNotation(DOMDocument* doc, XMLCh* name);
64 bool docBuilder(DOMDocument* document, XMLCh* name);
65 
66 void findTestNodes(DOMDocument* document);
67 void findTestNodes(DOMNode* node);
68 
69 
70 bool testAttr(DOMDocument* document);
71 bool testCDATASection(DOMDocument* document);
72 bool testCharacterData(DOMDocument* document);
73 bool testChildNodeList(DOMDocument* document);
74 bool testComment(DOMDocument* document);
75 bool testDeepNodeList(DOMDocument* document);
76 
77 /**
78  **** ALL DOMDocument create methods are run in docBuilder except createAttribute which is in testAttribute**
79  */
80 bool testDocument(DOMDocument* document);
81 
82 
83 /**
84  ********This really isn't needed, only exists to throw NO_MODIFICATION_ALLOWED_ERR ********
85  */
86 bool testDocumentFragment(DOMDocument* document);
87 
88 bool testDocumentType(DOMDocument* document);
89 bool testDOMerrors(DOMDocument* document);
90 bool testXPath(DOMDocument* document);
91 bool testDOMImplementation(DOMDocument* document);
92 bool testElement(DOMDocument* document);
93 bool testEntity(DOMDocument* document);
94 bool testEntityReference(DOMDocument* document);
95 
96 
97 /**
98  ********* This is only for a test of cloneNode "deep"*******
99  ********* And for error tests*********
100  */
101 bool testNode(DOMDocument* document);
102 
103 bool testNotation(DOMDocument* document);
104 bool testPI(DOMDocument* document);
105 bool testText(DOMDocument* document);
106 bool treeCompare(DOMNode* node, DOMNode* node2);
107 
108 bool testBaseURI(XercesDOMParser* parser);
109 bool testWholeText(XercesDOMParser* parser);
110 bool testLSExceptions();
111 bool testElementTraversal();
112 
113 bool testRegex();
114 bool testScanner(XercesDOMParser* parser);
115 bool testUtilFunctions();
116 
117 };
118 
119 class myUserDataHandler : public DOMUserDataHandler {
120 private:
121     DOMOperationType currentType;
122     XMLCh* currentKey;
123     void* currentData;
124     DOMNode* currentSrc;
125     DOMNode* currentDst;
126 
127 public:
myUserDataHandler()128     myUserDataHandler() :
129       currentKey(0),
130       currentData(0),
131       currentSrc(0),
132       currentDst(0) {};
133 
handle(DOMOperationType operation,const XMLCh * const key,void * data,const DOMNode * src,DOMNode * dst)134     virtual void handle(DOMOperationType operation,
135                 const XMLCh* const key,
136                 void* data,
137                 const DOMNode* src,
138                 DOMNode* dst)
139     {
140         currentType = operation;
141         currentKey = (XMLCh*) key;
142         currentData = data;
143         currentSrc = (DOMNode*) src;
144         currentDst = dst;
145     };
146 
getCurrentType()147     DOMOperationType getCurrentType() {
148         return currentType;
149     };
getCurrentKey()150     XMLCh* getCurrentKey() const {
151         return currentKey;
152     };
getCurrentData()153     void* getCurrentData() const {
154         return currentData;
155     };
getCurrentSrc()156     DOMNode* getCurrentSrc() const {
157         return currentSrc;
158     };
getCurrentDst()159     DOMNode* getCurrentDst() const {
160         return currentDst;
161     };
162 
163 };
164 
165 
166