This repository was archived by the owner on Jul 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCBoostTestTreeLister.cpp
118 lines (91 loc) · 2.52 KB
/
CBoostTestTreeLister.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "CBoostTestTreeLister.h"
#include <iostream>
//suppression of warnings related to 3rd party files
#pragma warning ( disable: 6001 )
#pragma warning ( disable: 6031 )
#include <boost/test/utils/xml_printer.hpp>
//end suppression of warnings related to 3rd party files
#pragma warning ( default: 6001 )
#pragma warning ( default: 6031 )
namespace
{
std::ostream& noop(std::ostream& out)
{
return out;
};
// Utility function which is used to simply avoid writing '::boost::unit_test::attr_value()'
::boost::unit_test::attr_value attr_value()
{
return ::boost::unit_test::attr_value();
};
} // namespace anonymous
namespace etas
{
namespace boost
{
namespace unit_test
{
#define ENDLINE ((m_prettyPrint) ? static_cast<std::ostream& (*)(std::ostream&)>(std::endl) : noop)
CBoostTestTreeLister::CBoostTestTreeLister(const std::string& source) :
m_out(&std::cout),
m_source(source),
m_level(0),
m_prettyPrint(true)
{
WriteHeader();
}
CBoostTestTreeLister::CBoostTestTreeLister(const std::string& source, std::ostream* out) :
m_out(out),
m_source(source),
m_level(0),
m_prettyPrint(true)
{
}
CBoostTestTreeLister::~CBoostTestTreeLister()
{
}
void CBoostTestTreeLister::visit(const ::boost::unit_test::test_case& testCase)
{
Tab() << "<TestCase id" << attr_value() << testCase.p_id << " name" << attr_value() << testCase.p_name.value << " />" << ENDLINE;
}
bool CBoostTestTreeLister::test_suite_start(const ::boost::unit_test::test_suite& testSuite)
{
Tab() << "<TestSuite id" << attr_value() << testSuite.p_id << " name" << attr_value() << testSuite.p_name.value << '>' << ENDLINE;
++m_level;
return true;
}
void CBoostTestTreeLister::test_suite_finish(const ::boost::unit_test::test_suite& testSuite)
{
m_level = (m_level == 0) ? 0 : (m_level - 1);
Tab() << "</TestSuite>" << ENDLINE;
}
std::ostream& CBoostTestTreeLister::WriteHeader()
{
Out() << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << ENDLINE
<< "<BoostTestFramework source" << attr_value() << m_source << '>' << ENDLINE;
++m_level;
return Out();
}
std::ostream& CBoostTestTreeLister::WriteTrailer()
{
--m_level;
return Out() << "</BoostTestFramework>" << ENDLINE;
}
std::ostream& CBoostTestTreeLister::Tab()
{
if (m_prettyPrint)
{
for (std::size_t i = 0; i < m_level; ++i)
{
Out() << " ";
}
}
return Out();
}
std::ostream& CBoostTestTreeLister::Out()
{
return *m_out;
}
} // namespace unit_test
} // namespace boost
} // namespace etas