xml tests fix

This commit is contained in:
Marian Krivos
2011-09-14 16:13:26 +00:00
parent d589a60abe
commit 87f604a743
8 changed files with 872 additions and 347 deletions

View File

@@ -630,6 +630,280 @@ void ElementTest::testChildElementNS()
} }
void ElementTest::testNodeByPath()
{
/*
<root>
<elem1>
<elemA/>
<elemA/>
</elem1>
<elem2>
<elemB attr1="value1"/>
<elemB attr1="value2"/>
<elemB attr1="value3"/>
<elemC attr1="value1">
<elemC1 attr1="value1"/>
<elemC2/>
</elemC>
<elemC attr1="value2"/>
</elem2>
</root>
*/
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElement("root");
AutoPtr<Element> pElem1 = pDoc->createElement("elem1");
AutoPtr<Element> pElem11 = pDoc->createElement("elemA");
AutoPtr<Element> pElem12 = pDoc->createElement("elemA");
AutoPtr<Element> pElem2 = pDoc->createElement("elem2");
AutoPtr<Element> pElem21 = pDoc->createElement("elemB");
AutoPtr<Element> pElem22 = pDoc->createElement("elemB");
AutoPtr<Element> pElem23 = pDoc->createElement("elemB");
AutoPtr<Element> pElem24 = pDoc->createElement("elemC");
AutoPtr<Element> pElem25 = pDoc->createElement("elemC");
pElem21->setAttribute("attr1", "value1");
pElem22->setAttribute("attr1", "value2");
pElem23->setAttribute("attr1", "value3");
pElem24->setAttribute("attr1", "value1");
pElem25->setAttribute("attr1", "value2");
AutoPtr<Element> pElem241 = pDoc->createElement("elemC1");
AutoPtr<Element> pElem242 = pDoc->createElement("elemC2");
pElem241->setAttribute("attr1", "value1");
pElem24->appendChild(pElem241);
pElem24->appendChild(pElem242);
pElem1->appendChild(pElem11);
pElem1->appendChild(pElem12);
pElem2->appendChild(pElem21);
pElem2->appendChild(pElem22);
pElem2->appendChild(pElem23);
pElem2->appendChild(pElem24);
pElem2->appendChild(pElem25);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
Node* pNode = pRoot->getNodeByPath("/");
assert (pNode == pRoot);
pNode = pRoot->getNodeByPath("/elem1");
assert (pNode == pElem1);
pNode = pDoc->getNodeByPath("/root/elem1");
assert (pNode == pElem1);
pNode = pRoot->getNodeByPath("/elem2");
assert (pNode == pElem2);
pNode = pRoot->getNodeByPath("/elem1/elemA");
assert (pNode == pElem11);
pNode = pRoot->getNodeByPath("/elem1/elemA[0]");
assert (pNode == pElem11);
pNode = pRoot->getNodeByPath("/elem1/elemA[1]");
assert (pNode == pElem12);
pNode = pRoot->getNodeByPath("/elem1/elemA[2]");
assert (pNode == 0);
pNode = pRoot->getNodeByPath("/elem2/elemB");
assert (pNode == pElem21);
pNode = pRoot->getNodeByPath("/elem2/elemB[0]");
assert (pNode == pElem21);
pNode = pRoot->getNodeByPath("/elem2/elemB[1]");
assert (pNode == pElem22);
pNode = pRoot->getNodeByPath("/elem2/elemB[2]");
assert (pNode == pElem23);
pNode = pRoot->getNodeByPath("/elem2/elemB[3]");
assert (pNode == 0);
pNode = pRoot->getNodeByPath("/elem2/elemB[@attr1]");
assert (pNode && pNode->nodeValue() == "value1");
pNode = pRoot->getNodeByPath("/elem2/elemB[@attr2]");
assert (pNode == 0);
pNode = pRoot->getNodeByPath("/elem2/elemB[@attr1='value2']");
assert (pNode == pElem22);
pNode = pRoot->getNodeByPath("/elem2/elemC[@attr1='value1']/elemC1");
assert (pNode == pElem241);
pNode = pRoot->getNodeByPath("/elem2/elemC[@attr1='value1']/elemC1[@attr1]");
assert (pNode && pNode->nodeValue() == "value1");
pNode = pDoc->getNodeByPath("//elemB[@attr1='value1']");
assert (pNode == pElem21);
pNode = pDoc->getNodeByPath("//elemB[@attr1='value2']");
assert (pNode == pElem22);
pNode = pDoc->getNodeByPath("//elemB[@attr1='value3']");
assert (pNode == pElem23);
pNode = pDoc->getNodeByPath("//elemB[@attr1='value4']");
assert (pNode == 0);
pNode = pDoc->getNodeByPath("//[@attr1='value1']");
assert (pNode == pElem21);
pNode = pDoc->getNodeByPath("//[@attr1='value2']");
assert (pNode == pElem22);
}
void ElementTest::testNodeByPathNS()
{
/*
<ns1:root xmlns:ns1="urn:ns1">
<ns1:elem1>
<ns2:elemA xmlns:ns2="urn:ns2"/>
<ns3:elemA xmlns:ns3="urn:ns2"/>
</ns1:elem1>
<ns1:elem2>
<ns2:elemB ns2:attr1="value1" xmlns:ns2="urn:ns2"/>
<ns2:elemB ns2:attr1="value2" xmlns:ns2="urn:ns2"/>
<ns2:elemB ns2:attr1="value3" xmlns:ns2="urn:ns2"/>
<ns2:elemC ns2:attr1="value1" xmlns:ns2="urn:ns2">
<ns2:elemC1 ns2:attr1="value1"/>
<ns2:elemC2/>
</ns2:elemC>
<ns2:elemC ns2:attr1="value2" xmlns:ns2="urn:ns2"/>
</ns1:elem2>
</ns1:root>
*/
AutoPtr<Document> pDoc = new Document;
AutoPtr<Element> pRoot = pDoc->createElementNS("urn:ns1", "ns1:root");
AutoPtr<Element> pElem1 = pDoc->createElementNS("urn:ns1", "ns1:elem1");
AutoPtr<Element> pElem11 = pDoc->createElementNS("urn:ns2", "ns2:elemA");
AutoPtr<Element> pElem12 = pDoc->createElementNS("urn:ns2", "ns2:elemA");
AutoPtr<Element> pElem2 = pDoc->createElementNS("urn:ns1", "ns1:elem2");
AutoPtr<Element> pElem21 = pDoc->createElementNS("urn:ns2", "ns2:elemB");
AutoPtr<Element> pElem22 = pDoc->createElementNS("urn:ns2", "ns2:elemB");
AutoPtr<Element> pElem23 = pDoc->createElementNS("urn:ns2", "ns2:elemB");
AutoPtr<Element> pElem24 = pDoc->createElementNS("urn:ns2", "ns2:elemC");
AutoPtr<Element> pElem25 = pDoc->createElementNS("urn:ns2", "ns2:elemC");
pElem21->setAttributeNS("urn:ns2", "ns2:attr1", "value1");
pElem22->setAttributeNS("urn:ns2", "ns2:attr1", "value2");
pElem23->setAttributeNS("urn:ns2", "ns2:attr1", "value3");
pElem24->setAttributeNS("urn:ns2", "ns2:attr1", "value1");
pElem25->setAttributeNS("urn:ns2", "ns2:attr1", "value2");
AutoPtr<Element> pElem241 = pDoc->createElementNS("urn:ns2", "elemC1");
AutoPtr<Element> pElem242 = pDoc->createElementNS("urn:ns2", "elemC2");
pElem241->setAttributeNS("urn:ns2", "ns2:attr1", "value1");
pElem24->appendChild(pElem241);
pElem24->appendChild(pElem242);
pElem1->appendChild(pElem11);
pElem1->appendChild(pElem12);
pElem2->appendChild(pElem21);
pElem2->appendChild(pElem22);
pElem2->appendChild(pElem23);
pElem2->appendChild(pElem24);
pElem2->appendChild(pElem25);
pRoot->appendChild(pElem1);
pRoot->appendChild(pElem2);
pDoc->appendChild(pRoot);
Element::NSMap nsMap;
nsMap.declarePrefix("ns1", "urn:ns1");
nsMap.declarePrefix("NS2", "urn:ns2");
Node* pNode = pRoot->getNodeByPathNS("/", nsMap);
assert (pNode == pRoot);
pNode = pRoot->getNodeByPathNS("/ns1:elem1", nsMap);
assert (pNode == pElem1);
pNode = pDoc->getNodeByPathNS("/ns1:root/ns1:elem1", nsMap);
assert (pNode == pElem1);
pNode = pRoot->getNodeByPathNS("/ns1:elem2", nsMap);
assert (pNode == pElem2);
pNode = pRoot->getNodeByPathNS("/ns1:elem1/NS2:elemA", nsMap);
assert (pNode == pElem11);
pNode = pRoot->getNodeByPathNS("/ns1:elem1/NS2:elemA[0]", nsMap);
assert (pNode == pElem11);
pNode = pRoot->getNodeByPathNS("/ns1:elem1/NS2:elemA[1]", nsMap);
assert (pNode == pElem12);
pNode = pRoot->getNodeByPathNS("/ns1:elem1/NS2:elemA[2]", nsMap);
assert (pNode == 0);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemB", nsMap);
assert (pNode == pElem21);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemB[0]", nsMap);
assert (pNode == pElem21);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemB[1]", nsMap);
assert (pNode == pElem22);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemB[2]", nsMap);
assert (pNode == pElem23);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemB[3]", nsMap);
assert (pNode == 0);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemB[@NS2:attr1]", nsMap);
assert (pNode && pNode->nodeValue() == "value1");
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemB[@NS2:attr2]", nsMap);
assert (pNode == 0);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemB[@NS2:attr1='value2']", nsMap);
assert (pNode == pElem22);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemC[@NS2:attr1='value1']/NS2:elemC1", nsMap);
assert (pNode == pElem241);
pNode = pRoot->getNodeByPathNS("/ns1:elem2/NS2:elemC[@NS2:attr1='value1']/NS2:elemC1[@NS2:attr1]", nsMap);
assert (pNode && pNode->nodeValue() == "value1");
pNode = pRoot->getNodeByPathNS("/NS2:elem1", nsMap);
assert (pNode == 0);
pNode = pDoc->getNodeByPathNS("//NS2:elemB[@NS2:attr1='value1']", nsMap);
assert (pNode == pElem21);
pNode = pDoc->getNodeByPathNS("//NS2:elemB[@NS2:attr1='value2']", nsMap);
assert (pNode == pElem22);
pNode = pDoc->getNodeByPathNS("//NS2:elemB[@NS2:attr1='value3']", nsMap);
assert (pNode == pElem23);
pNode = pDoc->getNodeByPathNS("//NS2:elemB[@NS2:attr1='value4']", nsMap);
assert (pNode == 0);
pNode = pDoc->getNodeByPathNS("//[@NS2:attr1='value1']", nsMap);
assert (pNode == pElem21);
pNode = pDoc->getNodeByPathNS("//[@NS2:attr1='value2']", nsMap);
assert (pNode == pElem22);
}
void ElementTest::setUp() void ElementTest::setUp()
{ {
} }
@@ -650,9 +924,11 @@ CppUnit::Test* ElementTest::suite()
CppUnit_addTest(pSuite, ElementTest, testAttrMapNS); CppUnit_addTest(pSuite, ElementTest, testAttrMapNS);
CppUnit_addTest(pSuite, ElementTest, testElementsByTagName); CppUnit_addTest(pSuite, ElementTest, testElementsByTagName);
CppUnit_addTest(pSuite, ElementTest, testElementsByTagNameNS); CppUnit_addTest(pSuite, ElementTest, testElementsByTagNameNS);
CppUnit_addTest(pSuite, ElementTest, testInnerText); CppUnit_addTest(pSuite, ElementTest, testInnerText);
CppUnit_addTest(pSuite, ElementTest, testChildElement); CppUnit_addTest(pSuite, ElementTest, testChildElement);
CppUnit_addTest(pSuite, ElementTest, testChildElementNS); CppUnit_addTest(pSuite, ElementTest, testChildElementNS);
CppUnit_addTest(pSuite, ElementTest, testNodeByPath);
CppUnit_addTest(pSuite, ElementTest, testNodeByPathNS);
return pSuite; return pSuite;
} }

