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: DTest.cpp 830538 2009-10-28 13:41:11Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | /** |
---|
25 | * This class tests methods for XML DOM implementation |
---|
26 | * DOMException errors are tested by calls to DOMExceptionsTest from: Main, docBuilder... |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | #include <stdio.h> |
---|
31 | #include "DTest.h" |
---|
32 | #include <xercesc/util/PlatformUtils.hpp> |
---|
33 | #include <xercesc/util/XMLException.hpp> |
---|
34 | #include <xercesc/util/XMLString.hpp> |
---|
35 | #include <xercesc/util/BinInputStream.hpp> |
---|
36 | #include <xercesc/parsers/XercesDOMParser.hpp> |
---|
37 | #include <xercesc/dom/DOMException.hpp> |
---|
38 | #include <xercesc/dom/DOMLSException.hpp> |
---|
39 | #include <xercesc/dom/DOMLSParserFilter.hpp> |
---|
40 | #include <xercesc/util/OutOfMemoryException.hpp> |
---|
41 | #include <xercesc/framework/MemBufInputSource.hpp> |
---|
42 | #include <xercesc/validators/common/CMStateSet.hpp> |
---|
43 | |
---|
44 | #define UNUSED(x) { if(x!=0){} } |
---|
45 | |
---|
46 | #define EXCEPTIONSTEST(operation, expectedException, resultFlag, testNum) \ |
---|
47 | { \ |
---|
48 | try \ |
---|
49 | { \ |
---|
50 | operation; \ |
---|
51 | fprintf(stderr, "Exceptions Test # %d: no Exception thrown->\n", testNum); \ |
---|
52 | } \ |
---|
53 | catch (DOMException &e) \ |
---|
54 | { \ |
---|
55 | if (e.code != expectedException) { \ |
---|
56 | fprintf(stderr, "Exceptions Test # %d: wrong DOMException thrown->\n", \ |
---|
57 | testNum); \ |
---|
58 | resultFlag = false; \ |
---|
59 | } \ |
---|
60 | } \ |
---|
61 | catch (...) \ |
---|
62 | { \ |
---|
63 | fprintf(stderr, "Exceptions Test # %d: unknown exception thrown->\n", \ |
---|
64 | testNum); \ |
---|
65 | resultFlag = false; \ |
---|
66 | } \ |
---|
67 | } |
---|
68 | |
---|
69 | #define USERDATAHANDLERTEST(userhandler, uoperation, ukey, udata, usrc, udst, uline) \ |
---|
70 | if (userhandler.getCurrentType() != uoperation) {\ |
---|
71 | fprintf(stderr, "DOMUserDataHandler::handler's operationType does not work in line %i\n", uline); \ |
---|
72 | OK = false; \ |
---|
73 | } \ |
---|
74 | if (XMLString::compareString(userhandler.getCurrentKey(), ukey)) {\ |
---|
75 | fprintf(stderr, "DOMUserDataHandler::handler's key does not work in line %i\n", uline); \ |
---|
76 | OK = false; \ |
---|
77 | } \ |
---|
78 | if (userhandler.getCurrentData() != udata) {\ |
---|
79 | fprintf(stderr, "DOMUserDataHandler::handler's data does not work in line %i\n", uline); \ |
---|
80 | OK = false; \ |
---|
81 | } \ |
---|
82 | if (userhandler.getCurrentSrc() != usrc) {\ |
---|
83 | fprintf(stderr, "DOMUserDataHandler::handler's src does not work in line %i\n", uline); \ |
---|
84 | OK = false; \ |
---|
85 | } \ |
---|
86 | if (userhandler.getCurrentDst() != udst) {\ |
---|
87 | fprintf(stderr, "DOMUserDataHandler::handler's dst does not work in line %i\n", uline); \ |
---|
88 | OK = false; \ |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | #define LOOKUPDEFAULTNSTEST(thisNode, uri, pass, line) \ |
---|
93 | if(thisNode->isDefaultNamespace(uri)) { \ |
---|
94 | if(!pass) { \ |
---|
95 | fprintf(stderr, "DOMNode::isDefaultNamespace returned true in line %i\n", line); \ |
---|
96 | OK = false; \ |
---|
97 | } \ |
---|
98 | } \ |
---|
99 | else { \ |
---|
100 | if(pass) { \ |
---|
101 | fprintf(stderr, "DOMNode::isDefaultNamespace returned false in line %i\n", line); \ |
---|
102 | OK = false; \ |
---|
103 | } \ |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | #define LOOKUPNSTEST(thisNode, prefix, uri, pass, line) \ |
---|
108 | prefixResult = XMLString::compareString(thisNode->lookupPrefix(uri), prefix); \ |
---|
109 | uriResult = XMLString::compareString(thisNode->lookupNamespaceURI(prefix), uri); \ |
---|
110 | if(pass) { \ |
---|
111 | if(prefixResult != 0) { \ |
---|
112 | fprintf(stderr, "DOMNode::lookupNamespacePrefix does not work in line %i\n", line); \ |
---|
113 | OK = false; \ |
---|
114 | } \ |
---|
115 | if(uriResult != 0) { \ |
---|
116 | fprintf(stderr, "DOMNode::lookupNamespaceURI does not work in line %i\n", line); \ |
---|
117 | OK = false;\ |
---|
118 | } \ |
---|
119 | } \ |
---|
120 | else { \ |
---|
121 | if(prefixResult == 0) { \ |
---|
122 | fprintf(stderr, "DOMNode::lookupNamespacePrefix does not work in line %i\n", line); \ |
---|
123 | OK = false; \ |
---|
124 | } \ |
---|
125 | if(uriResult == 0) { \ |
---|
126 | fprintf(stderr, "DOMNode::lookupNamespaceURI does not work in line %i\n", line); \ |
---|
127 | OK = false; \ |
---|
128 | } \ |
---|
129 | } \ |
---|
130 | |
---|
131 | int prefixResult; |
---|
132 | int uriResult; |
---|
133 | |
---|
134 | #define COMPARETREEPOSITIONTEST(thisNode, otherNode, position, line) \ |
---|
135 | myposition = thisNode->compareDocumentPosition(otherNode); \ |
---|
136 | if ((myposition & position) == 0) {\ |
---|
137 | fprintf(stderr, "DOMNode::compareDocumentPosition does not work in line %i\n", line); \ |
---|
138 | OK = false; \ |
---|
139 | } |
---|
140 | |
---|
141 | // temp position for compareDocumentPosition |
---|
142 | short myposition; |
---|
143 | |
---|
144 | //temp XMLCh String Buffer |
---|
145 | XMLCh tempStr[4000]; |
---|
146 | XMLCh tempStr2[4000]; |
---|
147 | XMLCh tempStr3[4000]; |
---|
148 | XMLCh tempStr4[4000]; |
---|
149 | XMLCh tempStr5[4000]; |
---|
150 | |
---|
151 | //DOMUserDataHandler |
---|
152 | myUserDataHandler userhandler; |
---|
153 | |
---|
154 | DOMElement* DOMTest::testElementNode; |
---|
155 | DOMAttr* DOMTest::testAttributeNode; |
---|
156 | DOMText* DOMTest::testTextNode; |
---|
157 | DOMCDATASection* DOMTest::testCDATASectionNode; |
---|
158 | DOMEntityReference* DOMTest::testEntityReferenceNode; |
---|
159 | DOMEntity* DOMTest::testEntityNode; |
---|
160 | DOMProcessingInstruction* DOMTest::testProcessingInstructionNode; |
---|
161 | DOMComment* DOMTest::testCommentNode; |
---|
162 | DOMDocument* DOMTest::testDocumentNode; |
---|
163 | DOMDocumentType* DOMTest::testDocumentTypeNode; |
---|
164 | DOMDocumentFragment* DOMTest::testDocumentFragmentNode; |
---|
165 | DOMNotation* DOMTest::testNotationNode; |
---|
166 | |
---|
167 | /** |
---|
168 | * |
---|
169 | * |
---|
170 | */ |
---|
171 | |
---|
172 | DOMTest::DOMTest() |
---|
173 | { |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | /** |
---|
178 | * |
---|
179 | * @return DOMDocument |
---|
180 | * |
---|
181 | */ |
---|
182 | DOMDocument* DOMTest::createDocument() { |
---|
183 | XMLCh coreStr[100]; |
---|
184 | XMLString::transcode("Core",coreStr,99); |
---|
185 | |
---|
186 | DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(coreStr); |
---|
187 | return impl->createDocument(); |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | /** |
---|
192 | * |
---|
193 | * @return DOMDocumentType |
---|
194 | * @param name XMLCh* |
---|
195 | * |
---|
196 | */ |
---|
197 | DOMDocumentType* DOMTest::createDocumentType(DOMDocument* doc, XMLCh* name) { |
---|
198 | return doc->createDocumentType(name); //Replace with a DOMDocumentType* creator |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | /** |
---|
203 | * |
---|
204 | * @return org.w3c.dom.DOMEntity |
---|
205 | * @param doc org.w3c.dom.DOMDocument |
---|
206 | * @param name XMLCh* |
---|
207 | * |
---|
208 | */ |
---|
209 | DOMEntity* DOMTest::createEntity(DOMDocument* doc, XMLCh* name) { |
---|
210 | return doc->createEntity(name); |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | /** |
---|
216 | * |
---|
217 | * @return org.w3c.dom.DOMNotation |
---|
218 | * @param doc org.w3c.dom.DOMDocument |
---|
219 | * @param name XMLCh* |
---|
220 | * |
---|
221 | */ |
---|
222 | DOMNotation* DOMTest::createNotation(DOMDocument* doc, XMLCh* name) { |
---|
223 | return doc->createNotation(name); |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | /** |
---|
228 | * This method builds test documents for the XML DOM implementation |
---|
229 | * @param document org.w3c.dom.DOMDocument |
---|
230 | * @param name document's name |
---|
231 | * @param type document's type |
---|
232 | * |
---|
233 | */ |
---|
234 | bool DOMTest::docBuilder(DOMDocument* document, XMLCh* nameIn) |
---|
235 | { |
---|
236 | XMLCh* name = XMLString::replicate(nameIn); |
---|
237 | |
---|
238 | DOMDocument* doc = document; |
---|
239 | bool OK = true; |
---|
240 | |
---|
241 | //name + "FirstElement" |
---|
242 | XMLString::transcode("FirstElement", tempStr2, 3999); |
---|
243 | XMLString::copyString(tempStr, name); |
---|
244 | XMLString::catString(tempStr, tempStr2); |
---|
245 | |
---|
246 | DOMElement* docFirstElement = doc->createElement(tempStr); |
---|
247 | doc->appendChild(docFirstElement); |
---|
248 | |
---|
249 | //name + "FirstElement", name + "firstElement" |
---|
250 | XMLString::catString(tempStr, name); |
---|
251 | XMLString::transcode("FirstElement", tempStr2, 3999); |
---|
252 | XMLString::catString(tempStr, tempStr2); |
---|
253 | XMLString::catString(tempStr2, name); |
---|
254 | XMLString::transcode("firstElement", tempStr3, 3999); |
---|
255 | XMLString::catString(tempStr2, tempStr3); |
---|
256 | docFirstElement->setAttribute(tempStr, tempStr2); |
---|
257 | DOMAttr* docFirstElementAttr = docFirstElement->getAttributeNode(tempStr); |
---|
258 | |
---|
259 | //name + "TargetProcessorChannel" + "This is " + doc->getNodeName() + "'s processing instruction"); |
---|
260 | XMLString::copyString(tempStr, name); |
---|
261 | XMLString::transcode("TargetProcessorChannel", tempStr2, 3999); |
---|
262 | XMLString::catString(tempStr, tempStr2); |
---|
263 | XMLString::transcode("This is ", tempStr2, 3999); |
---|
264 | XMLString::catString(tempStr2, doc->getNodeName()); |
---|
265 | XMLString::transcode("'s processing instruction", tempStr3, 3999); |
---|
266 | XMLString::catString(tempStr2, tempStr3); |
---|
267 | |
---|
268 | DOMProcessingInstruction* docProcessingInstruction = doc->createProcessingInstruction(tempStr, tempStr2); |
---|
269 | docFirstElement->appendChild(docProcessingInstruction); |
---|
270 | |
---|
271 | //name + "TestBody" |
---|
272 | XMLString::copyString(tempStr, name); |
---|
273 | XMLString::transcode("TestBody", tempStr2, 3999); |
---|
274 | XMLString::catString(tempStr, tempStr2); |
---|
275 | DOMElement* docBody = doc->createElement(tempStr); |
---|
276 | docFirstElement->appendChild(docBody); |
---|
277 | |
---|
278 | //name + "BodyLevel21" |
---|
279 | XMLString::copyString(tempStr, name); |
---|
280 | XMLString::transcode("BodyLevel21", tempStr2, 3999); |
---|
281 | XMLString::catString(tempStr, tempStr2); |
---|
282 | DOMElement* docBodyLevel21 = doc->createElement(tempStr); |
---|
283 | |
---|
284 | //name + "BodyLevel22" |
---|
285 | XMLString::copyString(tempStr, name); |
---|
286 | XMLString::transcode("BodyLevel22", tempStr2, 3999); |
---|
287 | XMLString::catString(tempStr, tempStr2); |
---|
288 | DOMElement* docBodyLevel22 = doc->createElement(tempStr); |
---|
289 | |
---|
290 | //name + "BodyLevel23" |
---|
291 | XMLString::copyString(tempStr, name); |
---|
292 | XMLString::transcode("BodyLevel23", tempStr2, 3999); |
---|
293 | XMLString::catString(tempStr, tempStr2); |
---|
294 | DOMElement* docBodyLevel23 = doc->createElement(tempStr); |
---|
295 | |
---|
296 | //name + "BodyLevel24" |
---|
297 | XMLString::copyString(tempStr, name); |
---|
298 | XMLString::transcode("BodyLevel24", tempStr2, 3999); |
---|
299 | XMLString::catString(tempStr, tempStr2); |
---|
300 | DOMElement* docBodyLevel24 = doc->createElement(tempStr); |
---|
301 | |
---|
302 | docBody->appendChild(docBodyLevel21); |
---|
303 | docBody->appendChild(docBodyLevel22); |
---|
304 | docBody->appendChild(docBodyLevel23); |
---|
305 | docBody->appendChild(docBodyLevel24); |
---|
306 | |
---|
307 | //name + "BodyLevel31" |
---|
308 | XMLString::copyString(tempStr, name); |
---|
309 | XMLString::transcode("BodyLevel31", tempStr2, 3999); |
---|
310 | XMLString::catString(tempStr, tempStr2); |
---|
311 | DOMElement* docBodyLevel31 = doc->createElement(tempStr); |
---|
312 | |
---|
313 | //name + "BodyLevel32" |
---|
314 | XMLString::copyString(tempStr, name); |
---|
315 | XMLString::transcode("BodyLevel32", tempStr2, 3999); |
---|
316 | XMLString::catString(tempStr, tempStr2); |
---|
317 | DOMElement* docBodyLevel32 = doc->createElement(tempStr); |
---|
318 | |
---|
319 | //name + "BodyLevel33" |
---|
320 | XMLString::copyString(tempStr, name); |
---|
321 | XMLString::transcode("BodyLevel33", tempStr2, 3999); |
---|
322 | XMLString::catString(tempStr, tempStr2); |
---|
323 | DOMElement* docBodyLevel33 = doc->createElement(tempStr); |
---|
324 | |
---|
325 | //name + "BodyLevel34" |
---|
326 | XMLString::copyString(tempStr, name); |
---|
327 | XMLString::transcode("BodyLevel34", tempStr2, 3999); |
---|
328 | XMLString::catString(tempStr, tempStr2); |
---|
329 | DOMElement* docBodyLevel34 = doc->createElement(tempStr); |
---|
330 | |
---|
331 | docBodyLevel21->appendChild(docBodyLevel31); |
---|
332 | docBodyLevel21->appendChild(docBodyLevel32); |
---|
333 | docBodyLevel22->appendChild(docBodyLevel33); |
---|
334 | docBodyLevel22->appendChild(docBodyLevel34); |
---|
335 | |
---|
336 | //name + "BodyLevel31'sChildTextNode11" |
---|
337 | XMLString::copyString(tempStr, name); |
---|
338 | XMLString::transcode("BodyLevel31'sChildTextNode11", tempStr2, 3999); |
---|
339 | XMLString::catString(tempStr, tempStr2); |
---|
340 | DOMText* docTextNode11 = doc->createTextNode(tempStr); |
---|
341 | |
---|
342 | //name + "BodyLevel31'sChildTextNode12" |
---|
343 | XMLString::copyString(tempStr, name); |
---|
344 | XMLString::transcode("BodyLevel31'sChildTextNode12", tempStr2, 3999); |
---|
345 | XMLString::catString(tempStr, tempStr2); |
---|
346 | DOMText* docTextNode12 = doc->createTextNode(tempStr); |
---|
347 | |
---|
348 | //name + "BodyLevel31'sChildTextNode13" |
---|
349 | XMLString::copyString(tempStr, name); |
---|
350 | XMLString::transcode("BodyLevel31'sChildTextNode13", tempStr2, 3999); |
---|
351 | XMLString::catString(tempStr, tempStr2); |
---|
352 | DOMText* docTextNode13 = doc->createTextNode(tempStr); |
---|
353 | |
---|
354 | //name + "TextNode2" |
---|
355 | XMLString::copyString(tempStr, name); |
---|
356 | XMLString::transcode("TextNode2", tempStr2, 3999); |
---|
357 | XMLString::catString(tempStr, tempStr2); |
---|
358 | DOMText* docTextNode2 = doc->createTextNode(tempStr); |
---|
359 | |
---|
360 | //name + "TextNode3" |
---|
361 | XMLString::copyString(tempStr, name); |
---|
362 | XMLString::transcode("TextNode3", tempStr2, 3999); |
---|
363 | XMLString::catString(tempStr, tempStr2); |
---|
364 | DOMText* docTextNode3 = doc->createTextNode(tempStr); |
---|
365 | |
---|
366 | //name + "TextNode4" |
---|
367 | XMLString::copyString(tempStr, name); |
---|
368 | XMLString::transcode("TextNode4", tempStr2, 3999); |
---|
369 | XMLString::catString(tempStr, tempStr2); |
---|
370 | DOMText* docTextNode4 = doc->createTextNode(tempStr); |
---|
371 | |
---|
372 | docBodyLevel31->appendChild(docTextNode11); |
---|
373 | docBodyLevel31->appendChild(docTextNode12); |
---|
374 | docBodyLevel31->appendChild(docTextNode13); |
---|
375 | docBodyLevel32->appendChild(docTextNode2); |
---|
376 | docBodyLevel33->appendChild(docTextNode3); |
---|
377 | docBodyLevel34->appendChild(docTextNode4); |
---|
378 | |
---|
379 | //"<![CDATA[<greeting>Hello, world!</greeting>]]>" |
---|
380 | XMLString::transcode("<![CDATA[<greeting>Hello, world!</greeting>]]>", tempStr, 3999); |
---|
381 | DOMCDATASection* docCDATASection = doc->createCDATASection(tempStr); |
---|
382 | docBodyLevel23->appendChild(docCDATASection); |
---|
383 | |
---|
384 | //"This should be a comment of some kind " |
---|
385 | XMLString::transcode("This should be a comment of some kind ", tempStr, 3999); |
---|
386 | DOMComment* docComment = doc->createComment(tempStr); |
---|
387 | |
---|
388 | //Test compareDocumentPosition before append |
---|
389 | COMPARETREEPOSITIONTEST(docFirstElementAttr, docComment, DOMNode::DOCUMENT_POSITION_DISCONNECTED, __LINE__); |
---|
390 | |
---|
391 | docBodyLevel23->appendChild(docComment); |
---|
392 | |
---|
393 | //"ourEntityNode" |
---|
394 | XMLString::transcode("ourEntityNode", tempStr, 3999); |
---|
395 | DOMEntityReference* docReferenceEntity = doc->createEntityReference(tempStr); |
---|
396 | docBodyLevel24->appendChild(docReferenceEntity); |
---|
397 | |
---|
398 | DOMTest make; |
---|
399 | |
---|
400 | //"ourNotationNode" |
---|
401 | XMLString::transcode("ourNotationNode", tempStr, 3999); |
---|
402 | DOMNotation* docNotation = make.createNotation(doc, tempStr); |
---|
403 | DOMNode* abc1 = doc->getFirstChild(); |
---|
404 | DOMDocumentType* docType = (DOMDocumentType*) abc1; |
---|
405 | DOMNode* rem = docType->getNotations()->setNamedItem(docNotation); |
---|
406 | if (rem) |
---|
407 | rem->release(); |
---|
408 | |
---|
409 | |
---|
410 | //***********Do some quick compareDocumentPosition tests |
---|
411 | //The tree now looks like |
---|
412 | // |
---|
413 | // docFirstElement (has docFirstElementAttr) |
---|
414 | // | |
---|
415 | // |_ docProcessInstruction |
---|
416 | // | |
---|
417 | // |_ docBody |
---|
418 | // | |
---|
419 | // |_ docBodyLevel21 |
---|
420 | // | | |
---|
421 | // | |_ docBodyLevel31 |
---|
422 | // | | | |
---|
423 | // | | |_ docTextNode11 |
---|
424 | // | | | |
---|
425 | // | | |_ docTextNode12 |
---|
426 | // | | | |
---|
427 | // | | |_ docTextNode13 |
---|
428 | // | | |
---|
429 | // | |_ docBodyLevel32 |
---|
430 | // | | |
---|
431 | // | |_ docTextNode2 |
---|
432 | // | |
---|
433 | // |_ docBodyLevel22 |
---|
434 | // | | |
---|
435 | // | |_ docBodyLevel33 |
---|
436 | // | | | |
---|
437 | // | | |_ docTextNode3 |
---|
438 | // | | |
---|
439 | // | | |
---|
440 | // | |_ docBodyLevel34 |
---|
441 | // | | |
---|
442 | // | |_ docTextNode4 |
---|
443 | // | |
---|
444 | // |_ docBodyLevel23 |
---|
445 | // | | |
---|
446 | // | |_ docCDATASection |
---|
447 | // | | |
---|
448 | // | |_ docComment |
---|
449 | // | |
---|
450 | // |_ docBodyLevel24 |
---|
451 | // | |
---|
452 | // |_ docReferenceEntity |
---|
453 | // |
---|
454 | |
---|
455 | COMPARETREEPOSITIONTEST(docProcessingInstruction, docBody, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
456 | COMPARETREEPOSITIONTEST(docBodyLevel24, docProcessingInstruction, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
457 | COMPARETREEPOSITIONTEST(docBodyLevel23, docBodyLevel21, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
458 | COMPARETREEPOSITIONTEST(docBodyLevel21, docTextNode11, DOMNode::DOCUMENT_POSITION_CONTAINED_BY, __LINE__); |
---|
459 | COMPARETREEPOSITIONTEST(docCDATASection, docFirstElement, DOMNode::DOCUMENT_POSITION_CONTAINS, __LINE__); |
---|
460 | COMPARETREEPOSITIONTEST(docReferenceEntity, docFirstElement, DOMNode::DOCUMENT_POSITION_CONTAINS, __LINE__); |
---|
461 | COMPARETREEPOSITIONTEST(docFirstElementAttr, docFirstElement, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
462 | COMPARETREEPOSITIONTEST(docFirstElementAttr, docProcessingInstruction, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
463 | COMPARETREEPOSITIONTEST(docProcessingInstruction, docFirstElementAttr, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
464 | COMPARETREEPOSITIONTEST(docFirstElementAttr, doc, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
465 | COMPARETREEPOSITIONTEST(doc, docFirstElementAttr, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
466 | COMPARETREEPOSITIONTEST(docBodyLevel21, docBodyLevel22, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
467 | |
---|
468 | COMPARETREEPOSITIONTEST(docNotation, docFirstElement, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
469 | |
---|
470 | myposition = docFirstElement->compareDocumentPosition(docFirstElement); |
---|
471 | if (myposition != 0) { |
---|
472 | fprintf(stderr, "DOMNode::compareDocumentPosition does not work in line %i\n", __LINE__); |
---|
473 | OK = false; |
---|
474 | } |
---|
475 | |
---|
476 | //now do some lookupNamespaceURI and lookupNamespacePrefix |
---|
477 | //first lets add some attributes |
---|
478 | XMLString::transcode("http://www.w3.org/2000/xmlns/", tempStr, 3999); |
---|
479 | XMLString::transcode("xmlns:pre1", tempStr2, 3999); |
---|
480 | XMLString::transcode("pre1URI", tempStr3, 3999); |
---|
481 | XMLString::transcode("pre1", tempStr4, 3999); |
---|
482 | |
---|
483 | DOMAttr *attr1 = doc->createAttributeNS(tempStr, tempStr2); |
---|
484 | attr1->setValue(tempStr3); |
---|
485 | docFirstElement->setAttributeNodeNS(attr1); |
---|
486 | |
---|
487 | |
---|
488 | LOOKUPNSTEST(docProcessingInstruction, tempStr4, tempStr3, true, __LINE__); |
---|
489 | LOOKUPNSTEST(docBodyLevel24, tempStr4, tempStr3, true, __LINE__); |
---|
490 | LOOKUPNSTEST(docBodyLevel23, tempStr4, tempStr3, true, __LINE__); |
---|
491 | LOOKUPNSTEST(docBodyLevel21, tempStr4, tempStr3, true, __LINE__); |
---|
492 | LOOKUPNSTEST(docBodyLevel31, tempStr4, tempStr3, true, __LINE__); |
---|
493 | LOOKUPNSTEST(docBodyLevel32, tempStr4, tempStr3, true, __LINE__); |
---|
494 | LOOKUPNSTEST(docCDATASection, tempStr4, tempStr3, true, __LINE__); |
---|
495 | LOOKUPNSTEST(docFirstElement, tempStr4, tempStr3, true, __LINE__); |
---|
496 | LOOKUPNSTEST(docReferenceEntity, tempStr4, tempStr3, true, __LINE__); |
---|
497 | LOOKUPNSTEST(docFirstElementAttr, tempStr4, tempStr3, true, __LINE__); |
---|
498 | LOOKUPNSTEST(doc, tempStr4, tempStr3, true, __LINE__); |
---|
499 | LOOKUPNSTEST(docNotation, tempStr4, tempStr3, false, __LINE__); |
---|
500 | LOOKUPNSTEST(docTextNode2, tempStr4, tempStr3, true, __LINE__); |
---|
501 | LOOKUPNSTEST(docTextNode4, tempStr4, tempStr3, true, __LINE__); |
---|
502 | LOOKUPNSTEST(docComment, tempStr4, tempStr3, true, __LINE__); |
---|
503 | |
---|
504 | XMLString::transcode("xmlns:pre2", tempStr2, 3999); |
---|
505 | XMLString::transcode("pre2URI", tempStr3, 3999); |
---|
506 | XMLString::transcode("pre2", tempStr4, 3999); |
---|
507 | |
---|
508 | DOMAttr *attr2 = doc->createAttributeNS(tempStr, tempStr2); |
---|
509 | attr2->setValue(tempStr3); |
---|
510 | docBodyLevel21->setAttributeNodeNS(attr2); |
---|
511 | |
---|
512 | |
---|
513 | LOOKUPNSTEST(docProcessingInstruction, tempStr4, tempStr3, false, __LINE__); |
---|
514 | LOOKUPNSTEST(docBodyLevel24, tempStr4, tempStr3, false, __LINE__); |
---|
515 | LOOKUPNSTEST(docBodyLevel23, tempStr4, tempStr3, false, __LINE__); |
---|
516 | LOOKUPNSTEST(docBodyLevel21, tempStr4, tempStr3, true, __LINE__); |
---|
517 | LOOKUPNSTEST(docBodyLevel31, tempStr4, tempStr3, true, __LINE__); |
---|
518 | LOOKUPNSTEST(docBodyLevel32, tempStr4, tempStr3, true, __LINE__); |
---|
519 | LOOKUPNSTEST(docCDATASection, tempStr4, tempStr3, false, __LINE__); |
---|
520 | LOOKUPNSTEST(docFirstElement, tempStr4, tempStr3, false, __LINE__); |
---|
521 | LOOKUPNSTEST(docReferenceEntity, tempStr4, tempStr3, false, __LINE__); |
---|
522 | LOOKUPNSTEST(docFirstElementAttr, tempStr4, tempStr3, false, __LINE__); |
---|
523 | LOOKUPNSTEST(doc, tempStr4, tempStr3, false, __LINE__); |
---|
524 | LOOKUPNSTEST(docNotation, tempStr4, tempStr3, false, __LINE__); |
---|
525 | LOOKUPNSTEST(docComment, tempStr4, tempStr3, false, __LINE__); |
---|
526 | LOOKUPNSTEST(docTextNode2, tempStr4, tempStr3, true, __LINE__); |
---|
527 | LOOKUPNSTEST(docTextNode4, tempStr4, tempStr3, false, __LINE__); |
---|
528 | |
---|
529 | |
---|
530 | XMLString::transcode("xmlns", tempStr2, 3999); |
---|
531 | XMLString::transcode("default", tempStr3, 3999); |
---|
532 | XMLString::transcode("", tempStr4, 3999); |
---|
533 | |
---|
534 | |
---|
535 | DOMAttr *attr3 = doc->createAttributeNS(tempStr, tempStr2); |
---|
536 | attr3->setValue(tempStr3); |
---|
537 | docFirstElement->setAttributeNodeNS(attr3); |
---|
538 | |
---|
539 | LOOKUPNSTEST(docProcessingInstruction, 0, tempStr3, true, __LINE__); |
---|
540 | LOOKUPNSTEST(docBodyLevel24, 0, tempStr3, true, __LINE__); |
---|
541 | LOOKUPNSTEST(docBodyLevel23, 0, tempStr3, true, __LINE__); |
---|
542 | LOOKUPNSTEST(docBodyLevel21, 0, tempStr3, true, __LINE__); |
---|
543 | LOOKUPNSTEST(docBodyLevel31, 0, tempStr3, true, __LINE__); |
---|
544 | LOOKUPNSTEST(docBodyLevel32, 0, tempStr3, true, __LINE__); |
---|
545 | LOOKUPNSTEST(docCDATASection, 0, tempStr3, true, __LINE__); |
---|
546 | LOOKUPNSTEST(docFirstElement, 0, tempStr3, true, __LINE__); |
---|
547 | LOOKUPNSTEST(docReferenceEntity, 0, tempStr3, true, __LINE__); |
---|
548 | LOOKUPNSTEST(docFirstElementAttr, 0, tempStr3, true, __LINE__); |
---|
549 | LOOKUPNSTEST(doc, 0, tempStr3, true, __LINE__); |
---|
550 | LOOKUPNSTEST(docComment, 0, tempStr3, true, __LINE__); |
---|
551 | LOOKUPNSTEST(docTextNode2, 0, tempStr3, true, __LINE__); |
---|
552 | LOOKUPNSTEST(docTextNode4, 0, tempStr3, true, __LINE__); |
---|
553 | |
---|
554 | //this has to be done separately because negative lookup is the same as default ns lookup!!! |
---|
555 | |
---|
556 | prefixResult = XMLString::compareString(docNotation->lookupPrefix(tempStr3), 0); |
---|
557 | |
---|
558 | uriResult = XMLString::compareString(docNotation->lookupNamespaceURI(0), 0); |
---|
559 | if(prefixResult != 0) { |
---|
560 | fprintf(stderr, "DOMNode::lookupNamespacePrefix does not work in line %i\n", __LINE__); |
---|
561 | OK = false; |
---|
562 | } |
---|
563 | if(uriResult != 0) { |
---|
564 | fprintf(stderr, "DOMNode::lookupNamespacePrefix does not work in line %i\n", __LINE__); |
---|
565 | OK = false; |
---|
566 | } |
---|
567 | |
---|
568 | XMLString::transcode("notset", tempStr3, 3999); |
---|
569 | |
---|
570 | LOOKUPDEFAULTNSTEST(docProcessingInstruction, tempStr3, false, __LINE__); |
---|
571 | LOOKUPDEFAULTNSTEST(docBodyLevel24, tempStr3, false, __LINE__); |
---|
572 | LOOKUPDEFAULTNSTEST(docBodyLevel23, tempStr3, false, __LINE__); |
---|
573 | LOOKUPDEFAULTNSTEST(docBodyLevel21, tempStr3, false, __LINE__); |
---|
574 | LOOKUPDEFAULTNSTEST(docBodyLevel31, tempStr3, false, __LINE__); |
---|
575 | LOOKUPDEFAULTNSTEST(docBodyLevel32, tempStr3, false, __LINE__); |
---|
576 | LOOKUPDEFAULTNSTEST(docCDATASection, tempStr3, false, __LINE__); |
---|
577 | LOOKUPDEFAULTNSTEST(docFirstElement, tempStr3, false, __LINE__); |
---|
578 | LOOKUPDEFAULTNSTEST(docReferenceEntity, tempStr3, false, __LINE__); |
---|
579 | LOOKUPDEFAULTNSTEST(docFirstElementAttr, tempStr3, false, __LINE__); |
---|
580 | LOOKUPDEFAULTNSTEST(doc, tempStr3, false, __LINE__); |
---|
581 | LOOKUPDEFAULTNSTEST(docNotation, tempStr3, false, __LINE__); |
---|
582 | LOOKUPDEFAULTNSTEST(docComment, tempStr3, false, __LINE__); |
---|
583 | LOOKUPDEFAULTNSTEST(docTextNode2, tempStr3, false, __LINE__); |
---|
584 | LOOKUPDEFAULTNSTEST(docTextNode4, tempStr3, false, __LINE__); |
---|
585 | |
---|
586 | |
---|
587 | XMLString::transcode("default", tempStr3, 3999); |
---|
588 | |
---|
589 | LOOKUPDEFAULTNSTEST(docProcessingInstruction, tempStr3, false, __LINE__); |
---|
590 | LOOKUPDEFAULTNSTEST(docBodyLevel24, tempStr3, false, __LINE__); |
---|
591 | LOOKUPDEFAULTNSTEST(docBodyLevel23, tempStr3, false, __LINE__); |
---|
592 | LOOKUPDEFAULTNSTEST(docBodyLevel21, tempStr3, false, __LINE__); |
---|
593 | LOOKUPDEFAULTNSTEST(docBodyLevel31, tempStr3, false, __LINE__); |
---|
594 | LOOKUPDEFAULTNSTEST(docBodyLevel32, tempStr3, false, __LINE__); |
---|
595 | LOOKUPDEFAULTNSTEST(docCDATASection, tempStr3, false, __LINE__); |
---|
596 | LOOKUPDEFAULTNSTEST(docFirstElement, tempStr3, false, __LINE__); |
---|
597 | LOOKUPDEFAULTNSTEST(docReferenceEntity, tempStr3, false, __LINE__); |
---|
598 | LOOKUPDEFAULTNSTEST(docFirstElementAttr, tempStr3, false, __LINE__); |
---|
599 | LOOKUPDEFAULTNSTEST(doc, tempStr3, false, __LINE__); |
---|
600 | LOOKUPDEFAULTNSTEST(docNotation, tempStr3, false, __LINE__); |
---|
601 | LOOKUPDEFAULTNSTEST(docComment, tempStr3, false, __LINE__); |
---|
602 | LOOKUPDEFAULTNSTEST(docTextNode2, tempStr3, false, __LINE__); |
---|
603 | LOOKUPDEFAULTNSTEST(docTextNode4, tempStr3, false, __LINE__); |
---|
604 | |
---|
605 | //remove the xmlns attr |
---|
606 | docFirstElement->removeAttributeNode(attr3); |
---|
607 | |
---|
608 | LOOKUPDEFAULTNSTEST(docProcessingInstruction, 0, true, __LINE__); |
---|
609 | LOOKUPDEFAULTNSTEST(docBodyLevel24, 0, true, __LINE__); |
---|
610 | LOOKUPDEFAULTNSTEST(docBodyLevel23, 0, true, __LINE__); |
---|
611 | LOOKUPDEFAULTNSTEST(docBodyLevel21, 0, true, __LINE__); |
---|
612 | LOOKUPDEFAULTNSTEST(docBodyLevel31, 0, true, __LINE__); |
---|
613 | LOOKUPDEFAULTNSTEST(docBodyLevel32, 0, true, __LINE__); |
---|
614 | LOOKUPDEFAULTNSTEST(docCDATASection, 0, true, __LINE__); |
---|
615 | LOOKUPDEFAULTNSTEST(docFirstElement, 0, true, __LINE__); |
---|
616 | LOOKUPDEFAULTNSTEST(docReferenceEntity, 0, true, __LINE__); |
---|
617 | LOOKUPDEFAULTNSTEST(docFirstElementAttr, 0, true, __LINE__); |
---|
618 | LOOKUPDEFAULTNSTEST(doc, 0, true, __LINE__); |
---|
619 | LOOKUPDEFAULTNSTEST(docNotation, 0, false, __LINE__); |
---|
620 | LOOKUPDEFAULTNSTEST(docComment, 0, true, __LINE__); |
---|
621 | LOOKUPDEFAULTNSTEST(docTextNode2, 0, true, __LINE__); |
---|
622 | LOOKUPDEFAULTNSTEST(docTextNode4, 0, true, __LINE__); |
---|
623 | |
---|
624 | XMLString::transcode("someSpecialURI", tempStr3, 3999); |
---|
625 | XMLString::transcode("newNameForEle", tempStr4, 3999); |
---|
626 | DOMElement *ele = doc->createElementNS(tempStr3, tempStr4); |
---|
627 | docFirstElement->insertBefore(ele, docFirstElement->getFirstChild()); |
---|
628 | |
---|
629 | // test for bug# 26919 |
---|
630 | docFirstElement->insertBefore(docFirstElement->getFirstChild(), docFirstElement->getFirstChild()); |
---|
631 | |
---|
632 | //a test for lookup when xmlns is not set so we take the fact that there is no prefix to be confimation |
---|
633 | LOOKUPDEFAULTNSTEST(ele, tempStr3, true, __LINE__); |
---|
634 | |
---|
635 | docFirstElement->removeAttributeNode(attr1); |
---|
636 | docBodyLevel21->removeAttributeNode(attr2); |
---|
637 | docFirstElement->removeChild(ele); |
---|
638 | |
---|
639 | //***********Following are for errorTests |
---|
640 | DOMDocumentFragment* docDocFragment = doc->createDocumentFragment(); |
---|
641 | UNUSED(docDocFragment); // silence warning |
---|
642 | |
---|
643 | //name + "docTextNode3" |
---|
644 | XMLString::copyString(tempStr, name); |
---|
645 | XMLString::transcode("docTextNode3", tempStr2, 3999); |
---|
646 | XMLString::catString(tempStr, tempStr2); |
---|
647 | DOMText* docNode3 = doc->createTextNode(tempStr); |
---|
648 | |
---|
649 | //name + "docTextNode4" |
---|
650 | XMLString::copyString(tempStr, name); |
---|
651 | XMLString::transcode("docTextNode4", tempStr2, 3999); |
---|
652 | XMLString::catString(tempStr, tempStr2); |
---|
653 | DOMText* docNode4 = doc->createTextNode(tempStr); |
---|
654 | |
---|
655 | //"ourEntityNode" |
---|
656 | XMLString::transcode("ourEntityNode", tempStr, 3999); |
---|
657 | DOMNode* abc2 = doc->getDoctype()->getEntities()->getNamedItem(tempStr); // Get the DOMEntity* node |
---|
658 | DOMEntity* docEntity = (DOMEntity*) abc2; |
---|
659 | UNUSED(docEntity); // silence warning |
---|
660 | DOMNode* abc3 = doc->getFirstChild(); // Get the DOMDocumentType* node |
---|
661 | DOMDocumentType* docDocType = (DOMDocumentType*) abc3; |
---|
662 | UNUSED(docDocType); // silence warning |
---|
663 | DOMNode* abc4 = doc->getLastChild()->getLastChild()->getLastChild()->getFirstChild(); |
---|
664 | DOMEntityReference* entityReferenceText = (DOMEntityReference*) abc4; |
---|
665 | UNUSED(entityReferenceText); // silence warning |
---|
666 | |
---|
667 | //"entityReferenceText information" |
---|
668 | XMLString::transcode("entityReferenceText information", tempStr, 3999); |
---|
669 | DOMText* entityReferenceText2 = doc->createTextNode(tempStr); |
---|
670 | //************************************************ ERROR TESTS |
---|
671 | DOMTest tests; |
---|
672 | |
---|
673 | EXCEPTIONSTEST(document->appendChild(docBody), DOMException::HIERARCHY_REQUEST_ERR, OK, 1); |
---|
674 | |
---|
675 | EXCEPTIONSTEST(document->appendChild(docBody), DOMException::HIERARCHY_REQUEST_ERR, OK, 2); |
---|
676 | EXCEPTIONSTEST(docNode3->appendChild(docNode4), DOMException::HIERARCHY_REQUEST_ERR, OK, 3); |
---|
677 | // EXCEPTIONSTEST(doc->insertBefore(docEntity, docFirstElement), DOMException::HIERARCHY_REQUEST_ERR, OK, 4); |
---|
678 | EXCEPTIONSTEST(doc->replaceChild(docCDATASection, docFirstElement), DOMException::HIERARCHY_REQUEST_ERR, OK, 5); |
---|
679 | |
---|
680 | //"This shouldn't work!" |
---|
681 | XMLString::transcode("entityReferenceText information", tempStr, 3999); |
---|
682 | |
---|
683 | // The following setNodeValue tests are not invalid |
---|
684 | // According to DOM spec, if the node value is defined to be null in the DOM spec, setting it has no effect. |
---|
685 | // Only those node type that are supposed to have node value, exception will be raised if the node is readonly. |
---|
686 | // EXCEPTIONSTEST(docFirstElement->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 6); |
---|
687 | // EXCEPTIONSTEST(docReferenceEntity->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 7); |
---|
688 | // EXCEPTIONSTEST(docEntity->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 8); |
---|
689 | // EXCEPTIONSTEST(doc->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 9); |
---|
690 | // EXCEPTIONSTEST(docDocType->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 10); |
---|
691 | // EXCEPTIONSTEST(docDocFragment->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 11); |
---|
692 | // EXCEPTIONSTEST(docNotation->setNodeValue(tempStr), DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 12); |
---|
693 | EXCEPTIONSTEST(docReferenceEntity->appendChild(entityReferenceText2 ), DOMException::NO_MODIFICATION_ALLOWED_ERR , OK, 13); |
---|
694 | EXCEPTIONSTEST(docBodyLevel32->insertBefore(docTextNode11,docBody ), DOMException::NOT_FOUND_ERR, OK, 14); |
---|
695 | EXCEPTIONSTEST(docBodyLevel32->removeChild(docFirstElement), DOMException::NOT_FOUND_ERR, OK, 15); |
---|
696 | EXCEPTIONSTEST(docBodyLevel32->replaceChild(docTextNode11,docFirstElement ), DOMException::NOT_FOUND_ERR, OK, 16); |
---|
697 | |
---|
698 | XMLString::release(&name); |
---|
699 | |
---|
700 | return OK; |
---|
701 | |
---|
702 | |
---|
703 | //!! Throws a NOT_FOUND_ERR ******** |
---|
704 | |
---|
705 | // docBodyLevel32->getAttributes()->removeNamedItem(testAttribute->getName()); 16 // To test removeNamedItem |
---|
706 | |
---|
707 | } //END OF DOCBUILDER |
---|
708 | |
---|
709 | |
---|
710 | |
---|
711 | /** |
---|
712 | * @param document org.w3c.dom.DOMDocument |
---|
713 | */ |
---|
714 | void DOMTest::findTestNodes(DOMDocument* document) { |
---|
715 | DOMNode* node = document; |
---|
716 | int nodeCount = 0; |
---|
717 | |
---|
718 | // Walk the tree until you find and assign all node types needed that exist. |
---|
719 | while (node != 0 && nodeCount < 12) |
---|
720 | { |
---|
721 | |
---|
722 | switch (node->getNodeType()) |
---|
723 | { |
---|
724 | case DOMNode::ELEMENT_NODE : |
---|
725 | if (testElementNode == 0) {testElementNode = (DOMElement*)node; nodeCount++;} |
---|
726 | break; |
---|
727 | case DOMNode::ATTRIBUTE_NODE : |
---|
728 | if (testAttributeNode == 0) {testAttributeNode = (DOMAttr*)node; nodeCount++;} |
---|
729 | break; |
---|
730 | case DOMNode::TEXT_NODE : |
---|
731 | if (testTextNode == 0) {testTextNode = (DOMText*)node; nodeCount++;} |
---|
732 | break; |
---|
733 | case DOMNode::CDATA_SECTION_NODE : |
---|
734 | if (testCDATASectionNode == 0) {testCDATASectionNode = (DOMCDATASection*)node; nodeCount++;} |
---|
735 | break; |
---|
736 | case DOMNode::ENTITY_REFERENCE_NODE : |
---|
737 | if (testEntityReferenceNode == 0) {testEntityReferenceNode = (DOMEntityReference*)node; nodeCount++;} |
---|
738 | break; |
---|
739 | case DOMNode::ENTITY_NODE : |
---|
740 | if (testEntityNode == 0) {testEntityNode = (DOMEntity*)node; nodeCount++;} |
---|
741 | break; |
---|
742 | case DOMNode::PROCESSING_INSTRUCTION_NODE : |
---|
743 | if (testProcessingInstructionNode == 0) {testProcessingInstructionNode = (DOMProcessingInstruction*)node; nodeCount++;} |
---|
744 | break; |
---|
745 | case DOMNode::COMMENT_NODE : |
---|
746 | if (testCommentNode == 0) {testCommentNode = (DOMComment*)node; nodeCount++;} |
---|
747 | break; |
---|
748 | case DOMNode::DOCUMENT_TYPE_NODE : |
---|
749 | if (testDocumentTypeNode == 0) {testDocumentTypeNode = (DOMDocumentType*)node; nodeCount++;} |
---|
750 | break; |
---|
751 | case DOMNode::DOCUMENT_FRAGMENT_NODE : |
---|
752 | if (testDocumentFragmentNode == 0) {testDocumentFragmentNode = (DOMDocumentFragment*)node; nodeCount++;} |
---|
753 | break; |
---|
754 | case DOMNode::NOTATION_NODE : |
---|
755 | if (testNotationNode == 0) {testNotationNode = (DOMNotation*)node; nodeCount++;} |
---|
756 | break; |
---|
757 | case DOMNode::DOCUMENT_NODE : |
---|
758 | if (testDocumentNode == 0) {testDocumentNode = (DOMDocument*)node; nodeCount++;} |
---|
759 | break; |
---|
760 | default: |
---|
761 | ; |
---|
762 | }// End of switch |
---|
763 | |
---|
764 | } // End of while |
---|
765 | } |
---|
766 | |
---|
767 | |
---|
768 | /** |
---|
769 | * @param document org.w3c.dom.DOMDocument |
---|
770 | */ |
---|
771 | void DOMTest::findTestNodes(DOMNode* node) { |
---|
772 | DOMTest test; |
---|
773 | DOMNode* kid; |
---|
774 | // Walk the tree until you find and assign all node types needed that exist. |
---|
775 | |
---|
776 | |
---|
777 | if (node->getFirstChild() != 0) |
---|
778 | { |
---|
779 | kid = node->getFirstChild(); |
---|
780 | test.findTestNodes(kid); |
---|
781 | } |
---|
782 | |
---|
783 | |
---|
784 | if (node->getNextSibling() != 0) |
---|
785 | { |
---|
786 | kid = node->getNextSibling(); |
---|
787 | test.findTestNodes(kid); |
---|
788 | } |
---|
789 | |
---|
790 | |
---|
791 | switch (node->getNodeType()) |
---|
792 | { |
---|
793 | case DOMNode::ELEMENT_NODE : |
---|
794 | if (testElementNode == 0) {testElementNode = (DOMElement*)node; } |
---|
795 | break; |
---|
796 | case DOMNode::ATTRIBUTE_NODE : |
---|
797 | if (testAttributeNode == 0) {testAttributeNode = (DOMAttr*)node; } |
---|
798 | break; |
---|
799 | case DOMNode::TEXT_NODE : |
---|
800 | if (testTextNode == 0) {testTextNode = (DOMText*)node; } |
---|
801 | break; |
---|
802 | case DOMNode::CDATA_SECTION_NODE : |
---|
803 | if (testCDATASectionNode == 0) {testCDATASectionNode = (DOMCDATASection*)node; } |
---|
804 | break; |
---|
805 | case DOMNode::ENTITY_REFERENCE_NODE : |
---|
806 | if (testEntityReferenceNode == 0) {testEntityReferenceNode = (DOMEntityReference*)node;} |
---|
807 | break; |
---|
808 | case DOMNode::ENTITY_NODE : |
---|
809 | if (testEntityNode == 0) {testEntityNode = (DOMEntity*)node;} |
---|
810 | break; |
---|
811 | case DOMNode::PROCESSING_INSTRUCTION_NODE : |
---|
812 | if (testProcessingInstructionNode == 0) {testProcessingInstructionNode = (DOMProcessingInstruction*)node;} |
---|
813 | break; |
---|
814 | case DOMNode::COMMENT_NODE : |
---|
815 | if (testCommentNode == 0) {testCommentNode = (DOMComment*)node;} |
---|
816 | break; |
---|
817 | case DOMNode::DOCUMENT_TYPE_NODE : |
---|
818 | if (testDocumentTypeNode == 0) {testDocumentTypeNode = (DOMDocumentType*)node; } |
---|
819 | break; |
---|
820 | case DOMNode::DOCUMENT_FRAGMENT_NODE : |
---|
821 | if (testDocumentFragmentNode == 0) {testDocumentFragmentNode = (DOMDocumentFragment*)node;} |
---|
822 | break; |
---|
823 | case DOMNode::NOTATION_NODE : |
---|
824 | if (testNotationNode == 0) {testNotationNode = (DOMNotation*)node;} |
---|
825 | break; |
---|
826 | case DOMNode::DOCUMENT_NODE : |
---|
827 | if (testDocumentNode == 0) {testDocumentNode = (DOMDocument*)node;} |
---|
828 | break; |
---|
829 | default: |
---|
830 | ; |
---|
831 | }// End of switch |
---|
832 | }//End of class |
---|
833 | |
---|
834 | /** |
---|
835 | * |
---|
836 | * |
---|
837 | */ |
---|
838 | int main(int /*argc*/, char ** /*argv*/) |
---|
839 | { |
---|
840 | bool OK = true; |
---|
841 | |
---|
842 | { |
---|
843 | // Nest entire test in an inner block. |
---|
844 | // Reference counting should recover all document |
---|
845 | // storage when this block exits. |
---|
846 | |
---|
847 | DOMTest test; |
---|
848 | try { |
---|
849 | XMLPlatformUtils::Initialize(); |
---|
850 | } |
---|
851 | catch (const XMLException& toCatch) { |
---|
852 | char *pMessage = XMLString::transcode(toCatch.getMessage()); |
---|
853 | fprintf(stderr, "Error during initialization! \n %s \n", pMessage); |
---|
854 | XMLString::release(&pMessage); |
---|
855 | return -1; |
---|
856 | } |
---|
857 | |
---|
858 | // for (int i=0; i< 1000; i++) |
---|
859 | // { |
---|
860 | // AH Revisit // startTime = System.currentTimeMillis(); |
---|
861 | // if(!OK) |
---|
862 | // break; |
---|
863 | |
---|
864 | DOMDocument* d = test.createDocument(); |
---|
865 | |
---|
866 | XMLString::transcode("testDocument1", tempStr, 3999); |
---|
867 | DOMDocumentType* docDocType = test.createDocumentType(d,tempStr); |
---|
868 | d->appendChild(docDocType); |
---|
869 | |
---|
870 | XMLString::transcode("ourEntityNode", tempStr, 3999); |
---|
871 | DOMEntity* docEntity = test.createEntity( d, tempStr); |
---|
872 | UNUSED(docEntity); // silence warning |
---|
873 | //Build a branch for entityReference tests |
---|
874 | // DOMText* entityChildText = d.createTextNode("entityChildText information"); // |
---|
875 | // docEntity->appendChild(entityChildText); |
---|
876 | // docDocType->getEntities()->setNamedItem(docEntity); |
---|
877 | |
---|
878 | XMLString::transcode("d", tempStr3, 3999); |
---|
879 | OK &= test.docBuilder(d, tempStr3); |
---|
880 | |
---|
881 | test.findTestNodes((DOMNode*)d); |
---|
882 | |
---|
883 | OK &= test.testAttr(d); |
---|
884 | OK &= test.testCDATASection(d); |
---|
885 | OK &= test.testCharacterData(d); |
---|
886 | OK &= test.testChildNodeList(d); |
---|
887 | OK &= test.testComment(d); |
---|
888 | OK &= test.testDeepNodeList(d); |
---|
889 | OK &= test.testDocument(d); |
---|
890 | OK &= test.testDocumentFragment(d); |
---|
891 | OK &= test.testDocumentType(d); |
---|
892 | OK &= test.testDOMImplementation(d); |
---|
893 | OK &= test.testElement(d); |
---|
894 | // OK &= test.testEntity(d); // Can not test entities; only parser can create them. |
---|
895 | OK &= test.testEntityReference(d); |
---|
896 | OK &= test.testNode(d); |
---|
897 | OK &= test.testNotation(d); |
---|
898 | OK &= test.testPI(d); |
---|
899 | OK &= test.testText(d); |
---|
900 | OK &= test.testDOMerrors(d); |
---|
901 | OK &= test.testXPath(d); |
---|
902 | OK &= test.testRegex(); |
---|
903 | |
---|
904 | // Null out the static object references in class DOMTest, |
---|
905 | // which will recover their storage. |
---|
906 | DOMTest::testElementNode = 0; |
---|
907 | DOMTest::testAttributeNode = 0; |
---|
908 | DOMTest::testTextNode = 0; |
---|
909 | DOMTest::testCDATASectionNode = 0; |
---|
910 | DOMTest::testEntityReferenceNode = 0; |
---|
911 | DOMTest::testEntityNode = 0; |
---|
912 | DOMTest::testProcessingInstructionNode = 0; |
---|
913 | DOMTest::testCommentNode = 0; |
---|
914 | DOMTest::testDocumentNode = 0; |
---|
915 | DOMTest::testDocumentTypeNode = 0; |
---|
916 | DOMTest::testDocumentFragmentNode = 0; |
---|
917 | DOMTest::testNotationNode = 0; |
---|
918 | |
---|
919 | // test release of attributes |
---|
920 | DOMElement* elt = d->createElement(tempStr3); |
---|
921 | elt->setAttribute(tempStr3, tempStr3); |
---|
922 | elt->release(); |
---|
923 | |
---|
924 | elt = d->createElement(tempStr3); |
---|
925 | DOMAttr *attr = d->createAttribute(tempStr3); |
---|
926 | attr->setValue(tempStr3); |
---|
927 | elt->setAttributeNode(attr); |
---|
928 | elt->setIdAttributeNode(attr, true); |
---|
929 | |
---|
930 | DOMElement *eleTest = d->getElementById(tempStr3); |
---|
931 | if(eleTest==NULL) |
---|
932 | { |
---|
933 | fprintf(stderr, "getElementById test failed at line %i\n", __LINE__); |
---|
934 | OK = false; |
---|
935 | } |
---|
936 | |
---|
937 | //all good until here |
---|
938 | elt->release(); |
---|
939 | eleTest = d->getElementById(tempStr3); |
---|
940 | if(eleTest!=NULL) |
---|
941 | { |
---|
942 | fprintf(stderr, "getElementById test failed at line %i\n", __LINE__); |
---|
943 | OK = false; |
---|
944 | } |
---|
945 | |
---|
946 | // we couldn't really test the user data handler call as the userhandler is already |
---|
947 | // deleted when the release() is done, but still set it to test the code internally |
---|
948 | d->setUserData(tempStr, (void*) tempStr, &userhandler); |
---|
949 | d->release(); |
---|
950 | |
---|
951 | // Test baseURI. BaseURI is set on nodes at parse time so we |
---|
952 | // cannot use the docBuilder document above |
---|
953 | |
---|
954 | //Setup parser |
---|
955 | |
---|
956 | XercesDOMParser *parser = new XercesDOMParser; |
---|
957 | parser->setValidationScheme(XercesDOMParser::Val_Never); |
---|
958 | parser->setDoNamespaces(true); |
---|
959 | parser->setDoSchema(true); |
---|
960 | parser->setCreateEntityReferenceNodes(true); |
---|
961 | |
---|
962 | OK &= test.testBaseURI(parser); |
---|
963 | |
---|
964 | parser->setCreateEntityReferenceNodes(false); |
---|
965 | OK &= test.testBaseURI(parser); |
---|
966 | |
---|
967 | parser->setDoNamespaces(false); |
---|
968 | parser->setDoSchema(false); |
---|
969 | OK &= test.testBaseURI(parser); |
---|
970 | |
---|
971 | parser->setCreateEntityReferenceNodes(true); |
---|
972 | OK &= test.testBaseURI(parser); |
---|
973 | |
---|
974 | OK &= test.testWholeText(parser); |
---|
975 | OK &= test.testScanner(parser); |
---|
976 | delete parser; |
---|
977 | |
---|
978 | OK &= test.testLSExceptions(); |
---|
979 | |
---|
980 | OK &= test.testElementTraversal(); |
---|
981 | |
---|
982 | OK &= test.testUtilFunctions(); |
---|
983 | } |
---|
984 | |
---|
985 | XMLPlatformUtils::Terminate(); |
---|
986 | |
---|
987 | if (!OK) { |
---|
988 | printf("Test Failed\n"); |
---|
989 | return 4; |
---|
990 | } |
---|
991 | |
---|
992 | printf("Test Run Successfully\n"); |
---|
993 | |
---|
994 | return 0; |
---|
995 | } |
---|
996 | |
---|
997 | |
---|
998 | /** |
---|
999 | * This method tests DOMAttr* methods for the XML DOM implementation |
---|
1000 | * @param document org.w3c.dom.DOMDocument |
---|
1001 | * |
---|
1002 | */ |
---|
1003 | bool DOMTest::testAttr(DOMDocument* document) |
---|
1004 | { |
---|
1005 | DOMNode* node; |
---|
1006 | DOMAttr* attributeNode; |
---|
1007 | bool T = true; |
---|
1008 | bool OK = true; |
---|
1009 | // For debugging***** printf("\n testAttr's outputs:\n\n"); |
---|
1010 | |
---|
1011 | XMLString::transcode("testAttribute", tempStr, 3999); |
---|
1012 | DOMAttr* testAttribute = document->createAttribute(tempStr); |
---|
1013 | |
---|
1014 | XMLString::transcode("testAttribute's value", tempStr, 3999); |
---|
1015 | testAttribute->setValue(tempStr); |
---|
1016 | node = document->getDocumentElement(); // node gets first element |
---|
1017 | |
---|
1018 | // ((DOMElement*)node)->setAttributeNode(testAttribute); |
---|
1019 | // attributeNode = ((DOMElement*)node)->getAttributeNode("testAttribute"); |
---|
1020 | DOMElement* el = (DOMElement*)node; |
---|
1021 | DOMNode* rem = el->setAttributeNode(testAttribute); |
---|
1022 | if (rem) |
---|
1023 | rem->release(); |
---|
1024 | |
---|
1025 | XMLString::transcode("testAttribute", tempStr, 3999); |
---|
1026 | attributeNode = el->getAttributeNode(tempStr); |
---|
1027 | |
---|
1028 | //Test compareDocumentPosition, the equivalent case here |
---|
1029 | XMLString::transcode("dFirstElementdFirstElement", tempStr2, 3999); |
---|
1030 | DOMAttr* docFirstElementAttr = el->getAttributeNode(tempStr2); |
---|
1031 | |
---|
1032 | COMPARETREEPOSITIONTEST(docFirstElementAttr, attributeNode, DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, __LINE__); |
---|
1033 | |
---|
1034 | // Test the name and other data |
---|
1035 | if (XMLString::compareString(tempStr, attributeNode->getName())) |
---|
1036 | { |
---|
1037 | fprintf(stderr, "Warning!!! DOMAttr's 'getName' method failed to work properly!\n"); |
---|
1038 | OK = false; |
---|
1039 | } |
---|
1040 | |
---|
1041 | XMLString::transcode("testAttribute's value", tempStr, 3999); |
---|
1042 | if (XMLString::compareString(tempStr, attributeNode->getNodeValue())) |
---|
1043 | { |
---|
1044 | fprintf(stderr, "Warning!!! DOMAttr's 'getNodeValue' method failed to work properly!\n"); |
---|
1045 | OK = false; |
---|
1046 | } |
---|
1047 | if (! T ==attributeNode->getSpecified()) |
---|
1048 | { |
---|
1049 | fprintf(stderr, "Warning!!! DOMAttr's 'getSpecified' method failed to work properly!\n"); |
---|
1050 | OK = false; |
---|
1051 | } |
---|
1052 | |
---|
1053 | if (XMLString::compareString(tempStr, attributeNode->getValue())) |
---|
1054 | { |
---|
1055 | fprintf(stderr, "Warning!!! DOMAttr's 'getValue' method failed to work properly!\n"); |
---|
1056 | OK = false; |
---|
1057 | } |
---|
1058 | |
---|
1059 | |
---|
1060 | XMLString::transcode("Reset Value", tempStr, 3999); |
---|
1061 | attributeNode->setNodeValue(tempStr); /// LEAK!!!!! |
---|
1062 | if (XMLString::compareString(tempStr, attributeNode->getNodeValue())) |
---|
1063 | { |
---|
1064 | fprintf(stderr, "Warning!!! DOMAttr's 'setNodeValue' method failed to work properly!\n"); |
---|
1065 | OK = false; |
---|
1066 | } |
---|
1067 | |
---|
1068 | attributeNode->setValue(XMLUni::fgZeroLenString); |
---|
1069 | if (XMLString::compareString(XMLUni::fgZeroLenString, attributeNode->getValue())) |
---|
1070 | { |
---|
1071 | fprintf(stderr, "Warning!!! DOMAttr's 'setValue' to '0' method failed to work properly!\n"); |
---|
1072 | OK = false; |
---|
1073 | } |
---|
1074 | |
---|
1075 | XMLString::transcode("Another value ", tempStr, 3999); |
---|
1076 | attributeNode->setValue(tempStr); |
---|
1077 | if (XMLString::compareString(tempStr, attributeNode->getValue())) |
---|
1078 | { |
---|
1079 | fprintf(stderr, "Warning!!! DOMAttr's 'setValue' method failed to work properly!"); |
---|
1080 | OK = false; |
---|
1081 | } |
---|
1082 | |
---|
1083 | node = attributeNode->cloneNode(T); |
---|
1084 | |
---|
1085 | // Check nodes for equality, both their name and value or lack thereof |
---|
1086 | bool cloneOK = true; |
---|
1087 | if (XMLString::compareString(node->getNodeName(), attributeNode->getNodeName())) |
---|
1088 | cloneOK = false; |
---|
1089 | if (node->getNodeValue() == 0 && |
---|
1090 | attributeNode->getNodeValue() != 0) |
---|
1091 | { |
---|
1092 | cloneOK = false; |
---|
1093 | } |
---|
1094 | |
---|
1095 | if (node->getNodeValue() != 0 && attributeNode->getNodeValue() == 0) |
---|
1096 | { |
---|
1097 | cloneOK = false; |
---|
1098 | } |
---|
1099 | |
---|
1100 | if (node->getNodeValue() != 0 && attributeNode->getNodeValue() != 0) |
---|
1101 | { |
---|
1102 | if (XMLString::compareString(node->getNodeValue(),attributeNode->getNodeValue())) |
---|
1103 | cloneOK = false; |
---|
1104 | } |
---|
1105 | |
---|
1106 | |
---|
1107 | /* |
---|
1108 | if (! (node->getNodeName(), attributeNode->getNodeName()) && // Compares node names for equality |
---|
1109 | (node->getNodeValue() != 0 && attributeNode->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
1110 | ? node->getNodeValue(), attributeNode->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
1111 | : (node->getNodeValue() == 0 && attributeNode->getNodeValue() == 0)))// If one node doesn't have a value node make sure both don't |
---|
1112 | */ |
---|
1113 | if (cloneOK == false) |
---|
1114 | { |
---|
1115 | fprintf(stderr, "'cloneNode' did not clone the Attribute node correctly\n"); |
---|
1116 | OK = false; |
---|
1117 | } |
---|
1118 | // Deep clone test comparison is in testNode & testDocument |
---|
1119 | |
---|
1120 | //************************************************* ERROR TESTS |
---|
1121 | DOMTest tests; |
---|
1122 | //!! Throws HIERARCHY_REQUEST_ERR **************** |
---|
1123 | // doc->getDocumentElement()->appendChild(attributeNode); |
---|
1124 | |
---|
1125 | //!! Throws a NOT_FOUND_ERR ******** |
---|
1126 | // attribute2 = doc->createAttribute("testAttribute2"); |
---|
1127 | // doc->getDocumentElement()->removeAttributeNode(attribute2); |
---|
1128 | |
---|
1129 | //!! Throws an INUSE_ATTRIBUTE_ERR ****** |
---|
1130 | // DOMElement* element = (DOMElement*)doc->getLastChild()->getLastChild(); |
---|
1131 | // element->setAttributeNode(testAttribute );// Tests setNamedItem which generates error through justSetNamedItem. |
---|
1132 | |
---|
1133 | |
---|
1134 | // Test the user data |
---|
1135 | // Test simple set and get |
---|
1136 | DOMAttr* userTest = testAttribute; |
---|
1137 | DOMElement* userFirst = el; |
---|
1138 | XMLCh* userSecond = tempStr2; |
---|
1139 | XMLString::transcode("first", tempStr, 3999); |
---|
1140 | |
---|
1141 | XMLString::transcode("document", tempStr2, 3999); |
---|
1142 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
1143 | void* mydocument = userTest->getUserData(tempStr2); |
---|
1144 | if (document != mydocument) { |
---|
1145 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
1146 | OK = false; |
---|
1147 | } |
---|
1148 | |
---|
1149 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
1150 | void* myFirst = userTest->getUserData(tempStr); |
---|
1151 | if (userFirst != myFirst) { |
---|
1152 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
1153 | OK = false; |
---|
1154 | } |
---|
1155 | |
---|
1156 | // Test overwrite |
---|
1157 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
1158 | void* mySecond = userTest->getUserData(tempStr); |
---|
1159 | if (userSecond != mySecond) { |
---|
1160 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1161 | OK = false; |
---|
1162 | } |
---|
1163 | if (userFirst != myFirst2) { |
---|
1164 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1165 | OK = false; |
---|
1166 | } |
---|
1167 | if (userFirst == mySecond) { |
---|
1168 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1169 | OK = false; |
---|
1170 | } |
---|
1171 | |
---|
1172 | // Test null |
---|
1173 | // test non-exist key |
---|
1174 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
1175 | if (userTest->getUserData(tempStr3)) { |
---|
1176 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1177 | OK = false; |
---|
1178 | } |
---|
1179 | |
---|
1180 | // use a node that does not have user data set before |
---|
1181 | if (userFirst->getUserData(tempStr)) { |
---|
1182 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1183 | OK = false; |
---|
1184 | } |
---|
1185 | |
---|
1186 | // Test reset |
---|
1187 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
1188 | void* myNull = userTest->getUserData(tempStr); |
---|
1189 | if (userSecond != mySecond2) { |
---|
1190 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1191 | OK = false; |
---|
1192 | } |
---|
1193 | if (myNull) { |
---|
1194 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1195 | OK = false; |
---|
1196 | } |
---|
1197 | |
---|
1198 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
1199 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
1200 | if (mydocument != mydocument2) { |
---|
1201 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1202 | OK = false; |
---|
1203 | } |
---|
1204 | if (myNull2) { |
---|
1205 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1206 | OK = false; |
---|
1207 | } |
---|
1208 | |
---|
1209 | //the userTest user data table should be null now |
---|
1210 | if (userTest->getUserData(tempStr)) { |
---|
1211 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1212 | OK = false; |
---|
1213 | } |
---|
1214 | if (userTest->getUserData(tempStr2)) { |
---|
1215 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1216 | OK = false; |
---|
1217 | } |
---|
1218 | |
---|
1219 | // Test DOMUserDataHandler |
---|
1220 | // test clone |
---|
1221 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
1222 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
1223 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
1224 | |
---|
1225 | // test import |
---|
1226 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
1227 | DOMNode* myimport = document->importNode(userTest,true); |
---|
1228 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
1229 | |
---|
1230 | // test delete |
---|
1231 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
1232 | myimport->release(); |
---|
1233 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
1234 | |
---|
1235 | // Test isSameNode |
---|
1236 | if (!userTest->isSameNode(userTest)) { |
---|
1237 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
1238 | OK = false; |
---|
1239 | } |
---|
1240 | if (userTest->isSameNode(userFirst)) { |
---|
1241 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
1242 | OK = false; |
---|
1243 | } |
---|
1244 | |
---|
1245 | // Test isEqualNode |
---|
1246 | if (!userTest->isEqualNode(mycloned)) { |
---|
1247 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1248 | OK = false; |
---|
1249 | } |
---|
1250 | |
---|
1251 | if (!userTest->isEqualNode(userTest)) { |
---|
1252 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1253 | OK = false; |
---|
1254 | } |
---|
1255 | if (userTest->isEqualNode(userFirst)) { |
---|
1256 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1257 | OK = false; |
---|
1258 | } |
---|
1259 | |
---|
1260 | // Test renameNode |
---|
1261 | XMLString::transcode("http://nsa", tempStr4, 3999); |
---|
1262 | XMLString::transcode("aa", tempStr5, 3999); |
---|
1263 | XMLString::transcode("pnsa:aa", tempStr3, 3999); |
---|
1264 | |
---|
1265 | // create the attribute |
---|
1266 | DOMAttr* renameTestAttribute = document->createAttribute(tempStr5); |
---|
1267 | DOMAttr* renameTestAttributeNS = document->createAttributeNS(tempStr4, tempStr3); |
---|
1268 | |
---|
1269 | // create the owner element and append the attribute node |
---|
1270 | DOMElement* renameTestElement = document->createElement(tempStr5); |
---|
1271 | renameTestElement->setAttributeNode(renameTestAttribute); |
---|
1272 | renameTestElement->setAttributeNode(renameTestAttributeNS); |
---|
1273 | |
---|
1274 | // set up the userdata |
---|
1275 | renameTestAttribute->setUserData(tempStr5, (void*) document, &userhandler); |
---|
1276 | renameTestAttributeNS->setUserData(tempStr4, (void*) document, 0); |
---|
1277 | |
---|
1278 | // set up the node value |
---|
1279 | renameTestAttribute->setNodeValue(tempStr5); |
---|
1280 | renameTestAttributeNS->setNodeValue(tempStr4); |
---|
1281 | |
---|
1282 | XMLString::transcode("http://nsb", tempStr, 3999); |
---|
1283 | XMLString::transcode("bb", tempStr2, 3999); |
---|
1284 | XMLString::transcode("pnsb:bb", tempStr3, 3999); |
---|
1285 | |
---|
1286 | // start the rename tests |
---|
1287 | // rename the NS Attribute |
---|
1288 | DOMAttr* renameTest = (DOMAttr*) document->renameNode(renameTestAttributeNS, tempStr, tempStr3); |
---|
1289 | // test the name |
---|
1290 | if (XMLString::compareString(tempStr, renameTest->getNamespaceURI())) |
---|
1291 | { |
---|
1292 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1293 | OK = false; |
---|
1294 | } |
---|
1295 | if (XMLString::compareString(tempStr2, renameTest->getLocalName())) |
---|
1296 | { |
---|
1297 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1298 | OK = false; |
---|
1299 | } |
---|
1300 | if (XMLString::compareString(tempStr3, renameTest->getNodeName())) |
---|
1301 | { |
---|
1302 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1303 | OK = false; |
---|
1304 | } |
---|
1305 | // test the child / nodevalue |
---|
1306 | if (XMLString::compareString(tempStr4, renameTest->getNodeValue())) |
---|
1307 | { |
---|
1308 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1309 | OK = false; |
---|
1310 | } |
---|
1311 | if (XMLString::compareString(tempStr4, renameTest->getFirstChild()->getNodeValue())) |
---|
1312 | { |
---|
1313 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1314 | OK = false; |
---|
1315 | } |
---|
1316 | // test the owner element |
---|
1317 | if (!renameTestElement->getAttributeNodeNS(tempStr, tempStr2)) { |
---|
1318 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1319 | OK = false; |
---|
1320 | } |
---|
1321 | if (renameTestElement->getAttributeNodeNS(tempStr4, tempStr5)) { |
---|
1322 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1323 | OK = false; |
---|
1324 | } |
---|
1325 | // test user data |
---|
1326 | void* renamedocument = renameTest->getUserData(tempStr4); |
---|
1327 | if (document != renamedocument) { |
---|
1328 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1329 | OK = false; |
---|
1330 | } |
---|
1331 | // test isSame and isEqual |
---|
1332 | if (!renameTestAttributeNS->isEqualNode(renameTest)) { |
---|
1333 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1334 | OK = false; |
---|
1335 | } |
---|
1336 | if (!renameTestAttributeNS->isSameNode(renameTest)) { |
---|
1337 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1338 | OK = false; |
---|
1339 | } |
---|
1340 | |
---|
1341 | |
---|
1342 | // rename the Attribute (null namespace) |
---|
1343 | renameTest = (DOMAttr*) document->renameNode(renameTestAttribute, 0, tempStr2); |
---|
1344 | // test the name |
---|
1345 | if (renameTest->getNamespaceURI()) |
---|
1346 | { |
---|
1347 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1348 | OK = false; |
---|
1349 | } |
---|
1350 | if (renameTest->getLocalName()) |
---|
1351 | { |
---|
1352 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1353 | OK = false; |
---|
1354 | } |
---|
1355 | if (XMLString::compareString(tempStr2, renameTest->getNodeName())) |
---|
1356 | { |
---|
1357 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1358 | OK = false; |
---|
1359 | } |
---|
1360 | // test the child / nodevalue |
---|
1361 | if (XMLString::compareString(tempStr5, renameTest->getNodeValue())) |
---|
1362 | { |
---|
1363 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1364 | OK = false; |
---|
1365 | } |
---|
1366 | if (XMLString::compareString(tempStr5, renameTest->getFirstChild()->getNodeValue())) |
---|
1367 | { |
---|
1368 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1369 | OK = false; |
---|
1370 | } |
---|
1371 | // test the owner element |
---|
1372 | if (!renameTestElement->getAttributeNode(tempStr2)) { |
---|
1373 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1374 | OK = false; |
---|
1375 | } |
---|
1376 | if (renameTestElement->getAttributeNode(tempStr5)) { |
---|
1377 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1378 | OK = false; |
---|
1379 | } |
---|
1380 | // test user data |
---|
1381 | renamedocument = renameTest->getUserData(tempStr5); |
---|
1382 | if (document != renamedocument) { |
---|
1383 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
1384 | OK = false; |
---|
1385 | } |
---|
1386 | // test isSame and isEqual |
---|
1387 | if (!renameTestAttribute->isEqualNode(renameTest)) { |
---|
1388 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1389 | OK = false; |
---|
1390 | } |
---|
1391 | if (!renameTestAttribute->isSameNode(renameTest)) { |
---|
1392 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1393 | OK = false; |
---|
1394 | } |
---|
1395 | |
---|
1396 | |
---|
1397 | // rename the Attribute (with namespace) |
---|
1398 | renameTest = (DOMAttr*) document->renameNode(renameTestAttribute, tempStr, tempStr3); |
---|
1399 | // test the name |
---|
1400 | if (XMLString::compareString(tempStr, renameTest->getNamespaceURI())) |
---|
1401 | { |
---|
1402 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1403 | OK = false; |
---|
1404 | } |
---|
1405 | if (XMLString::compareString(tempStr2, renameTest->getLocalName())) |
---|
1406 | { |
---|
1407 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1408 | OK = false; |
---|
1409 | } |
---|
1410 | if (XMLString::compareString(tempStr3, renameTest->getNodeName())) |
---|
1411 | { |
---|
1412 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1413 | OK = false; |
---|
1414 | } |
---|
1415 | // test the child / nodevalue |
---|
1416 | if (XMLString::compareString(tempStr5, renameTest->getNodeValue())) |
---|
1417 | { |
---|
1418 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1419 | OK = false; |
---|
1420 | } |
---|
1421 | if (XMLString::compareString(tempStr5, renameTest->getFirstChild()->getNodeValue())) |
---|
1422 | { |
---|
1423 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1424 | OK = false; |
---|
1425 | } |
---|
1426 | if (renameTestAttribute->getFirstChild()) |
---|
1427 | { |
---|
1428 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1429 | OK = false; |
---|
1430 | } |
---|
1431 | // test the owner element |
---|
1432 | if (!renameTestElement->getAttributeNodeNS(tempStr, tempStr2)) { |
---|
1433 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1434 | OK = false; |
---|
1435 | } |
---|
1436 | if (renameTestElement->getAttributeNodeNS(0, tempStr2)) { |
---|
1437 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1438 | OK = false; |
---|
1439 | } |
---|
1440 | if (renameTestElement->getAttributeNode(tempStr2)) { |
---|
1441 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1442 | OK = false; |
---|
1443 | } |
---|
1444 | // test user data |
---|
1445 | renamedocument = renameTest->getUserData(tempStr5); |
---|
1446 | if (document != renamedocument) { |
---|
1447 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1448 | OK = false; |
---|
1449 | } |
---|
1450 | // test userdatahandler |
---|
1451 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_RENAMED, tempStr5, document, renameTestAttribute, renameTest, __LINE__); |
---|
1452 | // test isSame and isEqual |
---|
1453 | // a new node is created here, so both isSame and isEqual are not compared |
---|
1454 | if (renameTestAttribute->isEqualNode(renameTest)) { |
---|
1455 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1456 | OK = false; |
---|
1457 | } |
---|
1458 | if (renameTestAttribute->isSameNode(renameTest)) { |
---|
1459 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
1460 | OK = false; |
---|
1461 | } |
---|
1462 | |
---|
1463 | |
---|
1464 | |
---|
1465 | //isID tests |
---|
1466 | |
---|
1467 | XMLString::transcode("http://nsa", tempStr4, 3999); |
---|
1468 | XMLString::transcode("aa", tempStr5, 3999); |
---|
1469 | |
---|
1470 | DOMAttr *idAtt = document->createAttributeNS(tempStr4, tempStr5); |
---|
1471 | testElementNode->setAttributeNode(idAtt); |
---|
1472 | |
---|
1473 | |
---|
1474 | if(idAtt->isId()) { |
---|
1475 | fprintf(stderr, "isID failed in line %i\n", __LINE__); |
---|
1476 | OK = false; |
---|
1477 | } |
---|
1478 | |
---|
1479 | testElementNode->setIdAttributeNode(idAtt,true); |
---|
1480 | |
---|
1481 | if(!idAtt->isId()) { |
---|
1482 | fprintf(stderr, "isID failed in line %i\n", __LINE__); |
---|
1483 | OK = false; |
---|
1484 | } |
---|
1485 | |
---|
1486 | testElementNode->setIdAttributeNode(idAtt,false); |
---|
1487 | |
---|
1488 | if(idAtt->isId()) { |
---|
1489 | fprintf(stderr, "isID failed in line %i\n", __LINE__); |
---|
1490 | OK = false; |
---|
1491 | } |
---|
1492 | //clean up |
---|
1493 | testElementNode->removeAttributeNode(idAtt); |
---|
1494 | |
---|
1495 | if (! OK) |
---|
1496 | printf("\n*****The DOMAttr* method calls listed above failed, all others worked correctly.*****\n"); |
---|
1497 | return OK; |
---|
1498 | |
---|
1499 | } |
---|
1500 | |
---|
1501 | |
---|
1502 | |
---|
1503 | |
---|
1504 | /** |
---|
1505 | * This method tests DOMCDATASection* methods for the XML DOM implementation |
---|
1506 | * @param document org.w3c.dom.DOMDocument |
---|
1507 | * |
---|
1508 | */ |
---|
1509 | bool DOMTest::testCDATASection(DOMDocument* document) |
---|
1510 | { |
---|
1511 | DOMNode* node; |
---|
1512 | DOMNode* node2; |
---|
1513 | bool T = true; |
---|
1514 | bool OK = true; |
---|
1515 | // For debugging***** printf("\n testCDATASection's outputs:\n"); |
---|
1516 | XMLString::transcode("dBodyLevel23", tempStr, 3999); |
---|
1517 | node = document->getDocumentElement()->getElementsByTagName(tempStr)->item(0)->getFirstChild(); // node gets DOMCDATASection* node |
---|
1518 | |
---|
1519 | node2 = node->cloneNode(T);//*****? |
---|
1520 | |
---|
1521 | // Check nodes for equality, both their name and value or lack thereof |
---|
1522 | if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality |
---|
1523 | (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
1524 | ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
1525 | : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
1526 | { |
---|
1527 | fprintf(stderr, "'cloneNode' did not clone the DOMCDATASection* node correctly\n"); |
---|
1528 | OK = false; |
---|
1529 | } |
---|
1530 | // Deep clone test comparison is in testNode & testDocument |
---|
1531 | |
---|
1532 | |
---|
1533 | // Test the user data |
---|
1534 | // Test simple set and get |
---|
1535 | DOMCDATASection* userTest = (DOMCDATASection*) node; |
---|
1536 | DOMCDATASection* userFirst = (DOMCDATASection*) node2; |
---|
1537 | XMLCh* userSecond = tempStr2; |
---|
1538 | XMLString::transcode("first", tempStr, 3999); |
---|
1539 | |
---|
1540 | XMLString::transcode("document", tempStr2, 3999); |
---|
1541 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
1542 | void* mydocument = userTest->getUserData(tempStr2); |
---|
1543 | if (document != mydocument) { |
---|
1544 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
1545 | OK = false; |
---|
1546 | } |
---|
1547 | |
---|
1548 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
1549 | void* myFirst = userTest->getUserData(tempStr); |
---|
1550 | if (userFirst != myFirst) { |
---|
1551 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
1552 | OK = false; |
---|
1553 | } |
---|
1554 | |
---|
1555 | // Test overwrite |
---|
1556 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
1557 | void* mySecond = userTest->getUserData(tempStr); |
---|
1558 | if (userSecond != mySecond) { |
---|
1559 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1560 | OK = false; |
---|
1561 | } |
---|
1562 | if (userFirst != myFirst2) { |
---|
1563 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1564 | OK = false; |
---|
1565 | } |
---|
1566 | if (userFirst == mySecond) { |
---|
1567 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1568 | OK = false; |
---|
1569 | } |
---|
1570 | |
---|
1571 | // Test null |
---|
1572 | // test non-exist key |
---|
1573 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
1574 | if (userTest->getUserData(tempStr3)) { |
---|
1575 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1576 | OK = false; |
---|
1577 | } |
---|
1578 | |
---|
1579 | // use a node that does not have user data set before |
---|
1580 | if (userFirst->getUserData(tempStr)) { |
---|
1581 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1582 | OK = false; |
---|
1583 | } |
---|
1584 | |
---|
1585 | // Test reset |
---|
1586 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
1587 | void* myNull = userTest->getUserData(tempStr); |
---|
1588 | if (userSecond != mySecond2) { |
---|
1589 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1590 | OK = false; |
---|
1591 | } |
---|
1592 | if (myNull) { |
---|
1593 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1594 | OK = false; |
---|
1595 | } |
---|
1596 | |
---|
1597 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
1598 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
1599 | if (mydocument != mydocument2) { |
---|
1600 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1601 | OK = false; |
---|
1602 | } |
---|
1603 | if (myNull2) { |
---|
1604 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1605 | OK = false; |
---|
1606 | } |
---|
1607 | |
---|
1608 | //the userTest user data table should be null now |
---|
1609 | if (userTest->getUserData(tempStr)) { |
---|
1610 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1611 | OK = false; |
---|
1612 | } |
---|
1613 | if (userTest->getUserData(tempStr2)) { |
---|
1614 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1615 | OK = false; |
---|
1616 | } |
---|
1617 | |
---|
1618 | // Test DOMUserDataHandler |
---|
1619 | // test clone |
---|
1620 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
1621 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
1622 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
1623 | |
---|
1624 | // test import |
---|
1625 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
1626 | DOMNode* myimport = document->importNode(userTest,true); |
---|
1627 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
1628 | |
---|
1629 | // test delete |
---|
1630 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
1631 | myimport->release(); |
---|
1632 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
1633 | |
---|
1634 | // Test isSameNode |
---|
1635 | if (!userTest->isSameNode(userTest)) { |
---|
1636 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
1637 | OK = false; |
---|
1638 | } |
---|
1639 | if (userTest->isSameNode(userFirst)) { |
---|
1640 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
1641 | OK = false; |
---|
1642 | } |
---|
1643 | |
---|
1644 | // Test isEqualNode |
---|
1645 | if (!userTest->isEqualNode(mycloned)) { |
---|
1646 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1647 | OK = false; |
---|
1648 | } |
---|
1649 | |
---|
1650 | if (!userTest->isEqualNode(userTest)) { |
---|
1651 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1652 | OK = false; |
---|
1653 | } |
---|
1654 | if (userTest->isEqualNode(document)) { |
---|
1655 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1656 | OK = false; |
---|
1657 | } |
---|
1658 | |
---|
1659 | // Test rename, should throw exception |
---|
1660 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 204 ); |
---|
1661 | |
---|
1662 | if (! OK) |
---|
1663 | printf("\n*****The DOMCDATASection* method calls listed above failed, all others worked correctly.*****\n"); |
---|
1664 | return OK; |
---|
1665 | } |
---|
1666 | |
---|
1667 | |
---|
1668 | |
---|
1669 | /** |
---|
1670 | * This method tests DOMCharacterData methods for the XML DOM implementation |
---|
1671 | * @param document org.w3c.dom.DOMDocument |
---|
1672 | * |
---|
1673 | */ |
---|
1674 | bool DOMTest::testCharacterData(DOMDocument* document) |
---|
1675 | { |
---|
1676 | DOMCharacterData* charData; |
---|
1677 | XMLCh resetData[3999]; |
---|
1678 | bool OK = true; |
---|
1679 | // For debugging***** printf("\n testCharacterData's outputs:\n"); |
---|
1680 | XMLString::transcode("dBodyLevel31", tempStr, 3999); |
---|
1681 | DOMNode* abc1 = document->getDocumentElement()->getElementsByTagName(tempStr)->item(0)->getFirstChild(); // charData gets textNode11 |
---|
1682 | |
---|
1683 | charData = (DOMCharacterData *) abc1; |
---|
1684 | |
---|
1685 | XMLString::transcode("dBodyLevel31'sChildTextNode11", tempStr, 3999); |
---|
1686 | if (XMLString::compareString(tempStr, charData->getData())) |
---|
1687 | { |
---|
1688 | fprintf(stderr, "Warning!!! DOMCharacterData's 'getData' failed to work properly!\n This may corrupt other DOMCharacterData tests!!!*****\n"); |
---|
1689 | OK = false; |
---|
1690 | } |
---|
1691 | |
---|
1692 | XMLString::copyString(resetData,charData->getData()); |
---|
1693 | // printf("This node's original data is: " + charData->getData()); |
---|
1694 | |
---|
1695 | XMLString::transcode(" This is new data for this node", tempStr2, 3999); |
---|
1696 | |
---|
1697 | XMLString::copyString(tempStr, charData->getData()); |
---|
1698 | XMLString::catString(tempStr, tempStr2); |
---|
1699 | |
---|
1700 | charData->appendData(tempStr2); |
---|
1701 | |
---|
1702 | |
---|
1703 | if (XMLString::compareString(tempStr, charData->getData())) |
---|
1704 | { |
---|
1705 | fprintf(stderr, "Warning!!! DOMCharacterData's 'appendData' failed to work properly!\n"); |
---|
1706 | OK = false; |
---|
1707 | } |
---|
1708 | // printf("This node's appended data is: " + charData->getData()); |
---|
1709 | |
---|
1710 | XMLString::transcode("dBodyLevel", tempStr, 3999); |
---|
1711 | charData->deleteData(10, 100); |
---|
1712 | if (XMLString::compareString(tempStr, charData->getData())) |
---|
1713 | { |
---|
1714 | fprintf(stderr, "Warning!!! DOMCharacterData's 'deleteData' failed to work properly!\n"); |
---|
1715 | OK = false; |
---|
1716 | } |
---|
1717 | // printf("This node's partially deleted data is: " + charData->getData()); |
---|
1718 | |
---|
1719 | XMLSize_t length = 10; |
---|
1720 | if (!(length == charData->getLength())) |
---|
1721 | { |
---|
1722 | fprintf(stderr, "Warning!!! DOMCharacterData's 'getLength' failed to work properly!\n"); |
---|
1723 | OK = false; |
---|
1724 | } |
---|
1725 | // printf("This node's data length is: " + charData->getLength()); |
---|
1726 | |
---|
1727 | XMLString::transcode("dBody' This is data inserted into this node'Level", tempStr, 3999); |
---|
1728 | XMLString::transcode("' This is data inserted into this node'", tempStr2, 3999); |
---|
1729 | charData->insertData(5, tempStr2); |
---|
1730 | if (XMLString::compareString(tempStr, charData->getData())) |
---|
1731 | { |
---|
1732 | fprintf(stderr, "Warning!!! DOMCharacterData's 'insertData' failed to work properly!\n"); |
---|
1733 | OK = false; |
---|
1734 | } |
---|
1735 | // printf("This node's updated with insert data is: " + charData->getData()); |
---|
1736 | |
---|
1737 | XMLString::transcode("dBody' This is ' replacement data'ted into this node'Level", tempStr, 3999); |
---|
1738 | XMLString::transcode("' replacement data'", tempStr2, 3999); |
---|
1739 | charData->replaceData(15, 10, tempStr2); |
---|
1740 | if (XMLString::compareString(tempStr, charData->getData())) |
---|
1741 | { |
---|
1742 | fprintf(stderr, "Warning!!! DOMCharacterData's 'replaceData' failed to work properly!\n"); |
---|
1743 | OK = false; |
---|
1744 | } |
---|
1745 | // printf("This node's updated with replacement data is: " +charData->getData()); |
---|
1746 | |
---|
1747 | XMLString::transcode("New data A123456789B123456789C123456789D123456789E123456789", tempStr, 3999); |
---|
1748 | charData->setData(tempStr); |
---|
1749 | if (XMLString::compareString(tempStr, charData->getData())) |
---|
1750 | { |
---|
1751 | fprintf(stderr, "Warning!!! DOMCharacterData's 'setData' failed to work properly!"); |
---|
1752 | OK = false; |
---|
1753 | } |
---|
1754 | // printf("This node's new data via setData: " + charData->getData()); |
---|
1755 | |
---|
1756 | XMLString::transcode("123456789D123456789E123456789", tempStr, 3999); |
---|
1757 | if (XMLString::compareString(tempStr, charData->substringData(30, 30))) |
---|
1758 | { |
---|
1759 | fprintf(stderr, "Warning!!! DOMCharacterData's 'substringData' failed to work properly!\n"); |
---|
1760 | OK = false; |
---|
1761 | } |
---|
1762 | // printf("Using subString 30,30 you get:"); charData->substringData(30,30)).print(); |
---|
1763 | |
---|
1764 | XMLString::transcode("New data A123456789B12345", tempStr, 3999); |
---|
1765 | if (XMLString::compareString(tempStr, charData->substringData(0, 25))) |
---|
1766 | { |
---|
1767 | fprintf(stderr, "Warning!!! DOMCharacterData's 'substringData' failed to work properly!\n"); |
---|
1768 | OK = false; |
---|
1769 | } |
---|
1770 | // printf("Using subString 0,25 you get: "); charData->substringData(0,25)).print(); |
---|
1771 | |
---|
1772 | //************************************************* ERROR TESTS |
---|
1773 | DOMTest tests; // What is this for? 'tests' is never used. |
---|
1774 | |
---|
1775 | //!! Throws INDEX_SIZE_ERR ******************** |
---|
1776 | EXCEPTIONSTEST(charData->deleteData((XMLSize_t)-1, 5), DOMException::INDEX_SIZE_ERR, OK, 101 ); |
---|
1777 | // Test 102 is not an error because the -1 parameter is an unsigned value, and counts |
---|
1778 | // that exceed the length of the string are allowed. |
---|
1779 | // EXCEPTIONSTEST(charData->deleteData(2, -1), DOMException::INDEX_SIZE_ERR, OK, 102 ); |
---|
1780 | EXCEPTIONSTEST(charData->deleteData(100, 5), DOMException::INDEX_SIZE_ERR, OK,103 ); |
---|
1781 | |
---|
1782 | //can't set negative XMLSize_t in c++ compiler |
---|
1783 | |
---|
1784 | // EXCEPTIONSTEST(charData->insertData(-1, "Stuff inserted"), DOMException::INDEX_SIZE_ERR, OK, 104 ); |
---|
1785 | XMLString::transcode("Stuff inserted", tempStr, 3999); |
---|
1786 | EXCEPTIONSTEST(charData->insertData(100, tempStr), DOMException::INDEX_SIZE_ERR, OK, 105 ); |
---|
1787 | |
---|
1788 | // EXCEPTIONSTEST(charData->replaceData(-1, 5, "Replacement stuff") , DOMException::INDEX_SIZE_ERR, OK, 106 ); |
---|
1789 | XMLString::transcode("Replacement stuff", tempStr, 3999); |
---|
1790 | EXCEPTIONSTEST(charData->replaceData(100, 5 ,tempStr), DOMException::INDEX_SIZE_ERR, OK, 107 ); |
---|
1791 | // EXCEPTIONSTEST(charData->replaceData(2, -1, "Replacement stuff"), DOMException::INDEX_SIZE_ERR, OK, 108 ); |
---|
1792 | |
---|
1793 | EXCEPTIONSTEST(charData->substringData((XMLSize_t)-1, 5), DOMException::INDEX_SIZE_ERR, OK, 109 ); |
---|
1794 | EXCEPTIONSTEST(charData->substringData(100, 5), DOMException::INDEX_SIZE_ERR, OK, 110 ); |
---|
1795 | // EXCEPTIONSTEST(charData->substringData(2, -1), DOMException::INDEX_SIZE_ERR, OK, 111 ); |
---|
1796 | |
---|
1797 | |
---|
1798 | // Test the user data |
---|
1799 | // Test simple set and get |
---|
1800 | DOMCharacterData* userTest = charData; |
---|
1801 | DOMDocument* userFirst = document; |
---|
1802 | XMLCh* userSecond = tempStr2; |
---|
1803 | XMLString::transcode("first", tempStr, 3999); |
---|
1804 | |
---|
1805 | XMLString::transcode("document", tempStr2, 3999); |
---|
1806 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
1807 | void* mydocument = userTest->getUserData(tempStr2); |
---|
1808 | if (document != mydocument) { |
---|
1809 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
1810 | OK = false; |
---|
1811 | } |
---|
1812 | |
---|
1813 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
1814 | void* myFirst = userTest->getUserData(tempStr); |
---|
1815 | if (userFirst != myFirst) { |
---|
1816 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
1817 | OK = false; |
---|
1818 | } |
---|
1819 | |
---|
1820 | // Test overwrite |
---|
1821 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
1822 | void* mySecond = userTest->getUserData(tempStr); |
---|
1823 | if (userSecond != mySecond) { |
---|
1824 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1825 | OK = false; |
---|
1826 | } |
---|
1827 | if (userFirst != myFirst2) { |
---|
1828 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1829 | OK = false; |
---|
1830 | } |
---|
1831 | if (userFirst == mySecond) { |
---|
1832 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1833 | OK = false; |
---|
1834 | } |
---|
1835 | |
---|
1836 | // Test null |
---|
1837 | // test non-exist key |
---|
1838 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
1839 | if (userTest->getUserData(tempStr3)) { |
---|
1840 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1841 | OK = false; |
---|
1842 | } |
---|
1843 | |
---|
1844 | // use a node that does not have user data set before |
---|
1845 | if (userFirst->getUserData(tempStr)) { |
---|
1846 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1847 | OK = false; |
---|
1848 | } |
---|
1849 | |
---|
1850 | // Test reset |
---|
1851 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
1852 | void* myNull = userTest->getUserData(tempStr); |
---|
1853 | if (userSecond != mySecond2) { |
---|
1854 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1855 | OK = false; |
---|
1856 | } |
---|
1857 | if (myNull) { |
---|
1858 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1859 | OK = false; |
---|
1860 | } |
---|
1861 | |
---|
1862 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
1863 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
1864 | if (mydocument != mydocument2) { |
---|
1865 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1866 | OK = false; |
---|
1867 | } |
---|
1868 | if (myNull2) { |
---|
1869 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
1870 | OK = false; |
---|
1871 | } |
---|
1872 | |
---|
1873 | //the userTest user data table should be null now |
---|
1874 | if (userTest->getUserData(tempStr)) { |
---|
1875 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1876 | OK = false; |
---|
1877 | } |
---|
1878 | if (userTest->getUserData(tempStr2)) { |
---|
1879 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
1880 | OK = false; |
---|
1881 | } |
---|
1882 | |
---|
1883 | // Test DOMUserDataHandler |
---|
1884 | // test clone |
---|
1885 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
1886 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
1887 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
1888 | |
---|
1889 | // test import |
---|
1890 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
1891 | DOMNode* myimport = document->importNode(userTest,true); |
---|
1892 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
1893 | |
---|
1894 | // test delete |
---|
1895 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
1896 | myimport->release(); |
---|
1897 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
1898 | |
---|
1899 | // Test isSameNode |
---|
1900 | if (!userTest->isSameNode(userTest)) { |
---|
1901 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
1902 | OK = false; |
---|
1903 | } |
---|
1904 | if (userTest->isSameNode(userFirst)) { |
---|
1905 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
1906 | OK = false; |
---|
1907 | } |
---|
1908 | |
---|
1909 | // Test isEqualNode |
---|
1910 | if (!userTest->isEqualNode(mycloned)) { |
---|
1911 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1912 | OK = false; |
---|
1913 | } |
---|
1914 | |
---|
1915 | if (!userTest->isEqualNode(userTest)) { |
---|
1916 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1917 | OK = false; |
---|
1918 | } |
---|
1919 | if (userTest->isEqualNode(userFirst)) { |
---|
1920 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
1921 | OK = false; |
---|
1922 | } |
---|
1923 | |
---|
1924 | // Test rename, should throw exception |
---|
1925 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 205 ); |
---|
1926 | |
---|
1927 | if (!OK) |
---|
1928 | printf("\n*****The DOMCharacterData method calls listed above failed, all others worked correctly.*****\n"); |
---|
1929 | charData->setData(resetData); // reset node to original data |
---|
1930 | return OK; |
---|
1931 | } |
---|
1932 | |
---|
1933 | |
---|
1934 | |
---|
1935 | |
---|
1936 | /** |
---|
1937 | * This method tests ChildNodeList methods for the XML DOM implementation |
---|
1938 | * @param document org.w3c.dom.DOMDocument |
---|
1939 | * |
---|
1940 | */ |
---|
1941 | bool DOMTest::testChildNodeList(DOMDocument* document) |
---|
1942 | { |
---|
1943 | DOMNode* node; |
---|
1944 | DOMNode* node2; |
---|
1945 | bool OK = true; |
---|
1946 | // For debugging***** printf("\n testChildNodeList's outputs:\n"); |
---|
1947 | node = document->getDocumentElement()->getLastChild(); // node gets doc's testBody element |
---|
1948 | |
---|
1949 | if (!(node->getChildNodes()->getLength()== 4)) |
---|
1950 | OK = false; |
---|
1951 | node2 = node->getChildNodes()->item(2); |
---|
1952 | XMLString::transcode("dBodyLevel23", tempStr, 3999); |
---|
1953 | if (XMLString::compareString(tempStr, node2->getNodeName())) |
---|
1954 | OK = false; |
---|
1955 | |
---|
1956 | if (!OK) |
---|
1957 | printf("\n*****The ChildNodeList method calls listed above failed, all others worked correctly.*****\n"); |
---|
1958 | return OK; |
---|
1959 | } |
---|
1960 | |
---|
1961 | |
---|
1962 | |
---|
1963 | /** |
---|
1964 | * This method tests DOMComment* methods for the XML DOM implementation |
---|
1965 | * @param document org.w3c.dom.DOMDocument |
---|
1966 | * |
---|
1967 | */ |
---|
1968 | bool DOMTest::testComment(DOMDocument* document) |
---|
1969 | { |
---|
1970 | DOMNode* node; |
---|
1971 | DOMNode* node2; |
---|
1972 | bool T = true; |
---|
1973 | bool OK = true; |
---|
1974 | // For debugging***** printf("\n testComment's outputs:\n"); |
---|
1975 | XMLString::transcode("dBodyLevel31", tempStr, 3999); |
---|
1976 | node = document->getDocumentElement()->getElementsByTagName(tempStr)->item(0)->getFirstChild(); // node gets textNode11 |
---|
1977 | node2 = node->cloneNode(T); |
---|
1978 | // Check nodes for equality, both their name and value or lack thereof |
---|
1979 | if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality |
---|
1980 | (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
1981 | ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
1982 | : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
1983 | { |
---|
1984 | fprintf(stderr, "'cloneNode' did not clone the DOMComment* node correctly\n"); |
---|
1985 | OK = false; |
---|
1986 | } |
---|
1987 | // Deep clone test comparison is in testNode & testDocument |
---|
1988 | |
---|
1989 | // Test the user data |
---|
1990 | // Test simple set and get |
---|
1991 | DOMComment* userTest = (DOMComment*) node; |
---|
1992 | DOMComment* userFirst = (DOMComment*) node2; |
---|
1993 | XMLCh* userSecond = tempStr2; |
---|
1994 | XMLString::transcode("first", tempStr, 3999); |
---|
1995 | |
---|
1996 | XMLString::transcode("document", tempStr2, 3999); |
---|
1997 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
1998 | void* mydocument = userTest->getUserData(tempStr2); |
---|
1999 | if (document != mydocument) { |
---|
2000 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
2001 | OK = false; |
---|
2002 | } |
---|
2003 | |
---|
2004 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
2005 | void* myFirst = userTest->getUserData(tempStr); |
---|
2006 | if (userFirst != myFirst) { |
---|
2007 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
2008 | OK = false; |
---|
2009 | } |
---|
2010 | |
---|
2011 | // Test overwrite |
---|
2012 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
2013 | void* mySecond = userTest->getUserData(tempStr); |
---|
2014 | if (userSecond != mySecond) { |
---|
2015 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2016 | OK = false; |
---|
2017 | } |
---|
2018 | if (userFirst != myFirst2) { |
---|
2019 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2020 | OK = false; |
---|
2021 | } |
---|
2022 | if (userFirst == mySecond) { |
---|
2023 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2024 | OK = false; |
---|
2025 | } |
---|
2026 | |
---|
2027 | // Test null |
---|
2028 | // test non-exist key |
---|
2029 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
2030 | if (userTest->getUserData(tempStr3)) { |
---|
2031 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2032 | OK = false; |
---|
2033 | } |
---|
2034 | |
---|
2035 | // use a node that does not have user data set before |
---|
2036 | if (userFirst->getUserData(tempStr)) { |
---|
2037 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2038 | OK = false; |
---|
2039 | } |
---|
2040 | |
---|
2041 | // Test reset |
---|
2042 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
2043 | void* myNull = userTest->getUserData(tempStr); |
---|
2044 | if (userSecond != mySecond2) { |
---|
2045 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2046 | OK = false; |
---|
2047 | } |
---|
2048 | if (myNull) { |
---|
2049 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2050 | OK = false; |
---|
2051 | } |
---|
2052 | |
---|
2053 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
2054 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
2055 | if (mydocument != mydocument2) { |
---|
2056 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2057 | OK = false; |
---|
2058 | } |
---|
2059 | if (myNull2) { |
---|
2060 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2061 | OK = false; |
---|
2062 | } |
---|
2063 | |
---|
2064 | //the userTest user data table should be null now |
---|
2065 | if (userTest->getUserData(tempStr)) { |
---|
2066 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2067 | OK = false; |
---|
2068 | } |
---|
2069 | if (userTest->getUserData(tempStr2)) { |
---|
2070 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2071 | OK = false; |
---|
2072 | } |
---|
2073 | |
---|
2074 | // Test DOMUserDataHandler |
---|
2075 | // test clone |
---|
2076 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
2077 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
2078 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
2079 | |
---|
2080 | // test import |
---|
2081 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
2082 | DOMNode* myimport = document->importNode(userTest,true); |
---|
2083 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
2084 | |
---|
2085 | // test delete |
---|
2086 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
2087 | myimport->release(); |
---|
2088 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
2089 | |
---|
2090 | // Test isSameNode |
---|
2091 | if (!userTest->isSameNode(userTest)) { |
---|
2092 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
2093 | OK = false; |
---|
2094 | } |
---|
2095 | if (userTest->isSameNode(userFirst)) { |
---|
2096 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
2097 | OK = false; |
---|
2098 | } |
---|
2099 | |
---|
2100 | // Test isEqualNode |
---|
2101 | if (!userTest->isEqualNode(mycloned)) { |
---|
2102 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2103 | OK = false; |
---|
2104 | } |
---|
2105 | |
---|
2106 | if (!userTest->isEqualNode(userTest)) { |
---|
2107 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2108 | OK = false; |
---|
2109 | } |
---|
2110 | if (userTest->isEqualNode(document)) { |
---|
2111 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2112 | OK = false; |
---|
2113 | } |
---|
2114 | |
---|
2115 | // Test rename, should throw exception |
---|
2116 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 206 ); |
---|
2117 | |
---|
2118 | if (!OK) |
---|
2119 | printf("\n*****The DOMComment* method calls listed above failed, all others worked correctly.*****\n"); |
---|
2120 | return OK; |
---|
2121 | } |
---|
2122 | |
---|
2123 | |
---|
2124 | |
---|
2125 | /** |
---|
2126 | * This method tests DeepNodeList methods for the XML DOM implementation |
---|
2127 | * @param document org.w3c.dom.DOMDocument |
---|
2128 | * |
---|
2129 | */ |
---|
2130 | bool DOMTest::testDeepNodeList(DOMDocument* document) |
---|
2131 | { |
---|
2132 | DOMNode* node; |
---|
2133 | DOMNode* node2; |
---|
2134 | bool OK = true; |
---|
2135 | // For debugging***** printf("\n testDeepNodeList's outputs:\n\n"); |
---|
2136 | node = document->getLastChild()->getLastChild(); // node gets docBody element |
---|
2137 | // DOMElement* el = (DOMElement*)node; |
---|
2138 | // DOMNodeList nl = el->getElementsByTagName("*"); |
---|
2139 | // int len = nl->getLength(); |
---|
2140 | // if (len != 8) |
---|
2141 | XMLString::transcode("*",tempStr, 3999); |
---|
2142 | if (!(8 == ((DOMElement*) node)->getElementsByTagName(tempStr)->getLength())) |
---|
2143 | { |
---|
2144 | printf ("Warning!!! DeepNodeList's 'getLength' failed to work properly!\n"); |
---|
2145 | OK = false; |
---|
2146 | } |
---|
2147 | node2 = ((DOMElement*) node)->getElementsByTagName(tempStr)->item(2); //This also runs through 'nextMatchingElementAfter" |
---|
2148 | |
---|
2149 | XMLString::transcode("dBodyLevel32", tempStr, 3999); |
---|
2150 | if (XMLString::compareString(tempStr, node2->getNodeName())) |
---|
2151 | { |
---|
2152 | printf ("Warning!!! DeepNodeList's 'item' (or DOMElement's 'getElementsBy TagName)failed to work properly!\n"); |
---|
2153 | OK = false; |
---|
2154 | } |
---|
2155 | node2 = document->getLastChild(); |
---|
2156 | XMLString::transcode("dTestBody", tempStr, 3999); |
---|
2157 | if (XMLString::compareString(tempStr, ((DOMElement*) node2)->getElementsByTagName(tempStr)->item(0)->getNodeName()))//This also runs through 'nextMatchingElementAfter" |
---|
2158 | { |
---|
2159 | printf ("Warning!!! DeepNodeList's 'item' (or DOMElement's 'getElementsBy TagName)failed to work properly!\n"); |
---|
2160 | OK = false; |
---|
2161 | } |
---|
2162 | |
---|
2163 | if (!OK) |
---|
2164 | printf("\n*****The DeepNodeList method calls listed above failed, all others worked correctly.*****\n"); |
---|
2165 | return OK; |
---|
2166 | } |
---|
2167 | |
---|
2168 | |
---|
2169 | |
---|
2170 | /** |
---|
2171 | * This method tests DOMDocument* methods for the XML DOM implementation |
---|
2172 | * @param document org.w3c.dom.DOMDocument |
---|
2173 | * |
---|
2174 | * |
---|
2175 | **** ALL DOMDocument* create methods are run in docBuilder except createAttribute which is in testAttribute** |
---|
2176 | */ |
---|
2177 | bool DOMTest::testDocument(DOMDocument* document) |
---|
2178 | { |
---|
2179 | DOMTest make; |
---|
2180 | DOMDocumentFragment* docFragment, *docFragment2; |
---|
2181 | DOMElement* newElement; |
---|
2182 | DOMNode* node, *node2; |
---|
2183 | |
---|
2184 | const char* elementNames[] = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32", |
---|
2185 | "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"}; |
---|
2186 | const char* newElementNames[] = {"dFirstElement", "dTestBody", "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23"}; |
---|
2187 | |
---|
2188 | |
---|
2189 | bool result; |
---|
2190 | bool OK = true; |
---|
2191 | // For debugging***** printf("\n testDocument's outputs:\n \n"); |
---|
2192 | |
---|
2193 | XMLString::transcode("testDocument1", tempStr, 3999); |
---|
2194 | DOMDocumentType* checkDocType = make.createDocumentType(document,tempStr); |
---|
2195 | DOMDocumentType* docType = document->getDoctype(); |
---|
2196 | |
---|
2197 | if (XMLString::compareString(checkDocType->getNodeName(),docType->getNodeName() )) |
---|
2198 | { |
---|
2199 | fprintf(stderr, "Warning!!! DOMDocument's 'getDocType method failed!\n" ); |
---|
2200 | OK = false; |
---|
2201 | } |
---|
2202 | |
---|
2203 | if (XMLString::compareString(checkDocType->getNodeValue(), docType->getNodeValue())) |
---|
2204 | { |
---|
2205 | fprintf(stderr, "Warning!!! DOMDocument's 'getDocType method failed!\n" ); |
---|
2206 | OK = false; |
---|
2207 | } |
---|
2208 | |
---|
2209 | /* |
---|
2210 | if (! (checkDocType->getNodeName(), docType->getNodeName()) && // Compares node names for equality |
---|
2211 | (checkDocType->getNodeValue() != 0 && docType->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
2212 | ? checkDocType->getNodeValue(), docType->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
2213 | : (checkDocType->getNodeValue() == 0 && docType->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
2214 | { |
---|
2215 | fprintf(stderr, "Warning!!! DOMDocument's 'getDocType method failed!\n" ); |
---|
2216 | OK = false; |
---|
2217 | } |
---|
2218 | */ |
---|
2219 | |
---|
2220 | DOMNode* rootElement = document->getLastChild(); |
---|
2221 | |
---|
2222 | bool check = (rootElement->getNodeValue() && document->getDocumentElement()->getNodeValue()) // Checks to make sure each node has a value node |
---|
2223 | ? !XMLString::compareString(rootElement->getNodeValue(), document->getDocumentElement()->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
2224 | : (rootElement->getNodeValue() == 0 && document->getDocumentElement()->getNodeValue() == 0); // If one node doesn't have a value node make sure both don't |
---|
2225 | if (!(!XMLString::compareString(rootElement->getNodeName(), document->getDocumentElement()->getNodeName()) && // Compares node names for equality |
---|
2226 | check)) |
---|
2227 | { |
---|
2228 | fprintf(stderr, "Warning!!! DOMDocument's 'getDocumentElement' method failed!\n" ); |
---|
2229 | OK = false; |
---|
2230 | } |
---|
2231 | |
---|
2232 | XMLString::transcode("*", tempStr, 3999); |
---|
2233 | DOMNodeList* docElements = document->getElementsByTagName(tempStr); |
---|
2234 | XMLSize_t docSize = docElements->getLength(); |
---|
2235 | XMLSize_t i; |
---|
2236 | for (i = 0; i < docSize; i++) |
---|
2237 | { |
---|
2238 | DOMNode* n = (DOMNode*) docElements->item(i); |
---|
2239 | XMLString::transcode(elementNames[i], tempStr, 3999); |
---|
2240 | if (XMLString::compareString(tempStr, n->getNodeName())) |
---|
2241 | { |
---|
2242 | fprintf(stderr, "Comparison of this document's elements failed at element number %d at line %i \n", i, __LINE__); |
---|
2243 | OK = false; |
---|
2244 | break; |
---|
2245 | } |
---|
2246 | } |
---|
2247 | |
---|
2248 | // What is this supposed to be doing? |
---|
2249 | // |
---|
2250 | //if (document->equals(document->getImplementation())) |
---|
2251 | //{ |
---|
2252 | // fprintf(stderr, "Warning!!! DOMDocument's 'getImplementation' method failed!\n" ); |
---|
2253 | // OK = false; |
---|
2254 | //} |
---|
2255 | |
---|
2256 | XMLString::transcode("NewElementTestsInsertBefore", tempStr, 3999); |
---|
2257 | newElement = document->createElement(tempStr); |
---|
2258 | // doc->insertBefore(newElement,0);//!! Throws a HIERARCHY_REQUEST_ERR ******* |
---|
2259 | // doc->removeChild(docElements->item(9));//!! Throws a NOT_FOUND_ERR ******** |
---|
2260 | |
---|
2261 | docFragment = document->createDocumentFragment(); |
---|
2262 | //Tests removeChild and stores removed branch for tree reconstruction |
---|
2263 | docFragment->appendChild(docElements->item(1)->removeChild(docElements->item(9))); |
---|
2264 | docFragment2 = document->createDocumentFragment(); |
---|
2265 | //Tests removeChild and stores removed branch for tree reconstruction |
---|
2266 | docFragment2->appendChild(docElements->item(1)->removeChild(docElements->item(2))); |
---|
2267 | docSize = docElements->getLength(); |
---|
2268 | for (i = 0; i < docSize; i++) |
---|
2269 | { |
---|
2270 | DOMNode* n = (DOMNode*) docElements->item(i); |
---|
2271 | XMLString::transcode(newElementNames[i], tempStr, 3999); |
---|
2272 | if (XMLString::compareString(tempStr, n->getNodeName())) |
---|
2273 | { |
---|
2274 | fprintf(stderr, "Comparison of new document's elements failed at element number %d at line %i \n", i, __LINE__); |
---|
2275 | OK = false; |
---|
2276 | break; |
---|
2277 | } |
---|
2278 | } |
---|
2279 | docElements->item(1)->insertBefore(docFragment, 0); //Reattaches removed branch to restore tree to the original |
---|
2280 | // AH Revist. Note: insertBefore should be able to take |
---|
2281 | // a 0 as its second parameter. |
---|
2282 | docElements->item(1)->insertBefore(docFragment2, docElements->item(2)); //Reattaches removed branch to restore tree to the original |
---|
2283 | |
---|
2284 | // printf(docElements->item(2)->getNodeName()); |
---|
2285 | |
---|
2286 | docSize = docElements->getLength(); |
---|
2287 | for (i = 0; i < docSize; i++) |
---|
2288 | { |
---|
2289 | DOMNode* n = (DOMNode*) docElements->item(i); |
---|
2290 | XMLString::transcode(elementNames[i], tempStr, 3999); |
---|
2291 | if (XMLString::compareString(tempStr, n->getNodeName())) |
---|
2292 | { |
---|
2293 | fprintf(stderr, "Comparison of restored document's elements failed at element number %d at line %i \n", i, __LINE__); |
---|
2294 | OK = false; |
---|
2295 | break; |
---|
2296 | } |
---|
2297 | } |
---|
2298 | |
---|
2299 | DOMTest tests; |
---|
2300 | |
---|
2301 | |
---|
2302 | // DOMDocument* z = tests.createDocument(); |
---|
2303 | // tests.docBuilder(z, "z"); |
---|
2304 | |
---|
2305 | //!! Throws WRONG_DOCUMENT_ERR ********** |
---|
2306 | // EXCEPTIONSTEST(z->appendChild( |
---|
2307 | // z->appendChild(d.createComment("Test doc d comment"));// Tries to append z document with document d comment |
---|
2308 | // d->getDocumentElement()->appendChild(z.createElement("newZdocElement"));// Tries to append d document with document z DOMElement |
---|
2309 | // d->getLastChild()->getLastChild()->insertBefore(z.createElement("newZdocElement"),d->getLastChild()->getLastChild()->getFirstChild());// Tries to insert into d document with document z DOMElement |
---|
2310 | // d->replaceChild(z.createElement("newZdocElement"),d->getLastChild()->getLastChild()->getFirstChild()); // Tries to replace in d document with document z DOMElement |
---|
2311 | |
---|
2312 | // doc->setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** |
---|
2313 | |
---|
2314 | node = document; |
---|
2315 | node2 = document->cloneNode(true); |
---|
2316 | result = treeCompare(node, node2); // Deep clone test comparison of document cloneNode |
---|
2317 | if (!result) |
---|
2318 | { |
---|
2319 | fprintf(stderr, "Warning!!! Deep clone of the document failed!\n"); |
---|
2320 | OK = false; |
---|
2321 | } |
---|
2322 | node2->release(); |
---|
2323 | |
---|
2324 | // Deep clone test comparison is also in testNode |
---|
2325 | |
---|
2326 | // Test the user data |
---|
2327 | // Test simple set and get |
---|
2328 | DOMDocumentFragment* userTest = docFragment; |
---|
2329 | DOMDocumentFragment* userFirst = docFragment2; |
---|
2330 | XMLCh* userSecond = tempStr2; |
---|
2331 | XMLString::transcode("first", tempStr, 3999); |
---|
2332 | |
---|
2333 | XMLString::transcode("document", tempStr2, 3999); |
---|
2334 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
2335 | void* mydocument = userTest->getUserData(tempStr2); |
---|
2336 | if (document != mydocument) { |
---|
2337 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
2338 | OK = false; |
---|
2339 | } |
---|
2340 | |
---|
2341 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
2342 | void* myFirst = userTest->getUserData(tempStr); |
---|
2343 | if (userFirst != myFirst) { |
---|
2344 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
2345 | OK = false; |
---|
2346 | } |
---|
2347 | |
---|
2348 | // Test overwrite |
---|
2349 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
2350 | void* mySecond = userTest->getUserData(tempStr); |
---|
2351 | if (userSecond != mySecond) { |
---|
2352 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2353 | OK = false; |
---|
2354 | } |
---|
2355 | if (userFirst != myFirst2) { |
---|
2356 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2357 | OK = false; |
---|
2358 | } |
---|
2359 | if (userFirst == mySecond) { |
---|
2360 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2361 | OK = false; |
---|
2362 | } |
---|
2363 | |
---|
2364 | // Test null |
---|
2365 | // test non-exist key |
---|
2366 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
2367 | if (userTest->getUserData(tempStr3)) { |
---|
2368 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2369 | OK = false; |
---|
2370 | } |
---|
2371 | |
---|
2372 | // use a node that does not have user data set before |
---|
2373 | if (userFirst->getUserData(tempStr)) { |
---|
2374 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2375 | OK = false; |
---|
2376 | } |
---|
2377 | |
---|
2378 | // Test reset |
---|
2379 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
2380 | void* myNull = userTest->getUserData(tempStr); |
---|
2381 | if (userSecond != mySecond2) { |
---|
2382 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2383 | OK = false; |
---|
2384 | } |
---|
2385 | if (myNull) { |
---|
2386 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2387 | OK = false; |
---|
2388 | } |
---|
2389 | |
---|
2390 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
2391 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
2392 | if (mydocument != mydocument2) { |
---|
2393 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2394 | OK = false; |
---|
2395 | } |
---|
2396 | if (myNull2) { |
---|
2397 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2398 | OK = false; |
---|
2399 | } |
---|
2400 | |
---|
2401 | //the userTest user data table should be null now |
---|
2402 | if (userTest->getUserData(tempStr)) { |
---|
2403 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2404 | OK = false; |
---|
2405 | } |
---|
2406 | if (userTest->getUserData(tempStr2)) { |
---|
2407 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2408 | OK = false; |
---|
2409 | } |
---|
2410 | |
---|
2411 | // Test DOMUserDataHandler |
---|
2412 | // test clone |
---|
2413 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
2414 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
2415 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
2416 | |
---|
2417 | // test import |
---|
2418 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
2419 | DOMNode* myimport = document->importNode(userTest,true); |
---|
2420 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
2421 | |
---|
2422 | // test delete |
---|
2423 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
2424 | myimport->release(); |
---|
2425 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
2426 | |
---|
2427 | // Test isSameNode |
---|
2428 | if (!userTest->isSameNode(userTest)) { |
---|
2429 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
2430 | OK = false; |
---|
2431 | } |
---|
2432 | if (userTest->isSameNode(userFirst)) { |
---|
2433 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
2434 | OK = false; |
---|
2435 | } |
---|
2436 | |
---|
2437 | // Test isEqualNode |
---|
2438 | if (!userTest->isEqualNode(mycloned)) { |
---|
2439 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2440 | OK = false; |
---|
2441 | } |
---|
2442 | |
---|
2443 | if (!userTest->isEqualNode(userTest)) { |
---|
2444 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2445 | OK = false; |
---|
2446 | } |
---|
2447 | if (userTest->isEqualNode(document)) { |
---|
2448 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2449 | OK = false; |
---|
2450 | } |
---|
2451 | |
---|
2452 | // Test rename, should throw exception |
---|
2453 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 207 ); |
---|
2454 | |
---|
2455 | if (!OK) |
---|
2456 | printf("\n*****The DOMDocument* method calls listed above failed, all others worked correctly.*****\n"); |
---|
2457 | return OK; |
---|
2458 | } |
---|
2459 | |
---|
2460 | |
---|
2461 | |
---|
2462 | /** |
---|
2463 | * This method tests DOMDocumentFragment* methods for the XML DOM implementation |
---|
2464 | * @param document org.w3c.dom.DOMDocument |
---|
2465 | * |
---|
2466 | * |
---|
2467 | * |
---|
2468 | ********This really isn't needed, only exists to throw NO_MODIFICATION_ALLOWED_ERR ******** |
---|
2469 | */ |
---|
2470 | bool DOMTest::testDocumentFragment(DOMDocument* document) |
---|
2471 | { |
---|
2472 | bool OK = true; |
---|
2473 | // For debugging***** printf("\n testDocumentFragment's outputs:\n"); |
---|
2474 | DOMDocumentFragment* testDocFragment = document->createDocumentFragment(); |
---|
2475 | |
---|
2476 | // testDocFragment->setNodeValue("This is a document fragment!");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** |
---|
2477 | |
---|
2478 | // Test isSameNode |
---|
2479 | DOMDocumentFragment* userTest = testDocFragment; |
---|
2480 | DOMNode* mycloned = testDocFragment->cloneNode(true); |
---|
2481 | DOMDocument* userFirst = document; |
---|
2482 | |
---|
2483 | if (!userTest->isSameNode(userTest)) { |
---|
2484 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
2485 | OK = false; |
---|
2486 | } |
---|
2487 | if (userTest->isSameNode(userFirst)) { |
---|
2488 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
2489 | OK = false; |
---|
2490 | } |
---|
2491 | |
---|
2492 | // Test isEqualNode |
---|
2493 | if (!userTest->isEqualNode(mycloned)) { |
---|
2494 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2495 | OK = false; |
---|
2496 | } |
---|
2497 | |
---|
2498 | if (!userTest->isEqualNode(userTest)) { |
---|
2499 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2500 | OK = false; |
---|
2501 | } |
---|
2502 | if (userTest->isEqualNode(userFirst)) { |
---|
2503 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2504 | OK = false; |
---|
2505 | } |
---|
2506 | |
---|
2507 | // Test rename, should throw exception |
---|
2508 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 208 ); |
---|
2509 | |
---|
2510 | if (!OK) |
---|
2511 | printf("\n*****The DOMDocumentFragment* method calls listed above failed, all others worked correctly.*****\n"); |
---|
2512 | return OK; |
---|
2513 | } |
---|
2514 | |
---|
2515 | |
---|
2516 | |
---|
2517 | /** |
---|
2518 | * This method tests DOMDocumentType* methods for the XML DOM implementation |
---|
2519 | * @param document org.w3c.dom.DOMDocument |
---|
2520 | * |
---|
2521 | */ |
---|
2522 | bool DOMTest::testDocumentType(DOMDocument* document) |
---|
2523 | { |
---|
2524 | DOMTest test; |
---|
2525 | DOMDocumentType* docType, *holdDocType; |
---|
2526 | DOMNamedNodeMap* docNotationMap; |
---|
2527 | DOMNode* node, *node2; |
---|
2528 | bool OK = true; |
---|
2529 | // For debugging***** printf("\n testDocumentType's outputs:\n"); |
---|
2530 | XMLString::transcode("TestDocument", tempStr, 3999); |
---|
2531 | DOMDocumentType* newDocumentType = test.createDocumentType(document, tempStr); |
---|
2532 | node = document->getFirstChild(); // node gets doc's docType node |
---|
2533 | node2 = node->cloneNode(true); |
---|
2534 | // Check nodes for equality, both their name and value or lack thereof |
---|
2535 | if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality |
---|
2536 | (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
2537 | ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
2538 | : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
2539 | { |
---|
2540 | fprintf(stderr, "'cloneNode' did not clone the DOMDocumentType* node correctly\n"); |
---|
2541 | OK = false; |
---|
2542 | } |
---|
2543 | // Deep clone test comparison is in testNode & testDocument |
---|
2544 | |
---|
2545 | DOMNode* abc9 = document->getFirstChild(); |
---|
2546 | docType = (DOMDocumentType*) abc9; |
---|
2547 | |
---|
2548 | XMLString::transcode("ourNotationNode", tempStr, 3999); |
---|
2549 | docNotationMap = docType->getNotations(); |
---|
2550 | if (XMLString::compareString(tempStr, docNotationMap->item(0)->getNodeName())) |
---|
2551 | { |
---|
2552 | fprintf(stderr, "Warning!!! DOMDocumentType's 'getNotations' failed!\n"); |
---|
2553 | OK = false; |
---|
2554 | } |
---|
2555 | // doc->appendChild(newDocumentTypeImpl);//!! Throws a HIERARCHY_REQUEST_ERR ******* |
---|
2556 | DOMNode* abc10 = document->removeChild(document->getFirstChild()); //Tests removeChild and stores removed branch for tree reconstruction |
---|
2557 | holdDocType = (DOMDocumentType*) abc10; |
---|
2558 | document->insertBefore(newDocumentType, document->getDocumentElement()); |
---|
2559 | //** Other aspects of insertBefore are tested in docBuilder through appendChild* |
---|
2560 | |
---|
2561 | DOMNode* rem = document->removeChild(document->getFirstChild()); //Removes newDocumentType for tree restoral |
---|
2562 | rem->release(); |
---|
2563 | document->insertBefore(holdDocType, document->getFirstChild()); //Reattaches removed branch to restore tree to the original |
---|
2564 | |
---|
2565 | // Test the user data |
---|
2566 | // Test simple set and get |
---|
2567 | DOMDocumentType* userTest = docType; |
---|
2568 | DOMNamedNodeMap* userFirst = docNotationMap; |
---|
2569 | XMLCh* userSecond = tempStr2; |
---|
2570 | XMLString::transcode("first", tempStr, 3999); |
---|
2571 | |
---|
2572 | XMLString::transcode("document", tempStr2, 3999); |
---|
2573 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
2574 | void* mydocument = userTest->getUserData(tempStr2); |
---|
2575 | if (document != mydocument) { |
---|
2576 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
2577 | OK = false; |
---|
2578 | } |
---|
2579 | |
---|
2580 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
2581 | void* myFirst = userTest->getUserData(tempStr); |
---|
2582 | if (userFirst != myFirst) { |
---|
2583 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
2584 | OK = false; |
---|
2585 | } |
---|
2586 | |
---|
2587 | // Test overwrite |
---|
2588 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
2589 | void* mySecond = userTest->getUserData(tempStr); |
---|
2590 | if (userSecond != mySecond) { |
---|
2591 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2592 | OK = false; |
---|
2593 | } |
---|
2594 | if (userFirst != myFirst2) { |
---|
2595 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2596 | OK = false; |
---|
2597 | } |
---|
2598 | if (userFirst == mySecond) { |
---|
2599 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2600 | OK = false; |
---|
2601 | } |
---|
2602 | |
---|
2603 | // Test null |
---|
2604 | // test non-exist key |
---|
2605 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
2606 | if (userTest->getUserData(tempStr3)) { |
---|
2607 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2608 | OK = false; |
---|
2609 | } |
---|
2610 | |
---|
2611 | // use a node that does not have user data set before |
---|
2612 | if (node2->getUserData(tempStr)) { |
---|
2613 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2614 | OK = false; |
---|
2615 | } |
---|
2616 | |
---|
2617 | // Test reset |
---|
2618 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
2619 | void* myNull = userTest->getUserData(tempStr); |
---|
2620 | if (userSecond != mySecond2) { |
---|
2621 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2622 | OK = false; |
---|
2623 | } |
---|
2624 | if (myNull) { |
---|
2625 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2626 | OK = false; |
---|
2627 | } |
---|
2628 | |
---|
2629 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
2630 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
2631 | if (mydocument != mydocument2) { |
---|
2632 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2633 | OK = false; |
---|
2634 | } |
---|
2635 | if (myNull2) { |
---|
2636 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
2637 | OK = false; |
---|
2638 | } |
---|
2639 | |
---|
2640 | //the userTest user data table should be null now |
---|
2641 | if (userTest->getUserData(tempStr)) { |
---|
2642 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2643 | OK = false; |
---|
2644 | } |
---|
2645 | if (userTest->getUserData(tempStr2)) { |
---|
2646 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
2647 | OK = false; |
---|
2648 | } |
---|
2649 | |
---|
2650 | // Test DOMUserDataHandler |
---|
2651 | // test clone |
---|
2652 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
2653 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
2654 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
2655 | |
---|
2656 | // document type cannot be imported, so no test import, rather test the exception |
---|
2657 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
2658 | EXCEPTIONSTEST(document->importNode(userTest,true), DOMException::NOT_SUPPORTED_ERR, OK, 203 ); |
---|
2659 | |
---|
2660 | // Test isSameNode |
---|
2661 | if (!userTest->isSameNode(userTest)) { |
---|
2662 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
2663 | OK = false; |
---|
2664 | } |
---|
2665 | if (userTest->isSameNode(document)) { |
---|
2666 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
2667 | OK = false; |
---|
2668 | } |
---|
2669 | |
---|
2670 | // Test isEqualNode |
---|
2671 | if (!userTest->isEqualNode(mycloned)) { |
---|
2672 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2673 | OK = false; |
---|
2674 | } |
---|
2675 | |
---|
2676 | if (!userTest->isEqualNode(userTest)) { |
---|
2677 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2678 | OK = false; |
---|
2679 | } |
---|
2680 | if (userTest->isEqualNode(document)) { |
---|
2681 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
2682 | OK = false; |
---|
2683 | } |
---|
2684 | |
---|
2685 | // Test rename, should throw exception |
---|
2686 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 209 ); |
---|
2687 | |
---|
2688 | if (!OK) |
---|
2689 | printf("\n*****The DOMDocumentType* method calls listed above failed, all others worked correctly.*****\n"); |
---|
2690 | return OK; |
---|
2691 | } |
---|
2692 | |
---|
2693 | |
---|
2694 | |
---|
2695 | /** |
---|
2696 | * @param document org.w3c.dom.DOMDocument |
---|
2697 | */ |
---|
2698 | bool DOMTest::testDOMerrors(DOMDocument* document) { |
---|
2699 | bool OK = true; |
---|
2700 | |
---|
2701 | DOMTest tests; |
---|
2702 | |
---|
2703 | EXCEPTIONSTEST(document->appendChild(testElementNode), DOMException::HIERARCHY_REQUEST_ERR, OK, 201 ); |
---|
2704 | EXCEPTIONSTEST(testTextNode->appendChild(testTextNode), DOMException::HIERARCHY_REQUEST_ERR, OK, 202 ); |
---|
2705 | return OK; |
---|
2706 | } |
---|
2707 | |
---|
2708 | #define TEST_VALID_XPATH(xpath, expected, line) \ |
---|
2709 | try \ |
---|
2710 | { \ |
---|
2711 | XMLCh xpathStr[100]; \ |
---|
2712 | XMLString::transcode(xpath,xpathStr,99); \ |
---|
2713 | DOMXPathResult* result=(DOMXPathResult*)document->evaluate(xpathStr, document->getDocumentElement(), NULL, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL); \ |
---|
2714 | if(result->getSnapshotLength() != expected) { \ |
---|
2715 | fprintf(stderr, "DOMDocument::evaluate does not work in line %i (%d nodes instead of %d)\n", line, result->getSnapshotLength(), expected); \ |
---|
2716 | OK = false; \ |
---|
2717 | } \ |
---|
2718 | result->release(); \ |
---|
2719 | } \ |
---|
2720 | catch(DOMException&) \ |
---|
2721 | { \ |
---|
2722 | fprintf(stderr, "DOMDocument::evaluate failed at line %i\n", line); \ |
---|
2723 | OK = false; \ |
---|
2724 | } |
---|
2725 | |
---|
2726 | #define TEST_VALID_XPATH_NS(xpath, resolver, expected, line) \ |
---|
2727 | try \ |
---|
2728 | { \ |
---|
2729 | XMLCh xpathStr[100]; \ |
---|
2730 | XMLString::transcode(xpath,xpathStr,99); \ |
---|
2731 | DOMXPathResult* result=(DOMXPathResult*)document->evaluate(xpathStr, document->getDocumentElement(), resolver, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL); \ |
---|
2732 | if(result->getSnapshotLength() != expected) { \ |
---|
2733 | fprintf(stderr, "DOMDocument::evaluate does not work in line %i (%d nodes instead of %d)\n", line, result->getSnapshotLength(), expected); \ |
---|
2734 | OK = false; \ |
---|
2735 | } \ |
---|
2736 | result->release(); \ |
---|
2737 | } \ |
---|
2738 | catch(DOMException&) \ |
---|
2739 | { \ |
---|
2740 | fprintf(stderr, "DOMDocument::evaluate failed at line %i\n", line); \ |
---|
2741 | OK = false; \ |
---|
2742 | } |
---|
2743 | |
---|
2744 | #define TEST_INVALID_XPATH(xpath, line) \ |
---|
2745 | try \ |
---|
2746 | { \ |
---|
2747 | XMLCh xpathStr[100]; \ |
---|
2748 | XMLString::transcode(xpath,xpathStr,99); \ |
---|
2749 | DOMXPathResult* result=(DOMXPathResult*)document->evaluate(xpathStr, document->getDocumentElement(), NULL, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL); \ |
---|
2750 | fprintf(stderr, "DOMDocument::evaluate does not work in line %i (invalid XPath)\n", line); \ |
---|
2751 | OK = false; \ |
---|
2752 | result->release(); \ |
---|
2753 | } \ |
---|
2754 | catch(DOMException& ) \ |
---|
2755 | { \ |
---|
2756 | } |
---|
2757 | |
---|
2758 | #define TEST_VALID_XPATH_SINGLE(xpath, line) \ |
---|
2759 | try \ |
---|
2760 | { \ |
---|
2761 | XMLCh xpathStr[100]; \ |
---|
2762 | XMLString::transcode(xpath,xpathStr,99); \ |
---|
2763 | DOMXPathResult* result=(DOMXPathResult*)document->evaluate(xpathStr, document->getDocumentElement(), NULL, DOMXPathResult::FIRST_ORDERED_NODE_TYPE, NULL); \ |
---|
2764 | if(result->getNodeValue() == NULL) { \ |
---|
2765 | fprintf(stderr, "DOMDocument::evaluate does not work in line %i (single node not found)\n", line); \ |
---|
2766 | OK = false; \ |
---|
2767 | } \ |
---|
2768 | result->release(); \ |
---|
2769 | } \ |
---|
2770 | catch(DOMException& ) \ |
---|
2771 | { \ |
---|
2772 | fprintf(stderr, "DOMDocument::evaluate failed at line %i\n", line); \ |
---|
2773 | OK = false; \ |
---|
2774 | } |
---|
2775 | |
---|
2776 | #include <xercesc/framework/StdOutFormatTarget.hpp> |
---|
2777 | |
---|
2778 | bool DOMTest::testXPath(DOMDocument* document) { |
---|
2779 | bool OK = true; |
---|
2780 | |
---|
2781 | #if 0 |
---|
2782 | XMLCh tempLS[3] = {chLatin_L, chLatin_S, chNull}; |
---|
2783 | DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempLS); |
---|
2784 | DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer(); |
---|
2785 | DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput(); |
---|
2786 | StdOutFormatTarget myFormTarget; |
---|
2787 | theOutputDesc->setByteStream(&myFormTarget); |
---|
2788 | theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true); |
---|
2789 | theSerializer->write(document, theOutputDesc); |
---|
2790 | |
---|
2791 | theOutputDesc->release(); |
---|
2792 | theSerializer->release(); |
---|
2793 | #endif |
---|
2794 | |
---|
2795 | TEST_VALID_XPATH("*", 1, __LINE__); |
---|
2796 | TEST_VALID_XPATH("dTestBody/dBodyLevel24", 1, __LINE__); |
---|
2797 | TEST_VALID_XPATH("//dBodyLevel34", 1, __LINE__); |
---|
2798 | TEST_VALID_XPATH("/*", 1, __LINE__); |
---|
2799 | TEST_VALID_XPATH("/dFirstElement/dTestBody/dBodyLevel24", 1, __LINE__); |
---|
2800 | TEST_INVALID_XPATH("/dFirstElement//dBodyLevel34", __LINE__); // the "//" can only be at the beginning |
---|
2801 | TEST_INVALID_XPATH("/dFirstElement/@dFirstElementdFirstElement", __LINE__); // cannot select attributes |
---|
2802 | TEST_VALID_XPATH("//*", 10, __LINE__); |
---|
2803 | TEST_VALID_XPATH_SINGLE("//*", __LINE__); |
---|
2804 | TEST_INVALID_XPATH("//ns:node", __LINE__); // "ns" prefix is undefined |
---|
2805 | |
---|
2806 | XMLCh tempStr[100]; |
---|
2807 | XMLString::transcode("xmlns:ns",tempStr,99); |
---|
2808 | DOMAttr* attr=document->createAttributeNS(XMLUni::fgXMLNSURIName, tempStr); |
---|
2809 | attr->setNodeValue(XMLUni::fgXSAXMLScanner); |
---|
2810 | document->getDocumentElement()->setAttributeNodeNS(attr); |
---|
2811 | const DOMXPathNSResolver* resolver=document->createNSResolver(document->getDocumentElement()); |
---|
2812 | TEST_VALID_XPATH_NS("//ns:node", resolver, 0, __LINE__); |
---|
2813 | document->getDocumentElement()->removeAttributeNode(attr); |
---|
2814 | |
---|
2815 | return OK; |
---|
2816 | } |
---|
2817 | |
---|
2818 | /** |
---|
2819 | * This method tests DOMImplementation methods for the XML DOM implementation |
---|
2820 | * @param document org.w3c.dom.DOMDocument |
---|
2821 | * |
---|
2822 | */ |
---|
2823 | bool DOMTest::testDOMImplementation(DOMDocument* document) |
---|
2824 | { |
---|
2825 | |
---|
2826 | DOMImplementation* implementation; |
---|
2827 | bool result = false; |
---|
2828 | bool OK = true; |
---|
2829 | // For debugging***** printf("\n testDOMImplementation's outputs:\n"); |
---|
2830 | implementation = document->getImplementation(); //Uses getDOMImplementation to obtain implementation |
---|
2831 | |
---|
2832 | XMLString::transcode("XML", tempStr, 3999); |
---|
2833 | XMLString::transcode("1.0", tempStr2, 3999); |
---|
2834 | result = implementation->hasFeature(tempStr, tempStr2); |
---|
2835 | if(!result) |
---|
2836 | { |
---|
2837 | fprintf(stderr, "Warning!!! DOMImplementation's 'hasFeature' that should be 'true' failed!"); |
---|
2838 | OK = false; |
---|
2839 | } |
---|
2840 | |
---|
2841 | XMLString::transcode("HTML", tempStr, 3999); |
---|
2842 | XMLString::transcode("4.0", tempStr2, 3999); |
---|
2843 | result = implementation->hasFeature(tempStr, tempStr2); |
---|
2844 | if(result) |
---|
2845 | { |
---|
2846 | fprintf(stderr, "Warning!!! DOMImplementation's 'hasFeature' that should be 'false' failed!"); |
---|
2847 | OK = false; |
---|
2848 | } |
---|
2849 | |
---|
2850 | |
---|
2851 | if (!OK) |
---|
2852 | fprintf(stderr, "\n*****The DOMImplementation method calls listed above failed, all others worked correctly.*****\n"); |
---|
2853 | return OK; |
---|
2854 | } |
---|
2855 | |
---|
2856 | |
---|
2857 | |
---|
2858 | /** |
---|
2859 | * This method tests DOMElement* methods for the XML DOM implementation |
---|
2860 | * @param document org.w3c.dom.DOMDocument |
---|
2861 | * |
---|
2862 | */ |
---|
2863 | bool DOMTest::testElement(DOMDocument* document) |
---|
2864 | { |
---|
2865 | DOMAttr* attributeNode, *newAttributeNode; |
---|
2866 | DOMElement* element, *element2; |
---|
2867 | DOMNode* node, *node2; |
---|
2868 | |
---|
2869 | const char* elementNames[] = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32", |
---|
2870 | "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"}; |
---|
2871 | const char* textCompare[] = {"dBodyLevel31'sChildTextNode11", |
---|
2872 | "dBodyLevel31'sChildTextNode12", |
---|
2873 | "dBodyLevel31'sChildTextNode13"}; |
---|
2874 | |
---|
2875 | DOMNamedNodeMap* nodeMap; |
---|
2876 | bool OK = true; |
---|
2877 | node = document->getDocumentElement(); // node gets doc's firstElement |
---|
2878 | node2 = node->cloneNode(true); |
---|
2879 | // Check nodes for equality, both their name and value or lack thereof |
---|
2880 | if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality |
---|
2881 | (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
2882 | ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
2883 | : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
2884 | { |
---|
2885 | fprintf(stderr, "'cloneNode' did not clone the DOMElement* node correctly.\n"); |
---|
2886 | OK = false; |
---|
2887 | } |
---|
2888 | // Deep clone test comparison is in testNode & testDocument |
---|
2889 | |
---|
2890 | element = document->getDocumentElement(); // element gets doc's firstElement |
---|
2891 | |
---|
2892 | XMLString::copyString(tempStr, document->getNodeValue()); |
---|
2893 | XMLString::transcode("'s test attribute", tempStr2, 3999); |
---|
2894 | XMLString::catString(tempStr, tempStr2); |
---|
2895 | if (XMLString::compareString(XMLUni::fgZeroLenString, element->getAttribute(tempStr))) |
---|
2896 | { |
---|
2897 | fprintf(stderr, "Warning!!! DOMElement's 'getAttribute' failed!\n"); |
---|
2898 | OK = false; |
---|
2899 | } |
---|
2900 | |
---|
2901 | XMLString::copyString(tempStr, document->getNodeValue()); |
---|
2902 | XMLString::transcode("FirstElement", tempStr2, 3999); |
---|
2903 | XMLString::catString(tempStr, tempStr2); |
---|
2904 | attributeNode = element->getAttributeNode(tempStr); |
---|
2905 | if(! (attributeNode == 0)) |
---|
2906 | { |
---|
2907 | fprintf(stderr, "Warning!!! DOMElement's 'getAttributeNode' failed! It should have returned '0' here!\n"); |
---|
2908 | OK = false; |
---|
2909 | } |
---|
2910 | |
---|
2911 | |
---|
2912 | XMLString::transcode("AnotherFirstElementAttribute", tempStr, 3999); |
---|
2913 | newAttributeNode = document->createAttribute(tempStr); |
---|
2914 | |
---|
2915 | XMLString::transcode("A new attribute which helps test calls in DOMElement", tempStr, 3999); |
---|
2916 | newAttributeNode->setValue(tempStr); |
---|
2917 | // This test is incorrect. It assumes that there is a defined ordering of the entries |
---|
2918 | // in a nodeMap, but there is no ordering required. |
---|
2919 | #ifdef TheFollowingCheckIsInvalid |
---|
2920 | DOMNode* rem2 = element->setAttributeNode(newAttributeNode); |
---|
2921 | if (rem2) |
---|
2922 | rem2->release(); |
---|
2923 | nodeMap = element->getAttributes(); |
---|
2924 | XMLSize_t size = nodeMap->getLength(); |
---|
2925 | XMLSize_t k; |
---|
2926 | for (k = 0; k < size; k++) |
---|
2927 | { |
---|
2928 | DOMNode* n = (DOMNode) nodeMap->item(k); |
---|
2929 | XMLString::transcode(attributeCompare[k], tempStr, 3999); |
---|
2930 | if (XMLString::compareString(tempStr, n->getNodeName()))) |
---|
2931 | { |
---|
2932 | fprintf(stderr, "Warning!!! Comparison of firstElement's attributes failed at line %i.\n", __LINE__); |
---|
2933 | fprintf(stderr, " This failure can be a result of DOMElement's 'setValue' and/or 'setAttributeNode' and/or 'getAttributes' failing.\n"); |
---|
2934 | OK = false; |
---|
2935 | break; |
---|
2936 | } |
---|
2937 | // printf("firstElement's attribute number " + k + " : " + n->getNodeName()); |
---|
2938 | } |
---|
2939 | #endif |
---|
2940 | |
---|
2941 | nodeMap = element->getAttributes(); |
---|
2942 | XMLSize_t size = nodeMap->getLength(); |
---|
2943 | if (size != 2) |
---|
2944 | { |
---|
2945 | fprintf(stderr, "DOMElement* Tests Failure 001\n"); |
---|
2946 | OK = false; |
---|
2947 | } |
---|
2948 | DOMNode* rem = element->setAttributeNode(newAttributeNode); |
---|
2949 | if (rem) |
---|
2950 | rem->release(); |
---|
2951 | size = nodeMap->getLength(); |
---|
2952 | if (size != 3) |
---|
2953 | { |
---|
2954 | fprintf(stderr, "DOMElement* Tests Failure 002\n"); |
---|
2955 | OK = false; |
---|
2956 | } |
---|
2957 | |
---|
2958 | // Fetch the newly added attribute node back out of from the named node map, |
---|
2959 | // and check that we are returned the same node that we put in-> |
---|
2960 | XMLString::transcode("AnotherFirstElementAttribute", tempStr, 3999); |
---|
2961 | DOMNode* abc12 = nodeMap->getNamedItem(tempStr); |
---|
2962 | DOMAttr* fetchedAttr = (DOMAttr*) abc12; |
---|
2963 | if (fetchedAttr != newAttributeNode) |
---|
2964 | { |
---|
2965 | fprintf(stderr, "DOMElement* Tests Failure 003\n"); |
---|
2966 | OK = false; |
---|
2967 | } |
---|
2968 | |
---|
2969 | // Fetch the newly added attribute back out directly from the element itself. |
---|
2970 | XMLString::transcode("AnotherFirstElementAttribute", tempStr, 3999); |
---|
2971 | fetchedAttr = element->getAttributeNode(tempStr); |
---|
2972 | if (fetchedAttr != newAttributeNode) |
---|
2973 | { |
---|
2974 | fprintf(stderr, "DOMElement* Tests Failure 004\n"); |
---|
2975 | OK = false; |
---|
2976 | } |
---|
2977 | |
---|
2978 | |
---|
2979 | |
---|
2980 | XMLString::transcode("*",tempStr, 3999); |
---|
2981 | DOMNodeList* docElements = document->getElementsByTagName(tempStr); |
---|
2982 | XMLSize_t docSize = docElements->getLength(); |
---|
2983 | XMLSize_t i; |
---|
2984 | for (i = 0; i < docSize; i++) |
---|
2985 | { |
---|
2986 | DOMNode* n = docElements->item(i); |
---|
2987 | XMLString::transcode(elementNames[i], tempStr, 3999); |
---|
2988 | if (XMLString::compareString(tempStr, n->getNodeName())) |
---|
2989 | { |
---|
2990 | fprintf(stderr, "Warning!!! Comparison of DOMElement's 'getElementsByTagName' " |
---|
2991 | "and/or 'item' failed at element number %d at line %i \n", i, __LINE__ ); |
---|
2992 | fprintf(stderr, "\n"); |
---|
2993 | OK = false; |
---|
2994 | break; |
---|
2995 | } |
---|
2996 | // printf("docElement's number " + i + " is: " + n->getNodeName()); |
---|
2997 | } |
---|
2998 | XMLString::transcode("dBodyLevel21", tempStr, 3999); |
---|
2999 | DOMNode* abc15 = document->getElementsByTagName(tempStr)->item(0); // element gets DOMElement* test BodyLevel21 |
---|
3000 | element = (DOMElement*) abc15; |
---|
3001 | |
---|
3002 | XMLString::transcode("dBodyLevel31", tempStr, 3999); |
---|
3003 | DOMNode* abc16 = document->getElementsByTagName(tempStr)->item(0); // element2 gets DOMElement* test BodyLevel31 |
---|
3004 | element2 = (DOMElement*) abc16; |
---|
3005 | DOMNodeList* text = ((DOMNode* &) element2)->getChildNodes(); |
---|
3006 | XMLSize_t textSize = text->getLength(); |
---|
3007 | XMLSize_t j; |
---|
3008 | static bool firstTime = true; |
---|
3009 | if (firstTime) |
---|
3010 | { |
---|
3011 | firstTime = false; // Temporary fix. Subsequent tests alter the doc, causing |
---|
3012 | // this test to fail on all but the first time through. |
---|
3013 | for (j = 0; j < textSize; j++) |
---|
3014 | { |
---|
3015 | DOMNode* n = text->item(j); |
---|
3016 | XMLString::transcode(textCompare[j], tempStr, 3999); |
---|
3017 | if (XMLString::compareString(tempStr, n->getNodeValue())) |
---|
3018 | { |
---|
3019 | fprintf(stderr, "Warning!!! Comparison of original text nodes via DOMNode* 'getChildNodes' & DOMNodeList 'item'\n" |
---|
3020 | " failed at text node: #%d at line %i \n ", j, __LINE__ ); |
---|
3021 | OK = false; |
---|
3022 | break; |
---|
3023 | } |
---|
3024 | // printf("DOMElement* testBodyLevel31's child text node " + j + " is: " + n->getNodeValue()); |
---|
3025 | } |
---|
3026 | } |
---|
3027 | |
---|
3028 | element = document->getDocumentElement(); // element gets doc's firstElement |
---|
3029 | element->normalize(); // Concatenates all adjacent text nodes in this element's subtree |
---|
3030 | DOMNodeList* text2 = ((DOMNode*) element2)->getChildNodes(); |
---|
3031 | XMLString::transcode("dBodyLevel31'sChildTextNode11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13", tempStr, 3999); |
---|
3032 | DOMNode* n = text2->item(0); |
---|
3033 | if (XMLString::compareString(tempStr, n->getNodeValue())) |
---|
3034 | { |
---|
3035 | fprintf(stderr, "Warning!!! Comparison of concatenated text nodes created by DOMElement's 'normalize' failed!\n"); |
---|
3036 | OK = false; |
---|
3037 | } |
---|
3038 | |
---|
3039 | XMLString::transcode("FirstElementLastAttribute", tempStr, 3999); |
---|
3040 | XMLString::transcode("More attribute stuff for firstElement!!", tempStr2, 3999); |
---|
3041 | element->setAttribute(tempStr, tempStr2); |
---|
3042 | |
---|
3043 | XMLString::transcode("FirstElementLastAttribute", tempStr, 3999); |
---|
3044 | element->removeAttribute(tempStr); |
---|
3045 | rem = element->removeAttributeNode(newAttributeNode); |
---|
3046 | if (rem) |
---|
3047 | rem->release(); |
---|
3048 | |
---|
3049 | // doc->getLastChild()->setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR*** |
---|
3050 | |
---|
3051 | // Test the user data |
---|
3052 | // Test simple set and get |
---|
3053 | DOMElement* userTest = element; |
---|
3054 | DOMAttr* userFirst = newAttributeNode; |
---|
3055 | XMLCh* userSecond = tempStr2; |
---|
3056 | XMLString::transcode("first", tempStr, 3999); |
---|
3057 | |
---|
3058 | XMLString::transcode("document", tempStr2, 3999); |
---|
3059 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
3060 | void* mydocument = userTest->getUserData(tempStr2); |
---|
3061 | if (document != mydocument) { |
---|
3062 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3063 | OK = false; |
---|
3064 | } |
---|
3065 | |
---|
3066 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
3067 | void* myFirst = userTest->getUserData(tempStr); |
---|
3068 | if (userFirst != myFirst) { |
---|
3069 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3070 | OK = false; |
---|
3071 | } |
---|
3072 | |
---|
3073 | // Test overwrite |
---|
3074 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
3075 | void* mySecond = userTest->getUserData(tempStr); |
---|
3076 | if (userSecond != mySecond) { |
---|
3077 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3078 | OK = false; |
---|
3079 | } |
---|
3080 | if (userFirst != myFirst2) { |
---|
3081 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3082 | OK = false; |
---|
3083 | } |
---|
3084 | if (userFirst == mySecond) { |
---|
3085 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3086 | OK = false; |
---|
3087 | } |
---|
3088 | |
---|
3089 | // Test null |
---|
3090 | // test non-exist key |
---|
3091 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
3092 | if (userTest->getUserData(tempStr3)) { |
---|
3093 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3094 | OK = false; |
---|
3095 | } |
---|
3096 | |
---|
3097 | // use a node that does not have user data set before |
---|
3098 | if (userFirst->getUserData(tempStr)) { |
---|
3099 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3100 | OK = false; |
---|
3101 | } |
---|
3102 | |
---|
3103 | // Test reset |
---|
3104 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
3105 | void* myNull = userTest->getUserData(tempStr); |
---|
3106 | if (userSecond != mySecond2) { |
---|
3107 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3108 | OK = false; |
---|
3109 | } |
---|
3110 | if (myNull) { |
---|
3111 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3112 | OK = false; |
---|
3113 | } |
---|
3114 | |
---|
3115 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
3116 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
3117 | if (mydocument != mydocument2) { |
---|
3118 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3119 | OK = false; |
---|
3120 | } |
---|
3121 | if (myNull2) { |
---|
3122 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3123 | OK = false; |
---|
3124 | } |
---|
3125 | |
---|
3126 | //the userTest user data table should be null now |
---|
3127 | if (userTest->getUserData(tempStr)) { |
---|
3128 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3129 | OK = false; |
---|
3130 | } |
---|
3131 | if (userTest->getUserData(tempStr2)) { |
---|
3132 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3133 | OK = false; |
---|
3134 | } |
---|
3135 | |
---|
3136 | // Test DOMUserDataHandler |
---|
3137 | // test clone |
---|
3138 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
3139 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
3140 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
3141 | |
---|
3142 | // test import |
---|
3143 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
3144 | DOMNode* myimport = document->importNode(userTest,true); |
---|
3145 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
3146 | |
---|
3147 | // test delete |
---|
3148 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
3149 | myimport->release(); |
---|
3150 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
3151 | |
---|
3152 | // Test isSameNode |
---|
3153 | if (!userTest->isSameNode(userTest)) { |
---|
3154 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
3155 | OK = false; |
---|
3156 | } |
---|
3157 | if (userTest->isSameNode(userFirst)) { |
---|
3158 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
3159 | OK = false; |
---|
3160 | } |
---|
3161 | |
---|
3162 | // Test isEqualNode |
---|
3163 | if (!userTest->isEqualNode(mycloned)) { |
---|
3164 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3165 | OK = false; |
---|
3166 | } |
---|
3167 | |
---|
3168 | if (!userTest->isEqualNode(userTest)) { |
---|
3169 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3170 | OK = false; |
---|
3171 | } |
---|
3172 | if (userTest->isEqualNode(userFirst)) { |
---|
3173 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3174 | OK = false; |
---|
3175 | } |
---|
3176 | |
---|
3177 | // Test renameNode |
---|
3178 | XMLString::transcode("http://nsa", tempStr4, 3999); |
---|
3179 | XMLString::transcode("aa", tempStr5, 3999); |
---|
3180 | XMLString::transcode("pnsa:aa", tempStr3, 3999); |
---|
3181 | |
---|
3182 | // create the element |
---|
3183 | DOMElement* renameTestElement = document->createElement(tempStr5); |
---|
3184 | DOMElement* renameTestElementNS = document->createElementNS(tempStr4, tempStr3); |
---|
3185 | |
---|
3186 | // create the parent |
---|
3187 | DOMElement* renameTestParent = document->createElement(tempStr5); |
---|
3188 | renameTestParent->appendChild(renameTestElement); |
---|
3189 | renameTestParent->appendChild(renameTestElementNS); |
---|
3190 | |
---|
3191 | // set up the userdata |
---|
3192 | renameTestElement->setUserData(tempStr5, (void*) document, &userhandler); |
---|
3193 | renameTestElementNS->setUserData(tempStr4, (void*) document, 0); |
---|
3194 | |
---|
3195 | // append a text node as child |
---|
3196 | DOMText* renameTestText = document->createTextNode(tempStr5); |
---|
3197 | DOMText* renameTestTextNS = document->createTextNode(tempStr4); |
---|
3198 | renameTestElement->appendChild(renameTestText); |
---|
3199 | renameTestElementNS->appendChild(renameTestTextNS); |
---|
3200 | |
---|
3201 | XMLString::transcode("http://nsb", tempStr, 3999); |
---|
3202 | XMLString::transcode("bb", tempStr2, 3999); |
---|
3203 | XMLString::transcode("pnsb:bb", tempStr3, 3999); |
---|
3204 | |
---|
3205 | // set up some attributes |
---|
3206 | DOMAttr* renameTestAttribute = document->createAttribute(tempStr5); |
---|
3207 | DOMAttr* renameTestAttributeNS = document->createAttributeNS(tempStr4, tempStr3); |
---|
3208 | renameTestElement->setAttributeNode(renameTestAttribute); |
---|
3209 | renameTestElementNS->setAttributeNodeNS(renameTestAttributeNS); |
---|
3210 | |
---|
3211 | //Test compareDocumentPosition first before testing rename |
---|
3212 | // renameTestParent |
---|
3213 | // | |
---|
3214 | // |_ renameTestElement (has renameTestAttribute) |
---|
3215 | // | | |
---|
3216 | // | |_ renameTestText |
---|
3217 | // | |
---|
3218 | // |_ renameTestElementNS (has renameTestAttributeNS) |
---|
3219 | // | | |
---|
3220 | // | |_ renameTestTextNS |
---|
3221 | // |
---|
3222 | COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestAttributeNS, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
3223 | COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestElement, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
3224 | COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestText, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
3225 | COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestTextNS, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
3226 | COMPARETREEPOSITIONTEST(renameTestAttribute, renameTestParent, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
3227 | |
---|
3228 | COMPARETREEPOSITIONTEST(renameTestAttributeNS, renameTestAttribute, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
3229 | COMPARETREEPOSITIONTEST(renameTestElement, renameTestAttributeNS, DOMNode::DOCUMENT_POSITION_FOLLOWING, __LINE__); |
---|
3230 | COMPARETREEPOSITIONTEST(renameTestAttributeNS, renameTestText, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
3231 | COMPARETREEPOSITIONTEST(renameTestTextNS, renameTestAttributeNS, DOMNode::DOCUMENT_POSITION_PRECEDING, __LINE__); |
---|
3232 | |
---|
3233 | // start the rename tests |
---|
3234 | // rename the NS Element |
---|
3235 | DOMElement* renameTest = (DOMElement*) document->renameNode(renameTestElementNS, tempStr, tempStr3); |
---|
3236 | // test the name |
---|
3237 | if (XMLString::compareString(tempStr, renameTest->getNamespaceURI())) |
---|
3238 | { |
---|
3239 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3240 | OK = false; |
---|
3241 | } |
---|
3242 | if (XMLString::compareString(tempStr2, renameTest->getLocalName())) |
---|
3243 | { |
---|
3244 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3245 | OK = false; |
---|
3246 | } |
---|
3247 | if (XMLString::compareString(tempStr3, renameTest->getNodeName())) |
---|
3248 | { |
---|
3249 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3250 | OK = false; |
---|
3251 | } |
---|
3252 | // test the child / nodevalue |
---|
3253 | if (XMLString::compareString(tempStr4, renameTest->getFirstChild()->getNodeValue())) |
---|
3254 | { |
---|
3255 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3256 | OK = false; |
---|
3257 | } |
---|
3258 | // test the attribute |
---|
3259 | if (!renameTest->getAttributeNodeNS(tempStr4, tempStr2)) |
---|
3260 | { |
---|
3261 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3262 | OK = false; |
---|
3263 | } |
---|
3264 | // test the owner element |
---|
3265 | if (renameTestParent->getElementsByTagNameNS(tempStr, tempStr2)->getLength() != 1) { |
---|
3266 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3267 | OK = false; |
---|
3268 | } |
---|
3269 | if (renameTestParent->getElementsByTagNameNS(tempStr4, tempStr5)->getLength() != 0) { |
---|
3270 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3271 | OK = false; |
---|
3272 | } |
---|
3273 | // test user data |
---|
3274 | void* renamedocument = renameTest->getUserData(tempStr4); |
---|
3275 | if (document != renamedocument) { |
---|
3276 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3277 | OK = false; |
---|
3278 | } |
---|
3279 | // test isSame and isEqual |
---|
3280 | if (!renameTestElementNS->isEqualNode(renameTest)) { |
---|
3281 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3282 | OK = false; |
---|
3283 | } |
---|
3284 | if (!renameTestElementNS->isSameNode(renameTest)) { |
---|
3285 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3286 | OK = false; |
---|
3287 | } |
---|
3288 | |
---|
3289 | |
---|
3290 | // rename the Element (null namespace) |
---|
3291 | renameTest = (DOMElement*) document->renameNode(renameTestElement, 0, tempStr2); |
---|
3292 | // test the name |
---|
3293 | if (renameTest->getNamespaceURI()) |
---|
3294 | { |
---|
3295 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3296 | OK = false; |
---|
3297 | } |
---|
3298 | if (renameTest->getLocalName()) |
---|
3299 | { |
---|
3300 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3301 | OK = false; |
---|
3302 | } |
---|
3303 | if (XMLString::compareString(tempStr2, renameTest->getNodeName())) |
---|
3304 | { |
---|
3305 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3306 | OK = false; |
---|
3307 | } |
---|
3308 | // test the child / nodevalue |
---|
3309 | if (XMLString::compareString(tempStr5, renameTest->getFirstChild()->getNodeValue())) |
---|
3310 | { |
---|
3311 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3312 | OK = false; |
---|
3313 | } |
---|
3314 | // test the attribute |
---|
3315 | if (!renameTest->getAttributeNode(tempStr5)) |
---|
3316 | { |
---|
3317 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3318 | OK = false; |
---|
3319 | } |
---|
3320 | // test the owner element |
---|
3321 | if (renameTestParent->getElementsByTagName(tempStr2)->getLength() != 1) { |
---|
3322 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3323 | OK = false; |
---|
3324 | } |
---|
3325 | if (renameTestParent->getElementsByTagName(tempStr5)->getLength() != 0) { |
---|
3326 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3327 | OK = false; |
---|
3328 | } |
---|
3329 | // test user data |
---|
3330 | renamedocument = renameTest->getUserData(tempStr5); |
---|
3331 | if (document != renamedocument) { |
---|
3332 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3333 | OK = false; |
---|
3334 | } |
---|
3335 | // test isSame and isEqual |
---|
3336 | if (!renameTestElement->isEqualNode(renameTest)) { |
---|
3337 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3338 | OK = false; |
---|
3339 | } |
---|
3340 | if (!renameTestElement->isSameNode(renameTest)) { |
---|
3341 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3342 | OK = false; |
---|
3343 | } |
---|
3344 | |
---|
3345 | |
---|
3346 | // rename the Element (with namespace) |
---|
3347 | renameTest = (DOMElement*) document->renameNode(renameTestElement, tempStr, tempStr3); |
---|
3348 | // test the name |
---|
3349 | if (XMLString::compareString(tempStr, renameTest->getNamespaceURI())) |
---|
3350 | { |
---|
3351 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3352 | OK = false; |
---|
3353 | } |
---|
3354 | if (XMLString::compareString(tempStr2, renameTest->getLocalName())) |
---|
3355 | { |
---|
3356 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3357 | OK = false; |
---|
3358 | } |
---|
3359 | if (XMLString::compareString(tempStr3, renameTest->getNodeName())) |
---|
3360 | { |
---|
3361 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3362 | OK = false; |
---|
3363 | } |
---|
3364 | // test the child / nodevalue |
---|
3365 | if (XMLString::compareString(tempStr5, renameTest->getFirstChild()->getNodeValue())) |
---|
3366 | { |
---|
3367 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3368 | OK = false; |
---|
3369 | } |
---|
3370 | if (renameTestElement->getFirstChild()) |
---|
3371 | { |
---|
3372 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3373 | OK = false; |
---|
3374 | } |
---|
3375 | // test the attribute |
---|
3376 | if (!renameTest->getAttributeNode(tempStr5)) |
---|
3377 | { |
---|
3378 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3379 | OK = false; |
---|
3380 | } |
---|
3381 | if (renameTestElement->getAttributeNode(tempStr5)) |
---|
3382 | { |
---|
3383 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3384 | OK = false; |
---|
3385 | } |
---|
3386 | // test the owner element |
---|
3387 | // the nodelist should be 2 items as we have to count the renameTestElementNS as well |
---|
3388 | if (renameTestParent->getElementsByTagNameNS(tempStr, tempStr2)->getLength() != 2) { |
---|
3389 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3390 | OK = false; |
---|
3391 | } |
---|
3392 | if (renameTestParent->getElementsByTagNameNS(0, tempStr2)->getLength() != 0) { |
---|
3393 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3394 | OK = false; |
---|
3395 | } |
---|
3396 | if (renameTestParent->getElementsByTagName(tempStr2)->getLength() != 0) { |
---|
3397 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3398 | OK = false; |
---|
3399 | } |
---|
3400 | // test user data |
---|
3401 | renamedocument = renameTest->getUserData(tempStr5); |
---|
3402 | if (document != renamedocument) { |
---|
3403 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3404 | OK = false; |
---|
3405 | } |
---|
3406 | // test userdatahandler |
---|
3407 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_RENAMED, tempStr5, document, renameTestElement, renameTest, __LINE__); |
---|
3408 | // test isSame and isEqual |
---|
3409 | // a new node is created here, so both isSame and isEqual are not compared |
---|
3410 | if (renameTestElement->isEqualNode(renameTest)) { |
---|
3411 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3412 | OK = false; |
---|
3413 | } |
---|
3414 | if (renameTestElement->isSameNode(renameTest)) { |
---|
3415 | fprintf(stderr, "renameNode failed in line %i\n", __LINE__); |
---|
3416 | OK = false; |
---|
3417 | } |
---|
3418 | |
---|
3419 | |
---|
3420 | //setIdAttribute tests |
---|
3421 | |
---|
3422 | XMLString::transcode("http://nsa", tempStr4, 3999); |
---|
3423 | XMLString::transcode("aa", tempStr5, 3999); |
---|
3424 | |
---|
3425 | DOMAttr *idAtt = document->createAttributeNS(tempStr4, tempStr5); |
---|
3426 | |
---|
3427 | //tests for node not being on testElementNode |
---|
3428 | EXCEPTIONSTEST(testElementNode->setIdAttribute(tempStr4, true), DOMException::NOT_FOUND_ERR, OK, 1000); |
---|
3429 | EXCEPTIONSTEST(testElementNode->setIdAttributeNS(tempStr4, tempStr5, true), DOMException::NOT_FOUND_ERR, OK, 1001); |
---|
3430 | EXCEPTIONSTEST(testElementNode->setIdAttributeNode(idAtt, true), DOMException::NOT_FOUND_ERR, OK, 1002); |
---|
3431 | |
---|
3432 | //should test NO_MODIFICATION_ALLOWED_ERR but dont know how to without direct access to DOMAttrImpl. |
---|
3433 | |
---|
3434 | idAtt = document->createAttributeNS(tempStr4, tempStr5); |
---|
3435 | idAtt->setValue(tempStr3); |
---|
3436 | testElementNode->setAttributeNode(idAtt); |
---|
3437 | testElementNode->setIdAttributeNode(idAtt, true); |
---|
3438 | |
---|
3439 | if(!idAtt->isId()) { |
---|
3440 | fprintf(stderr, "setIdAttributeNode failed in line %i\n", __LINE__); |
---|
3441 | OK = false; |
---|
3442 | } |
---|
3443 | |
---|
3444 | DOMElement *idEle = document->getElementById(tempStr3); |
---|
3445 | |
---|
3446 | if(!idEle || !idEle->isSameNode(testElementNode)) { |
---|
3447 | fprintf(stderr, "setIdAttributeNode failed in line %i\n", __LINE__); |
---|
3448 | OK = false; |
---|
3449 | } |
---|
3450 | |
---|
3451 | testElementNode->setIdAttributeNode(idAtt, false); |
---|
3452 | |
---|
3453 | if(idAtt->isId()) { |
---|
3454 | fprintf(stderr, "setIdAttributeNode failed in line %i\n", __LINE__); |
---|
3455 | OK = false; |
---|
3456 | } |
---|
3457 | |
---|
3458 | idEle = document->getElementById(tempStr3); |
---|
3459 | |
---|
3460 | if(idEle) { |
---|
3461 | fprintf(stderr, "setIdAttributeNode failed in line %i\n", __LINE__); |
---|
3462 | OK = false; |
---|
3463 | } |
---|
3464 | |
---|
3465 | testElementNode->removeAttributeNode(idAtt); |
---|
3466 | |
---|
3467 | |
---|
3468 | XMLString::transcode("someval", tempStr3, 3999); |
---|
3469 | idAtt = document->createAttributeNS(tempStr4, tempStr5); |
---|
3470 | idAtt->setValue(tempStr3); |
---|
3471 | testElementNode->setAttributeNode(idAtt); |
---|
3472 | testElementNode->setIdAttributeNS(tempStr4, tempStr5, true); |
---|
3473 | |
---|
3474 | if(!idAtt->isId()) { |
---|
3475 | fprintf(stderr, "setIdAttributeNS failed in line %i\n", __LINE__); |
---|
3476 | OK = false; |
---|
3477 | } |
---|
3478 | |
---|
3479 | idEle = document->getElementById(tempStr3); |
---|
3480 | |
---|
3481 | if(!idEle || !idEle->isSameNode(testElementNode)) { |
---|
3482 | fprintf(stderr, "setIdAttributeNS failed in line %i\n", __LINE__); |
---|
3483 | OK = false; |
---|
3484 | } |
---|
3485 | |
---|
3486 | testElementNode->setIdAttributeNS(tempStr4, tempStr5, false); |
---|
3487 | |
---|
3488 | if(idAtt->isId()) { |
---|
3489 | fprintf(stderr, "setIdAttributeNS failed in line %i\n", __LINE__); |
---|
3490 | OK = false; |
---|
3491 | } |
---|
3492 | |
---|
3493 | idEle = document->getElementById(tempStr3); |
---|
3494 | |
---|
3495 | if(idEle) { |
---|
3496 | fprintf(stderr, "setIdAttributeNS failed in line %i\n", __LINE__); |
---|
3497 | OK = false; |
---|
3498 | } |
---|
3499 | |
---|
3500 | testElementNode->removeAttributeNode(idAtt); |
---|
3501 | idAtt->release(); |
---|
3502 | |
---|
3503 | |
---|
3504 | XMLString::transcode("somevalDif", tempStr3, 3999); |
---|
3505 | idAtt = document->createAttribute(tempStr5); |
---|
3506 | idAtt->setValue(tempStr3); |
---|
3507 | testElementNode->setAttributeNode(idAtt); |
---|
3508 | testElementNode->setIdAttribute(tempStr5, true); |
---|
3509 | |
---|
3510 | if(!idAtt->isId()) { |
---|
3511 | fprintf(stderr, "setIdAttribute failed in line %i\n", __LINE__); |
---|
3512 | OK = false; |
---|
3513 | } |
---|
3514 | |
---|
3515 | idEle = document->getElementById(tempStr3); |
---|
3516 | |
---|
3517 | if(!idEle || !idEle->isSameNode(testElementNode)) { |
---|
3518 | fprintf(stderr, "setIdAttribute failed in line %i\n", __LINE__); |
---|
3519 | OK = false; |
---|
3520 | } |
---|
3521 | |
---|
3522 | testElementNode->setIdAttribute(tempStr5, false); |
---|
3523 | |
---|
3524 | if(idAtt->isId()) { |
---|
3525 | fprintf(stderr, "setIdAttribute failed in line %i\n", __LINE__); |
---|
3526 | OK = false; |
---|
3527 | } |
---|
3528 | |
---|
3529 | idEle = document->getElementById(tempStr3); |
---|
3530 | |
---|
3531 | if(idEle) { |
---|
3532 | fprintf(stderr, "setIdAttribute failed in line %i\n", __LINE__); |
---|
3533 | OK = false; |
---|
3534 | } |
---|
3535 | |
---|
3536 | testElementNode->removeAttributeNode(idAtt); |
---|
3537 | idAtt->release(); |
---|
3538 | |
---|
3539 | if (!OK) |
---|
3540 | printf("\n*****The DOMElement* method calls listed above failed, all others worked correctly.*****\n"); |
---|
3541 | return OK; |
---|
3542 | } |
---|
3543 | |
---|
3544 | |
---|
3545 | |
---|
3546 | /** |
---|
3547 | * This method tests DOMEntity* methods for the XML DOM implementation |
---|
3548 | * @param document org.w3c.dom.DOMDocument |
---|
3549 | * |
---|
3550 | */ |
---|
3551 | bool DOMTest::testEntity(DOMDocument* document) |
---|
3552 | { |
---|
3553 | DOMEntity* entity; |
---|
3554 | DOMNode* node, *node2; |
---|
3555 | bool OK = true; |
---|
3556 | // For debugging***** printf("\n testEntity's outputs:\n\n"); |
---|
3557 | XMLString::transcode("ourEntityNode", tempStr, 3999); |
---|
3558 | DOMNode* abc20 = document->getDoctype()->getEntities()->getNamedItem(tempStr); |
---|
3559 | entity = (DOMEntity*) abc20; |
---|
3560 | node = entity; |
---|
3561 | node2 = entity->cloneNode(true); |
---|
3562 | // Check nodes for equality, both their name and value or lack thereof |
---|
3563 | if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality |
---|
3564 | (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
3565 | ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
3566 | : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
3567 | { |
---|
3568 | fprintf(stderr, "'cloneNode' did not clone the DOMEntity* node correctly"); |
---|
3569 | OK = false; |
---|
3570 | } |
---|
3571 | // Deep clone test comparison is in testNode & testDocument |
---|
3572 | |
---|
3573 | // Test the user data |
---|
3574 | // Test simple set and get |
---|
3575 | DOMEntity* userTest = entity; |
---|
3576 | DOMNode* userFirst = node; |
---|
3577 | XMLCh* userSecond = tempStr2; |
---|
3578 | XMLString::transcode("first", tempStr, 3999); |
---|
3579 | |
---|
3580 | XMLString::transcode("document", tempStr2, 3999); |
---|
3581 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
3582 | void* mydocument = userTest->getUserData(tempStr2); |
---|
3583 | if (document != mydocument) { |
---|
3584 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3585 | OK = false; |
---|
3586 | } |
---|
3587 | |
---|
3588 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
3589 | void* myFirst = userTest->getUserData(tempStr); |
---|
3590 | if (userFirst != myFirst) { |
---|
3591 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3592 | OK = false; |
---|
3593 | } |
---|
3594 | |
---|
3595 | // Test overwrite |
---|
3596 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
3597 | void* mySecond = userTest->getUserData(tempStr); |
---|
3598 | if (userSecond != mySecond) { |
---|
3599 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3600 | OK = false; |
---|
3601 | } |
---|
3602 | if (userFirst != myFirst2) { |
---|
3603 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3604 | OK = false; |
---|
3605 | } |
---|
3606 | if (userFirst == mySecond) { |
---|
3607 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3608 | OK = false; |
---|
3609 | } |
---|
3610 | |
---|
3611 | // Test null |
---|
3612 | // test non-exist key |
---|
3613 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
3614 | if (userTest->getUserData(tempStr3)) { |
---|
3615 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3616 | OK = false; |
---|
3617 | } |
---|
3618 | |
---|
3619 | // use a node that does not have user data set before |
---|
3620 | if (userFirst->getUserData(tempStr)) { |
---|
3621 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3622 | OK = false; |
---|
3623 | } |
---|
3624 | |
---|
3625 | // Test reset |
---|
3626 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
3627 | void* myNull = userTest->getUserData(tempStr); |
---|
3628 | if (userSecond != mySecond2) { |
---|
3629 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3630 | OK = false; |
---|
3631 | } |
---|
3632 | if (myNull) { |
---|
3633 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3634 | OK = false; |
---|
3635 | } |
---|
3636 | |
---|
3637 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
3638 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
3639 | if (mydocument != mydocument2) { |
---|
3640 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3641 | OK = false; |
---|
3642 | } |
---|
3643 | if (myNull2) { |
---|
3644 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3645 | OK = false; |
---|
3646 | } |
---|
3647 | |
---|
3648 | //the userTest user data table should be null now |
---|
3649 | if (userTest->getUserData(tempStr)) { |
---|
3650 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3651 | OK = false; |
---|
3652 | } |
---|
3653 | if (userTest->getUserData(tempStr2)) { |
---|
3654 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3655 | OK = false; |
---|
3656 | } |
---|
3657 | |
---|
3658 | // Test DOMUserDataHandler |
---|
3659 | // test clone |
---|
3660 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
3661 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
3662 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
3663 | |
---|
3664 | // test import |
---|
3665 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
3666 | DOMNode* myimport = document->importNode(userTest,true); |
---|
3667 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
3668 | |
---|
3669 | // test delete |
---|
3670 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
3671 | myimport->release(); |
---|
3672 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
3673 | |
---|
3674 | // Test isSameNode |
---|
3675 | if (!userTest->isSameNode(userTest)) { |
---|
3676 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
3677 | OK = false; |
---|
3678 | } |
---|
3679 | if (userTest->isSameNode(userFirst)) { |
---|
3680 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
3681 | OK = false; |
---|
3682 | } |
---|
3683 | |
---|
3684 | // Test isEqualNode |
---|
3685 | if (!userTest->isEqualNode(mycloned)) { |
---|
3686 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3687 | OK = false; |
---|
3688 | } |
---|
3689 | |
---|
3690 | if (!userTest->isEqualNode(userTest)) { |
---|
3691 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3692 | OK = false; |
---|
3693 | } |
---|
3694 | if (userTest->isEqualNode(userFirst)) { |
---|
3695 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3696 | OK = false; |
---|
3697 | } |
---|
3698 | |
---|
3699 | // Test rename, should throw exception |
---|
3700 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 210 ); |
---|
3701 | |
---|
3702 | if (!OK) |
---|
3703 | printf("\n*****The DOMEntity* method calls listed above failed, all others worked correctly.*****\n"); |
---|
3704 | return OK; |
---|
3705 | } |
---|
3706 | |
---|
3707 | |
---|
3708 | /** |
---|
3709 | * This method tests DOMEntityReference* methods for the XML DOM implementation |
---|
3710 | * @param document org.w3c.dom.DOMDocument |
---|
3711 | * |
---|
3712 | */ |
---|
3713 | bool DOMTest::testEntityReference(DOMDocument* document) |
---|
3714 | { |
---|
3715 | DOMEntityReference* entityReference; |
---|
3716 | DOMNode* node, *node2; |
---|
3717 | bool OK = true; |
---|
3718 | // For debugging***** printf("\n testEntityReference's outputs:\n"); |
---|
3719 | DOMNode* abc30 = document->getLastChild()->getLastChild()->getLastChild()->getFirstChild(); |
---|
3720 | entityReference = (DOMEntityReference*) abc30; |
---|
3721 | node = entityReference; |
---|
3722 | node2 = node->cloneNode(true); |
---|
3723 | // Check nodes for equality, both their name and value or lack thereof |
---|
3724 | if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality |
---|
3725 | (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
3726 | ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
3727 | : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
3728 | { |
---|
3729 | fprintf(stderr, "'cloneNode' did not clone the DOMEntityReference* node correctly\n"); |
---|
3730 | OK = false; |
---|
3731 | } |
---|
3732 | // Deep clone test comparison is in testNode & testDocument |
---|
3733 | |
---|
3734 | // entityReference->setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** |
---|
3735 | |
---|
3736 | // Test the user data |
---|
3737 | // Test simple set and get |
---|
3738 | DOMEntityReference* userTest = entityReference; |
---|
3739 | DOMNode* userFirst = node2; |
---|
3740 | XMLCh* userSecond = tempStr2; |
---|
3741 | XMLString::transcode("first", tempStr, 3999); |
---|
3742 | |
---|
3743 | XMLString::transcode("document", tempStr2, 3999); |
---|
3744 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
3745 | void* mydocument = userTest->getUserData(tempStr2); |
---|
3746 | if (document != mydocument) { |
---|
3747 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3748 | OK = false; |
---|
3749 | } |
---|
3750 | |
---|
3751 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
3752 | void* myFirst = userTest->getUserData(tempStr); |
---|
3753 | if (userFirst != myFirst) { |
---|
3754 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3755 | OK = false; |
---|
3756 | } |
---|
3757 | |
---|
3758 | // Test overwrite |
---|
3759 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
3760 | void* mySecond = userTest->getUserData(tempStr); |
---|
3761 | if (userSecond != mySecond) { |
---|
3762 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3763 | OK = false; |
---|
3764 | } |
---|
3765 | if (userFirst != myFirst2) { |
---|
3766 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3767 | OK = false; |
---|
3768 | } |
---|
3769 | if (userFirst == mySecond) { |
---|
3770 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3771 | OK = false; |
---|
3772 | } |
---|
3773 | |
---|
3774 | // Test null |
---|
3775 | // test non-exist key |
---|
3776 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
3777 | if (userTest->getUserData(tempStr3)) { |
---|
3778 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3779 | OK = false; |
---|
3780 | } |
---|
3781 | |
---|
3782 | // use a node that does not have user data set before |
---|
3783 | if (node2->getUserData(tempStr)) { |
---|
3784 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3785 | OK = false; |
---|
3786 | } |
---|
3787 | |
---|
3788 | // Test reset |
---|
3789 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
3790 | void* myNull = userTest->getUserData(tempStr); |
---|
3791 | if (userSecond != mySecond2) { |
---|
3792 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3793 | OK = false; |
---|
3794 | } |
---|
3795 | if (myNull) { |
---|
3796 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3797 | OK = false; |
---|
3798 | } |
---|
3799 | |
---|
3800 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
3801 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
3802 | if (mydocument != mydocument2) { |
---|
3803 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3804 | OK = false; |
---|
3805 | } |
---|
3806 | if (myNull2) { |
---|
3807 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3808 | OK = false; |
---|
3809 | } |
---|
3810 | |
---|
3811 | //the userTest user data table should be null now |
---|
3812 | if (userTest->getUserData(tempStr)) { |
---|
3813 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3814 | OK = false; |
---|
3815 | } |
---|
3816 | if (userTest->getUserData(tempStr2)) { |
---|
3817 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3818 | OK = false; |
---|
3819 | } |
---|
3820 | |
---|
3821 | // Test DOMUserDataHandler |
---|
3822 | // test clone |
---|
3823 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
3824 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
3825 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
3826 | |
---|
3827 | // test import |
---|
3828 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
3829 | DOMNode* myimport = document->importNode(userTest,true); |
---|
3830 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
3831 | |
---|
3832 | // test delete |
---|
3833 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
3834 | myimport->release(); |
---|
3835 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
3836 | |
---|
3837 | // Test isSameNode |
---|
3838 | if (!userTest->isSameNode(userTest)) { |
---|
3839 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
3840 | OK = false; |
---|
3841 | } |
---|
3842 | if (userTest->isSameNode(userFirst)) { |
---|
3843 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
3844 | OK = false; |
---|
3845 | } |
---|
3846 | |
---|
3847 | // Test isEqualNode |
---|
3848 | if (!userTest->isEqualNode(mycloned)) { |
---|
3849 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3850 | OK = false; |
---|
3851 | } |
---|
3852 | |
---|
3853 | if (!userTest->isEqualNode(userTest)) { |
---|
3854 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3855 | OK = false; |
---|
3856 | } |
---|
3857 | if (userTest->isEqualNode(document)) { |
---|
3858 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
3859 | OK = false; |
---|
3860 | } |
---|
3861 | |
---|
3862 | // Test rename, should throw exception |
---|
3863 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 211 ); |
---|
3864 | |
---|
3865 | if (!OK) |
---|
3866 | printf("\n*****The DOMEntityReference* method calls listed above failed, all others worked correctly.*****\n"); |
---|
3867 | return OK; |
---|
3868 | } |
---|
3869 | |
---|
3870 | |
---|
3871 | |
---|
3872 | /** |
---|
3873 | * This method tests DOMNode* methods for the XML DOM implementation |
---|
3874 | * @param document org.w3c.dom.DOMDocument |
---|
3875 | * |
---|
3876 | * |
---|
3877 | * |
---|
3878 | ********* This is only for a test of cloneNode "deep"******* |
---|
3879 | ********* And for error tests********* |
---|
3880 | */ |
---|
3881 | bool DOMTest::testNode(DOMDocument* document) |
---|
3882 | { |
---|
3883 | DOMNode* node, *node2; |
---|
3884 | bool result; |
---|
3885 | bool OK = true; |
---|
3886 | // For debugging***** printf("\n testNode's outputs:\n"); |
---|
3887 | node = document->getDocumentElement(); |
---|
3888 | node2 = node->cloneNode(true); |
---|
3889 | result = treeCompare(node, node2); // Deep clone test of cloneNode |
---|
3890 | if (result) |
---|
3891 | { |
---|
3892 | //printf("'cloneNode' successfully cloned this whole node tree (deep)!\n"); |
---|
3893 | } |
---|
3894 | else |
---|
3895 | { |
---|
3896 | fprintf(stderr, "'cloneNode' did not successfully clone this whole node tree (deep)!\n"); |
---|
3897 | OK = false; |
---|
3898 | } |
---|
3899 | //!! The following gives a did not clone successfully message********* |
---|
3900 | node = document->getDocumentElement(); |
---|
3901 | node2 = node->getFirstChild(); |
---|
3902 | result = treeCompare(node, node2); |
---|
3903 | if (!result) |
---|
3904 | { |
---|
3905 | //fprintf(stderr, "'cloneNode' did not successfully clone this whole node tree (deep)!\n"); |
---|
3906 | } |
---|
3907 | else |
---|
3908 | { |
---|
3909 | fprintf(stderr, "'cloneNode' was supposed to fail here, either it or 'treeCompare' failed!!!\n"); |
---|
3910 | OK = false; |
---|
3911 | } |
---|
3912 | // Deep clone test also in testDocument |
---|
3913 | |
---|
3914 | // Test the user data |
---|
3915 | // Test simple set and get |
---|
3916 | DOMNode* userTest = node; |
---|
3917 | DOMNode* userFirst = node2; |
---|
3918 | XMLCh* userSecond = tempStr2; |
---|
3919 | XMLString::transcode("first", tempStr, 3999); |
---|
3920 | |
---|
3921 | XMLString::transcode("document", tempStr2, 3999); |
---|
3922 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
3923 | void* mydocument = userTest->getUserData(tempStr2); |
---|
3924 | if (document != mydocument) { |
---|
3925 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3926 | OK = false; |
---|
3927 | } |
---|
3928 | |
---|
3929 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
3930 | void* myFirst = userTest->getUserData(tempStr); |
---|
3931 | if (userFirst != myFirst) { |
---|
3932 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
3933 | OK = false; |
---|
3934 | } |
---|
3935 | |
---|
3936 | // Test overwrite |
---|
3937 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
3938 | void* mySecond = userTest->getUserData(tempStr); |
---|
3939 | if (userSecond != mySecond) { |
---|
3940 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3941 | OK = false; |
---|
3942 | } |
---|
3943 | if (userFirst != myFirst2) { |
---|
3944 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3945 | OK = false; |
---|
3946 | } |
---|
3947 | if (userFirst == mySecond) { |
---|
3948 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3949 | OK = false; |
---|
3950 | } |
---|
3951 | |
---|
3952 | // Test null |
---|
3953 | // test non-exist key |
---|
3954 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
3955 | if (userTest->getUserData(tempStr3)) { |
---|
3956 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3957 | OK = false; |
---|
3958 | } |
---|
3959 | |
---|
3960 | // use a node that does not have user data set before |
---|
3961 | if (userFirst->getUserData(tempStr)) { |
---|
3962 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3963 | OK = false; |
---|
3964 | } |
---|
3965 | |
---|
3966 | // Test reset |
---|
3967 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
3968 | void* myNull = userTest->getUserData(tempStr); |
---|
3969 | if (userSecond != mySecond2) { |
---|
3970 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3971 | OK = false; |
---|
3972 | } |
---|
3973 | if (myNull) { |
---|
3974 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3975 | OK = false; |
---|
3976 | } |
---|
3977 | |
---|
3978 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
3979 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
3980 | if (mydocument != mydocument2) { |
---|
3981 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3982 | OK = false; |
---|
3983 | } |
---|
3984 | if (myNull2) { |
---|
3985 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
3986 | OK = false; |
---|
3987 | } |
---|
3988 | |
---|
3989 | //the userTest user data table should be null now |
---|
3990 | if (userTest->getUserData(tempStr)) { |
---|
3991 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3992 | OK = false; |
---|
3993 | } |
---|
3994 | if (userTest->getUserData(tempStr2)) { |
---|
3995 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
3996 | OK = false; |
---|
3997 | } |
---|
3998 | |
---|
3999 | // Test DOMUserDataHandler |
---|
4000 | // test clone |
---|
4001 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
4002 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
4003 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
4004 | |
---|
4005 | // test import |
---|
4006 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
4007 | DOMNode* myimport = document->importNode(userTest,true); |
---|
4008 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
4009 | |
---|
4010 | // test delete |
---|
4011 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
4012 | myimport->release(); |
---|
4013 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
4014 | |
---|
4015 | // Test isSameNode |
---|
4016 | if (!userTest->isSameNode(userTest)) { |
---|
4017 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
4018 | OK = false; |
---|
4019 | } |
---|
4020 | if (userTest->isSameNode(userFirst)) { |
---|
4021 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
4022 | OK = false; |
---|
4023 | } |
---|
4024 | |
---|
4025 | // Test isEqualNode |
---|
4026 | if (!userTest->isEqualNode(mycloned)) { |
---|
4027 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4028 | OK = false; |
---|
4029 | } |
---|
4030 | |
---|
4031 | if (!userTest->isEqualNode(userTest)) { |
---|
4032 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4033 | OK = false; |
---|
4034 | } |
---|
4035 | if (userTest->isEqualNode(document)) { |
---|
4036 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4037 | OK = false; |
---|
4038 | } |
---|
4039 | |
---|
4040 | if (!OK) |
---|
4041 | printf("\n*****The DOMNode* method calls listed above failed, all others worked correctly.*****\n"); |
---|
4042 | return OK; |
---|
4043 | } |
---|
4044 | |
---|
4045 | |
---|
4046 | |
---|
4047 | /** |
---|
4048 | * This method tests DOMNotation* methods for the XML DOM implementation |
---|
4049 | * @param document org.w3c.dom.DOMDocument |
---|
4050 | * |
---|
4051 | */ |
---|
4052 | bool DOMTest::testNotation(DOMDocument* document) |
---|
4053 | { |
---|
4054 | DOMNode* node, *node2; |
---|
4055 | DOMNotation* notation; |
---|
4056 | bool OK = true; |
---|
4057 | // For debugging***** printf("\n testNotation's outputs:\n"); |
---|
4058 | XMLString::transcode("ourNotationNode", tempStr, 3999); |
---|
4059 | DOMNode* abc40 = document->getDoctype()->getNotations()->getNamedItem(tempStr); |
---|
4060 | notation = (DOMNotation*) abc40; |
---|
4061 | node = notation; |
---|
4062 | node2 = notation->cloneNode(true);//*****? |
---|
4063 | // Check nodes for equality, both their name and value or lack thereof |
---|
4064 | if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality |
---|
4065 | (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
4066 | ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
4067 | : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
4068 | { |
---|
4069 | fprintf(stderr, "'cloneNode' did not clone the DOMNotation* node correctly"); |
---|
4070 | OK = false; |
---|
4071 | } |
---|
4072 | // Deep clone test comparison is in testNode & testDocument |
---|
4073 | |
---|
4074 | // notation->setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** |
---|
4075 | |
---|
4076 | // Test the user data |
---|
4077 | // Test simple set and get |
---|
4078 | DOMNotation* userTest = notation; |
---|
4079 | DOMNode* userFirst = node2; |
---|
4080 | XMLCh* userSecond = tempStr2; |
---|
4081 | XMLString::transcode("first", tempStr, 3999); |
---|
4082 | |
---|
4083 | XMLString::transcode("document", tempStr2, 3999); |
---|
4084 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
4085 | void* mydocument = userTest->getUserData(tempStr2); |
---|
4086 | if (document != mydocument) { |
---|
4087 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
4088 | OK = false; |
---|
4089 | } |
---|
4090 | |
---|
4091 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
4092 | void* myFirst = userTest->getUserData(tempStr); |
---|
4093 | if (userFirst != myFirst) { |
---|
4094 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
4095 | OK = false; |
---|
4096 | } |
---|
4097 | |
---|
4098 | // Test overwrite |
---|
4099 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
4100 | void* mySecond = userTest->getUserData(tempStr); |
---|
4101 | if (userSecond != mySecond) { |
---|
4102 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4103 | OK = false; |
---|
4104 | } |
---|
4105 | if (userFirst != myFirst2) { |
---|
4106 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4107 | OK = false; |
---|
4108 | } |
---|
4109 | if (userFirst == mySecond) { |
---|
4110 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4111 | OK = false; |
---|
4112 | } |
---|
4113 | |
---|
4114 | // Test null |
---|
4115 | // test non-exist key |
---|
4116 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
4117 | if (userTest->getUserData(tempStr3)) { |
---|
4118 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4119 | OK = false; |
---|
4120 | } |
---|
4121 | |
---|
4122 | // use a node that does not have user data set before |
---|
4123 | if (userFirst->getUserData(tempStr)) { |
---|
4124 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4125 | OK = false; |
---|
4126 | } |
---|
4127 | |
---|
4128 | // Test reset |
---|
4129 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
4130 | void* myNull = userTest->getUserData(tempStr); |
---|
4131 | if (userSecond != mySecond2) { |
---|
4132 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4133 | OK = false; |
---|
4134 | } |
---|
4135 | if (myNull) { |
---|
4136 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4137 | OK = false; |
---|
4138 | } |
---|
4139 | |
---|
4140 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
4141 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
4142 | if (mydocument != mydocument2) { |
---|
4143 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4144 | OK = false; |
---|
4145 | } |
---|
4146 | if (myNull2) { |
---|
4147 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4148 | OK = false; |
---|
4149 | } |
---|
4150 | |
---|
4151 | //the userTest user data table should be null now |
---|
4152 | if (userTest->getUserData(tempStr)) { |
---|
4153 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4154 | OK = false; |
---|
4155 | } |
---|
4156 | if (userTest->getUserData(tempStr2)) { |
---|
4157 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4158 | OK = false; |
---|
4159 | } |
---|
4160 | |
---|
4161 | // Test DOMUserDataHandler |
---|
4162 | // test clone |
---|
4163 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
4164 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
4165 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
4166 | |
---|
4167 | // test import |
---|
4168 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
4169 | DOMNode* myimport = document->importNode(userTest,true); |
---|
4170 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
4171 | |
---|
4172 | // test delete |
---|
4173 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
4174 | myimport->release(); |
---|
4175 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
4176 | |
---|
4177 | // Test isSameNode |
---|
4178 | if (!userTest->isSameNode(userTest)) { |
---|
4179 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
4180 | OK = false; |
---|
4181 | } |
---|
4182 | if (userTest->isSameNode(userFirst)) { |
---|
4183 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
4184 | OK = false; |
---|
4185 | } |
---|
4186 | |
---|
4187 | // Test isEqualNode |
---|
4188 | if (!userTest->isEqualNode(mycloned)) { |
---|
4189 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4190 | OK = false; |
---|
4191 | } |
---|
4192 | |
---|
4193 | if (!userTest->isEqualNode(userTest)) { |
---|
4194 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4195 | OK = false; |
---|
4196 | } |
---|
4197 | if (userTest->isEqualNode(document)) { |
---|
4198 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4199 | OK = false; |
---|
4200 | } |
---|
4201 | |
---|
4202 | // Test rename, should throw exception |
---|
4203 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 212 ); |
---|
4204 | |
---|
4205 | if (!OK) |
---|
4206 | printf("\n*****The DOMNotation* method calls listed above failed, all others worked correctly.*****\n"); |
---|
4207 | return OK; |
---|
4208 | } |
---|
4209 | |
---|
4210 | |
---|
4211 | |
---|
4212 | /** |
---|
4213 | * This method tests DOMProcessingInstruction* methods for the XML DOM implementation |
---|
4214 | * @param document org.w3c.dom.DOMDocument |
---|
4215 | * |
---|
4216 | */ |
---|
4217 | bool DOMTest::testPI(DOMDocument* document) |
---|
4218 | { |
---|
4219 | DOMProcessingInstruction* pI, *pI2; |
---|
4220 | bool OK = true; |
---|
4221 | // For debugging***** printf("\n testPI's outputs:\n"); |
---|
4222 | DOMNode* abc50 = document->getDocumentElement()->getFirstChild();// Get doc's DOMProcessingInstruction |
---|
4223 | pI = (DOMProcessingInstruction*) abc50; |
---|
4224 | DOMNode* abc51 = pI->cloneNode(true);//*****? |
---|
4225 | pI2 = (DOMProcessingInstruction*) abc51; |
---|
4226 | // Check nodes for equality, both their name and value or lack thereof |
---|
4227 | if (!(!XMLString::compareString(pI->getNodeName(), pI2->getNodeName()) && // Compares node names for equality |
---|
4228 | (pI->getNodeValue() != 0 && pI2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
4229 | ? !XMLString::compareString(pI->getNodeValue(), pI2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
4230 | :(pI->getNodeValue() == 0 && pI2->getNodeValue() == 0)))// If one node doesn't have a value node make sure both don't |
---|
4231 | { |
---|
4232 | fprintf(stderr, "'cloneNode' did not clone the DOMEntity* node correctly\n"); |
---|
4233 | OK = false; |
---|
4234 | } |
---|
4235 | // Deep clone test comparison is in testNode & testDocument |
---|
4236 | // compare = "This is [#document: 0]'s processing instruction"; // AH Revisit. Where id |
---|
4237 | // this ": 0]" stuff come from in the Java version?? I don' think that it is right. |
---|
4238 | XMLString::transcode("This is #document's processing instruction", tempStr, 3999); |
---|
4239 | if (XMLString::compareString(tempStr, pI->getData())) |
---|
4240 | { |
---|
4241 | fprintf(stderr, "Warning!!! PI's 'getData' failed!\n"); |
---|
4242 | OK = false; |
---|
4243 | } |
---|
4244 | |
---|
4245 | XMLString::transcode("PI's reset data", tempStr, 3999); |
---|
4246 | pI->setData(tempStr); |
---|
4247 | if (XMLString::compareString(tempStr, pI->getData())) |
---|
4248 | { |
---|
4249 | fprintf(stderr, "Warning!!! PI's 'setData' failed!\n"); |
---|
4250 | OK = false; |
---|
4251 | } |
---|
4252 | XMLString::transcode("dTargetProcessorChannel", tempStr, 3999); |
---|
4253 | if (XMLString::compareString(tempStr, pI->getTarget())) |
---|
4254 | { |
---|
4255 | fprintf(stderr, "Warning!!! PI's 'getTarget' failed!\n"); |
---|
4256 | OK = false; |
---|
4257 | } |
---|
4258 | |
---|
4259 | |
---|
4260 | // Restore original PI data. |
---|
4261 | XMLString::transcode("This is #document's processing instruction", tempStr, 3999); |
---|
4262 | pI->setData(tempStr); |
---|
4263 | |
---|
4264 | // Test the user data |
---|
4265 | // Test simple set and get |
---|
4266 | DOMProcessingInstruction* userTest = pI; |
---|
4267 | DOMNode* userFirst = abc51; |
---|
4268 | XMLCh* userSecond = tempStr2; |
---|
4269 | XMLString::transcode("first", tempStr, 3999); |
---|
4270 | |
---|
4271 | XMLString::transcode("document", tempStr2, 3999); |
---|
4272 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
4273 | void* mydocument = userTest->getUserData(tempStr2); |
---|
4274 | if (document != mydocument) { |
---|
4275 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
4276 | OK = false; |
---|
4277 | } |
---|
4278 | |
---|
4279 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
4280 | void* myFirst = userTest->getUserData(tempStr); |
---|
4281 | if (userFirst != myFirst) { |
---|
4282 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
4283 | OK = false; |
---|
4284 | } |
---|
4285 | |
---|
4286 | // Test overwrite |
---|
4287 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
4288 | void* mySecond = userTest->getUserData(tempStr); |
---|
4289 | if (userSecond != mySecond) { |
---|
4290 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4291 | OK = false; |
---|
4292 | } |
---|
4293 | if (userFirst != myFirst2) { |
---|
4294 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4295 | OK = false; |
---|
4296 | } |
---|
4297 | if (userFirst == mySecond) { |
---|
4298 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4299 | OK = false; |
---|
4300 | } |
---|
4301 | |
---|
4302 | // Test null |
---|
4303 | // test non-exist key |
---|
4304 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
4305 | if (userTest->getUserData(tempStr3)) { |
---|
4306 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4307 | OK = false; |
---|
4308 | } |
---|
4309 | |
---|
4310 | // use a node that does not have user data set before |
---|
4311 | if (abc51->getUserData(tempStr)) { |
---|
4312 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4313 | OK = false; |
---|
4314 | } |
---|
4315 | |
---|
4316 | // Test reset(reset) |
---|
4317 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
4318 | void* myNull = userTest->getUserData(tempStr); |
---|
4319 | if (userSecond != mySecond2) { |
---|
4320 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4321 | OK = false; |
---|
4322 | } |
---|
4323 | if (myNull) { |
---|
4324 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4325 | OK = false; |
---|
4326 | } |
---|
4327 | |
---|
4328 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
4329 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
4330 | if (mydocument != mydocument2) { |
---|
4331 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4332 | OK = false; |
---|
4333 | } |
---|
4334 | if (myNull2) { |
---|
4335 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4336 | OK = false; |
---|
4337 | } |
---|
4338 | |
---|
4339 | //the userTest user data table should be null now |
---|
4340 | if (userTest->getUserData(tempStr)) { |
---|
4341 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4342 | OK = false; |
---|
4343 | } |
---|
4344 | if (userTest->getUserData(tempStr2)) { |
---|
4345 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4346 | OK = false; |
---|
4347 | } |
---|
4348 | |
---|
4349 | // Test DOMUserDataHandler |
---|
4350 | // test clone |
---|
4351 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
4352 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
4353 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
4354 | |
---|
4355 | // test import |
---|
4356 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
4357 | DOMNode* myimport = document->importNode(userTest,true); |
---|
4358 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
4359 | |
---|
4360 | // test delete |
---|
4361 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
4362 | myimport->release(); |
---|
4363 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
4364 | |
---|
4365 | // Test isSameNode |
---|
4366 | if (!userTest->isSameNode(userTest)) { |
---|
4367 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
4368 | OK = false; |
---|
4369 | } |
---|
4370 | if (userTest->isSameNode(userFirst)) { |
---|
4371 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
4372 | OK = false; |
---|
4373 | } |
---|
4374 | |
---|
4375 | // Test isEqualNode |
---|
4376 | if (!userTest->isEqualNode(mycloned)) { |
---|
4377 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4378 | OK = false; |
---|
4379 | } |
---|
4380 | |
---|
4381 | if (!userTest->isEqualNode(userTest)) { |
---|
4382 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4383 | OK = false; |
---|
4384 | } |
---|
4385 | if (userTest->isEqualNode(document)) { |
---|
4386 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4387 | OK = false; |
---|
4388 | } |
---|
4389 | |
---|
4390 | // Test rename, should throw exception |
---|
4391 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 213 ); |
---|
4392 | |
---|
4393 | if (!OK) |
---|
4394 | printf("\n*****The PI method calls listed above failed, all others worked correctly.*****\n"); |
---|
4395 | |
---|
4396 | return OK; |
---|
4397 | } |
---|
4398 | |
---|
4399 | |
---|
4400 | |
---|
4401 | /** |
---|
4402 | * This method tests DOMText* methods for the XML DOM implementation |
---|
4403 | * @param document org.w3c.dom.DOMDocument |
---|
4404 | * |
---|
4405 | */ |
---|
4406 | bool DOMTest::testText(DOMDocument* document) |
---|
4407 | { |
---|
4408 | DOMNode* node, *node2; |
---|
4409 | DOMText* text; |
---|
4410 | bool OK = true; |
---|
4411 | // For debugging***** printf("\n testText's outputs:\n"); |
---|
4412 | XMLString::transcode("dBodyLevel31", tempStr, 3999); |
---|
4413 | DOMNode* abc70 = document->getDocumentElement()->getElementsByTagName(tempStr)->item(0); |
---|
4414 | DOMElement* elem = (DOMElement*) abc70; |
---|
4415 | node = elem->getFirstChild(); // charData gets textNode11 |
---|
4416 | text = (DOMText*) node; |
---|
4417 | node2 = node->cloneNode(true);//*****? |
---|
4418 | // Check nodes for equality, both their name and value or lack thereof |
---|
4419 | if (!(!XMLString::compareString(node->getNodeName(), node2->getNodeName()) && // Compares node names for equality |
---|
4420 | (node->getNodeValue() != 0 && node2->getNodeValue() != 0) // Checks to make sure each node has a value node |
---|
4421 | ? !XMLString::compareString(node->getNodeValue(), node2->getNodeValue()) // If both have value nodes test those value nodes for equality |
---|
4422 | : (node->getNodeValue() == 0 && node2->getNodeValue() == 0))) // If one node doesn't have a value node make sure both don't |
---|
4423 | { |
---|
4424 | fprintf(stderr, "'cloneNode' did not clone the DOMText* node correctly\n"); |
---|
4425 | OK = false; |
---|
4426 | } |
---|
4427 | // Deep clone test comparison is in testNode & testDocument |
---|
4428 | |
---|
4429 | text->splitText(25); |
---|
4430 | // Three original text nodes were concatenated by 'normalize' in testElement |
---|
4431 | XMLString::transcode("dBodyLevel31'sChildTextNo", tempStr, 3999); |
---|
4432 | if (XMLString::compareString(tempStr, text->getNodeValue())) |
---|
4433 | { |
---|
4434 | fprintf(stderr, "First part of DOMText's split text failed!\n" ); |
---|
4435 | OK = false; |
---|
4436 | } |
---|
4437 | // Three original text nodes were concatenated by 'normalize' in testElement |
---|
4438 | XMLString::transcode("de11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13", tempStr, 3999); |
---|
4439 | if (XMLString::compareString(tempStr, text->getNextSibling()->getNodeValue())) |
---|
4440 | { |
---|
4441 | fprintf(stderr, "The second part of DOMText's split text failed!\n") ; |
---|
4442 | OK = false; |
---|
4443 | } |
---|
4444 | |
---|
4445 | // Re-normalize the text nodes under elem, so that this test can be rerun-> |
---|
4446 | elem->normalize(); |
---|
4447 | |
---|
4448 | |
---|
4449 | //************************************************* ERROR TESTS |
---|
4450 | DOMTest tests; |
---|
4451 | //!! Throws INDEX_SIZE_ERR ******************** |
---|
4452 | // text.splitText(-1); |
---|
4453 | // text.splitText(100); |
---|
4454 | |
---|
4455 | // Test the user data |
---|
4456 | // Test simple set and get |
---|
4457 | DOMText* userTest = text; |
---|
4458 | DOMNode* userFirst = node2; |
---|
4459 | XMLCh* userSecond = tempStr2; |
---|
4460 | XMLString::transcode("first", tempStr, 3999); |
---|
4461 | |
---|
4462 | XMLString::transcode("document", tempStr2, 3999); |
---|
4463 | userTest->setUserData(tempStr2, (void*) document, 0); |
---|
4464 | void* mydocument = userTest->getUserData(tempStr2); |
---|
4465 | if (document != mydocument) { |
---|
4466 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
4467 | OK = false; |
---|
4468 | } |
---|
4469 | |
---|
4470 | userTest->setUserData(tempStr, (void*) userFirst, 0); |
---|
4471 | void* myFirst = userTest->getUserData(tempStr); |
---|
4472 | if (userFirst != myFirst) { |
---|
4473 | fprintf(stderr, "'set/getUserData' in line %i does not work\n", __LINE__); |
---|
4474 | OK = false; |
---|
4475 | } |
---|
4476 | |
---|
4477 | // Test overwrite |
---|
4478 | void* myFirst2 = userTest->setUserData(tempStr, (void*) userSecond, 0); |
---|
4479 | void* mySecond = userTest->getUserData(tempStr); |
---|
4480 | if (userSecond != mySecond) { |
---|
4481 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4482 | OK = false; |
---|
4483 | } |
---|
4484 | if (userFirst != myFirst2) { |
---|
4485 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4486 | OK = false; |
---|
4487 | } |
---|
4488 | if (userFirst == mySecond) { |
---|
4489 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4490 | OK = false; |
---|
4491 | } |
---|
4492 | |
---|
4493 | // Test null |
---|
4494 | // test non-exist key |
---|
4495 | XMLString::transcode("not-exist", tempStr3, 3999); |
---|
4496 | if (userTest->getUserData(tempStr3)) { |
---|
4497 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4498 | OK = false; |
---|
4499 | } |
---|
4500 | |
---|
4501 | // use a node that does not have user data set before |
---|
4502 | if (userFirst->getUserData(tempStr)) { |
---|
4503 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4504 | OK = false; |
---|
4505 | } |
---|
4506 | |
---|
4507 | // Test reset |
---|
4508 | void* mySecond2 = userTest->setUserData(tempStr, (void*) 0, 0); |
---|
4509 | void* myNull = userTest->getUserData(tempStr); |
---|
4510 | if (userSecond != mySecond2) { |
---|
4511 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4512 | OK = false; |
---|
4513 | } |
---|
4514 | if (myNull) { |
---|
4515 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4516 | OK = false; |
---|
4517 | } |
---|
4518 | |
---|
4519 | void* mydocument2 = userTest->setUserData(tempStr2, (void*) 0, 0); |
---|
4520 | void* myNull2 = userTest->getUserData(tempStr2); |
---|
4521 | if (mydocument != mydocument2) { |
---|
4522 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4523 | OK = false; |
---|
4524 | } |
---|
4525 | if (myNull2) { |
---|
4526 | fprintf(stderr, "overwrite userdata with same key in line %i does not work\n", __LINE__); |
---|
4527 | OK = false; |
---|
4528 | } |
---|
4529 | |
---|
4530 | //the userTest user data table should be null now |
---|
4531 | if (userTest->getUserData(tempStr)) { |
---|
4532 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4533 | OK = false; |
---|
4534 | } |
---|
4535 | if (userTest->getUserData(tempStr2)) { |
---|
4536 | fprintf(stderr, "get non-exist user data in line %i does not work\n", __LINE__); |
---|
4537 | OK = false; |
---|
4538 | } |
---|
4539 | |
---|
4540 | // Test DOMUserDataHandler |
---|
4541 | // test clone |
---|
4542 | userTest->setUserData(tempStr2, (void*) document, &userhandler); |
---|
4543 | DOMNode* mycloned = userTest->cloneNode(true); |
---|
4544 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_CLONED, tempStr2, document, userTest, mycloned, __LINE__); |
---|
4545 | |
---|
4546 | // test import |
---|
4547 | document->setUserData(tempStr2, (void*) document, &userhandler); |
---|
4548 | DOMNode* myimport = document->importNode(userTest,true); |
---|
4549 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_IMPORTED, tempStr2, document, userTest, myimport, __LINE__); |
---|
4550 | |
---|
4551 | // test delete |
---|
4552 | myimport->setUserData(tempStr2, (void*) userTest, &userhandler); |
---|
4553 | myimport->release(); |
---|
4554 | USERDATAHANDLERTEST(userhandler, DOMUserDataHandler::NODE_DELETED, tempStr2, userTest, 0, 0, __LINE__); |
---|
4555 | |
---|
4556 | // Test isSameNode |
---|
4557 | if (!userTest->isSameNode(userTest)) { |
---|
4558 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
4559 | OK = false; |
---|
4560 | } |
---|
4561 | if (userTest->isSameNode(userFirst)) { |
---|
4562 | fprintf(stderr, "isSameNode failed in line %i\n", __LINE__); |
---|
4563 | OK = false; |
---|
4564 | } |
---|
4565 | |
---|
4566 | // Test isEqualNode |
---|
4567 | if (!userTest->isEqualNode(mycloned)) { |
---|
4568 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4569 | OK = false; |
---|
4570 | } |
---|
4571 | |
---|
4572 | if (!userTest->isEqualNode(userTest)) { |
---|
4573 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4574 | OK = false; |
---|
4575 | } |
---|
4576 | if (userTest->isEqualNode(abc70)) { |
---|
4577 | fprintf(stderr, "isEqualNode failed in line %i\n", __LINE__); |
---|
4578 | OK = false; |
---|
4579 | } |
---|
4580 | |
---|
4581 | // Test rename, should throw exception |
---|
4582 | EXCEPTIONSTEST(document->renameNode(userTest, 0, tempStr2), DOMException::NOT_SUPPORTED_ERR, OK, 214 ); |
---|
4583 | |
---|
4584 | if (!OK) |
---|
4585 | printf("\n*****The DOMText* method calls listed above failed, all others worked correctly.*****\n"); |
---|
4586 | |
---|
4587 | return OK; |
---|
4588 | } |
---|
4589 | |
---|
4590 | |
---|
4591 | /** |
---|
4592 | * This method tests setting the DOM Level 3 baseURI attribute at |
---|
4593 | * parse time on nodes from the document personal-schema.xml.xml |
---|
4594 | * |
---|
4595 | */ |
---|
4596 | |
---|
4597 | bool DOMTest::testBaseURI(XercesDOMParser* parser) { |
---|
4598 | |
---|
4599 | bool OK = true; |
---|
4600 | |
---|
4601 | try { |
---|
4602 | // this one assumes executing in samples/data where personal-schema.xml resides |
---|
4603 | // please modify if this is not correct |
---|
4604 | parser->parse("personal-schema.xml"); |
---|
4605 | } |
---|
4606 | catch (const OutOfMemoryException&) |
---|
4607 | { |
---|
4608 | fprintf(stderr, "OutOfMemoryException.\n"); |
---|
4609 | return false; |
---|
4610 | } |
---|
4611 | catch (...) { |
---|
4612 | fprintf(stderr, "parsing personal-schema.xml failed at line %i\n", __LINE__); |
---|
4613 | return false; |
---|
4614 | } |
---|
4615 | |
---|
4616 | // test only if there is no error |
---|
4617 | if (!parser->getErrorCount()) { |
---|
4618 | |
---|
4619 | //Setup testing strings |
---|
4620 | XMLCh *fileSchema = XMLString::transcode("file://"); |
---|
4621 | XMLCh *filePath = XMLString::transcode("samples/data/personal-schema.xml"); |
---|
4622 | |
---|
4623 | //Test document baseURI |
---|
4624 | DOMDocument *document = parser->getDocument(); |
---|
4625 | |
---|
4626 | //The baseURI should contain `file://' and `samples/data/personal-schema.xml' |
---|
4627 | const XMLCh *docBaseURI = document->getBaseURI(); |
---|
4628 | |
---|
4629 | if(XMLString::patternMatch(docBaseURI, fileSchema) == -1) { |
---|
4630 | OK = false; |
---|
4631 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4632 | } |
---|
4633 | |
---|
4634 | if(XMLString::patternMatch(docBaseURI, filePath) == -1) { |
---|
4635 | OK = false; |
---|
4636 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4637 | } |
---|
4638 | |
---|
4639 | //Create relative paths from document baseURI |
---|
4640 | |
---|
4641 | XMLCh *docBaseURIRoot = new XMLCh [ XMLString::stringLen(docBaseURI) ]; |
---|
4642 | XMLString::copyNString(docBaseURIRoot, docBaseURI, XMLString::lastIndexOf(docBaseURI, chForwardSlash) + 1); |
---|
4643 | |
---|
4644 | XMLCh *base_foobar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 8]; |
---|
4645 | XMLString::copyString(base_foobar, docBaseURIRoot); |
---|
4646 | XMLCh *foobar = XMLString::transcode("foo/bar"); |
---|
4647 | XMLString::catString(base_foobar, foobar); |
---|
4648 | |
---|
4649 | XMLCh *base_foobarbar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 12]; |
---|
4650 | XMLString::copyString(base_foobarbar, docBaseURIRoot); |
---|
4651 | XMLCh *foobarbar = XMLString::transcode("foo/bar/bar"); |
---|
4652 | XMLString::catString(base_foobarbar, foobarbar); |
---|
4653 | |
---|
4654 | XMLCh *base_foocarbar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 12]; |
---|
4655 | XMLString::copyString(base_foocarbar, docBaseURIRoot); |
---|
4656 | XMLCh *foocarbar = XMLString::transcode("foo/car/bar"); |
---|
4657 | XMLString::catString(base_foocarbar, foocarbar); |
---|
4658 | |
---|
4659 | XMLCh *file_autobar = XMLString::transcode("file:///auto/bar"); |
---|
4660 | XMLCh *file_carfoo = XMLString::transcode("file:///car/foo/"); |
---|
4661 | XMLCh *file_carfoobarbar = XMLString::transcode("file:///car/foo/bar/bar"); |
---|
4662 | |
---|
4663 | XMLCh *http_carcar = XMLString::transcode("http://www.example.com/car/car"); |
---|
4664 | XMLCh *http_barfoo = XMLString::transcode("http://www.example.com/bar/foo/"); |
---|
4665 | XMLCh *http_barfoofoobar = XMLString::transcode("http://www.example.com/bar/foo/foo/bar"); |
---|
4666 | |
---|
4667 | //Processing instruction before Document Element (has document baseURI) |
---|
4668 | |
---|
4669 | DOMNode *node = document->getFirstChild(); |
---|
4670 | while(node->getNodeType() != DOMNode::PROCESSING_INSTRUCTION_NODE) |
---|
4671 | node = node->getNextSibling(); |
---|
4672 | |
---|
4673 | if(XMLString::compareString(node->getBaseURI(), docBaseURI) != 0) { |
---|
4674 | OK = false; |
---|
4675 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4676 | } |
---|
4677 | |
---|
4678 | //Document Element baseURI (same as document) |
---|
4679 | |
---|
4680 | node = document->getDocumentElement(); |
---|
4681 | |
---|
4682 | if(XMLString::compareString(node->getBaseURI(), docBaseURI) != 0) { |
---|
4683 | OK = false; |
---|
4684 | fprintf(stderr, "checking baseURI, failed at line %i\n", __LINE__); |
---|
4685 | } |
---|
4686 | |
---|
4687 | // <level 1> |
---|
4688 | |
---|
4689 | node = node->getFirstChild(); |
---|
4690 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4691 | node = node->getNextSibling(); |
---|
4692 | |
---|
4693 | DOMNode *level1 = node; |
---|
4694 | |
---|
4695 | // <one> |
---|
4696 | |
---|
4697 | node = node->getFirstChild(); |
---|
4698 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4699 | node = node->getNextSibling(); |
---|
4700 | |
---|
4701 | if(XMLString::compareString(node->getBaseURI(), base_foobar) != 0) { |
---|
4702 | OK = false; |
---|
4703 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4704 | } |
---|
4705 | |
---|
4706 | // <inner1> |
---|
4707 | |
---|
4708 | node = node->getFirstChild(); |
---|
4709 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4710 | node = node->getNextSibling(); |
---|
4711 | |
---|
4712 | if(XMLString::compareString(node->getBaseURI(), base_foobarbar) != 0) { |
---|
4713 | OK = false; |
---|
4714 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4715 | } |
---|
4716 | |
---|
4717 | // <inner2> |
---|
4718 | |
---|
4719 | node = node->getNextSibling(); |
---|
4720 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4721 | node = node->getNextSibling(); |
---|
4722 | |
---|
4723 | if(XMLString::compareString(node->getBaseURI(), base_foocarbar) != 0) { |
---|
4724 | OK = false; |
---|
4725 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4726 | } |
---|
4727 | |
---|
4728 | // <?proc-inst-2?> |
---|
4729 | |
---|
4730 | node = node->getNextSibling(); |
---|
4731 | while(node->getNodeType() != DOMNode::PROCESSING_INSTRUCTION_NODE) |
---|
4732 | node = node->getNextSibling(); |
---|
4733 | |
---|
4734 | if(XMLString::compareString(node->getBaseURI(), base_foobar) != 0) { |
---|
4735 | OK = false; |
---|
4736 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4737 | } |
---|
4738 | |
---|
4739 | // <level2> |
---|
4740 | |
---|
4741 | node = level1->getNextSibling(); |
---|
4742 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4743 | node = node->getNextSibling(); |
---|
4744 | |
---|
4745 | DOMNode *level2 = node; |
---|
4746 | |
---|
4747 | if(XMLString::compareString(node->getBaseURI(), file_autobar) != 0) { |
---|
4748 | OK = false; |
---|
4749 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4750 | } |
---|
4751 | |
---|
4752 | // <two> |
---|
4753 | |
---|
4754 | node = node->getFirstChild(); |
---|
4755 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4756 | node = node->getNextSibling(); |
---|
4757 | |
---|
4758 | if(XMLString::compareString(node->getBaseURI(), file_carfoo) != 0) { |
---|
4759 | OK = false; |
---|
4760 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4761 | } |
---|
4762 | |
---|
4763 | // <inner1> |
---|
4764 | |
---|
4765 | node = node->getFirstChild(); |
---|
4766 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4767 | node = node->getNextSibling(); |
---|
4768 | |
---|
4769 | if(XMLString::compareString(node->getBaseURI(), file_carfoobarbar) != 0) { |
---|
4770 | OK = false; |
---|
4771 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4772 | } |
---|
4773 | |
---|
4774 | // <level3> |
---|
4775 | |
---|
4776 | node = level2->getNextSibling(); |
---|
4777 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4778 | node = node->getNextSibling(); |
---|
4779 | |
---|
4780 | if(XMLString::compareString(node->getBaseURI(), http_carcar) != 0) { |
---|
4781 | OK = false; |
---|
4782 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4783 | } |
---|
4784 | |
---|
4785 | // <three> |
---|
4786 | |
---|
4787 | node = node->getFirstChild(); |
---|
4788 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4789 | node = node->getNextSibling(); |
---|
4790 | |
---|
4791 | if(XMLString::compareString(node->getBaseURI(), http_barfoo) != 0) { |
---|
4792 | OK = false; |
---|
4793 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4794 | } |
---|
4795 | |
---|
4796 | // <inner1> |
---|
4797 | |
---|
4798 | node = node->getFirstChild(); |
---|
4799 | while(node->getNodeType() != DOMNode::ELEMENT_NODE) |
---|
4800 | node = node->getNextSibling(); |
---|
4801 | |
---|
4802 | if(XMLString::compareString(node->getBaseURI(), http_barfoofoobar) != 0) { |
---|
4803 | OK = false; |
---|
4804 | fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__); |
---|
4805 | } |
---|
4806 | } |
---|
4807 | else { |
---|
4808 | printf("baseURI test was not carried out\n"); |
---|
4809 | } |
---|
4810 | |
---|
4811 | return OK; |
---|
4812 | } |
---|
4813 | |
---|
4814 | bool DOMTest::testWholeText(XercesDOMParser* parser) { |
---|
4815 | const char* sXml="<?xml version='1.0'?>" |
---|
4816 | "<!DOCTYPE root[" |
---|
4817 | "<!ENTITY ent1 'Dallas. &ent3; #5668'>" |
---|
4818 | "<!ENTITY ent2 '1900 Dallas Road<![CDATA[ (East) ]]>'>" |
---|
4819 | "<!ENTITY ent3 'California. &ent4; PO'> " |
---|
4820 | "<!ENTITY ent4 'USA '>" |
---|
4821 | "<!ENTITY ent5 'The Content &ent6; never reached'>" |
---|
4822 | "<!ENTITY ent6 'ends here. <foo/>'>" |
---|
4823 | "]>" |
---|
4824 | "<root>&ent1; &ent2;" |
---|
4825 | "<elem>Home </elem>" |
---|
4826 | "<elem>Test: &ent5;</elem>" |
---|
4827 | "</root>"; |
---|
4828 | MemBufInputSource is((XMLByte*)sXml, strlen(sXml), "bufId"); |
---|
4829 | parser->parse(is); |
---|
4830 | DOMDocument* doc=parser->getDocument(); |
---|
4831 | // pointing to "Dallas. " |
---|
4832 | DOMNode* t1=doc->getDocumentElement()->getFirstChild()->getFirstChild(); |
---|
4833 | if(t1==NULL || t1->getNodeType()!=DOMNode::TEXT_NODE) |
---|
4834 | { |
---|
4835 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4836 | return false; |
---|
4837 | } |
---|
4838 | const XMLCh* s1=((DOMText*)t1)->getWholeText(); |
---|
4839 | const XMLCh* refText=XMLString::transcode("Dallas. California. USA PO #5668 1900 Dallas Road (East) "); |
---|
4840 | if(XMLString::compareString(s1,refText)!=0) |
---|
4841 | { |
---|
4842 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4843 | return false; |
---|
4844 | } |
---|
4845 | |
---|
4846 | // pointing to " (East) " [CDATA] |
---|
4847 | DOMNode* t2=doc->getDocumentElement()->getFirstChild()->getNextSibling()->getNextSibling()->getFirstChild()->getNextSibling(); |
---|
4848 | if(t2==NULL || t2->getNodeType()!=DOMNode::CDATA_SECTION_NODE) |
---|
4849 | { |
---|
4850 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4851 | return false; |
---|
4852 | } |
---|
4853 | const XMLCh* s2=((DOMText*)t2)->getWholeText(); |
---|
4854 | if(XMLString::compareString(s2,refText)!=0) |
---|
4855 | { |
---|
4856 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4857 | return false; |
---|
4858 | } |
---|
4859 | |
---|
4860 | // pointing to "Home " |
---|
4861 | DOMNode* t3=doc->getDocumentElement()->getFirstChild()->getNextSibling()->getNextSibling()->getNextSibling()->getFirstChild(); |
---|
4862 | if(t3==NULL || t3->getNodeType()!=DOMNode::TEXT_NODE) |
---|
4863 | { |
---|
4864 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4865 | return false; |
---|
4866 | } |
---|
4867 | const XMLCh* s3=((DOMText*)t3)->getWholeText(); |
---|
4868 | refText=XMLString::transcode("Home "); |
---|
4869 | if(XMLString::compareString(s3,refText)!=0) |
---|
4870 | { |
---|
4871 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4872 | return false; |
---|
4873 | } |
---|
4874 | |
---|
4875 | // pointing to "The Content " |
---|
4876 | DOMNode* t4=doc->getDocumentElement()->getFirstChild()->getNextSibling()->getNextSibling()->getNextSibling()->getNextSibling()->getFirstChild()->getNextSibling()->getFirstChild(); |
---|
4877 | if(t4==NULL || t4->getNodeType()!=DOMNode::TEXT_NODE) |
---|
4878 | { |
---|
4879 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4880 | return false; |
---|
4881 | } |
---|
4882 | const XMLCh* s4=((DOMText*)t4)->getWholeText(); |
---|
4883 | refText=XMLString::transcode("Test: The Content ends here. "); |
---|
4884 | if(XMLString::compareString(s4,refText)!=0) |
---|
4885 | { |
---|
4886 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4887 | return false; |
---|
4888 | } |
---|
4889 | |
---|
4890 | DOMNode* newt2=((DOMText*)t2)->replaceWholeText(s2); |
---|
4891 | UNUSED(newt2); //silence warning |
---|
4892 | DOMNode* newt3=((DOMText*)t3)->replaceWholeText(s3); |
---|
4893 | UNUSED(newt3); //silence warning |
---|
4894 | try |
---|
4895 | { |
---|
4896 | DOMNode* newt4=((DOMText*)t4)->replaceWholeText(s4); |
---|
4897 | UNUSED(newt4); //silence warning |
---|
4898 | // ent5 contains a <foo/> node, and cannot be removed |
---|
4899 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4900 | return false; |
---|
4901 | } |
---|
4902 | catch(DOMException&) |
---|
4903 | { |
---|
4904 | } |
---|
4905 | |
---|
4906 | DOMLSSerializer* writer=DOMImplementation::getImplementation()->createLSSerializer(); |
---|
4907 | const XMLCh* xml=writer->writeToString(doc->getDocumentElement()); |
---|
4908 | |
---|
4909 | refText=XMLString::transcode("<root><![CDATA[Dallas. California. USA PO #5668 1900 Dallas Road (East) ]]>" |
---|
4910 | "<elem>Home </elem>" |
---|
4911 | "<elem>Test: &ent5;</elem>" |
---|
4912 | "</root>"); |
---|
4913 | if(XMLString::compareString(xml,refText)!=0) |
---|
4914 | { |
---|
4915 | fprintf(stderr, "checking wholeText failed at line %i\n", __LINE__); |
---|
4916 | return false; |
---|
4917 | } |
---|
4918 | writer->release(); |
---|
4919 | return true; |
---|
4920 | } |
---|
4921 | |
---|
4922 | class ParserAborter : public DOMLSParserFilter |
---|
4923 | { |
---|
4924 | public: |
---|
4925 | ParserAborter() {} |
---|
4926 | |
---|
4927 | virtual FilterAction acceptNode(DOMNode* ) { return DOMLSParserFilter::FILTER_INTERRUPT; } |
---|
4928 | virtual FilterAction startElement(DOMElement* ) { return DOMLSParserFilter::FILTER_INTERRUPT; } |
---|
4929 | virtual DOMNodeFilter::ShowType getWhatToShow() const { return DOMNodeFilter::SHOW_ALL; } |
---|
4930 | }; |
---|
4931 | |
---|
4932 | class ParserNester : public DOMLSParserFilter |
---|
4933 | { |
---|
4934 | public: |
---|
4935 | ParserNester(DOMLSParser* parser, DOMLSInput* input) { m_parser=parser; m_input=input; } |
---|
4936 | |
---|
4937 | virtual FilterAction acceptNode(DOMNode* ) { m_parser->parse(m_input); return DOMLSParserFilter::FILTER_ACCEPT;} |
---|
4938 | virtual FilterAction startElement(DOMElement* ) { return DOMLSParserFilter::FILTER_ACCEPT; } |
---|
4939 | virtual DOMNodeFilter::ShowType getWhatToShow() const { return DOMNodeFilter::SHOW_ALL; } |
---|
4940 | |
---|
4941 | DOMLSParser* m_parser; |
---|
4942 | DOMLSInput* m_input; |
---|
4943 | }; |
---|
4944 | |
---|
4945 | class ParserSkipper : public DOMLSParserFilter |
---|
4946 | { |
---|
4947 | public: |
---|
4948 | ParserSkipper() : fCallbackCalls(0) { } |
---|
4949 | |
---|
4950 | virtual FilterAction acceptNode(DOMNode* node) { fCallbackCalls++; return DOMLSParserFilter::FILTER_ACCEPT;} |
---|
4951 | virtual FilterAction startElement(DOMElement* node) |
---|
4952 | { |
---|
4953 | XMLCh elem[]={chLatin_e, chLatin_l, chLatin_e, chLatin_m, chNull }; |
---|
4954 | if(XMLString::equals(node->getNodeName(), elem)) |
---|
4955 | return DOMLSParserFilter::FILTER_REJECT; |
---|
4956 | else |
---|
4957 | return DOMLSParserFilter::FILTER_ACCEPT; |
---|
4958 | } |
---|
4959 | virtual DOMNodeFilter::ShowType getWhatToShow() const { return DOMNodeFilter::SHOW_ALL; } |
---|
4960 | |
---|
4961 | unsigned int fCallbackCalls; |
---|
4962 | }; |
---|
4963 | |
---|
4964 | bool DOMTest::testLSExceptions() { |
---|
4965 | bool OK = true; |
---|
4966 | |
---|
4967 | const char* sXml="<?xml version='1.0'?>" |
---|
4968 | "<!DOCTYPE root[" |
---|
4969 | "<!ENTITY ent1 'Dallas. &ent3; #5668'>" |
---|
4970 | "<!ENTITY ent2 '1900 Dallas Road<![CDATA[ (East) ]]>'>" |
---|
4971 | "<!ENTITY ent3 'California. &ent4; PO'> " |
---|
4972 | "<!ENTITY ent4 'USA '>" |
---|
4973 | "<!ENTITY ent5 'The Content &ent6; never reached'>" |
---|
4974 | "<!ENTITY ent6 'ends here. <foo/>'>" |
---|
4975 | "]>" |
---|
4976 | "<root>&ent1; &ent2;" |
---|
4977 | "<elem>Home </elem>" |
---|
4978 | "<elem>Test: &ent5;</elem>" |
---|
4979 | "</root>"; |
---|
4980 | |
---|
4981 | static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; |
---|
4982 | DOMImplementationLS *impl = (DOMImplementationLS*)DOMImplementationRegistry::getDOMImplementation(gLS); |
---|
4983 | DOMLSParser *domBuilder = impl->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0); |
---|
4984 | DOMLSInput *input = impl->createLSInput(); |
---|
4985 | XMLString::transcode(sXml, tempStr, 3999); |
---|
4986 | input->setStringData(tempStr); |
---|
4987 | try |
---|
4988 | { |
---|
4989 | ParserAborter aborter; |
---|
4990 | domBuilder->setFilter(&aborter); |
---|
4991 | DOMDocument* doc=domBuilder->parse(input); |
---|
4992 | |
---|
4993 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
4994 | OK=false; |
---|
4995 | } |
---|
4996 | catch(DOMLSException& e) |
---|
4997 | { |
---|
4998 | if(e.code!=DOMLSException::PARSE_ERR) |
---|
4999 | { |
---|
5000 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5001 | OK=false; |
---|
5002 | } |
---|
5003 | } |
---|
5004 | |
---|
5005 | try |
---|
5006 | { |
---|
5007 | ParserNester nester(domBuilder, input); |
---|
5008 | domBuilder->setFilter(&nester); |
---|
5009 | DOMDocument* doc=domBuilder->parse(input); |
---|
5010 | |
---|
5011 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5012 | OK=false; |
---|
5013 | } |
---|
5014 | catch(DOMException& e) |
---|
5015 | { |
---|
5016 | if(e.code!=DOMException::INVALID_STATE_ERR) |
---|
5017 | { |
---|
5018 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5019 | OK=false; |
---|
5020 | } |
---|
5021 | } |
---|
5022 | |
---|
5023 | try |
---|
5024 | { |
---|
5025 | ParserSkipper skipper; |
---|
5026 | domBuilder->setFilter(&skipper); |
---|
5027 | domBuilder->getDomConfig()->setParameter(XMLUni::fgDOMEntities, false); |
---|
5028 | DOMDocument* doc=domBuilder->parse(input); |
---|
5029 | |
---|
5030 | // verify that we get only 3 calls: for the text node, the CDATA section and the root element |
---|
5031 | if(doc==NULL || doc->getDocumentElement()==NULL || doc->getDocumentElement()->getChildElementCount()!=0 || skipper.fCallbackCalls!=3) |
---|
5032 | { |
---|
5033 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5034 | OK=false; |
---|
5035 | } |
---|
5036 | } |
---|
5037 | catch(DOMException&) |
---|
5038 | { |
---|
5039 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5040 | OK=false; |
---|
5041 | } |
---|
5042 | |
---|
5043 | // this XML should trigger reuse of DOMElement |
---|
5044 | const char* sXml2="<?xml version='1.0'?>" |
---|
5045 | "<root xmlns:x='urn:yyy'>" |
---|
5046 | "<elem xmlns:x='urn:xxx'>Home</elem>" |
---|
5047 | "<elem2>Test</elem2>" |
---|
5048 | "<elem>Home</elem>" |
---|
5049 | "<elem2>Test</elem2>" |
---|
5050 | "</root>"; |
---|
5051 | XMLString::transcode(sXml2, tempStr, 3999); |
---|
5052 | input->setStringData(tempStr); |
---|
5053 | try |
---|
5054 | { |
---|
5055 | ParserSkipper skipper; |
---|
5056 | domBuilder->setFilter(&skipper); |
---|
5057 | DOMDocument* doc=domBuilder->parse(input); |
---|
5058 | |
---|
5059 | // verify that we get only 5 calls: for the root element, the two elem2 and the two text nodes under them |
---|
5060 | if(doc==NULL || doc->getDocumentElement()==NULL || doc->getDocumentElement()->getChildElementCount()!=2 || skipper.fCallbackCalls!=5) |
---|
5061 | { |
---|
5062 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5063 | OK=false; |
---|
5064 | } |
---|
5065 | } |
---|
5066 | catch(DOMException&) |
---|
5067 | { |
---|
5068 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5069 | OK=false; |
---|
5070 | } |
---|
5071 | |
---|
5072 | // test for parseWithContext |
---|
5073 | try |
---|
5074 | { |
---|
5075 | XMLString::transcode("root", tempStr2, 3999); |
---|
5076 | domBuilder->setFilter(NULL); |
---|
5077 | DOMDocument* doc=domBuilder->parse(input); |
---|
5078 | domBuilder->parseWithContext(input, doc->getDocumentElement()->getFirstElementChild(), DOMLSParser::ACTION_APPEND_AS_CHILDREN); |
---|
5079 | // the first 'elem' child of 'root' must have a 'root' child |
---|
5080 | if(!XMLString::equals(doc->getDocumentElement()->getFirstElementChild()->getFirstElementChild()->getNodeName(), tempStr2)) |
---|
5081 | { |
---|
5082 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5083 | OK=false; |
---|
5084 | } |
---|
5085 | |
---|
5086 | doc=domBuilder->parse(input); |
---|
5087 | domBuilder->parseWithContext(input, doc->getDocumentElement()->getFirstElementChild(), DOMLSParser::ACTION_REPLACE_CHILDREN); |
---|
5088 | // the first 'elem' child of 'root' must have a 'root' child |
---|
5089 | if(!XMLString::equals(doc->getDocumentElement()->getFirstElementChild()->getFirstElementChild()->getNodeName(), tempStr2)) |
---|
5090 | { |
---|
5091 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5092 | OK=false; |
---|
5093 | } |
---|
5094 | |
---|
5095 | doc=domBuilder->parse(input); |
---|
5096 | domBuilder->parseWithContext(input, doc->getDocumentElement()->getFirstElementChild(), DOMLSParser::ACTION_INSERT_BEFORE); |
---|
5097 | // the first child of 'root' must be another 'root' child |
---|
5098 | if(!XMLString::equals(doc->getDocumentElement()->getFirstElementChild()->getNodeName(), tempStr2)) |
---|
5099 | { |
---|
5100 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5101 | OK=false; |
---|
5102 | } |
---|
5103 | |
---|
5104 | doc=domBuilder->parse(input); |
---|
5105 | domBuilder->parseWithContext(input, doc->getDocumentElement()->getFirstElementChild(), DOMLSParser::ACTION_INSERT_AFTER); |
---|
5106 | // the node after the first child of 'root' must be another 'root' child |
---|
5107 | if(!XMLString::equals(doc->getDocumentElement()->getFirstElementChild()->getNextElementSibling()->getNodeName(), tempStr2)) |
---|
5108 | { |
---|
5109 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5110 | OK=false; |
---|
5111 | } |
---|
5112 | |
---|
5113 | doc=domBuilder->parse(input); |
---|
5114 | domBuilder->parseWithContext(input, doc->getDocumentElement()->getFirstElementChild(), DOMLSParser::ACTION_REPLACE); |
---|
5115 | // the first child of 'root' must be another 'root' child |
---|
5116 | if(!XMLString::equals(doc->getDocumentElement()->getFirstElementChild()->getNodeName(), tempStr2)) |
---|
5117 | { |
---|
5118 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5119 | OK=false; |
---|
5120 | } |
---|
5121 | |
---|
5122 | // verify that namespaces are in scope |
---|
5123 | doc=domBuilder->parse(input); |
---|
5124 | const char* sXml3="<x:root/>"; |
---|
5125 | XMLString::transcode(sXml3, tempStr2, 3999); |
---|
5126 | input->setStringData(tempStr2); |
---|
5127 | domBuilder->parseWithContext(input, doc->getDocumentElement()->getFirstElementChild(), DOMLSParser::ACTION_APPEND_AS_CHILDREN); |
---|
5128 | // the first 'elem' child of 'root' must have a 'x:root' child |
---|
5129 | XMLString::transcode("urn:xxx", tempStr2, 3999); |
---|
5130 | if(!XMLString::equals(doc->getDocumentElement()->getFirstElementChild()->getFirstElementChild()->getNamespaceURI(), tempStr2)) |
---|
5131 | { |
---|
5132 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5133 | OK=false; |
---|
5134 | } |
---|
5135 | } |
---|
5136 | catch(DOMException&) |
---|
5137 | { |
---|
5138 | fprintf(stderr, "checking testLSExceptions failed at line %i\n", __LINE__); |
---|
5139 | OK=false; |
---|
5140 | } |
---|
5141 | |
---|
5142 | input->release(); |
---|
5143 | domBuilder->release(); |
---|
5144 | |
---|
5145 | return OK; |
---|
5146 | } |
---|
5147 | |
---|
5148 | bool DOMTest::testElementTraversal() { |
---|
5149 | const char* sXml="<?xml version='1.0'?>" |
---|
5150 | "<!DOCTYPE g [" |
---|
5151 | "<!ENTITY ent1 '<nestedEl>&ent2;</nestedEl>'>" |
---|
5152 | "<!ENTITY ent2 'text'>" |
---|
5153 | "]>" |
---|
5154 | "<g id='shapeGroup'>\n" |
---|
5155 | "\n" |
---|
5156 | "\t<rect id='rect1' x='5' y='5' width='310' height='220' rx='15' ry='15' fill='skyblue'/>\n" |
---|
5157 | "\t<rect id='rect2' x='15' y='15' width='210' height='180' rx='15' ry='15' fill='cornflowerblue'/>\n" |
---|
5158 | "\n" |
---|
5159 | "\t<ellipse id='ellipse1' cx='90' cy='70' rx='50' ry='30' fill='yellow' stroke='orange'/>\n" |
---|
5160 | "\n" |
---|
5161 | "\t<path id='path1' stroke-width='15' stroke='orange' fill='none' stroke-linecap='round'\n" |
---|
5162 | "\t\td='M25,150 C180,180 290,0 400,140 S420,100 460,90'/>\n" |
---|
5163 | "\t<text id='text1' x='0' y='0' font-size='35' fill='yellow' stroke='orange'\n" |
---|
5164 | "\t\tstroke-width='2' stroke-linejoin='round' font-weight='bold'>\n" |
---|
5165 | "\t\t<textPath id='textPath1' href='#path1'>&ent1;&ent2;&ent1;</textPath></text>\n" |
---|
5166 | "</g>"; |
---|
5167 | MemBufInputSource is((XMLByte*)sXml, strlen(sXml), "bufId"); |
---|
5168 | |
---|
5169 | static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; |
---|
5170 | DOMImplementationLS *impl = (DOMImplementationLS*)DOMImplementationRegistry::getDOMImplementation(gLS); |
---|
5171 | DOMLSParser *domBuilder = impl->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0); |
---|
5172 | DOMLSInput *input = impl->createLSInput(); |
---|
5173 | XMLString::transcode(sXml, tempStr, 3999); |
---|
5174 | input->setStringData(tempStr); |
---|
5175 | try |
---|
5176 | { |
---|
5177 | DOMDocument* doc=domBuilder->parse(input); |
---|
5178 | |
---|
5179 | XMLSize_t c = doc->getDocumentElement()->getChildNodes()->getLength(); |
---|
5180 | if(c!=11) |
---|
5181 | { |
---|
5182 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5183 | return false; |
---|
5184 | } |
---|
5185 | DOMNode* firstNode = doc->getDocumentElement()->getFirstChild(); |
---|
5186 | if(firstNode==NULL || firstNode->getNodeType()!=DOMNode::TEXT_NODE || *firstNode->getNodeValue()=='\r') |
---|
5187 | { |
---|
5188 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5189 | return false; |
---|
5190 | } |
---|
5191 | DOMElement* childNode = doc->getDocumentElement()->getFirstElementChild(); |
---|
5192 | XMLString::transcode("id", tempStr, 3999); |
---|
5193 | XMLString::transcode("rect1", tempStr2, 3999); |
---|
5194 | if(childNode==NULL || childNode->getNodeType()!=DOMNode::ELEMENT_NODE || !XMLString::equals(childNode->getAttribute(tempStr),tempStr2)) |
---|
5195 | { |
---|
5196 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5197 | return false; |
---|
5198 | } |
---|
5199 | XMLSize_t count=0; |
---|
5200 | while(childNode!=NULL) |
---|
5201 | { |
---|
5202 | count++; |
---|
5203 | childNode=childNode->getNextElementSibling(); |
---|
5204 | } |
---|
5205 | if(count!=5) |
---|
5206 | { |
---|
5207 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5208 | return false; |
---|
5209 | } |
---|
5210 | count = doc->getDocumentElement()->getChildElementCount(); |
---|
5211 | if(count!=5) |
---|
5212 | { |
---|
5213 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5214 | return false; |
---|
5215 | } |
---|
5216 | DOMElement* text=doc->getDocumentElement()->getLastElementChild(); |
---|
5217 | XMLString::transcode("id", tempStr, 3999); |
---|
5218 | XMLString::transcode("text1", tempStr2, 3999); |
---|
5219 | if(text==NULL || text->getNodeType()!=DOMNode::ELEMENT_NODE || !XMLString::equals(text->getAttribute(tempStr),tempStr2)) |
---|
5220 | { |
---|
5221 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5222 | return false; |
---|
5223 | } |
---|
5224 | DOMElement* textPath=text->getFirstElementChild(); |
---|
5225 | XMLString::transcode("id", tempStr, 3999); |
---|
5226 | XMLString::transcode("textPath1", tempStr2, 3999); |
---|
5227 | if(textPath==NULL || textPath->getNodeType()!=DOMNode::ELEMENT_NODE || !XMLString::equals(textPath->getAttribute(tempStr),tempStr2)) |
---|
5228 | { |
---|
5229 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5230 | return false; |
---|
5231 | } |
---|
5232 | count = textPath->getChildElementCount(); |
---|
5233 | if(count!=2) |
---|
5234 | { |
---|
5235 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5236 | return false; |
---|
5237 | } |
---|
5238 | DOMElement* insideEntity=textPath->getFirstElementChild(); |
---|
5239 | if(insideEntity==NULL || insideEntity->getNodeType()!=DOMNode::ELEMENT_NODE) |
---|
5240 | { |
---|
5241 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5242 | return false; |
---|
5243 | } |
---|
5244 | DOMElement* insideEntity2=textPath->getLastElementChild(); |
---|
5245 | if(insideEntity2==NULL || insideEntity2->getNodeType()!=DOMNode::ELEMENT_NODE) |
---|
5246 | { |
---|
5247 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5248 | return false; |
---|
5249 | } |
---|
5250 | if(insideEntity->getNextElementSibling()!=insideEntity2 || insideEntity!=insideEntity2->getPreviousElementSibling()) |
---|
5251 | { |
---|
5252 | fprintf(stderr, "checking ElementTraversal failed at line %i\n", __LINE__); |
---|
5253 | return false; |
---|
5254 | } |
---|
5255 | return true; |
---|
5256 | } |
---|
5257 | catch(DOMLSException&) |
---|
5258 | { |
---|
5259 | fprintf(stderr, "checking testElementTraversal failed at line %i\n", __LINE__); |
---|
5260 | return false; |
---|
5261 | } |
---|
5262 | |
---|
5263 | input->release(); |
---|
5264 | domBuilder->release(); |
---|
5265 | |
---|
5266 | return true; |
---|
5267 | } |
---|
5268 | |
---|
5269 | /** |
---|
5270 | * |
---|
5271 | * @param node org.w3c.dom.DOMNode |
---|
5272 | * @param node2 org.w3c.dom.DOMNode |
---|
5273 | * |
---|
5274 | */ |
---|
5275 | bool DOMTest::treeCompare(DOMNode* node, DOMNode* node2) |
---|
5276 | { |
---|
5277 | bool answer = true; |
---|
5278 | |
---|
5279 | DOMNode* kid, *kid2; // Check the subtree for equality |
---|
5280 | kid = node->getFirstChild(); |
---|
5281 | kid2 = node2->getFirstChild(); |
---|
5282 | if (kid && kid2) |
---|
5283 | { |
---|
5284 | answer = treeCompare(kid, kid2); |
---|
5285 | if (!answer) |
---|
5286 | return answer; |
---|
5287 | else |
---|
5288 | if (kid->getNextSibling() && kid2->getNextSibling()) |
---|
5289 | { |
---|
5290 | while (kid->getNextSibling() && kid2->getNextSibling()) |
---|
5291 | { |
---|
5292 | answer = treeCompare(kid->getNextSibling(), kid2->getNextSibling()); |
---|
5293 | if (!answer) |
---|
5294 | return answer; |
---|
5295 | else |
---|
5296 | { |
---|
5297 | kid = kid->getNextSibling(); |
---|
5298 | kid2 = kid2->getNextSibling(); |
---|
5299 | } |
---|
5300 | } |
---|
5301 | } else |
---|
5302 | if (!(!kid->getNextSibling() && !kid2->getNextSibling())) |
---|
5303 | { |
---|
5304 | return false; |
---|
5305 | } |
---|
5306 | } else |
---|
5307 | if (kid != kid2) |
---|
5308 | { |
---|
5309 | // One or the other of (kid1, kid2) is 0, but not both. |
---|
5310 | return false; |
---|
5311 | } |
---|
5312 | |
---|
5313 | if (XMLString::compareString(node->getNodeName(), node2->getNodeName())) |
---|
5314 | return false; |
---|
5315 | if (node->getNodeValue()==0 && node2->getNodeValue()!=0) |
---|
5316 | return false; |
---|
5317 | if (node->getNodeValue()!=0 && node2->getNodeValue()==0) |
---|
5318 | return false; |
---|
5319 | if (XMLString::compareString(node->getNodeValue(), node2->getNodeValue())) |
---|
5320 | return false; |
---|
5321 | |
---|
5322 | return answer; |
---|
5323 | } |
---|
5324 | |
---|
5325 | #define TEST_VALID_REGEX(str, regex, line) \ |
---|
5326 | try \ |
---|
5327 | { \ |
---|
5328 | RegularExpression p(regex); \ |
---|
5329 | if(!p.matches(str)) \ |
---|
5330 | { \ |
---|
5331 | fprintf(stderr, "Regular expression test failed at line %i\n", line); \ |
---|
5332 | OK = false; \ |
---|
5333 | } \ |
---|
5334 | } \ |
---|
5335 | catch(XMLException& ) \ |
---|
5336 | { \ |
---|
5337 | fprintf(stderr, "Regular expression test failed at line %i\n", line); \ |
---|
5338 | OK = false; \ |
---|
5339 | } |
---|
5340 | |
---|
5341 | #define TEST_INVALID_REGEX(str, regex, line) \ |
---|
5342 | try \ |
---|
5343 | { \ |
---|
5344 | RegularExpression p(regex); \ |
---|
5345 | if(p.matches(str)) \ |
---|
5346 | { \ |
---|
5347 | fprintf(stderr, "Regular expression test failed at line %i\n", line); \ |
---|
5348 | OK = false; \ |
---|
5349 | } \ |
---|
5350 | } \ |
---|
5351 | catch(XMLException& ) \ |
---|
5352 | { \ |
---|
5353 | fprintf(stderr, "Regular expression test failed at line %i\n", line); \ |
---|
5354 | OK = false; \ |
---|
5355 | } |
---|
5356 | |
---|
5357 | #define TEST_VALID_SCHEMA_REGEX(str, regex, line) \ |
---|
5358 | try \ |
---|
5359 | { \ |
---|
5360 | RegularExpression p(regex, "X"); \ |
---|
5361 | if(!p.matches(str)) \ |
---|
5362 | { \ |
---|
5363 | fprintf(stderr, "Regular expression test failed at line %i\n", line); \ |
---|
5364 | OK = false; \ |
---|
5365 | } \ |
---|
5366 | } \ |
---|
5367 | catch(XMLException& ) \ |
---|
5368 | { \ |
---|
5369 | fprintf(stderr, "Regular expression test failed at line %i\n", line); \ |
---|
5370 | OK = false; \ |
---|
5371 | } |
---|
5372 | |
---|
5373 | #define TEST_INVALID_SCHEMA_REGEX(str, regex, line) \ |
---|
5374 | try \ |
---|
5375 | { \ |
---|
5376 | RegularExpression p(regex, "X"); \ |
---|
5377 | if(p.matches(str)) \ |
---|
5378 | { \ |
---|
5379 | fprintf(stderr, "Regular expression test failed at line %i\n", line); \ |
---|
5380 | OK = false; \ |
---|
5381 | } \ |
---|
5382 | } \ |
---|
5383 | catch(XMLException& ) \ |
---|
5384 | { \ |
---|
5385 | fprintf(stderr, "Regular expression test failed at line %i\n", line); \ |
---|
5386 | OK = false; \ |
---|
5387 | } |
---|
5388 | |
---|
5389 | #define HUGE_STRING (100*1024) // 100Kb |
---|
5390 | |
---|
5391 | bool DOMTest::testRegex() { |
---|
5392 | bool OK = true; |
---|
5393 | |
---|
5394 | char* hugeString=new char[HUGE_STRING+1]; |
---|
5395 | for(int i=0;i<HUGE_STRING;i++) |
---|
5396 | hugeString[i]='A'; |
---|
5397 | hugeString[HUGE_STRING]=0; |
---|
5398 | TEST_VALID_REGEX(hugeString, "([A-F0-9]{2})*", __LINE__); |
---|
5399 | |
---|
5400 | TEST_VALID_REGEX("12_END", "[12]{2}_END", __LINE__); |
---|
5401 | TEST_INVALID_REGEX("12", "[12]{2}_END", __LINE__); |
---|
5402 | |
---|
5403 | TEST_VALID_REGEX("AE", "(A|B*|C)E", __LINE__); |
---|
5404 | TEST_VALID_REGEX("E", "(A|B*|C)E", __LINE__); |
---|
5405 | TEST_VALID_REGEX("BBBBBBBBBBBBBE", "(A|B*|C)E", __LINE__); |
---|
5406 | TEST_VALID_REGEX("CE", "(A|B*|C)E", __LINE__); |
---|
5407 | TEST_INVALID_REGEX("A", "(A|B*|C)E", __LINE__); |
---|
5408 | TEST_INVALID_REGEX("", "(A|B*|C)E", __LINE__); |
---|
5409 | TEST_INVALID_REGEX("BBBBBBBBBBBBB", "(A|B*|C)E", __LINE__); |
---|
5410 | TEST_INVALID_REGEX("C", "(A|B*|C)E", __LINE__); |
---|
5411 | |
---|
5412 | // this tests the closures that need fOffset in the context |
---|
5413 | for(int j=0;j<HUGE_STRING-1;j++) |
---|
5414 | hugeString[j]=j%2?'B':'C'; |
---|
5415 | hugeString[HUGE_STRING-1]='E'; |
---|
5416 | // we run out of stack space when testing this one |
---|
5417 | //TEST_VALID_REGEX(hugeString, "(B?C?)*E", __LINE__); |
---|
5418 | TEST_VALID_REGEX("BBBBE", "(B?C?)*E", __LINE__); |
---|
5419 | TEST_VALID_REGEX("E", "(B?C?)*E", __LINE__); |
---|
5420 | TEST_VALID_REGEX("CCCCCCCE", "(B?C?)*E", __LINE__); |
---|
5421 | TEST_VALID_REGEX("BCBCBBBBCCCCCE", "(B?C?)*E", __LINE__); |
---|
5422 | |
---|
5423 | TEST_VALID_REGEX(" C", "[\\s]*[\\S]+[\\s\\S]*", __LINE__); |
---|
5424 | TEST_VALID_REGEX("C asasaskja ksakj", "[\\s]*[\\S]+[\\s\\S]*", __LINE__); |
---|
5425 | TEST_VALID_REGEX(" C", "[\\s]*[\\S]+[\\s\\S]*", __LINE__); |
---|
5426 | TEST_INVALID_REGEX("\t ", "[\\s]*[\\S]+[\\S]*", __LINE__); |
---|
5427 | |
---|
5428 | TEST_VALID_REGEX("U2VsZWN0IFRoaXMgaXMgZmlmdGg7DQogDQpOT1RFOiBUaGUgaW5mb3JtYXRpb24gY29udGFpbmVk\n" |
---|
5429 | "IGluIHRoaXMgZW1haWwgbWVzc2FnZSBpcyBjb25zaWRlcmVkIGNvbmZpZGVudGlhbCBhbmQgcHJv\n" |
---|
5430 | "cHJpZXRhcnkgdG8gdGhlIHNlbmRlciBhbmQgaXMgaW50ZW5kZWQgc29sZWx5IGZvciByZXZpZXcg\n" |
---|
5431 | "YW5kIHVzZSBieSB0aGUgbmFtZWQgcmVjaXBpZW50LiAgQW55IHVuYXV0aG9yaXplZCByZXZpZXcs\n" |
---|
5432 | "IHVzZSBvciBkaXN0cmlidXRpb24gaXMgc3RyaWN0bHkgcHJvaGliaXRlZC4gSWYgeW91IGhhdmUg\n" |
---|
5433 | "cmVjZWl2ZWQgdGhpcyBtZXNzYWdlIGluIGVycm9yLCBwbGVhc2UgYWR2aXNlIHRoZSBzZW5kZXIg\n" |
---|
5434 | "YnkgcmVwbHkgZW1haWwgYW5kIGRlbGV0ZSB0aGUgbWVzc2FnZS4NCg==\n", "(^(([A-Za-z0-9+/=]){4}){1,19}$)*", __LINE__); |
---|
5435 | |
---|
5436 | // examples from XMLSchema specs |
---|
5437 | TEST_VALID_SCHEMA_REGEX("123 456", "123 (\\d+\\s)*456", __LINE__); |
---|
5438 | TEST_VALID_SCHEMA_REGEX("123 987 456", "123 (\\d+\\s)*456", __LINE__); |
---|
5439 | TEST_VALID_SCHEMA_REGEX("123 987 567 456", "123 (\\d+\\s)*456", __LINE__); |
---|
5440 | |
---|
5441 | TEST_VALID_SCHEMA_REGEX("P0100Y02M", "P\\p{Nd}{4}Y\\p{Nd}{2}M", __LINE__); |
---|
5442 | TEST_VALID_SCHEMA_REGEX("en-US", "[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*", __LINE__); |
---|
5443 | |
---|
5444 | TEST_VALID_SCHEMA_REGEX("123-XX", "\\d{3}-[A-Z]{2}", __LINE__); |
---|
5445 | |
---|
5446 | TEST_VALID_SCHEMA_REGEX("01803", "[0-9]{5}(-[0-9]{4})?", __LINE__); |
---|
5447 | |
---|
5448 | TEST_VALID_SCHEMA_REGEX("_id1", "\\i\\c*", __LINE__); |
---|
5449 | TEST_INVALID_SCHEMA_REGEX("0id", "\\i\\c*", __LINE__); |
---|
5450 | |
---|
5451 | TEST_VALID_SCHEMA_REGEX("hello", "[\\i-[:]][\\c-[:]]*", __LINE__); |
---|
5452 | TEST_INVALID_SCHEMA_REGEX("0qq", "[\\i-[:]][\\c-[:]]*", __LINE__); |
---|
5453 | TEST_INVALID_SCHEMA_REGEX("ns:localname", "[\\i-[:]][\\c-[:]]*", __LINE__); |
---|
5454 | TEST_INVALID_SCHEMA_REGEX("ns:", "[\\i-[:]][\\c-[:]]*", __LINE__); |
---|
5455 | TEST_INVALID_SCHEMA_REGEX(":qq", "[\\i-[:]][\\c-[:]]*", __LINE__); |
---|
5456 | |
---|
5457 | TEST_VALID_SCHEMA_REGEX("900", "[\\-+]?[0-9]+", __LINE__); |
---|
5458 | TEST_VALID_SCHEMA_REGEX("-900", "[\\-+]?[0-9]+", __LINE__); |
---|
5459 | TEST_VALID_SCHEMA_REGEX("+900", "[\\-+]?[0-9]+", __LINE__); |
---|
5460 | TEST_INVALID_SCHEMA_REGEX("+", "[\\-+]?[0-9]+", __LINE__); |
---|
5461 | TEST_INVALID_SCHEMA_REGEX("-", "[\\-+]?[0-9]+", __LINE__); |
---|
5462 | TEST_INVALID_SCHEMA_REGEX("0.4", "[\\-+]?[0-9]+", __LINE__); |
---|
5463 | |
---|
5464 | TEST_VALID_SCHEMA_REGEX("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "A.*Z", __LINE__); |
---|
5465 | TEST_INVALID_SCHEMA_REGEX("Z", "A.*Z", __LINE__); |
---|
5466 | TEST_INVALID_SCHEMA_REGEX("A", "A.*Z", __LINE__); |
---|
5467 | TEST_INVALID_SCHEMA_REGEX("ABC", "A.*Z", __LINE__); |
---|
5468 | |
---|
5469 | // tests from the XMLSchema Test Suite |
---|
5470 | TEST_VALID_SCHEMA_REGEX("Chapter b", "Chapter\\s{0,2}\\w", __LINE__); |
---|
5471 | TEST_VALID_SCHEMA_REGEX("Chapter\tb", "Chapter\\s{0,2}\\w", __LINE__); |
---|
5472 | TEST_VALID_SCHEMA_REGEX("Chapter\nb", "Chapter\\s{0,2}\\w", __LINE__); |
---|
5473 | |
---|
5474 | TEST_VALID_SCHEMA_REGEX("abx", "(a|b)+x", __LINE__); |
---|
5475 | TEST_VALID_SCHEMA_REGEX("bax", "(a|b)+x", __LINE__); |
---|
5476 | TEST_VALID_SCHEMA_REGEX("bbx", "(a|b)+x", __LINE__); |
---|
5477 | TEST_VALID_SCHEMA_REGEX("aaax", "(a|b)+x", __LINE__); |
---|
5478 | TEST_VALID_SCHEMA_REGEX("abax", "(a|b)+x", __LINE__); |
---|
5479 | TEST_VALID_SCHEMA_REGEX("abbx", "(a|b)+x", __LINE__); |
---|
5480 | TEST_VALID_SCHEMA_REGEX("bbax", "(a|b)+x", __LINE__); |
---|
5481 | |
---|
5482 | TEST_VALID_SCHEMA_REGEX("1x2abc", ".*abc.*", __LINE__); |
---|
5483 | TEST_VALID_SCHEMA_REGEX("abc1x2", ".*abc.*", __LINE__); |
---|
5484 | TEST_VALID_SCHEMA_REGEX("z3455abch00ray", ".*abc.*", __LINE__); |
---|
5485 | TEST_VALID_SCHEMA_REGEX("bcabcabcab", ".*abc.*", __LINE__); |
---|
5486 | |
---|
5487 | TEST_VALID_SCHEMA_REGEX("abbbx", "ab{2,4}x", __LINE__); |
---|
5488 | TEST_VALID_SCHEMA_REGEX("abbbbx", "ab{2,4}x", __LINE__); |
---|
5489 | TEST_INVALID_SCHEMA_REGEX("abx", "ab{2,4}x", __LINE__); |
---|
5490 | TEST_INVALID_SCHEMA_REGEX("abbbbbx", "ab{2,4}x", __LINE__); |
---|
5491 | TEST_VALID_SCHEMA_REGEX("PAG_1", "PAG_[0-9]{1,}", __LINE__); |
---|
5492 | |
---|
5493 | TEST_VALID_SCHEMA_REGEX("5 Bedford Street Boston , MA 15604-1536", "\\d{1,5}\\s([A-Z][a-z]{1,20}\\s){1}Street\\s([A-Z][a-z]{1,20}\\s){1},\\s[A-Z]{2}\\s15604-1536", __LINE__); |
---|
5494 | |
---|
5495 | // from X3D schema |
---|
5496 | TEST_VALID_SCHEMA_REGEX("0.5 0.2 1.0", "((((\\.[0-9]+|0(\\.[0-9]*)?)((E|e)(\\+|\\-)?[0-9]+)?)|(1(\\.[0]*)?((E|e)\\-[0-9]+)?)|([1-9](\\.[0-9]*)((E|e)\\-[0-9]+))) (((\\.[0-9]+|0(\\.[0-9]*)?)((E|e)(\\+|\\-)?[0-9]+)?)|(1(\\.[0]*)?((E|e)\\-[0-9]+)?)|([1-9](\\.[0-9]*)((E|e)\\-[0-9]+))) (((\\.[0-9]+|0(\\.[0-9]*)?)((E|e)(\\+|\\-)?[0-9]+)?)|(1(\\.[0]*)?((E|e)\\-[0-9]+)?)|([1-9](\\.[0-9]*)((E|e)\\-[0-9]+))))?", __LINE__); |
---|
5497 | TEST_VALID_SCHEMA_REGEX("5.0e-2 .2 1", "((((\\.[0-9]+|0(\\.[0-9]*)?)((E|e)(\\+|\\-)?[0-9]+)?)|(1(\\.[0]*)?((E|e)\\-[0-9]+)?)|([1-9](\\.[0-9]*)((E|e)\\-[0-9]+))) (((\\.[0-9]+|0(\\.[0-9]*)?)((E|e)(\\+|\\- |
---|