Skip to content
Merged
Prev Previous commit
Next Next commit
core: Test order of command line argument parsing
  • Loading branch information
Alexander Krotov committed Mar 22, 2017
commit 5060a4a671b278c6c9f0976e63a3966cb66eedba
32 changes: 32 additions & 0 deletions src/core/test/command-line-test-suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,37 @@ CommandLineStringTestCase::DoRun (void)
NS_TEST_ASSERT_MSG_EQ (myStr, "XX", "Command parser did not correctly set an string value to \"XX\"");
}

/*************************************************************************//**
* Test order of argument parsing
****************************************************************************/
class CommandLineOrderTestCase : public CommandLineTestCaseBase
{
public:
CommandLineOrderTestCase (); /**< Constructor */
virtual ~CommandLineOrderTestCase () {} /**< Destructor */

private:
virtual void DoRun (void); /**< Run the test */

};

CommandLineOrderTestCase::CommandLineOrderTestCase ()
: CommandLineTestCaseBase ("order")
{
}

void
CommandLineOrderTestCase::DoRun (void)
{
CommandLine cmd;
uint32_t myUint32 = 0;

cmd.AddValue ("my-uint32", "help", myUint32);

Parse (cmd, 2, "--my-uint32=1", "--my-uint32=2");

NS_TEST_ASSERT_MSG_EQ (myUint32, 2, "Command parser did not correctly set an unsigned integer value to 2");
}
/*************************************************************************//**
* The Test Suite that glues all of the Test Cases together.
****************************************************************************/
Expand All @@ -271,6 +302,7 @@ CommandLineTestSuite::CommandLineTestSuite ()
AddTestCase (new CommandLineIntTestCase, TestCase::QUICK);
AddTestCase (new CommandLineUnsignedIntTestCase, TestCase::QUICK);
AddTestCase (new CommandLineStringTestCase, TestCase::QUICK);
AddTestCase (new CommandLineOrderTestCase, TestCase::QUICK);
}

static CommandLineTestSuite CommandLineTestSuite; /**< Test instance */