aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-25 12:57:27 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-25 16:55:34 +0000
commitbf3ada970ee7a445868c6763d2e6e2d036aea608 (patch)
tree081a1dc2c85ef9881c1d9231c9afeabcf40c84eb
parentd304be1945067c24830c9210bc03638f4f4b3a12 (diff)
downloadpaludis-bf3ada970ee7a445868c6763d2e6e2d036aea608.tar.gz
paludis-bf3ada970ee7a445868c6763d2e6e2d036aea608.tar.xz
gtest more
-rw-r--r--paludis/repositories/virtuals/Makefile.am12
-rw-r--r--paludis/repositories/virtuals/installed_virtuals_repository_TEST.cc22
-rw-r--r--paludis/repositories/virtuals/virtuals_repository_TEST.cc265
3 files changed, 140 insertions, 159 deletions
diff --git a/paludis/repositories/virtuals/Makefile.am b/paludis/repositories/virtuals/Makefile.am
index 3058f31..eda3157 100644
--- a/paludis/repositories/virtuals/Makefile.am
+++ b/paludis/repositories/virtuals/Makefile.am
@@ -31,19 +31,23 @@ check_SCRIPTS =
EXTRA_DIST = $(virtuals_repository_TEST_SOURCES) $(installed_virtuals_repository_TEST_SOURCES)
virtuals_repository_TEST_LDADD = \
+ $(top_builddir)/paludis/util/gtest_runner.o \
$(top_builddir)/paludis/util/libpaludisutil_@PALUDIS_PC_SLOT@.la \
- $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \
- $(top_builddir)/test/libtest.a
+ $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la
virtuals_repository_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+virtuals_repository_TEST_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@
+
installed_virtuals_repository_TEST_LDADD = \
+ $(top_builddir)/paludis/util/gtest_runner.o \
$(top_builddir)/paludis/util/libpaludisutil_@PALUDIS_PC_SLOT@.la \
- $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \
- $(top_builddir)/test/libtest.a
+ $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la
installed_virtuals_repository_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+installed_virtuals_repository_TEST_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@
+
virtuals_repository_TEST_SOURCES = \
virtuals_repository_TEST.cc
diff --git a/paludis/repositories/virtuals/installed_virtuals_repository_TEST.cc b/paludis/repositories/virtuals/installed_virtuals_repository_TEST.cc
index d1156cb..aac3eac 100644
--- a/paludis/repositories/virtuals/installed_virtuals_repository_TEST.cc
+++ b/paludis/repositories/virtuals/installed_virtuals_repository_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008, 2010 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2010, 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
@@ -17,25 +17,17 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
#include <paludis/repositories/virtuals/installed_virtuals_repository.hh>
+
#include <paludis/environments/test/test_environment.hh>
-using namespace test;
+#include <gtest/gtest.h>
+
using namespace paludis;
-namespace test_cases
+TEST(InstalledVirtualsRepository, Workss)
{
- struct InstalledVirtualsRepositoryTest : TestCase
- {
- InstalledVirtualsRepositoryTest() : TestCase("installed virtuals repository") { }
-
- void run()
- {
- TestEnvironment env;
- std::shared_ptr<const InstalledVirtualsRepository> r(std::make_shared<InstalledVirtualsRepository>(&env, FSPath("/")));
- }
- } test_installed_virtuals_repository;
+ TestEnvironment env;
+ std::shared_ptr<const InstalledVirtualsRepository> r(std::make_shared<InstalledVirtualsRepository>(&env, FSPath("/")));
}
diff --git a/paludis/repositories/virtuals/virtuals_repository_TEST.cc b/paludis/repositories/virtuals/virtuals_repository_TEST.cc
index 6c27e44..e38d4a4 100644
--- a/paludis/repositories/virtuals/virtuals_repository_TEST.cc
+++ b/paludis/repositories/virtuals/virtuals_repository_TEST.cc
@@ -17,164 +17,149 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
-
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
+
#include <paludis/repositories/virtuals/virtuals_repository.hh>
+
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/package_database.hh>
#include <paludis/generator.hh>
#include <paludis/filter.hh>
#include <paludis/filtered_generator.hh>
#include <paludis/selection.hh>
+#include <paludis/user_dep_spec.hh>
+
#include <paludis/util/sequence.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/options.hh>
#include <paludis/util/make_named_values.hh>
-#include <paludis/user_dep_spec.hh>
-using namespace test;
+#include <gtest/gtest.h>
+
using namespace paludis;
-namespace test_cases
+TEST(VirtualsRepository, Works)
+{
+ TestEnvironment env;
+ std::shared_ptr<VirtualsRepository> virtuals(std::make_shared<VirtualsRepository>(&env));
+ const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo")
+ )));
+ std::shared_ptr<FakeInstalledRepository> installed(std::make_shared<FakeInstalledRepository>(
+ make_named_values<FakeInstalledRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("installed"),
+ n::suitable_destination() = true,
+ n::supports_uninstall() = true
+ )));
+
+ ASSERT_TRUE(repo->virtuals_interface());
+
+ env.package_database()->add_repository(2, virtuals);
+ env.package_database()->add_repository(3, repo);
+ env.package_database()->add_repository(4, installed);
+
+ repo->add_version("cat", "pkg", "1")->provide_key()->set_from_string("virtual/pkg");
+ repo->add_version("cat", "pkg", "2")->provide_key()->set_from_string("virtual/pkg");
+ repo->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
+ parse_user_package_dep_spec(">=cat/pkg-2", &env, { })));
+
+ ASSERT_TRUE(bool(repo->virtual_packages()));
+ ASSERT_EQ(1, std::distance(repo->virtual_packages()->begin(), repo->virtual_packages()->end()));
+
+ EXPECT_TRUE(virtuals->has_category_named(CategoryNamePart("virtual"), { }));
+ EXPECT_TRUE(virtuals->has_package_named(QualifiedPackageName("virtual/pkg"), { }));
+
+ std::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
+ ASSERT_EQ("cat/pkg-1:0::repo | cat/pkg-2:0::repo | virtual/pkg-2::virtuals (virtual for cat/pkg-2:0::repo)",
+ join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "));
+}
+
+TEST(VirtualsRepository, Duplicates)
+{
+ TestEnvironment env;
+ std::shared_ptr<VirtualsRepository> virtuals(std::make_shared<VirtualsRepository>(&env));
+ const std::shared_ptr<FakeRepository> repo1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo1")
+ )));
+ const std::shared_ptr<FakeRepository> repo2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo2")
+ )));
+ std::shared_ptr<FakeInstalledRepository> installed(std::make_shared<FakeInstalledRepository>(
+ make_named_values<FakeInstalledRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("installed"),
+ n::suitable_destination() = true,
+ n::supports_uninstall() = true
+ )));
+
+ env.package_database()->add_repository(2, virtuals);
+ env.package_database()->add_repository(3, repo1);
+ env.package_database()->add_repository(4, repo2);
+ env.package_database()->add_repository(5, installed);
+
+ repo1->add_version("cat", "pkg", "1")->provide_key()->set_from_string("virtual/pkg");
+ repo1->add_version("cat", "pkg", "2")->provide_key()->set_from_string("virtual/pkg");
+ repo1->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
+ parse_user_package_dep_spec(">=cat/pkg-2", &env, { })));
+ repo1->add_virtual_package(QualifiedPackageName("virtual/foo"), std::make_shared<PackageDepSpec>(
+ parse_user_package_dep_spec(">=cat/pkg-2", &env, { })));
+
+ repo2->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
+ parse_user_package_dep_spec(">=cat/pkg-2", &env, { })));
+ repo2->add_virtual_package(QualifiedPackageName("virtual/foo"), std::make_shared<PackageDepSpec>(
+ parse_user_package_dep_spec("<=cat/pkg-1", &env, { })));
+
+ EXPECT_TRUE(virtuals->has_category_named(CategoryNamePart("virtual"), { }));
+ EXPECT_TRUE(virtuals->has_package_named(QualifiedPackageName("virtual/pkg"), { }));
+
+ std::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
+ ASSERT_EQ("cat/pkg-1:0::repo1 | cat/pkg-2:0::repo1 | "
+ "virtual/foo-1::virtuals (virtual for cat/pkg-1:0::repo1) | "
+ "virtual/foo-2::virtuals (virtual for cat/pkg-2:0::repo1) | "
+ "virtual/pkg-2::virtuals (virtual for cat/pkg-2:0::repo1)",
+ join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "));
+}
+
+TEST(VirtualsRepository, Recursion)
{
- struct VirtualsRepositoryTest : TestCase
- {
- VirtualsRepositoryTest() : TestCase("virtuals repository") { }
-
- void run()
- {
- TestEnvironment env;
- std::shared_ptr<VirtualsRepository> virtuals(std::make_shared<VirtualsRepository>(&env));
- const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo")
- )));
- std::shared_ptr<FakeInstalledRepository> installed(std::make_shared<FakeInstalledRepository>(
- make_named_values<FakeInstalledRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("installed"),
- n::suitable_destination() = true,
- n::supports_uninstall() = true
- )));
-
- TEST_CHECK(repo->virtuals_interface());
-
- env.package_database()->add_repository(2, virtuals);
- env.package_database()->add_repository(3, repo);
- env.package_database()->add_repository(4, installed);
-
- repo->add_version("cat", "pkg", "1")->provide_key()->set_from_string("virtual/pkg");
- repo->add_version("cat", "pkg", "2")->provide_key()->set_from_string("virtual/pkg");
- repo->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
- parse_user_package_dep_spec(">=cat/pkg-2", &env, { })));
-
- TEST_CHECK(bool(repo->virtual_packages()));
- TEST_CHECK_EQUAL(std::distance(repo->virtual_packages()->begin(), repo->virtual_packages()->end()), 1);
-
- TEST_CHECK(virtuals->has_category_named(CategoryNamePart("virtual"), { }));
- TEST_CHECK(virtuals->has_package_named(QualifiedPackageName("virtual/pkg"), { }));
-
- std::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
- TEST_CHECK_STRINGIFY_EQUAL(join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "),
- "cat/pkg-1:0::repo | cat/pkg-2:0::repo | virtual/pkg-2::virtuals (virtual for cat/pkg-2:0::repo)");
- }
- } test_virtuals_repository;
-
- struct VirtualsRepositoryDuplicatesTest : TestCase
- {
- VirtualsRepositoryDuplicatesTest() : TestCase("virtuals repository duplicates") { }
-
- void run()
- {
- TestEnvironment env;
- std::shared_ptr<VirtualsRepository> virtuals(std::make_shared<VirtualsRepository>(&env));
- const std::shared_ptr<FakeRepository> repo1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo1")
- )));
- const std::shared_ptr<FakeRepository> repo2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo2")
- )));
- std::shared_ptr<FakeInstalledRepository> installed(std::make_shared<FakeInstalledRepository>(
- make_named_values<FakeInstalledRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("installed"),
- n::suitable_destination() = true,
- n::supports_uninstall() = true
- )));
-
- env.package_database()->add_repository(2, virtuals);
- env.package_database()->add_repository(3, repo1);
- env.package_database()->add_repository(4, repo2);
- env.package_database()->add_repository(5, installed);
-
- repo1->add_version("cat", "pkg", "1")->provide_key()->set_from_string("virtual/pkg");
- repo1->add_version("cat", "pkg", "2")->provide_key()->set_from_string("virtual/pkg");
- repo1->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
- parse_user_package_dep_spec(">=cat/pkg-2", &env, { })));
- repo1->add_virtual_package(QualifiedPackageName("virtual/foo"), std::make_shared<PackageDepSpec>(
- parse_user_package_dep_spec(">=cat/pkg-2", &env, { })));
-
- repo2->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
- parse_user_package_dep_spec(">=cat/pkg-2", &env, { })));
- repo2->add_virtual_package(QualifiedPackageName("virtual/foo"), std::make_shared<PackageDepSpec>(
- parse_user_package_dep_spec("<=cat/pkg-1", &env, { })));
-
- TEST_CHECK(virtuals->has_category_named(CategoryNamePart("virtual"), { }));
- TEST_CHECK(virtuals->has_package_named(QualifiedPackageName("virtual/pkg"), { }));
-
- std::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
- TEST_CHECK_STRINGIFY_EQUAL(join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "),
- "cat/pkg-1:0::repo1 | cat/pkg-2:0::repo1 | "
- "virtual/foo-1::virtuals (virtual for cat/pkg-1:0::repo1) | "
- "virtual/foo-2::virtuals (virtual for cat/pkg-2:0::repo1) | "
- "virtual/pkg-2::virtuals (virtual for cat/pkg-2:0::repo1)");
- }
- } test_virtuals_repository_duplicates;
-
- struct VirtualsRepositoryRecursionTest : TestCase
- {
- VirtualsRepositoryRecursionTest() : TestCase("virtuals repository recursion") { }
-
- void run()
- {
- TestEnvironment env;
- std::shared_ptr<VirtualsRepository> virtuals(std::make_shared<VirtualsRepository>(&env));
- const std::shared_ptr<FakeRepository> repo1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo1")
- )));
- const std::shared_ptr<FakeRepository> repo2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo2")
- )));
-
- env.package_database()->add_repository(2, repo1);
- env.package_database()->add_repository(3, repo2);
- env.package_database()->add_repository(4, virtuals);
-
- repo1->add_version("virtual", "gkp", "1")->provide_key()->set_from_string("virtual/pkg");
- repo1->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
- parse_user_package_dep_spec("virtual/gkp", &env, { })));
-
- repo2->add_version("virtual", "pkg", "2")->provide_key()->set_from_string("virtual/pkg");
- repo2->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
- parse_user_package_dep_spec("virtual/pkg", &env, { })));
-
- TEST_CHECK(virtuals->has_category_named(CategoryNamePart("virtual"), { }));
- TEST_CHECK(virtuals->has_package_named(QualifiedPackageName("virtual/pkg"), { }));
-
- std::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
- TEST_CHECK_STRINGIFY_EQUAL(join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "),
- "virtual/gkp-1:0::repo1 | virtual/pkg-1::virtuals (virtual for virtual/gkp-1:0::repo1) | "
- "virtual/pkg-2:0::repo2 | virtual/pkg-2::virtuals (virtual for virtual/pkg-2:0::repo2)");
- }
- } test_virtuals_repository_recursion;
+ TestEnvironment env;
+ std::shared_ptr<VirtualsRepository> virtuals(std::make_shared<VirtualsRepository>(&env));
+ const std::shared_ptr<FakeRepository> repo1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo1")
+ )));
+ const std::shared_ptr<FakeRepository> repo2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo2")
+ )));
+
+ env.package_database()->add_repository(2, repo1);
+ env.package_database()->add_repository(3, repo2);
+ env.package_database()->add_repository(4, virtuals);
+
+ repo1->add_version("virtual", "gkp", "1")->provide_key()->set_from_string("virtual/pkg");
+ repo1->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
+ parse_user_package_dep_spec("virtual/gkp", &env, { })));
+
+ repo2->add_version("virtual", "pkg", "2")->provide_key()->set_from_string("virtual/pkg");
+ repo2->add_virtual_package(QualifiedPackageName("virtual/pkg"), std::make_shared<PackageDepSpec>(
+ parse_user_package_dep_spec("virtual/pkg", &env, { })));
+
+ EXPECT_TRUE(virtuals->has_category_named(CategoryNamePart("virtual"), { }));
+ EXPECT_TRUE(virtuals->has_package_named(QualifiedPackageName("virtual/pkg"), { }));
+
+ std::shared_ptr<const PackageIDSequence> r(env[selection::AllVersionsSorted(generator::All())]);
+ ASSERT_EQ(
+ "virtual/gkp-1:0::repo1 | virtual/pkg-1::virtuals (virtual for virtual/gkp-1:0::repo1) | "
+ "virtual/pkg-2:0::repo2 | virtual/pkg-2::virtuals (virtual for virtual/pkg-2:0::repo2)",
+ join(indirect_iterator(r->begin()), indirect_iterator(r->end()), " | "));
}