finished up the test cases. now to get them to work

This commit is contained in:
jez 2010-07-14 10:04:34 +01:00
parent 7e8752fe30
commit 7080c5049e
4 changed files with 153 additions and 1 deletions

View file

@ -18,6 +18,15 @@ class StreamTest : public TestCase
typedef Arabica::DOM::Element<string_type, string_adaptor> ElementT; typedef Arabica::DOM::Element<string_type, string_adaptor> ElementT;
typedef std::basic_ostringstream<typename string_adaptor::value_type> stringstreamT; typedef std::basic_ostringstream<typename string_adaptor::value_type> 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: public:
StreamTest(const std::string& name) : StreamTest(const std::string& name) :
TestCase(name) TestCase(name)
@ -34,6 +43,13 @@ public:
return SA::construct_from_utf8(cs); return SA::construct_from_utf8(cs);
} // s } // s
#ifndef ARABICA_NO_WCHAR_T
string_type s(const wchar_t* cs)
{
return SA::construct_from_utf16(cs);
} // s
#endif
void testNoNS() void testNoNS()
{ {
DocumentT doc = factory.createDocument(s(""), s("a"), 0); DocumentT doc = factory.createDocument(s(""), s("a"), 0);
@ -46,9 +62,117 @@ public:
stringstreamT stream; stringstreamT stream;
stream << a; stream << a;
assert(stream.str() == "<a><b><c/></b></a>"); assertEquals(s("<a><b><c/></b></a>"), s(stream.str().c_str()), __LINE__);
} // testNoNS } // 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("<a xmlns=\"urn:test\"><b><c/></b></a>"), 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("<t:a xmlns:t=\"urn:test\"><t:b><t:c/></t:b></t:a>"), 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("<t:a xmlns:t=\"urn:test\"><t:b><t:c/></t:b></t:a>"), 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("<t:a xmlns:t=\"urn:test\"><t:b x=\"y\"><t:c/></t:b></t:a>"), 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("<t:a xmlns:t=\"urn:test\"><t:b c:x=\"y\" xmlns:c=\"urn:case\"><t:c/></t:b></t:a>"), 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("<t:a xmlns:t=\"urn:test\"><t:b a0:x=\"y\" xmlns:a0=\"urn:case\"><t:c/></t:b></t:a>"), 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("<a xmlns=\"urn:test\"><b a0:x=\"y\" xmlns:a0=\"urn:case\"><c/></b></a>"), s(stream.str().c_str()), __LINE__);
} // testNSPrefixAttrNS3
}; // class StreamTest }; // class StreamTest
template<class string_type, class string_adaptor> template<class string_type, class string_adaptor>
@ -56,6 +180,14 @@ TestSuite* StreamTest_suite()
{ {
TestSuite* suiteOfTests = new TestSuite; TestSuite* suiteOfTests = new TestSuite;
suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNoNS", &StreamTest<string_type, string_adaptor>::testNoNS)); suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNoNS", &StreamTest<string_type, string_adaptor>::testNoNS));
suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNSNoPrefix", &StreamTest<string_type, string_adaptor>::testNSNoPrefix));
suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNSPrefix", &StreamTest<string_type, string_adaptor>::testNSPrefix));
suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNSMixed", &StreamTest<string_type, string_adaptor>::testNSMixed));
suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNSPrefixAttr", &StreamTest<string_type, string_adaptor>::testNSPrefixAttr));
suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNSPrefixAttrNS", &StreamTest<string_type, string_adaptor>::testNSPrefixAttrNS));
suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNSPrefixAttrNS2", &StreamTest<string_type, string_adaptor>::testNSPrefixAttrNS2));
suiteOfTests->addTest(new TestCaller<StreamTest<string_type, string_adaptor> >("testNSPrefixAttrNS3", &StreamTest<string_type, string_adaptor>::testNSPrefixAttrNS3));
return suiteOfTests;
} // StreamTest_suite } // StreamTest_suite
#endif #endif

View file

@ -257,6 +257,10 @@
RelativePath=".\..\tests\DOM\test_Siblings.hpp" RelativePath=".\..\tests\DOM\test_Siblings.hpp"
> >
</File> </File>
<File
RelativePath="..\tests\DOM\test_Stream.hpp"
>
</File>
<File <File
RelativePath=".\..\tests\DOM\test_Text.hpp" RelativePath=".\..\tests\DOM\test_Text.hpp"
> >

View file

@ -262,10 +262,18 @@
RelativePath="..\tests\Dom\test_Siblings.hpp" RelativePath="..\tests\Dom\test_Siblings.hpp"
> >
</File> </File>
<File
RelativePath="..\tests\DOM\test_Stream.hpp"
>
</File>
<File <File
RelativePath="..\tests\Dom\test_Text.hpp" RelativePath="..\tests\Dom\test_Text.hpp"
> >
</File> </File>
<File
RelativePath="..\tests\DOM\test_TreeWalker.hpp"
>
</File>
</Filter> </Filter>
</Files> </Files>
<Globals> <Globals>

View file

@ -253,10 +253,18 @@
RelativePath="..\tests\Dom\test_Siblings.hpp" RelativePath="..\tests\Dom\test_Siblings.hpp"
> >
</File> </File>
<File
RelativePath="..\tests\DOM\test_Stream.hpp"
>
</File>
<File <File
RelativePath="..\tests\Dom\test_Text.hpp" RelativePath="..\tests\Dom\test_Text.hpp"
> >
</File> </File>
<File
RelativePath="..\tests\DOM\test_TreeWalker.hpp"
>
</File>
</Filter> </Filter>
</Files> </Files>
<Globals> <Globals>