initial import

This commit is contained in:
Guenter Obiltschnig
2006-07-11 16:33:40 +00:00
commit f476bd6b32
1463 changed files with 242402 additions and 0 deletions

View File

@@ -0,0 +1,266 @@
//
// AttributesImplTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/AttributesImplTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "AttributesImplTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "SAX/AttributesImpl.h"
using XML::AttributesImpl;
AttributesImplTest::AttributesImplTest(const std::string& name): CppUnit::TestCase(name)
{
}
AttributesImplTest::~AttributesImplTest()
{
}
void AttributesImplTest::testNoNamespaces()
{
AttributesImpl attrs;
assert (attrs.getLength() == 0);
assert (attrs.getIndex("foo") == -1);
assert (attrs.getValue("foo").empty());
attrs.addAttribute("", "", "a1", "CDATA", "v1");
assert (attrs.getLength() == 1);
assert (attrs.getIndex("a1") == 0);
assert (attrs.getQName(0) == "a1");
assert (attrs.getType(0) == "CDATA");
assert (attrs.getValue(0) == "v1");
assert (attrs.isSpecified(0));
assert (attrs.getType("a1") == "CDATA");
assert (attrs.getValue("a1") == "v1");
attrs.addAttribute("", "", "a2", "CDATA", "v2");
assert (attrs.getLength() == 2);
assert (attrs.getIndex("a2") == 1);
assert (attrs.getQName(1) == "a2");
assert (attrs.getType(1) == "CDATA");
assert (attrs.getValue(1) == "v2");
assert (attrs.isSpecified(1));
assert (attrs.getType("a2") == "CDATA");
assert (attrs.getValue("a2") == "v2");
attrs.addAttribute("", "", "a3", "CDATA", "v3");
assert (attrs.getLength() == 3);
assert (attrs.getIndex("a3") == 2);
assert (attrs.getValue("a3") == "v3");
attrs.removeAttribute(0);
assert (attrs.getLength() == 2);
assert (attrs.getIndex("a1") == -1);
assert (attrs.getIndex("a2") == 0);
assert (attrs.getIndex("a3") == 1);
assert (attrs.getQName(0) == "a2");
assert (attrs.getQName(1) == "a3");
attrs.removeAttribute("a3");
assert (attrs.getLength() == 1);
assert (attrs.getIndex("a1") == -1);
assert (attrs.getIndex("a2") == 0);
assert (attrs.getIndex("a3") == -1);
assert (attrs.getQName(0) == "a2");
}
void AttributesImplTest::testNamespaces()
{
AttributesImpl attrs;
assert (attrs.getLength() == 0);
assert (attrs.getIndex("urn:ns", "foo") == -1);
assert (attrs.getValue("urn:ns", "foo").empty());
attrs.addAttribute("urn:ns", "a1", "p:a1", "CDATA", "v1");
assert (attrs.getLength() == 1);
assert (attrs.getIndex("urn:ns", "a1") == 0);
assert (attrs.getQName(0) == "p:a1");
assert (attrs.getLocalName(0) == "a1");
assert (attrs.getURI(0) == "urn:ns");
assert (attrs.getType(0) == "CDATA");
assert (attrs.getValue(0) == "v1");
assert (attrs.isSpecified(0));
assert (attrs.getType("urn:ns", "a1") == "CDATA");
assert (attrs.getValue("urn:ns", "a1") == "v1");
attrs.addAttribute("urn:ns", "a2", "p:a2", "CDATA", "v2");
assert (attrs.getLength() == 2);
assert (attrs.getIndex("urn:ns", "a2") == 1);
assert (attrs.getQName(1) == "p:a2");
assert (attrs.getLocalName(1) == "a2");
assert (attrs.getURI(1) == "urn:ns");
assert (attrs.getType(1) == "CDATA");
assert (attrs.getValue(1) == "v2");
assert (attrs.isSpecified(1));
assert (attrs.getType("urn:ns", "a2") == "CDATA");
assert (attrs.getValue("urn:ns", "a2") == "v2");
assert (attrs.getIndex("urn:ns2", "a2") == -1);
attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3");
assert (attrs.getLength() == 3);
assert (attrs.getIndex("urn:ns2", "a3") == 2);
assert (attrs.getValue("urn:ns2", "a3") == "v3");
attrs.removeAttribute(0);
assert (attrs.getLength() == 2);
assert (attrs.getIndex("urn:ns", "a1") == -1);
assert (attrs.getIndex("urn:ns", "a2") == 0);
assert (attrs.getIndex("urn:ns2", "a3") == 1);
assert (attrs.getQName(0) == "p:a2");
assert (attrs.getLocalName(0) == "a2");
assert (attrs.getURI(0) == "urn:ns");
assert (attrs.getQName(1) == "q:a3");
assert (attrs.getLocalName(1) == "a3");
assert (attrs.getURI(1) == "urn:ns2");
attrs.removeAttribute("urn:ns", "a3");
assert (attrs.getLength() == 2);
attrs.removeAttribute("urn:ns2", "a3");
assert (attrs.getLength() == 1);
assert (attrs.getIndex("urn:ns", "a1") == -1);
assert (attrs.getIndex("urn:ns", "a2") == 0);
assert (attrs.getIndex("urn:ns2", "a3") == -1);
assert (attrs.getQName(0) == "p:a2");
}
void AttributesImplTest::testAccessors()
{
AttributesImpl attrs;
attrs.addAttribute("urn:ns1", "a1", "p:a1", "CDATA", "v1");
attrs.addAttribute("urn:ns1", "a2", "p:a2", "CDATA", "v2", false);
attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3", true);
assert (attrs.getQName(0) == "p:a1");
assert (attrs.getQName(1) == "p:a2");
assert (attrs.getQName(2) == "q:a3");
assert (attrs.getLocalName(0) == "a1");
assert (attrs.getLocalName(1) == "a2");
assert (attrs.getLocalName(2) == "a3");
assert (attrs.getURI(0) == "urn:ns1");
assert (attrs.getURI(1) == "urn:ns1");
assert (attrs.getURI(2) == "urn:ns2");
assert (attrs.getValue(0) == "v1");
assert (attrs.getValue(1) == "v2");
assert (attrs.getValue(2) == "v3");
assert (attrs.isSpecified(0));
assert (!attrs.isSpecified(1));
assert (attrs.isSpecified(2));
attrs.setType(0, "NMTOKEN");
assert (attrs.getType(0) == "NMTOKEN");
assert (attrs.getType("urn:ns1", "a1") == "NMTOKEN");
attrs.setValue(1, "v2 v2");
assert (attrs.getValue(1) == "v2 v2");
assert (attrs.getValue("urn:ns1", "a2") == "v2 v2");
assert (attrs.isSpecified(1));
attrs.setLocalName(2, "A3");
assert (attrs.getLocalName(2) == "A3");
attrs.setQName(2, "p:A3");
assert (attrs.getQName(2) == "p:A3");
attrs.setURI(2, "urn:ns1");
assert (attrs.getURI(2) == "urn:ns1");
assert (attrs.getValue("urn:ns1", "A3") == "v3");
}
void AttributesImplTest::testCopy()
{
AttributesImpl attrs;
attrs.addAttribute("urn:ns1", "a1", "p:a1", "CDATA", "v1");
attrs.addAttribute("urn:ns1", "a2", "p:a2", "CDATA", "v2");
attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3");
AttributesImpl attrs2;
attrs2.setAttributes(attrs);
assert (attrs2.getLength() == 3);
assert (attrs2.getQName(0) == "p:a1");
assert (attrs2.getQName(1) == "p:a2");
assert (attrs2.getQName(2) == "q:a3");
assert (attrs2.getLocalName(0) == "a1");
assert (attrs2.getLocalName(1) == "a2");
assert (attrs2.getLocalName(2) == "a3");
assert (attrs2.getURI(0) == "urn:ns1");
assert (attrs2.getURI(1) == "urn:ns1");
assert (attrs2.getURI(2) == "urn:ns2");
assert (attrs2.getValue(0) == "v1");
assert (attrs2.getValue(1) == "v2");
assert (attrs2.getValue(2) == "v3");
}
void AttributesImplTest::setUp()
{
}
void AttributesImplTest::tearDown()
{
}
CppUnit::Test* AttributesImplTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AttributesImplTest");
CppUnit_addTest(pSuite, AttributesImplTest, testNoNamespaces);
CppUnit_addTest(pSuite, AttributesImplTest, testNamespaces);
CppUnit_addTest(pSuite, AttributesImplTest, testAccessors);
CppUnit_addTest(pSuite, AttributesImplTest, testCopy);
return pSuite;
}

View File

@@ -0,0 +1,67 @@
//
// AttributesImplTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/AttributesImplTest.h#2 $
//
// Definition of the AttributesImplTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef AttributesImplTest_INCLUDED
#define AttributesImplTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class AttributesImplTest: public CppUnit::TestCase
{
public:
AttributesImplTest(const std::string& name);
~AttributesImplTest();
void testNoNamespaces();
void testNamespaces();
void testAccessors();
void testCopy();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // AttributesImplTest_INCLUDED

View File

@@ -0,0 +1,124 @@
//
// ChildNodesTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/ChildNodesTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "ChildNodesTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/Document.h"
#include "DOM/Element.h"
#include "DOM/NodeList.h"
#include "DOM/AutoPtr.h"
using XML::Element;
using XML::Document;
using XML::NodeList;
using XML::Node;
using XML::AutoPtr;
ChildNodesTest::ChildNodesTest(const std::string& name): CppUnit::TestCase(name)
{
}
ChildNodesTest::~ChildNodesTest()
{
}
void ChildNodesTest::testChildNodes()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
assert (!pRoot->hasChildNodes());
AutoPtr<NodeList> pNL = pRoot->childNodes();
assert (pNL->length() == 0);
AutoPtr<Element> pChild1 = pDoc->createElement("child1");
pRoot->appendChild(pChild1);
assert (pRoot->hasChildNodes());
assert (pNL->length() == 1);
assert (pNL->item(0) == pChild1);
AutoPtr<Element> pChild2 = pDoc->createElement("child2");
pRoot->appendChild(pChild2);
assert (pNL->length() == 2);
assert (pNL->item(0) == pChild1);
assert (pNL->item(1) == pChild2);
AutoPtr<Element> pChild0 = pDoc->createElement("child0");
pRoot->insertBefore(pChild0, pChild1);
assert (pNL->length() == 3);
assert (pNL->item(0) == pChild0);
assert (pNL->item(1) == pChild1);
assert (pNL->item(2) == pChild2);
pRoot->removeChild(pChild1);
assert (pNL->length() == 2);
assert (pNL->item(0) == pChild0);
assert (pNL->item(1) == pChild2);
pRoot->removeChild(pChild0);
assert (pNL->length() == 1);
assert (pNL->item(0) == pChild2);
pRoot->removeChild(pChild2);
assert (pNL->length() == 0);
assert (pNL->item(0) == 0);
assert (!pRoot->hasChildNodes());
}
void ChildNodesTest::setUp()
{
}
void ChildNodesTest::tearDown()
{
}
CppUnit::Test* ChildNodesTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ChildNodesTest");
CppUnit_addTest(pSuite, ChildNodesTest, testChildNodes);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// ChildNodesTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/ChildNodesTest.h#2 $
//
// Definition of the ChildNodesTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ChildNodesTest_INCLUDED
#define ChildNodesTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class ChildNodesTest: public CppUnit::TestCase
{
public:
ChildNodesTest(const std::string& name);
~ChildNodesTest();
void testChildNodes();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // ChildNodesTest_INCLUDED

View File

@@ -0,0 +1,62 @@
//
// DOMTestSuite.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/DOMTestSuite.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOMTestSuite.h"
#include "NodeTest.h"
#include "ChildNodesTest.h"
#include "ElementTest.h"
#include "TextTest.h"
#include "DocumentTest.h"
#include "DocumentTypeTest.h"
#include "EventTest.h"
#include "NodeIteratorTest.h"
#include "TreeWalkerTest.h"
#include "ParserWriterTest.h"
CppUnit::Test* DOMTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DOMTestSuite");
pSuite->addTest(NodeTest::suite());
pSuite->addTest(ChildNodesTest::suite());
pSuite->addTest(ElementTest::suite());
pSuite->addTest(TextTest::suite());
pSuite->addTest(DocumentTest::suite());
pSuite->addTest(DocumentTypeTest::suite());
pSuite->addTest(EventTest::suite());
pSuite->addTest(NodeIteratorTest::suite());
pSuite->addTest(TreeWalkerTest::suite());
pSuite->addTest(ParserWriterTest::suite());
return pSuite;
}

View File

@@ -0,0 +1,51 @@
//
// DOMTestSuite.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/DOMTestSuite.h#2 $
//
// Definition of the DOMTestSuite class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef DOMTestSuite_INCLUDED
#define DOMTestSuite_INCLUDED
#ifndef CppUnit_TestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
#endif
class DOMTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // DOMTestSuite_INCLUDED

View File

