Repository navigation
Expand file tree
/
Copy pathtest.cpp
More file actions
195 lines (161 loc) · 5.13 KB
/
Copy pathtest.cpp
File metadata and controls
195 lines (161 loc) · 5.13 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
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
192
193
194
195
///////////////////////////////////////////////////////////////////////////////
// Name: test.cpp
// Purpose: Test program for wxWidgets
// Author: Mike Wetherell
// RCS-ID: $Id$
// Copyright: (c) 2004 Mike Wetherell
// Licence: wxWidgets licence
///////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h"
// and "wx/cppunit.h"
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/cmdline.h"
#include <iostream>
using CppUnit::Test;
using CppUnit::TestSuite;
using CppUnit::TestFactoryRegistry;
using CppUnit::TextUi::TestRunner;
using CppUnit::CompilerOutputter;
using std::string;
using std::vector;
using std::auto_ptr;
using std::cout;
// The application class
//
class TestApp : public wxAppConsole
{
public:
TestApp();
// standard overrides
void OnInitCmdLine(wxCmdLineParser& parser);
bool OnCmdLineParsed(wxCmdLineParser& parser);
bool OnInit();
int OnRun();
private:
void List(Test *test, const string& parent = "") const;
// command lines options/parameters
bool m_list;
bool m_longlist;
vector<string> m_registries;
};
IMPLEMENT_APP_CONSOLE(TestApp)
TestApp::TestApp()
: m_list(false),
m_longlist(false)
{
}
// Init
//
bool TestApp::OnInit()
{
cout << "Test program for wxWidgets\n"
<< "build: " << WX_BUILD_OPTIONS_SIGNATURE << std::endl;
#if !wxUSE_WXVSNPRINTF
cout << "\n";
cout << "WARNING: VsnprintfTestCase will test the system vsnprintf() function\n";
cout << " instead of the wxWidgets wxVsnprintf_ implementation!" << std::endl;
cout << "\n";
#endif
return wxAppConsole::OnInit();
};
// The table of command line options
//
void TestApp::OnInitCmdLine(wxCmdLineParser& parser)
{
wxAppConsole::OnInitCmdLine(parser);
static const wxCmdLineEntryDesc cmdLineDesc[] = {
{ wxCMD_LINE_SWITCH, _T("l"), _T("list"),
_T("list the test suites, do not run them"),
wxCMD_LINE_VAL_NONE, 0 },
{ wxCMD_LINE_SWITCH, _T("L"), _T("longlist"),
_T("list the test cases, do not run them"),
wxCMD_LINE_VAL_NONE, 0 },
{ wxCMD_LINE_PARAM, 0, 0, _T("REGISTRY"), wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
{ wxCMD_LINE_NONE , 0, 0, 0, wxCMD_LINE_VAL_NONE, 0 }
};
parser.SetDesc(cmdLineDesc);
}
// Handle command line options
//
bool TestApp::OnCmdLineParsed(wxCmdLineParser& parser)
{
if (parser.GetParamCount())
for (size_t i = 0; i < parser.GetParamCount(); i++)
m_registries.push_back(string(parser.GetParam(i).mb_str()));
else
m_registries.push_back("");
m_longlist = parser.Found(_T("longlist"));
m_list = m_longlist || parser.Found(_T("list"));
return wxAppConsole::OnCmdLineParsed(parser);
}
// Run
//
int TestApp::OnRun()
{
TestRunner runner;
for (size_t i = 0; i < m_registries.size(); i++) {
auto_ptr<Test> test(m_registries[i].empty() ?
TestFactoryRegistry::getRegistry().makeTest() :
TestFactoryRegistry::getRegistry(m_registries[i]).makeTest());
TestSuite *suite = dynamic_cast<TestSuite*>(test.get());
if (suite && suite->countTestCases() == 0)
wxLogError(_T("No such test suite: %s"),
wxString(m_registries[i].c_str(), wxConvUTF8).c_str());
else if (m_list)
List(test.get());
else
runner.addTest(test.release());
}
runner.setOutputter(new CompilerOutputter(&runner.result(), cout));
#if wxUSE_LOG
// Switch off logging unless --verbose
bool verbose = wxLog::GetVerbose();
wxLog::EnableLogging(verbose);
#else
bool verbose = false;
#endif
return ( m_list || runner.run("", false, true, !verbose) )
? EXIT_SUCCESS
: EXIT_FAILURE;
}
// List the tests
//
void TestApp::List(Test *test, const string& parent /*=""*/) const
{
TestSuite *suite = dynamic_cast<TestSuite*>(test);
string name;
if (suite) {
// take the last component of the name and append to the parent
name = test->getName();
string::size_type i = name.find_last_of(".:");
if (i != string::npos)
name = name.substr(i + 1);
name = parent + "." + name;
// drop the 1st component from the display and indent
if (parent != "") {
string::size_type j = i = name.find('.', 1);
while ((j = name.find('.', j + 1)) != string::npos)
cout << " ";
cout << " " << name.substr(i + 1) << "\n";
}
typedef vector<Test*> Tests;
typedef Tests::const_iterator Iter;
const Tests& tests = suite->getTests();
for (Iter it = tests.begin(); it != tests.end(); ++it)
List(*it, name);
}
else if (m_longlist) {
string::size_type i = 0;
while ((i = parent.find('.', i + 1)) != string::npos)
cout << " ";
cout << " " << test->getName() << "\n";
}
}