1 | // |
---|---|
2 | // ChildNodesTest.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 "ChildNodesTest.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/NodeList.h" |
17 | #include "Poco/DOM/AutoPtr.h" |
18 | |
19 | |
20 | using Poco::XML::Element; |
21 | using Poco::XML::Document; |
22 | using Poco::XML::NodeList; |
23 | using Poco::XML::Node; |
24 | using Poco::XML::AutoPtr; |
25 | |
26 | |
27 | ChildNodesTest::ChildNodesTest(const std::string& name): CppUnit::TestCase(name) |
28 | { |
29 | } |
30 | |
31 | |
32 | ChildNodesTest::~ChildNodesTest() |
33 | { |
34 | } |
35 | |
36 | |
37 | void ChildNodesTest::testChildNodes() |
38 | { |
39 | AutoPtr<Document> pDoc = new Document; |
40 | AutoPtr<Element> pRoot = pDoc->createElement("root"); |
41 | |
42 | assertTrue (!pRoot->hasChildNodes()); |
43 | AutoPtr<NodeList> pNL = pRoot->childNodes(); |
44 | assertTrue (pNL->length() == 0); |
45 | |
46 | AutoPtr<Element> pChild1 = pDoc->createElement("child1"); |
47 | pRoot->appendChild(pChild1); |
48 | assertTrue (pRoot->hasChildNodes()); |
49 | |
50 | assertTrue (pNL->length() == 1); |
51 | assertTrue (pNL->item(0) == pChild1); |
52 | |
53 | AutoPtr<Element> pChild2 = pDoc->createElement("child2"); |
54 | pRoot->appendChild(pChild2); |
55 | |
56 | assertTrue (pNL->length() == 2); |
57 | assertTrue (pNL->item(0) == pChild1); |
58 | assertTrue (pNL->item(1) == pChild2); |
59 | |
60 | AutoPtr<Element> pChild0 = pDoc->createElement("child0"); |
61 | pRoot->insertBefore(pChild0, pChild1); |
62 | |
63 | assertTrue (pNL->length() == 3); |
64 | assertTrue (pNL->item(0) == pChild0); |
65 | assertTrue (pNL->item(1) == pChild1); |
66 | assertTrue (pNL->item(2) == pChild2); |
67 | |
68 | pRoot->removeChild(pChild1); |
69 | assertTrue (pNL->length() == 2); |
70 | assertTrue (pNL->item(0) == pChild0); |
71 | assertTrue (pNL->item(1) == pChild2); |
72 | |
73 | pRoot->removeChild(pChild0); |
74 | assertTrue (pNL->length() == 1); |
75 | assertTrue (pNL->item(0) == pChild2); |
76 | |
77 | pRoot->removeChild(pChild2); |
78 | assertTrue (pNL->length() == 0); |
79 | assertTrue (pNL->item(0) == 0); |
80 | |
81 | assertTrue (!pRoot->hasChildNodes()); |
82 | } |
83 | |
84 | |
85 | void ChildNodesTest::setUp() |
86 | { |
87 | } |
88 | |
89 | |
90 | void ChildNodesTest::tearDown() |
91 | { |
92 | } |
93 | |
94 | |
95 | CppUnit::Test* ChildNodesTest::suite() |
96 | { |
97 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ChildNodesTest"); |
98 | |
99 | CppUnit_addTest(pSuite, ChildNodesTest, testChildNodes); |
100 | |
101 | return pSuite; |
102 | } |
103 |