@@ -0,0 +1,227 @@
//
// DocumentTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/DocumentTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DocumentTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/Document.h"
#include "DOM/Element.h"
#include "DOM/Text.h"
#include "DOM/NodeList.h"
#include "DOM/AutoPtr.h"
#include "DOM/DOMException.h"
using XML::Element;
using XML::Document;
using XML::Text;
using XML::Node;
using XML::NodeList;
using XML::AutoPtr;
using XML::XMLString;
using XML::DOMException;
DocumentTest::DocumentTest(const std::string& name): CppUnit::TestCase(name)
{
}
DocumentTest::~DocumentTest()
{
}
void DocumentTest::testDocumentElement()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
assert (pDoc->documentElement() == 0);
pDoc->appendChild(pRoot);
assert (pDoc->documentElement() == pRoot);
AutoPtr<Text> pText = pDoc->createTextNode(" ");
pDoc->insertBefore(pText, pRoot);
assert (pDoc->documentElement() == pRoot);
}
void DocumentTest::testImport()
{
AutoPtr<Document> pDoc1 = new Document;
AutoPtr<Element> pRoot1 = pDoc1->createElement("root");
AutoPtr<Document> pDoc2 = new Document;
try
{
pDoc2->appendChild(pRoot1);
fail("wrong document - must throw exception");
}
catch (DOMException&)
{
}
AutoPtr<Element> pRoot2 = static_cast<Element*>(pDoc2->importNode(pRoot1, false));
assert (pRoot2->ownerDocument() == pDoc2);
assert (pRoot1->ownerDocument() == pDoc1);
pDoc2->appendChild(pRoot2);
}
void DocumentTest::testImportDeep()
{
AutoPtr<Document> pDoc1 = new Document;
AutoPtr<Element> pRoot1 = pDoc1->createElement("root");
AutoPtr<Element> pElem1 = pDoc1->createElement("elem");
AutoPtr<Text> pText1 = pDoc1->createTextNode("text");
pElem1->appendChild(pText1);
pRoot1->appendChild(pElem1);
pRoot1->setAttribute("a1", "v1");
pRoot1->setAttribute("a2", "v2");
AutoPtr<Document> pDoc2 = new Document;
try
{
pDoc2->appendChild(pRoot1);
fail("wrong document - must throw exception");
}
catch (DOMException&)
{
}
AutoPtr<Element> pRoot2 = static_cast<Element*>(pDoc2->importNode(pRoot1, true));
assert (pRoot2->ownerDocument() == pDoc2);
assert (pRoot2->firstChild()->ownerDocument() == pDoc2);
assert (pRoot2->firstChild()->firstChild()->ownerDocument() == pDoc2);
assert (pRoot1->ownerDocument() == pDoc1);
assert (pRoot1->firstChild()->ownerDocument() == pDoc1);
assert (pRoot1->firstChild()->firstChild()->ownerDocument() == pDoc1);
pDoc2->appendChild(pRoot2);
}
void DocumentTest::testElementsByTagName()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
pDoc->appendChild(pRoot);
AutoPtr<NodeList> pNL1 = pDoc->getElementsByTagName("*");
AutoPtr<NodeList> pNL2 = pDoc->getElementsByTagName("elem");
assert (pNL1->length() == 1);
assert (pNL1->item(0) == pRoot);
assert (pNL2->length() == 0);
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
pRoot->appendChild(pElem1);
assert (pNL1->length() == 2);
assert (pNL2->length() == 1);
assert (pNL1->item(0) == pRoot);
assert (pNL1->item(1) == pElem1);
assert (pNL2->item(0) == pElem1);
AutoPtr<Element> pElem2 = pDoc->createElement("Elem");
pRoot->appendChild(pElem2);
assert (pNL1->length() == 3);
assert (pNL2->length() == 1);
assert (pNL1->item(0) == pRoot);
assert (pNL1->item(1) == pElem1);
assert (pNL1->item(2) == pElem2);
assert (pNL2->item(0) == pElem1);
}
void DocumentTest::testElementsByTagNameNS()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElementNS("urn:ns1", "root");
pDoc->appendChild(pRoot);
AutoPtr<NodeList> pNL1 = pDoc->getElementsByTagNameNS("*", "*");
AutoPtr<NodeList> pNL2 = pDoc->getElementsByTagNameNS("*", "elem");
assert (pNL1->length() == 1);
assert (pNL1->item(0) == pRoot);
assert (pNL2->length() == 0);
AutoPtr<Element> pElem1 = pDoc->createElementNS("urn:ns1", "elem");
pRoot->appendChild(pElem1);
assert (pNL1->length() == 2);
assert (pNL2->length() == 1);
assert (pNL1->item(0) == pRoot);
assert (pNL1->item(1) == pElem1);
assert (pNL2->item(0) == pElem1);
AutoPtr<Element> pElem2 = pDoc->createElementNS("urn:ns1", "Elem");
pRoot->appendChild(pElem2);
assert (pNL1->length() == 3);
assert (pNL2->length() == 1);
assert (pNL1->item(0) == pRoot);
assert (pNL1->item(1) == pElem1);
assert (pNL1->item(2) == pElem2);
assert (pNL2->item(0) == pElem1);
}
void DocumentTest::setUp()
{
}
void DocumentTest::tearDown()
{
}
CppUnit::Test* DocumentTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DocumentTest");
CppUnit_addTest(pSuite, DocumentTest, testDocumentElement);
CppUnit_addTest(pSuite, DocumentTest, testImport);
CppUnit_addTest(pSuite, DocumentTest, testImportDeep);
CppUnit_addTest(pSuite, DocumentTest, testElementsByTagName);
CppUnit_addTest(pSuite, DocumentTest, testElementsByTagNameNS);
return pSuite;
}

View File

