Skip to content

Commit 9f066f9

Browse files
author
Luis Díaz Más
committed
Supporting failures and cdata
1 parent b97068d commit 9f066f9

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

data/gtests.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<testcase name="shouldPerformOperationFool21" status="run" time="0" classname="TestSuite2" />
2727
<testcase name="shouldPerformOperationFool22" status="run" time="0" classname="TestSuite2" />
2828
</testsuite>
29-
<testsuite name="TestSuite3" tests="3" failures="0" disabled="0" errors="0" time="0.005">
29+
<testsuite name="TestSuite3" tests="4" failures="0" disabled="0" errors="0" time="0.005">
3030
<testcase name="shouldPerformOperationFool23" status="run" time="0.002" classname="TestSuite3" />
3131
<testcase name="shouldPerformOperationFool24" status="run" time="0.002" classname="TestSuite3" />
3232
<testcase name="shouldPerformOperationFool25" status="run" time="0.001" classname="TestSuite3" />

include/Types.h

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ struct TestCase
1818

1919
QString _name;
2020
QString _valid;
21+
QString _failureMsg;
22+
QString _cDATA;
2123
};
2224

2325
struct TestSuite

include/XmlJoiner.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class XmlJoiner
4242
private:
4343
void processTestSuiteAttrs(const QXmlStreamAttributes attrs);
4444
void processTestCaseAttrs(const QXmlStreamAttributes attrs);
45+
void processTestFailureAttrs(const QXmlStreamAttributes attrs);
46+
void processTestCDataAttrs(const QStringRef text);
4547

4648
void outputXmlHeader(QXmlStreamWriter &writer);
4749
void outputXmlElements(QXmlStreamWriter &writer);

src/XmlJoiner.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ void XmlJoiner::processFile(const QString absolutePath)
6969
}
7070
else if (xml.name() == "failure")
7171
{
72+
processTestFailureAttrs(xml.attributes());
73+
xml.readNext();
74+
Q_ASSERT(xml.isCDATA());
75+
processTestCDataAttrs(xml.text());
7276
}
7377
}
7478
}
@@ -86,6 +90,9 @@ void XmlJoiner::processTestSuiteAttrs(const QXmlStreamAttributes attrs)
8690
attrs.value("tests").toString().toInt(),
8791
attrs.value("failures").toString().toInt(),
8892
attrs.value("errors").toString().toInt());
93+
94+
/// \todo set "disabled" field
95+
/// \todo set "time" field
8996
_suites.push_back(suite);
9097
}
9198

@@ -107,6 +114,18 @@ void XmlJoiner::processTestCaseAttrs(const QXmlStreamAttributes attrs)
107114
suite->_cases.push_back(testCase);
108115
}
109116

117+
void XmlJoiner::processTestFailureAttrs(const QXmlStreamAttributes attrs)
118+
{
119+
TestCase *testCase = _suites.back()->_cases.back();
120+
testCase->_failureMsg = attrs.value("message").toString();
121+
}
122+
123+
void XmlJoiner::processTestCDataAttrs(const QStringRef text)
124+
{
125+
TestCase *testCase = _suites.back()->_cases.back();
126+
testCase->_cDATA.append(text);
127+
}
128+
110129
void XmlJoiner::writeOutput(const QString pathFile)
111130
{
112131
QFile outFile(pathFile);
@@ -150,12 +169,22 @@ void XmlJoiner::outputXmlElements(QXmlStreamWriter &writer)
150169
writer.writeAttribute("failures", QString::number(testSuite->_failures));
151170
writer.writeAttribute("errors", QString::number(testSuite->_errors));
152171

153-
foreach(const auto testCase, testSuite->_cases)
172+
for(const auto &testCase: testSuite->_cases)
154173
{
155174
writer.writeStartElement("testcase");
156175
writer.writeAttribute("name", testCase->_name);
157176
writer.writeAttribute("status", testCase->_valid);
158177
writer.writeAttribute("classname", testSuite->_name);
178+
179+
if (testCase->_failureMsg.isEmpty() == false)
180+
{
181+
writer.writeStartElement("failure");
182+
writer.writeAttribute("message", testCase->_failureMsg);
183+
writer.writeAttribute("type", "");
184+
writer.writeCDATA(testCase->_cDATA);
185+
writer.writeEndElement();
186+
}
187+
159188
writer.writeEndElement();
160189
}
161190

utils/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
if(BUILD_UTILS)
2+
include_directories(${PROJECT_SOURCE_DIR}/include)
23

34
add_executable(xml_join xml_join.cpp)
4-
target_link_libraries(xml_join ${PROJECT_NAME})
5+
target_link_libraries(xml_join ${PROJECT_NAME} ${ARGTABLE})
56

67
endif()

utils/xml_join.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <argtable2.h>
1616
#include <iostream>
1717

18+
using namespace TestsXml;
19+
using namespace TestsXml;
20+
1821
// ##### PROTOTYPES - LOCAL TO THIS SOURCE FILE ##################
1922
static void readArguments(int argc, char **argv);
2023

0 commit comments

Comments
 (0)