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()
{
}
@@ -653,6 +927,8 @@ CppUnit::Test* ElementTest::suite()
CppUnit_addTest(pSuite, ElementTest, testInnerText);
CppUnit_addTest(pSuite, ElementTest, testChildElement);
CppUnit_addTest(pSuite, ElementTest, testChildElementNS);
CppUnit_addTest(pSuite, ElementTest, testNodeByPath);
CppUnit_addTest(pSuite, ElementTest, testNodeByPathNS);
return pSuite;
}

View File

@@ -55,6 +55,8 @@ public:
void testInnerText();
void testChildElement();
void testChildElementNS();
void testNodeByPath();
void testNodeByPathNS();
void setUp();
void tearDown();

View File

@@ -36,6 +36,7 @@
#include "Poco/DOM/DOMParser.h"
#include "Poco/DOM/DOMWriter.h"
#include "Poco/DOM/Document.h"
#include "Poco/DOM/Element.h"
#include "Poco/DOM/AutoPtr.h"
#include "Poco/SAX/InputSource.h"
#include "Poco/XML/XMLWriter.h"
@@ -90,7 +91,6 @@ void ParserWriterTest::testParseWriteXHTML2()
assert (xml == XHTML2);
}
void ParserWriterTest::testParseWriteWSDL()
{
std::istringstream istr(WSDL);
@@ -110,6 +110,39 @@ void ParserWriterTest::testParseWriteWSDL()
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);
}
void ParserWriterTest::setUp()
{
@@ -128,6 +161,7 @@ CppUnit::Test* ParserWriterTest::suite()
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML);
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML2);
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteWSDL);
CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteSimple);
return pSuite;
}

View File

@@ -49,6 +49,7 @@ public:
void testParseWriteXHTML();
void testParseWriteXHTML2();
void testParseWriteWSDL();
void testParseWriteSimple();
void setUp();
void tearDown();

View File

@@ -320,8 +320,18 @@ void SAXParserTest::testCharacters()
void SAXParserTest::testParseMemory()
{
SAXParser parser;
std::string xml = parseMemory(parser, XMLWriter::CANONICAL, ATTRIBUTES);
assert (xml == ATTRIBUTES);
std::string xml = parseMemory(parser, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT, WSDL);
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::ostringstream ostr;
XMLWriter writer(ostr, options);
writer.setNewLine(XMLWriter::NEWLINE_LF);
reader.setContentHandler(&writer);
reader.setDTDHandler(&writer);
reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&writer));
@@ -354,6 +365,7 @@ std::string SAXParserTest::parseMemory(XMLReader& reader, int options, const std
std::istringstream istr(data);
std::ostringstream ostr;
XMLWriter writer(ostr, options);
writer.setNewLine(XMLWriter::NEWLINE_LF);
reader.setContentHandler(&writer);
reader.setDTDHandler(&writer);
reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&writer));
@@ -386,8 +398,9 @@ CppUnit::Test* SAXParserTest::suite()
CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNoNamespace);
CppUnit_addTest(pSuite, SAXParserTest, testRSS);
CppUnit_addTest(pSuite, SAXParserTest, testEncoding);
CppUnit_addTest(pSuite, SAXParserTest, testParseMemory);
CppUnit_addTest(pSuite, SAXParserTest, testCharacters);
CppUnit_addTest(pSuite, SAXParserTest, testParseMemory);
CppUnit_addTest(pSuite, SAXParserTest, testParsePartialReads);
return pSuite;
}
@@ -1034,3 +1047,148 @@ const std::string SAXParserTest::RSS =
const std::string SAXParserTest::ENCODING =
"<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>"
"<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

@@ -69,6 +69,7 @@ public:
void testEncoding();
void testParseMemory();
void testCharacters();
void testParsePartialReads();
void setUp();
void tearDown();
@@ -96,6 +97,7 @@ public:
static const std::string XHTML_LATIN1_ENTITIES;
static const std::string RSS;
static const std::string ENCODING;
static const std::string WSDL;
};

View File

@@ -66,6 +66,19 @@ void XMLWriterTest::testTrivial()
}
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()
{
std::ostringstream str;
@@ -222,6 +235,23 @@ 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()
{
std::ostringstream str;
@@ -370,6 +400,22 @@ 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()
{
std::ostringstream str;
@@ -568,6 +614,7 @@ CppUnit::Test* XMLWriterTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLWriterTest");
CppUnit_addTest(pSuite, XMLWriterTest, testTrivial);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialCanonical);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDecl);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDeclPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragment);
@@ -577,6 +624,7 @@ CppUnit::Test* XMLWriterTest::suite()
CppUnit_addTest(pSuite, XMLWriterTest, testDTDNotation);
CppUnit_addTest(pSuite, XMLWriterTest, testDTDEntity);
CppUnit_addTest(pSuite, XMLWriterTest, testAttributes);
CppUnit_addTest(pSuite, XMLWriterTest, testAttributesPretty);
CppUnit_addTest(pSuite, XMLWriterTest, testData);
CppUnit_addTest(pSuite, XMLWriterTest, testEmptyData);
CppUnit_addTest(pSuite, XMLWriterTest, testDataPretty);
@@ -587,6 +635,7 @@ CppUnit::Test* XMLWriterTest::suite()
CppUnit_addTest(pSuite, XMLWriterTest, testEmptyCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testCDATA);
CppUnit_addTest(pSuite, XMLWriterTest, testRawCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testAttributeCharacters);
CppUnit_addTest(pSuite, XMLWriterTest, testDefaultNamespace);
CppUnit_addTest(pSuite, XMLWriterTest, testQNamespaces);
CppUnit_addTest(pSuite, XMLWriterTest, testQNamespacesNested);

View File

@@ -47,6 +47,7 @@ public:
~XMLWriterTest();
void testTrivial();
void testTrivialCanonical();
void testTrivialDecl();
void testTrivialDeclPretty();
void testTrivialFragment();
@@ -56,6 +57,7 @@ public:
void testDTDNotation();
void testDTDEntity();
void testAttributes();
void testAttributesPretty();
void testData();
void testEmptyData();
void testDataPretty();
@@ -66,6 +68,7 @@ public:
void testEmptyCharacters();
void testCDATA();
void testRawCharacters();
void testAttributeCharacters();
void testDefaultNamespace();
void testQNamespaces();
void testQNamespacesNested();