arabica/tests/DOM/test_Siblings.hpp

196 lines
7.3 KiB
C++
Raw Permalink Normal View History

2002-06-21 13:16:28 +02:00
#ifndef test_Siblings_H
#define test_Siblings_H
2005-10-26 22:52:48 +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-26 22:52:48 +02:00
template<class string_type, class string_adaptor>
class SiblingsTest : public TestCase
{
Arabica::DOM::DOMImplementation<string_type, string_adaptor> factory;
2005-10-31 13:07:30 +01:00
typedef string_adaptor SA;
2005-10-26 22:52:48 +02:00
public:
SiblingsTest(std::string name) :
TestCase(name)
{
} // SiblingsTest
void setUp()
{
2007-09-05 13:47:13 +02:00
factory = Arabica::SimpleDOM::DOMImplementation<string_type, string_adaptor>::getDOMImplementation();
2005-10-26 22:52:48 +02:00
} // setUp
void test1()
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
Arabica::DOM::Element<string_type, string_adaptor> root = d.createElement(SA::construct_from_utf8("root"));
2005-10-26 22:52:48 +02:00
d.appendChild(root);
assert(root.getPreviousSibling() == 0);
assert(root.getNextSibling() == 0);
Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> p = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data"));
2005-10-26 22:52:48 +02:00
d.insertBefore(p, root);
assert(d.getFirstChild() == p);
assert(d.getLastChild() == root);
assert(p.getPreviousSibling() == 0);
assert(p.getNextSibling() == root);
assert(root.getPreviousSibling() == p);
assert(root.getNextSibling() == 0);
Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> p2 = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data"));
2005-10-26 22:52:48 +02:00
d.insertBefore(p2, root);
assert(d.getFirstChild() == p);
assert(d.getLastChild() == root);
assert(p.getPreviousSibling() == 0);
assert(p.getNextSibling() == p2);
assert(p2.getPreviousSibling() == p);
assert(p2.getNextSibling() == root);
assert(root.getPreviousSibling() == p2);
assert(root.getNextSibling() == 0);
d.removeChild(p2);
assert(d.getFirstChild() == p);
assert(d.getLastChild() == root);
assert(p.getPreviousSibling() == 0);
assert(p.getNextSibling() == root);
assert(p2.getPreviousSibling() == 0);
assert(p2.getNextSibling() == 0);
assert(root.getPreviousSibling() == p);
assert(root.getNextSibling() == 0);
d.insertBefore(p2, root);
assert(d.getFirstChild() == p);
assert(d.getLastChild() == root);
assert(p.getPreviousSibling() == 0);
assert(p.getNextSibling() == p2);
assert(p2.getPreviousSibling() == p);
assert(p2.getNextSibling() == root);
assert(root.getPreviousSibling() == p2);
assert(root.getNextSibling() == 0);
d.removeChild(p);
assert(d.getFirstChild() == p2);
assert(d.getLastChild() == root);
assert(p.getPreviousSibling() == 0);
assert(p.getNextSibling() == 0);
assert(p2.getPreviousSibling() == 0);
assert(p2.getNextSibling() == root);
assert(root.getPreviousSibling() == p2);
assert(root.getNextSibling() == 0);
d.replaceChild(p, p2);
assert(d.getFirstChild() == p);
assert(d.getLastChild() == root);
assert(p.getPreviousSibling() == 0);
assert(p.getNextSibling() == root);
assert(p2.getPreviousSibling() == 0);
assert(p2.getNextSibling() == 0);
assert(root.getPreviousSibling() == p);
assert(root.getNextSibling() == 0);
d.appendChild(p2);
assert(d.getFirstChild() == p);
assert(d.getLastChild() == p2);
assert(p.getPreviousSibling() == 0);
assert(p.getNextSibling() == root);
assert(root.getPreviousSibling() == p);
assert(root.getNextSibling() == p2);
assert(p2.getPreviousSibling() == root);
assert(p2.getNextSibling() == 0);
} // test1
void test2()
{
Arabica::DOM::Element<string_type, string_adaptor> root;
2005-10-26 22:52:48 +02:00
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
2005-10-31 13:07:30 +01:00
root = d.createElement(SA::construct_from_utf8("root"));
2005-10-26 22:52:48 +02:00
d.appendChild(root);
assert(root.getPreviousSibling() == 0);
assert(root.getNextSibling() == 0);
Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> p = d.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data"));
2005-10-26 22:52:48 +02:00
d.insertBefore(p, root);
}
Arabica::DOM::Node<string_type, string_adaptor> n = root.getPreviousSibling();
Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> p = Arabica::DOM::ProcessingInstruction<string_type, string_adaptor>(n);
2005-10-31 13:07:30 +01:00
assert(p.getTarget() == SA::construct_from_utf8("target"));
assert(p.getData() == SA::construct_from_utf8("data"));
2005-10-26 22:52:48 +02:00
} // test2
2005-11-25 23:39:16 +01:00
void test3()
{
Arabica::DOM::Element<string_type, string_adaptor> root;
2005-11-25 23:39:16 +01:00
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
2005-11-25 23:39:16 +01:00
root = d.createElement(SA::construct_from_utf8("root"));
d.appendChild(root);
root.appendChild(d.createElement(SA::construct_from_utf8("child1")));
root.appendChild(d.createElement(SA::construct_from_utf8("child2")));
}
Arabica::DOM::Node<string_type, string_adaptor> c = root.getFirstChild();
2005-11-25 23:39:16 +01:00
assert(c.getNextSibling() == root.getLastChild());
root.purgeChild(c);
assert(c == 0);
assert(root.getLastChild() == root.getFirstChild());
} // test3
void test4()
{
Arabica::DOM::Element<string_type, string_adaptor> root;
2005-11-25 23:39:16 +01:00
{
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
2005-11-25 23:39:16 +01:00
root = d.createElement(SA::construct_from_utf8("root"));
d.appendChild(root);
root.appendChild(d.createElement(SA::construct_from_utf8("child1")));
root.appendChild(d.createElement(SA::construct_from_utf8("child2")));
}
Arabica::DOM::Node<string_type, string_adaptor> c1 = root.getFirstChild();
Arabica::DOM::Node<string_type, string_adaptor> c2 = root.getLastChild();
2005-11-25 23:39:16 +01:00
try {
c1.purgeChild(c2);
}
2007-09-05 13:47:13 +02:00
catch(Arabica::DOM::DOMException& e)
2005-11-25 23:39:16 +01:00
{
2007-09-05 13:47:13 +02:00
assert(e.code() == Arabica::DOM::DOMException::NOT_FOUND_ERR);
2005-11-25 23:39:16 +01:00
} // catch
assert(c1 != 0);
assert(c2 != 0);
assert(c1.getNextSibling() == c2);
assert(c2.getPreviousSibling() == c1);
} // test4
2005-10-26 22:52:48 +02:00
};
template<class string_type, class string_adaptor>
TestSuite* SiblingsTest_suite()
{
TestSuite *suiteOfTests = new TestSuite;
2005-11-25 23:39:16 +01:00
2005-10-26 22:52:48 +02:00
suiteOfTests->addTest(new TestCaller<SiblingsTest<string_type, string_adaptor> >("test1", &SiblingsTest<string_type, string_adaptor>::test1));
suiteOfTests->addTest(new TestCaller<SiblingsTest<string_type, string_adaptor> >("test2", &SiblingsTest<string_type, string_adaptor>::test2));
2005-11-25 23:39:16 +01:00
suiteOfTests->addTest(new TestCaller<SiblingsTest<string_type, string_adaptor> >("test3", &SiblingsTest<string_type, string_adaptor>::test3));
suiteOfTests->addTest(new TestCaller<SiblingsTest<string_type, string_adaptor> >("test4", &SiblingsTest<string_type, string_adaptor>::test4));
2005-10-26 22:52:48 +02:00
return suiteOfTests;
} // SiblingsTest_suite
2002-06-21 13:16:28 +02:00
#endif