diff options
Diffstat (limited to 'test/bin-common/option-action.cc')
-rw-r--r-- | test/bin-common/option-action.cc | 168 |
1 files changed, 68 insertions, 100 deletions
diff --git a/test/bin-common/option-action.cc b/test/bin-common/option-action.cc index 18e0c73c..4a0674e1 100644 --- a/test/bin-common/option-action.cc +++ b/test/bin-common/option-action.cc @@ -16,46 +16,29 @@ * *********************************************************************/ +#include <gtest/gtest.h> + #include <bin-common/option-action.h> #include <bin-common/options.h> #include <iostream> -#include <cppunit/extensions/HelperMacros.h> - using bin_common::option_action; -using namespace CppUnit; -class test_option_action : public TestFixture -{ - CPPUNIT_TEST_SUITE(test_option_action); - CPPUNIT_TEST(test_construction); - CPPUNIT_TEST(test_default); - CPPUNIT_TEST_EXCEPTION(test_default_fail, bin_common::options::error); - CPPUNIT_TEST(test_current); - CPPUNIT_TEST_EXCEPTION(test_current_fail, bin_common::options::error); - CPPUNIT_TEST_EXCEPTION(test_current_fail_multipleset, - bin_common::options::error); - CPPUNIT_TEST(test_operators); - CPPUNIT_TEST_EXCEPTION(test_operators_fail_multipleset, - bin_common::options::error); - CPPUNIT_TEST_SUITE_END(); - -protected: - option_action *action; +class OptionAction : public ::testing::Test +{ public: - test_option_action(): - TestFixture(), - action() - {} + option_action *action; - virtual ~test_option_action() - {} + void SetUp() + { + action = new option_action; + } - void setUp() + void TearDown() { - this->action = new option_action; + delete action; } static void @@ -67,92 +50,77 @@ public: act.add("info"); act.add("config"); } +}; - void tearDown() - { - delete this->action; - } - - void - test_construction() - { - option_action act; - } - - void - test_default() - { - add_examples(*this->action); - CPPUNIT_ASSERT(this->action->get_default() == ""); - CPPUNIT_ASSERT(this->action->get() == ""); +TEST_F(OptionAction, Construct) +{ + ASSERT_NO_THROW(option_action act); +} - this->action->set_default("info"); - CPPUNIT_ASSERT(this->action->get_default() == "info"); - CPPUNIT_ASSERT(this->action->get() == "info"); - } +TEST_F(OptionAction, Default) +{ + add_examples(*action); + EXPECT_EQ(action->get_default(), ""); + EXPECT_EQ(action->get(), ""); - void - test_default_fail() - { - add_examples(*this->action); + action->set_default("info"); + EXPECT_EQ(action->get_default(), "info"); + EXPECT_EQ(action->get(), "info"); +} - this->action->set_default("invalid"); - } +TEST_F(OptionAction, DefaultFail) +{ + add_examples(*action); - void - test_current() - { - add_examples(*this->action); + ASSERT_THROW(action->set_default("invalid"), bin_common::options::error); +} - CPPUNIT_ASSERT(this->action->get_default() == ""); - CPPUNIT_ASSERT(this->action->get() == ""); - this->action->set_default("list"); +TEST_F(OptionAction, Current) +{ + add_examples(*action); - CPPUNIT_ASSERT(this->action->get_default() == "list"); - CPPUNIT_ASSERT(this->action->get() == "list"); + EXPECT_EQ(action->get_default(), ""); + EXPECT_EQ(action->get(), ""); + action->set_default("list"); - this->action->set("config"); - CPPUNIT_ASSERT(this->action->get_default() == "list"); - CPPUNIT_ASSERT(this->action->get() == "config"); - } + EXPECT_EQ(action->get_default(), "list"); + EXPECT_EQ(action->get(), "list"); - void - test_current_fail() - { - add_examples(*this->action); + action->set("config"); + EXPECT_EQ(action->get_default(), "list"); + EXPECT_EQ(action->get(), "config"); +} - this->action->set("invalid"); - } +TEST_F(OptionAction, CurrentFail) +{ + add_examples(*action); - void - test_current_fail_multipleset() - { - add_examples(*this->action); + ASSERT_THROW(action->set("invalid"), bin_common::options::error); +} - this->action->set("list"); - this->action->set("info"); - } +TEST_F(OptionAction, CurrentFailMultipleSet) +{ + add_examples(*action); - void - test_operators() - { - add_examples(*this->action); + ASSERT_NO_THROW(action->set("list")); + ASSERT_THROW(action->set("info"), bin_common::options::error); +} - *this->action = "list"; - CPPUNIT_ASSERT(*this->action == "list"); - CPPUNIT_ASSERT(!(*this->action != "list")); - CPPUNIT_ASSERT(*this->action != "invalid"); - CPPUNIT_ASSERT(!(*this->action == "invalid")); - } +TEST_F(OptionAction, Operators) +{ + add_examples(*action); - void - test_operators_fail_multipleset() - { - add_examples(*this->action); + *action = "list"; + EXPECT_TRUE(*action == "list"); + EXPECT_FALSE(*action !="list"); + EXPECT_TRUE(*action != "invalid"); + EXPECT_FALSE(*action == "invalid"); +} - *this->action = "list"; - *this->action = "config"; - } -}; +TEST_F(OptionAction, OperatorsFailMultipleSet) +{ + add_examples(*action); -CPPUNIT_TEST_SUITE_REGISTRATION(test_option_action); + ASSERT_NO_THROW(*action = "list"); + ASSERT_THROW(*action = "config", bin_common::options::error); +} |