arabica/tests/DOM/test_ProcessingInstruction.hpp

115 lines
4.1 KiB
C++
Raw Permalink Normal View History

2002-06-21 13:16:28 +02:00
#ifndef test_PI_H
#define test_PI_H
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 PITest : 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:
PITest(std::string name) :
TestCase(name)
{
} // PITest
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::ProcessingInstruction<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 testCreate()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> p = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data"));
2005-10-24 23:59:44 +02:00
2005-10-29 01:00:54 +02:00
assert(p.getTarget() == SA::construct_from_utf8("target"));
assert(p.getData() == SA::construct_from_utf8("data"));
2005-10-24 23:59:44 +02:00
assert(p.getNodeName() == p.getTarget());
assert(p.getNodeValue() == p.getData());
2005-10-29 01:00:54 +02:00
p.setData(SA::construct_from_utf8("newData"));
assert(p.getData() == SA::construct_from_utf8("newData"));
2005-10-24 23:59:44 +02:00
} // testCreate
void testConversion()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> pi = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data"));
2005-10-24 23:59:44 +02:00
Arabica::DOM::Node<string_type, string_adaptor> n;
2005-10-24 23:59:44 +02:00
assert(n != pi);
n = pi;
assert(n == pi);
Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> pi2;
2005-10-24 23:59:44 +02:00
assert(n != pi2);
pi2 = Arabica::DOM::ProcessingInstruction<string_type, string_adaptor>(n);
2005-10-24 23:59:44 +02:00
assert(pi == pi2);
assert(n == pi2);
} // testConverstion
void testEverythingElse()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> pi = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data"));
2005-10-24 23:59:44 +02:00
assert(pi.getNodeType() == Arabica::DOM::Node_base::PROCESSING_INSTRUCTION_NODE);
2005-10-24 23:59:44 +02:00
assert(pi.hasAttributes() == false);
assert(pi.getAttributes() == 0);
assert(pi.getChildNodes() == 0);
assert(pi.getFirstChild() == 0);
try
{
pi.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(pi.getFirstChild() == 0);
assert(pi.getOwnerDocument() == d);
assert(pi.getParentNode() == 0);
d.appendChild(pi);
assert(pi.getOwnerDocument() == d);
assert(pi.getParentNode() == d);
assert(d.getFirstChild() == pi);
} // testEverythingElse
}; // class PITest
template<class string_type, class string_adaptor>
TestSuite* ProcessingInstructionTest_suite()
{
TestSuite *suiteOfTests = new TestSuite;
suiteOfTests->addTest(new TestCaller<PITest<string_type, string_adaptor> >("testNull", &PITest<string_type, string_adaptor>::testNull));
suiteOfTests->addTest(new TestCaller<PITest<string_type, string_adaptor> >("testCreate", &PITest<string_type, string_adaptor>::testCreate));
suiteOfTests->addTest(new TestCaller<PITest<string_type, string_adaptor> >("testConversion", &PITest<string_type, string_adaptor>::testConversion));
suiteOfTests->addTest(new TestCaller<PITest<string_type, string_adaptor> >("testEverythingElse", &PITest<string_type, string_adaptor>::testEverythingElse));
return suiteOfTests;
} // ProcessingInstructionTest_suite
2002-06-21 13:16:28 +02:00
#endif