View File

@@ -52,12 +52,14 @@ public:
void testAttrMapNS(); void testAttrMapNS();
void testElementsByTagName(); void testElementsByTagName();
void testElementsByTagNameNS(); void testElementsByTagNameNS();
void testInnerText(); void testInnerText();
void testChildElement(); void testChildElement();
void testChildElementNS(); void testChildElementNS();
void testNodeByPath();
void setUp(); void testNodeByPathNS();
void tearDown();
void setUp();
void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();

View File

@@ -36,6 +36,7 @@
#include "Poco/DOM/DOMParser.h" #include "Poco/DOM/DOMParser.h"
#include "Poco/DOM/DOMWriter.h" #include "Poco/DOM/DOMWriter.h"
#include "Poco/DOM/Document.h" #include "Poco/DOM/Document.h"
#include "Poco/DOM/Element.h"
#include "Poco/DOM/AutoPtr.h" #include "Poco/DOM/AutoPtr.h"
#include "Poco/SAX/InputSource.h" #include "Poco/SAX/InputSource.h"
#include "Poco/XML/XMLWriter.h" #include "Poco/XML/XMLWriter.h"
@@ -90,7 +91,6 @@ void ParserWriterTest::testParseWriteXHTML2()
assert (xml == XHTML2); assert (xml == XHTML2);
} }
void ParserWriterTest::testParseWriteWSDL() void ParserWriterTest::testParseWriteWSDL()
{ {
std::istringstream istr(WSDL); std::istringstream istr(WSDL);
@@ -107,7 +107,40 @@ void ParserWriterTest::testParseWriteWSDL()
writer.writeNode(ostr, pDoc); writer.writeNode(ostr, pDoc);
std::string xml = ostr.str(); std::string xml = ostr.str();
assert (xml == WSDL); assert (xml == WSDL);
}
void ParserWriterTest::testParseWriteSimple()
{
static const std::string simple =
"<config>\n"
"\t<prop1>value1</prop1>\n"
"\t<prop2>value2</prop2>\n"
"</config>\n";
std::istringstream istr(simple);
std::ostringstream ostr;
DOMParser parser;
parser.setFeature(DOMParser::FEATURE_FILTER_WHITESPACE, true);
parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false);
DOMWriter writer;
writer.setNewLine("\n");
writer.setOptions(XMLWriter::PRETTY_PRINT);
InputSource source(istr);
AutoPtr<Document> pDoc = parser.parse(&source);
writer.writeNode(ostr, pDoc);
unsigned int numChildren = 0;
Poco::XML::Node* child = pDoc->documentElement()->firstChild();
while (child) {
numChildren++;
child = child->nextSibling();
}
assert (numChildren == 2);
std::string xml = ostr.str();
assert (xml == simple);
} }
@@ -125,11 +158,12 @@ CppUnit::Test* ParserWriterTest::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ParserWriterTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ParserWriterTest");
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML); CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML);
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML2); CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML2);
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteWSDL); CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteWSDL);
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteSimple);
return pSuite; return pSuite;
} }
@@ -171,151 +205,151 @@ const std::string ParserWriterTest::XHTML2 =
"\t\t<![CDATA[\n" "\t\t<![CDATA[\n"
"\t\tThe following <tag attr=\"value\">is inside a CDATA section</tag>.\n" "\t\tThe following <tag attr=\"value\">is inside a CDATA section</tag>.\n"
"\t\t]]>\n" "\t\t]]>\n"
"\t</xns:body>\n" "\t</xns:body>\n"
"</xns:html>"; "</xns:html>";
const std::string ParserWriterTest::WSDL = const std::string ParserWriterTest::WSDL =
"<!-- WSDL description of the Google Web APIs.\n" "<!-- WSDL description of the Google Web APIs.\n"
" The Google Web APIs are in beta release. All interfaces are subject to\n" " The Google Web APIs are in beta release. All interfaces are subject to\n"
" change as we refine and extend our APIs. Please see the terms of use\n" " change as we refine and extend our APIs. Please see the terms of use\n"
" for more information. -->\n" " for more information. -->\n"
"<!-- Revision 2002-08-16 -->\n" "<!-- Revision 2002-08-16 -->\n"
"<ns1:definitions name=\"GoogleSearch\" targetNamespace=\"urn:GoogleSearch\" xmlns:ns1=\"http://schemas.xmlsoap.org/wsdl/\">\n" "<ns1:definitions name=\"GoogleSearch\" targetNamespace=\"urn:GoogleSearch\" xmlns:ns1=\"http://schemas.xmlsoap.org/wsdl/\">\n"
"\t<!-- Types for search - result elements, directory categories -->\n" "\t<!-- Types for search - result elements, directory categories -->\n"
"\t<ns1:types>\n" "\t<ns1:types>\n"
"\t\t<ns2:schema targetNamespace=\"urn:GoogleSearch\" xmlns:ns2=\"http://www.w3.org/2001/XMLSchema\">\n" "\t\t<ns2:schema targetNamespace=\"urn:GoogleSearch\" xmlns:ns2=\"http://www.w3.org/2001/XMLSchema\">\n"
"\t\t\t<ns2:complexType name=\"GoogleSearchResult\">\n" "\t\t\t<ns2:complexType name=\"GoogleSearchResult\">\n"
"\t\t\t\t<ns2:all>\n" "\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"documentFiltering\" type=\"xsd:boolean\"/>\n" "\t\t\t\t\t<ns2:element name=\"documentFiltering\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchComments\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"searchComments\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"estimatedTotalResultsCount\" type=\"xsd:int\"/>\n" "\t\t\t\t\t<ns2:element name=\"estimatedTotalResultsCount\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"estimateIsExact\" type=\"xsd:boolean\"/>\n" "\t\t\t\t\t<ns2:element name=\"estimateIsExact\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"resultElements\" type=\"typens:ResultElementArray\"/>\n" "\t\t\t\t\t<ns2:element name=\"resultElements\" type=\"typens:ResultElementArray\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchQuery\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"searchQuery\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"startIndex\" type=\"xsd:int\"/>\n" "\t\t\t\t\t<ns2:element name=\"startIndex\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"endIndex\" type=\"xsd:int\"/>\n" "\t\t\t\t\t<ns2:element name=\"endIndex\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchTips\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"searchTips\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryCategories\" type=\"typens:DirectoryCategoryArray\"/>\n" "\t\t\t\t\t<ns2:element name=\"directoryCategories\" type=\"typens:DirectoryCategoryArray\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchTime\" type=\"xsd:double\"/>\n" "\t\t\t\t\t<ns2:element name=\"searchTime\" type=\"xsd:double\"/>\n"
"\t\t\t\t</ns2:all>\n" "\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n" "\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"ResultElement\">\n" "\t\t\t<ns2:complexType name=\"ResultElement\">\n"
"\t\t\t\t<ns2:all>\n" "\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"summary\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"summary\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"URL\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"URL\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"snippet\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"snippet\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"title\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"title\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"cachedSize\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"cachedSize\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"relatedInformationPresent\" type=\"xsd:boolean\"/>\n" "\t\t\t\t\t<ns2:element name=\"relatedInformationPresent\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"hostName\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"hostName\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryCategory\" type=\"typens:DirectoryCategory\"/>\n" "\t\t\t\t\t<ns2:element name=\"directoryCategory\" type=\"typens:DirectoryCategory\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryTitle\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"directoryTitle\" type=\"xsd:string\"/>\n"
"\t\t\t\t</ns2:all>\n" "\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n" "\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"ResultElementArray\">\n" "\t\t\t<ns2:complexType name=\"ResultElementArray\">\n"
"\t\t\t\t<ns2:complexContent>\n" "\t\t\t\t<ns2:complexContent>\n"
"\t\t\t\t\t<ns2:restriction base=\"soapenc:Array\">\n" "\t\t\t\t\t<ns2:restriction base=\"soapenc:Array\">\n"
"\t\t\t\t\t\t<ns2:attribute ns1:arrayType=\"typens:ResultElement[]\" ref=\"soapenc:arrayType\"/>\n" "\t\t\t\t\t\t<ns2:attribute ns1:arrayType=\"typens:ResultElement[]\" ref=\"soapenc:arrayType\"/>\n"
"\t\t\t\t\t</ns2:restriction>\n" "\t\t\t\t\t</ns2:restriction>\n"
"\t\t\t\t</ns2:complexContent>\n" "\t\t\t\t</ns2:complexContent>\n"
"\t\t\t</ns2:complexType>\n" "\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"DirectoryCategoryArray\">\n" "\t\t\t<ns2:complexType name=\"DirectoryCategoryArray\">\n"
"\t\t\t\t<ns2:complexContent>\n" "\t\t\t\t<ns2:complexContent>\n"
"\t\t\t\t\t<ns2:restriction base=\"soapenc:Array\">\n" "\t\t\t\t\t<ns2:restriction base=\"soapenc:Array\">\n"
"\t\t\t\t\t\t<ns2:attribute ns1:arrayType=\"typens:DirectoryCategory[]\" ref=\"soapenc:arrayType\"/>\n" "\t\t\t\t\t\t<ns2:attribute ns1:arrayType=\"typens:DirectoryCategory[]\" ref=\"soapenc:arrayType\"/>\n"
"\t\t\t\t\t</ns2:restriction>\n" "\t\t\t\t\t</ns2:restriction>\n"
"\t\t\t\t</ns2:complexContent>\n" "\t\t\t\t</ns2:complexContent>\n"
"\t\t\t</ns2:complexType>\n" "\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"DirectoryCategory\">\n" "\t\t\t<ns2:complexType name=\"DirectoryCategory\">\n"
"\t\t\t\t<ns2:all>\n" "\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"fullViewableName\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"fullViewableName\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"specialEncoding\" type=\"xsd:string\"/>\n" "\t\t\t\t\t<ns2:element name=\"specialEncoding\" type=\"xsd:string\"/>\n"
"\t\t\t\t</ns2:all>\n" "\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n" "\t\t\t</ns2:complexType>\n"
"\t\t</ns2:schema>\n" "\t\t</ns2:schema>\n"
"\t</ns1:types>\n" "\t</ns1:types>\n"
"\t<!-- Messages for Google Web APIs - cached page, search, spelling. -->\n" "\t<!-- Messages for Google Web APIs - cached page, search, spelling. -->\n"
"\t<ns1:message name=\"doGetCachedPage\">\n" "\t<ns1:message name=\"doGetCachedPage\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"url\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"url\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n" "\t</ns1:message>\n"
"\t<ns1:message name=\"doGetCachedPageResponse\">\n" "\t<ns1:message name=\"doGetCachedPageResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"xsd:base64Binary\"/>\n" "\t\t<ns1:part name=\"return\" type=\"xsd:base64Binary\"/>\n"
"\t</ns1:message>\n" "\t</ns1:message>\n"
"\t<ns1:message name=\"doSpellingSuggestion\">\n" "\t<ns1:message name=\"doSpellingSuggestion\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"phrase\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"phrase\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n" "\t</ns1:message>\n"
"\t<ns1:message name=\"doSpellingSuggestionResponse\">\n" "\t<ns1:message name=\"doSpellingSuggestionResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"return\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n" "\t</ns1:message>\n"
"\t<!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->\n" "\t<!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->\n"
"\t<ns1:message name=\"doGoogleSearch\">\n" "\t<ns1:message name=\"doGoogleSearch\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"q\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"q\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"start\" type=\"xsd:int\"/>\n" "\t\t<ns1:part name=\"start\" type=\"xsd:int\"/>\n"
"\t\t<ns1:part name=\"maxResults\" type=\"xsd:int\"/>\n" "\t\t<ns1:part name=\"maxResults\" type=\"xsd:int\"/>\n"
"\t\t<ns1:part name=\"filter\" type=\"xsd:boolean\"/>\n" "\t\t<ns1:part name=\"filter\" type=\"xsd:boolean\"/>\n"
"\t\t<ns1:part name=\"restrict\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"restrict\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"safeSearch\" type=\"xsd:boolean\"/>\n" "\t\t<ns1:part name=\"safeSearch\" type=\"xsd:boolean\"/>\n"
"\t\t<ns1:part name=\"lr\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"lr\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"ie\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"ie\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"oe\" type=\"xsd:string\"/>\n" "\t\t<ns1:part name=\"oe\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n" "\t</ns1:message>\n"
"\t<ns1:message name=\"doGoogleSearchResponse\">\n" "\t<ns1:message name=\"doGoogleSearchResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"typens:GoogleSearchResult\"/>\n" "\t\t<ns1:part name=\"return\" type=\"typens:GoogleSearchResult\"/>\n"
"\t</ns1:message>\n" "\t</ns1:message>\n"
"\t<!-- Port for Google Web APIs, \"GoogleSearch\" -->\n" "\t<!-- Port for Google Web APIs, \"GoogleSearch\" -->\n"
"\t<ns1:portType name=\"GoogleSearchPort\">\n" "\t<ns1:portType name=\"GoogleSearchPort\">\n"
"\t\t<ns1:operation name=\"doGetCachedPage\">\n" "\t\t<ns1:operation name=\"doGetCachedPage\">\n"
"\t\t\t<ns1:input message=\"typens:doGetCachedPage\"/>\n" "\t\t\t<ns1:input message=\"typens:doGetCachedPage\"/>\n"
"\t\t\t<ns1:output message=\"typens:doGetCachedPageResponse\"/>\n" "\t\t\t<ns1:output message=\"typens:doGetCachedPageResponse\"/>\n"
"\t\t</ns1:operation>\n" "\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doSpellingSuggestion\">\n" "\t\t<ns1:operation name=\"doSpellingSuggestion\">\n"
"\t\t\t<ns1:input message=\"typens:doSpellingSuggestion\"/>\n" "\t\t\t<ns1:input message=\"typens:doSpellingSuggestion\"/>\n"
"\t\t\t<ns1:output message=\"typens:doSpellingSuggestionResponse\"/>\n" "\t\t\t<ns1:output message=\"typens:doSpellingSuggestionResponse\"/>\n"
"\t\t</ns1:operation>\n" "\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doGoogleSearch\">\n" "\t\t<ns1:operation name=\"doGoogleSearch\">\n"
"\t\t\t<ns1:input message=\"typens:doGoogleSearch\"/>\n" "\t\t\t<ns1:input message=\"typens:doGoogleSearch\"/>\n"
"\t\t\t<ns1:output message=\"typens:doGoogleSearchResponse\"/>\n" "\t\t\t<ns1:output message=\"typens:doGoogleSearchResponse\"/>\n"
"\t\t</ns1:operation>\n" "\t\t</ns1:operation>\n"
"\t</ns1:portType>\n" "\t</ns1:portType>\n"
"\t<!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->\n" "\t<!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->\n"
"\t<ns1:binding name=\"GoogleSearchBinding\" type=\"typens:GoogleSearchPort\">\n" "\t<ns1:binding name=\"GoogleSearchBinding\" type=\"typens:GoogleSearchPort\">\n"
"\t\t<ns3:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\"/>\n" "\t\t<ns3:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\"/>\n"
"\t\t<ns1:operation name=\"doGetCachedPage\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n" "\t\t<ns1:operation name=\"doGetCachedPage\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n" "\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n" "\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n" "\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n" "\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n" "\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n" "\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n" "\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n" "\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doSpellingSuggestion\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n" "\t\t<ns1:operation name=\"doSpellingSuggestion\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n" "\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n" "\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n" "\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n" "\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n" "\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n" "\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n" "\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n" "\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doGoogleSearch\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n" "\t\t<ns1:operation name=\"doGoogleSearch\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n" "\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n" "\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n" "\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n" "\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n" "\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n" "\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n" "\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n" "\t\t</ns1:operation>\n"
"\t</ns1:binding>\n" "\t</ns1:binding>\n"
"\t<!-- Endpoint for Google Web APIs -->\n" "\t<!-- Endpoint for Google Web APIs -->\n"
"\t<ns1:service name=\"GoogleSearchService\">\n" "\t<ns1:service name=\"GoogleSearchService\">\n"
"\t\t<ns1:port binding=\"typens:GoogleSearchBinding\" name=\"GoogleSearchPort\">\n" "\t\t<ns1:port binding=\"typens:GoogleSearchBinding\" name=\"GoogleSearchPort\">\n"
"\t\t\t<ns4:address location=\"http://api.google.com/search/beta2\" xmlns:ns4=\"http://schemas.xmlsoap.org/wsdl/soap/\"/>\n" "\t\t\t<ns4:address location=\"http://api.google.com/search/beta2\" xmlns:ns4=\"http://schemas.xmlsoap.org/wsdl/soap/\"/>\n"
"\t\t</ns1:port>\n" "\t\t</ns1:port>\n"
"\t</ns1:service>\n" "\t</ns1:service>\n"
"</ns1:definitions>\n"; "</ns1:definitions>\n";

