forked from EbenZhang/kcppunitlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestresultxml.cpp
More file actions
101 lines (72 loc) · 2.7 KB
/
testresultxml.cpp
File metadata and controls
101 lines (72 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "tinyxml.h"
#include "testresultxml.h"
#ifdef _MSC_VER
#ifdef _DEBUG
#include "afx.h"
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#endif
using namespace CppUnitLite;
TestResultXml::TestResultXml( std::string szFilePath ) : m_szFilePath(szFilePath)
{
}
void TestResultXml::endTests()
{
TestResult::endTests();
TiXmlDocument doc;
////xml desc.
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
doc.LinkEndChild( decl );
TiXmlElement* pRoot = new TiXmlElement( "TestRun" );
doc.LinkEndChild(pRoot);
GenerateFailures(pRoot);
GenerateSuccess(pRoot);
GenerateStatistics(pRoot);
doc.SaveFile(m_szFilePath.c_str());
}
void TestResultXml::GenerateFailures( TiXmlElement* pParent )
{
TiXmlElement* pAllFailedTests = new TiXmlElement( "FailedTests" );
pParent->LinkEndChild(pAllFailedTests);
std::vector<Failure>::iterator iter = failures.begin();
std::vector<Failure>::iterator iterEnd = failures.end();
for (int id = successes.size();iter != iterEnd; ++iter,++id)
{
const Failure& fail = *iter;
TiXmlElement* pFailedTest = new TiXmlElement( "FailedTest" );
pAllFailedTests->LinkEndChild(pFailedTest);
pFailedTest->SetAttribute("id",id);
pFailedTest->SetAttribute("Name",fail.testName.c_str());
pFailedTest->SetAttribute("FailureType","fail");
TiXmlElement* pLocationInfo = new TiXmlElement( "Location" );
pFailedTest->LinkEndChild(pLocationInfo);
pLocationInfo->SetAttribute("File",fail.fileName.c_str());
pLocationInfo->SetAttribute("Line",fail.lineNumber);
pFailedTest->SetAttribute("Message",fail.condition.c_str());
}
}
void TestResultXml::GenerateSuccess( TiXmlElement* pParent )
{
TiXmlElement* pAllOKTest = new TiXmlElement( "SuccessfulTests" );
pParent->LinkEndChild(pAllOKTest);
std::vector<Success>::iterator iter = successes.begin();
std::vector<Success>::iterator iterEnd = successes.end();
for (int id = 0;iter != iterEnd; ++iter,++id)
{
const Success& success = *iter;
TiXmlElement* pTest = new TiXmlElement( "Test" );
pAllOKTest->LinkEndChild(pTest);
pTest->SetAttribute("id",id);//id
pTest->SetAttribute("Name",success.getTestName().c_str());
}
}
void TestResultXml::GenerateStatistics( TiXmlElement* pParent )
{
TiXmlElement* pStatistics = new TiXmlElement( "Statistics" );
pParent->LinkEndChild(pStatistics);
pStatistics->SetAttribute("Tests",testCount);
pStatistics->SetAttribute("FailuresTotal",failures.size());
}
//end of file