#ifndef test_Stream_HPP #define test_Stream_HPP #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include #include template class StreamTest : public TestCase { Arabica::DOM::DOMImplementation factory; typedef string_adaptor SA; typedef Arabica::DOM::Document DocumentT; typedef Arabica::DOM::Element ElementT; typedef std::basic_ostringstream stringstreamT; void assertEquals(string_type expected, string_type actual, long lineNumber) { if (expected != actual) assertImplementation (false, notEqualsMessage(SA::asStdString(expected), SA::asStdString(actual)), lineNumber, "test_Stream.hpp"); } public: StreamTest(const std::string& name) : TestCase(name) { } // StreamTest void setUp() { factory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); } // setUp string_type s(const char* cs) { return SA::construct_from_utf8(cs); } // s #ifndef ARABICA_NO_WCHAR_T string_type s(const wchar_t* cs) { return SA::construct_from_utf16(cs); } // s #endif void testNoNS() { DocumentT doc = factory.createDocument(s(""), s("a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElement(s("b")); ElementT c = doc.createElement(s("c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNoNS void testNSNoPrefix() { DocumentT doc = factory.createDocument(s("urn:test"), s("a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("b")); ElementT c = doc.createElementNS(s("urn:test"), s("c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSNoPrefix void testNSPrefix() { DocumentT doc = factory.createDocument(s("urn:test"), s("t:a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("t:b")); ElementT c = doc.createElementNS(s("urn:test"), s("t:c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSPrefix void testNSMixed() { DocumentT doc = factory.createDocument(s("urn:test"), s("t:a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("b")); ElementT c = doc.createElementNS(s("urn:test"), s("s:c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSMixed void testNSPrefixAttr() { DocumentT doc = factory.createDocument(s("urn:test"), s("t:a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("t:b")); b.setAttribute(s("x"), s("y")); ElementT c = doc.createElementNS(s("urn:test"), s("t:c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSPrefixAttr void testNSPrefixAttrNS() { DocumentT doc = factory.createDocument(s("urn:test"), s("t:a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("t:b")); b.setAttributeNS(s("urn:case"), s("c:x"), s("y")); ElementT c = doc.createElementNS(s("urn:test"), s("t:c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSPrefixAttrNS void testNSPrefixAttrNS2() { DocumentT doc = factory.createDocument(s("urn:test"), s("t:a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("t:b")); b.setAttributeNS(s("urn:case"), s("x"), s("y")); ElementT c = doc.createElementNS(s("urn:test"), s("t:c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSPrefixAttrNS2 void testNSPrefixAttrNS3() { DocumentT doc = factory.createDocument(s("urn:test"), s("a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("b")); b.setAttributeNS(s("urn:case"), s("x"), s("y")); ElementT c = doc.createElementNS(s("urn:test"), s("c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSPrefixAttrNS3 void testNSPrefixAttrNS4() { DocumentT doc = factory.createDocument(s("urn:test"), s("a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("b")); b.setAttributeNS(s("urn:case"), s("x"), s("y")); b.setAttributeNS(s("urn:box"), s("z"), s("y")); ElementT c = doc.createElementNS(s("urn:test"), s("c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSPrefixAttrNS4 void testNSPrefixAttrNS5() { DocumentT doc = factory.createDocument(s("urn:test"), s("a"), 0); ElementT a = doc.getDocumentElement(); ElementT b = doc.createElementNS(s("urn:test"), s("b")); b.setAttributeNS(s("urn:case"), s("x"), s("y")); b.setAttributeNS(s("urn:box"), s("x"), s("y")); ElementT c = doc.createElementNS(s("urn:test"), s("c")); a.appendChild(b); b.appendChild(c); stringstreamT stream; stream << a; assertEquals(s(""), s(stream.str().c_str()), __LINE__); } // testNSPrefixAttrNS5 }; // class StreamTest template TestSuite* StreamTest_suite() { TestSuite* suiteOfTests = new TestSuite; // suiteOfTests->addTest(new TestCaller >("testNoNS", &StreamTest::testNoNS)); // suiteOfTests->addTest(new TestCaller >("testNSNoPrefix", &StreamTest::testNSNoPrefix)); // suiteOfTests->addTest(new TestCaller >("testNSPrefix", &StreamTest::testNSPrefix)); // suiteOfTests->addTest(new TestCaller >("testNSMixed", &StreamTest::testNSMixed)); // suiteOfTests->addTest(new TestCaller >("testNSPrefixAttr", &StreamTest::testNSPrefixAttr)); // suiteOfTests->addTest(new TestCaller >("testNSPrefixAttrNS", &StreamTest::testNSPrefixAttrNS)); // suiteOfTests->addTest(new TestCaller >("testNSPrefixAttrNS2", &StreamTest::testNSPrefixAttrNS2)); // suiteOfTests->addTest(new TestCaller >("testNSPrefixAttrNS3", &StreamTest::testNSPrefixAttrNS3)); // suiteOfTests->addTest(new TestCaller >("testNSPrefixAttrNS4", &StreamTest::testNSPrefixAttrNS4)); suiteOfTests->addTest(new TestCaller >("testNSPrefixAttrNS5", &StreamTest::testNSPrefixAttrNS5)); return suiteOfTests; } // StreamTest_suite #endif