#include "QDomDocumentWithSpacesTest.h" #include #include #include #include #include auto parse(QString const& anInput) { QDomDocument doc; QXmlStreamReader sr(anInput); QString errorMessage; int errorLine; if (auto const parseOk = doc.setContent(&sr, true, &errorMessage, &errorLine); !parseOk) { qWarning() << "XML parsing failed: " << errorMessage << " [" << errorLine << "]"; } return doc; } void QDomDocumentWithSpacesTest::entityWithoutSpace() { // an XML document where has no content QString const xmlDocumentWithOutSpace = R"( )"; auto const doc = parse(xmlDocumentWithOutSpace); QCOMPARE(doc.firstChild().toElement().text(), ""); } void QDomDocumentWithSpacesTest::entityWithSpace() { // an XML document where has a whitespace as content QString const xmlDocumentWithSpace = R"( )"; auto const doc = parse(xmlDocumentWithSpace); QCOMPARE(doc.firstChild().toElement().text(), ""); } void QDomDocumentWithSpacesTest::entityWithSpaceAndPreserve() { // an XML document where has a whitespace as content and uses // xml:space="preserve" QString const xmlDocumentWithSpacePreserve = R"( )"; auto const doc = parse(xmlDocumentWithSpacePreserve); QCOMPARE(doc.firstChild().toElement().text(), " "); } QTEST_MAIN(QDomDocumentWithSpacesTest)