| 1 | // |
| 2 | // DocumentTypeTest.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 "DocumentTypeTest.h" |
| 12 | #include "Poco/CppUnit/TestCaller.h" |
| 13 | #include "Poco/CppUnit/TestSuite.h" |
| 14 | #include "Poco/DOM/DocumentType.h" |
| 15 | #include "Poco/DOM/Document.h" |
| 16 | #include "Poco/DOM/Notation.h" |
| 17 | #include "Poco/DOM/Entity.h" |
| 18 | #include "Poco/DOM/DOMImplementation.h" |
| 19 | #include "Poco/DOM/NamedNodeMap.h" |
| 20 | #include "Poco/DOM/AutoPtr.h" |
| 21 | |
| 22 | |
| 23 | using Poco::XML::DocumentType; |
| 24 | using Poco::XML::Document; |
| 25 | using Poco::XML::Entity; |
| 26 | using Poco::XML::Notation; |
| 27 | using Poco::XML::DOMImplementation; |
| 28 | using Poco::XML::NamedNodeMap; |
| 29 | using Poco::XML::AutoPtr; |
| 30 | |
| 31 | |
| 32 | DocumentTypeTest::DocumentTypeTest(const std::string& name): CppUnit::TestCase(name) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | |
| 37 | DocumentTypeTest::~DocumentTypeTest() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | |
| 42 | void DocumentTypeTest::testDocumentType() |
| 43 | { |
| 44 | AutoPtr<DocumentType> pDoctype = DOMImplementation::instance().createDocumentType("test" , "public" , "system" ); |
| 45 | |
| 46 | assertTrue (pDoctype->ownerDocument() == 0); |
| 47 | assertTrue (pDoctype->name() == "test" ); |
| 48 | assertTrue (pDoctype->publicId() == "public" ); |
| 49 | assertTrue (pDoctype->systemId() == "system" ); |
| 50 | |
| 51 | AutoPtr<Document> pDoc = new Document(pDoctype); |
| 52 | assertTrue (pDoc->doctype() == pDoctype); |
| 53 | assertTrue (pDoctype->ownerDocument() == pDoc); |
| 54 | |
| 55 | AutoPtr<NamedNodeMap> pEntities = pDoctype->entities(); |
| 56 | AutoPtr<NamedNodeMap> pNotations = pDoctype->notations(); |
| 57 | |
| 58 | assertTrue (pEntities->length() == 0); |
| 59 | assertTrue (pNotations->length() == 0); |
| 60 | |
| 61 | AutoPtr<Entity> pEntity1 = pDoc->createEntity("entity1" , "public1" , "system1" , "" ); |
| 62 | pDoctype->appendChild(pEntity1); |
| 63 | |
| 64 | assertTrue (pEntities->length() == 1); |
| 65 | assertTrue (pNotations->length() == 0); |
| 66 | assertTrue (pEntities->item(0) == pEntity1); |
| 67 | assertTrue (pEntities->getNamedItem("entity1" ) == pEntity1); |
| 68 | |
| 69 | AutoPtr<Entity> pEntity2 = pDoc->createEntity("entity2" , "public2" , "system2" , "" ); |
| 70 | pDoctype->appendChild(pEntity2); |
| 71 | assertTrue (pEntities->length() == 2); |
| 72 | assertTrue (pNotations->length() == 0); |
| 73 | assertTrue (pEntities->item(0) == pEntity1); |
| 74 | assertTrue (pEntities->item(1) == pEntity2); |
| 75 | assertTrue (pEntities->getNamedItem("entity1" ) == pEntity1); |
| 76 | assertTrue (pEntities->getNamedItem("entity2" ) == pEntity2); |
| 77 | |
| 78 | AutoPtr<Notation> pNotation = pDoc->createNotation("notation" , "public" , "system" ); |
| 79 | pDoctype->appendChild(pNotation); |
| 80 | assertTrue (pEntities->length() == 2); |
| 81 | assertTrue (pNotations->length() == 1); |
| 82 | assertTrue (pEntities->item(0) == pEntity1); |
| 83 | assertTrue (pEntities->item(1) == pEntity2); |
| 84 | assertTrue (pNotations->item(0) == pNotation); |
| 85 | assertTrue (pEntities->getNamedItem("entity1" ) == pEntity1); |
| 86 | assertTrue (pEntities->getNamedItem("entity2" ) == pEntity2); |
| 87 | assertTrue (pNotations->getNamedItem("notation" ) == pNotation); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | void DocumentTypeTest::setUp() |
| 92 | { |
| 93 | } |
| 94 | |
| 95 | |
| 96 | void DocumentTypeTest::tearDown() |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | |
| 101 | CppUnit::Test* DocumentTypeTest::suite() |
| 102 | { |
| 103 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DocumentTypeTest" ); |
| 104 | |
| 105 | CppUnit_addTest(pSuite, DocumentTypeTest, testDocumentType); |
| 106 | |
| 107 | return pSuite; |
| 108 | } |
| 109 | |