@@ -0,0 +1,68 @@
//
// DocumentTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/DocumentTest.h#2 $
//
// Definition of the DocumentTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef DocumentTest_INCLUDED
#define DocumentTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class DocumentTest: public CppUnit::TestCase
{
public:
DocumentTest(const std::string& name);
~DocumentTest();
void testDocumentElement();
void testImport();
void testImportDeep();
void testElementsByTagName();
void testElementsByTagNameNS();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // DocumentTest_INCLUDED

View File

@@ -0,0 +1,130 @@
//
// DocumentTypeTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/DocumentTypeTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DocumentTypeTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/DocumentType.h"
#include "DOM/Document.h"
#include "DOM/Notation.h"
#include "DOM/Entity.h"
#include "DOM/DOMImplementation.h"
#include "DOM/NamedNodeMap.h"
#include "DOM/AutoPtr.h"
using XML::DocumentType;
using XML::Document;
using XML::Entity;
using XML::Notation;
using XML::DOMImplementation;
using XML::NamedNodeMap;
using XML::AutoPtr;
DocumentTypeTest::DocumentTypeTest(const std::string& name): CppUnit::TestCase(name)
{
}
DocumentTypeTest::~DocumentTypeTest()
{
}
void DocumentTypeTest::testDocumentType()
{
AutoPtr<DocumentType> pDoctype = DOMImplementation::instance().createDocumentType("test", "public", "system");
assert (pDoctype->ownerDocument() == 0);
assert (pDoctype->name() == "test");
assert (pDoctype->publicId() == "public");
assert (pDoctype->systemId() == "system");
AutoPtr<Document> pDoc = new Document(pDoctype);
assert (pDoc->doctype() == pDoctype);
assert (pDoctype->ownerDocument() == pDoc);
AutoPtr<NamedNodeMap> pEntities = pDoctype->entities();
AutoPtr<NamedNodeMap> pNotations = pDoctype->notations();
assert (pEntities->length() == 0);
assert (pNotations->length() == 0);
AutoPtr<Entity> pEntity1 = pDoc->createEntity("entity1", "public1", "system1", "");
pDoctype->appendChild(pEntity1);
assert (pEntities->length() == 1);
assert (pNotations->length() == 0);
assert (pEntities->item(0) == pEntity1);
assert (pEntities->getNamedItem("entity1") == pEntity1);
AutoPtr<Entity> pEntity2 = pDoc->createEntity("entity2", "public2", "system2", "");
pDoctype->appendChild(pEntity2);
assert (pEntities->length() == 2);
assert (pNotations->length() == 0);
assert (pEntities->item(0) == pEntity1);
assert (pEntities->item(1) == pEntity2);
assert (pEntities->getNamedItem("entity1") == pEntity1);
assert (pEntities->getNamedItem("entity2") == pEntity2);
AutoPtr<Notation> pNotation = pDoc->createNotation("notation", "public", "system");
pDoctype->appendChild(pNotation);
assert (pEntities->length() == 2);
assert (pNotations->length() == 1);
assert (pEntities->item(0) == pEntity1);
assert (pEntities->item(1) == pEntity2);
assert (pNotations->item(0) == pNotation);
assert (pEntities->getNamedItem("entity1") == pEntity1);
assert (pEntities->getNamedItem("entity2") == pEntity2);
assert (pNotations->getNamedItem("notation") == pNotation);
}
void DocumentTypeTest::setUp()
{
}
void DocumentTypeTest::tearDown()
{
}
CppUnit::Test* DocumentTypeTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DocumentTypeTest");
CppUnit_addTest(pSuite, DocumentTypeTest, testDocumentType);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// DocumentTypeTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/DocumentTypeTest.h#2 $
//
// Definition of the DocumentTypeTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef DocumentTypeTest_INCLUDED
#define DocumentTypeTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class DocumentTypeTest: public CppUnit::TestCase
{
public:
DocumentTypeTest(const std::string& name);
~DocumentTypeTest();
void testDocumentType();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // DocumentTypeTest_INCLUDED

View File

@@ -0,0 +1,39 @@
//
// Driver.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/Driver.cpp#2 $
//
// Console-based test driver for Poco XML.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "CppUnit/TestRunner.h"
#include "XMLTestSuite.h"
CppUnitMain(XMLTestSuite)

View File

@@ -0,0 +1,658 @@
//
// ElementTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/ElementTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "ElementTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/Document.h"
#include "DOM/Element.h"
#include "DOM/Attr.h"
#include "DOM/Text.h"
#include "DOM/NamedNodeMap.h"
#include "DOM/NodeList.h"
#include "DOM/AutoPtr.h"
using XML::Element;
using XML::Document;
using XML::Attr;
using XML::Text;
using XML::Node;
using XML::NamedNodeMap;
using XML::NodeList;
using XML::AutoPtr;
using XML::XMLString;
ElementTest::ElementTest(const std::string& name): CppUnit::TestCase(name)
{
}
ElementTest::~ElementTest()
{
}
void ElementTest::testAttributes()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pElem = pDoc->createElement("elem");
assert (!pElem->hasAttributes());
pElem->setAttribute("a1", "v1");
assert (pElem->hasAttributes());
assert (pElem->hasAttribute("a1"));
assert (pElem->getAttribute("a1") == "v1");
Attr* pAttr1 = pElem->getAttributeNode("a1");
assert (pAttr1 != 0);
assert (pAttr1->name() == "a1");
assert (pAttr1->nodeName() == "a1");
assert (pAttr1->value() == "v1");
assert (pAttr1->nodeValue() == "v1");
assert (pAttr1->ownerElement() == pElem);
assert (pAttr1->ownerDocument() == pDoc);
assert (pAttr1->innerText() == "v1");
assert (pAttr1->previousSibling() == 0);
assert (pAttr1->nextSibling() == 0);
pAttr1->setValue("V1");
assert (pElem->getAttribute("a1") == "V1");
pElem->setAttribute("a2", "v2");
assert (pElem->hasAttribute("a1"));
assert (pElem->getAttribute("a1") == "V1");
assert (pElem->hasAttribute("a2"));
assert (pElem->getAttribute("a2") == "v2");
Attr* pAttr2 = pElem->getAttributeNode("a2");
assert (pAttr2 != 0);
assert (pAttr2->name() == "a2");
assert (pAttr2->value() == "v2");
assert (pAttr2->ownerElement() == pElem);
assert (pAttr1->previousSibling() == 0);
assert (pAttr1->nextSibling() == pAttr2);
assert (pAttr2->previousSibling() == pAttr1);
assert (pAttr2->nextSibling() == 0);
Attr* pAttr3 = pElem->getAttributeNode("a3");
assert (pAttr3 == 0);
pAttr3 = pDoc->createAttribute("a3");
pAttr3->setValue("v3");
pElem->setAttributeNode(pAttr3);
pAttr3->release();
assert (pElem->hasAttribute("a1"));
assert (pElem->getAttribute("a1") == "V1");
assert (pElem->hasAttribute("a2"));
assert (pElem->getAttribute("a2") == "v2");
assert (pElem->hasAttribute("a3"));
assert (pElem->getAttribute("a3") == "v3");
assert (pAttr1->previousSibling() == 0);
assert (pAttr1->nextSibling() == pAttr2);
assert (pAttr2->previousSibling() == pAttr1);
assert (pAttr2->nextSibling() == pAttr3);
assert (pAttr3->previousSibling() == pAttr2);
assert (pAttr3->nextSibling() == 0);
pAttr2 = pDoc->createAttribute("a2");
pAttr2->setValue("V2");
pElem->setAttributeNode(pAttr2);
pAttr2->release();
assert (pElem->hasAttribute("a1"));
assert (pElem->getAttribute("a1") == "V1");
assert (pElem->hasAttribute("a2"));
assert (pElem->getAttribute("a2") == "V2");
assert (pElem->hasAttribute("a3"));
assert (pElem->getAttribute("a3") == "v3");
pAttr1 = pDoc->createAttribute("a1");
pAttr1->setValue("v1");
pElem->setAttributeNode(pAttr1);
pAttr1->release();
assert (pElem->hasAttribute("a1"));
assert (pElem->getAttribute("a1") == "v1");
assert (pElem->hasAttribute("a2"));
assert (pElem->getAttribute("a2") == "V2");
assert (pElem->hasAttribute("a3"));
assert (pElem->getAttribute("a3") == "v3");
pAttr3 = pDoc->createAttribute("a3");
pAttr3->setValue("V3");
pElem->setAttributeNode(pAttr3);
pAttr3->release();
assert (pElem->hasAttribute("a1"));
assert (pElem->getAttribute("a1") == "v1");
assert (pElem->hasAttribute("a2"));
assert (pElem->getAttribute("a2") == "V2");
assert (pElem->hasAttribute("a3"));
assert (pElem->getAttribute("a3") == "V3");
pElem->removeAttributeNode(pAttr3);
assert (!pElem->hasAttribute("a3"));
pElem->removeAttribute("a1");
assert (!pElem->hasAttribute("a1"));
pElem->removeAttribute("a2");
assert (!pElem->hasAttribute("a2"));
assert (!pElem->hasAttributes());
}
void ElementTest::testAttributesNS()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pElem = pDoc->createElementNS("urn:ns1", "p:elem");
assert (pElem->namespaceURI() == "urn:ns1");
assert (pElem->prefix() == "p");
assert (pElem->tagName() == "p:elem");
assert (pElem->localName() == "elem");
assert (!pElem->hasAttributes());
pElem->setAttributeNS("urn:ns1", "a1", "v1");
assert (pElem->hasAttributes());
assert (pElem->hasAttributeNS("urn:ns1", "a1"));
assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1");
Attr* pAttr1 = pElem->getAttributeNodeNS("urn:ns1", "a1");
assert (pAttr1 != 0);
assert (pAttr1->name() == "a1");
assert (pAttr1->namespaceURI() == "urn:ns1");
assert (pAttr1->prefix().empty());
assert (pAttr1->localName() == "a1");
assert (pAttr1->nodeName() == "a1");
assert (pAttr1->value() == "v1");
assert (pAttr1->nodeValue() == "v1");
assert (pAttr1->ownerElement() == pElem);
pAttr1->setValue("V1");
assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1");
pElem->setAttributeNS("urn:ns1", "a2", "v2");
assert (pElem->hasAttributeNS("urn:ns1", "a1"));
assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1");
assert (pElem->hasAttributeNS("urn:ns1", "a2"));
assert (pElem->getAttributeNS("urn:ns1", "a2") == "v2");
Attr* pAttr2 = pElem->getAttributeNodeNS("urn:ns1", "a2");
assert (pAttr2 != 0);
assert (pAttr2->name() == "a2");
assert (pAttr2->namespaceURI() == "urn:ns1");
assert (pAttr2->prefix().empty());
assert (pAttr2->localName() == "a2");
assert (pAttr2->value() == "v2");
assert (pAttr2->ownerElement() == pElem);
Attr* pAttr3 = pElem->getAttributeNodeNS("urn:ns2", "p:a3");
assert (pAttr3 == 0);
pAttr3 = pDoc->createAttributeNS("urn:ns2", "p:a3");
pAttr3->setValue("v3");
pElem->setAttributeNodeNS(pAttr3);
pAttr3->release();
assert (pElem->hasAttributeNS("urn:ns1", "a1"));
assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1");
assert (pElem->hasAttributeNS("urn:ns1", "a2"));
assert (pElem->getAttributeNS("urn:ns1", "a2") == "v2");
assert (pElem->hasAttributeNS("urn:ns2", "a3"));
assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3");
pAttr2 = pDoc->createAttributeNS("urn:ns1", "a2");
pAttr2->setValue("V2");
pElem->setAttributeNodeNS(pAttr2);
pAttr2->release();
assert (pElem->hasAttributeNS("urn:ns1", "a1"));
assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1");
assert (pElem->hasAttributeNS("urn:ns1", "a2"));
assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2");
assert (pElem->hasAttributeNS("urn:ns2", "a3"));
assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3");
pAttr1 = pDoc->createAttributeNS("urn:ns1", "a1");
pAttr1->setValue("v1");
pElem->setAttributeNodeNS(pAttr1);
pAttr1->release();
assert (pElem->hasAttributeNS("urn:ns1", "a1"));
assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1");
assert (pElem->hasAttributeNS("urn:ns1", "a2"));
assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2");
assert (pElem->hasAttributeNS("urn:ns2", "a3"));
assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3");
pAttr3 = pDoc->createAttributeNS("urn:ns2", "q:a3");
pAttr3->setValue("V3");
pElem->setAttributeNodeNS(pAttr3);
pAttr3->release();
assert (pElem->hasAttributeNS("urn:ns1", "a1"));
assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1");
assert (pElem->hasAttributeNS("urn:ns1", "a2"));
assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2");
assert (pElem->hasAttributeNS("urn:ns2", "a3"));
assert (pElem->getAttributeNS("urn:ns2", "a3") == "V3");
pElem->removeAttributeNode(pAttr3);
assert (!pElem->hasAttributeNS("urn:ns2", "a3"));
pElem->removeAttributeNS("urn:ns1", "a1");
assert (!pElem->hasAttributeNS("urn:ns1", "a1"));
pElem->removeAttributeNS("urn:ns1", "a2");
assert (!pElem->hasAttributeNS("urn:ns1", "a2"));
assert (!pElem->hasAttributes());
}
void ElementTest::testAttrMap()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pElem = pDoc->createElement("elem");
AutoPtr<NamedNodeMap> pNNM = pElem->attributes();
assert (pNNM->length() == 0);
pElem->setAttribute("a1", "v1");
assert (pNNM->length() == 1);
assert (pNNM->item(0)->nodeName() == "a1");
assert (pNNM->getNamedItem("a1")->nodeName() == "a1");
pElem->setAttribute("a2", "v2");
assert (pNNM->length() == 2);
assert (pNNM->item(0)->nodeName() == "a1");
assert (pNNM->getNamedItem("a1")->nodeName() == "a1");
assert (pNNM->item(1)->nodeName() == "a2");
assert (pNNM->getNamedItem("a2")->nodeName() == "a2");
Attr* pAttr = pDoc->createAttribute("a3");
pNNM->setNamedItem(pAttr);
pAttr->release();
assert (pNNM->length() == 3);
assert (pNNM->item(0)->nodeName() == "a1");
assert (pNNM->getNamedItem("a1")->nodeName() == "a1");
assert (pNNM->item(1)->nodeName() == "a2");
assert (pNNM->getNamedItem("a2")->nodeName() == "a2");
assert (pNNM->item(2)->nodeName() == "a3");
assert (pNNM->getNamedItem("a3")->nodeName() == "a3");
pNNM->removeNamedItem("a2");
assert (pNNM->length() == 2);
assert (!pElem->hasAttribute("a2"));
pNNM->removeNamedItem("a3");
assert (pNNM->length() == 1);
assert (!pElem->hasAttribute("a3"));
pElem->removeAttribute("a1");
assert (pNNM->length() == 0);
}
void ElementTest::testAttrMapNS()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pElem = pDoc->createElementNS("urn:ns1", "elem");
AutoPtr<NamedNodeMap> pNNM = pElem->attributes();
assert (pNNM->length() == 0);
pElem->setAttributeNS("urn:ns1", "a1", "v1");
assert (pNNM->length() == 1);
assert (pNNM->item(0)->nodeName() == "a1");
assert (pNNM->getNamedItemNS("urn:ns1", "a1")->nodeName() == "a1");
pElem->setAttributeNS("urn:ns1", "a2", "v2");
assert (pNNM->length() == 2);
assert (pNNM->item(0)->nodeName() == "a1");
assert (pNNM->getNamedItem("a1")->nodeName() == "a1");
assert (pNNM->item(1)->nodeName() == "a2");
assert (pNNM->getNamedItem("a2")->nodeName() == "a2");
Attr* pAttr = pDoc->createAttributeNS("urn:ns2", "a3");
pNNM->setNamedItem(pAttr);
pAttr->release();
assert (pNNM->length() == 3);
assert (pNNM->item(0)->nodeName() == "a1");
assert (pNNM->getNamedItemNS("urn:ns1", "a1")->nodeName() == "a1");
assert (pNNM->item(1)->nodeName() == "a2");
assert (pNNM->getNamedItemNS("urn:ns1", "a2")->nodeName() == "a2");
assert (pNNM->item(2)->nodeName() == "a3");
assert (pNNM->getNamedItemNS("urn:ns2", "a3")->nodeName() == "a3");
pNNM->removeNamedItemNS("urn:ns1", "a2");
assert (pNNM->length() == 2);
assert (!pElem->hasAttributeNS("urn:ns1", "a2"));
pNNM->removeNamedItemNS("urn:ns2", "a3");
assert (pNNM->length() == 1);
assert (!pElem->hasAttributeNS("urn:ns2", "a3"));
pElem->removeAttributeNS("urn:ns1", "a1");
assert (pNNM->length() == 0);
}
void ElementTest::testElementsByTagName()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<NodeList> pNL1 = pRoot->getElementsByTagName("*");
AutoPtr<NodeList> pNL2 = pRoot->getElementsByTagName("elem");
assert (pNL1->length() == 0);
assert (pNL2->length() == 0);
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
pRoot->appendChild(pElem1);
assert (pNL1->length() == 1);
assert (pNL2->length() == 1);
assert (pNL1->item(0) == pElem1);
assert (pNL2->item(0) == pElem1);
AutoPtr<Element> pElem2 = pDoc->createElement("Elem");
pRoot->appendChild(pElem2);
assert (pNL1->length() == 2);
assert (pNL2->length() == 1);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem2);
assert (pNL2->item(0) == pElem1);
AutoPtr<Element> pElem3 = pDoc->createElement("elem");
pRoot->appendChild(pElem3);
assert (pNL1->length() == 3);
assert (pNL2->length() == 2);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem2);
assert (pNL1->item(2) == pElem3);
assert (pNL2->item(0) == pElem1);
assert (pNL2->item(1) == pElem3);
AutoPtr<Element> pElem11 = pDoc->createElement("elem");
pElem1->appendChild(pElem11);
assert (pNL1->length() == 4);
assert (pNL2->length() == 3);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem11);
assert (pNL1->item(2) == pElem2);
assert (pNL1->item(3) == pElem3);
assert (pNL2->item(0) == pElem1);
assert (pNL2->item(1) == pElem11);
assert (pNL2->item(2) == pElem3);
AutoPtr<Element> pElem12 = pDoc->createElement("Elem");
pElem1->appendChild(pElem12);
assert (pNL1->length() == 5);
assert (pNL2->length() == 3);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem11);
assert (pNL1->item(2) == pElem12);
assert (pNL1->item(3) == pElem2);
assert (pNL1->item(4) == pElem3);
assert (pNL2->item(0) == pElem1);
assert (pNL2->item(1) == pElem11);
assert (pNL2->item(2) == pElem3);
AutoPtr<Element> pElem21 = pDoc->createElement("elem");
pElem2->appendChild(pElem21);
assert (pNL1->length() == 6);
assert (pNL2->length() == 4);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem11);
assert (pNL1->item(2) == pElem12);
assert (pNL1->item(3) == pElem2);
assert (pNL1->item(4) == pElem21);
assert (pNL1->item(5) == pElem3);
assert (pNL2->item(0) == pElem1);
assert (pNL2->item(1) == pElem11);
assert (pNL2->item(2) == pElem21);
assert (pNL2->item(3) == pElem3);
}
void ElementTest::testElementsByTagNameNS()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElementNS("urn:ns1", "root");
AutoPtr<NodeList> pNL1 = pRoot->getElementsByTagNameNS("*", "*");
AutoPtr<NodeList> pNL2 = pRoot->getElementsByTagNameNS("*", "elem");
AutoPtr<NodeList> pNL3 = pRoot->getElementsByTagNameNS("urn:ns1", "elem");
assert (pNL1->length() == 0);
assert (pNL2->length() == 0);
AutoPtr<Element> pElem1 = pDoc->createElementNS("urn:ns1", "elem");
pRoot->appendChild(pElem1);
assert (pNL1->length() == 1);
assert (pNL2->length() == 1);
assert (pNL3->length() == 1);
assert (pNL1->item(0) == pElem1);
assert (pNL2->item(0) == pElem1);
assert (pNL3->item(0) == pElem1);
AutoPtr<Element> pElem2 = pDoc->createElementNS("urn:ns1", "Elem");
pRoot->appendChild(pElem2);
assert (pNL1->length() == 2);
assert (pNL2->length() == 1);
assert (pNL3->length() == 1);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem2);
assert (pNL2->item(0) == pElem1);
assert (pNL3->item(0) == pElem1);
AutoPtr<Element> pElem3 = pDoc->createElementNS("urn:ns2", "elem");
pRoot->appendChild(pElem3);
assert (pNL1->length() == 3);
assert (pNL2->length() == 2);
assert (pNL3->length() == 1);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem2);
assert (pNL1->item(2) == pElem3);
assert (pNL2->item(0) == pElem1);
assert (pNL2->item(1) == pElem3);
assert (pNL3->item(0) == pElem1);
AutoPtr<Element> pElem11 = pDoc->createElementNS("urn:ns1", "elem");
pElem1->appendChild(pElem11);
assert (pNL1->length() == 4);
assert (pNL2->length() == 3);
assert (pNL3->length() == 2);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem11);
assert (pNL1->item(2) == pElem2);
assert (pNL1->item(3) == pElem3);
assert (pNL2->item(0) == pElem1);
assert (pNL2->item(1) == pElem11);
assert (pNL2->item(2) == pElem3);
assert (pNL3->item(0) == pElem1);
assert (pNL3->item(1) == pElem11);
AutoPtr<Element> pElem12 = pDoc->createElementNS("urn:ns1", "Elem");
pElem1->appendChild(pElem12);
assert (pNL1->length() == 5);
assert (pNL2->length() == 3);
assert (pNL3->length() == 2);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem11);
assert (pNL1->item(2) == pElem12);
assert (pNL1->item(3) == pElem2);
assert (pNL1->item(4) == pElem3);
assert (pNL2->item(0) == pElem1);
assert (pNL2->item(1) == pElem11);
assert (pNL2->item(2) == pElem3);
assert (pNL3->item(0) == pElem1);
assert (pNL3->item(1) == pElem11);
AutoPtr<Element> pElem21 = pDoc->createElementNS("urn:ns1", "elem");
pElem2->appendChild(pElem21);
assert (pNL1->length() == 6);
assert (pNL2->length() == 4);
assert (pNL3->length() == 3);
assert (pNL1->item(0) == pElem1);
assert (pNL1->item(1) == pElem11);
assert (pNL1->item(2) == pElem12);
assert (pNL1->item(3) == pElem2);
assert (pNL1->item(4) == pElem21);
assert (pNL1->item(5) == pElem3);
assert (pNL2->item(0) == pElem1);
assert (pNL2->item(1) == pElem11);
assert (pNL2->item(2) == pElem21);
assert (pNL2->item(3) == pElem3);
assert (pNL3->item(0) == pElem1);
assert (pNL3->item(1) == pElem11);
assert (pNL3->item(2) == pElem21);
}
void ElementTest::testInnerText()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Element> pElem1 = pDoc->createElement("elem1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
AutoPtr<Text> pText3 = pDoc->createTextNode("text3");
pElem1->appendChild(pText2);
pRoot->appendChild(pText1);
pRoot->appendChild(pElem1);
pRoot->appendChild(pText3);
XMLString innerText = pRoot->innerText();
assert (innerText == "text1text2text3");
}
void ElementTest::testChildElement()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem1");
AutoPtr<Element> pElem2 = pDoc->createElement("elem2");
AutoPtr<Element> pElem3 = pDoc->createElement("elem3");
AutoPtr<Element> pElem4 = pDoc->createElement("elem3");
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pRoot->appendChild(pElem3);
pRoot->appendChild(pElem4);
assert (pRoot->getChildElement("elem1") == pElem1);
assert (pRoot->getChildElement("elem2") == pElem2);
assert (pRoot->getChildElement("elem3") == pElem3);
assert (pRoot->getChildElement("elem4") == 0);
assert (pElem1->getChildElement("elem11") == 0);
}
void ElementTest::testChildElementNS()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElementNS("urn:ns", "root");
AutoPtr<Element> pElem1 = pDoc->createElementNS("urn:ns", "elem1");
AutoPtr<Element> pElem2 = pDoc->createElementNS("urn:ns", "elem2");
AutoPtr<Element> pElem3 = pDoc->createElementNS("urn:ns", "elem3");
AutoPtr<Element> pElem4 = pDoc->createElementNS("urn:ns", "elem3");
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pRoot->appendChild(pElem3);
pRoot->appendChild(pElem4);
assert (pRoot->getChildElementNS("urn:ns", "elem1") == pElem1);
assert (pRoot->getChildElementNS("urn:ns", "elem2") == pElem2);
assert (pRoot->getChildElementNS("urn:ns", "elem3") == pElem3);
assert (pRoot->getChildElementNS("urn:ns", "elem4") == 0);
assert (pRoot->getChildElementNS("urn:NS", "elem1") == 0);
assert (pElem1->getChildElementNS("urn:ns", "elem11") == 0);
}
void ElementTest::setUp()
{
}
void ElementTest::tearDown()
{
}
CppUnit::Test* ElementTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ElementTest");
CppUnit_addTest(pSuite, ElementTest, testAttributes);
CppUnit_addTest(pSuite, ElementTest, testAttributesNS);
CppUnit_addTest(pSuite, ElementTest, testAttrMap);
CppUnit_addTest(pSuite, ElementTest, testAttrMapNS);
CppUnit_addTest(pSuite, ElementTest, testElementsByTagName);
CppUnit_addTest(pSuite, ElementTest, testElementsByTagNameNS);
CppUnit_addTest(pSuite, ElementTest, testInnerText);
CppUnit_addTest(pSuite, ElementTest, testChildElement);
CppUnit_addTest(pSuite, ElementTest, testChildElementNS);
return pSuite;
}

