arabica/tests/DOM/test_CharacterData.hpp

162 lines
6.4 KiB
C++
Raw Normal View History

2005-08-30 13:58:54 +02:00
#ifndef ARABICA_TEST_SAX2DOM_CHARACTER_DATA_HPP
#define ARABICA_TEST_SAX2DOM_CHARACTER_DATA_HPP
2005-10-24 23:59:44 +02:00
#include "../CppUnit/framework/TestCase.h"
#include "../CppUnit/framework/TestSuite.h"
#include "../CppUnit/framework/TestCaller.h"
2007-09-05 00:55:47 +02:00
#include <DOM/Simple/DOMImplementation.hpp>
2005-10-24 23:59:44 +02:00
template<class string_type, class string_adaptor>
class CharacterDataTest : public TestCase
{
Arabica::DOM::DOMImplementation<string_type, string_adaptor> factory;
2005-10-29 01:00:54 +02:00
typedef string_adaptor SA;
2005-10-24 23:59:44 +02:00
public:
CharacterDataTest(std::string name) :
TestCase(name)
{
} // CharacterDataTest
void setUp()
{
2007-09-05 13:47:13 +02:00
factory = Arabica::SimpleDOM::DOMImplementation<string_type, string_adaptor>::getDOMImplementation();
2005-10-24 23:59:44 +02:00
} // setUp
void testNull()
{
Arabica::DOM::CharacterData<string_type, string_adaptor> d;
Arabica::DOM::Node<string_type, string_adaptor> n;
2005-10-24 23:59:44 +02:00
assert(d == 0);
assert(n == 0);
assert(n == d);
} // testNull
void testCreateText()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
Arabica::DOM::CharacterData<string_type, string_adaptor> t = d.createTextNode(SA::construct_from_utf8("some data"));
2005-10-24 23:59:44 +02:00
2005-10-29 01:00:54 +02:00
assert(t.getData() == SA::construct_from_utf8("some data"));
assert(t.getNodeName() == SA::construct_from_utf8("#text"));
2005-10-24 23:59:44 +02:00
assert(t.getNodeValue() == t.getData());
2005-10-29 01:00:54 +02:00
t.setData(SA::construct_from_utf8("newData"));
assert(t.getData() == SA::construct_from_utf8("newData"));
2005-10-24 23:59:44 +02:00
assert(t.getNodeType() == Arabica::DOM::Node_base::TEXT_NODE);
2005-10-24 23:59:44 +02:00
assert(t.hasAttributes() == false);
assert(t.getAttributes() == 0);
assert(t.getChildNodes() == 0);
assert(t.getFirstChild() == 0);
try
{
t.appendChild(Arabica::DOM::Node<string_type, string_adaptor>());
2005-10-24 23:59:44 +02:00
}
2007-09-05 13:47:13 +02:00
catch(const Arabica::DOM::DOMException&)
2005-10-24 23:59:44 +02:00
{
}
assert(t.getFirstChild() == 0);
assert(t.getOwnerDocument() == d);
assert(t.getParentNode() == 0);
} // testCreateText
void testCreateCDATA()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
Arabica::DOM::CharacterData<string_type, string_adaptor> t = d.createCDATASection(SA::construct_from_utf8("some data"));
2005-10-24 23:59:44 +02:00
2005-10-29 01:00:54 +02:00
assert(t.getData() == SA::construct_from_utf8("some data"));
assert(t.getNodeName() == SA::construct_from_utf8("#cdata-section"));
2005-10-24 23:59:44 +02:00
assert(t.getNodeValue() == t.getData());
2005-10-29 01:00:54 +02:00
t.setData(SA::construct_from_utf8("newData"));
assert(t.getData() == SA::construct_from_utf8("newData"));
2005-10-24 23:59:44 +02:00
assert(t.getNodeType() == Arabica::DOM::Node_base::CDATA_SECTION_NODE);
2005-10-24 23:59:44 +02:00
assert(t.hasAttributes() == false);
assert(t.getAttributes() == 0);
assert(t.getChildNodes() == 0);
assert(t.getFirstChild() == 0);
try
{
t.appendChild(Arabica::DOM::Node<string_type, string_adaptor>());
2005-10-24 23:59:44 +02:00
}
2007-09-05 13:47:13 +02:00
catch(const Arabica::DOM::DOMException&)
2005-10-24 23:59:44 +02:00
{
}
assert(t.getFirstChild() == 0);
assert(t.getOwnerDocument() == d);
assert(t.getParentNode() == 0);
} // testCreateCDATA
void testDownCasts()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
Arabica::DOM::CDATASection<string_type, string_adaptor> cd = d.createCDATASection(SA::construct_from_utf8("some data"));
2005-10-24 23:59:44 +02:00
Arabica::DOM::Text<string_type, string_adaptor> t = cd;
Arabica::DOM::CharacterData<string_type, string_adaptor> c = t;
2005-10-24 23:59:44 +02:00
Arabica::DOM::Node<string_type, string_adaptor> n = c;
2005-10-24 23:59:44 +02:00
assert(c == cd);
assert(c == t);
assert(c == n);
assert(n == c);
assert(n == cd);
} // testDownCasts
void testTextUpCasts()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
Arabica::DOM::Node<string_type, string_adaptor> n = d.createTextNode(SA::construct_from_utf8("some data"));
2005-10-24 23:59:44 +02:00
Arabica::DOM::CharacterData<string_type, string_adaptor> c = Arabica::DOM::CharacterData<string_type, string_adaptor>(n);
Arabica::DOM::Text<string_type, string_adaptor> t = Arabica::DOM::Text<string_type, string_adaptor>(c);
2005-10-24 23:59:44 +02:00
assert(c == t);
assert(c == n);
assert(n == c);
} // testTextUpCasts
void testCDATAUpCasts()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
Arabica::DOM::Node<string_type, string_adaptor> n = d.createCDATASection(SA::construct_from_utf8("some data"));
2005-10-24 23:59:44 +02:00
Arabica::DOM::CharacterData<string_type, string_adaptor> c = Arabica::DOM::CharacterData<string_type, string_adaptor>(n);
Arabica::DOM::Text<string_type, string_adaptor> t = Arabica::DOM::Text<string_type, string_adaptor>(c);
Arabica::DOM::CDATASection<string_type, string_adaptor> cd = Arabica::DOM::CDATASection<string_type, string_adaptor>(c);
2005-10-24 23:59:44 +02:00
assert(c == cd);
assert(c == t);
assert(c == n);
assert(n == c);
assert(n == cd);
} // testCDATAUpCasts
};
template<class string_type, class string_adaptor>
TestSuite* CharacterDataTest_suite()
{
TestSuite *suiteOfTests = new TestSuite;
suiteOfTests->addTest(new TestCaller<CharacterDataTest<string_type, string_adaptor> >("testNull", &CharacterDataTest<string_type, string_adaptor>::testNull));
suiteOfTests->addTest(new TestCaller<CharacterDataTest<string_type, string_adaptor> >("testCreateText", &CharacterDataTest<string_type, string_adaptor>::testCreateText));
suiteOfTests->addTest(new TestCaller<CharacterDataTest<string_type, string_adaptor> >("testCreateCDATA", &CharacterDataTest<string_type, string_adaptor>::testCreateCDATA));
suiteOfTests->addTest(new TestCaller<CharacterDataTest<string_type, string_adaptor> >("testDownCasts", &CharacterDataTest<string_type, string_adaptor>::testDownCasts));
suiteOfTests->addTest(new TestCaller<CharacterDataTest<string_type, string_adaptor> >("testTextUpCasts", &CharacterDataTest<string_type, string_adaptor>::testTextUpCasts));
suiteOfTests->addTest(new TestCaller<CharacterDataTest<string_type, string_adaptor> >("testCDATAUpCasts", &CharacterDataTest<string_type, string_adaptor>::testCDATAUpCasts));
return suiteOfTests;
} // CharacterDataTest_suite
2005-08-30 13:58:54 +02:00
2005-10-31 13:07:30 +01:00
#endif