added CharacterData node tests

This commit is contained in:
jez_higgins 2005-08-30 11:58:54 +00:00
parent 8a90fc60d1
commit b72f67e044
5 changed files with 179 additions and 0 deletions

View file

@ -151,6 +151,9 @@
<File
RelativePath=".\test_CDATA.cpp">
</File>
<File
RelativePath=".\test_CharacterData.cpp">
</File>
<File
RelativePath=".\test_Document.cpp">
</File>
@ -188,6 +191,9 @@
<File
RelativePath=".\test_CDATA.hpp">
</File>
<File
RelativePath=".\test_CharacterData.hpp">
</File>
<File
RelativePath=".\test_Document.h">
</File>

View file

@ -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);

View file

@ -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<std::string>(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()

View file

@ -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 <DOM/Simple/DOMImplementation.h>
class CharacterDataTest : public TestCase
{
DOM::DOMImplementation<std::string> factory;
public:
CharacterDataTest(std::string name) :
TestCase(name)
{
} // CharacterDataTest
void setUp()
{
factory = SimpleDOM::DOMImplementation<std::string>::getDOMImplementation();
} // setUp
void testNull()
{
DOM::CharacterData<std::string> d;
DOM::Node<std::string> n;
assert(d == 0);
assert(n == 0);
assert(n == d);
} // testNull
void testCreateText()
{
DOM::Document<std::string> d = factory.createDocument("","", 0);
DOM::CharacterData<std::string> 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<std::string>::TEXT_NODE);
assert(t.hasAttributes() == false);
assert(t.getAttributes() == 0);
assert(t.getChildNodes() == 0);
assert(t.getFirstChild() == 0);
try
{
t.appendChild(DOM::Node<std::string>());
}
catch(const DOM::DOMException&)
{
}
assert(t.getFirstChild() == 0);
assert(t.getOwnerDocument() == d);
assert(t.getParentNode() == 0);
} // testCreateText
void testCreateCDATA()
{
DOM::Document<std::string> d = factory.createDocument("","", 0);
DOM::CharacterData<std::string> 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<std::string>::CDATA_SECTION_NODE);
assert(t.hasAttributes() == false);
assert(t.getAttributes() == 0);
assert(t.getChildNodes() == 0);
assert(t.getFirstChild() == 0);
try
{
t.appendChild(DOM::Node<std::string>());
}
catch(const DOM::DOMException&)
{
}
assert(t.getFirstChild() == 0);
assert(t.getOwnerDocument() == d);
assert(t.getParentNode() == 0);
} // testCreateCDATA
void testDownCasts()
{
DOM::Document<std::string> d = factory.createDocument("","", 0);
DOM::CDATASection<std::string> cd = d.createCDATASection("some data");
DOM::Text<std::string> t = cd;
DOM::CharacterData<std::string> c = t;
DOM::Node<std::string> n = c;
assert(c == cd);
assert(c == t);
assert(c == n);
assert(n == c);
assert(n == cd);
} // testDownCasts
void testTextUpCasts()
{
DOM::Document<std::string> d = factory.createDocument("","", 0);
DOM::Node<std::string> n = d.createTextNode("some data");
DOM::CharacterData<std::string> c = DOM::CharacterData<std::string>(n);
DOM::Text<std::string> t = DOM::Text<std::string>(c);
assert(c == t);
assert(c == n);
assert(n == c);
} // testTextUpCasts
void testCDATAUpCasts()
{
DOM::Document<std::string> d = factory.createDocument("","", 0);
DOM::Node<std::string> n = d.createCDATASection("some data");
DOM::CharacterData<std::string> c = DOM::CharacterData<std::string>(n);
DOM::Text<std::string> t = DOM::Text<std::string>(c);
DOM::CDATASection<std::string> cd = DOM::CDATASection<std::string>(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<CharacterDataTest>("testNull", &CharacterDataTest::testNull));
suiteOfTests->addTest(new TestCaller<CharacterDataTest>("testCreateText", &CharacterDataTest::testCreateText));
suiteOfTests->addTest(new TestCaller<CharacterDataTest>("testCreateCDATA", &CharacterDataTest::testCreateCDATA));
suiteOfTests->addTest(new TestCaller<CharacterDataTest>("testDownCasts", &CharacterDataTest::testDownCasts));
suiteOfTests->addTest(new TestCaller<CharacterDataTest>("testTextUpCasts", &CharacterDataTest::testTextUpCasts));
suiteOfTests->addTest(new TestCaller<CharacterDataTest>("testCDATAUpCasts", &CharacterDataTest::testCDATAUpCasts));
return suiteOfTests;
} // CharacterDataTest_suite

View file

@ -0,0 +1,6 @@
#ifndef ARABICA_TEST_SAX2DOM_CHARACTER_DATA_HPP
#define ARABICA_TEST_SAX2DOM_CHARACTER_DATA_HPP
TestSuite* CharacterDataTest_suite();
#endif