View File

@@ -0,0 +1,72 @@
//
// ElementTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/ElementTest.h#2 $
//
// Definition of the ElementTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ElementTest_INCLUDED
#define ElementTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class ElementTest: public CppUnit::TestCase
{
public:
ElementTest(const std::string& name);
~ElementTest();
void testAttributes();
void testAttributesNS();
void testAttrMap();
void testAttrMapNS();
void testElementsByTagName();
void testElementsByTagNameNS();
void testInnerText();
void testChildElement();
void testChildElementNS();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // ElementTest_INCLUDED

View File

@@ -0,0 +1,593 @@
//
// EventTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/EventTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "EventTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/Event.h"
#include "DOM/MutationEvent.h"
#include "DOM/EventListener.h"
#include "DOM/Document.h"
#include "DOM/Element.h"
#include "DOM/Attr.h"
#include "DOM/Text.h"
#include "DOM/AutoPtr.h"
using XML::Event;
using XML::MutationEvent;
using XML::EventListener;
using XML::Element;
using XML::Document;
using XML::Attr;
using XML::Text;
using XML::Node;
using XML::AutoPtr;
using XML::XMLString;
class TestEventListener: public EventListener
{
public:
TestEventListener(const XMLString& name, bool cancel = false, bool readd = false, bool capture = false):
_name(name),
_cancel(cancel),
_readd(readd),
_capture(capture)
{
}
void handleEvent(Event* evt)
{
XMLString type = evt->type();
XMLString phase;
switch (evt->eventPhase())
{
case Event::CAPTURING_PHASE:
phase = "CAPTURING_PHASE"; break;
case Event::AT_TARGET:
phase = "AT_TARGET"; break;
case Event::BUBBLING_PHASE:
phase = "BUBBLING_PHASE"; break;
}
Node* pTarget = static_cast<Node*>(evt->target());
Node* pCurrentTarget = static_cast<Node*>(evt->currentTarget());
_log.append(_name);
_log.append(":");
_log.append(type);
_log.append(":");
_log.append(phase);
_log.append(":");
_log.append(pTarget->nodeName());
_log.append(":");
_log.append(pCurrentTarget->nodeName());
_log.append(":");
_log.append(evt->bubbles() ? "B" : "-");
_log.append(":");
_log.append(evt->cancelable() ? "C" : "-");
MutationEvent* pME = dynamic_cast<MutationEvent*>(evt);
if (pME)
{
XMLString attrChange;
switch (pME->attrChange())
{
case MutationEvent::MODIFICATION:
attrChange = "MODIFICATION"; break;
case MutationEvent::ADDITION:
attrChange = "ADDITION"; break;
case MutationEvent::REMOVAL:
attrChange = "REMOVAL"; break;
}
XMLString relatedNode;
Node* pRelatedNode = pME->relatedNode();
if (pRelatedNode) relatedNode = pRelatedNode->nodeName();
_log.append(":");
_log.append(attrChange);
_log.append(":");
_log.append(relatedNode);
_log.append(":");
_log.append(pME->attrName());
_log.append(":");
_log.append(pME->prevValue());
_log.append(":");
_log.append(pME->newValue());
}
_log.append("\n");
if (_cancel) evt->stopPropagation();
if (_readd)
pCurrentTarget->addEventListener(type, this, _capture);
}
static const XMLString& log()
{
return _log;
}
static void reset()
{
_log.clear();
}
private:
XMLString _name;
bool _cancel;
bool _readd;
bool _capture;
static XMLString _log;
};
XMLString TestEventListener::_log;
EventTest::EventTest(const std::string& name): CppUnit::TestCase(name)
{
}
EventTest::~EventTest()
{
}
void EventTest::testInsert()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
TestEventListener docListener("doc");
TestEventListener docCapListener("docCap");
TestEventListener rootListener("root");
TestEventListener rootCapListener("rootCap");
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true);
pDoc->appendChild(pRoot);
const XMLString& log = TestEventListener::log();
assert (log ==
"docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
"rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
"root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
"doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
"docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
"root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
"docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
"doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
);
TestEventListener::reset();
AutoPtr<Text> pText = pDoc->createTextNode("text");
pRoot->appendChild(pText);
assert (log ==
"docCap:DOMNodeInserted:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
"rootCap:DOMNodeInserted:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
"root:DOMNodeInserted:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
"doc:DOMNodeInserted:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
"docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
"docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n"
"rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
"root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
"doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n"
);
}
void EventTest::testInsertSubtree()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
TestEventListener docListener("doc");
TestEventListener docCapListener("docCap");
TestEventListener rootListener("root");
TestEventListener rootCapListener("rootCap");
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true);
AutoPtr<Text> pText = pDoc->createTextNode("text");
pRoot->appendChild(pText);
TestEventListener::reset();
pDoc->appendChild(pRoot);
const XMLString& log = TestEventListener::log();
assert (log ==
"docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
"rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
"root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
"doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
"docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
"root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
"docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
"docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
"doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
);
}
void EventTest::testRemove()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
TestEventListener docListener("doc");
TestEventListener docCapListener("docCap");
TestEventListener rootListener("root");
TestEventListener rootCapListener("rootCap");
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docCapListener, true);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootCapListener, true);
pDoc->appendChild(pRoot);
AutoPtr<Text> pText = pDoc->createTextNode("text");
pRoot->appendChild(pText);
TestEventListener::reset();
pRoot->removeChild(pText);
const XMLString& log = TestEventListener::log();
assert (log ==
"docCap:DOMNodeRemoved:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
"rootCap:DOMNodeRemoved:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
"root:DOMNodeRemoved:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
"doc:DOMNodeRemoved:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
"docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
"docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n"
"rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
"root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
"doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n"
);
}
void EventTest::testRemoveSubtree()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
TestEventListener docListener("doc");
TestEventListener docCapListener("docCap");
TestEventListener rootListener("root");
TestEventListener rootCapListener("rootCap");
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docCapListener, true);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootCapListener, true);
pDoc->appendChild(pRoot);
AutoPtr<Text> pText = pDoc->createTextNode("text");
pRoot->appendChild(pText);
TestEventListener::reset();
pDoc->removeChild(pRoot);
const XMLString& log = TestEventListener::log();
assert (log ==
"docCap:DOMNodeRemoved:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
"rootCap:DOMNodeRemoved:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
"root:DOMNodeRemoved:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
"doc:DOMNodeRemoved:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
"docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeRemovedFromDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
"root:DOMNodeRemovedFromDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
"docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
"docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
"doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
);
}
void EventTest::testCharacterData()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Text> pText = pDoc->createTextNode("text");
pRoot->appendChild(pText);
pDoc->appendChild(pRoot);
TestEventListener docListener("doc");
TestEventListener docCapListener("docCap");
TestEventListener rootListener("root");
TestEventListener rootCapListener("rootCap");
TestEventListener textListener("text");
TestEventListener textCapListener("textCap");
pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docCapListener, true);
pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootCapListener, true);
pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textListener, false);
pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textCapListener, true);
TestEventListener::reset();
pText->setData("modified");
const XMLString& log = TestEventListener::log();
assert (log ==
"docCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n"
"rootCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:::text:modified\n"
"textCap:DOMCharacterDataModified:AT_TARGET:#text:#text:B:-:MODIFICATION:::text:modified\n"
"text:DOMCharacterDataModified:AT_TARGET:#text:#text:B:-:MODIFICATION:::text:modified\n"
"root:DOMCharacterDataModified:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:::text:modified\n"
"doc:DOMCharacterDataModified:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n"
);
}
void EventTest::testCancel()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Text> pText = pDoc->createTextNode("text");
pRoot->appendChild(pText);
pDoc->appendChild(pRoot);
TestEventListener docListener("doc");
TestEventListener docCapListener("docCap", true);
TestEventListener rootListener("root");
TestEventListener rootCapListener("rootCap");
TestEventListener textListener("text");
TestEventListener textCapListener("textCap");
pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docCapListener, true);
pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootCapListener, true);
pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textListener, false);
pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textCapListener, true);
TestEventListener::reset();
pText->setData("modified");
const XMLString& log = TestEventListener::log();
assert (log == "docCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n");
}
void EventTest::testAttributes()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
TestEventListener rootListener("root");
pRoot->addEventListener(MutationEvent::DOMAttrModified, &rootListener, false);
pRoot->setAttribute("a1", "v1");
const XMLString& log = TestEventListener::log();
assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:ADDITION:a1:a1::v1\n");
TestEventListener::reset();
pRoot->setAttribute("a1", "V1");
assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:MODIFICATION:a1:a1:v1:V1\n");
TestEventListener::reset();
pRoot->setAttribute("a2", "v2");
assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:ADDITION:a2:a2::v2\n");
TestEventListener::reset();
pRoot->removeAttribute("a1");
assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:REMOVAL:a1:a1:V1:\n");
}
void EventTest::testAddRemoveInEvent()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
TestEventListener docListener("doc", false, true, false);
TestEventListener docCapListener("docCap", false, true, true);
TestEventListener rootListener("root", false, true, false);
TestEventListener rootCapListener("rootCap", false, true, true);
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false);
pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true);
pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false);
pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true);
pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true);
pDoc->appendChild(pRoot);
const XMLString& log = TestEventListener::log();
assert (log ==
"docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
"rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
"root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n"
"doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n"
"docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
"root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n"
"docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
"doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n"
);
TestEventListener::reset();
AutoPtr<Text> pText = pDoc->createTextNode("text");
pRoot->appendChild(pText);
assert (log ==
"docCap:DOMNodeInserted:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
"rootCap:DOMNodeInserted:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
"root:DOMNodeInserted:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n"
"doc:DOMNodeInserted:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n"
"docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n"
"rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n"
"docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n"
"rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
"root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n"
"doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n"
);
}
void EventTest::testSuspended()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
pDoc->suspendEvents();
TestEventListener rootListener("root");
pRoot->addEventListener(MutationEvent::DOMAttrModified, &rootListener, false);
pRoot->setAttribute("a1", "v1");
const XMLString& log = TestEventListener::log();
assert (log.empty());
TestEventListener::reset();
pRoot->setAttribute("a1", "V1");
assert (log.empty());
TestEventListener::reset();
pRoot->setAttribute("a2", "v2");
assert (log.empty());
TestEventListener::reset();
pRoot->removeAttribute("a1");
assert (log.empty());
}
void EventTest::setUp()
{
TestEventListener::reset();
}
void EventTest::tearDown()
{
}
CppUnit::Test* EventTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("EventTest");
CppUnit_addTest(pSuite, EventTest, testInsert);
CppUnit_addTest(pSuite, EventTest, testInsertSubtree);
CppUnit_addTest(pSuite, EventTest, testRemove);
CppUnit_addTest(pSuite, EventTest, testRemoveSubtree);
CppUnit_addTest(pSuite, EventTest, testCharacterData);
CppUnit_addTest(pSuite, EventTest, testCancel);
CppUnit_addTest(pSuite, EventTest, testAttributes);
CppUnit_addTest(pSuite, EventTest, testAddRemoveInEvent);
CppUnit_addTest(pSuite, EventTest, testSuspended);
return pSuite;
}

