Allow iterating over wxCmdLineParser arguments in order.
This allows the meaning of the options to depend on their order relatively to the other options which wasn't possible before. See http://review.bakefile.org/r/557/ git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75723 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
#include "wx/msgout.h"
|
||||
#include "wx/scopeguard.h"
|
||||
|
||||
#include "testdate.h"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// test class
|
||||
// --------------------------------------------------------------------------
|
||||
@@ -36,11 +38,13 @@ private:
|
||||
CPPUNIT_TEST_SUITE( CmdLineTestCase );
|
||||
CPPUNIT_TEST( ConvertStringTestCase );
|
||||
CPPUNIT_TEST( ParseSwitches );
|
||||
CPPUNIT_TEST( ArgumentsCollection );
|
||||
CPPUNIT_TEST( Usage );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void ConvertStringTestCase();
|
||||
void ParseSwitches();
|
||||
void ArgumentsCollection();
|
||||
void Usage();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(CmdLineTestCase)
|
||||
@@ -202,6 +206,78 @@ void CmdLineTestCase::ParseSwitches()
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_SWITCH_OFF, p.FoundSwitch("n") );
|
||||
}
|
||||
|
||||
void CmdLineTestCase::ArgumentsCollection()
|
||||
{
|
||||
wxCmdLineParser p;
|
||||
|
||||
p.AddLongSwitch ("verbose");
|
||||
p.AddOption ("l", "long", wxEmptyString, wxCMD_LINE_VAL_NUMBER);
|
||||
p.AddOption ("d", "date", wxEmptyString, wxCMD_LINE_VAL_DATE);
|
||||
p.AddOption ("f", "double", wxEmptyString, wxCMD_LINE_VAL_DOUBLE);
|
||||
p.AddOption ("s", "string", wxEmptyString, wxCMD_LINE_VAL_STRING);
|
||||
p.AddParam (wxEmptyString, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE);
|
||||
|
||||
wxDateTime wasNow = wxDateTime::Now().GetDateOnly();
|
||||
p.SetCmdLine (wxString::Format ("--verbose param1 -l 22 -d \"%s\" -f 50.12e-1 param2 --string \"some string\"",
|
||||
wasNow.FormatISODate()));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, p.Parse(false) );
|
||||
|
||||
wxCmdLineArgs::const_iterator itargs = p.GetArguments().begin();
|
||||
|
||||
// --verbose
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_SWITCH, itargs->GetKind());
|
||||
CPPUNIT_ASSERT_EQUAL("verbose", itargs->GetLongName());
|
||||
CPPUNIT_ASSERT_EQUAL(false, itargs->IsNegated());
|
||||
|
||||
// param1
|
||||
++itargs; // pre incrementation test
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_PARAM, itargs->GetKind());
|
||||
CPPUNIT_ASSERT_EQUAL("param1", itargs->GetStrVal());
|
||||
|
||||
// -l 22
|
||||
itargs++; // post incrementation test
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_OPTION, itargs->GetKind());
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_VAL_NUMBER, itargs->GetType());
|
||||
CPPUNIT_ASSERT_EQUAL("l", itargs->GetShortName());
|
||||
CPPUNIT_ASSERT_EQUAL(22, itargs->GetLongVal());
|
||||
|
||||
// -d (some date)
|
||||
++itargs;
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_OPTION, itargs->GetKind());
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_VAL_DATE, itargs->GetType());
|
||||
CPPUNIT_ASSERT_EQUAL("d", itargs->GetShortName());
|
||||
CPPUNIT_ASSERT_EQUAL(wasNow, itargs->GetDateVal());
|
||||
|
||||
// -f 50.12e-1
|
||||
++itargs;
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_OPTION, itargs->GetKind());
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_VAL_DOUBLE, itargs->GetType());
|
||||
CPPUNIT_ASSERT_EQUAL("f", itargs->GetShortName());
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(50.12e-1, itargs->GetDoubleVal(), 0.000001);
|
||||
|
||||
// param2
|
||||
++itargs;
|
||||
CPPUNIT_ASSERT_EQUAL (wxCMD_LINE_PARAM, itargs->GetKind());
|
||||
CPPUNIT_ASSERT_EQUAL ("param2", itargs->GetStrVal());
|
||||
|
||||
// --string "some string"
|
||||
++itargs;
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_OPTION, itargs->GetKind());
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_VAL_STRING, itargs->GetType());
|
||||
CPPUNIT_ASSERT_EQUAL("s", itargs->GetShortName());
|
||||
CPPUNIT_ASSERT_EQUAL("string", itargs->GetLongName());
|
||||
CPPUNIT_ASSERT_EQUAL("some string", itargs->GetStrVal());
|
||||
|
||||
// testing pre and post-increment
|
||||
--itargs;
|
||||
itargs--;
|
||||
CPPUNIT_ASSERT_EQUAL(wxCMD_LINE_VAL_DOUBLE, itargs->GetType());
|
||||
|
||||
++itargs;++itargs;++itargs;
|
||||
CPPUNIT_ASSERT(itargs == p.GetArguments().end());
|
||||
}
|
||||
|
||||
void CmdLineTestCase::Usage()
|
||||
{
|
||||
// check that Usage() returns roughly what we expect (don't check all the
|
||||
|
Reference in New Issue
Block a user