I am writing a C ++ function to create XML using TinyXML. I would like to verify that the (relatively small) tree created by my function turns into a string identical to the reference string.
// intended XML:
<element type="correct" />
It seems that the easiest way to do this comparison is to copy the link string into the code:
std::string intended = "<element type=\"correct\" />";
However, backslashes, in order to avoid quotes, do not allow comparison with the subsequent one.
#include <tinyxml.h>
#include <string.h>
TiXmlElement test = TiXmlElement("element");
test.SetAttribute("type", "correct");
TiXmlPrinter printer;
test.Accept(&printer);
ASSERT_EQ(intended, printer.CStr());
output:
Value of: printer.CStr()
Actual: "<element type="correct" />"
Expected: intended
Which is: "<element type=\"correct\" />"
source
share