22 #include "gtest/gtest.h"
23 #include "boost/smart_ptr.hpp"
28 class CmdArgumentsTest :
public ::testing::Test {
34 char exe_name[] =
"test";
35 char a1[] =
"--arg1=val1";
36 char a2[] =
"--arg2=2.2";
37 char *argv[] = { exe_name, a1, a2 };
42 virtual ~CmdArgumentsTest() {
49 virtual void SetUp() {
54 virtual void TearDown() {
60 boost::scoped_ptr<CmdArguments> args_;
63 TEST_F(CmdArgumentsTest, RetrieveCorrectFatal) {
65 std::string arg1 = args_->getArg<std::string>(
"arg1",
true);
66 double arg2 = args_->getArg<
double>(
"arg2",
true);
68 EXPECT_EQ(
"val1", arg1) <<
"first argument string value wrong";
69 EXPECT_EQ(2.2, arg2) <<
"second argument double value wrong";
72 TEST_F(CmdArgumentsTest, ThrowOnNotPresentFatal) {
75 args_->getArg<std::string>(
"arg11",
true)
79 TEST_F(CmdArgumentsTest, CorrectDefaultIfNotPresent) {
81 double arg = args_->getArg<
double>(
"arg22", 10.0,
false);
82 EXPECT_EQ(10.0,
arg) <<
"second argument double value wrong";
87 int main(
int argc,
char **argv) {
88 ::testing::InitGoogleTest(&argc, argv);
89 return RUN_ALL_TESTS();
int main(int argc, char **argv)