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
;
36 // The application class
38 class TestApp
: public wxAppConsole
44 void OnInitCmdLine(wxCmdLineParser
& parser
);
45 bool OnCmdLineParsed(wxCmdLineParser
& parser
);
50 void List(Test
*test
, const string
& parent
= "") const;
52 // command lines options/parameters
55 vector
<string
> m_registries
;
58 IMPLEMENT_APP_CONSOLE(TestApp
)
68 bool TestApp::OnInit()
70 cout
<< "Test program for wxWidgets\n"
71 << "build: " << WX_BUILD_OPTIONS_SIGNATURE
<< std::endl
;
72 return wxAppConsole::OnInit();
75 // The table of command line options
77 void TestApp::OnInitCmdLine(wxCmdLineParser
& parser
)
79 wxAppConsole::OnInitCmdLine(parser
);
81 static const wxCmdLineEntryDesc cmdLineDesc
[] = {
82 { wxCMD_LINE_SWITCH
, _T("l"), _T("list"),
83 _T("list the test suites, do not run them"),
84 wxCMD_LINE_VAL_NONE
, 0 },
85 { wxCMD_LINE_SWITCH
, _T("L"), _T("longlist"),
86 _T("list the test cases, do not run them"),
87 wxCMD_LINE_VAL_NONE
, 0 },
88 { wxCMD_LINE_PARAM
, 0, 0, _T("REGISTRY"), wxCMD_LINE_VAL_STRING
,
89 wxCMD_LINE_PARAM_OPTIONAL
| wxCMD_LINE_PARAM_MULTIPLE
},
90 { wxCMD_LINE_NONE
, 0, 0, 0, wxCMD_LINE_VAL_NONE
, 0 }
93 parser
.SetDesc(cmdLineDesc
);
96 // Handle command line options
98 bool TestApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
100 if (parser
.GetParamCount())
101 for (size_t i
= 0; i
< parser
.GetParamCount(); i
++)
102 m_registries
.push_back(string(parser
.GetParam(i
).mb_str()));
104 m_registries
.push_back("");
106 m_longlist
= parser
.Found(_T("longlist"));
107 m_list
= m_longlist
|| parser
.Found(_T("list"));
109 return wxAppConsole::OnCmdLineParsed(parser
);
118 for (size_t i
= 0; i
< m_registries
.size(); i
++) {
119 auto_ptr
<Test
> test(m_registries
[i
].empty() ?
120 TestFactoryRegistry::getRegistry().makeTest() :
121 TestFactoryRegistry::getRegistry(m_registries
[i
]).makeTest());
123 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
.get());
125 if (suite
&& suite
->countTestCases() == 0)
126 wxLogError(_T("No such test suite: %s"),
127 wxString(m_registries
[i
].c_str(), wxConvUTF8
).c_str());
131 runner
.addTest(test
.release());
135 // Switch off logging unless --verbose
136 bool verbose
= wxLog::GetVerbose();
137 wxLog::EnableLogging(verbose
);
139 bool verbose
= false;
142 return ( m_list
|| runner
.run("", false, true, !verbose
) )
149 void TestApp::List(Test
*test
, const string
& parent
/*=""*/) const
151 TestSuite
*suite
= dynamic_cast<TestSuite
*>(test
);
155 // take the last component of the name and append to the parent
156 name
= test
->getName();
157 string::size_type i
= name
.find_last_of(".:");
158 if (i
!= string::npos
)
159 name
= name
.substr(i
+ 1);
160 name
= parent
+ "." + name
;
162 // drop the 1st component from the display and indent
164 string::size_type j
= i
= name
.find('.', 1);
165 while ((j
= name
.find('.', j
+ 1)) != string::npos
)
167 cout
<< " " << name
.substr(i
+ 1) << "\n";
170 typedef vector
<Test
*> Tests
;
171 typedef Tests::const_iterator Iter
;
173 const Tests
& tests
= suite
->getTests();
175 for (Iter it
= tests
.begin(); it
!= tests
.end(); ++it
)
178 else if (m_longlist
) {
179 string::size_type i
= 0;
180 while ((i
= parent
.find('.', i
+ 1)) != string::npos
)
182 cout
<< " " << test
->getName() << "\n";