From 7080c5049e26093e84c495c1aafda929fc5311b5 Mon Sep 17 00:00:00 2001 From: jez Date: Wed, 14 Jul 2010 10:04:34 +0100 Subject: [PATCH] finished up the test cases. now to get them to work --- tests/DOM/test_Stream.hpp | 134 +++++++++++++++++++++++++++++++++++++- vs9/test_DOM.vcproj | 4 ++ vs9/test_DOM_silly.vcproj | 8 +++ vs9/test_DOM_wide.vcproj | 8 +++ 4 files changed, 153 insertions(+), 1 deletion(-) diff --git a/tests/DOM/test_Stream.hpp b/tests/DOM/test_Stream.hpp index 2bc5d0a4..6bafa977 100644 --- a/tests/DOM/test_Stream.hpp +++ b/tests/DOM/test_Stream.hpp @@ -18,6 +18,15 @@ class StreamTest : public TestCase 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) @@ -34,6 +43,13 @@ public: 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); @@ -46,9 +62,117 @@ public: stringstreamT stream; stream << a; - assert(stream.str() == ""); + 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 }; // class StreamTest template @@ -56,6 +180,14 @@ 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)); + return suiteOfTests; } // StreamTest_suite #endif diff --git a/vs9/test_DOM.vcproj b/vs9/test_DOM.vcproj index 6f5beea9..f7a9ad46 100644 --- a/vs9/test_DOM.vcproj +++ b/vs9/test_DOM.vcproj @@ -257,6 +257,10 @@ RelativePath=".\..\tests\DOM\test_Siblings.hpp" > + + diff --git a/vs9/test_DOM_silly.vcproj b/vs9/test_DOM_silly.vcproj index be9bf9cd..9f41fc19 100644 --- a/vs9/test_DOM_silly.vcproj +++ b/vs9/test_DOM_silly.vcproj @@ -262,10 +262,18 @@ RelativePath="..\tests\Dom\test_Siblings.hpp" > + + + + diff --git a/vs9/test_DOM_wide.vcproj b/vs9/test_DOM_wide.vcproj index c86b8909..6ac89949 100644 --- a/vs9/test_DOM_wide.vcproj +++ b/vs9/test_DOM_wide.vcproj @@ -253,10 +253,18 @@ RelativePath="..\tests\Dom\test_Siblings.hpp" > + + + +