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
55 IMPLEMENT_APP_CONSOLE(TestApp
)
64 bool TestApp::OnInit()
66 cout
<< "Test program for wxWidgets\n"
67 << "build: " << WX_BUILD_OPTIONS_SIGNATURE
<< endl
;
68 return wxAppConsole::OnInit();
71 // The table of command line options
73 void TestApp::OnInitCmdLine(wxCmdLineParser
& parser
)
75 wxAppConsole::OnInitCmdLine(parser
);
77 static const wxCmdLineEntryDesc cmdLineDesc
[] = {
78 { wxCMD_LINE_SWITCH
, _T("l"), _T("list"),
79 _T("list the tests, do not run them"),
80 wxCMD_LINE_VAL_NONE
, 0 },
81 { wxCMD_LINE_PARAM
, 0, 0, _T("REGISTRY"), wxCMD_LINE_VAL_STRING
,
82 wxCMD_LINE_PARAM_OPTIONAL
},
83 { wxCMD_LINE_NONE
, 0, 0, 0, wxCMD_LINE_VAL_NONE
, 0 }
86 parser
.SetDesc(cmdLineDesc
);
89 // Handle command line options
91 bool TestApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
93 if (parser
.GetParamCount() > 0)
94 m_registry
= parser
.GetParam(0).mb_str();
96 m_list
= parser
.Found(_T("list"));
98 return wxAppConsole::OnCmdLineParsed(parser
);
105 Test
*test
= m_registry
.empty()?
106 TestFactoryRegistry::getRegistry().makeTest() :
107 TestFactoryRegistry::getRegistry(m_registry
).makeTest();
113 TextUi::TestRunner runner
;
114 runner
.addTest(test
);
115 return runner
.run("", false, true, false) ? EXIT_SUCCESS
: EXIT_FAILURE
;
121 void TestApp::List(Test
*test
, int depth
/*=0*/) const
123 cout
<< string(depth
* 2, ' ') << test
->getName() << "\n";
125 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
);
128 typedef const std::vector
<Test
*> Tests
;
129 typedef Tests::const_iterator Iter
;
131 Tests
& tests
= suite
->getTests();
133 for (Iter it
= tests
.begin(); it
!= tests
.end(); ++it
)
134 List(*it
, depth
+ 1);