View File

@@ -46,19 +46,20 @@ public:
ParserWriterTest(const std::string& name); ParserWriterTest(const std::string& name);
~ParserWriterTest(); ~ParserWriterTest();
void testParseWriteXHTML(); void testParseWriteXHTML();
void testParseWriteXHTML2(); void testParseWriteXHTML2();
void testParseWriteWSDL(); void testParseWriteWSDL();
void testParseWriteSimple();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();
private: private:
static const std::string XHTML; static const std::string XHTML;
static const std::string XHTML2; static const std::string XHTML2;
static const std::string WSDL; static const std::string WSDL;
}; };

View File

@@ -320,8 +320,18 @@ void SAXParserTest::testCharacters()
void SAXParserTest::testParseMemory() void SAXParserTest::testParseMemory()
{ {
SAXParser parser; SAXParser parser;
std::string xml = parseMemory(parser, XMLWriter::CANONICAL, ATTRIBUTES); std::string xml = parseMemory(parser, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT, WSDL);
assert (xml == ATTRIBUTES); assert (xml == WSDL);
}
void SAXParserTest::testParsePartialReads()
{
SAXParser parser;
parser.setFeature("http://www.appinf.com/features/enable-partial-reads", true);
std::string xml = parse(parser, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT, WSDL);
assert (xml == WSDL);
} }
@@ -340,6 +350,7 @@ std::string SAXParserTest::parse(XMLReader& reader, int options, const std::stri
std::istringstream istr(data); std::istringstream istr(data);
std::ostringstream ostr; std::ostringstream ostr;
XMLWriter writer(ostr, options); XMLWriter writer(ostr, options);
writer.setNewLine(XMLWriter::NEWLINE_LF);
reader.setContentHandler(&writer); reader.setContentHandler(&writer);
reader.setDTDHandler(&writer); reader.setDTDHandler(&writer);
reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&writer)); reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&writer));
@@ -351,9 +362,10 @@ std::string SAXParserTest::parse(XMLReader& reader, int options, const std::stri
std::string SAXParserTest::parseMemory(XMLReader& reader, int options, const std::string& data) std::string SAXParserTest::parseMemory(XMLReader& reader, int options, const std::string& data)
{ {
std::istringstream istr(data); std::istringstream istr(data);
std::ostringstream ostr; std::ostringstream ostr;
XMLWriter writer(ostr, options); XMLWriter writer(ostr, options);
writer.setNewLine(XMLWriter::NEWLINE_LF);
reader.setContentHandler(&writer); reader.setContentHandler(&writer);
reader.setDTDHandler(&writer); reader.setDTDHandler(&writer);
reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&writer)); reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&writer));
@@ -383,13 +395,14 @@ CppUnit::Test* SAXParserTest::suite()
CppUnit_addTest(pSuite, SAXParserTest, testNoNamespaces); CppUnit_addTest(pSuite, SAXParserTest, testNoNamespaces);
CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespace); CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespace);
CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespaceNoPrefixes); CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespaceNoPrefixes);
CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNoNamespace); CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNoNamespace);
CppUnit_addTest(pSuite, SAXParserTest, testRSS); CppUnit_addTest(pSuite, SAXParserTest, testRSS);
CppUnit_addTest(pSuite, SAXParserTest, testEncoding); CppUnit_addTest(pSuite, SAXParserTest, testEncoding);
CppUnit_addTest(pSuite, SAXParserTest, testParseMemory); CppUnit_addTest(pSuite, SAXParserTest, testCharacters);
CppUnit_addTest(pSuite, SAXParserTest, testCharacters); CppUnit_addTest(pSuite, SAXParserTest, testParseMemory);
CppUnit_addTest(pSuite, SAXParserTest, testParsePartialReads);
return pSuite; return pSuite;
} }
@@ -1034,3 +1047,148 @@ const std::string SAXParserTest::RSS =
const std::string SAXParserTest::ENCODING = const std::string SAXParserTest::ENCODING =
"<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>" "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>"
"<euro-sign>\244</euro-sign>"; "<euro-sign>\244</euro-sign>";
const std::string SAXParserTest::WSDL =
"<!-- WSDL description of the Google Web APIs.\n"
" The Google Web APIs are in beta release. All interfaces are subject to\n"
" change as we refine and extend our APIs. Please see the terms of use\n"
" for more information. -->\n"
"<!-- Revision 2002-08-16 -->\n"
"<ns1:definitions name=\"GoogleSearch\" targetNamespace=\"urn:GoogleSearch\" xmlns:ns1=\"http://schemas.xmlsoap.org/wsdl/\">\n"
"\t<!-- Types for search - result elements, directory categories -->\n"
"\t<ns1:types>\n"
"\t\t<ns2:schema targetNamespace=\"urn:GoogleSearch\" xmlns:ns2=\"http://www.w3.org/2001/XMLSchema\">\n"
"\t\t\t<ns2:complexType name=\"GoogleSearchResult\">\n"
"\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"documentFiltering\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchComments\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"estimatedTotalResultsCount\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"estimateIsExact\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"resultElements\" type=\"typens:ResultElementArray\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchQuery\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"startIndex\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"endIndex\" type=\"xsd:int\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchTips\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryCategories\" type=\"typens:DirectoryCategoryArray\"/>\n"
"\t\t\t\t\t<ns2:element name=\"searchTime\" type=\"xsd:double\"/>\n"
"\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"ResultElement\">\n"
"\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"summary\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"URL\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"snippet\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"title\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"cachedSize\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"relatedInformationPresent\" type=\"xsd:boolean\"/>\n"
"\t\t\t\t\t<ns2:element name=\"hostName\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryCategory\" type=\"typens:DirectoryCategory\"/>\n"
"\t\t\t\t\t<ns2:element name=\"directoryTitle\" type=\"xsd:string\"/>\n"
"\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"ResultElementArray\">\n"
"\t\t\t\t<ns2:complexContent>\n"
"\t\t\t\t\t<ns2:restriction base=\"soapenc:Array\">\n"
"\t\t\t\t\t\t<ns2:attribute ns1:arrayType=\"typens:ResultElement[]\" ref=\"soapenc:arrayType\"/>\n"
"\t\t\t\t\t</ns2:restriction>\n"
"\t\t\t\t</ns2:complexContent>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"DirectoryCategoryArray\">\n"
"\t\t\t\t<ns2:complexContent>\n"
"\t\t\t\t\t<ns2:restriction base=\"soapenc:Array\">\n"
"\t\t\t\t\t\t<ns2:attribute ns1:arrayType=\"typens:DirectoryCategory[]\" ref=\"soapenc:arrayType\"/>\n"
"\t\t\t\t\t</ns2:restriction>\n"
"\t\t\t\t</ns2:complexContent>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t\t<ns2:complexType name=\"DirectoryCategory\">\n"
"\t\t\t\t<ns2:all>\n"
"\t\t\t\t\t<ns2:element name=\"fullViewableName\" type=\"xsd:string\"/>\n"
"\t\t\t\t\t<ns2:element name=\"specialEncoding\" type=\"xsd:string\"/>\n"
"\t\t\t\t</ns2:all>\n"
"\t\t\t</ns2:complexType>\n"
"\t\t</ns2:schema>\n"
"\t</ns1:types>\n"
"\t<!-- Messages for Google Web APIs - cached page, search, spelling. -->\n"
"\t<ns1:message name=\"doGetCachedPage\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"url\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n"
"\t<ns1:message name=\"doGetCachedPageResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"xsd:base64Binary\"/>\n"
"\t</ns1:message>\n"
"\t<ns1:message name=\"doSpellingSuggestion\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"phrase\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n"
"\t<ns1:message name=\"doSpellingSuggestionResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n"
"\t<!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->\n"
"\t<ns1:message name=\"doGoogleSearch\">\n"
"\t\t<ns1:part name=\"key\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"q\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"start\" type=\"xsd:int\"/>\n"
"\t\t<ns1:part name=\"maxResults\" type=\"xsd:int\"/>\n"
"\t\t<ns1:part name=\"filter\" type=\"xsd:boolean\"/>\n"
"\t\t<ns1:part name=\"restrict\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"safeSearch\" type=\"xsd:boolean\"/>\n"
"\t\t<ns1:part name=\"lr\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"ie\" type=\"xsd:string\"/>\n"
"\t\t<ns1:part name=\"oe\" type=\"xsd:string\"/>\n"
"\t</ns1:message>\n"
"\t<ns1:message name=\"doGoogleSearchResponse\">\n"
"\t\t<ns1:part name=\"return\" type=\"typens:GoogleSearchResult\"/>\n"
"\t</ns1:message>\n"
"\t<!-- Port for Google Web APIs, \"GoogleSearch\" -->\n"
"\t<ns1:portType name=\"GoogleSearchPort\">\n"
"\t\t<ns1:operation name=\"doGetCachedPage\">\n"
"\t\t\t<ns1:input message=\"typens:doGetCachedPage\"/>\n"
"\t\t\t<ns1:output message=\"typens:doGetCachedPageResponse\"/>\n"
"\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doSpellingSuggestion\">\n"
"\t\t\t<ns1:input message=\"typens:doSpellingSuggestion\"/>\n"
"\t\t\t<ns1:output message=\"typens:doSpellingSuggestionResponse\"/>\n"
"\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doGoogleSearch\">\n"
"\t\t\t<ns1:input message=\"typens:doGoogleSearch\"/>\n"
"\t\t\t<ns1:output message=\"typens:doGoogleSearchResponse\"/>\n"
"\t\t</ns1:operation>\n"
"\t</ns1:portType>\n"
"\t<!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->\n"
"\t<ns1:binding name=\"GoogleSearchBinding\" type=\"typens:GoogleSearchPort\">\n"
"\t\t<ns3:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\"/>\n"
"\t\t<ns1:operation name=\"doGetCachedPage\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doSpellingSuggestion\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n"
"\t\t<ns1:operation name=\"doGoogleSearch\" xmlns:ns3=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n"
"\t\t\t<ns3:operation soapAction=\"urn:GoogleSearchAction\"/>\n"
"\t\t\t<ns1:input>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:input>\n"
"\t\t\t<ns1:output>\n"
"\t\t\t\t<ns3:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"urn:GoogleSearch\" use=\"encoded\"/>\n"
"\t\t\t</ns1:output>\n"
"\t\t</ns1:operation>\n"
"\t</ns1:binding>\n"
"\t<!-- Endpoint for Google Web APIs -->\n"
"\t<ns1:service name=\"GoogleSearchService\">\n"
"\t\t<ns1:port binding=\"typens:GoogleSearchBinding\" name=\"GoogleSearchPort\">\n"
"\t\t\t<ns4:address location=\"http://api.google.com/search/beta2\" xmlns:ns4=\"http://schemas.xmlsoap.org/wsdl/soap/\"/>\n"
"\t\t</ns1:port>\n"
"\t</ns1:service>\n"
"</ns1:definitions>\n";

