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
;
38 typedef wxApp TestAppBase
;
40 typedef wxAppConsole TestAppBase
;
43 // The application class
45 class TestApp
: public TestAppBase
51 virtual void OnInitCmdLine(wxCmdLineParser
& parser
);
52 virtual bool OnCmdLineParsed(wxCmdLineParser
& parser
);
53 virtual bool OnInit();
58 void List(Test
*test
, const string
& parent
= "") const;
60 // command lines options/parameters
63 vector
<string
> m_registries
;
66 IMPLEMENT_APP_CONSOLE(TestApp
)
76 bool TestApp::OnInit()
78 if ( !TestAppBase::OnInit() )
81 cout
<< "Test program for wxWidgets\n"
82 << "build: " << WX_BUILD_OPTIONS_SIGNATURE
<< std::endl
;
84 #if !wxUSE_WXVSNPRINTF
86 cout
<< "WARNING: VsnprintfTestCase will test the system vsnprintf() function\n";
87 cout
<< " instead of the wxWidgets wxVsnprintf_ implementation!" << std::endl
;
92 // create a hidden parent window to be used as parent for the GUI controls
93 new wxFrame(NULL
, wxID_ANY
, "Hidden wx test frame");
99 // The table of command line options
101 void TestApp::OnInitCmdLine(wxCmdLineParser
& parser
)
103 TestAppBase::OnInitCmdLine(parser
);
105 static const wxCmdLineEntryDesc cmdLineDesc
[] = {
106 { wxCMD_LINE_SWITCH
, "l", "list",
107 "list the test suites, do not run them",
108 wxCMD_LINE_VAL_NONE
, 0 },
109 { wxCMD_LINE_SWITCH
, "L", "longlist",
110 "list the test cases, do not run them",
111 wxCMD_LINE_VAL_NONE
, 0 },
112 { wxCMD_LINE_PARAM
, NULL
, NULL
, "REGISTRY", wxCMD_LINE_VAL_STRING
,
113 wxCMD_LINE_PARAM_OPTIONAL
| wxCMD_LINE_PARAM_MULTIPLE
},
117 parser
.SetDesc(cmdLineDesc
);
120 // Handle command line options
122 bool TestApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
124 if (parser
.GetParamCount())
125 for (size_t i
= 0; i
< parser
.GetParamCount(); i
++)
126 m_registries
.push_back(string(parser
.GetParam(i
).mb_str()));
128 m_registries
.push_back("");
130 m_longlist
= parser
.Found(_T("longlist"));
131 m_list
= m_longlist
|| parser
.Found(_T("list"));
133 return TestAppBase::OnCmdLineParsed(parser
);
142 for (size_t i
= 0; i
< m_registries
.size(); i
++) {
143 auto_ptr
<Test
> test(m_registries
[i
].empty() ?
144 TestFactoryRegistry::getRegistry().makeTest() :
145 TestFactoryRegistry::getRegistry(m_registries
[i
]).makeTest());
147 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
.get());
149 if (suite
&& suite
->countTestCases() == 0)
150 wxLogError(_T("No such test suite: %s"),
151 wxString(m_registries
[i
].c_str(), wxConvUTF8
).c_str());
155 runner
.addTest(test
.release());
158 runner
.setOutputter(new CompilerOutputter(&runner
.result(), cout
));
161 // Switch off logging unless --verbose
162 bool verbose
= wxLog::GetVerbose();
163 wxLog::EnableLogging(verbose
);
165 bool verbose
= false;
168 return ( m_list
|| runner
.run("", false, true, !verbose
) )
173 int TestApp::OnExit()
176 delete GetTopWindow();
184 void TestApp::List(Test
*test
, const string
& parent
/*=""*/) const
186 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
);
190 // take the last component of the name and append to the parent
191 name
= test
->getName();
192 string::size_type i
= name
.find_last_of(".:");
193 if (i
!= string::npos
)
194 name
= name
.substr(i
+ 1);
195 name
= parent
+ "." + name
;
197 // drop the 1st component from the display and indent
199 string::size_type j
= i
= name
.find('.', 1);
200 while ((j
= name
.find('.', j
+ 1)) != string::npos
)
202 cout
<< " " << name
.substr(i
+ 1) << "\n";
205 typedef vector
<Test
*> Tests
;
206 typedef Tests::const_iterator Iter
;
208 const Tests
& tests
= suite
->getTests();
210 for (Iter it
= tests
.begin(); it
!= tests
.end(); ++it
)
213 else if (m_longlist
) {
214 string::size_type i
= 0;
215 while ((i
= parent
.find('.', i
+ 1)) != string::npos
)
217 cout
<< " " << test
->getName() << "\n";