#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 = static_cast >(d.getDocumentElement().getFirstChild()); assertEquals("child", elem.getNodeName()); assertEquals(true, elem.hasAttributes()); assertEquals("poop", elem.getAttribute("attr")); } // test4 void test8() { DOM::Document d = parse(""); DOM::Element elem = d.getDocumentElement(); DOM::Element e2 = static_cast >(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"); } // test7 }; 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)); return suiteOfTests; } // MathTest_suite