#ifndef test_Attr_H #define test_Attr_H #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class AttrTest : public TestCase { Arabica::DOM::DOMImplementation factory; typedef string_adaptor SA; public: AttrTest(std::string name) : TestCase(name) { } // AttrTest void setUp() { factory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); } // setUp void test1() { Arabica::DOM::Attr d; Arabica::DOM::Node n; assert(d == 0); assert(n == 0); assert(n == d); } // test1 void test2() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttribute(SA::construct_from_utf8("attr")); 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("")); assert(attr.hasNamespaceURI() == false); assert(attr.hasPrefix() == false); } // test2 void test3() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8("http://attr"), SA::construct_from_utf8("attr:value")); 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")); assert(attr.hasNamespaceURI() == true); assert(attr.hasPrefix() == true); } // test3 void test4() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8("http://attr"), SA::construct_from_utf8("attr")); 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("")); assert(attr.hasNamespaceURI() == true); assert(attr.hasPrefix() == false); } // test4 void test5() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8("http://attr"), SA::construct_from_utf8("attr:value")); 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")); assert(attr.hasNamespaceURI() == true); assert(attr.hasPrefix() == true); } // test5 void test6() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8("http://attr"), SA::construct_from_utf8("value")); 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")); assert(attr.hasNamespaceURI() == true); assert(attr.hasPrefix() == true); } // test6 void test7() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8("http://www.w3.org/2000/xmlns/"), SA::construct_from_utf8("xmlns")); 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); } // test7 void test8() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr; try { attr = d.createAttributeNS(SA::construct_from_utf8("ppopopop"), SA::construct_from_utf8("xmlns")); } catch(const Arabica::DOM::DOMException&) { } assert(attr == 0); } // test8 void test9() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr; try { attr = d.createAttributeNS(SA::construct_from_utf8("ahuafh"), SA::construct_from_utf8("xmlns:billy")); } catch(const Arabica::DOM::DOMException&) { } assert(attr == 0); } // test9 void test10() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8("http://www.w3.org/2000/xmlns/"), SA::construct_from_utf8("nothing:much")); try { attr.setPrefix(SA::construct_from_utf8("xmlns")); } catch(const Arabica::DOM::DOMException&) { } assert(attr.getPrefix() == SA::construct_from_utf8("xmlns")); } // test10 void test11() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8("charles"), SA::construct_from_utf8("nothing:much")); try { attr.setPrefix(SA::construct_from_utf8("xmlns")); } catch(const Arabica::DOM::DOMException&) { } assert(attr.getPrefix() == SA::construct_from_utf8("nothing")); } // test11 void test12() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8(""), SA::construct_from_utf8("much")); try { attr.setPrefix(SA::construct_from_utf8("charles")); } catch(const Arabica::DOM::DOMException&) { } assert(attr.hasPrefix() == false); } // test12 void test13() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr; try { attr = d.createAttributeNS(SA::construct_from_utf8(""), SA::construct_from_utf8("trouser:pants")); } catch(const Arabica::DOM::DOMException&) { } assert(attr == 0); } // test13 void test14() { Arabica::DOM::Document d = factory.createDocument(SA::construct_from_utf8(""),SA::construct_from_utf8(""), 0); Arabica::DOM::Attr attr = d.createAttributeNS(SA::construct_from_utf8("http://www.w3.org/2000/xmlns/"), SA::construct_from_utf8("xmlns")); 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 }; template TestSuite* AttrTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("test1", &AttrTest::test1)); suiteOfTests->addTest(new TestCaller >("test2", &AttrTest::test2)); suiteOfTests->addTest(new TestCaller >("test3", &AttrTest::test3)); suiteOfTests->addTest(new TestCaller >("test4", &AttrTest::test4)); suiteOfTests->addTest(new TestCaller >("test5", &AttrTest::test5)); suiteOfTests->addTest(new TestCaller >("test6", &AttrTest::test6)); suiteOfTests->addTest(new TestCaller >("test7", &AttrTest::test7)); suiteOfTests->addTest(new TestCaller >("test8", &AttrTest::test8)); suiteOfTests->addTest(new TestCaller >("test9", &AttrTest::test9)); suiteOfTests->addTest(new TestCaller >("test10", &AttrTest::test10)); suiteOfTests->addTest(new TestCaller >("test11", &AttrTest::test11)); suiteOfTests->addTest(new TestCaller >("test12", &AttrTest::test12)); suiteOfTests->addTest(new TestCaller >("test13", &AttrTest::test13)); suiteOfTests->addTest(new TestCaller >("test14", &AttrTest::test14)); return suiteOfTests; } // AttrTest_suite #endif