From b72f67e0440e356979770c88c84e4c78b2b849ce Mon Sep 17 00:00:00 2001 From: jez_higgins <> Date: Tue, 30 Aug 2005 11:58:54 +0000 Subject: [PATCH] added CharacterData node tests --- test/SAX2DOM/SAX2DOM_test.vcproj | 6 ++ test/SAX2DOM/main.cpp | 2 + test/SAX2DOM/test_CDATA.cpp | 9 ++ test/SAX2DOM/test_CharacterData.cpp | 156 ++++++++++++++++++++++++++++ test/SAX2DOM/test_CharacterData.hpp | 6 ++ 5 files changed, 179 insertions(+) create mode 100644 test/SAX2DOM/test_CharacterData.cpp create mode 100644 test/SAX2DOM/test_CharacterData.hpp diff --git a/test/SAX2DOM/SAX2DOM_test.vcproj b/test/SAX2DOM/SAX2DOM_test.vcproj index 6c8302f0..1b4edf70 100644 --- a/test/SAX2DOM/SAX2DOM_test.vcproj +++ b/test/SAX2DOM/SAX2DOM_test.vcproj @@ -151,6 +151,9 @@ + + @@ -188,6 +191,9 @@ + + diff --git a/test/SAX2DOM/main.cpp b/test/SAX2DOM/main.cpp index 11542d97..cdd02c4a 100644 --- a/test/SAX2DOM/main.cpp +++ b/test/SAX2DOM/main.cpp @@ -26,6 +26,7 @@ #include "test_SAX.h" #include "test_Text.hpp" #include "test_CDATA.hpp" +#include "test_CharacterData.hpp" class TestRunner { @@ -60,6 +61,7 @@ int main(int argc, char* argv[]) runner.addTest("ProcessingInstructionTest", ProcessingInstructionTest_suite()); runner.addTest("TextTest", TextTest_suite()); runner.addTest("CDATATest", CDATATest_suite()); + runner.addTest("CharacterDataText", CharacterDataTest_suite()); runner.addTest("DocumentFragmentTest", DocumentFragmentTest_suite()); runner.addTest("SAX2DOMTest", SAXTest_suite()); runner.run(argc, argv); diff --git a/test/SAX2DOM/test_CDATA.cpp b/test/SAX2DOM/test_CDATA.cpp index edbf0c36..909bca61 100644 --- a/test/SAX2DOM/test_CDATA.cpp +++ b/test/SAX2DOM/test_CDATA.cpp @@ -97,6 +97,15 @@ class CDATATest : public TestCase assert(t == cd2); assert(cd == cd2); assert(cd2 == cd); + + t = d.createTextNode("boom"); + try { + cd = DOM::CDATASection(t); + assertImplementation(false, "converted text to CDATA"); + } + catch(const std::bad_cast& ex) { + assertEquals(ex.what(), "Cannot convert Node to CDATA section"); + } } // testConversionToTest void testEverythingElse() diff --git a/test/SAX2DOM/test_CharacterData.cpp b/test/SAX2DOM/test_CharacterData.cpp new file mode 100644 index 00000000..20135e6b --- /dev/null +++ b/test/SAX2DOM/test_CharacterData.cpp @@ -0,0 +1,156 @@ +#ifdef _MSC_VER +#pragma warning(disable: 4786 4250 4503) +#endif +#include "../CppUnit/framework/TestCase.h" +#include "../CppUnit/framework/TestSuite.h" +#include "../CppUnit/framework/TestCaller.h" + +#include + +class CharacterDataTest : public TestCase +{ + DOM::DOMImplementation factory; + + public: + CharacterDataTest(std::string name) : + TestCase(name) + { + } // CharacterDataTest + + void setUp() + { + factory = SimpleDOM::DOMImplementation::getDOMImplementation(); + } // setUp + + void testNull() + { + DOM::CharacterData d; + DOM::Node n; + assert(d == 0); + assert(n == 0); + assert(n == d); + } // testNull + + void testCreateText() + { + DOM::Document d = factory.createDocument("","", 0); + DOM::CharacterData t = d.createTextNode("some data"); + + assert(t.getData() == "some data"); + assert(t.getNodeName() == "#text"); + assert(t.getNodeValue() == t.getData()); + + t.setData("newData"); + assert(t.getData() == "newData"); + + assert(t.getNodeType() == DOM::Node::TEXT_NODE); + assert(t.hasAttributes() == false); + assert(t.getAttributes() == 0); + assert(t.getChildNodes() == 0); + assert(t.getFirstChild() == 0); + + try + { + t.appendChild(DOM::Node()); + } + catch(const DOM::DOMException&) + { + } + + assert(t.getFirstChild() == 0); + + assert(t.getOwnerDocument() == d); + assert(t.getParentNode() == 0); + } // testCreateText + + void testCreateCDATA() + { + DOM::Document d = factory.createDocument("","", 0); + DOM::CharacterData t = d.createCDATASection("some data"); + + assert(t.getData() == "some data"); + assert(t.getNodeName() == "#cdata-section"); + assert(t.getNodeValue() == t.getData()); + + t.setData("newData"); + assert(t.getData() == "newData"); + + assert(t.getNodeType() == DOM::Node::CDATA_SECTION_NODE); + assert(t.hasAttributes() == false); + assert(t.getAttributes() == 0); + assert(t.getChildNodes() == 0); + assert(t.getFirstChild() == 0); + + try + { + t.appendChild(DOM::Node()); + } + catch(const DOM::DOMException&) + { + } + + assert(t.getFirstChild() == 0); + + assert(t.getOwnerDocument() == d); + assert(t.getParentNode() == 0); + } // testCreateCDATA + + void testDownCasts() + { + DOM::Document d = factory.createDocument("","", 0); + DOM::CDATASection cd = d.createCDATASection("some data"); + + DOM::Text t = cd; + DOM::CharacterData c = t; + + DOM::Node n = c; + + assert(c == cd); + assert(c == t); + assert(c == n); + assert(n == c); + assert(n == cd); + } // testDownCasts + + void testTextUpCasts() + { + DOM::Document d = factory.createDocument("","", 0); + DOM::Node n = d.createTextNode("some data"); + + DOM::CharacterData c = DOM::CharacterData(n); + DOM::Text t = DOM::Text(c); + + assert(c == t); + assert(c == n); + assert(n == c); + } // testTextUpCasts + + void testCDATAUpCasts() + { + DOM::Document d = factory.createDocument("","", 0); + DOM::Node n = d.createCDATASection("some data"); + + DOM::CharacterData c = DOM::CharacterData(n); + DOM::Text t = DOM::Text(c); + DOM::CDATASection cd = DOM::CDATASection(c); + + assert(c == cd); + assert(c == t); + assert(c == n); + assert(n == c); + assert(n == cd); + } // testCDATAUpCasts +}; + +TestSuite* CharacterDataTest_suite() +{ + TestSuite *suiteOfTests = new TestSuite; + suiteOfTests->addTest(new TestCaller("testNull", &CharacterDataTest::testNull)); + suiteOfTests->addTest(new TestCaller("testCreateText", &CharacterDataTest::testCreateText)); + suiteOfTests->addTest(new TestCaller("testCreateCDATA", &CharacterDataTest::testCreateCDATA)); + suiteOfTests->addTest(new TestCaller("testDownCasts", &CharacterDataTest::testDownCasts)); + suiteOfTests->addTest(new TestCaller("testTextUpCasts", &CharacterDataTest::testTextUpCasts)); + suiteOfTests->addTest(new TestCaller("testCDATAUpCasts", &CharacterDataTest::testCDATAUpCasts)); + return suiteOfTests; +} // CharacterDataTest_suite + diff --git a/test/SAX2DOM/test_CharacterData.hpp b/test/SAX2DOM/test_CharacterData.hpp new file mode 100644 index 00000000..d410670d --- /dev/null +++ b/test/SAX2DOM/test_CharacterData.hpp @@ -0,0 +1,6 @@ +#ifndef ARABICA_TEST_SAX2DOM_CHARACTER_DATA_HPP +#define ARABICA_TEST_SAX2DOM_CHARACTER_DATA_HPP + +TestSuite* CharacterDataTest_suite(); + +#endif \ No newline at end of file