1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Test program for wxWidgets
4 // Author: Mike Wetherell
6 // Copyright: (c) 2004 Mike Wetherell
7 // Licence: wxWidgets licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(__APPLE__)
11 #pragma implementation
15 // For compilers that support precompilation, includes "wx/wx.h".
16 #include "wx/wxprec.h"
22 // for all others, include the necessary headers
27 #include "wx/cmdline.h"
28 #include "wx/cppunit.h"
32 using namespace CppUnit
;
34 // The application class
36 class TestApp
: public wxAppConsole
42 void OnInitCmdLine(wxCmdLineParser
& parser
);
43 bool OnCmdLineParsed(wxCmdLineParser
& parser
);
48 void List(Test
*test
, const string
& parent
= "") const;
50 // command lines options/parameters
53 vector
<string
> m_registries
;
56 IMPLEMENT_APP_CONSOLE(TestApp
)
66 bool TestApp::OnInit()
68 cout
<< "Test program for wxWidgets\n"
69 << "build: " << WX_BUILD_OPTIONS_SIGNATURE
<< endl
;
70 return wxAppConsole::OnInit();
73 // The table of command line options
75 void TestApp::OnInitCmdLine(wxCmdLineParser
& parser
)
77 wxAppConsole::OnInitCmdLine(parser
);
79 static const wxCmdLineEntryDesc cmdLineDesc
[] = {
80 { wxCMD_LINE_SWITCH
, _T("l"), _T("list"),
81 _T("list the test suites, do not run them"),
82 wxCMD_LINE_VAL_NONE
, 0 },
83 { wxCMD_LINE_SWITCH
, _T("L"), _T("longlist"),
84 _T("list the test cases, do not run them"),
85 wxCMD_LINE_VAL_NONE
, 0 },
86 { wxCMD_LINE_PARAM
, 0, 0, _T("REGISTRY"), wxCMD_LINE_VAL_STRING
,
87 wxCMD_LINE_PARAM_OPTIONAL
| wxCMD_LINE_PARAM_MULTIPLE
},
88 { wxCMD_LINE_NONE
, 0, 0, 0, wxCMD_LINE_VAL_NONE
, 0 }
91 parser
.SetDesc(cmdLineDesc
);
94 // Handle command line options
96 bool TestApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
98 if (parser
.GetParamCount())
99 for (size_t i
= 0; i
< parser
.GetParamCount(); i
++)
100 m_registries
.push_back(string(parser
.GetParam(i
).mb_str()));
102 m_registries
.push_back("");
104 m_longlist
= parser
.Found(_T("longlist"));
105 m_list
= m_longlist
|| parser
.Found(_T("list"));
107 return wxAppConsole::OnCmdLineParsed(parser
);
114 TextUi::TestRunner runner
;
116 for (size_t i
= 0; i
< m_registries
.size(); i
++) {
117 auto_ptr
<Test
> test(m_registries
[i
].empty() ?
118 TestFactoryRegistry::getRegistry().makeTest() :
119 TestFactoryRegistry::getRegistry(m_registries
[i
]).makeTest());
121 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
.get());
123 if (suite
&& suite
->countTestCases() == 0)
124 wxLogError(_T("No such test suite: %s"),
125 wxString(m_registries
[i
].c_str(), wxConvUTF8
).c_str());
129 runner
.addTest(test
.release());
132 // Switch off logging unless --verbose
133 wxLog::EnableLogging(wxLog::GetVerbose());
135 return m_list
|| runner
.run("", false, true, !wxLog::GetVerbose()) ?
136 EXIT_SUCCESS
: EXIT_FAILURE
;
141 void TestApp::List(Test
*test
, const string
& parent
/*=""*/) const
143 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
);
147 // take the last component of the name and append to the parent
148 name
= test
->getName();
149 string::size_type i
= name
.find_last_of(".:");
150 name
= parent
+ "." + (i
!= string::npos
? name
.substr(i
+ 1) : name
);
152 // drop the 1st component from the display and indent
154 string::size_type j
= i
= name
.find('.', 1);
155 while ((j
= name
.find('.', j
+ 1)) != string::npos
)
157 cout
<< " " << name
.substr(i
+ 1) << "\n";
160 typedef vector
<Test
*> Tests
;
161 typedef Tests::const_iterator Iter
;
163 const Tests
& tests
= suite
->getTests();
165 for (Iter it
= tests
.begin(); it
!= tests
.end(); ++it
)
168 else if (m_longlist
) {
169 string::size_type i
= 0;
170 while ((i
= parent
.find('.', i
+ 1)) != string::npos
)
172 cout
<< " " << test
->getName() << "\n";