1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Test program for wxWidgets
4 // Author: Mike Wetherell
6 // Copyright: (c) 2004 Mike Wetherell
7 // Licence: wxWidgets licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx/wx.h"
18 // for all others, include the necessary headers
23 #include "wx/cmdline.h"
27 using CppUnit::TestSuite
;
28 using CppUnit::TestFactoryRegistry
;
29 using CppUnit::TextUi::TestRunner
;
30 using CppUnit::CompilerOutputter
;
35 typedef wxApp TestAppBase
;
37 typedef wxAppConsole TestAppBase
;
40 // The application class
42 class TestApp
: public TestAppBase
48 virtual void OnInitCmdLine(wxCmdLineParser
& parser
);
49 virtual bool OnCmdLineParsed(wxCmdLineParser
& parser
);
50 virtual bool OnInit();
55 void List(Test
*test
, const string
& parent
= "") const;
57 // command lines options/parameters
60 vector
<string
> m_registries
;
63 IMPLEMENT_APP_CONSOLE(TestApp
)
73 bool TestApp::OnInit()
75 if ( !TestAppBase::OnInit() )
78 cout
<< "Test program for wxWidgets\n"
79 << "build: " << WX_BUILD_OPTIONS_SIGNATURE
<< std::endl
;
82 // create a hidden parent window to be used as parent for the GUI controls
83 new wxFrame(NULL
, wxID_ANY
, "Hidden wx test frame");
89 // The table of command line options
91 void TestApp::OnInitCmdLine(wxCmdLineParser
& parser
)
93 TestAppBase::OnInitCmdLine(parser
);
95 static const wxCmdLineEntryDesc cmdLineDesc
[] = {
96 { wxCMD_LINE_SWITCH
, "l", "list",
97 "list the test suites, do not run them",
98 wxCMD_LINE_VAL_NONE
, 0 },
99 { wxCMD_LINE_SWITCH
, "L", "longlist",
100 "list the test cases, do not run them",
101 wxCMD_LINE_VAL_NONE
, 0 },
102 { wxCMD_LINE_PARAM
, NULL
, NULL
, "REGISTRY", wxCMD_LINE_VAL_STRING
,
103 wxCMD_LINE_PARAM_OPTIONAL
| wxCMD_LINE_PARAM_MULTIPLE
},
107 parser
.SetDesc(cmdLineDesc
);
110 // Handle command line options
112 bool TestApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
114 if (parser
.GetParamCount())
115 for (size_t i
= 0; i
< parser
.GetParamCount(); i
++)
116 m_registries
.push_back(string(parser
.GetParam(i
).mb_str()));
118 m_registries
.push_back("");
120 m_longlist
= parser
.Found(_T("longlist"));
121 m_list
= m_longlist
|| parser
.Found(_T("list"));
123 return TestAppBase::OnCmdLineParsed(parser
);
132 for (size_t i
= 0; i
< m_registries
.size(); i
++) {
133 auto_ptr
<Test
> test(m_registries
[i
].empty() ?
134 TestFactoryRegistry::getRegistry().makeTest() :
135 TestFactoryRegistry::getRegistry(m_registries
[i
]).makeTest());
137 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
.get());
139 if (suite
&& suite
->countTestCases() == 0)
140 wxLogError(_T("No such test suite: %s"),
141 wxString(m_registries
[i
].c_str(), wxConvUTF8
).c_str());
145 runner
.addTest(test
.release());
148 runner
.setOutputter(new CompilerOutputter(&runner
.result(), cout
));
151 // Switch off logging unless --verbose
152 bool verbose
= wxLog::GetVerbose();
153 wxLog::EnableLogging(verbose
);
155 bool verbose
= false;
158 return ( m_list
|| runner
.run("", false, true, !verbose
) )
163 int TestApp::OnExit()
166 delete GetTopWindow();
174 void TestApp::List(Test
*test
, const string
& parent
/*=""*/) const
176 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
);
180 // take the last component of the name and append to the parent
181 name
= test
->getName();
182 string::size_type i
= name
.find_last_of(".:");
183 if (i
!= string::npos
)
184 name
= name
.substr(i
+ 1);
185 name
= parent
+ "." + name
;
187 // drop the 1st component from the display and indent
189 string::size_type j
= i
= name
.find('.', 1);
190 while ((j
= name
.find('.', j
+ 1)) != string::npos
)
192 cout
<< " " << name
.substr(i
+ 1) << "\n";
195 typedef vector
<Test
*> Tests
;
196 typedef Tests::const_iterator Iter
;
198 const Tests
& tests
= suite
->getTests();
200 for (Iter it
= tests
.begin(); it
!= tests
.end(); ++it
)
203 else if (m_longlist
) {
204 string::size_type i
= 0;
205 while ((i
= parent
.find('.', i
+ 1)) != string::npos
)
207 cout
<< " " << test
->getName() << "\n";