View File

@@ -66,12 +66,13 @@ public:
void testUndeclaredNamespaceNoPrefixes(); void testUndeclaredNamespaceNoPrefixes();
void testUndeclaredNoNamespace(); void testUndeclaredNoNamespace();
void testRSS(); void testRSS();
void testEncoding(); void testEncoding();
void testParseMemory(); void testParseMemory();
void testCharacters(); void testCharacters();
void testParsePartialReads();
void setUp(); void setUp();
void tearDown(); void tearDown();
std::string parse(Poco::XML::XMLReader& reader, int options, const std::string& data); std::string parse(Poco::XML::XMLReader& reader, int options, const std::string& data);
std::string parseMemory(Poco::XML::XMLReader& reader, int options, const std::string& data); std::string parseMemory(Poco::XML::XMLReader& reader, int options, const std::string& data);
@@ -93,9 +94,10 @@ public:
static const std::string DEFAULT_NAMESPACE; static const std::string DEFAULT_NAMESPACE;
static const std::string NAMESPACES; static const std::string NAMESPACES;
static const std::string UNDECLARED_NAMESPACE; static const std::string UNDECLARED_NAMESPACE;
static const std::string XHTML_LATIN1_ENTITIES; static const std::string XHTML_LATIN1_ENTITIES;
static const std::string RSS; static const std::string RSS;
static const std::string ENCODING; static const std::string ENCODING;
static const std::string WSDL;
}; };

