X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/28d4f49b78058c04ee51ed7c4104a94870ff028e..3c3ead1d1513a5eb79091a604f4e42b45d1bdf5d:/tests/cmdline/cmdlinetest.cpp diff --git a/tests/cmdline/cmdlinetest.cpp b/tests/cmdline/cmdlinetest.cpp index 04e5c2ac83..87d02b2d16 100644 --- a/tests/cmdline/cmdlinetest.cpp +++ b/tests/cmdline/cmdlinetest.cpp @@ -21,6 +21,8 @@ #endif // WX_PRECOMP #include "wx/cmdline.h" +#include "wx/msgout.h" +#include "wx/scopeguard.h" // -------------------------------------------------------------------------- // test class @@ -34,10 +36,12 @@ public: private: CPPUNIT_TEST_SUITE( CmdLineTestCase ); CPPUNIT_TEST( ConvertStringTestCase ); + CPPUNIT_TEST( ParseSwitches ); CPPUNIT_TEST( Usage ); CPPUNIT_TEST_SUITE_END(); void ConvertStringTestCase(); + void ParseSwitches(); void Usage(); DECLARE_NO_COPY_CLASS(CmdLineTestCase) @@ -117,6 +121,69 @@ void CmdLineTestCase::ConvertStringTestCase() #undef WX_ASSERT_ARGS_EQUAL } +void CmdLineTestCase::ParseSwitches() +{ + // install a dummy message output object just suppress error messages from + // wxCmdLineParser::Parse() + class NoMessageOutput : public wxMessageOutput + { + public: + virtual void Output(const wxString& WXUNUSED(str)) { } + } noMessages; + + wxMessageOutput * const old = wxMessageOutput::Set(&noMessages); + wxON_BLOCK_EXIT1( wxMessageOutput::Set, old ); + + wxCmdLineParser p; + p.AddSwitch("a"); + p.AddSwitch("b"); + p.AddSwitch("c"); + p.AddSwitch("d"); + + p.SetCmdLine(""); + CPPUNIT_ASSERT_EQUAL(0, p.Parse(false) ); + CPPUNIT_ASSERT( !p.Found("a") ); + + p.SetCmdLine("-z"); + CPPUNIT_ASSERT( p.Parse(false) != 0 ); + + p.SetCmdLine("-a"); + CPPUNIT_ASSERT_EQUAL(0, p.Parse(false) ); + CPPUNIT_ASSERT( p.Found("a") ); + CPPUNIT_ASSERT( !p.Found("b") ); + + p.SetCmdLine("-a -d"); + CPPUNIT_ASSERT_EQUAL(0, p.Parse(false) ); + CPPUNIT_ASSERT( p.Found("a") ); + CPPUNIT_ASSERT( !p.Found("b") ); + CPPUNIT_ASSERT( !p.Found("c") ); + CPPUNIT_ASSERT( p.Found("d") ); + + p.SetCmdLine("-abd"); + CPPUNIT_ASSERT_EQUAL(0, p.Parse(false) ); + CPPUNIT_ASSERT( p.Found("a") ); + CPPUNIT_ASSERT( p.Found("b") ); + CPPUNIT_ASSERT( !p.Found("c") ); + CPPUNIT_ASSERT( p.Found("d") ); + + p.SetCmdLine("-abdz"); + CPPUNIT_ASSERT( p.Parse(false) != 0 ); + + p.SetCmdLine("-ab -cd"); + CPPUNIT_ASSERT_EQUAL(0, p.Parse(false) ); + CPPUNIT_ASSERT( p.Found("a") ); + CPPUNIT_ASSERT( p.Found("b") ); + CPPUNIT_ASSERT( p.Found("c") ); + CPPUNIT_ASSERT( p.Found("d") ); + + p.SetCmdLine("-da"); + CPPUNIT_ASSERT_EQUAL(0, p.Parse(false) ); + CPPUNIT_ASSERT( p.Found("a") ); + CPPUNIT_ASSERT( !p.Found("b") ); + CPPUNIT_ASSERT( !p.Found("c") ); + CPPUNIT_ASSERT( p.Found("d") ); +} + void CmdLineTestCase::Usage() { // check that Usage() returns roughly what we expect (don't check all the