aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-24 23:31:48 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-24 23:31:48 +0000
commit7d3d34aefc05a3081ae075476230f9a69a7934d5 (patch)
treee2c2da87b550ec9a30a01b63fc6e1d2763cecf68
parentb511402f669b5e74e13d54e2fd11a06ac5f04963 (diff)
downloadpaludis-7d3d34aefc05a3081ae075476230f9a69a7934d5.tar.gz
paludis-7d3d34aefc05a3081ae075476230f9a69a7934d5.tar.xz
gtest more
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/package_database_TEST.cc326
2 files changed, 143 insertions, 185 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 652a4fc..e8de1a9 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -75,7 +75,7 @@ add(`notifier_callback', `hh', `cc', `fwd')
add(`output_manager', `hh', `fwd', `cc', `se')
add(`output_manager_factory', `hh', `fwd', `cc')
add(`output_manager_from_environment', `hh', `fwd', `cc')
-add(`package_database', `hh', `cc', `fwd', `test')
+add(`package_database', `hh', `cc', `fwd', `gtest')
add(`package_dep_spec_collection', `hh', `cc', `fwd')
add(`package_dep_spec_properties', `hh', `cc', `fwd')
add(`package_id', `hh', `cc', `fwd', `se')
diff --git a/paludis/package_database_TEST.cc b/paludis/package_database_TEST.cc
index 431be9b..b56aa44 100644
--- a/paludis/package_database_TEST.cc
+++ b/paludis/package_database_TEST.cc
@@ -17,9 +17,6 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <paludis/package_database.hh>
-#include <paludis/user_dep_spec.hh>
-#include <paludis/filter.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
@@ -30,197 +27,158 @@
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/options.hh>
#include <paludis/util/make_named_values.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
+
+#include <paludis/package_database.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/filter.hh>
+
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
-/** \file
- * Test cases for package_database.hh.
- *
- */
+TEST(PackageDatabase, Repositories)
+{
+ TestEnvironment e;
+ PackageDatabase & p(*e.package_database());
+
+ const std::shared_ptr<FakeRepository> r1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("repo1")
+ )));
+ const std::shared_ptr<FakeRepository> r2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("repo2")
+ )));
+
+ EXPECT_THROW(p.fetch_repository(RepositoryName("repo1")), NoSuchRepositoryError);
+ EXPECT_THROW(p.fetch_repository(RepositoryName("repo2")), NoSuchRepositoryError);
+
+ p.add_repository(10, r1);
+ ASSERT_TRUE(bool(p.fetch_repository(RepositoryName("repo1"))));
+ EXPECT_EQ(RepositoryName("repo1"), p.fetch_repository(RepositoryName("repo1"))->name());
+ EXPECT_THROW(p.fetch_repository(RepositoryName("repo2")), NoSuchRepositoryError);
+
+ EXPECT_THROW(p.add_repository(10, r1), DuplicateRepositoryError);
+
+ p.add_repository(11, r2);
+ ASSERT_TRUE(bool(p.fetch_repository(RepositoryName("repo1"))));
+ EXPECT_EQ(RepositoryName("repo1"), p.fetch_repository(RepositoryName("repo1"))->name());
+ ASSERT_TRUE(bool(p.fetch_repository(RepositoryName("repo2"))));
+ EXPECT_EQ(RepositoryName("repo2"), p.fetch_repository(RepositoryName("repo2"))->name());
+
+ EXPECT_THROW(p.add_repository(10, r1), DuplicateRepositoryError);
+ EXPECT_THROW(p.add_repository(5, r2), DuplicateRepositoryError);
+
+ ASSERT_TRUE(bool(p.fetch_repository(RepositoryName("repo1"))));
+ EXPECT_EQ(RepositoryName("repo1"), p.fetch_repository(RepositoryName("repo1"))->name());
+ ASSERT_TRUE(bool(p.fetch_repository(RepositoryName("repo2"))));
+ EXPECT_EQ(RepositoryName("repo2"), p.fetch_repository(RepositoryName("repo2"))->name());
+
+ EXPECT_TRUE(! p.more_important_than(RepositoryName("repo1"), RepositoryName("repo2")));
+ EXPECT_TRUE(p.more_important_than(RepositoryName("repo2"), RepositoryName("repo1")));
+ EXPECT_TRUE(! p.more_important_than(RepositoryName("repo2"), RepositoryName("repo2")));
+ EXPECT_TRUE(! p.more_important_than(RepositoryName("repo1"), RepositoryName("repo1")));
+}
-namespace test_cases
+namespace
{
- struct PackageDatabaseRepositoryTest : TestCase
+ struct CoolFakeRepository :
+ FakeRepository
{
- PackageDatabaseRepositoryTest() : TestCase("package database repository") { }
-
- void run()
+ CoolFakeRepository(const Environment * const e, const RepositoryName & rn) :
+ FakeRepository(make_named_values<FakeRepositoryParams>(
+ n::environment() = e,
+ n::name() = rn
+ ))
{
- TestEnvironment e;
- PackageDatabase & p(*e.package_database());
-
- const std::shared_ptr<FakeRepository> r1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("repo1")
- )));
- const std::shared_ptr<FakeRepository> r2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("repo2")
- )));
-
- TEST_CHECK_THROWS(p.fetch_repository(RepositoryName("repo1")), NoSuchRepositoryError);
- TEST_CHECK_THROWS(p.fetch_repository(RepositoryName("repo2")), NoSuchRepositoryError);
-
- p.add_repository(10, r1);
- TEST_CHECK(bool(p.fetch_repository(RepositoryName("repo1"))));
- TEST_CHECK_EQUAL(p.fetch_repository(RepositoryName("repo1"))->name(),
- RepositoryName("repo1"));
- TEST_CHECK_THROWS(p.fetch_repository(RepositoryName("repo2")), NoSuchRepositoryError);
-
- TEST_CHECK_THROWS(p.add_repository(10, r1), DuplicateRepositoryError);
-
- p.add_repository(11, r2);
- TEST_CHECK(bool(p.fetch_repository(RepositoryName("repo1"))));
- TEST_CHECK_EQUAL(p.fetch_repository(RepositoryName("repo1"))->name(),
- RepositoryName("repo1"));
- TEST_CHECK(bool(p.fetch_repository(RepositoryName("repo2"))));
- TEST_CHECK_EQUAL(p.fetch_repository(RepositoryName("repo2"))->name(),
- RepositoryName("repo2"));
-
- TEST_CHECK_THROWS(p.add_repository(10, r1), DuplicateRepositoryError);
- TEST_CHECK_THROWS(p.add_repository(5, r2), DuplicateRepositoryError);
-
- TEST_CHECK(bool(p.fetch_repository(RepositoryName("repo1"))));
- TEST_CHECK_EQUAL(p.fetch_repository(RepositoryName("repo1"))->name(),
- RepositoryName("repo1"));
- TEST_CHECK(bool(p.fetch_repository(RepositoryName("repo2"))));
- TEST_CHECK_EQUAL(p.fetch_repository(RepositoryName("repo2"))->name(),
- RepositoryName("repo2"));
-
- TEST_CHECK(! p.more_important_than(RepositoryName("repo1"), RepositoryName("repo2")));
- TEST_CHECK(p.more_important_than(RepositoryName("repo2"), RepositoryName("repo1")));
- TEST_CHECK(! p.more_important_than(RepositoryName("repo2"), RepositoryName("repo2")));
- TEST_CHECK(! p.more_important_than(RepositoryName("repo1"), RepositoryName("repo1")));
}
- } package_database_repository_test;
- struct PackageDatabaseDisambiguateTest : TestCase
- {
- PackageDatabaseDisambiguateTest() : TestCase("package database disambiguate") { }
-
- struct CoolFakeRepository :
- FakeRepository
- {
- CoolFakeRepository(const Environment * const e, const RepositoryName & rn) :
- FakeRepository(make_named_values<FakeRepositoryParams>(
- n::environment() = e,
- n::name() = rn
- ))
- {
- }
-
- std::shared_ptr<const CategoryNamePartSet> unimportant_category_names(const RepositoryContentMayExcludes &) const
- {
- std::shared_ptr<CategoryNamePartSet> result(std::make_shared<CategoryNamePartSet>());
- result->insert(CategoryNamePart("bad-cat1"));
- result->insert(CategoryNamePart("bad-cat2"));
- return result;
- }
- };
-
- void run()
+ std::shared_ptr<const CategoryNamePartSet> unimportant_category_names(const RepositoryContentMayExcludes &) const
{
- TestEnvironment e;
- PackageDatabase & p(*e.package_database());
-
- std::shared_ptr<FakeRepository> r1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("repo1"))));
- r1->add_version(CategoryNamePart("cat-one") + PackageNamePart("pkg-one"), VersionSpec("0", { }));
- r1->add_version(CategoryNamePart("cat-one") + PackageNamePart("pkg-two"), VersionSpec("0", { }));
- r1->add_version(CategoryNamePart("cat-two") + PackageNamePart("pkg-two"), VersionSpec("0", { }));
- r1->add_version(CategoryNamePart("cat-two") + PackageNamePart("pkg-three"), VersionSpec("0", { }));
- p.add_repository(10, r1);
- TEST_CHECK(true);
-
- std::shared_ptr<FakeRepository> r2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("repo2"))));
- r2->add_version(CategoryNamePart("cat-three") + PackageNamePart("pkg-three"), VersionSpec("0", { }));
- r2->add_version(CategoryNamePart("cat-three") + PackageNamePart("pkg-four"), VersionSpec("0", { }));
- p.add_repository(10, r2);
- TEST_CHECK(true);
-
- std::shared_ptr<FakeRepository> r3(std::make_shared<CoolFakeRepository>(&e, RepositoryName("repo3")));
- r3->add_version(CategoryNamePart("bad-cat1") + PackageNamePart("pkg-important"), VersionSpec("0", { }));
- r3->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-important"), VersionSpec("0", { }));
-
- r3->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-installed"), VersionSpec("0", { }));
- r3->add_version(CategoryNamePart("good-cat2") + PackageNamePart("pkg-installed"), VersionSpec("0", { }));
-
- r3->add_version(CategoryNamePart("bad-cat1") + PackageNamePart("pkg-fail1"), VersionSpec("0", { }));
- r3->add_version(CategoryNamePart("bad-cat2") + PackageNamePart("pkg-fail1"), VersionSpec("0", { }));
-
- r3->add_version(CategoryNamePart("bad-cat1") + PackageNamePart("pkg-fail2"), VersionSpec("0", { }));
- r3->add_version(CategoryNamePart("bad-cat2") + PackageNamePart("pkg-fail2"), VersionSpec("0", { }));
-
- r3->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-fail3"), VersionSpec("0", { }));
- r3->add_version(CategoryNamePart("good-cat2") + PackageNamePart("pkg-fail3"), VersionSpec("0", { }));
-
- r3->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-fail4"), VersionSpec("0", { }));
- r3->add_version(CategoryNamePart("good-cat2") + PackageNamePart("pkg-fail4"), VersionSpec("0", { }));
-
- r3->add_version(CategoryNamePart("avail-cat") + PackageNamePart("pkg-foo"), VersionSpec("0", { }));
- p.add_repository(10, r3);
- TEST_CHECK(true);
-
- std::shared_ptr<FakeInstalledRepository> r4(std::make_shared<FakeInstalledRepository>(
- make_named_values<FakeInstalledRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("repo4"),
- n::suitable_destination() = true,
- n::supports_uninstall() = true
- )));
- r4->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-installed"), VersionSpec("0", { }));
- r4->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-fail4"), VersionSpec("0", { }));
- r4->add_version(CategoryNamePart("good-cat2") + PackageNamePart("pkg-fail4"), VersionSpec("0", { }));
- r4->add_version(CategoryNamePart("inst-cat") + PackageNamePart("pkg-foo"), VersionSpec("0", { }));
- p.add_repository(10, r4);
-
- TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-one")),
- "cat-one/pkg-one");
- TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-four")),
- "cat-three/pkg-four");
-
- TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-important")),
- "good-cat1/pkg-important");
-
- TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-installed")),
- "good-cat1/pkg-installed");
-
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-two")),
- AmbiguousPackageNameError);
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-three")),
- AmbiguousPackageNameError);
-
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-fail1")),
- AmbiguousPackageNameError);
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-fail2")),
- AmbiguousPackageNameError);
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-fail3")),
- AmbiguousPackageNameError);
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-fail4")),
- AmbiguousPackageNameError);
-
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-five")),
- NoSuchPackageError);
-
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-one"),
- filter::SupportsAction<ConfigAction>()),
- NoSuchPackageError);
- TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-foo")),
- "inst-cat/pkg-foo");
- TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-foo"),
- filter::SupportsAction<InstallAction>()),
- "avail-cat/pkg-foo");
- TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-foo"),
- filter::All(), false),
- AmbiguousPackageNameError);
-
+ std::shared_ptr<CategoryNamePartSet> result(std::make_shared<CategoryNamePartSet>());
+ result->insert(CategoryNamePart("bad-cat1"));
+ result->insert(CategoryNamePart("bad-cat2"));
+ return result;
}
- } package_database_disambiguate_test;
+ };
+}
+
+TEST(PackageDatabase, Disambiguation)
+{
+ TestEnvironment e;
+ PackageDatabase & p(*e.package_database());
+
+ std::shared_ptr<FakeRepository> r1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("repo1"))));
+ r1->add_version(CategoryNamePart("cat-one") + PackageNamePart("pkg-one"), VersionSpec("0", { }));
+ r1->add_version(CategoryNamePart("cat-one") + PackageNamePart("pkg-two"), VersionSpec("0", { }));
+ r1->add_version(CategoryNamePart("cat-two") + PackageNamePart("pkg-two"), VersionSpec("0", { }));
+ r1->add_version(CategoryNamePart("cat-two") + PackageNamePart("pkg-three"), VersionSpec("0", { }));
+ p.add_repository(10, r1);
+
+ std::shared_ptr<FakeRepository> r2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("repo2"))));
+ r2->add_version(CategoryNamePart("cat-three") + PackageNamePart("pkg-three"), VersionSpec("0", { }));
+ r2->add_version(CategoryNamePart("cat-three") + PackageNamePart("pkg-four"), VersionSpec("0", { }));
+ p.add_repository(10, r2);
+
+ std::shared_ptr<FakeRepository> r3(std::make_shared<CoolFakeRepository>(&e, RepositoryName("repo3")));
+ r3->add_version(CategoryNamePart("bad-cat1") + PackageNamePart("pkg-important"), VersionSpec("0", { }));
+ r3->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-important"), VersionSpec("0", { }));
+
+ r3->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-installed"), VersionSpec("0", { }));
+ r3->add_version(CategoryNamePart("good-cat2") + PackageNamePart("pkg-installed"), VersionSpec("0", { }));
+
+ r3->add_version(CategoryNamePart("bad-cat1") + PackageNamePart("pkg-fail1"), VersionSpec("0", { }));
+ r3->add_version(CategoryNamePart("bad-cat2") + PackageNamePart("pkg-fail1"), VersionSpec("0", { }));
+
+ r3->add_version(CategoryNamePart("bad-cat1") + PackageNamePart("pkg-fail2"), VersionSpec("0", { }));
+ r3->add_version(CategoryNamePart("bad-cat2") + PackageNamePart("pkg-fail2"), VersionSpec("0", { }));
+
+ r3->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-fail3"), VersionSpec("0", { }));
+ r3->add_version(CategoryNamePart("good-cat2") + PackageNamePart("pkg-fail3"), VersionSpec("0", { }));
+
+ r3->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-fail4"), VersionSpec("0", { }));
+ r3->add_version(CategoryNamePart("good-cat2") + PackageNamePart("pkg-fail4"), VersionSpec("0", { }));
+
+ r3->add_version(CategoryNamePart("avail-cat") + PackageNamePart("pkg-foo"), VersionSpec("0", { }));
+ p.add_repository(10, r3);
+
+ std::shared_ptr<FakeInstalledRepository> r4(std::make_shared<FakeInstalledRepository>(
+ make_named_values<FakeInstalledRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("repo4"),
+ n::suitable_destination() = true,
+ n::supports_uninstall() = true
+ )));
+ r4->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-installed"), VersionSpec("0", { }));
+ r4->add_version(CategoryNamePart("good-cat1") + PackageNamePart("pkg-fail4"), VersionSpec("0", { }));
+ r4->add_version(CategoryNamePart("good-cat2") + PackageNamePart("pkg-fail4"), VersionSpec("0", { }));
+ r4->add_version(CategoryNamePart("inst-cat") + PackageNamePart("pkg-foo"), VersionSpec("0", { }));
+ p.add_repository(10, r4);
+
+ EXPECT_EQ("cat-one/pkg-one", stringify(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-one"))));
+ EXPECT_EQ("cat-three/pkg-four", stringify(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-four"))));
+ EXPECT_EQ("good-cat1/pkg-important", stringify(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-important"))));
+ EXPECT_EQ("good-cat1/pkg-installed", stringify(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-installed"))));
+
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-two")), AmbiguousPackageNameError);
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-three")), AmbiguousPackageNameError);
+
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-fail1")), AmbiguousPackageNameError);
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-fail2")), AmbiguousPackageNameError);
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-fail3")), AmbiguousPackageNameError);
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-fail4")), AmbiguousPackageNameError);
+
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-five")), NoSuchPackageError);
+
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-one"),
+ filter::SupportsAction<ConfigAction>()), NoSuchPackageError);
+ EXPECT_EQ("inst-cat/pkg-foo", stringify(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-foo"))));
+ EXPECT_EQ("avail-cat/pkg-foo", stringify(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-foo"), filter::SupportsAction<InstallAction>())));
+ EXPECT_THROW(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-foo"), filter::All(), false), AmbiguousPackageNameError);
+
}