Skip to content

Commit 0c07a4e

Browse files
committed
test
1 parent ffe7e9b commit 0c07a4e

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎gui/test/xmlreportv2/testxmlreportv2.cpp‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include "erroritem.h"
2222
#include "xmlreportv2.h"
2323

24+
#include <QFile>
2425
#include <QList>
26+
#include <QTemporaryDir>
2527
#include <QtTest>
2628

2729
void TestXmlReportV2::readXml() const
@@ -53,4 +55,39 @@ void TestXmlReportV2::readXml() const
5355
QCOMPARE(item2.message, QString("Mismatching allocation and deallocation: k"));
5456
}
5557

58+
void TestXmlReportV2::writeXmlEscaping() const
59+
{
60+
QTemporaryDir dir;
61+
const QString path = dir.path() + "/results.xml";
62+
63+
ErrorItem item;
64+
item.errorId = "id";
65+
item.severity = Severity::style;
66+
item.summary = "\"x\" & <y> &quot;";
67+
item.message = item.summary;
68+
QErrorPathItem loc;
69+
loc.file = "a&b.cpp";
70+
loc.line = 1;
71+
item.errorPath << loc;
72+
{
73+
XmlReportV2 report(path, QString());
74+
QVERIFY(report.create());
75+
report.writeHeader();
76+
report.writeError(item);
77+
report.writeFooter();
78+
}
79+
80+
QFile file(path);
81+
QVERIFY(file.open(QIODevice::ReadOnly));
82+
QVERIFY(file.readAll().contains("msg=\"&quot;x&quot; &amp; &lt;y&gt; &amp;quot;\""));
83+
84+
XmlReportV2 report(path, QString());
85+
QVERIFY(report.open());
86+
const QList<ErrorItem> errors = report.read();
87+
QCOMPARE(errors.size(), 1);
88+
QCOMPARE(errors[0].summary, item.summary);
89+
QCOMPARE(errors[0].message, item.message);
90+
QCOMPARE(errors[0].errorPath[0].file, loc.file);
91+
}
92+
5693
QTEST_MAIN(TestXmlReportV2)

‎gui/test/xmlreportv2/testxmlreportv2.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ class TestXmlReportV2 : public QObject {
2323

2424
private slots:
2525
void readXml() const;
26+
void writeXmlEscaping() const;
2627
};

0 commit comments

Comments
 (0)