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 CppUnit::TestSuite
;
33 using CppUnit::TestFactoryRegistry
;
34 using CppUnit::TextUi::TestRunner
;
41 // The application class
43 class TestApp
: public wxAppConsole
49 void OnInitCmdLine(wxCmdLineParser
& parser
);
50 bool OnCmdLineParsed(wxCmdLineParser
& parser
);
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 cout
<< "Test program for wxWidgets\n"
76 << "build: " << WX_BUILD_OPTIONS_SIGNATURE
<< std::endl
;
77 return wxAppConsole::OnInit();
80 // The table of command line options
82 void TestApp::OnInitCmdLine(wxCmdLineParser
& parser
)
84 wxAppConsole::OnInitCmdLine(parser
);
86 static const wxCmdLineEntryDesc cmdLineDesc
[] = {
87 { wxCMD_LINE_SWITCH
, _T("l"), _T("list"),
88 _T("list the test suites, do not run them"),
89 wxCMD_LINE_VAL_NONE
, 0 },
90 { wxCMD_LINE_SWITCH
, _T("L"), _T("longlist"),
91 _T("list the test cases, do not run them"),
92 wxCMD_LINE_VAL_NONE
, 0 },
93 { wxCMD_LINE_PARAM
, 0, 0, _T("REGISTRY"), wxCMD_LINE_VAL_STRING
,
94 wxCMD_LINE_PARAM_OPTIONAL
| wxCMD_LINE_PARAM_MULTIPLE
},
95 { wxCMD_LINE_NONE
, 0, 0, 0, wxCMD_LINE_VAL_NONE
, 0 }
98 parser
.SetDesc(cmdLineDesc
);
101 // Handle command line options
103 bool TestApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
105 if (parser
.GetParamCount())
106 for (size_t i
= 0; i
< parser
.GetParamCount(); i
++)
107 m_registries
.push_back(string(parser
.GetParam(i
).mb_str()));
109 m_registries
.push_back("");
111 m_longlist
= parser
.Found(_T("longlist"));
112 m_list
= m_longlist
|| parser
.Found(_T("list"));
114 return wxAppConsole::OnCmdLineParsed(parser
);
124 for (size_t i
= 0; i
< m_registries
.size(); i
++) {
125 auto_ptr
<Test
> test(m_registries
[i
].empty() ?
126 TestFactoryRegistry::getRegistry().makeTest() :
127 TestFactoryRegistry::getRegistry(m_registries
[i
]).makeTest());
129 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
.get());
131 if (suite
&& suite
->countTestCases() == 0)
132 wxLogError(_T("No such test suite: %s"),
133 wxString(m_registries
[i
].c_str(), wxConvUTF8
).c_str());
137 runner
.addTest(test
.release());
141 // Switch off logging unless --verbose
142 bool verbose
= wxLog::GetVerbose();
143 wxLog::EnableLogging(verbose
);
145 bool verbose
= false;
148 return ( m_list
|| runner
.run("", false, true, !verbose
) )
155 void TestApp::List(Test
*test
, const string
& parent
/*=""*/) const
157 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
);
161 // take the last component of the name and append to the parent
162 name
= test
->getName();
163 string::size_type i
= name
.find_last_of(".:");
164 name
= parent
+ "." + (i
!= string::npos
? name
.substr(i
+ 1) : name
);
166 // drop the 1st component from the display and indent
168 string::size_type j
= i
= name
.find('.', 1);
169 while ((j
= name
.find('.', j
+ 1)) != string::npos
)
171 cout
<< " " << name
.substr(i
+ 1) << "\n";
174 typedef vector
<Test
*> Tests
;
175 typedef Tests::const_iterator Iter
;
177 const Tests
& tests
= suite
->getTests();
179 for (Iter it
= tests
.begin(); it
!= tests
.end(); ++it
)
182 else if (m_longlist
) {
183 string::size_type i
= 0;
184 while ((i
= parent
.find('.', i
+ 1)) != string::npos
)
186 cout
<< " " << test
->getName() << "\n";