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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
// //////////////////////////////////////////////////////////////////////////
// Implementation file TestRunnerModel.cpp for class TestRunnerModel
// (c)Copyright 2000, Baptiste Lepilleur.
// Created: 2001/04/26
// //////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "TestRunnerModel.h"
#include <algorithm>
#include <cppunit/testsuite.h>
TestRunnerModel::TestRunnerModel( CppUnit::Test *rootTest ) :
m_autorunOnLaunch( true ),
m_rootTest( rootTest )
{
}
TestRunnerModel::~TestRunnerModel()
{
}
bool
TestRunnerModel::autorunOnLaunch() const
{
return m_autorunOnLaunch;
}
void
TestRunnerModel::setAutorunOnLaunch( bool autorunOnLaunch )
{
m_autorunOnLaunch = autorunOnLaunch;
}
const TestRunnerModel::History &
TestRunnerModel::history() const
{
return m_history;
}
void
TestRunnerModel::selectHistoryTest( CppUnit::Test *test )
{
History::iterator end =
std::remove( m_history.begin(), m_history.end(), test );
m_history.erase( end, m_history.end() );
if ( test != NULL )
m_history.push_front( test );
}
CppUnit::Test *
TestRunnerModel::selectedTest() const
{
if ( m_history.size() > 0 )
return m_history[0];
return NULL;
}
void
TestRunnerModel::loadSettings()
{
CWinApp *app = AfxGetApp();
ASSERT( app != NULL );
int autorun = app->GetProfileInt( "CppUnit",
"AutorunAtStartup",
1 );
m_autorunOnLaunch = (autorun == 1);
m_history.clear();
int idx = 1;
do
{
std::string testName = loadHistoryEntry( idx++ );
if ( testName.empty() )
break;
CppUnit::Test *test = findTestByName( testName );
if ( test != NULL )
m_history.push_back( test );
}
while ( true );
}
std::string
TestRunnerModel::loadHistoryEntry( int idx )
{
CWinApp *app = AfxGetApp();
ASSERT( app != NULL );
return std::string(
app->GetProfileString( "CppUnit",
getHistoryEntryName( idx ).c_str() ) );
}
void
TestRunnerModel::saveSettings()
{
CWinApp *app = AfxGetApp();
ASSERT( app != NULL );
int autorun = m_autorunOnLaunch ? 1 : 0;
app->WriteProfileInt( "CppUnit", "AutorunAtStartup", autorun );
int idx = 1;
for ( History::const_iterator it = m_history.begin();
it != m_history.end();
++it , ++idx )
{
CppUnit::Test *test = *it;
saveHistoryEntry( idx, test->getName() );
}
}
void
TestRunnerModel::saveHistoryEntry( int idx,
std::string testName )
{
CWinApp *app = AfxGetApp();
ASSERT( app != NULL );
app->WriteProfileString( "CppUnit",
getHistoryEntryName( idx ).c_str(),
testName.c_str() );
}
std::string
TestRunnerModel::getHistoryEntryName( int idx ) const
{
char entry[20];
::sprintf( entry, "HistoryTest%d", idx );
return std::string( entry );
}
CppUnit::Test *
TestRunnerModel::rootTest()
{
return m_rootTest;
}
void
TestRunnerModel::setRootTest( CppUnit::Test *test )
{
m_rootTest = test;
}
CppUnit::Test *
TestRunnerModel::findTestByName( std::string name ) const
{
return findTestByNameFor( name, m_rootTest );
}
CppUnit::Test *
TestRunnerModel::findTestByNameFor( const std::string &name,
CppUnit::Test *test ) const
{
if ( name == test->getName() )
return test;
CppUnit::TestSuite *suite = dynamic_cast<CppUnit::TestSuite *>(test);
if ( suite == NULL )
return NULL;
const std::vector<CppUnit::Test *> &tests = suite->getTests();
for ( std::vector<CppUnit::Test *>::const_iterator it = tests.begin();
it != tests.end();
++it )
{
CppUnit::Test *testFound = findTestByNameFor( name, *it );
if ( testFound != NULL )
return testFound;
}
return NULL;
}
|