View File

@@ -0,0 +1,72 @@
//
// EventTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/EventTest.h#2 $
//
// Definition of the EventTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef EventTest_INCLUDED
#define EventTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class EventTest: public CppUnit::TestCase
{
public:
EventTest(const std::string& name);
~EventTest();
void testInsert();
void testInsertSubtree();
void testRemove();
void testRemoveSubtree();
void testCharacterData();
void testCancel();
void testAttributes();
void testAddRemoveInEvent();
void testSuspended();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // EventTest_INCLUDED

View File

@@ -0,0 +1,94 @@
//
// NamePoolTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/NamePoolTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "NamePoolTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "XML/NamePool.h"
#include "XML/Name.h"
#include "DOM/AutoPtr.h"
using XML::NamePool;
using XML::Name;
using XML::AutoPtr;
NamePoolTest::NamePoolTest(const std::string& name): CppUnit::TestCase(name)
{
}
NamePoolTest::~NamePoolTest()
{
}
void NamePoolTest::testNamePool()
{
AutoPtr<NamePool> pool = new NamePool;
const Name* pName = 0;
Name name("pre:local", "http://www.appinf.com");
pName = &pool->insert(name);
const Name* pName2 = &pool->insert("pre:local", "http://www.appinf.com", "local");
assert (pName == pName2);
pName2 = &pool->insert("pre:local2", "http://www.appinf.com", "local2");
assert (pName2 != pName);
pName2 = &pool->insert(name);
assert (pName2 == pName);
pName2 = &pool->insert(*pName);
assert (pName2 == pName);
}
void NamePoolTest::setUp()
{
}
void NamePoolTest::tearDown()
{
}
CppUnit::Test* NamePoolTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NamePoolTest");
CppUnit_addTest(pSuite, NamePoolTest, testNamePool);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// NamePoolTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/NamePoolTest.h#2 $
//
// Definition of the NamePoolTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef NamePoolTest_INCLUDED
#define NamePoolTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class NamePoolTest: public CppUnit::TestCase
{
public:
NamePoolTest(const std::string& name);
~NamePoolTest();
void testNamePool();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // NamePoolTest_INCLUDED

View File

@@ -0,0 +1,193 @@
//
// NameTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/NameTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "NameTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "XML/Name.h"
using XML::Name;
NameTest::NameTest(const std::string& name): CppUnit::TestCase(name)
{
}
NameTest::~NameTest()
{
}
void NameTest::testSplit()
{
std::string qname = "name";
std::string prefix;
std::string local;
Name::split(qname, prefix, local);
assert (prefix.empty());
assert (local == "name");
qname = "p:l";
Name::split(qname, prefix, local);
assert (prefix == "p");
assert (local == "l");
qname = "pre:local";
Name::split(qname, prefix, local);
assert (prefix == "pre");
assert (local == "local");
}
void NameTest::testLocalName()
{
std::string qname = "name";
std::string local = Name::localName(qname);
assert (local == "name");
qname = "p:l";
local = Name::localName(qname);
assert (local == "l");
qname = "pre:local";
local = Name::localName(qname);
assert (local == "local");
}
void NameTest::testPrefix()
{
std::string qname = "name";
std::string prefix = Name::prefix(qname);
assert (prefix.empty());
qname = "p:l";
prefix = Name::prefix(qname);
assert (prefix == "p");
qname = "pre:local";
prefix = Name::prefix(qname);
assert (prefix == "pre");
}
void NameTest::testName()
{
std::string qname = "name";
Name name(qname);
assert (name.qname() == "name");
assert (name.prefix().empty());
assert (name.namespaceURI().empty());
assert (name.localName().empty());
qname.clear();
name.assign(qname, "http://www.appinf.com/", "local");
assert (name.qname().empty());
assert (name.prefix().empty());
assert (name.namespaceURI() == "http://www.appinf.com/");
assert (name.localName() == "local");
Name name2("pre:local", "http://www.appinf.com/");
assert (name2.qname() == "pre:local");
assert (name2.prefix() == "pre");
assert (name2.namespaceURI() == "http://www.appinf.com/");
assert (name2.localName() == "local");
name2.assign("PRE:Local", "http://www.appinf.com/");
assert (name2.qname() == "PRE:Local");
assert (name2.prefix() == "PRE");
assert (name2.namespaceURI() == "http://www.appinf.com/");
assert (name2.localName() == "Local");
}
void NameTest::testCompare()
{
Name n1("pre:local");
Name n2(n1);
Name n3("pre:local2");
assert (n1.equals(n2));
assert (!n1.equals(n3));
n1.assign("pre:local", "http://www.appinf.com", "local");
n2.assign("pre:local", "http://www.appinf.com", "local");
n3.assign("pre:local2", "http://www.appinf.com", "local2");
assert (n1.equals(n2));
assert (!n1.equals(n3));
assert (n1.equals("pre:local", "http://www.appinf.com", "local"));
assert (!n1.equals("pre:local", "", ""));
assert (n1.equalsWeakly("pre:local", "", ""));
assert (!n1.equalsWeakly("pre:local2", "", ""));
assert (!n1.equals("", "http://www.appinf.com", "local"));
assert (n1.equalsWeakly("", "http://www.appinf.com", "local"));
assert (!n1.equalsWeakly("", "http://www.appinf.com", "local2"));
}
void NameTest::testSwap()
{
Name n1("ns:name1", "http://www.appinf.com");
Name n2("ns:name2", "http://www.foobar.com");
n1.swap(n2);
assert (n1.qname() == "ns:name2");
assert (n1.namespaceURI() == "http://www.foobar.com");
assert (n1.localName() == "name2");
assert (n2.qname() == "ns:name1");
assert (n2.namespaceURI() == "http://www.appinf.com");
assert (n2.localName() == "name1");
}
void NameTest::setUp()
{
}
void NameTest::tearDown()
{
}
CppUnit::Test* NameTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NameTest");
CppUnit_addTest(pSuite, NameTest, testSplit);
CppUnit_addTest(pSuite, NameTest, testLocalName);
CppUnit_addTest(pSuite, NameTest, testPrefix);
CppUnit_addTest(pSuite, NameTest, testName);
CppUnit_addTest(pSuite, NameTest, testCompare);
CppUnit_addTest(pSuite, NameTest, testSwap);
return pSuite;
}

View File

@@ -0,0 +1,69 @@
//
// NameTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/NameTest.h#2 $
//
// Definition of the NameTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef NameTest_INCLUDED
#define NameTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class NameTest: public CppUnit::TestCase
{
public:
NameTest(const std::string& name);
~NameTest();
void testSplit();
void testLocalName();
void testPrefix();
void testName();
void testCompare();
void testSwap();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // NameTest_INCLUDED

View File

@@ -0,0 +1,212 @@
//
// NamespaceSupportTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/NamespaceSupportTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "NamespaceSupportTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "SAX/NamespaceSupport.h"
using XML::NamespaceSupport;
NamespaceSupportTest::NamespaceSupportTest(const std::string& name): CppUnit::TestCase(name)
{
}
NamespaceSupportTest::~NamespaceSupportTest()
{
}
void NamespaceSupportTest::testNamespaceSupport()
{
NamespaceSupport ns;
NamespaceSupport::PrefixSet prefixes;
ns.getDeclaredPrefixes(prefixes);
assert (prefixes.size() == 2);
assert (prefixes.find("xml") != prefixes.end());
assert (prefixes.find("xmlns") != prefixes.end());
ns.getPrefixes(prefixes);
assert (prefixes.size() == 2);
assert (prefixes.find("xml") != prefixes.end());
assert (prefixes.find("xmlns") != prefixes.end());
ns.pushContext();
ns.declarePrefix("ns1", "urn:ns1");
ns.declarePrefix("ns2", "urn:ns2");
ns.getDeclaredPrefixes(prefixes);
assert (prefixes.size() == 2);
assert (prefixes.find("ns1") != prefixes.end());
assert (prefixes.find("ns2") != prefixes.end());
ns.pushContext();
ns.declarePrefix("ns3", "urn:ns3");
ns.getDeclaredPrefixes(prefixes);
assert (prefixes.size() == 1);
assert (prefixes.find("ns3") != prefixes.end());
ns.getPrefixes(prefixes);
assert (prefixes.size() == 5);
assert (prefixes.find("xml") != prefixes.end());
assert (prefixes.find("xmlns") != prefixes.end());
assert (prefixes.find("ns1") != prefixes.end());
assert (prefixes.find("ns2") != prefixes.end());
assert (prefixes.find("ns3") != prefixes.end());
ns.popContext();
ns.getDeclaredPrefixes(prefixes);
assert (prefixes.size() == 2);
assert (prefixes.find("ns1") != prefixes.end());
assert (prefixes.find("ns2") != prefixes.end());
assert (ns.isMapped("urn:ns1"));
assert (ns.isMapped("urn:ns2"));
assert (ns.isMapped("http://www.w3.org/XML/1998/namespace"));
assert (!ns.isMapped("urn:ns3"));
ns.getPrefixes("urn:ns2", prefixes);
assert (prefixes.size() == 1);
assert (prefixes.find("ns2") != prefixes.end());
ns.pushContext();
ns.declarePrefix("", "urn:ns3");
ns.declarePrefix("NS2", "urn:ns2");
ns.getPrefixes("urn:ns2", prefixes);
assert (prefixes.size() == 2);
assert (prefixes.find("ns2") != prefixes.end());
assert (prefixes.find("NS2") != prefixes.end());
ns.getPrefixes(prefixes);
assert (prefixes.size() == 5);
assert (prefixes.find("xml") != prefixes.end());
assert (prefixes.find("xmlns") != prefixes.end());
assert (prefixes.find("ns1") != prefixes.end());
assert (prefixes.find("ns2") != prefixes.end());
assert (prefixes.find("NS2") != prefixes.end());
ns.getDeclaredPrefixes(prefixes);
assert (prefixes.size() == 2);
assert (prefixes.find("") != prefixes.end());
assert (prefixes.find("NS2") != prefixes.end());
assert (ns.getPrefix("urn:ns3") == "");
assert (ns.getPrefix("urn:ns2") == "NS2");
assert (ns.getPrefix("urn:ns4") == "");
assert (ns.isMapped("urn:ns3"));
assert (ns.isMapped("urn:ns2"));
assert (!ns.isMapped("urn:ns4"));
assert (ns.getURI("xml") == "http://www.w3.org/XML/1998/namespace");
assert (ns.getURI("ns1") == "urn:ns1");
assert (ns.getURI("") == "urn:ns3");
assert (ns.getURI("NS2") == "urn:ns2");
std::string localName;
std::string namespaceURI;
bool declared = ns.processName("elem", namespaceURI, localName, false);
assert (declared);
assert (localName == "elem");
assert (namespaceURI == "urn:ns3");
declared = ns.processName("NS2:elem", namespaceURI, localName, false);
assert (declared);
assert (localName == "elem");
assert (namespaceURI == "urn:ns2");
declared = ns.processName("ns3:elem", namespaceURI, localName, false);
assert (!declared);
assert (localName == "elem");
assert (namespaceURI == "");
declared = ns.processName("ns2:attr", namespaceURI, localName, true);
assert (declared);
assert (localName == "attr");
assert (namespaceURI == "urn:ns2");
declared = ns.processName("attr", namespaceURI, localName, true);
assert (declared);
assert (localName == "attr");
assert (namespaceURI == "");
declared = ns.processName("ns3:attr", namespaceURI, localName, true);
assert (!declared);
assert (localName == "attr");
assert (namespaceURI == "");
ns.popContext();
assert (ns.getURI("xml") == "http://www.w3.org/XML/1998/namespace");
assert (ns.getURI("ns1") == "urn:ns1");
assert (ns.getURI("") == "");
assert (ns.getURI("NS2") == "");
declared = ns.processName("elem", namespaceURI, localName, false);
assert (declared);
assert (localName == "elem");
assert (namespaceURI == "");
declared = ns.processName("ns2:elem", namespaceURI, localName, false);
assert (declared);
assert (localName == "elem");
assert (namespaceURI == "urn:ns2");
declared = ns.processName("ns3:elem", namespaceURI, localName, false);
assert (!declared);
assert (localName == "elem");
assert (namespaceURI == "");
}
void NamespaceSupportTest::setUp()
{
}
void NamespaceSupportTest::tearDown()
{
}
CppUnit::Test* NamespaceSupportTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NamespaceSupportTest");
CppUnit_addTest(pSuite, NamespaceSupportTest, testNamespaceSupport);
return pSuite;
}

View File

@@ -0,0 +1,64 @@
//
// NamespaceSupportTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/NamespaceSupportTest.h#2 $
//
// Definition of the NamespaceSupportTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef NamespaceSupportTest_INCLUDED
#define NamespaceSupportTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class NamespaceSupportTest: public CppUnit::TestCase
{
public:
NamespaceSupportTest(const std::string& name);
~NamespaceSupportTest();
void testNamespaceSupport();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // NamespaceSupportTest_INCLUDED

View File

@@ -0,0 +1,210 @@
//
// NodeIteratorTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/NodeIteratorTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "NodeIteratorTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/NodeIterator.h"
#include "DOM/NodeFilter.h"
#include "DOM/Document.h"
#include "DOM/Element.h"
#include "DOM/Text.h"
#include "DOM/AutoPtr.h"
using XML::NodeIterator;
using XML::NodeFilter;
using XML::Element;
using XML::Document;
using XML::Text;
using XML::Node;
using XML::AutoPtr;
using XML::XMLString;
namespace
{
class TestNodeFilter: public NodeFilter
{
short acceptNode(Node* node)
{
if (node->innerText() == "text1")
return NodeFilter::FILTER_ACCEPT;
else
return NodeFilter::FILTER_REJECT;
}
};
}
NodeIteratorTest::NodeIteratorTest(const std::string& name): CppUnit::TestCase(name)
{
}
NodeIteratorTest::~NodeIteratorTest()
{
}
void NodeIteratorTest::testShowAll()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
AutoPtr<Element> pElem2 = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
pElem1->appendChild(pText1);
pElem2->appendChild(pText2);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
NodeIterator it(pRoot, NodeFilter::SHOW_ALL);
assert (it.nextNode() == pRoot);
assert (it.nextNode() == pElem1);
assert (it.nextNode() == pText1);
assert (it.nextNode() == pElem2);
assert (it.nextNode() == pText2);
assert (it.nextNode() == 0);
assert (it.previousNode() == pText2);
assert (it.previousNode() == pElem2);
assert (it.previousNode() == pText1);
assert (it.previousNode() == pElem1);
assert (it.previousNode() == pRoot);
assert (it.previousNode() == 0);
}
void NodeIteratorTest::testShowElements()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
AutoPtr<Element> pElem2 = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
pElem1->appendChild(pText1);
pElem2->appendChild(pText2);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
NodeIterator it(pRoot, NodeFilter::SHOW_ELEMENT);
assert (it.nextNode() == pRoot);
assert (it.nextNode() == pElem1);
assert (it.nextNode() == pElem2);
assert (it.nextNode() == 0);
assert (it.previousNode() == pElem2);
assert (it.previousNode() == pElem1);
assert (it.previousNode() == pRoot);
assert (it.previousNode() == 0);
}
void NodeIteratorTest::testFilter()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
AutoPtr<Element> pElem2 = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
pElem1->appendChild(pText1);
pElem2->appendChild(pText2);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
TestNodeFilter filter;
NodeIterator it(pRoot, NodeFilter::SHOW_ELEMENT, &filter);
assert (it.nextNode() == pElem1);
assert (it.nextNode() == 0);
assert (it.previousNode() == pElem1);
assert (it.previousNode() == 0);
}
void NodeIteratorTest::testShowNothing()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
AutoPtr<Element> pElem2 = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
pElem1->appendChild(pText1);
pElem2->appendChild(pText2);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
NodeIterator it(pRoot, 0);
assert (it.nextNode() == 0);
assert (it.previousNode() == 0);
}
void NodeIteratorTest::setUp()
{
}
void NodeIteratorTest::tearDown()
{
}
CppUnit::Test* NodeIteratorTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NodeIteratorTest");
CppUnit_addTest(pSuite, NodeIteratorTest, testShowAll);
CppUnit_addTest(pSuite, NodeIteratorTest, testShowElements);
CppUnit_addTest(pSuite, NodeIteratorTest, testFilter);
CppUnit_addTest(pSuite, NodeIteratorTest, testShowNothing);
return pSuite;
}

