test/command_line.cpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Includes
13 *****************************************************************************/
14 
15 #include <gtest/gtest.h>
16 #include "../../include/ecl/command_line.hpp"
17 
18 /*****************************************************************************
19 ** Using
20 *****************************************************************************/
21 
22 using ecl::CmdLine;
23 using ecl::SwitchArg;
24 using ecl::ValueArg;
25 using ecl::ArgException;
26 
27 /*****************************************************************************
28 ** Globals
29 *****************************************************************************/
30 
31 static int myargc;
32 static char **myargv;
33 
34 /*****************************************************************************
35 ** Tests
36 *****************************************************************************/
37 
38 TEST(CommandLineTests,verify) {
39 // try {
40  // Supply a program description, argument separator (optional) and version number (optional).
41  CmdLine cmd("This is a test program to test the command line parsing facilities provided by TCLAP.");
42 // CmdLine cmd("This is a test program to test the command line parsing facilities provided by TCLAP.", ' ', "0.01");
43 
44  // Add a boolean (flag, name, description), sets the default state to false unless it is found on the command line.
45  SwitchArg debugSwitch("d","debug","Enable debugging.");
46  // Add a boolean (flag, name, description, default)
47  // SwitchArg debug("d","debug","Enable debugging.", false);
48  cmd.add(debugSwitch);
49 
50  // Add an int (flag,name,description,compulsory flag?,default value,help description of the type")
51  ValueArg<int> intArg("i","integer","An integer argument for testing.",false,5,"integer");
52  cmd.add(intArg);
53 
54  /*********************
55  ** Parse
56  **********************/
57  cmd.parse(myargc,myargv); // RoS gtest 'make test' breaks here.
58  bool debug = debugSwitch.getValue();
59  int test = intArg.getValue();
60 
61  EXPECT_EQ(5,test);
62  EXPECT_FALSE(debug);
63 
64  } catch ( ArgException &e ) {
65  ADD_FAILURE() << "Failed to parse commadn line arguments";
66  }
67 }
68 
69 /*****************************************************************************
70 ** Main
71 *****************************************************************************/
72 
73 int main(int argc, char **argv) {
74 
75  myargc = argc;
76  myargv = argv;
77 
78  testing::InitGoogleTest(&argc,argv);
79  return RUN_ALL_TESTS();
80 }
81 
82 
myargc
static int myargc
Definition: test/command_line.cpp:31
main
int main(int argc, char **argv)
Definition: test/command_line.cpp:73
ecl::CmdLine
Manages the command line parsing object.
Definition: cmd_line.hpp:51
myargv
static char ** myargv
Definition: test/command_line.cpp:32
ecl::SwitchArg::getValue
bool getValue()
Definition: switch_arg.hpp:131
ecl::ValueArg::getValue
T & getValue()
Definition: value_arg.hpp:417
ecl::ArgException
Defines the exception that is thrown whenever a command line is created and parsed.
Definition: arg_exception.hpp:32
ecl::CmdLine::add
void add(Arg &a)
Definition: cmd_line.hpp:351
ecl::SwitchArg
Definition: switch_arg.hpp:33
TEST
TEST(CommandLineTests, verify)
Definition: test/command_line.cpp:38
ecl::ValueArg
Definition: value_arg.hpp:36
ecl::CmdLine::parse
void parse(int argc, char **argv)
Definition: cmd_line.hpp:370


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:13