Skip to content

Commit f87d0e3

Browse files
committed
Add test for new and default behaviour
1 parent 487f42a commit f87d0e3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

xmltest.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,41 @@ int main( int argc, const char ** argv )
26952695
XMLTest("Test attribute encode with a Hex value", value5, "!"); // hex value in unicode value
26962696
}
26972697

2698+
// ---------- XMLPrinter Apos Escaping ------
2699+
{
2700+
const char* testText = "text containing a ' character";
2701+
XMLDocument doc;
2702+
XMLElement* element = doc.NewElement( "element" );
2703+
doc.InsertEndChild( element );
2704+
element->SetAttribute( "attrib", testText );
2705+
{
2706+
XMLPrinter defaultPrinter;
2707+
doc.Print( &defaultPrinter );
2708+
const char* defaultOutput = defaultPrinter.CStr();
2709+
const bool foundTextWithUnescapedApos = (strstr(defaultOutput, testText) != nullptr);
2710+
XMLTest("Default XMLPrinter should escape ' characters", false, foundTextWithUnescapedApos);
2711+
{
2712+
XMLDocument parsingDoc;
2713+
parsingDoc.Parse(defaultOutput);
2714+
const XMLAttribute* attrib = parsingDoc.FirstChildElement("element")->FindAttribute("attrib");
2715+
XMLTest("Default XMLPrinter should output parsable xml", testText, attrib->Value(), true);
2716+
}
2717+
}
2718+
{
2719+
XMLPrinter customPrinter(0, false, 0, XMLPrinter::DONT_ESCAPE_APOS_CHARS_IN_ATTRIBUTES);
2720+
doc.Print( &customPrinter );
2721+
const char* customOutput = customPrinter.CStr();
2722+
const bool foundTextWithUnescapedApos = (strstr(customOutput, testText) != nullptr);
2723+
XMLTest("Custom XMLPrinter should not escape ' characters", true, foundTextWithUnescapedApos);
2724+
{
2725+
XMLDocument parsingDoc;
2726+
parsingDoc.Parse(customOutput);
2727+
const XMLAttribute* attrib = parsingDoc.FirstChildElement("element")->FindAttribute("attrib");
2728+
XMLTest("Custom XMLPrinter should output parsable xml", testText, attrib->Value(), true);
2729+
}
2730+
}
2731+
}
2732+
26982733
// ----------- Performance tracking --------------
26992734
{
27002735
#if defined( _MSC_VER )

0 commit comments

Comments
 (0)