OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
CmdArgumentsTest.cpp
Go to the documentation of this file.
1 #include "Util/CmdArguments.h"
2 #include "gtest/gtest.h"
3 #include "boost/smart_ptr.hpp"
4 
5 namespace {
6 
7  // The fixture for testing class Foo.
8  class CmdArgumentsTest : public ::testing::Test {
9  protected:
10 
11  CmdArgumentsTest() {
12  // You can do set-up work for each test here.
13  int argc = 3;
14  char exe_name[] = "test";
15  char a1[] = "--arg1=val1";
16  char a2[] = "--arg2=2.2";
17  char *argv[] = { exe_name, a1, a2 };
18 
19  args_.reset(new CmdArguments(argc, argv));
20  }
21 
22  virtual ~CmdArgumentsTest() {
23  // You can do clean-up work that doesn't throw exceptions here.
24  }
25 
26  // If the constructor and destructor are not enough for setting up
27  // and cleaning up each test, you can define the following methods:
28 
29  virtual void SetUp() {
30  // Code here will be called immediately after the constructor (right
31  // before each test).
32  }
33 
34  virtual void TearDown() {
35  // Code here will be called immediately after each test (right
36  // before the destructor).
37  }
38 
39  // Objects declared here can be used by all tests in the test case
40  boost::scoped_ptr<CmdArguments> args_;
41  };
42 
43  TEST_F(CmdArgumentsTest, RetrieveCorrectFatal) {
44 
45  std::string arg1 = args_->getArg<std::string>("arg1", true);
46  double arg2 = args_->getArg<double>("arg2", true);
47 
48  EXPECT_EQ("val1", arg1) << "first argument string value wrong";
49  EXPECT_EQ(2.2, arg2) << "second argument double value wrong";
50  }
51 
52  TEST_F(CmdArgumentsTest, ThrowOnNotPresentFatal) {
53 
54  EXPECT_ANY_THROW(
55  args_->getArg<std::string>("arg11", true)
56  );
57  }
58 
59  TEST_F(CmdArgumentsTest, CorrectDefaultIfNotPresent) {
60 
61  double arg = args_->getArg<double>("arg22", 10.0, false);
62  EXPECT_EQ(10.0, arg) << "second argument double value wrong";
63  }
64 
65 }
66 
67 int main(int argc, char **argv) {
68  ::testing::InitGoogleTest(&argc, argv);
69  return RUN_ALL_TESTS();
70 }
Parsing command line arguments.
Definition: CmdArguments.h:26
arg(a))
int main(int argc, char *argv[])
Definition: Main.cpp:107