View File

@@ -0,0 +1,67 @@
//
// NodeIteratorTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/NodeIteratorTest.h#2 $
//
// Definition of the NodeIteratorTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef NodeIteratorTest_INCLUDED
#define NodeIteratorTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class NodeIteratorTest: public CppUnit::TestCase
{
public:
NodeIteratorTest(const std::string& name);
~NodeIteratorTest();
void testShowAll();
void testShowElements();
void testFilter();
void testShowNothing();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // NodeIteratorTest_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,76 @@
//
// NodeTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/NodeTest.h#2 $
//
// Definition of the NodeTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef NodeTest_INCLUDED
#define NodeTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class NodeTest: public CppUnit::TestCase
{
public:
NodeTest(const std::string& name);
~NodeTest();
void testInsert();
void testAppend();
void testRemove();
void testReplace();
void testInsertFragment1();
void testInsertFragment2();
void testInsertFragment3();
void testAppendFragment1();
void testAppendFragment2();
void testAppendFragment3();
void testReplaceFragment1();
void testReplaceFragment2();
void testReplaceFragment3();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // NodeTest_INCLUDED

View File

@@ -0,0 +1,282 @@
//
// ParserWriterTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/ParserWriterTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "ParserWriterTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/DOMParser.h"
#include "DOM/DOMWriter.h"
#include "DOM/Document.h"
#include "DOM/AutoPtr.h"
#include "SAX/InputSource.h"
#include "XML/XMLWriter.h"
#include <sstream>
#include <fstream>
using XML::DOMParser;
using XML::DOMWriter;
using XML::XMLWriter;
using XML::Document;
using XML::AutoPtr;
using XML::InputSource;
ParserWriterTest::ParserWriterTest(const std::string& name): CppUnit::TestCase(name)
{
}
ParserWriterTest::~ParserWriterTest()
{
}
void ParserWriterTest::testParseWriteXHTML()
{
std::ostringstream ostr;
DOMParser parser;
DOMWriter writer;
AutoPtr<Document> pDoc = parser.parseString(XHTML);
writer.writeNode(ostr, pDoc);
std::string xml = ostr.str();
assert (xml == XHTML);
}
void ParserWriterTest::testParseWriteWSDL()
{
std::istringstream istr(WSDL);
std::ostringstream ostr;
DOMParser parser;
parser.setFeature(DOMParser::FEATURE_WHITESPACE, false);
DOMWriter writer;
writer.setOptions(XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
writer.setNewLine(XMLWriter::NEWLINE_LF);
InputSource source(istr);
AutoPtr<Document> pDoc = parser.parse(&source);
writer.writeNode(ostr, pDoc);
std::string xml = ostr.str();
assert (xml == WSDL);
}
void ParserWriterTest::setUp()
{
}
void ParserWriterTest::tearDown()
{
}
CppUnit::Test* ParserWriterTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ParserWriterTest");
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML);
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteWSDL);
return pSuite;
}
const std::string ParserWriterTest::XHTML =
"<!--\n"
"\tThis is a comment.\n"
"-->"
"<ns1:html xml:lang=\"en\" xmlns:ns1=\"http://www.w3.org/1999/xhtml\">\n"
"\t<ns1:head>\n"
"\t\t<ns1:link href=\"styles.css\" rel=\"stylesheet\" type=\"text/css\"/>\n"
"\t\t<?xml-stylesheet href=\"styles.css\" type=\"text/css\"?>\n"
"\t\t<ns1:title>A XHTML Example</ns1:title>\n"
"\t</ns1:head>\n"
"\t<ns1:body>\n"
"\t\t<ns1:h1>XHTML Example</ns1:h1>\n"
"\t\t<ns1:p>This is a XHTML example page.</ns1:p>\n"
"\t\t<ns1:img alt=\"Example Picture\" border=\"0\" height=\"192\" src=\"example.gif\" width=\"256\"/>\n"
"\t\t<![CDATA[\n"
"\t\tThe following <tag attr=\"value\">is inside a CDATA section</tag>.\n"
"\t\t]]>\n"
"\t</ns1:body>\n"
"</ns1:html>";
const std::string ParserWriterTest::WSDL =
"<!-- WSDL description of the Google Web APIs.\n"
" The Google Web APIs are in beta release. All interfaces are subject to\n"
" change as we refine and extend our APIs. Please see the terms of use\n"
" for more information. -->\n"
"<!-- Revision 2002-08-16 -->\n"
"<ns1:definitions name=\"GoogleSearch\" targetNamespace=\"urn:GoogleSearch\" xmlns:ns1=\"http://schemas.xmlsoap.org/wsdl/\">\n"
"\t<!-- Types for search - result elements, directory categories -->\n"
"\t<ns1:types>\n"
"\t\t<ns2:schema targetNamespace=\"urn:GoogleSearch\" xmlns:ns2=\"http://www.w3.org/2001/XMLSchema\">\n"
"\t\t\t<ns2:complexType name=\"GoogleSearchResult\">\n"
"\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"documentFiltering\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchComments\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"estimatedTotalResultsCount\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"estimateIsExact\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"resultElements\" type=\"typens:ResultElementArray\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchQuery\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"startIndex\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"endIndex\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchTips\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryCategories\" type=\"typens:DirectoryCategoryArray\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchTime\" type=\"xsd:double\"/>\n"
"\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"ResultElement\">\n"
"\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"summary\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"URL\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"snippet\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"title\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"cachedSize\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"relatedInformationPresent\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"hostName\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryCategory\" type=\"typens:DirectoryCategory\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryTitle\" type=\"xsd:string\"/>\n"
"\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"ResultElementArray\">\n"
"\t\t\t\t<ns2:complexContent>\n"
"\t\t\t\t\t<ns2:restriction base=\"soapenc:Array\">\n"
"\t\t\t\t\t\t<ns2:attribute ns1:arrayType=\"typens:ResultElement[]\" ref=\"soapenc:arrayType\"/>\n"
"\t\t\t\t\t</ns2:restriction>\n"
"\t\t\t\t</ns2:complexContent>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"DirectoryCategoryArray\">\n"
"\t\t\t\t<ns2:complexContent>\n"
"\t\t\t\t\t<ns2:restriction base=\"soapenc:Array\">\n"
"\t\t\t\t\t\t<ns2:attribute ns1:arrayType=\"typens:DirectoryCategory[]\" ref=\"soapenc:arrayType\"/>\n"
"\t\t\t\t\t</ns2:restriction>\n"
"\t\t\t\t</ns2:complexContent>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"DirectoryCategory\">\n"
"\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"fullViewableName\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"specialEncoding\" type=\"xsd:string\"/>\n"
"\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t</ns2:schema>\n"
"\t</ns1:types>\n"
"\t<!-- Messages for Google Web APIs - cached page, search, spelling. -->\n"
"\t<ns1:message name=\"doGetCachedPage\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"url\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n"
"\t<ns1:message name=\"doGetCachedPageResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"xsd:base64Binary\"/>\n"
"\t</ns1:message>\n"
"\t<ns1:message name=\"doSpellingSuggestion\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"phrase\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n"
"\t<ns1:message name=\"doSpellingSuggestionResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n"
"\t<!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->\n"
"\t<ns1:message name=\"doGoogleSearch\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"q\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"start\" type=\"xsd:int\"/>\n"
"\t\t<ns1:part name=\"maxResults\" type=\"xsd:int\"/>\n"
"\t\t<ns1:part name=\"filter\" type=\"xsd:boolean\"/>\n"
"\t\t<ns1:part name=\"restrict\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"safeSearch\" type=\"xsd:boolean\"/>\n"
"\t\t<ns1:part name=\"lr\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"ie\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"oe\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n"
"\t<ns1:message name=\"doGoogleSearchResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"typens:GoogleSearchResult\"/>\n"
"\t</ns1:message>\n"
"\t<!-- Port for Google Web APIs, \"GoogleSearch\" -->\n"
"\t<ns1:portType name=\"GoogleSearchPort\">\n"
"\t\t<ns1:operation name=\"doGetCachedPage\">\n"
"\t\t\t<ns1:input message=\"typens:doGetCachedPage\"/>\n"
"\t\t\t<ns1:output message=\"typens:doGetCachedPageResponse\"/>\n"
"\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doSpellingSuggestion\">\n"
"\t\t\t<ns1:input message=\"typens:doSpellingSuggestion\"/>\n"
"\t\t\t<ns1:output message=\"typens:doSpellingSuggestionResponse\"/>\n"
"\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doGoogleSearch\">\n"
"\t\t\t<ns1:input message=\"typens:doGoogleSearch\"/>\n"
"\t\t\t<ns1:output message=\"typens:doGoogleSearchResponse\"/>\n"
"\t\t</ns1:operation>\n"
"\t</ns1:portType>\n"
"\t<!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->\n"
"\t<ns1:binding name=\"GoogleSearchBinding\" type=\"typens:GoogleSearchPort\">\n"
"\t\t<ns3:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\"/>\n"
"\t\t<ns1:operation name=\"doGetCachedPage\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doSpellingSuggestion\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doGoogleSearch\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n"
"\t</ns1:binding>\n"
"\t<!-- Endpoint for Google Web APIs -->\n"
"\t<ns1:service name=\"GoogleSearchService\">\n"
"\t\t<ns1:port binding=\"typens:GoogleSearchBinding\" name=\"GoogleSearchPort\">\n"
"\t\t\t<ns4:address location=\"http://api.google.com/search/beta2\" xmlns:ns4=\"http://schemas.xmlsoap.org/wsdl/soap/\"/>\n"
"\t\t</ns1:port>\n"
"\t</ns1:service>\n"
"</ns1:definitions>\n";

View File

@@ -0,0 +1,67 @@
//
// ParserWriterTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/ParserWriterTest.h#2 $
//
// Definition of the ParserWriterTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ParserWriterTest_INCLUDED
#define ParserWriterTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class ParserWriterTest: public CppUnit::TestCase
{
public:
ParserWriterTest(const std::string& name);
~ParserWriterTest();
void testParseWriteXHTML();
void testParseWriteWSDL();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
static const std::string XHTML;
static const std::string WSDL;
};
#endif // ParserWriterTest_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,105 @@
//
// SAXParserTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/SAXParserTest.h#2 $
//
// Definition of the SAXParserTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef SAXParserTest_INCLUDED
#define SAXParserTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
#ifndef SAX_XMLReader_INCLUDED
#include "SAX/XMLReader.h"
#endif
class SAXParserTest: public CppUnit::TestCase
{
public:
SAXParserTest(const std::string& name);
~SAXParserTest();
void testSimple1();
void testSimple2();
void testAttributes();
void testCDATA();
void testComment();
void testPI();
void testDTD();
void testInternalEntity();
void testNotation();
void testExternalUnparsed();
void testExternalParsed();
void testDefaultNamespace();
void testNamespaces();
void testNamespacesNoPrefixes();
void testNoNamespaces();
void testUndeclaredNamespace();
void testUndeclaredNamespaceNoPrefixes();
void testUndeclaredNoNamespace();
void testRSS();
void testEncoding();
void setUp();
void tearDown();
std::string parse(XML::XMLReader& reader, int options, const std::string& data);
static CppUnit::Test* suite();
static const std::string SIMPLE1;
static const std::string SIMPLE2;
static const std::string ATTRIBUTES;
static const std::string CDATA;
static const std::string COMMENT;
static const std::string PROCESSING_INSTRUCTION;
static const std::string DTD;
static const std::string INTERNAL_ENTITY;
static const std::string NOTATION;
static const std::string EXTERNAL_UNPARSED;
static const std::string EXTERNAL_PARSED;
static const std::string INCLUDE;
static const std::string DEFAULT_NAMESPACE;
static const std::string NAMESPACES;
static const std::string UNDECLARED_NAMESPACE;
static const std::string XHTML_LATIN1_ENTITIES;
static const std::string RSS;
static const std::string ENCODING;
};
#endif // SAXParserTest_INCLUDED

