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 
static char ** myargv
static int myargc
void add(Arg &a)
Definition: cmd_line.hpp:349
Defines the exception that is thrown whenever a command line is created and parsed.
Manages the command line parsing object.
Definition: cmd_line.hpp:49
int main(int argc, char **argv)
TEST(CommandLineTests, verify)
void parse(int argc, char **argv)
Definition: cmd_line.hpp:368


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:08