aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-26 21:16:58 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-26 21:16:58 +0000
commita704721618f5bdefc9ea9b6e70c5973986ce8ac3 (patch)
tree7fc4dd8faa1852d4b4ef45edca7928d7953ccb8d
parent866188d1f7ea888ec44de0e112505f0fc14451c5 (diff)
downloadpaludis-a704721618f5bdefc9ea9b6e70c5973986ce8ac3.tar.gz
paludis-a704721618f5bdefc9ea9b6e70c5973986ce8ac3.tar.xz
gtest more
-rw-r--r--paludis/repositories/e/Makefile.am4
-rw-r--r--paludis/repositories/e/vdb_merger_TEST.cc303
2 files changed, 132 insertions, 175 deletions
diff --git a/paludis/repositories/e/Makefile.am b/paludis/repositories/e/Makefile.am
index 911a66d..e2478e4 100644
--- a/paludis/repositories/e/Makefile.am
+++ b/paludis/repositories/e/Makefile.am
@@ -356,13 +356,15 @@ exndbam_repository_TEST_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir) @PALUDIS_CXXFL
vdb_merger_TEST_SOURCES = vdb_merger_TEST.cc
vdb_merger_TEST_LDADD = \
- $(top_builddir)/paludis/util/libpaludisutil_@PALUDIS_PC_SLOT@.la \
+ $(top_builddir)/paludis/util/gtest_runner.o \
$(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \
$(top_builddir)/test/libtest.a \
$(DYNAMIC_LD_LIBS)
vdb_merger_TEST_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+vdb_merger_TEST_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@
+
vdb_unmerger_TEST_SOURCES = vdb_unmerger_TEST.cc
vdb_unmerger_TEST_LDADD = \
diff --git a/paludis/repositories/e/vdb_merger_TEST.cc b/paludis/repositories/e/vdb_merger_TEST.cc
index 79db1de..034a5b1 100644
--- a/paludis/repositories/e/vdb_merger_TEST.cc
+++ b/paludis/repositories/e/vdb_merger_TEST.cc
@@ -3,6 +3,7 @@
/*
* Copyright (c) 2007 Piotr JaroszyƄski
* Copyright (c) 2007 David Leverton
+ * Copyright (c) 2011 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -18,19 +19,22 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "vdb_merger.hh"
+#include <paludis/repositories/e/vdb_merger.hh>
+
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/repositories/fake/fake_repository.hh>
+
#include <paludis/util/make_named_values.hh>
#include <paludis/util/safe_ifstream.hh>
#include <paludis/util/set.hh>
#include <paludis/util/fs_stat.hh>
+
#include <paludis/standard_output_manager.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
+
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
namespace
{
@@ -58,198 +62,149 @@ namespace
}
};
- class VDBMergerTest :
- public TestCase
- {
- public:
-
- FSPath root_dir;
- std::string target;
- TestEnvironment env;
- VDBMergerNoDisplay merger;
-
- bool repeatable() const
- {
- return false;
- }
-
- protected:
-
- VDBMergerTest(const std::string & what) :
- TestCase("merge '" + what + "' test"),
- root_dir(FSPath::cwd() / "vdb_merger_TEST_dir" / what / "root"),
- target(what),
- merger(make_named_values<VDBMergerParams>(
- n::config_protect() = "/protected_file /protected_dir",
- n::config_protect_mask() = "/protected_dir/unprotected_file /protected_dir/unprotected_dir",
- n::contents_file() = FSPath::cwd() / "vdb_merger_TEST_dir/CONTENTS" / what,
- n::environment() = &env,
- n::fix_mtimes_before() = Timestamp(0, 0),
- n::image() = FSPath::cwd() / "vdb_merger_TEST_dir" / what / "image",
- n::merged_entries() = std::make_shared<FSPathSet>(),
- n::options() = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
- n::output_manager() = std::make_shared<StandardOutputManager>(),
- n::package_id() = std::shared_ptr<PackageID>(),
- n::root() = root_dir
- ))
- {
- }
- };
-}
-
-namespace test_cases
-{
- struct VDBMergerTestConfigProtect : VDBMergerTest
+ static std::string file_contents(const FSPath & f)
{
- VDBMergerTestConfigProtect() : VDBMergerTest("config_protect") { }
+ if (! f.stat().is_regular_file())
+ return "";
- static std::string file_contents(const FSPath & f)
+ try
{
- if (! f.stat().is_regular_file())
- return "";
-
- try
- {
- SafeIFStream stream(f);
+ SafeIFStream stream(f);
- std::string contents;
- stream >> contents;
- return contents;
- }
- catch (const SafeIFStreamError &)
- {
- return "";
- }
+ std::string contents;
+ stream >> contents;
+ return contents;
}
-
- void run()
+ catch (const SafeIFStreamError &)
{
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_file"), "bar");
- TEST_CHECK(! (root_dir / "._cfg0000_protected_file").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "unprotected_file"), "bar");
- TEST_CHECK(! (root_dir / "._cfg0000_unprotected_file").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_file_not_really"), "bar");
- TEST_CHECK(! (root_dir / "._cfg0000_protected_file_not_really").stat().exists());
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file"), "bar");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_protected_file").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_file"), "bar");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unprotected_file").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_file_not_really"), "bar");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unprotected_file_not_really").stat().exists());
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file_already_needs_update"), "bar");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file_already_needs_update"), "baz");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0001_protected_file_already_needs_update").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unchanged_protected_file"), "foo");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unchanged_protected_file").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file_same_as_existing_update"), "bar");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file_same_as_existing_update"), "foo");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0001_protected_file_same_as_existing_update").stat().exists());
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir/unprotected_file"), "bar");
- TEST_CHECK(! (root_dir / "protected_dir/unprotected_dir/._cfg0000_unprotected_file").stat().exists());
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir_not_really/protected_file"), "bar");
- TEST_CHECK(! (root_dir / "protected_dir/unprotected_dir_not_really/._cfg0000_protected_file").stat().exists());
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir_not_really/unprotected_file"), "bar");
- TEST_CHECK(! (root_dir / "protected_dir_not_really/._cfg0000_unprotected_file").stat().exists());
-
- merger.merge();
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_file"), "bar");
- TEST_CHECK_EQUAL(file_contents(root_dir / "._cfg0000_protected_file"), "foo");
- TEST_CHECK_EQUAL(file_contents(root_dir / "unprotected_file"), "foo");
- TEST_CHECK(! (root_dir / "._cfg0000_unprotected_file").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_file_not_really"), "foo");
- TEST_CHECK(! (root_dir / "._cfg0000_protected_file_not_really").stat().exists());
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file"), "bar");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file"), "foo");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_file"), "foo");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unprotected_file").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_file_not_really"), "bar");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_unprotected_file_not_really"), "foo");
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file_already_needs_update"), "bar");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file_already_needs_update"), "baz");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0001_protected_file_already_needs_update"), "foo");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unchanged_protected_file"), "foo");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0000_unchanged_protected_file").stat().exists());
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/protected_file_same_as_existing_update"), "bar");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/._cfg0000_protected_file_same_as_existing_update"), "foo");
- TEST_CHECK(! (root_dir / "protected_dir/._cfg0001_protected_file_same_as_existing_update").stat().exists());
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir/unprotected_file"), "foo");
- TEST_CHECK(! (root_dir / "protected_dir/unprotected_dir/._cfg0000_unprotected_file").stat().exists());
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir_not_really/protected_file"), "bar");
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir/unprotected_dir_not_really/._cfg0000_protected_file"), "foo");
-
- TEST_CHECK_EQUAL(file_contents(root_dir / "protected_dir_not_really/unprotected_file"), "foo");
- TEST_CHECK(! (root_dir / "protected_dir_not_really/._cfg0000_unprotected_file").stat().exists());
+ return "";
}
- } test_vdb_merger_config_protect;
+ }
- struct VDBMergerTestFileNewline : VDBMergerTest
+ struct VDBMergerTest :
+ testing::TestWithParam<std::string>
{
- VDBMergerTestFileNewline() : VDBMergerTest("file_newline") { }
+ TestEnvironment env;
+ std::string target;
+ FSPath root_dir;
+ std::shared_ptr<VDBMergerNoDisplay> merger;
- void run()
+ VDBMergerTest() :
+ root_dir("/")
{
- TEST_CHECK_THROWS(merger.check(), FSMergerError);
}
- } test_vdb_merger_file_newline;
-
- struct VDBMergerTestDirNewline : VDBMergerTest
- {
- VDBMergerTestDirNewline() : VDBMergerTest("dir_newline") { }
- void run()
+ void SetUp()
{
- TEST_CHECK_THROWS(merger.check(), FSMergerError);
+ target = GetParam();
+ root_dir = FSPath::cwd() / "vdb_merger_TEST_dir" / target / "root";
+ merger = std::make_shared<VDBMergerNoDisplay>(make_named_values<VDBMergerParams>(
+ n::config_protect() = "/protected_file /protected_dir",
+ n::config_protect_mask() = "/protected_dir/unprotected_file /protected_dir/unprotected_dir",
+ n::contents_file() = FSPath::cwd() / "vdb_merger_TEST_dir/CONTENTS" / target,
+ n::environment() = &env,
+ n::fix_mtimes_before() = Timestamp(0, 0),
+ n::image() = FSPath::cwd() / "vdb_merger_TEST_dir" / target / "image",
+ n::merged_entries() = std::make_shared<FSPathSet>(),
+ n::options() = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
+ n::output_manager() = std::make_shared<StandardOutputManager>(),
+ n::package_id() = std::shared_ptr<PackageID>(),
+ n::root() = root_dir
+ ));
}
- } test_vdb_merger_dir_newline;
-
- struct VDBMergerTestSymNewline : VDBMergerTest
- {
- VDBMergerTestSymNewline() : VDBMergerTest("sym_newline") { }
- void run()
+ void TearDown()
{
- TEST_CHECK_THROWS(merger.check(), FSMergerError);
+ merger.reset();
}
- } test_vdb_merger_sym_newline;
-
- struct VDBMergerTestSymTargetNewline : VDBMergerTest
- {
- VDBMergerTestSymTargetNewline() : VDBMergerTest("sym_target_newline") { }
+ };
+}
- void run()
- {
- TEST_CHECK_THROWS(merger.check(), FSMergerError);
- }
- } test_vdb_merger_sym_target_newline;
+struct VDBMergerTestConfigProtect : VDBMergerTest { };
- struct VDBMergerTestSymArrow : VDBMergerTest
- {
- VDBMergerTestSymArrow() : VDBMergerTest("sym_arrow") { }
+TEST_P(VDBMergerTestConfigProtect, ConfigProtect)
+{
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_file"));
+ EXPECT_TRUE(! (root_dir / "._cfg0000_protected_file").stat().exists());
+ EXPECT_EQ("bar", file_contents(root_dir / "unprotected_file"));
+ EXPECT_TRUE(! (root_dir / "._cfg0000_unprotected_file").stat().exists());
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_file_not_really"));
+ EXPECT_TRUE(! (root_dir / "._cfg0000_protected_file_not_really").stat().exists());
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/protected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0000_protected_file").stat().exists());
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/unprotected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0000_unprotected_file").stat().exists());
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/unprotected_file_not_really"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0000_unprotected_file_not_really").stat().exists());
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/protected_file_already_needs_update"));
+ EXPECT_EQ("baz", file_contents(root_dir / "protected_dir/._cfg0000_protected_file_already_needs_update"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0001_protected_file_already_needs_update").stat().exists());
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/unchanged_protected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0000_unchanged_protected_file").stat().exists());
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/protected_file_same_as_existing_update"));
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/._cfg0000_protected_file_same_as_existing_update"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0001_protected_file_same_as_existing_update").stat().exists());
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/unprotected_dir/unprotected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/unprotected_dir/._cfg0000_unprotected_file").stat().exists());
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/unprotected_dir_not_really/protected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/unprotected_dir_not_really/._cfg0000_protected_file").stat().exists());
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir_not_really/unprotected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir_not_really/._cfg0000_unprotected_file").stat().exists());
+
+ merger->merge();
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_file"));
+ EXPECT_EQ("foo", file_contents(root_dir / "._cfg0000_protected_file"));
+ EXPECT_EQ("foo", file_contents(root_dir / "unprotected_file"));
+ EXPECT_TRUE(! (root_dir / "._cfg0000_unprotected_file").stat().exists());
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_file_not_really"));
+ EXPECT_TRUE(! (root_dir / "._cfg0000_protected_file_not_really").stat().exists());
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/protected_file"));
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/._cfg0000_protected_file"));
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/unprotected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0000_unprotected_file").stat().exists());
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/unprotected_file_not_really"));
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/._cfg0000_unprotected_file_not_really"));
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/protected_file_already_needs_update"));
+ EXPECT_EQ("baz", file_contents(root_dir / "protected_dir/._cfg0000_protected_file_already_needs_update"));
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/._cfg0001_protected_file_already_needs_update"));
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/unchanged_protected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0000_unchanged_protected_file").stat().exists());
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/protected_file_same_as_existing_update"));
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/._cfg0000_protected_file_same_as_existing_update"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/._cfg0001_protected_file_same_as_existing_update").stat().exists());
+
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/unprotected_dir/unprotected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir/unprotected_dir/._cfg0000_unprotected_file").stat().exists());
+
+ EXPECT_EQ("bar", file_contents(root_dir / "protected_dir/unprotected_dir_not_really/protected_file"));
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir/unprotected_dir_not_really/._cfg0000_protected_file"));
+
+ EXPECT_EQ("foo", file_contents(root_dir / "protected_dir_not_really/unprotected_file"));
+ EXPECT_TRUE(! (root_dir / "protected_dir_not_really/._cfg0000_unprotected_file").stat().exists());
+}
- void run()
- {
- TEST_CHECK_THROWS(merger.check(), FSMergerError);
- }
- } test_vdb_merger_sym_arrow;
+INSTANTIATE_TEST_CASE_P(ConfigProtect, VDBMergerTestConfigProtect, testing::Values(std::string("config_protect")));
- struct VDBMergerTestSymArrow2 : VDBMergerTest
- {
- VDBMergerTestSymArrow2() : VDBMergerTest("sym_arrow2") { }
+struct VDBMergerErrorTest : VDBMergerTest { };
- void run()
- {
- TEST_CHECK_THROWS(merger.check(), FSMergerError);
- }
- } test_vdb_merger_sym_arrow2;
+TEST_P(VDBMergerErrorTest, Error)
+{
+ EXPECT_THROW(merger->check(), FSMergerError);
}
+INSTANTIATE_TEST_CASE_P(Errors, VDBMergerErrorTest, testing::Values(
+ std::string("dir_newline"),
+ std::string("sym_newline"),
+ std::string("sym_target_newline"),
+ std::string("sym_arrow"),
+ std::string("sym_arrow2")
+ ));
+