blob: 9d4e476c14b33da566c7179ffa8fb26f20b74f76 (
plain)
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
119
120
121
|
// //////////////////////////////////////////////////////////////////////////
// Implementation file DumperListener.cpp for class DumperListener
// (c)Copyright 2000, Baptiste Lepilleur.
// Created: 2002/04/19
// //////////////////////////////////////////////////////////////////////////
#include <cppunit/Test.h>
#include <cppunit/portability/Stream.h>
#include "DumperListener.h"
DumperListener::DumperListener( bool flatten )
: m_flatten( flatten )
, m_suiteCount( 0 )
, m_testCount( 0 )
, m_suiteWithTestCount( 0 )
{
}
DumperListener::~DumperListener()
{
}
void
DumperListener::startTest( CPPUNIT_NS::Test *test )
{
printPath( test, false );
++m_testCount;
}
void
DumperListener::endTest( CPPUNIT_NS::Test *test )
{
m_path.up();
if ( !m_suiteHasTest.empty() )
{
m_suiteHasTest.pop();
m_suiteHasTest.push( true );
}
}
void
DumperListener::startSuite( CPPUNIT_NS::Test *suite )
{
printPath( suite, true );
++m_suiteCount;
m_suiteHasTest.push( false );
}
void
DumperListener::endSuite( CPPUNIT_NS::Test *suite )
{
m_path.up();
if ( m_suiteHasTest.top() )
++m_suiteWithTestCount;
m_suiteHasTest.pop();
}
void
DumperListener::endTestRun( CPPUNIT_NS::Test *test,
CPPUNIT_NS::TestResult *eventManager )
{
double average = 0;
if ( m_suiteWithTestCount > 0 )
average = double(m_testCount) / m_suiteWithTestCount;
CPPUNIT_NS::stdCOut()
<< "Statistics: " << m_testCount << " test cases, "
<< m_suiteCount << " suites, "
<< average << " test cases / suite with test cases"
<< "\n";
}
void
DumperListener::printPath( CPPUNIT_NS::Test *test,
bool isSuite )
{
m_path.add( test );
if ( m_flatten )
printFlattenedPath( isSuite );
else
printIndentedPathChild();
}
void
DumperListener::printFlattenedPath( bool isSuite )
{
std::string path = m_path.toString();
if ( isSuite )
path += "/";
CPPUNIT_NS::stdCOut() << path << "\n";
}
void
DumperListener::printIndentedPathChild()
{
std::string indent = makeIndentString( m_path.getTestCount() -1 );
CPPUNIT_NS::stdCOut() << indent << m_path.getChildTest()->getName() << "\n";
}
std::string
DumperListener::makeIndentString( int indentLevel )
{
std::string indent;
for ( int parentIndent =0; parentIndent < indentLevel-1; ++parentIndent )
indent += "| ";
if ( indentLevel > 0 )
indent += "+--";
return indent;
}
|