Comparison with a hard-coded quoted string in C ++

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:

//assignment
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()); // gtests macro

output:

Value of: printer.CStr()
Actual: "<element type="correct" />"
Expected: intended
Which is: "<element type=\"correct\" />"
+4
source share
1 answer

googletest Primer , ASSERT_EQ() . ( , ). , ASSERT_STREQ().

ASSERT_STREQ(intended, printer.CStr());
+12

Source: https://habr.com/ru/post/1531443/


All Articles