View File

@@ -0,0 +1,48 @@
//
// SAXTestSuite.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/SAXTestSuite.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAXTestSuite.h"
#include "AttributesImplTest.h"
#include "NamespaceSupportTest.h"
#include "SAXParserTest.h"
CppUnit::Test* SAXTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SAXTestSuite");
pSuite->addTest(AttributesImplTest::suite());
pSuite->addTest(NamespaceSupportTest::suite());
pSuite->addTest(SAXParserTest::suite());
return pSuite;
}

View File

@@ -0,0 +1,51 @@
//
// SAXTestSuite.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/SAXTestSuite.h#2 $
//
// Definition of the SAXTestSuite class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef SAXTestSuite_INCLUDED
#define SAXTestSuite_INCLUDED
#ifndef CppUnit_TestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
#endif
class SAXTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // SAXTestSuite_INCLUDED

View File

@@ -0,0 +1,189 @@
//
// TextTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/TextTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "TextTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/Text.h"
#include "DOM/CDATASection.h"
#include "DOM/Element.h"
#include "DOM/Document.h"
#include "DOM/AutoPtr.h"
using XML::Text;
using XML::CDATASection;
using XML::Element;
using XML::Document;
using XML::AutoPtr;
using XML::XMLString;
TextTest::TextTest(const std::string& name): CppUnit::TestCase(name)
{
}
TextTest::~TextTest()
{
}
void TextTest::testLength()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Text> pText1 = pDoc->createTextNode("");
assert (pText1->length() == 0);
AutoPtr<Text> pText2 = pDoc->createTextNode("foo bar");
assert (pText2->length() == 7);
}
void TextTest::testSubstring()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Text> pText1 = pDoc->createTextNode("foo bar");
XMLString str = pText1->substringData(0, 3);
assert (str == "foo");
str = pText1->substringData(4, 3);
assert (str == "bar");
str = pText1->substringData(3, 0);
assert (str == "");
}
void TextTest::testAppend()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Text> pText1 = pDoc->createTextNode("foo");
pText1->appendData("bar");
assert (pText1->data() == "foobar");
}
void TextTest::testInsert()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Text> pText1 = pDoc->createTextNode("bar");
pText1->insertData(0, "foo");
assert (pText1->data() == "foobar");
pText1->insertData(pText1->length(), "!");
assert (pText1->data() == "foobar!");
pText1->insertData(3, " ");
assert (pText1->data() == "foo bar!");
}
void TextTest::testDelete()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Text> pText1 = pDoc->createTextNode("foo bar");
pText1->deleteData(3, 1);
assert (pText1->data() == "foobar");
pText1->deleteData(0, 3);
assert (pText1->data() == "bar");
pText1->deleteData(1, 0);
assert (pText1->data() == "bar");
pText1->deleteData(0, pText1->length());
assert (pText1->data() == "");
}
void TextTest::testReplace()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Text> pText1 = pDoc->createTextNode("foo bar");
pText1->replaceData(0, 3, "FOO");
assert (pText1->data() == "FOO bar");
pText1->replaceData(4, 3, "BAR!!!");
assert (pText1->data() == "FOO BAR!!!");
pText1->replaceData(3, 1, "-");
assert (pText1->data() == "FOO-BAR!!!");
pText1->replaceData(3, 1, "---");
assert (pText1->data() == "FOO---BAR!!!");
pText1->replaceData(3, 3, " ");
assert (pText1->data() == "FOO BAR!!!");
pText1->replaceData(0, pText1->length(), "foo bar");
assert (pText1->data() == "foo bar");
}
void TextTest::testSplit()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pElem = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createCDATASection("foobar");
pElem->appendChild(pText1);
pText1->splitText(3);
assert (pElem->firstChild()->nodeValue() == "foo");
assert (pElem->lastChild()->nodeValue() == "bar");
}
void TextTest::testSplitCDATA()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pElem = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("foobar");
pElem->appendChild(pText1);
pText1->splitText(3);
assert (pElem->firstChild()->nodeValue() == "foo");
assert (pElem->lastChild()->nodeValue() == "bar");
}
void TextTest::setUp()
{
}
void TextTest::tearDown()
{
}
CppUnit::Test* TextTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextTest");
CppUnit_addTest(pSuite, TextTest, testLength);
CppUnit_addTest(pSuite, TextTest, testSubstring);
CppUnit_addTest(pSuite, TextTest, testAppend);
CppUnit_addTest(pSuite, TextTest, testInsert);
CppUnit_addTest(pSuite, TextTest, testDelete);
CppUnit_addTest(pSuite, TextTest, testReplace);
CppUnit_addTest(pSuite, TextTest, testSplit);
CppUnit_addTest(pSuite, TextTest, testSplitCDATA);
return pSuite;
}

View File

@@ -0,0 +1,71 @@
//
// TextTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/TextTest.h#2 $
//
// Definition of the TextTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef TextTest_INCLUDED
#define TextTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class TextTest: public CppUnit::TestCase
{
public:
TextTest(const std::string& name);
~TextTest();
void testLength();
void testSubstring();
void testAppend();
void testInsert();
void testDelete();
void testReplace();
void testSplit();
void testSplitCDATA();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // TextTest_INCLUDED

View File

@@ -0,0 +1,329 @@
//
// TreeWalkerTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/TreeWalkerTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "TreeWalkerTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "DOM/TreeWalker.h"
#include "DOM/NodeFilter.h"
#include "DOM/Document.h"
#include "DOM/Element.h"
#include "DOM/Text.h"
#include "DOM/AutoPtr.h"
using XML::TreeWalker;
using XML::NodeFilter;
using XML::Element;
using XML::Document;
using XML::Text;
using XML::Node;
using XML::AutoPtr;
using XML::XMLString;
namespace
{
class RejectNodeFilter: public NodeFilter
{
short acceptNode(Node* node)
{
if (node->nodeType() != Node::ELEMENT_NODE || node->innerText() == "text1" || node->nodeName() == "root")
return NodeFilter::FILTER_ACCEPT;
else
return NodeFilter::FILTER_REJECT;
}
};
class SkipNodeFilter: public NodeFilter
{
short acceptNode(Node* node)
{
if (node->nodeType() != Node::ELEMENT_NODE || node->innerText() == "text1")
return NodeFilter::FILTER_ACCEPT;
else
return NodeFilter::FILTER_SKIP;
}
};
}
TreeWalkerTest::TreeWalkerTest(const std::string& name): CppUnit::TestCase(name)
{
}
TreeWalkerTest::~TreeWalkerTest()
{
}
void TreeWalkerTest::testShowAll()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
AutoPtr<Element> pElem2 = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
pElem1->appendChild(pText1);
pElem2->appendChild(pText2);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
TreeWalker it(pRoot, NodeFilter::SHOW_ALL);
assert (it.currentNode() == pRoot);
assert (it.nextNode() == pElem1);
assert (it.nextNode() == pText1);
assert (it.nextNode() == pElem2);
assert (it.nextNode() == pText2);
assert (it.nextNode() == 0);
assert (it.currentNode() == pText2);
assert (it.previousNode() == pElem2);
assert (it.previousNode() == pText1);
assert (it.previousNode() == pElem1);
assert (it.previousNode() == pRoot);
assert (it.previousNode() == 0);
assert (it.currentNode() == pRoot);
assert (it.parentNode() == 0);
assert (it.currentNode() == pRoot);
assert (it.firstChild() == pElem1);
assert (it.parentNode() == pRoot);
assert (it.lastChild() == pElem2);
assert (it.previousSibling() == pElem1);
assert (it.previousSibling() == 0);
assert (it.currentNode() == pElem1);
assert (it.nextSibling() == pElem2);
assert (it.nextSibling() == 0);
assert (it.currentNode() == pElem2);
assert (it.firstChild() == pText2);
assert (it.nextSibling() == 0);
assert (it.previousSibling() == 0);
assert (it.parentNode() == pElem2);
assert (it.lastChild() == pText2);
}
void TreeWalkerTest::testShowElements()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
AutoPtr<Element> pElem2 = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
pElem1->appendChild(pText1);
pElem2->appendChild(pText2);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
TreeWalker it(pRoot, NodeFilter::SHOW_ELEMENT);
assert (it.currentNode() == pRoot);
assert (it.nextNode() == pElem1);
assert (it.nextNode() == pElem2);
assert (it.nextNode() == 0);
assert (it.currentNode() == pElem2);
assert (it.previousNode() == pElem1);
assert (it.previousNode() == pRoot);
assert (it.previousNode() == 0);
assert (it.currentNode() == pRoot);
assert (it.parentNode() == 0);
assert (it.currentNode() == pRoot);
assert (it.firstChild() == pElem1);
assert (it.parentNode() == pRoot);
assert (it.lastChild() == pElem2);
assert (it.firstChild() == 0);
assert (it.currentNode() == pElem2);
assert (it.lastChild() == 0);
assert (it.currentNode() == pElem2);
assert (it.previousSibling() == pElem1);
assert (it.firstChild() == 0);
assert (it.lastChild() == 0);
assert (it.parentNode() == pRoot);
}
void TreeWalkerTest::testFilter()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
AutoPtr<Element> pElem2 = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
pElem1->appendChild(pText1);
pElem2->appendChild(pText2);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
SkipNodeFilter skipFilter;
TreeWalker it1(pRoot, NodeFilter::SHOW_ELEMENT, &skipFilter);
assert (it1.nextNode() == pElem1);
assert (it1.nextNode() == 0);
assert (it1.currentNode() == pElem1);
assert (it1.previousNode() == 0);
assert (it1.parentNode() == 0);
assert (it1.firstChild() == 0);
assert (it1.lastChild() == 0);
assert (it1.nextSibling() == 0);
assert (it1.previousSibling() == 0);
TreeWalker it2(pRoot, NodeFilter::SHOW_ALL, &skipFilter);
assert (it2.nextNode() == pElem1);
assert (it2.nextNode() == pText1);
assert (it2.nextNode() == pText2);
assert (it2.nextNode() == 0);
assert (it2.currentNode() == pText2);
assert (it2.previousNode() == pText1);
assert (it2.previousNode() == pElem1);
assert (it2.previousNode() == 0);
assert (it2.currentNode() == pElem1);
assert (it2.parentNode() == 0);
assert (it2.nextSibling() == 0);
assert (it2.previousSibling() == 0);
assert (it2.firstChild() == pText1);
assert (it2.nextSibling() == 0);
assert (it2.previousSibling() == 0);
assert (it2.parentNode() == pElem1);
RejectNodeFilter rejectFilter;
TreeWalker it3(pRoot, NodeFilter::SHOW_ELEMENT, &rejectFilter);
assert (it3.nextNode() == pElem1);
assert (it3.nextNode() == 0);
assert (it3.currentNode() == pElem1);
assert (it3.previousNode() == pRoot);
assert (it3.previousNode() == 0);
assert (it3.currentNode() == pRoot);
assert (it3.parentNode() == 0);
assert (it3.firstChild() == pElem1);
assert (it3.nextSibling() == 0);
assert (it3.previousSibling() == 0);
assert (it3.parentNode() == pRoot);
assert (it3.lastChild() == pElem1);
TreeWalker it4(pRoot, NodeFilter::SHOW_ALL, &rejectFilter);
assert (it4.nextNode() == pElem1);
assert (it4.nextNode() == pText1);
assert (it4.nextNode() == 0);
assert (it4.currentNode() == pText1);
assert (it4.previousNode() == pElem1);
assert (it4.previousNode() == pRoot);
assert (it4.previousNode() == 0);
assert (it4.currentNode() == pRoot);
assert (it4.parentNode() == 0);
assert (it4.firstChild() == pElem1);
assert (it4.firstChild() == pText1);
assert (it4.nextSibling() == 0);
assert (it4.previousSibling() == 0);
assert (it4.parentNode() == pElem1);
assert (it4.lastChild() == pText1);
assert (it4.parentNode() == pElem1);
assert (it4.nextSibling() == 0);
assert (it4.previousSibling() == 0);
assert (it4.parentNode() == pRoot);
}
void TreeWalkerTest::testShowNothing()
{
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem");
AutoPtr<Element> pElem2 = pDoc->createElement("elem");
AutoPtr<Text> pText1 = pDoc->createTextNode("text1");
AutoPtr<Text> pText2 = pDoc->createTextNode("text2");
pElem1->appendChild(pText1);
pElem2->appendChild(pText2);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
TreeWalker it(pRoot, 0);
assert (it.nextNode() == 0);
assert (it.previousNode() == 0);
assert (it.currentNode() == pRoot);
assert (it.firstChild() == 0);
assert (it.lastChild() == 0);
assert (it.nextSibling() == 0);
assert (it.previousSibling() == 0);
}
void TreeWalkerTest::setUp()
{
}
void TreeWalkerTest::tearDown()
{
}
CppUnit::Test* TreeWalkerTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TreeWalkerTest");
CppUnit_addTest(pSuite, TreeWalkerTest, testShowAll);
CppUnit_addTest(pSuite, TreeWalkerTest, testShowElements);
CppUnit_addTest(pSuite, TreeWalkerTest, testFilter);
CppUnit_addTest(pSuite, TreeWalkerTest, testShowNothing);
return pSuite;
}

