20 #include "ns3/command-line.h"
22 #include "ns3/config.h"
23 #include "ns3/global-value.h"
24 #include "ns3/type-id.h"
26 #include "ns3/string.h"
44 CommandLineTestCaseBase::CommandLineTestCaseBase (std::string description)
50 CommandLineTestCaseBase::Parse (
const CommandLine &cmd,
int n, ...)
52 char **args =
new char* [n+1];
53 args[0] = (
char *)
"Test";
59 char *arg = va_arg (ap,
char *);
64 cmd.
Parse (argc, args);
78 virtual void DoRun (
void);
82 CommandLineBooleanTestCase::CommandLineBooleanTestCase ()
93 cmd.
AddValue (
"my-bool",
"help", myBool);
95 Parse (cmd, 1,
"--my-bool=0");
96 NS_TEST_ASSERT_MSG_EQ (myBool,
false,
"Command parser did not correctly set a boolean value to false");
98 Parse (cmd, 1,
"--my-bool=1");
99 NS_TEST_ASSERT_MSG_EQ (myBool,
true,
"Command parser did not correctly set a boolean value to true");
112 virtual void DoRun (
void);
116 CommandLineIntTestCase::CommandLineIntTestCase ()
126 int32_t myInt32 = 10;
128 cmd.
AddValue (
"my-bool",
"help", myBool);
129 cmd.
AddValue (
"my-int32",
"help", myInt32);
131 Parse (cmd, 2,
"--my-bool=0",
"--my-int32=-3");
132 NS_TEST_ASSERT_MSG_EQ (myBool,
false,
"Command parser did not correctly set a boolean value to false");
133 NS_TEST_ASSERT_MSG_EQ (myInt32, -3,
"Command parser did not correctly set an integer value to -3");
135 Parse (cmd, 2,
"--my-bool=1",
"--my-int32=+2");
136 NS_TEST_ASSERT_MSG_EQ (myBool,
true,
"Command parser did not correctly set a boolean value to true");
137 NS_TEST_ASSERT_MSG_EQ (myInt32, +2,
"Command parser did not correctly set an integer value to +2");
150 virtual void DoRun (
void);
154 CommandLineUnsignedIntTestCase::CommandLineUnsignedIntTestCase ()
164 uint32_t myUint32 = 10;
166 cmd.
AddValue (
"my-bool",
"help", myBool);
167 cmd.
AddValue (
"my-uint32",
"help", myUint32);
169 Parse (cmd, 2,
"--my-bool=0",
"--my-uint32=9");
171 NS_TEST_ASSERT_MSG_EQ (myBool,
false,
"Command parser did not correctly set a boolean value to true");
172 NS_TEST_ASSERT_MSG_EQ (myUint32, 9,
"Command parser did not correctly set an unsigned integer value to 9");
185 virtual void DoRun (
void);
189 CommandLineStringTestCase::CommandLineStringTestCase ()
198 uint32_t myUint32 = 10;
199 std::string myStr =
"MyStr";
201 cmd.
AddValue (
"my-uint32",
"help", myUint32);
202 cmd.
AddValue (
"my-str",
"help", myStr);
204 Parse (cmd, 2,
"--my-uint32=9",
"--my-str=XX");
206 NS_TEST_ASSERT_MSG_EQ (myUint32, 9,
"Command parser did not correctly set an unsigned integer value to 9");
207 NS_TEST_ASSERT_MSG_EQ (myStr,
"XX",
"Command parser did not correctly set an string value to \"XX\"");
219 CommandLineTestSuite::CommandLineTestSuite ()
virtual void DoRun(void)
Implementation to actually run this test case.
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
void AddValue(const std::string &name, const std::string &help, T &value)
virtual void DoRun(void)
Implementation to actually run this test case.
void Parse(int argc, char *argv[]) const