1//
2// NodeTest.cpp
3//
4// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#include "NodeTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/DOM/Document.h"
15#include "Poco/DOM/Element.h"
16#include "Poco/DOM/DocumentFragment.h"
17#include "Poco/DOM/AutoPtr.h"
18
19
20using Poco::XML::Element;
21using Poco::XML::Document;
22using Poco::XML::DocumentFragment;
23using Poco::XML::Node;
24using Poco::XML::AutoPtr;
25
26
27NodeTest::NodeTest(const std::string& name): CppUnit::TestCase(name)
28{
29}
30
31
32NodeTest::~NodeTest()
33{
34}
35
36
37void NodeTest::testInsert()
38{
39 AutoPtr<Document> pDoc = new Document;
40 AutoPtr<Element> pRoot = pDoc->createElement("root");
41
42 assertTrue (!pRoot->hasChildNodes());
43 assertTrue (pRoot->firstChild() == 0);
44 assertTrue (pRoot->lastChild() == 0);
45
46 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
47 pRoot->insertBefore(pChild1, 0);
48 assertTrue (pRoot->hasChildNodes());
49 assertTrue (pRoot->firstChild() == pChild1);
50 assertTrue (pRoot->lastChild() == pChild1);
51
52 assertTrue (pChild1->previousSibling() == 0);
53 assertTrue (pChild1->nextSibling() == 0);
54
55 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
56 pRoot->insertBefore(pChild3, 0);
57 assertTrue (pRoot->firstChild() == pChild1);
58 assertTrue (pRoot->lastChild() == pChild3);
59
60 assertTrue (pChild1->previousSibling() == 0);
61 assertTrue (pChild1->nextSibling() == pChild3);
62 assertTrue (pChild3->previousSibling() == pChild1);
63 assertTrue (pChild3->nextSibling() == 0);
64
65 AutoPtr<Element> pChild0 = pDoc->createElement("child0");
66 pRoot->insertBefore(pChild0, pChild1);
67 assertTrue (pRoot->firstChild() == pChild0);
68 assertTrue (pRoot->lastChild() == pChild3);
69
70 assertTrue (pChild0->previousSibling() == 0);
71 assertTrue (pChild0->nextSibling() == pChild1);
72 assertTrue (pChild1->previousSibling() == pChild0);
73 assertTrue (pChild1->nextSibling() == pChild3);
74 assertTrue (pChild3->previousSibling() == pChild1);
75 assertTrue (pChild3->nextSibling() == 0);
76
77 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
78 pRoot->insertBefore(pChild2, pChild3);
79 assertTrue (pRoot->firstChild() == pChild0);
80 assertTrue (pRoot->lastChild() == pChild3);
81
82 assertTrue (pChild0->previousSibling() == 0);
83 assertTrue (pChild0->nextSibling() == pChild1);
84 assertTrue (pChild1->previousSibling() == pChild0);
85 assertTrue (pChild1->nextSibling() == pChild2);
86 assertTrue (pChild2->previousSibling() == pChild1);
87 assertTrue (pChild2->nextSibling() == pChild3);
88 assertTrue (pChild3->previousSibling() == pChild2);
89 assertTrue (pChild3->nextSibling() == 0);
90}
91
92
93void NodeTest::testAppend()
94{
95 AutoPtr<Document> pDoc = new Document;
96 AutoPtr<Element> pRoot = pDoc->createElement("root");
97
98 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
99 pRoot->appendChild(pChild1);
100 assertTrue (pRoot->firstChild() == pChild1);
101 assertTrue (pRoot->lastChild() == pChild1);
102
103 assertTrue (pChild1->previousSibling() == 0);
104 assertTrue (pChild1->nextSibling() == 0);
105
106 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
107 pRoot->appendChild(pChild2);
108 assertTrue (pRoot->firstChild() == pChild1);
109 assertTrue (pRoot->lastChild() == pChild2);
110
111 assertTrue (pChild1->previousSibling() == 0);
112 assertTrue (pChild1->nextSibling() == pChild2);
113 assertTrue (pChild2->previousSibling() == pChild1);
114 assertTrue (pChild2->nextSibling() == 0);
115
116 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
117 pRoot->appendChild(pChild3);
118 assertTrue (pRoot->firstChild() == pChild1);
119 assertTrue (pRoot->lastChild() == pChild3);
120
121 assertTrue (pChild1->previousSibling() == 0);
122 assertTrue (pChild1->nextSibling() == pChild2);
123 assertTrue (pChild2->previousSibling() == pChild1);
124 assertTrue (pChild2->nextSibling() == pChild3);
125 assertTrue (pChild3->previousSibling() == pChild2);
126 assertTrue (pChild3->nextSibling() == 0);
127}
128
129
130void NodeTest::testRemove()
131{
132 AutoPtr<Document> pDoc = new Document;
133 AutoPtr<Element> pRoot = pDoc->createElement("root");
134
135 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
136 pRoot->appendChild(pChild1);
137
138 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
139 pRoot->appendChild(pChild2);
140
141 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
142 pRoot->appendChild(pChild3);
143
144 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
145 pRoot->appendChild(pChild4);
146
147 pRoot->removeChild(pChild2);
148 assertTrue (pChild2->previousSibling() == 0);
149 assertTrue (pChild2->nextSibling() == 0);
150
151 assertTrue (pChild1->previousSibling() == 0);
152 assertTrue (pChild1->nextSibling() == pChild3);
153 assertTrue (pChild3->previousSibling() == pChild1);
154 assertTrue (pChild3->nextSibling() == pChild4);
155 assertTrue (pChild4->previousSibling() == pChild3);
156 assertTrue (pChild4->nextSibling() == 0);
157
158 pRoot->removeChild(pChild4);
159 assertTrue (pChild4->previousSibling() == 0);
160 assertTrue (pChild4->nextSibling() == 0);
161
162 assertTrue (pChild1->previousSibling() == 0);
163 assertTrue (pChild1->nextSibling() == pChild3);
164 assertTrue (pChild3->previousSibling() == pChild1);
165 assertTrue (pChild3->nextSibling() == 0);
166
167 assertTrue (pRoot->firstChild() == pChild1);
168 assertTrue (pRoot->lastChild() == pChild3);
169
170 pRoot->removeChild(pChild1);
171 assertTrue (pChild1->previousSibling() == 0);
172 assertTrue (pChild1->nextSibling() == 0);
173
174 assertTrue (pRoot->firstChild() == pChild3);
175 assertTrue (pRoot->lastChild() == pChild3);
176
177 pRoot->removeChild(pChild3);
178 assertTrue (pChild3->previousSibling() == 0);
179 assertTrue (pChild3->nextSibling() == 0);
180 assertTrue (pRoot->firstChild() == 0);
181 assertTrue (pRoot->lastChild() == 0);
182}
183
184
185void NodeTest::testReplace()
186{
187 AutoPtr<Document> pDoc = new Document;
188 AutoPtr<Element> pRoot = pDoc->createElement("root");
189
190 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
191 pRoot->appendChild(pChild1);
192
193 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
194 pRoot->appendChild(pChild2);
195
196 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
197 pRoot->appendChild(pChild3);
198
199 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
200 pRoot->appendChild(pChild4);
201
202 AutoPtr<Element> pChild11 = pDoc->createElement("child11");
203 pRoot->replaceChild(pChild11, pChild1);
204
205 assertTrue (pChild1->previousSibling() == 0);
206 assertTrue (pChild1->nextSibling() == 0);
207 assertTrue (pRoot->firstChild() == pChild11);
208 assertTrue (pRoot->lastChild() == pChild4);
209 assertTrue (pChild11->previousSibling() == 0);
210 assertTrue (pChild11->nextSibling() == pChild2);
211 assertTrue (pChild2->previousSibling() == pChild11);
212 assertTrue (pChild2->nextSibling() == pChild3);
213 assertTrue (pChild3->previousSibling() == pChild2);
214 assertTrue (pChild3->nextSibling() == pChild4);
215 assertTrue (pChild4->previousSibling() == pChild3);
216 assertTrue (pChild4->nextSibling() == 0);
217
218 AutoPtr<Element> pChild22 = pDoc->createElement("child22");
219 pRoot->replaceChild(pChild22, pChild2);
220
221 assertTrue (pChild2->previousSibling() == 0);
222 assertTrue (pChild2->nextSibling() == 0);
223 assertTrue (pRoot->firstChild() == pChild11);
224 assertTrue (pRoot->lastChild() == pChild4);
225 assertTrue (pChild11->previousSibling() == 0);
226 assertTrue (pChild11->nextSibling() == pChild22);
227 assertTrue (pChild22->previousSibling() == pChild11);
228 assertTrue (pChild22->nextSibling() == pChild3);
229 assertTrue (pChild3->previousSibling() == pChild22);
230 assertTrue (pChild3->nextSibling() == pChild4);
231 assertTrue (pChild4->previousSibling() == pChild3);
232 assertTrue (pChild4->nextSibling() == 0);
233
234 AutoPtr<Element> pChild33 = pDoc->createElement("child33");
235 pRoot->replaceChild(pChild33, pChild3);
236
237 assertTrue (pChild3->previousSibling() == 0);
238 assertTrue (pChild3->nextSibling() == 0);
239 assertTrue (pRoot->firstChild() == pChild11);
240 assertTrue (pRoot->lastChild() == pChild4);
241 assertTrue (pChild11->previousSibling() == 0);
242 assertTrue (pChild11->nextSibling() == pChild22);
243 assertTrue (pChild22->previousSibling() == pChild11);
244 assertTrue (pChild22->nextSibling() == pChild33);
245 assertTrue (pChild33->previousSibling() == pChild22);
246 assertTrue (pChild33->nextSibling() == pChild4);
247 assertTrue (pChild4->previousSibling() == pChild33);
248 assertTrue (pChild4->nextSibling() == 0);
249
250 AutoPtr<Element> pChild44 = pDoc->createElement("child44");
251 pRoot->replaceChild(pChild44, pChild4);
252
253 assertTrue (pChild4->previousSibling() == 0);
254 assertTrue (pChild4->nextSibling() == 0);
255 assertTrue (pRoot->firstChild() == pChild11);
256 assertTrue (pRoot->lastChild() == pChild44);
257 assertTrue (pChild11->previousSibling() == 0);
258 assertTrue (pChild11->nextSibling() == pChild22);
259 assertTrue (pChild22->previousSibling() == pChild11);
260 assertTrue (pChild22->nextSibling() == pChild33);
261 assertTrue (pChild33->previousSibling() == pChild22);
262 assertTrue (pChild33->nextSibling() == pChild44);
263 assertTrue (pChild44->previousSibling() == pChild33);
264 assertTrue (pChild44->nextSibling() == 0);
265}
266
267
268void NodeTest::testInsertFragment1()
269{
270 AutoPtr<Document> pDoc = new Document;
271 AutoPtr<Element> pRoot = pDoc->createElement("root");
272 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
273
274 assertTrue (!pRoot->hasChildNodes());
275 assertTrue (pRoot->firstChild() == 0);
276 assertTrue (pRoot->lastChild() == 0);
277
278 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
279 pFrag->appendChild(pChild1);
280 pRoot->insertBefore(pFrag, 0);
281 assertTrue (pFrag->firstChild() == 0);
282 assertTrue (pFrag->lastChild() == 0);
283 assertTrue (pRoot->firstChild() == pChild1);
284 assertTrue (pRoot->lastChild() == pChild1);
285
286 assertTrue (pChild1->previousSibling() == 0);
287 assertTrue (pChild1->nextSibling() == 0);
288
289 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
290 pFrag->appendChild(pChild3);
291 pRoot->insertBefore(pFrag, 0);
292 assertTrue (pRoot->firstChild() == pChild1);
293 assertTrue (pRoot->lastChild() == pChild3);
294
295 assertTrue (pChild1->previousSibling() == 0);
296 assertTrue (pChild1->nextSibling() == pChild3);
297 assertTrue (pChild3->previousSibling() == pChild1);
298 assertTrue (pChild3->nextSibling() == 0);
299
300 AutoPtr<Element> pChild0 = pDoc->createElement("child0");
301 pFrag->appendChild(pChild0);
302 pRoot->insertBefore(pFrag, pChild1);
303 assertTrue (pRoot->firstChild() == pChild0);
304 assertTrue (pRoot->lastChild() == pChild3);
305
306 assertTrue (pChild0->previousSibling() == 0);
307 assertTrue (pChild0->nextSibling() == pChild1);
308 assertTrue (pChild1->previousSibling() == pChild0);
309 assertTrue (pChild1->nextSibling() == pChild3);
310 assertTrue (pChild3->previousSibling() == pChild1);
311 assertTrue (pChild3->nextSibling() == 0);
312
313 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
314 pFrag->appendChild(pChild2);
315 pRoot->insertBefore(pFrag, pChild3);
316 assertTrue (pRoot->firstChild() == pChild0);
317 assertTrue (pRoot->lastChild() == pChild3);
318
319 assertTrue (pChild0->previousSibling() == 0);
320 assertTrue (pChild0->nextSibling() == pChild1);
321 assertTrue (pChild1->previousSibling() == pChild0);
322 assertTrue (pChild1->nextSibling() == pChild2);
323 assertTrue (pChild2->previousSibling() == pChild1);
324 assertTrue (pChild2->nextSibling() == pChild3);
325 assertTrue (pChild3->previousSibling() == pChild2);
326 assertTrue (pChild3->nextSibling() == 0);
327}
328
329
330void NodeTest::testInsertFragment2()
331{
332 AutoPtr<Document> pDoc = new Document;
333 AutoPtr<Element> pRoot = pDoc->createElement("root");
334 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
335
336 assertTrue (!pRoot->hasChildNodes());
337 assertTrue (pRoot->firstChild() == 0);
338 assertTrue (pRoot->lastChild() == 0);
339
340 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
341 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
342 pFrag->appendChild(pChild2);
343 pFrag->appendChild(pChild3);
344 pRoot->insertBefore(pFrag, 0);
345 assertTrue (pFrag->firstChild() == 0);
346 assertTrue (pFrag->lastChild() == 0);
347 assertTrue (pRoot->firstChild() == pChild2);
348 assertTrue (pRoot->lastChild() == pChild3);
349
350 assertTrue (pChild2->previousSibling() == 0);
351 assertTrue (pChild2->nextSibling() == pChild3);
352 assertTrue (pChild3->previousSibling() == pChild2);
353 assertTrue (pChild3->nextSibling() == 0);
354
355 AutoPtr<Element> pChild6 = pDoc->createElement("child6");
356 AutoPtr<Element> pChild7 = pDoc->createElement("child7");
357 pFrag->appendChild(pChild6);
358 pFrag->appendChild(pChild7);
359 pRoot->insertBefore(pFrag, 0);
360 assertTrue (pRoot->firstChild() == pChild2);
361 assertTrue (pRoot->lastChild() == pChild7);
362
363 assertTrue (pChild2->previousSibling() == 0);
364 assertTrue (pChild2->nextSibling() == pChild3);
365 assertTrue (pChild3->previousSibling() == pChild2);
366 assertTrue (pChild3->nextSibling() == pChild6);
367 assertTrue (pChild6->previousSibling() == pChild3);
368 assertTrue (pChild6->nextSibling() == pChild7);
369 assertTrue (pChild7->previousSibling() == pChild6);
370 assertTrue (pChild7->nextSibling() == 0);
371
372 AutoPtr<Element> pChild0 = pDoc->createElement("child0");
373 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
374 pFrag->appendChild(pChild0);
375 pFrag->appendChild(pChild1);
376 pRoot->insertBefore(pFrag, pChild2);
377 assertTrue (pRoot->firstChild() == pChild0);
378 assertTrue (pRoot->lastChild() == pChild7);
379
380 assertTrue (pChild0->previousSibling() == 0);
381 assertTrue (pChild0->nextSibling() == pChild1);
382 assertTrue (pChild1->previousSibling() == pChild0);
383 assertTrue (pChild1->nextSibling() == pChild2);
384 assertTrue (pChild2->previousSibling() == pChild1);
385 assertTrue (pChild2->nextSibling() == pChild3);
386 assertTrue (pChild3->previousSibling() == pChild2);
387 assertTrue (pChild3->nextSibling() == pChild6);
388 assertTrue (pChild6->previousSibling() == pChild3);
389 assertTrue (pChild6->nextSibling() == pChild7);
390 assertTrue (pChild7->previousSibling() == pChild6);
391 assertTrue (pChild7->nextSibling() == 0);
392
393 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
394 AutoPtr<Element> pChild5 = pDoc->createElement("child5");
395 pFrag->appendChild(pChild4);
396 pFrag->appendChild(pChild5);
397 pRoot->insertBefore(pFrag, pChild6);
398 assertTrue (pRoot->firstChild() == pChild0);
399 assertTrue (pRoot->lastChild() == pChild7);
400
401 assertTrue (pChild0->previousSibling() == 0);
402 assertTrue (pChild0->nextSibling() == pChild1);
403 assertTrue (pChild1->previousSibling() == pChild0);
404 assertTrue (pChild1->nextSibling() == pChild2);
405 assertTrue (pChild2->previousSibling() == pChild1);
406 assertTrue (pChild2->nextSibling() == pChild3);
407 assertTrue (pChild3->previousSibling() == pChild2);
408 assertTrue (pChild3->nextSibling() == pChild4);
409 assertTrue (pChild4->previousSibling() == pChild3);
410 assertTrue (pChild4->nextSibling() == pChild5);
411 assertTrue (pChild5->previousSibling() == pChild4);
412 assertTrue (pChild5->nextSibling() == pChild6);
413 assertTrue (pChild6->previousSibling() == pChild5);
414 assertTrue (pChild6->nextSibling() == pChild7);
415 assertTrue (pChild7->previousSibling() == pChild6);
416 assertTrue (pChild7->nextSibling() == 0);
417}
418
419
420void NodeTest::testInsertFragment3()
421{
422 AutoPtr<Document> pDoc = new Document;
423 AutoPtr<Element> pRoot = pDoc->createElement("root");
424 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
425
426 assertTrue (!pRoot->hasChildNodes());
427 assertTrue (pRoot->firstChild() == 0);
428 assertTrue (pRoot->lastChild() == 0);
429
430 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
431 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
432 AutoPtr<Element> pChild5 = pDoc->createElement("child5");
433 pFrag->appendChild(pChild3);
434 pFrag->appendChild(pChild4);
435 pFrag->appendChild(pChild5);
436 pRoot->insertBefore(pFrag, 0);
437 assertTrue (pFrag->firstChild() == 0);
438 assertTrue (pFrag->lastChild() == 0);
439 assertTrue (pRoot->firstChild() == pChild3);
440 assertTrue (pRoot->lastChild() == pChild5);
441
442 assertTrue (pChild3->previousSibling() == 0);
443 assertTrue (pChild3->nextSibling() == pChild4);
444 assertTrue (pChild4->previousSibling() == pChild3);
445 assertTrue (pChild4->nextSibling() == pChild5);
446 assertTrue (pChild5->previousSibling() == pChild4);
447 assertTrue (pChild5->nextSibling() == 0);
448
449 AutoPtr<Element> pChild9 = pDoc->createElement("child9");
450 AutoPtr<Element> pChild10 = pDoc->createElement("child10");
451 AutoPtr<Element> pChild11 = pDoc->createElement("child11");
452 pFrag->appendChild(pChild9);
453 pFrag->appendChild(pChild10);
454 pFrag->appendChild(pChild11);
455 pRoot->insertBefore(pFrag, 0);
456 assertTrue (pRoot->firstChild() == pChild3);
457 assertTrue (pRoot->lastChild() == pChild11);
458
459 assertTrue (pChild3->previousSibling() == 0);
460 assertTrue (pChild3->nextSibling() == pChild4);
461 assertTrue (pChild4->previousSibling() == pChild3);
462 assertTrue (pChild4->nextSibling() == pChild5);
463 assertTrue (pChild5->previousSibling() == pChild4);
464 assertTrue (pChild5->nextSibling() == pChild9);
465 assertTrue (pChild9->previousSibling() == pChild5);
466 assertTrue (pChild9->nextSibling() == pChild10);
467 assertTrue (pChild10->previousSibling() == pChild9);
468 assertTrue (pChild10->nextSibling() == pChild11);
469 assertTrue (pChild11->previousSibling() == pChild10);
470 assertTrue (pChild11->nextSibling() == 0);
471
472 AutoPtr<Element> pChild0 = pDoc->createElement("child0");
473 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
474 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
475 pFrag->appendChild(pChild0);
476 pFrag->appendChild(pChild1);
477 pFrag->appendChild(pChild2);
478 pRoot->insertBefore(pFrag, pChild3);
479 assertTrue (pRoot->firstChild() == pChild0);
480 assertTrue (pRoot->lastChild() == pChild11);
481
482 assertTrue (pChild0->previousSibling() == 0);
483 assertTrue (pChild0->nextSibling() == pChild1);
484 assertTrue (pChild1->previousSibling() == pChild0);
485 assertTrue (pChild1->nextSibling() == pChild2);
486 assertTrue (pChild2->previousSibling() == pChild1);
487 assertTrue (pChild2->nextSibling() == pChild3);
488 assertTrue (pChild3->previousSibling() == pChild2);
489 assertTrue (pChild3->nextSibling() == pChild4);
490 assertTrue (pChild4->previousSibling() == pChild3);
491 assertTrue (pChild4->nextSibling() == pChild5);
492 assertTrue (pChild5->previousSibling() == pChild4);
493 assertTrue (pChild5->nextSibling() == pChild9);
494 assertTrue (pChild9->previousSibling() == pChild5);
495 assertTrue (pChild9->nextSibling() == pChild10);
496 assertTrue (pChild10->previousSibling() == pChild9);
497 assertTrue (pChild10->nextSibling() == pChild11);
498 assertTrue (pChild11->previousSibling() == pChild10);
499 assertTrue (pChild11->nextSibling() == 0);
500
501 AutoPtr<Element> pChild6 = pDoc->createElement("child6");
502 AutoPtr<Element> pChild7 = pDoc->createElement("child7");
503 AutoPtr<Element> pChild8 = pDoc->createElement("child8");
504 pFrag->appendChild(pChild6);
505 pFrag->appendChild(pChild7);
506 pFrag->appendChild(pChild8);
507 pRoot->insertBefore(pFrag, pChild9);
508 assertTrue (pRoot->firstChild() == pChild0);
509 assertTrue (pRoot->lastChild() == pChild11);
510
511 assertTrue (pChild0->previousSibling() == 0);
512 assertTrue (pChild0->nextSibling() == pChild1);
513 assertTrue (pChild1->previousSibling() == pChild0);
514 assertTrue (pChild1->nextSibling() == pChild2);
515 assertTrue (pChild2->previousSibling() == pChild1);
516 assertTrue (pChild2->nextSibling() == pChild3);
517 assertTrue (pChild3->previousSibling() == pChild2);
518 assertTrue (pChild3->nextSibling() == pChild4);
519 assertTrue (pChild4->previousSibling() == pChild3);
520 assertTrue (pChild4->nextSibling() == pChild5);
521 assertTrue (pChild5->previousSibling() == pChild4);
522 assertTrue (pChild5->nextSibling() == pChild6);
523 assertTrue (pChild6->previousSibling() == pChild5);
524 assertTrue (pChild6->nextSibling() == pChild7);
525 assertTrue (pChild7->previousSibling() == pChild6);
526 assertTrue (pChild7->nextSibling() == pChild8);
527 assertTrue (pChild8->previousSibling() == pChild7);
528 assertTrue (pChild8->nextSibling() == pChild9);
529 assertTrue (pChild9->previousSibling() == pChild8);
530 assertTrue (pChild9->nextSibling() == pChild10);
531 assertTrue (pChild10->previousSibling() == pChild9);
532 assertTrue (pChild10->nextSibling() == pChild11);
533 assertTrue (pChild11->previousSibling() == pChild10);
534 assertTrue (pChild11->nextSibling() == 0);
535}
536
537
538void NodeTest::testAppendFragment1()
539{
540 AutoPtr<Document> pDoc = new Document;
541 AutoPtr<Element> pRoot = pDoc->createElement("root");
542 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
543
544 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
545 pFrag->appendChild(pChild1);
546 pRoot->appendChild(pFrag);
547 assertTrue (pFrag->firstChild() == 0);
548 assertTrue (pFrag->lastChild() == 0);
549 assertTrue (pRoot->firstChild() == pChild1);
550 assertTrue (pRoot->lastChild() == pChild1);
551
552 assertTrue (pChild1->previousSibling() == 0);
553 assertTrue (pChild1->nextSibling() == 0);
554
555 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
556 pFrag->appendChild(pChild2);
557 pRoot->appendChild(pFrag);
558 assertTrue (pRoot->firstChild() == pChild1);
559 assertTrue (pRoot->lastChild() == pChild2);
560
561 assertTrue (pChild1->previousSibling() == 0);
562 assertTrue (pChild1->nextSibling() == pChild2);
563 assertTrue (pChild2->previousSibling() == pChild1);
564 assertTrue (pChild2->nextSibling() == 0);
565
566 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
567 pFrag->appendChild(pChild3);
568 pRoot->appendChild(pFrag);
569 assertTrue (pRoot->firstChild() == pChild1);
570 assertTrue (pRoot->lastChild() == pChild3);
571
572 assertTrue (pChild1->previousSibling() == 0);
573 assertTrue (pChild1->nextSibling() == pChild2);
574 assertTrue (pChild2->previousSibling() == pChild1);
575 assertTrue (pChild2->nextSibling() == pChild3);
576 assertTrue (pChild3->previousSibling() == pChild2);
577 assertTrue (pChild3->nextSibling() == 0);
578}
579
580
581void NodeTest::testAppendFragment2()
582{
583 AutoPtr<Document> pDoc = new Document;
584 AutoPtr<Element> pRoot = pDoc->createElement("root");
585 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
586
587 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
588 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
589 pFrag->appendChild(pChild1);
590 pFrag->appendChild(pChild2);
591 pRoot->appendChild(pFrag);
592 assertTrue (pFrag->firstChild() == 0);
593 assertTrue (pFrag->lastChild() == 0);
594 assertTrue (pRoot->firstChild() == pChild1);
595 assertTrue (pRoot->lastChild() == pChild2);
596
597 assertTrue (pChild1->previousSibling() == 0);
598 assertTrue (pChild1->nextSibling() == pChild2);
599 assertTrue (pChild2->previousSibling() == pChild1);
600 assertTrue (pChild2->nextSibling() == 0);
601
602 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
603 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
604 pFrag->appendChild(pChild3);
605 pFrag->appendChild(pChild4);
606 pRoot->appendChild(pFrag);
607 assertTrue (pRoot->firstChild() == pChild1);
608 assertTrue (pRoot->lastChild() == pChild4);
609
610 assertTrue (pChild1->previousSibling() == 0);
611 assertTrue (pChild1->nextSibling() == pChild2);
612 assertTrue (pChild2->previousSibling() == pChild1);
613 assertTrue (pChild2->nextSibling() == pChild3);
614 assertTrue (pChild3->previousSibling() == pChild2);
615 assertTrue (pChild3->nextSibling() == pChild4);
616 assertTrue (pChild4->previousSibling() == pChild3);
617 assertTrue (pChild4->nextSibling() == 0);
618
619 AutoPtr<Element> pChild5 = pDoc->createElement("child5");
620 AutoPtr<Element> pChild6 = pDoc->createElement("child6");
621 pFrag->appendChild(pChild5);
622 pFrag->appendChild(pChild6);
623 pRoot->appendChild(pFrag);
624 assertTrue (pRoot->firstChild() == pChild1);
625 assertTrue (pRoot->lastChild() == pChild6);
626
627 assertTrue (pChild1->previousSibling() == 0);
628 assertTrue (pChild1->nextSibling() == pChild2);
629 assertTrue (pChild2->previousSibling() == pChild1);
630 assertTrue (pChild2->nextSibling() == pChild3);
631 assertTrue (pChild3->previousSibling() == pChild2);
632 assertTrue (pChild3->nextSibling() == pChild4);
633 assertTrue (pChild4->previousSibling() == pChild3);
634 assertTrue (pChild4->nextSibling() == pChild5);
635 assertTrue (pChild5->previousSibling() == pChild4);
636 assertTrue (pChild5->nextSibling() == pChild6);
637 assertTrue (pChild6->previousSibling() == pChild5);
638 assertTrue (pChild6->nextSibling() == 0);
639}
640
641
642void NodeTest::testAppendFragment3()
643{
644 AutoPtr<Document> pDoc = new Document;
645 AutoPtr<Element> pRoot = pDoc->createElement("root");
646 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
647
648 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
649 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
650 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
651 pFrag->appendChild(pChild1);
652 pFrag->appendChild(pChild2);
653 pFrag->appendChild(pChild3);
654 pRoot->appendChild(pFrag);
655 assertTrue (pFrag->firstChild() == 0);
656 assertTrue (pFrag->lastChild() == 0);
657 assertTrue (pRoot->firstChild() == pChild1);
658 assertTrue (pRoot->lastChild() == pChild3);
659
660 assertTrue (pChild1->previousSibling() == 0);
661 assertTrue (pChild1->nextSibling() == pChild2);
662 assertTrue (pChild2->previousSibling() == pChild1);
663 assertTrue (pChild2->nextSibling() == pChild3);
664 assertTrue (pChild3->previousSibling() == pChild2);
665 assertTrue (pChild3->nextSibling() == 0);
666
667 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
668 AutoPtr<Element> pChild5 = pDoc->createElement("child5");
669 AutoPtr<Element> pChild6 = pDoc->createElement("child6");
670 pFrag->appendChild(pChild4);
671 pFrag->appendChild(pChild5);
672 pFrag->appendChild(pChild6);
673 pRoot->appendChild(pFrag);
674 assertTrue (pRoot->firstChild() == pChild1);
675 assertTrue (pRoot->lastChild() == pChild6);
676
677 assertTrue (pChild1->previousSibling() == 0);
678 assertTrue (pChild1->nextSibling() == pChild2);
679 assertTrue (pChild2->previousSibling() == pChild1);
680 assertTrue (pChild2->nextSibling() == pChild3);
681 assertTrue (pChild3->previousSibling() == pChild2);
682 assertTrue (pChild3->nextSibling() == pChild4);
683 assertTrue (pChild4->previousSibling() == pChild3);
684 assertTrue (pChild4->nextSibling() == pChild5);
685 assertTrue (pChild5->previousSibling() == pChild4);
686 assertTrue (pChild5->nextSibling() == pChild6);
687 assertTrue (pChild6->previousSibling() == pChild5);
688 assertTrue (pChild6->nextSibling() == 0);
689
690 AutoPtr<Element> pChild7 = pDoc->createElement("child7");
691 AutoPtr<Element> pChild8 = pDoc->createElement("child8");
692 AutoPtr<Element> pChild9 = pDoc->createElement("child9");
693 pFrag->appendChild(pChild7);
694 pFrag->appendChild(pChild8);
695 pFrag->appendChild(pChild9);
696 pRoot->appendChild(pFrag);
697 assertTrue (pRoot->firstChild() == pChild1);
698 assertTrue (pRoot->lastChild() == pChild9);
699
700 assertTrue (pChild1->previousSibling() == 0);
701 assertTrue (pChild1->nextSibling() == pChild2);
702 assertTrue (pChild2->previousSibling() == pChild1);
703 assertTrue (pChild2->nextSibling() == pChild3);
704 assertTrue (pChild3->previousSibling() == pChild2);
705 assertTrue (pChild3->nextSibling() == pChild4);
706 assertTrue (pChild4->previousSibling() == pChild3);
707 assertTrue (pChild4->nextSibling() == pChild5);
708 assertTrue (pChild5->previousSibling() == pChild4);
709 assertTrue (pChild5->nextSibling() == pChild6);
710 assertTrue (pChild6->previousSibling() == pChild5);
711 assertTrue (pChild6->nextSibling() == pChild7);
712 assertTrue (pChild7->previousSibling() == pChild6);
713 assertTrue (pChild7->nextSibling() == pChild8);
714 assertTrue (pChild8->previousSibling() == pChild7);
715 assertTrue (pChild8->nextSibling() == pChild9);
716 assertTrue (pChild9->previousSibling() == pChild8);
717 assertTrue (pChild9->nextSibling() == 0);
718}
719
720
721void NodeTest::testReplaceFragment1()
722{
723 AutoPtr<Document> pDoc = new Document;
724 AutoPtr<Element> pRoot = pDoc->createElement("root");
725 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
726
727 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
728 pRoot->appendChild(pChild1);
729
730 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
731 pRoot->appendChild(pChild2);
732
733 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
734 pRoot->appendChild(pChild3);
735
736 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
737 pRoot->appendChild(pChild4);
738
739 AutoPtr<Element> pChild11 = pDoc->createElement("child11");
740 pFrag->appendChild(pChild11);
741 pRoot->replaceChild(pFrag, pChild1);
742 assertTrue (pFrag->firstChild() == 0);
743 assertTrue (pFrag->lastChild() == 0);
744
745 assertTrue (pChild1->previousSibling() == 0);
746 assertTrue (pChild1->nextSibling() == 0);
747 assertTrue (pRoot->firstChild() == pChild11);
748 assertTrue (pRoot->lastChild() == pChild4);
749 assertTrue (pChild11->previousSibling() == 0);
750 assertTrue (pChild11->nextSibling() == pChild2);
751 assertTrue (pChild2->previousSibling() == pChild11);
752 assertTrue (pChild2->nextSibling() == pChild3);
753 assertTrue (pChild3->previousSibling() == pChild2);
754 assertTrue (pChild3->nextSibling() == pChild4);
755 assertTrue (pChild4->previousSibling() == pChild3);
756 assertTrue (pChild4->nextSibling() == 0);
757
758 AutoPtr<Element> pChild22 = pDoc->createElement("child22");
759 pFrag->appendChild(pChild22);
760 pRoot->replaceChild(pFrag, pChild2);
761
762 assertTrue (pChild2->previousSibling() == 0);
763 assertTrue (pChild2->nextSibling() == 0);
764 assertTrue (pRoot->firstChild() == pChild11);
765 assertTrue (pRoot->lastChild() == pChild4);
766 assertTrue (pChild11->previousSibling() == 0);
767 assertTrue (pChild11->nextSibling() == pChild22);
768 assertTrue (pChild22->previousSibling() == pChild11);
769 assertTrue (pChild22->nextSibling() == pChild3);
770 assertTrue (pChild3->previousSibling() == pChild22);
771 assertTrue (pChild3->nextSibling() == pChild4);
772 assertTrue (pChild4->previousSibling() == pChild3);
773 assertTrue (pChild4->nextSibling() == 0);
774
775 AutoPtr<Element> pChild33 = pDoc->createElement("child33");
776 pFrag->appendChild(pChild33);
777 pRoot->replaceChild(pFrag, pChild3);
778
779 assertTrue (pChild3->previousSibling() == 0);
780 assertTrue (pChild3->nextSibling() == 0);
781 assertTrue (pRoot->firstChild() == pChild11);
782 assertTrue (pRoot->lastChild() == pChild4);
783 assertTrue (pChild11->previousSibling() == 0);
784 assertTrue (pChild11->nextSibling() == pChild22);
785 assertTrue (pChild22->previousSibling() == pChild11);
786 assertTrue (pChild22->nextSibling() == pChild33);
787 assertTrue (pChild33->previousSibling() == pChild22);
788 assertTrue (pChild33->nextSibling() == pChild4);
789 assertTrue (pChild4->previousSibling() == pChild33);
790 assertTrue (pChild4->nextSibling() == 0);
791
792 AutoPtr<Element> pChild44 = pDoc->createElement("child44");
793 pFrag->appendChild(pChild44);
794 pRoot->replaceChild(pFrag, pChild4);
795
796 assertTrue (pChild4->previousSibling() == 0);
797 assertTrue (pChild4->nextSibling() == 0);
798 assertTrue (pRoot->firstChild() == pChild11);
799 assertTrue (pRoot->lastChild() == pChild44);
800 assertTrue (pChild11->previousSibling() == 0);
801 assertTrue (pChild11->nextSibling() == pChild22);
802 assertTrue (pChild22->previousSibling() == pChild11);
803 assertTrue (pChild22->nextSibling() == pChild33);
804 assertTrue (pChild33->previousSibling() == pChild22);
805 assertTrue (pChild33->nextSibling() == pChild44);
806 assertTrue (pChild44->previousSibling() == pChild33);
807 assertTrue (pChild44->nextSibling() == 0);
808}
809
810
811void NodeTest::testReplaceFragment2()
812{
813 AutoPtr<Document> pDoc = new Document;
814 AutoPtr<Element> pRoot = pDoc->createElement("root");
815 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
816
817 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
818 pRoot->appendChild(pChild1);
819
820 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
821 pRoot->appendChild(pChild2);
822
823 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
824 pRoot->appendChild(pChild3);
825
826 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
827 pRoot->appendChild(pChild4);
828
829 AutoPtr<Element> pChild11 = pDoc->createElement("child11");
830 AutoPtr<Element> pChild12 = pDoc->createElement("child12");
831 pFrag->appendChild(pChild11);
832 pFrag->appendChild(pChild12);
833 pRoot->replaceChild(pFrag, pChild1);
834 assertTrue (pFrag->firstChild() == 0);
835 assertTrue (pFrag->lastChild() == 0);
836
837 assertTrue (pChild1->previousSibling() == 0);
838 assertTrue (pChild1->nextSibling() == 0);
839 assertTrue (pRoot->firstChild() == pChild11);
840 assertTrue (pRoot->lastChild() == pChild4);
841 assertTrue (pChild11->previousSibling() == 0);
842 assertTrue (pChild11->nextSibling() == pChild12);
843 assertTrue (pChild12->previousSibling() == pChild11);
844 assertTrue (pChild12->nextSibling() == pChild2);
845 assertTrue (pChild2->previousSibling() == pChild12);
846 assertTrue (pChild2->nextSibling() == pChild3);
847 assertTrue (pChild3->previousSibling() == pChild2);
848 assertTrue (pChild3->nextSibling() == pChild4);
849 assertTrue (pChild4->previousSibling() == pChild3);
850 assertTrue (pChild4->nextSibling() == 0);
851
852 AutoPtr<Element> pChild21 = pDoc->createElement("child21");
853 AutoPtr<Element> pChild22 = pDoc->createElement("child22");
854 pFrag->appendChild(pChild21);
855 pFrag->appendChild(pChild22);
856 pRoot->replaceChild(pFrag, pChild2);
857
858 assertTrue (pChild2->previousSibling() == 0);
859 assertTrue (pChild2->nextSibling() == 0);
860 assertTrue (pRoot->firstChild() == pChild11);
861 assertTrue (pRoot->lastChild() == pChild4);
862 assertTrue (pChild11->previousSibling() == 0);
863 assertTrue (pChild11->nextSibling() == pChild12);
864 assertTrue (pChild12->previousSibling() == pChild11);
865 assertTrue (pChild12->nextSibling() == pChild21);
866 assertTrue (pChild21->previousSibling() == pChild12);
867 assertTrue (pChild21->nextSibling() == pChild22);
868 assertTrue (pChild22->previousSibling() == pChild21);
869 assertTrue (pChild22->nextSibling() == pChild3);
870 assertTrue (pChild3->previousSibling() == pChild22);
871 assertTrue (pChild3->nextSibling() == pChild4);
872 assertTrue (pChild4->previousSibling() == pChild3);
873 assertTrue (pChild4->nextSibling() == 0);
874
875 AutoPtr<Element> pChild31 = pDoc->createElement("child31");
876 AutoPtr<Element> pChild32 = pDoc->createElement("child32");
877 pFrag->appendChild(pChild31);
878 pFrag->appendChild(pChild32);
879 pRoot->replaceChild(pFrag, pChild3);
880
881 assertTrue (pChild3->previousSibling() == 0);
882 assertTrue (pChild3->nextSibling() == 0);
883 assertTrue (pRoot->firstChild() == pChild11);
884 assertTrue (pRoot->lastChild() == pChild4);
885 assertTrue (pChild11->previousSibling() == 0);
886 assertTrue (pChild11->nextSibling() == pChild12);
887 assertTrue (pChild12->previousSibling() == pChild11);
888 assertTrue (pChild12->nextSibling() == pChild21);
889 assertTrue (pChild21->previousSibling() == pChild12);
890 assertTrue (pChild21->nextSibling() == pChild22);
891 assertTrue (pChild22->previousSibling() == pChild21);
892 assertTrue (pChild22->nextSibling() == pChild31);
893 assertTrue (pChild31->previousSibling() == pChild22);
894 assertTrue (pChild31->nextSibling() == pChild32);
895 assertTrue (pChild32->previousSibling() == pChild31);
896 assertTrue (pChild32->nextSibling() == pChild4);
897 assertTrue (pChild4->previousSibling() == pChild32);
898 assertTrue (pChild4->nextSibling() == 0);
899
900 AutoPtr<Element> pChild41 = pDoc->createElement("child41");
901 AutoPtr<Element> pChild42 = pDoc->createElement("child42");
902 pFrag->appendChild(pChild41);
903 pFrag->appendChild(pChild42);
904 pRoot->replaceChild(pFrag, pChild4);
905
906 assertTrue (pChild4->previousSibling() == 0);
907 assertTrue (pChild4->nextSibling() == 0);
908 assertTrue (pRoot->firstChild() == pChild11);
909 assertTrue (pRoot->lastChild() == pChild42);
910 assertTrue (pChild11->previousSibling() == 0);
911 assertTrue (pChild11->nextSibling() == pChild12);
912 assertTrue (pChild12->previousSibling() == pChild11);
913 assertTrue (pChild12->nextSibling() == pChild21);
914 assertTrue (pChild21->previousSibling() == pChild12);
915 assertTrue (pChild21->nextSibling() == pChild22);
916 assertTrue (pChild22->previousSibling() == pChild21);
917 assertTrue (pChild22->nextSibling() == pChild31);
918 assertTrue (pChild31->previousSibling() == pChild22);
919 assertTrue (pChild31->nextSibling() == pChild32);
920 assertTrue (pChild32->previousSibling() == pChild31);
921 assertTrue (pChild32->nextSibling() == pChild41);
922 assertTrue (pChild41->previousSibling() == pChild32);
923 assertTrue (pChild41->nextSibling() == pChild42);
924 assertTrue (pChild42->previousSibling() == pChild41);
925 assertTrue (pChild42->nextSibling() == 0);
926}
927
928
929void NodeTest::testReplaceFragment3()
930{
931 AutoPtr<Document> pDoc = new Document;
932 AutoPtr<Element> pRoot = pDoc->createElement("root");
933 AutoPtr<DocumentFragment> pFrag = pDoc->createDocumentFragment();
934
935 AutoPtr<Element> pChild1 = pDoc->createElement("child1");
936 pRoot->appendChild(pChild1);
937
938 AutoPtr<Element> pChild2 = pDoc->createElement("child2");
939 pRoot->appendChild(pChild2);
940
941 AutoPtr<Element> pChild3 = pDoc->createElement("child3");
942 pRoot->appendChild(pChild3);
943
944 AutoPtr<Element> pChild4 = pDoc->createElement("child4");
945 pRoot->appendChild(pChild4);
946
947 AutoPtr<Element> pChild11 = pDoc->createElement("child11");
948 AutoPtr<Element> pChild12 = pDoc->createElement("child12");
949 AutoPtr<Element> pChild13 = pDoc->createElement("child13");
950 pFrag->appendChild(pChild11);
951 pFrag->appendChild(pChild12);
952 pFrag->appendChild(pChild13);
953 pRoot->replaceChild(pFrag, pChild1);
954 assertTrue (pFrag->firstChild() == 0);
955 assertTrue (pFrag->lastChild() == 0);
956
957 assertTrue (pChild1->previousSibling() == 0);
958 assertTrue (pChild1->nextSibling() == 0);
959 assertTrue (pRoot->firstChild() == pChild11);
960 assertTrue (pRoot->lastChild() == pChild4);
961 assertTrue (pChild11->previousSibling() == 0);
962 assertTrue (pChild11->nextSibling() == pChild12);
963 assertTrue (pChild12->previousSibling() == pChild11);
964 assertTrue (pChild12->nextSibling() == pChild13);
965 assertTrue (pChild13->previousSibling() == pChild12);
966 assertTrue (pChild13->nextSibling() == pChild2);
967 assertTrue (pChild2->previousSibling() == pChild13);
968 assertTrue (pChild2->nextSibling() == pChild3);
969 assertTrue (pChild3->previousSibling() == pChild2);
970 assertTrue (pChild3->nextSibling() == pChild4);
971 assertTrue (pChild4->previousSibling() == pChild3);
972 assertTrue (pChild4->nextSibling() == 0);
973
974 AutoPtr<Element> pChild21 = pDoc->createElement("child21");
975 AutoPtr<Element> pChild22 = pDoc->createElement("child22");
976 AutoPtr<Element> pChild23 = pDoc->createElement("child23");
977 pFrag->appendChild(pChild21);
978 pFrag->appendChild(pChild22);
979 pFrag->appendChild(pChild23);
980 pRoot->replaceChild(pFrag, pChild2);
981
982 assertTrue (pChild2->previousSibling() == 0);
983 assertTrue (pChild2->nextSibling() == 0);
984 assertTrue (pRoot->firstChild() == pChild11);
985 assertTrue (pRoot->lastChild() == pChild4);
986 assertTrue (pChild11->previousSibling() == 0);
987 assertTrue (pChild11->nextSibling() == pChild12);
988 assertTrue (pChild12->previousSibling() == pChild11);
989 assertTrue (pChild12->nextSibling() == pChild13);
990 assertTrue (pChild13->previousSibling() == pChild12);
991 assertTrue (pChild13->nextSibling() == pChild21);
992 assertTrue (pChild21->previousSibling() == pChild13);
993 assertTrue (pChild21->nextSibling() == pChild22);
994 assertTrue (pChild22->previousSibling() == pChild21);
995 assertTrue (pChild22->nextSibling() == pChild23);
996 assertTrue (pChild23->previousSibling() == pChild22);
997 assertTrue (pChild23->nextSibling() == pChild3);
998 assertTrue (pChild3->previousSibling() == pChild23);
999 assertTrue (pChild3->nextSibling() == pChild4);
1000 assertTrue (pChild4->previousSibling() == pChild3);
1001 assertTrue (pChild4->nextSibling() == 0);
1002
1003 AutoPtr<Element> pChild31 = pDoc->createElement("child31");
1004 AutoPtr<Element> pChild32 = pDoc->createElement("child32");
1005 AutoPtr<Element> pChild33 = pDoc->createElement("child33");
1006 pFrag->appendChild(pChild31);
1007 pFrag->appendChild(pChild32);
1008 pFrag->appendChild(pChild33);
1009 pRoot->replaceChild(pFrag, pChild3);
1010
1011 assertTrue (pChild3->previousSibling() == 0);
1012 assertTrue (pChild3->nextSibling() == 0);
1013 assertTrue (pRoot->firstChild() == pChild11);
1014 assertTrue (pRoot->lastChild() == pChild4);
1015 assertTrue (pChild11->previousSibling() == 0);
1016 assertTrue (pChild11->nextSibling() == pChild12);
1017 assertTrue (pChild12->previousSibling() == pChild11);
1018 assertTrue (pChild12->nextSibling() == pChild13);
1019 assertTrue (pChild13->previousSibling() == pChild12);
1020 assertTrue (pChild13->nextSibling() == pChild21);
1021 assertTrue (pChild21->previousSibling() == pChild13);
1022 assertTrue (pChild21->nextSibling() == pChild22);
1023 assertTrue (pChild22->previousSibling() == pChild21);
1024 assertTrue (pChild22->nextSibling() == pChild23);
1025 assertTrue (pChild23->previousSibling() == pChild22);
1026 assertTrue (pChild23->nextSibling() == pChild31);
1027 assertTrue (pChild31->previousSibling() == pChild23);
1028 assertTrue (pChild31->nextSibling() == pChild32);
1029 assertTrue (pChild32->previousSibling() == pChild31);
1030 assertTrue (pChild32->nextSibling() == pChild33);
1031 assertTrue (pChild33->previousSibling() == pChild32);
1032 assertTrue (pChild33->nextSibling() == pChild4);
1033 assertTrue (pChild4->previousSibling() == pChild33);
1034 assertTrue (pChild4->nextSibling() == 0);
1035
1036 AutoPtr<Element> pChild41 = pDoc->createElement("child41");
1037 AutoPtr<Element> pChild42 = pDoc->createElement("child42");
1038 AutoPtr<Element> pChild43 = pDoc->createElement("child43");
1039 pFrag->appendChild(pChild41);
1040 pFrag->appendChild(pChild42);
1041 pFrag->appendChild(pChild43);
1042 pRoot->replaceChild(pFrag, pChild4);
1043
1044 assertTrue (pChild4->previousSibling() == 0);
1045 assertTrue (pChild4->nextSibling() == 0);
1046 assertTrue (pRoot->firstChild() == pChild11);
1047 assertTrue (pRoot->lastChild() == pChild43);
1048 assertTrue (pChild11->previousSibling() == 0);
1049 assertTrue (pChild11->nextSibling() == pChild12);
1050 assertTrue (pChild12->previousSibling() == pChild11);
1051 assertTrue (pChild12->nextSibling() == pChild13);
1052 assertTrue (pChild13->previousSibling() == pChild12);
1053 assertTrue (pChild13->nextSibling() == pChild21);
1054 assertTrue (pChild21->previousSibling() == pChild13);
1055 assertTrue (pChild21->nextSibling() == pChild22);
1056 assertTrue (pChild22->previousSibling() == pChild21);
1057 assertTrue (pChild22->nextSibling() == pChild23);
1058 assertTrue (pChild23->previousSibling() == pChild22);
1059 assertTrue (pChild23->nextSibling() == pChild31);
1060 assertTrue (pChild31->previousSibling() == pChild23);
1061 assertTrue (pChild31->nextSibling() == pChild32);
1062 assertTrue (pChild32->previousSibling() == pChild31);
1063 assertTrue (pChild32->nextSibling() == pChild33);
1064 assertTrue (pChild33->previousSibling() == pChild32);
1065 assertTrue (pChild33->nextSibling() == pChild41);
1066 assertTrue (pChild41->previousSibling() == pChild33);
1067 assertTrue (pChild41->nextSibling() == pChild42);
1068 assertTrue (pChild42->previousSibling() == pChild41);
1069 assertTrue (pChild42->nextSibling() == pChild43);
1070 assertTrue (pChild43->previousSibling() == pChild42);
1071 assertTrue (pChild43->nextSibling() == 0);
1072}
1073
1074
1075void NodeTest::setUp()
1076{
1077}
1078
1079
1080void NodeTest::tearDown()
1081{
1082}
1083
1084
1085CppUnit::Test* NodeTest::suite()
1086{
1087 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NodeTest");
1088
1089 CppUnit_addTest(pSuite, NodeTest, testInsert);
1090 CppUnit_addTest(pSuite, NodeTest, testAppend);
1091 CppUnit_addTest(pSuite, NodeTest, testRemove);
1092 CppUnit_addTest(pSuite, NodeTest, testReplace);
1093 CppUnit_addTest(pSuite, NodeTest, testInsertFragment1);
1094 CppUnit_addTest(pSuite, NodeTest, testInsertFragment2);
1095 CppUnit_addTest(pSuite, NodeTest, testInsertFragment3);
1096 CppUnit_addTest(pSuite, NodeTest, testAppendFragment1);
1097 CppUnit_addTest(pSuite, NodeTest, testAppendFragment2);
1098 CppUnit_addTest(pSuite, NodeTest, testAppendFragment3);
1099 CppUnit_addTest(pSuite, NodeTest, testReplaceFragment1);
1100 CppUnit_addTest(pSuite, NodeTest, testReplaceFragment2);
1101 CppUnit_addTest(pSuite, NodeTest, testReplaceFragment3);
1102
1103 return pSuite;
1104}
1105