#ifdef _MSC_VER #pragma warning(disable: 4786 4250 4503) #endif #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include #include class SAXTest : public TestCase { public: SAXTest(std::string name) : TestCase(name) { } // SAXTest void setUp() { } // setUp DOM::Document parse(std::string str) { std::stringstream ss; ss << str; SAX::InputSource is(ss); SAX2DOM::Parser parser; parser.parse(is); return parser.getDocument(); } // parse void test1() { DOM::Element d; DOM::Node n; assert(d == 0); assert(n == 0); assert(n == d); } // test1 void test2() { DOM::Document d = parse(""); DOM::Element elem = d.getDocumentElement(); assert(elem.getParentNode() == d); assert(elem.getOwnerDocument() == d); } // test2 void test3() { DOM::Document d = parse(""); DOM::Element elem = d.getDocumentElement(); assert(elem.hasAttributes() == true); assert(elem.getAttribute("attr") == "poop"); } // test3 void test4() { DOM::Document d = parse(""); DOM::Element elem = DOM::Element(d.getDocumentElement().getFirstChild()); assertEquals("child", elem.getNodeName()); assertEquals(true, elem.hasAttributes()); assertEquals("poop", elem.getAttribute("attr")); } // test4 void test5() { DOM::Document d = parse(""); DOM::Element elem = d.getDocumentElement(); assertEquals(true, elem.hasNamespaceURI()); assertEquals("http://example.com/stuff", elem.getNamespaceURI()); DOM::Attr attr = elem.getAttributeNode("attr"); assertEquals(false, attr.hasNamespaceURI()); } // test5 void test6() { DOM::Document d = parse(""); DOM::Element elem = d.getDocumentElement(); assertEquals(true, elem.hasNamespaceURI()); assertEquals("http://example.com/stuff", elem.getNamespaceURI()); DOM::Attr attr = elem.getAttributeNodeNS("http://example.com/stuff", "attr"); assertEquals(true, attr.hasNamespaceURI()); assertEquals("http://example.com/stuff", attr.getNamespaceURI()); } // test6 void test7() { DOM::Document d = parse(""); DOM::Element elem = d.getDocumentElement(); assertEquals(false, elem.hasNamespaceURI()); DOM::Attr attr = elem.getAttributeNodeNS("http://example.com/stuff", "attr"); assertEquals(true, attr.hasNamespaceURI()); assertEquals("http://example.com/stuff", attr.getNamespaceURI()); } // test7 void test8() { DOM::Document d = parse(""); DOM::Element elem = d.getDocumentElement(); DOM::Element e2 = DOM::Element(elem.cloneNode(true)); assert(e2.getOwnerDocument() == d); assert(e2.getParentNode() == 0); assert(e2.hasAttributes() == true); assert(e2.getAttribute("attr") == "poop"); assert(e2.getFirstChild().getNodeName() == "child"); } // test8 void test9() { DOM::Document d = parse(""); DOM::Element elem = d.getDocumentElement(); assertEquals(false, elem.hasNamespaceURI()); DOM::Attr attr = elem.getAttributeNode("attr"); assertEquals(false, attr.hasNamespaceURI()); } // test9 void test10() { DOM::Document d = parse(""); assert(d == 0); } // test10 void test11() { SAX2DOM::Parser parser; assert(parser.getFeature("http://xml.org/sax/features/validation") == true); parser.setFeature("http://xml.org/sax/features/validation", false); assert(parser.getFeature("http://xml.org/sax/features/validation") == false); parser.parse(""); } // test11 void test12() { SAX2DOM::Parser parser; try { parser.getFeature("made up name"); assert(false); } catch(const SAX::SAXNotRecognizedException&) { } } // test12 }; TestSuite* SAXTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller("test1", &SAXTest::test1)); suiteOfTests->addTest(new TestCaller("test2", &SAXTest::test2)); suiteOfTests->addTest(new TestCaller("test3", &SAXTest::test3)); suiteOfTests->addTest(new TestCaller("test4", &SAXTest::test4)); suiteOfTests->addTest(new TestCaller("test5", &SAXTest::test5)); suiteOfTests->addTest(new TestCaller("test6", &SAXTest::test6)); suiteOfTests->addTest(new TestCaller("test7", &SAXTest::test7)); suiteOfTests->addTest(new TestCaller("test8", &SAXTest::test8)); suiteOfTests->addTest(new TestCaller("test9", &SAXTest::test9)); suiteOfTests->addTest(new TestCaller("test10", &SAXTest::test10)); suiteOfTests->addTest(new TestCaller("test11", &SAXTest::test11)); suiteOfTests->addTest(new TestCaller("test12", &SAXTest::test12)); return suiteOfTests; } // MathTest_suite