View File

@@ -55,20 +55,33 @@ XMLWriterTest::~XMLWriterTest()
void XMLWriterTest::testTrivial() void XMLWriterTest::testTrivial()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "foo"); writer.startElement("", "", "foo");
writer.endElement("", "", "foo"); writer.endElement("", "", "foo");
writer.endDocument(); writer.endDocument();
std::string xml = str.str(); std::string xml = str.str();
assert (xml == "<foo/>"); assert (xml == "<foo/>");
} }
void XMLWriterTest::testTrivialCanonical()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL_XML);
writer.startDocument();
writer.startElement("", "", "foo");
writer.endElement("", "", "foo");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<foo></foo>");
}
void XMLWriterTest::testTrivialDecl() void XMLWriterTest::testTrivialDecl()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION); XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "foo"); writer.startElement("", "", "foo");
@@ -95,11 +108,11 @@ void XMLWriterTest::testTrivialDeclPretty()
void XMLWriterTest::testTrivialFragment() void XMLWriterTest::testTrivialFragment()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startFragment(); writer.startFragment();
writer.startElement("", "", "foo"); writer.startElement("", "", "foo");
writer.endElement("", "", "foo"); writer.endElement("", "", "foo");
writer.endFragment(); writer.endFragment();
std::string xml = str.str(); std::string xml = str.str();
assert (xml == "<foo/>"); assert (xml == "<foo/>");
@@ -208,11 +221,11 @@ void XMLWriterTest::testDTDEntity()
void XMLWriterTest::testAttributes() void XMLWriterTest::testAttributes()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
AttributesImpl attrs; AttributesImpl attrs;
attrs.addAttribute("", "", "a1", "CDATA", "v1"); attrs.addAttribute("", "", "a1", "CDATA", "v1");
attrs.addAttribute("", "", "a2", "CDATA", "v2"); attrs.addAttribute("", "", "a2", "CDATA", "v2");
writer.startElement("", "", "el", attrs); writer.startElement("", "", "el", attrs);
writer.endElement("", "", "el"); writer.endElement("", "", "el");
@@ -222,13 +235,30 @@ void XMLWriterTest::testAttributes()
} }
void XMLWriterTest::testAttributesPretty()
{
std::ostringstream str;
XMLWriter writer(str, XMLWriter::PRETTY_PRINT | XMLWriter::PRETTY_PRINT_ATTRIBUTES);
writer.setNewLine(XMLWriter::NEWLINE_LF);
writer.startDocument();
AttributesImpl attrs;
attrs.addAttribute("", "", "a1", "CDATA", "v1");
attrs.addAttribute("", "", "a2", "CDATA", "v2");
writer.startElement("", "", "el", attrs);
writer.endElement("", "", "el");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<el\n\ta1=\"v1\"\n\ta2=\"v2\"/>\n");
}
void XMLWriterTest::testData() void XMLWriterTest::testData()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3"); writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3");
writer.endDocument(); writer.endDocument();
std::string xml = str.str(); std::string xml = str.str();
assert (xml == "<d a1=\"v1\" a2=\"v2\" a3=\"v3\">data</d>"); assert (xml == "<d a1=\"v1\" a2=\"v2\" a3=\"v3\">data</d>");
} }
@@ -236,11 +266,11 @@ void XMLWriterTest::testData()
void XMLWriterTest::testEmptyData() void XMLWriterTest::testEmptyData()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.dataElement("", "", "d", "", "a1", "v1", "a2", "v2", "a3", "v3"); writer.dataElement("", "", "d", "", "a1", "v1", "a2", "v2", "a3", "v3");
writer.endDocument(); writer.endDocument();
std::string xml = str.str(); std::string xml = str.str();
assert (xml == "<d a1=\"v1\" a2=\"v2\" a3=\"v3\"/>"); assert (xml == "<d a1=\"v1\" a2=\"v2\" a3=\"v3\"/>");
} }
@@ -248,11 +278,11 @@ void XMLWriterTest::testEmptyData()
void XMLWriterTest::testDataPretty() void XMLWriterTest::testDataPretty()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n"); writer.setNewLine("\n");
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3"); writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3");
writer.endElement("", "", "r"); writer.endElement("", "", "r");
writer.endDocument(); writer.endDocument();
@@ -263,11 +293,11 @@ void XMLWriterTest::testDataPretty()
void XMLWriterTest::testEmptyDataPretty() void XMLWriterTest::testEmptyDataPretty()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n"); writer.setNewLine("\n");
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.dataElement("", "", "d", "", "a1", "v1", "a2", "v2", "a3", "v3"); writer.dataElement("", "", "d", "", "a1", "v1", "a2", "v2", "a3", "v3");
writer.endElement("", "", "r"); writer.endElement("", "", "r");
writer.endDocument(); writer.endDocument();
@@ -278,11 +308,11 @@ void XMLWriterTest::testEmptyDataPretty()
void XMLWriterTest::testComment() void XMLWriterTest::testComment()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n"); writer.setNewLine("\n");
writer.startDocument(); writer.startDocument();
writer.comment("a comment", 0, 9); writer.comment("a comment", 0, 9);
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.comment("<another comment>", 0, 17); writer.comment("<another comment>", 0, 17);
writer.dataElement("", "", "d", "data"); writer.dataElement("", "", "d", "data");
@@ -295,11 +325,11 @@ void XMLWriterTest::testComment()
void XMLWriterTest::testPI() void XMLWriterTest::testPI()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
writer.setNewLine("\n"); writer.setNewLine("\n");
writer.startDocument(); writer.startDocument();
writer.processingInstruction("target", "a processing instruction"); writer.processingInstruction("target", "a processing instruction");
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.processingInstruction("target", "another processing instruction"); writer.processingInstruction("target", "another processing instruction");
writer.dataElement("", "", "d", "data"); writer.dataElement("", "", "d", "data");
@@ -312,11 +342,11 @@ void XMLWriterTest::testPI()
void XMLWriterTest::testCharacters() void XMLWriterTest::testCharacters()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.characters("some \"chars\" that <must> be & escaped"); writer.characters("some \"chars\" that <must> be & escaped");
writer.endElement("", "", "r"); writer.endElement("", "", "r");
writer.endDocument(); writer.endDocument();
std::string xml = str.str(); std::string xml = str.str();
@@ -326,11 +356,11 @@ void XMLWriterTest::testCharacters()
void XMLWriterTest::testEmptyCharacters() void XMLWriterTest::testEmptyCharacters()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.characters(""); writer.characters("");
writer.endElement("", "", "r"); writer.endElement("", "", "r");
writer.endDocument(); writer.endDocument();
std::string xml = str.str(); std::string xml = str.str();
@@ -340,11 +370,11 @@ void XMLWriterTest::testEmptyCharacters()
void XMLWriterTest::testCDATA() void XMLWriterTest::testCDATA()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.startCDATA(); writer.startCDATA();
writer.characters("some \"chars\" that <must> be & escaped"); writer.characters("some \"chars\" that <must> be & escaped");
writer.endCDATA(); writer.endCDATA();
writer.endElement("", "", "r"); writer.endElement("", "", "r");
@@ -356,11 +386,11 @@ void XMLWriterTest::testCDATA()
void XMLWriterTest::testRawCharacters() void XMLWriterTest::testRawCharacters()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.startCDATA(); writer.startCDATA();
writer.rawCharacters("some \"chars\" that <must> be & escaped"); writer.rawCharacters("some \"chars\" that <must> be & escaped");
writer.endCDATA(); writer.endCDATA();
writer.endElement("", "", "r"); writer.endElement("", "", "r");
@@ -370,13 +400,29 @@ void XMLWriterTest::testRawCharacters()
} }
void XMLWriterTest::testAttributeCharacters()
{
std::ostringstream str;
XMLWriter writer(str, 0);
writer.startDocument();
AttributesImpl attrs;
attrs.addAttribute("", "", "a1", "CDATA", "a b c\n\td");
attrs.addAttribute("", "", "a2", "CDATA", "a b c\r\nd");
writer.startElement("", "", "el", attrs);
writer.endElement("", "", "el");
writer.endDocument();
std::string xml = str.str();
assert (xml == "<el a1=\"a b c&#xA;&#x9;d\" a2=\"a b c&#xD;&#xA;d\"/>");
}
void XMLWriterTest::testDefaultNamespace() void XMLWriterTest::testDefaultNamespace()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startPrefixMapping("", "urn:ns"); writer.startPrefixMapping("", "urn:ns");
writer.startElement("", "", "r"); writer.startElement("", "", "r");
writer.characters("data"); writer.characters("data");
writer.endElement("", "", "r"); writer.endElement("", "", "r");
writer.endPrefixMapping(""); writer.endPrefixMapping("");
@@ -388,11 +434,11 @@ void XMLWriterTest::testDefaultNamespace()
void XMLWriterTest::testQNamespaces() void XMLWriterTest::testQNamespaces()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("urn:ns", "r", "p:r"); writer.startElement("urn:ns", "r", "p:r");
writer.characters("data"); writer.characters("data");
writer.endElement("urn:ns", "r", "p:r"); writer.endElement("urn:ns", "r", "p:r");
writer.endDocument(); writer.endDocument();
std::string xml = str.str(); std::string xml = str.str();
@@ -402,11 +448,11 @@ void XMLWriterTest::testQNamespaces()
void XMLWriterTest::testQNamespacesNested() void XMLWriterTest::testQNamespacesNested()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("urn:ns", "r", "p:r"); writer.startElement("urn:ns", "r", "p:r");
writer.startElement("urn:ns", "e", "p:e"); writer.startElement("urn:ns", "e", "p:e");
writer.endElement("urn:ns", "e", "p:e"); writer.endElement("urn:ns", "e", "p:e");
writer.endElement("urn:ns", "r", "p:r"); writer.endElement("urn:ns", "r", "p:r");
writer.endDocument(); writer.endDocument();
@@ -417,11 +463,11 @@ void XMLWriterTest::testQNamespacesNested()
void XMLWriterTest::testNamespaces() void XMLWriterTest::testNamespaces()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("urn:ns", "r", ""); writer.startElement("urn:ns", "r", "");
writer.characters("data"); writer.characters("data");
writer.endElement("urn:ns", "r", ""); writer.endElement("urn:ns", "r", "");
writer.endDocument(); writer.endDocument();
std::string xml = str.str(); std::string xml = str.str();
@@ -430,28 +476,28 @@ void XMLWriterTest::testNamespaces()
void XMLWriterTest::testAttributeNamespaces() void XMLWriterTest::testAttributeNamespaces()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
Poco::XML::AttributesImpl attrs; Poco::XML::AttributesImpl attrs;
attrs.addAttribute("urn:other", "myattr", "", "", "attrValue"); attrs.addAttribute("urn:other", "myattr", "", "", "attrValue");
attrs.addAttribute("urn:ns", "myattr2", "", "", "attrValue2"); attrs.addAttribute("urn:ns", "myattr2", "", "", "attrValue2");
writer.startDocument(); writer.startDocument();
writer.startElement("urn:ns", "r", "", attrs); writer.startElement("urn:ns", "r", "", attrs);
writer.characters("data"); writer.characters("data");
writer.endElement("urn:ns", "r", ""); writer.endElement("urn:ns", "r", "");
writer.endDocument(); writer.endDocument();
std::string xml = str.str(); std::string xml = str.str();
assert (xml == "<ns1:r myattr2=\"attrValue2\" ns2:myattr=\"attrValue\" xmlns:ns1=\"urn:ns\" xmlns:ns2=\"urn:other\">data</ns1:r>"); assert (xml == "<ns1:r myattr2=\"attrValue2\" ns2:myattr=\"attrValue\" xmlns:ns1=\"urn:ns\" xmlns:ns2=\"urn:other\">data</ns1:r>");
} }
void XMLWriterTest::testNamespacesNested() void XMLWriterTest::testNamespacesNested()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("urn:ns1", "r", ""); writer.startElement("urn:ns1", "r", "");
writer.startElement("urn:ns1", "e", ""); writer.startElement("urn:ns1", "e", "");
writer.endElement("urn:ns1", "e", ""); writer.endElement("urn:ns1", "e", "");
writer.startElement("urn:ns2", "f", ""); writer.startElement("urn:ns2", "f", "");
writer.endElement("urn:ns2", "f", ""); writer.endElement("urn:ns2", "f", "");
@@ -464,11 +510,11 @@ void XMLWriterTest::testNamespacesNested()
void XMLWriterTest::testExplicitNamespaces() void XMLWriterTest::testExplicitNamespaces()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startPrefixMapping("p1", "urn:ns1"); writer.startPrefixMapping("p1", "urn:ns1");
writer.startPrefixMapping("p2", "urn:ns2"); writer.startPrefixMapping("p2", "urn:ns2");
writer.startElement("urn:ns1", "r", ""); writer.startElement("urn:ns1", "r", "");
writer.startElement("urn:ns2", "e", ""); writer.startElement("urn:ns2", "e", "");
writer.endElement("urn:ns2", "e", ""); writer.endElement("urn:ns2", "e", "");
@@ -486,11 +532,11 @@ void XMLWriterTest::testExplicitNamespaces()
void XMLWriterTest::testWellformed() void XMLWriterTest::testWellformed()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "foo"); writer.startElement("", "", "foo");
try try
{ {
writer.endElement("", "", "bar"); writer.endElement("", "", "bar");
fail("not wellformed - must throw exception"); fail("not wellformed - must throw exception");
@@ -503,11 +549,11 @@ void XMLWriterTest::testWellformed()
void XMLWriterTest::testWellformedNested() void XMLWriterTest::testWellformedNested()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "foo"); writer.startElement("", "", "foo");
writer.startElement("", "", "bar"); writer.startElement("", "", "bar");
try try
{ {
writer.endElement("", "", "foo"); writer.endElement("", "", "foo");
@@ -521,11 +567,11 @@ void XMLWriterTest::testWellformedNested()
void XMLWriterTest::testWellformedNamespace() void XMLWriterTest::testWellformedNamespace()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("urn:ns1", "foo", ""); writer.startElement("urn:ns1", "foo", "");
writer.startElement("urn:ns2", "bar", ""); writer.startElement("urn:ns2", "bar", "");
try try
{ {
writer.endElement("urn:ns1", "bar", ""); writer.endElement("urn:ns1", "bar", "");
@@ -539,11 +585,11 @@ void XMLWriterTest::testWellformedNamespace()
void XMLWriterTest::testEmpty() void XMLWriterTest::testEmpty()
{ {
std::ostringstream str; std::ostringstream str;
XMLWriter writer(str, XMLWriter::CANONICAL); XMLWriter writer(str, XMLWriter::CANONICAL);
writer.startDocument(); writer.startDocument();
writer.startElement("", "", "foo"); writer.startElement("", "", "foo");
writer.startElement("", "", "bar"); writer.startElement("", "", "bar");
writer.emptyElement("", "", "empty"); writer.emptyElement("", "", "empty");
writer.endElement("", "", "bar"); writer.endElement("", "", "bar");
writer.endElement("", "", "foo"); writer.endElement("", "", "foo");
@@ -565,31 +611,34 @@ void XMLWriterTest::tearDown()
CppUnit::Test* XMLWriterTest::suite() CppUnit::Test* XMLWriterTest::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLWriterTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLWriterTest");
CppUnit_addTest(pSuite, XMLWriterTest, testTrivial); CppUnit_addTest(pSuite, XMLWriterTest, testTrivial);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDecl); CppUnit_addTest(pSuite, XMLWriterTest, testTrivialCanonical);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDeclPretty); CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDecl);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragment); CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDeclPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragment);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragmentPretty); CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragmentPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testDTDPretty); CppUnit_addTest(pSuite, XMLWriterTest, testDTDPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testDTD); CppUnit_addTest(pSuite, XMLWriterTest, testDTD);
CppUnit_addTest(pSuite, XMLWriterTest, testDTDNotation); CppUnit_addTest(pSuite, XMLWriterTest, testDTDNotation);
CppUnit_addTest(pSuite, XMLWriterTest, testDTDEntity); CppUnit_addTest(pSuite, XMLWriterTest, testDTDEntity);
CppUnit_addTest(pSuite, XMLWriterTest, testAttributes); CppUnit_addTest(pSuite, XMLWriterTest, testAttributes);
CppUnit_addTest(pSuite, XMLWriterTest, testData); CppUnit_addTest(pSuite, XMLWriterTest, testAttributesPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testEmptyData); CppUnit_addTest(pSuite, XMLWriterTest, testData);
CppUnit_addTest(pSuite, XMLWriterTest, testDataPretty); CppUnit_addTest(pSuite, XMLWriterTest, testEmptyData);
CppUnit_addTest(pSuite, XMLWriterTest, testDataPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testEmptyDataPretty); CppUnit_addTest(pSuite, XMLWriterTest, testEmptyDataPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testComment); CppUnit_addTest(pSuite, XMLWriterTest, testComment);
CppUnit_addTest(pSuite, XMLWriterTest, testPI); CppUnit_addTest(pSuite, XMLWriterTest, testPI);
CppUnit_addTest(pSuite, XMLWriterTest, testCharacters); CppUnit_addTest(pSuite, XMLWriterTest, testCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testEmptyCharacters); CppUnit_addTest(pSuite, XMLWriterTest, testEmptyCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testCDATA); CppUnit_addTest(pSuite, XMLWriterTest, testCDATA);
CppUnit_addTest(pSuite, XMLWriterTest, testRawCharacters); CppUnit_addTest(pSuite, XMLWriterTest, testRawCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testDefaultNamespace); CppUnit_addTest(pSuite, XMLWriterTest, testAttributeCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testQNamespaces); CppUnit_addTest(pSuite, XMLWriterTest, testDefaultNamespace);
CppUnit_addTest(pSuite, XMLWriterTest, testQNamespacesNested); CppUnit_addTest(pSuite, XMLWriterTest, testQNamespaces);
CppUnit_addTest(pSuite, XMLWriterTest, testQNamespacesNested);
CppUnit_addTest(pSuite, XMLWriterTest, testNamespaces); CppUnit_addTest(pSuite, XMLWriterTest, testNamespaces);
CppUnit_addTest(pSuite, XMLWriterTest, testAttributeNamespaces); CppUnit_addTest(pSuite, XMLWriterTest, testAttributeNamespaces);
CppUnit_addTest(pSuite, XMLWriterTest, testNamespacesNested); CppUnit_addTest(pSuite, XMLWriterTest, testNamespacesNested);

