summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2013-09-08 11:51:44 +0100
committerRoger Leigh <rleigh@debian.org>2013-09-08 18:17:30 +0100
commit2a7730be0ee929ca117b8e016d35724f3aa67478 (patch)
tree22ce9fcdc73cb31b5aa595c79f778af448819236
parent40a09e6c099dbc840dea362ea97681c66672560c (diff)
downloadschroot-2a7730be0ee929ca117b8e016d35724f3aa67478.tar.gz
test: Convert test/bin-common/option-action to use gtest
-rw-r--r--test/Makefile.am2
-rw-r--r--test/bin-common/option-action.cc168
2 files changed, 69 insertions, 101 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index e650a89f..f829c531 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -178,7 +178,7 @@ test_sbuild_util_SOURCES = test/sbuild/util.cc
test_sbuild_util_LDADD = lib/test/libtest2.la
test_bin_common_option_action_SOURCES = test/bin-common/option-action.cc
-test_bin_common_option_action_LDADD = $(top_builddir)/lib/bin-common/libbin-common.la lib/test/libtest.la
+test_bin_common_option_action_LDADD = $(top_builddir)/lib/bin-common/libbin-common.la lib/test/libtest2.la
EXTRA_DIST += \
test/keyfile.ex1 \
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);
+}