+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") );
+}
+