View File

@@ -44,31 +44,34 @@ class XMLWriterTest: public CppUnit::TestCase
{ {
public: public:
XMLWriterTest(const std::string& name); XMLWriterTest(const std::string& name);
~XMLWriterTest(); ~XMLWriterTest();
void testTrivial(); void testTrivial();
void testTrivialDecl(); void testTrivialCanonical();
void testTrivialDeclPretty(); void testTrivialDecl();
void testTrivialFragment(); void testTrivialDeclPretty();
void testTrivialFragment();
void testTrivialFragmentPretty(); void testTrivialFragmentPretty();
void testDTDPretty(); void testDTDPretty();
void testDTD(); void testDTD();
void testDTDNotation(); void testDTDNotation();
void testDTDEntity(); void testDTDEntity();
void testAttributes(); void testAttributes();
void testData(); void testAttributesPretty();
void testEmptyData(); void testData();
void testDataPretty(); void testEmptyData();
void testDataPretty();
void testEmptyDataPretty(); void testEmptyDataPretty();
void testComment(); void testComment();
void testPI(); void testPI();
void testCharacters(); void testCharacters();
void testEmptyCharacters(); void testEmptyCharacters();
void testCDATA(); void testCDATA();
void testRawCharacters(); void testRawCharacters();
void testDefaultNamespace(); void testAttributeCharacters();
void testQNamespaces(); void testDefaultNamespace();
void testQNamespacesNested(); void testQNamespaces();
void testQNamespacesNested();
void testNamespaces(); void testNamespaces();
void testNamespacesNested(); void testNamespacesNested();
void testExplicitNamespaces(); void testExplicitNamespaces();