View File

@@ -0,0 +1,67 @@
//
// TreeWalkerTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/TreeWalkerTest.h#2 $
//
// Definition of the TreeWalkerTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef TreeWalkerTest_INCLUDED
#define TreeWalkerTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class TreeWalkerTest: public CppUnit::TestCase
{
public:
TreeWalkerTest(const std::string& name);
~TreeWalkerTest();
void testShowAll();
void testShowElements();
void testFilter();
void testShowNothing();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // TreeWalkerTest_INCLUDED

View File

@@ -0,0 +1,50 @@
//
// WinDriver.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/WinDriver.cpp#2 $
//
// Windows test driver for Poco XML.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "WinTestRunner/WinTestRunner.h"
#include "XMLTestSuite.h"
class TestDriver: public CppUnit::WinTestRunnerApp
{
void TestMain()
{
CppUnit::WinTestRunner runner;
runner.addTest(XMLTestSuite::suite());
runner.run();
}
};
TestDriver theDriver;

View File

@@ -0,0 +1,52 @@
//
// XMLTestSuite.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/XMLTestSuite.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XMLTestSuite.h"
#include "NameTest.h"
#include "NamePoolTest.h"
#include "XMLWriterTest.h"
#include "SAXTestSuite.h"
#include "DOMTestSuite.h"
CppUnit::Test* XMLTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLTestSuite");
pSuite->addTest(NameTest::suite());
pSuite->addTest(NamePoolTest::suite());
pSuite->addTest(XMLWriterTest::suite());
pSuite->addTest(SAXTestSuite::suite());
pSuite->addTest(DOMTestSuite::suite());
return pSuite;
}

View File

@@ -0,0 +1,51 @@
//
// XMLTestSuite.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/XMLTestSuite.h#2 $
//
// Definition of the XMLTestSuite class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef XMLTestSuite_INCLUDED
#define XMLTestSuite_INCLUDED
#ifndef CppUnit_TestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
#endif
class XMLTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // XMLTestSuite_INCLUDED

View File

@@ -0,0 +1,525 @@
//
// XMLWriterTest.cpp
//
// $Id: //poco/1.1.0/XML/testsuite/src/XMLWriterTest.cpp#2 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XMLWriterTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "XML/XMLWriter.h"
#include "SAX/AttributesImpl.h"
#include "Foundation/Exception.h"
#include <sstream>
using XML::XMLWriter;
using XML::AttributesImpl;
XMLWriterTest::XMLWriterTest(const std::string& name): CppUnit::TestCase(name)
{
}
XMLWriterTest::~XMLWriterTest()
{
}
void XMLWriterTest::testTrivial()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<foo/>");
}
void XMLWriterTest::testTrivialDecl()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION);
writer.startDocument();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo/>");
}
void XMLWriterTest::testTrivialDeclPretty()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n");
writer.startDocument();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo/>\n");
}
void XMLWriterTest::testTrivialFragment()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startFragment();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endFragment();
std::string xml = str.str();
assert (xml == "<foo/>");
}
void XMLWriterTest::testTrivialFragmentPretty()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n");
writer.startFragment();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endFragment();
std::string xml = str.str();
assert (xml == "<foo/>\n");
}
void XMLWriterTest::testDTDPretty()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n");
writer.startDocument();
writer.startDTD("test", "", "http://www.appinf.com/DTDs/test");
writer.endDTD();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE test SYSTEM \"http://www.appinf.com/DTDs/test\">\n"
"<foo/>\n");
}
void XMLWriterTest::testDTD()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION);
writer.setNewLine("\n");
writer.startDocument();
writer.startDTD("test", "", "http://www.appinf.com/DTDs/test");
writer.endDTD();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<!DOCTYPE test SYSTEM \"http://www.appinf.com/DTDs/test\">"
"<foo/>");
}
void XMLWriterTest::testDTDNotation()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n");
writer.startDocument();
writer.startDTD("test", "", "");
std::string systemId("quicktime");
writer.notationDecl("mov", 0, &systemId);
std::string publicId("-//W3C//NOTATION XML 1.0//EN");
writer.notationDecl("xml", &publicId, 0);
writer.endDTD();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE test [\n"
"\t<!NOTATION mov SYSTEM \"quicktime\">\n"
"\t<!NOTATION xml PUBLIC \"-//W3C//NOTATION XML 1.0//EN\">\n"
"]>\n"
"<foo/>\n");
}
void XMLWriterTest::testDTDEntity()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n");
writer.startDocument();
writer.startDTD("test", "", "");
std::string systemId("quicktime");
writer.notationDecl("mov", 0, &systemId);
std::string publicId("-//W3C//NOTATION XML 1.0//EN");
writer.unparsedEntityDecl("movie", 0, "movie.mov", "mov");
writer.endDTD();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE test [\n"
"\t<!NOTATION mov SYSTEM \"quicktime\">\n"
"\t<!ENTITY movie SYSTEM \"movie.mov\" NDATA mov>\n"
"]>\n"
"<foo/>\n");
}
void XMLWriterTest::testAttributes()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
AttributesImpl attrs;
attrs.addAttribute("", "", "a1", "CDATA", "v1");
attrs.addAttribute("", "", "a2", "CDATA", "v2");
writer.startElement("", "", "el", attrs);
writer.endElement("", "", "el");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<el a1=\"v1\" a2=\"v2\"/>");
}
void XMLWriterTest::testData()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<d a1=\"v1\" a2=\"v2\" a3=\"v3\">data</d>");
}
void XMLWriterTest::testDataPretty()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n");
writer.startDocument();
writer.startElement("", "", "r");
writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3");
writer.endElement("", "", "r");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<r>\n\t<d a1=\"v1\" a2=\"v2\" a3=\"v3\">data</d>\n</r>\n");
}
void XMLWriterTest::testComment()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n");
writer.startDocument();
writer.comment("a comment", 0, 9);
writer.startElement("", "", "r");
writer.comment("<another comment>", 0, 17);
writer.dataElement("", "", "d", "data");
writer.endElement("", "", "r");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<!--a comment-->\n<r>\n\t<!--<another comment>-->\n\t<d>data</d>\n</r>\n");
}
void XMLWriterTest::testPI()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n");
writer.startDocument();
writer.processingInstruction("target", "a processing instruction");
writer.startElement("", "", "r");
writer.processingInstruction("target", "another processing instruction");
writer.dataElement("", "", "d", "data");
writer.endElement("", "", "r");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<?target a processing instruction?>\n<r>\n\t<?target another processing instruction?>\n\t<d>data</d>\n</r>\n");
}
void XMLWriterTest::testCharacters()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("", "", "r");
writer.characters("some \"chars\" that <must> be & escaped");
writer.endElement("", "", "r");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<r>some &quot;chars&quot; that &lt;must&gt; be &amp; escaped</r>");
}
void XMLWriterTest::testCDATA()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("", "", "r");
writer.startCDATA();
writer.characters("some \"chars\" that <must> be & escaped");
writer.endCDATA();
writer.endElement("", "", "r");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<r><![CDATA[some \"chars\" that <must> be & escaped]]></r>");
}
void XMLWriterTest::testRawCharacters()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("", "", "r");
writer.startCDATA();
writer.rawCharacters("some \"chars\" that <must> be & escaped");
writer.endCDATA();
writer.endElement("", "", "r");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<r><![CDATA[some \"chars\" that <must> be & escaped]]></r>");
}
void XMLWriterTest::testDefaultNamespace()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startPrefixMapping("", "urn:ns");
writer.startElement("", "", "r");
writer.characters("data");
writer.endElement("", "", "r");
writer.endPrefixMapping("");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<r xmlns=\"urn:ns\">data</r>");
}
void XMLWriterTest::testQNamespaces()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("urn:ns", "r", "p:r");
writer.characters("data");
writer.endElement("urn:ns", "r", "p:r");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<p:r xmlns:p=\"urn:ns\">data</p:r>");
}
void XMLWriterTest::testQNamespacesNested()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("urn:ns", "r", "p:r");
writer.startElement("urn:ns", "e", "p:e");
writer.endElement("urn:ns", "e", "p:e");
writer.endElement("urn:ns", "r", "p:r");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<p:r xmlns:p=\"urn:ns\"><p:e/></p:r>");
}
void XMLWriterTest::testNamespaces()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("urn:ns", "r", "");
writer.characters("data");
writer.endElement("urn:ns", "r", "");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<ns1:r xmlns:ns1=\"urn:ns\">data</ns1:r>");
}
void XMLWriterTest::testNamespacesNested()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("urn:ns1", "r", "");
writer.startElement("urn:ns1", "e", "");
writer.endElement("urn:ns1", "e", "");
writer.startElement("urn:ns2", "f", "");
writer.endElement("urn:ns2", "f", "");
writer.endElement("urn:ns1", "r", "");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<ns1:r xmlns:ns1=\"urn:ns1\"><ns1:e/><ns2:f xmlns:ns2=\"urn:ns2\"/></ns1:r>");
}
void XMLWriterTest::testExplicitNamespaces()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startPrefixMapping("p1", "urn:ns1");
writer.startPrefixMapping("p2", "urn:ns2");
writer.startElement("urn:ns1", "r", "");
writer.startElement("urn:ns2", "e", "");
writer.endElement("urn:ns2", "e", "");
writer.startPrefixMapping("p3", "urn:ns3");
writer.startElement("urn:ns2", "e", "");
writer.startElement("urn:ns3", "f", "");
writer.endElement("urn:ns3", "f", "");
writer.endElement("urn:ns2", "e", "");
writer.endElement("urn:ns1", "r", "");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<p1:r xmlns:p1=\"urn:ns1\" xmlns:p2=\"urn:ns2\"><p2:e/><p2:e xmlns:p3=\"urn:ns3\"><p3:f/></p2:e></p1:r>");
}
void XMLWriterTest::testWellformed()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("", "", "foo");
try
{
writer.endElement("", "", "bar");
fail("not wellformed - must throw exception");
}
catch (Foundation::Exception&)
{
}
}
void XMLWriterTest::testWellformedNested()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("", "", "foo");
writer.startElement("", "", "bar");
try
{
writer.endElement("", "", "foo");
fail("not wellformed - must throw exception");
}
catch (Foundation::Exception&)
{
}
}
void XMLWriterTest::testWellformedNamespace()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument();
writer.startElement("urn:ns1", "foo", "");
writer.startElement("urn:ns2", "bar", "");
try
{
writer.endElement("urn:ns1", "bar", "");
fail("not wellformed - must throw exception");
}
catch (Foundation::Exception&)
{
}
}
void XMLWriterTest::setUp()
{
}
void XMLWriterTest::tearDown()
{
}
CppUnit::Test* XMLWriterTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLWriterTest");
CppUnit_addTest(pSuite, XMLWriterTest, testTrivial);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDecl);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDeclPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragment);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragmentPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testDTDPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testDTD);
CppUnit_addTest(pSuite, XMLWriterTest, testDTDNotation);
CppUnit_addTest(pSuite, XMLWriterTest, testDTDEntity);
CppUnit_addTest(pSuite, XMLWriterTest, testAttributes);
CppUnit_addTest(pSuite, XMLWriterTest, testData);
CppUnit_addTest(pSuite, XMLWriterTest, testDataPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testComment);
CppUnit_addTest(pSuite, XMLWriterTest, testPI);
CppUnit_addTest(pSuite, XMLWriterTest, testCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testCDATA);
CppUnit_addTest(pSuite, XMLWriterTest, testRawCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testDefaultNamespace);
CppUnit_addTest(pSuite, XMLWriterTest, testQNamespaces);
CppUnit_addTest(pSuite, XMLWriterTest, testQNamespacesNested);
CppUnit_addTest(pSuite, XMLWriterTest, testNamespaces);
CppUnit_addTest(pSuite, XMLWriterTest, testNamespacesNested);
CppUnit_addTest(pSuite, XMLWriterTest, testExplicitNamespaces);
CppUnit_addTest(pSuite, XMLWriterTest, testWellformed);
CppUnit_addTest(pSuite, XMLWriterTest, testWellformedNested);
CppUnit_addTest(pSuite, XMLWriterTest, testWellformedNamespace);
return pSuite;
}

View File

@@ -0,0 +1,89 @@
//
// XMLWriterTest.h
//
// $Id: //poco/1.1.0/XML/testsuite/src/XMLWriterTest.h#2 $
//
// Definition of the XMLWriterTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef XMLWriterTest_INCLUDED
#define XMLWriterTest_INCLUDED
#ifndef XML_XML_INCLUDED
#include "XML/XML.h"
#endif
#ifndef CppUnit_TestCase_INCLUDED
#include "CppUnit/TestCase.h"
#endif
class XMLWriterTest: public CppUnit::TestCase
{
public:
XMLWriterTest(const std::string& name);
~XMLWriterTest();
void testTrivial();
void testTrivialDecl();
void testTrivialDeclPretty();
void testTrivialFragment();
void testTrivialFragmentPretty();
void testDTDPretty();
void testDTD();
void testDTDNotation();
void testDTDEntity();
void testAttributes();
void testData();
void testDataPretty();
void testComment();
void testPI();
void testCharacters();
void testCDATA();
void testRawCharacters();
void testDefaultNamespace();
void testQNamespaces();
void testQNamespacesNested();
void testNamespaces();
void testNamespacesNested();
void testExplicitNamespaces();
void testWellformed();
void testWellformedNested();
void testWellformedNamespace();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // XMLWriterTest_INCLUDED