2002-06-21 13:16:28 +02:00
|
|
|
#ifndef test_Attr_H
|
|
|
|
#define test_Attr_H
|
|
|
|
|
2005-10-23 23:22:38 +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-23 23:22:38 +02:00
|
|
|
|
|
|
|
template<class string_type, class string_adaptor>
|
|
|
|
class AttrTest : public TestCase
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::DOMImplementation<string_type, string_adaptor> factory;
|
2005-10-29 20:19:33 +02:00
|
|
|
typedef string_adaptor SA;
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
AttrTest(std::string name) :
|
|
|
|
TestCase(name)
|
|
|
|
{
|
|
|
|
} // AttrTest
|
|
|
|
|
|
|
|
void setUp()
|
|
|
|
{
|
2007-09-05 13:47:13 +02:00
|
|
|
factory = Arabica::SimpleDOM::DOMImplementation<string_type, string_adaptor>::getDOMImplementation();
|
2005-10-23 23:22:38 +02:00
|
|
|
} // setUp
|
|
|
|
|
|
|
|
void test1()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> d;
|
|
|
|
Arabica::DOM::Node<string_type, string_adaptor> n;
|
2005-10-23 23:22:38 +02:00
|
|
|
assert(d == 0);
|
|
|
|
assert(n == 0);
|
|
|
|
assert(n == d);
|
|
|
|
} // test1
|
|
|
|
|
|
|
|
void test2()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttribute(SA::construct_from_utf8("attr"));
|
2005-10-29 20:19:33 +02:00
|
|
|
assert(attr.getName() == SA::construct_from_utf8("attr"));
|
|
|
|
assert(attr.getNodeName() == SA::construct_from_utf8("attr"));
|
|
|
|
assert(attr.getLocalName() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getNamespaceURI() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8(""));
|
2005-10-23 23:22:38 +02:00
|
|
|
assert(attr.hasNamespaceURI() == false);
|
|
|
|
assert(attr.hasPrefix() == false);
|
|
|
|
} // test2
|
|
|
|
|
|
|
|
void test3()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8("http://attr"), SA::construct_from_utf8("attr:value"));
|
2005-10-29 20:19:33 +02:00
|
|
|
assert(attr.getName() == SA::construct_from_utf8("attr:value"));
|
|
|
|
assert(attr.getValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getNodeName() == SA::construct_from_utf8("attr:value"));
|
|
|
|
assert(attr.getNodeValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getLocalName() == SA::construct_from_utf8("value"));
|
|
|
|
assert(attr.getNamespaceURI() == SA::construct_from_utf8("http://attr"));
|
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8("attr"));
|
2005-10-23 23:22:38 +02:00
|
|
|
assert(attr.hasNamespaceURI() == true);
|
|
|
|
assert(attr.hasPrefix() == true);
|
|
|
|
} // test3
|
|
|
|
|
|
|
|
void test4()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8("http://attr"), SA::construct_from_utf8("attr"));
|
2005-10-29 20:19:33 +02:00
|
|
|
assert(attr.getName() == SA::construct_from_utf8("attr"));
|
|
|
|
assert(attr.getValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getNodeName() == SA::construct_from_utf8("attr"));
|
|
|
|
assert(attr.getNodeValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getLocalName() == SA::construct_from_utf8("attr"));
|
|
|
|
assert(attr.getNamespaceURI() == SA::construct_from_utf8("http://attr"));
|
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8(""));
|
2005-10-23 23:22:38 +02:00
|
|
|
assert(attr.hasNamespaceURI() == true);
|
|
|
|
assert(attr.hasPrefix() == false);
|
|
|
|
} // test4
|
|
|
|
|
|
|
|
void test5()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8("http://attr"), SA::construct_from_utf8("attr:value"));
|
2005-10-29 20:19:33 +02:00
|
|
|
|
|
|
|
attr.setPrefix(SA::construct_from_utf8("monkey"));
|
|
|
|
assert(attr.getName() == SA::construct_from_utf8("monkey:value"));
|
|
|
|
assert(attr.getValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getNodeName() == SA::construct_from_utf8("monkey:value"));
|
|
|
|
assert(attr.getNodeValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getLocalName() == SA::construct_from_utf8("value"));
|
|
|
|
assert(attr.getNamespaceURI() == SA::construct_from_utf8("http://attr"));
|
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8("monkey"));
|
2005-10-23 23:22:38 +02:00
|
|
|
assert(attr.hasNamespaceURI() == true);
|
|
|
|
assert(attr.hasPrefix() == true);
|
|
|
|
} // test5
|
|
|
|
|
|
|
|
void test6()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8("http://attr"), SA::construct_from_utf8("value"));
|
2005-10-29 20:19:33 +02:00
|
|
|
|
|
|
|
attr.setPrefix(SA::construct_from_utf8("monkey"));
|
|
|
|
assert(attr.getName() == SA::construct_from_utf8("monkey:value"));
|
|
|
|
assert(attr.getValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getNodeName() == SA::construct_from_utf8("monkey:value"));
|
|
|
|
assert(attr.getNodeValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getLocalName() == SA::construct_from_utf8("value"));
|
|
|
|
assert(attr.getNamespaceURI() == SA::construct_from_utf8("http://attr"));
|
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8("monkey"));
|
2005-10-23 23:22:38 +02:00
|
|
|
assert(attr.hasNamespaceURI() == true);
|
|
|
|
assert(attr.hasPrefix() == true);
|
|
|
|
} // test6
|
|
|
|
|
|
|
|
void test7()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8("http://www.w3.org/2000/xmlns/"), SA::construct_from_utf8("xmlns"));
|
2005-10-29 20:19:33 +02:00
|
|
|
|
|
|
|
assert(attr.getName() == SA::construct_from_utf8("xmlns"));
|
|
|
|
assert(attr.getValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getNodeName() == SA::construct_from_utf8("xmlns"));
|
|
|
|
assert(attr.getNodeValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getLocalName() == SA::construct_from_utf8("xmlns"));
|
|
|
|
assert(attr.getNamespaceURI() == SA::construct_from_utf8("http://www.w3.org/2000/xmlns/"));
|
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8(""));
|
2005-10-23 23:22:38 +02:00
|
|
|
assert(attr.hasNamespaceURI() == true);
|
|
|
|
assert(attr.hasPrefix() == false);
|
|
|
|
} // test7
|
|
|
|
|
|
|
|
void test8()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr;
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
try {
|
2005-10-29 20:19:33 +02:00
|
|
|
attr = d.createAttributeNS(SA::construct_from_utf8("ppopopop"), SA::construct_from_utf8("xmlns"));
|
2005-10-23 23:22:38 +02:00
|
|
|
}
|
2007-09-05 13:47:13 +02:00
|
|
|
catch(const Arabica::DOM::DOMException&) { }
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
assert(attr == 0);
|
|
|
|
} // test8
|
|
|
|
|
|
|
|
void test9()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr;
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
try {
|
2005-10-29 20:19:33 +02:00
|
|
|
attr = d.createAttributeNS(SA::construct_from_utf8("ahuafh"), SA::construct_from_utf8("xmlns:billy"));
|
2005-10-23 23:22:38 +02:00
|
|
|
}
|
2007-09-05 13:47:13 +02:00
|
|
|
catch(const Arabica::DOM::DOMException&) { }
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
assert(attr == 0);
|
|
|
|
} // test9
|
|
|
|
|
|
|
|
void test10()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8("http://www.w3.org/2000/xmlns/"), SA::construct_from_utf8("nothing:much"));
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
try {
|
2005-10-29 20:19:33 +02:00
|
|
|
attr.setPrefix(SA::construct_from_utf8("xmlns"));
|
2005-10-23 23:22:38 +02:00
|
|
|
}
|
2007-09-05 13:47:13 +02:00
|
|
|
catch(const Arabica::DOM::DOMException&) { }
|
2005-10-23 23:22:38 +02:00
|
|
|
|
2005-10-29 20:19:33 +02:00
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8("xmlns"));
|
2005-10-23 23:22:38 +02:00
|
|
|
} // test10
|
|
|
|
|
|
|
|
void test11()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8("charles"), SA::construct_from_utf8("nothing:much"));
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
try {
|
2005-10-29 20:19:33 +02:00
|
|
|
attr.setPrefix(SA::construct_from_utf8("xmlns"));
|
2005-10-23 23:22:38 +02:00
|
|
|
}
|
2007-09-05 13:47:13 +02:00
|
|
|
catch(const Arabica::DOM::DOMException&) { }
|
2005-10-23 23:22:38 +02:00
|
|
|
|
2005-10-29 20:19:33 +02:00
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8("nothing"));
|
2005-10-23 23:22:38 +02:00
|
|
|
} // test11
|
|
|
|
|
|
|
|
void test12()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8(""), SA::construct_from_utf8("much"));
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
try {
|
2005-10-29 20:19:33 +02:00
|
|
|
attr.setPrefix(SA::construct_from_utf8("charles"));
|
2005-10-23 23:22:38 +02:00
|
|
|
}
|
2007-09-05 13:47:13 +02:00
|
|
|
catch(const Arabica::DOM::DOMException&) { }
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
assert(attr.hasPrefix() == false);
|
|
|
|
} // test12
|
|
|
|
|
|
|
|
void test13()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr;
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
try {
|
2005-10-29 20:19:33 +02:00
|
|
|
attr = d.createAttributeNS(SA::construct_from_utf8(""), SA::construct_from_utf8("trouser:pants"));
|
2005-10-23 23:22:38 +02:00
|
|
|
}
|
2007-09-05 13:47:13 +02:00
|
|
|
catch(const Arabica::DOM::DOMException&) { }
|
2005-10-23 23:22:38 +02:00
|
|
|
|
|
|
|
assert(attr == 0);
|
|
|
|
} // test13
|
|
|
|
|
2006-12-14 12:51:23 +01:00
|
|
|
void test14()
|
|
|
|
{
|
2007-09-08 01:52:30 +02:00
|
|
|
Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0);
|
|
|
|
Arabica::DOM::Attr<string_type, string_adaptor> attr = d.createAttributeNS(SA::construct_from_utf8("http://www.w3.org/2000/xmlns/"), SA::construct_from_utf8("xmlns"));
|
2006-12-14 12:51:23 +01:00
|
|
|
|
|
|
|
assert(attr.getName() == SA::construct_from_utf8("xmlns"));
|
|
|
|
assert(attr.getValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getNodeName() == SA::construct_from_utf8("xmlns"));
|
|
|
|
assert(attr.getNodeValue() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.getLocalName() == SA::construct_from_utf8("xmlns"));
|
|
|
|
assert(attr.getNamespaceURI() == SA::construct_from_utf8("http://www.w3.org/2000/xmlns/"));
|
|
|
|
assert(attr.getPrefix() == SA::construct_from_utf8(""));
|
|
|
|
assert(attr.hasNamespaceURI() == true);
|
|
|
|
assert(attr.hasPrefix() == false);
|
|
|
|
|
|
|
|
string_type norb = SA::construct_from_utf8("norb");
|
|
|
|
attr.setValue(norb);
|
|
|
|
assert(attr.getValue() == norb);
|
|
|
|
assert(attr.getNodeValue() == norb);
|
|
|
|
|
|
|
|
string_type porg = SA::construct_from_utf8("porg");
|
|
|
|
attr.setNodeValue(porg);
|
|
|
|
assert(attr.getValue() == porg);
|
|
|
|
assert(attr.getNodeValue() == porg);
|
|
|
|
} // test14
|
|
|
|
|
2005-10-23 23:22:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class string_type, class string_adaptor>
|
|
|
|
TestSuite* AttrTest_suite()
|
|
|
|
{
|
|
|
|
TestSuite *suiteOfTests = new TestSuite;
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test1", &AttrTest<string_type, string_adaptor>::test1));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test2", &AttrTest<string_type, string_adaptor>::test2));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test3", &AttrTest<string_type, string_adaptor>::test3));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test4", &AttrTest<string_type, string_adaptor>::test4));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test5", &AttrTest<string_type, string_adaptor>::test5));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test6", &AttrTest<string_type, string_adaptor>::test6));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test7", &AttrTest<string_type, string_adaptor>::test7));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test8", &AttrTest<string_type, string_adaptor>::test8));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test9", &AttrTest<string_type, string_adaptor>::test9));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test10", &AttrTest<string_type, string_adaptor>::test10));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test11", &AttrTest<string_type, string_adaptor>::test11));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test12", &AttrTest<string_type, string_adaptor>::test12));
|
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test13", &AttrTest<string_type, string_adaptor>::test13));
|
2006-12-14 12:51:23 +01:00
|
|
|
suiteOfTests->addTest(new TestCaller<AttrTest<string_type, string_adaptor> >("test14", &AttrTest<string_type, string_adaptor>::test14));
|
2005-10-23 23:22:38 +02:00
|
|
|
return suiteOfTests;
|
|
|
|
} // AttrTest_suite
|
|
|
|
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|