1//
2// EventTest.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 "EventTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/DOM/Event.h"
15#include "Poco/DOM/MutationEvent.h"
16#include "Poco/DOM/EventListener.h"
17#include "Poco/DOM/Document.h"
18#include "Poco/DOM/Element.h"
19#include "Poco/DOM/Attr.h"
20#include "Poco/DOM/Text.h"
21#include "Poco/DOM/AutoPtr.h"
22
23
24using Poco::XML::Event;
25using Poco::XML::MutationEvent;
26using Poco::XML::EventListener;
27using Poco::XML::Element;
28using Poco::XML::Document;
29using Poco::XML::Attr;
30using Poco::XML::Text;
31using Poco::XML::Node;
32using Poco::XML::AutoPtr;
33using Poco::XML::XMLString;
34
35
36class TestEventListener: public EventListener
37{
38public:
39 TestEventListener(const XMLString& name, bool cancel = false, bool readd = false, bool capture = false):
40 _name(name),
41 _cancel(cancel),
42 _readd(readd),
43 _capture(capture)
44 {
45 }
46
47 void handleEvent(Event* evt)
48 {
49 XMLString type = evt->type();
50 XMLString phase;
51 switch (evt->eventPhase())
52 {
53 case Event::CAPTURING_PHASE:
54 phase = "CAPTURING_PHASE"; break;
55 case Event::AT_TARGET:
56 phase = "AT_TARGET"; break;
57 case Event::BUBBLING_PHASE:
58 phase = "BUBBLING_PHASE"; break;
59 }
60 Node* pTarget = static_cast<Node*>(evt->target());
61 Node* pCurrentTarget = static_cast<Node*>(evt->currentTarget());
62
63 _log.append(_name);
64 _log.append(":");
65 _log.append(type);
66 _log.append(":");
67 _log.append(phase);
68 _log.append(":");
69 _log.append(pTarget->nodeName());
70 _log.append(":");
71 _log.append(pCurrentTarget->nodeName());
72 _log.append(":");
73 _log.append(evt->bubbles() ? "B" : "-");
74 _log.append(":");
75 _log.append(evt->cancelable() ? "C" : "-");
76
77 MutationEvent* pME = dynamic_cast<MutationEvent*>(evt);
78 if (pME)
79 {
80 XMLString attrChange;
81 switch (pME->attrChange())
82 {
83 case MutationEvent::MODIFICATION:
84 attrChange = "MODIFICATION"; break;
85 case MutationEvent::ADDITION:
86 attrChange = "ADDITION"; break;
87 case MutationEvent::REMOVAL:
88 attrChange = "REMOVAL"; break;
89 }
90 XMLString relatedNode;
91 Node* pRelatedNode = pME->relatedNode();
92 if (pRelatedNode) relatedNode = pRelatedNode->nodeName();
93
94 _log.append(":");
95 _log.append(attrChange);
96 _log.append(":");
97 _log.append(relatedNode);
98 _log.append(":");
99 _log.append(pME->attrName());
100 _log.append(":");
101 _log.append(pME->prevValue());
102 _log.append(":");
103 _log.append(pME->newValue());
104 }
105 _log.append("\n");
106
107 if (_cancel) evt->stopPropagation();
108 if (_readd)
109 pCurrentTarget->addEventListener(type, this, _capture);
110 }
111
112 static const XMLString& log()
113 {
114 return _log;
115 }
116
117 static void reset()
118 {
119 _log.clear();
120 }
121
122private:
123 XMLString _name;
124 bool _cancel;
125 bool _readd;
126 bool _capture;
127 static XMLString _log;
128};
129
130
131XMLString TestEventListener::_log;
132
133
134EventTest::EventTest(const std::string& name): CppUnit::TestCase(name)
135{
136}
137
138
139EventTest::~EventTest()
140{
141}
142
143
144void EventTest::testInsert()
145{
146 AutoPtr<Document> pDoc = new Document;
147 AutoPtr<Element> pRoot = pDoc->createElement("root");
148
149 TestEventListener docListener("doc");
150 TestEventListener docCapListener("docCap");
151 TestEventListener rootListener("root");
152 TestEventListener rootCapListener("rootCap");
153
154 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
155 pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false);
156 pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false);
157
158 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
159 pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true);
160 pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true);
161
162 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
163 pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false);
164 pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false);
165
166 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
167 pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true);
168 pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true);
169
170 pDoc->appendChild(pRoot);
171
172 const XMLString& log = TestEventListener::log();
173
174 assertTrue (log ==
175 "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
176 "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
177 "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
178 "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
179 "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n"
180 "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
181 "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
182 "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
183 "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
184 );
185
186 TestEventListener::reset();
187
188 AutoPtr<Text> pText = pDoc->createTextNode("text");
189 pRoot->appendChild(pText);
190
191 assertTrue (log ==
192 "docCap:DOMNodeInserted:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
193 "rootCap:DOMNodeInserted:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
194 "root:DOMNodeInserted:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
195 "doc:DOMNodeInserted:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
196 "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
197 "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
198 "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n"
199 "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
200 "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
201 "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n"
202 );
203}
204
205
206void EventTest::testInsertSubtree()
207{
208 AutoPtr<Document> pDoc = new Document;
209 AutoPtr<Element> pRoot = pDoc->createElement("root");
210
211 TestEventListener docListener("doc");
212 TestEventListener docCapListener("docCap");
213 TestEventListener rootListener("root");
214 TestEventListener rootCapListener("rootCap");
215
216 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
217 pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false);
218 pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false);
219
220 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
221 pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true);
222 pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true);
223
224 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
225 pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false);
226 pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false);
227
228 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
229 pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true);
230 pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true);
231
232 AutoPtr<Text> pText = pDoc->createTextNode("text");
233 pRoot->appendChild(pText);
234
235 TestEventListener::reset();
236
237 pDoc->appendChild(pRoot);
238
239 const XMLString& log = TestEventListener::log();
240 assertTrue (log ==
241 "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
242 "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
243 "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
244 "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
245 "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n"
246 "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
247 "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
248 "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
249 "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
250 "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
251 "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
252 );
253}
254
255
256void EventTest::testRemove()
257{
258 AutoPtr<Document> pDoc = new Document;
259 AutoPtr<Element> pRoot = pDoc->createElement("root");
260
261 TestEventListener docListener("doc");
262 TestEventListener docCapListener("docCap");
263 TestEventListener rootListener("root");
264 TestEventListener rootCapListener("rootCap");
265
266 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
267 pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docListener, false);
268 pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docListener, false);
269
270 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
271 pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docCapListener, true);
272 pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docCapListener, true);
273
274 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
275 pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootListener, false);
276 pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootListener, false);
277
278 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
279 pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootCapListener, true);
280 pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootCapListener, true);
281
282 pDoc->appendChild(pRoot);
283
284 AutoPtr<Text> pText = pDoc->createTextNode("text");
285 pRoot->appendChild(pText);
286
287 TestEventListener::reset();
288
289 pRoot->removeChild(pText);
290
291 const XMLString& log = TestEventListener::log();
292 assertTrue (log ==
293 "docCap:DOMNodeRemoved:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
294 "rootCap:DOMNodeRemoved:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
295 "root:DOMNodeRemoved:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
296 "doc:DOMNodeRemoved:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
297 "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
298 "rootCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
299 "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n"
300 "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
301 "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
302 "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n"
303 );
304}
305
306
307void EventTest::testRemoveSubtree()
308{
309 AutoPtr<Document> pDoc = new Document;
310 AutoPtr<Element> pRoot = pDoc->createElement("root");
311
312 TestEventListener docListener("doc");
313 TestEventListener docCapListener("docCap");
314 TestEventListener rootListener("root");
315 TestEventListener rootCapListener("rootCap");
316
317 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
318 pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docListener, false);
319 pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docListener, false);
320
321 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
322 pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docCapListener, true);
323 pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docCapListener, true);
324
325 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
326 pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootListener, false);
327 pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootListener, false);
328
329 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
330 pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootCapListener, true);
331 pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootCapListener, true);
332
333 pDoc->appendChild(pRoot);
334
335 AutoPtr<Text> pText = pDoc->createTextNode("text");
336 pRoot->appendChild(pText);
337
338 TestEventListener::reset();
339
340 pDoc->removeChild(pRoot);
341
342 const XMLString& log = TestEventListener::log();
343 assertTrue (log ==
344 "docCap:DOMNodeRemoved:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
345 "rootCap:DOMNodeRemoved:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
346 "root:DOMNodeRemoved:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
347 "doc:DOMNodeRemoved:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
348 "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n"
349 "rootCap:DOMNodeRemovedFromDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
350 "root:DOMNodeRemovedFromDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
351 "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
352 "rootCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
353 "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
354 "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
355 );
356}
357
358
359void EventTest::testCharacterData()
360{
361 AutoPtr<Document> pDoc = new Document;
362 AutoPtr<Element> pRoot = pDoc->createElement("root");
363 AutoPtr<Text> pText = pDoc->createTextNode("text");
364 pRoot->appendChild(pText);
365 pDoc->appendChild(pRoot);
366
367 TestEventListener docListener("doc");
368 TestEventListener docCapListener("docCap");
369 TestEventListener rootListener("root");
370 TestEventListener rootCapListener("rootCap");
371 TestEventListener textListener("text");
372 TestEventListener textCapListener("textCap");
373
374 pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docListener, false);
375 pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docCapListener, true);
376 pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootListener, false);
377 pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootCapListener, true);
378 pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textListener, false);
379 pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textCapListener, true);
380
381 TestEventListener::reset();
382
383 pText->setData("modified");
384
385 const XMLString& log = TestEventListener::log();
386 assertTrue (log ==
387 "docCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n"
388 "rootCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:::text:modified\n"
389 "textCap:DOMCharacterDataModified:AT_TARGET:#text:#text:B:-:MODIFICATION:::text:modified\n"
390 "text:DOMCharacterDataModified:AT_TARGET:#text:#text:B:-:MODIFICATION:::text:modified\n"
391 "root:DOMCharacterDataModified:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:::text:modified\n"
392 "doc:DOMCharacterDataModified:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n"
393 );
394}
395
396
397void EventTest::testCancel()
398{
399 AutoPtr<Document> pDoc = new Document;
400 AutoPtr<Element> pRoot = pDoc->createElement("root");
401 AutoPtr<Text> pText = pDoc->createTextNode("text");
402 pRoot->appendChild(pText);
403 pDoc->appendChild(pRoot);
404
405 TestEventListener docListener("doc");
406 TestEventListener docCapListener("docCap", true);
407 TestEventListener rootListener("root");
408 TestEventListener rootCapListener("rootCap");
409 TestEventListener textListener("text");
410 TestEventListener textCapListener("textCap");
411
412 pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docListener, false);
413 pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docCapListener, true);
414 pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootListener, false);
415 pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootCapListener, true);
416 pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textListener, false);
417 pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textCapListener, true);
418
419 TestEventListener::reset();
420
421 pText->setData("modified");
422
423 const XMLString& log = TestEventListener::log();
424 assertTrue (log == "docCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n");
425}
426
427
428void EventTest::testAttributes()
429{
430 AutoPtr<Document> pDoc = new Document;
431 AutoPtr<Element> pRoot = pDoc->createElement("root");
432
433 TestEventListener rootListener("root");
434 pRoot->addEventListener(MutationEvent::DOMAttrModified, &rootListener, false);
435
436 pRoot->setAttribute("a1", "v1");
437
438 const XMLString& log = TestEventListener::log();
439 assertTrue (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:ADDITION:a1:a1::v1\n");
440
441 TestEventListener::reset();
442 pRoot->setAttribute("a1", "V1");
443 assertTrue (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:MODIFICATION:a1:a1:v1:V1\n");
444
445 TestEventListener::reset();
446 pRoot->setAttribute("a2", "v2");
447 assertTrue (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:ADDITION:a2:a2::v2\n");
448
449 TestEventListener::reset();
450 pRoot->removeAttribute("a1");
451 assertTrue (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:REMOVAL:a1:a1:V1:\n");
452}
453
454
455void EventTest::testAddRemoveInEvent()
456{
457 AutoPtr<Document> pDoc = new Document;
458 AutoPtr<Element> pRoot = pDoc->createElement("root");
459
460 TestEventListener docListener("doc", false, true, false);
461 TestEventListener docCapListener("docCap", false, true, true);
462 TestEventListener rootListener("root", false, true, false);
463 TestEventListener rootCapListener("rootCap", false, true, true);
464
465 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
466 pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false);
467 pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false);
468
469 pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
470 pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true);
471 pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true);
472
473 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
474 pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false);
475 pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false);
476
477 pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
478 pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true);
479 pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true);
480
481 pDoc->appendChild(pRoot);
482
483 const XMLString& log = TestEventListener::log();
484 assertTrue (log ==
485 "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
486 "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
487 "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
488 "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
489 "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n"
490 "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
491 "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
492 "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
493 "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
494 );
495
496 TestEventListener::reset();
497
498 AutoPtr<Text> pText = pDoc->createTextNode("text");
499 pRoot->appendChild(pText);
500
501 assertTrue (log ==
502 "docCap:DOMNodeInserted:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
503 "rootCap:DOMNodeInserted:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
504 "root:DOMNodeInserted:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
505 "doc:DOMNodeInserted:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
506 "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
507 "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
508 "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n"
509 "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
510 "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
511 "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n"
512 );
513}
514
515
516void EventTest::testSuspended()
517{
518 AutoPtr<Document> pDoc = new Document;
519 AutoPtr<Element> pRoot = pDoc->createElement("root");
520
521 pDoc->suspendEvents();
522
523 TestEventListener rootListener("root");
524 pRoot->addEventListener(MutationEvent::DOMAttrModified, &rootListener, false);
525
526 pRoot->setAttribute("a1", "v1");
527
528 const XMLString& log = TestEventListener::log();
529 assertTrue (log.empty());
530
531 TestEventListener::reset();
532 pRoot->setAttribute("a1", "V1");
533 assertTrue (log.empty());
534
535 TestEventListener::reset();
536 pRoot->setAttribute("a2", "v2");
537 assertTrue (log.empty());
538
539 TestEventListener::reset();
540 pRoot->removeAttribute("a1");
541 assertTrue (log.empty());
542}
543
544
545void EventTest::setUp()
546{
547 TestEventListener::reset();
548}
549
550
551void EventTest::tearDown()
552{
553}
554
555
556CppUnit::Test* EventTest::suite()
557{
558 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("EventTest");
559
560 CppUnit_addTest(pSuite, EventTest, testInsert);
561 CppUnit_addTest(pSuite, EventTest, testInsertSubtree);
562 CppUnit_addTest(pSuite, EventTest, testRemove);
563 CppUnit_addTest(pSuite, EventTest, testRemoveSubtree);
564 CppUnit_addTest(pSuite, EventTest, testCharacterData);
565 CppUnit_addTest(pSuite, EventTest, testCancel);
566 CppUnit_addTest(pSuite, EventTest, testAttributes);
567 CppUnit_addTest(pSuite, EventTest, testAddRemoveInEvent);
568 CppUnit_addTest(pSuite, EventTest, testSuspended);
569
570 return pSuite;
571}
572