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
, int depth
= 0) const;
50 // command lines options/parameters
53 vector
<string
> m_registries
;
56 IMPLEMENT_APP_CONSOLE(TestApp
)
65 bool TestApp::OnInit()
67 cout
<< "Test program for wxWidgets\n"
68 << "build: " << WX_BUILD_OPTIONS_SIGNATURE
<< endl
;
69 return wxAppConsole::OnInit();
72 // The table of command line options
74 void TestApp::OnInitCmdLine(wxCmdLineParser
& parser
)
76 wxAppConsole::OnInitCmdLine(parser
);
78 static const wxCmdLineEntryDesc cmdLineDesc
[] = {
79 { wxCMD_LINE_SWITCH
, _T("l"), _T("list"),
80 _T("list the test suites, do not run them"),
81 wxCMD_LINE_VAL_NONE
, 0 },
82 { wxCMD_LINE_SWITCH
, _T("L"), _T("longlist"),
83 _T("list the test cases, do not run them"),
84 wxCMD_LINE_VAL_NONE
, 0 },
85 { wxCMD_LINE_PARAM
, 0, 0, _T("REGISTRY"), wxCMD_LINE_VAL_STRING
,
86 wxCMD_LINE_PARAM_OPTIONAL
| wxCMD_LINE_PARAM_MULTIPLE
},
87 { wxCMD_LINE_NONE
, 0, 0, 0, wxCMD_LINE_VAL_NONE
, 0 }
90 parser
.SetDesc(cmdLineDesc
);
93 // Handle command line options
95 bool TestApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
97 if (parser
.GetParamCount())
98 for (size_t i
= 0; i
< parser
.GetParamCount(); i
++)
99 m_registries
.push_back(string(parser
.GetParam(i
).mb_str()));
101 m_registries
.push_back("");
103 m_longlist
= parser
.Found(_T("longlist"));
104 m_list
= m_longlist
|| parser
.Found(_T("list"));
106 return wxAppConsole::OnCmdLineParsed(parser
);
113 TextUi::TestRunner runner
;
115 for (size_t i
= 0; i
< m_registries
.size(); i
++) {
116 auto_ptr
<Test
> test(m_registries
[i
].empty() ?
117 TestFactoryRegistry::getRegistry().makeTest() :
118 TestFactoryRegistry::getRegistry(m_registries
[i
]).makeTest());
120 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
.get());
122 if (suite
&& suite
->countTestCases() == 0)
123 wxLogError(_T("No such test suite: %s"),
124 wxString(m_registries
[i
].c_str(), wxConvUTF8
).c_str());
128 runner
.addTest(test
.release());
131 // Switch off logging unless --verbose
132 wxLog::EnableLogging(wxLog::GetVerbose());
134 return m_list
|| runner
.run("", false, true, !wxLog::GetVerbose()) ?
135 EXIT_SUCCESS
: EXIT_FAILURE
;
140 void TestApp::List(Test
*test
, int depth
/*=0*/) const
142 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
);
144 if (suite
|| m_longlist
)
145 cout
<< string(depth
* 2, ' ') << test
->getName() << "\n";
148 typedef const vector
<Test
*> Tests
;
149 typedef Tests::const_iterator Iter
;
151 Tests
& tests
= suite
->getTests();
153 for (Iter it
= tests
.begin(); it
!= tests
.end(); ++it
)
154 List(*it
, depth
+ 1);