aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-24 23:28:01 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-24 23:28:01 +0000
commitb511402f669b5e74e13d54e2fd11a06ac5f04963 (patch)
tree176d82ef198fda80f6636aa2e6aa3d9d6e2be0c8
parentde20a3101ef1ce2ec66b3c7de3991a0be1e48fa3 (diff)
downloadpaludis-b511402f669b5e74e13d54e2fd11a06ac5f04963.tar.gz
paludis-b511402f669b5e74e13d54e2fd11a06ac5f04963.tar.xz
gtest more
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/repository_name_cache_TEST.cc297
2 files changed, 131 insertions, 168 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 7579574..652a4fc 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -87,7 +87,7 @@ add(`pretty_print_options', `hh', `cc', `fwd', `se')
add(`pretty_printer', `hh', `cc', `fwd')
add(`repository', `hh', `fwd', `cc', `se')
add(`repository_factory', `hh', `fwd', `cc')
-add(`repository_name_cache', `hh', `cc', `test', `testscript')
+add(`repository_name_cache', `hh', `cc', `gtest', `testscript')
add(`selection', `hh', `cc', `fwd', `test')
add(`selection_cache', `hh', `cc', `fwd')
add(`selection_handler', `hh', `cc', `fwd')
diff --git a/paludis/repository_name_cache_TEST.cc b/paludis/repository_name_cache_TEST.cc
index c4b1b8f..acda6a9 100644
--- a/paludis/repository_name_cache_TEST.cc
+++ b/paludis/repository_name_cache_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007, 2008, 2009, 2010 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2008, 2009, 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,179 +17,142 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "repository_name_cache.hh"
-#include <paludis/environments/test/test_environment.hh>
-#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repository_name_cache.hh>
+#include <paludis/package_database.hh>
+
#include <paludis/util/join.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/set.hh>
#include <paludis/util/make_named_values.hh>
-#include <paludis/package_database.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
-using namespace test;
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/repositories/fake/fake_repository.hh>
+
+#include <gtest/gtest.h>
+
using namespace paludis;
-namespace test_cases
+TEST(RepositoryNameCache, Empty)
+{
+ TestEnvironment env;
+ const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo")
+ )));
+ env.package_database()->add_repository(10, repo);
+
+ RepositoryNameCache cache(FSPath("/var/empty"), repo.get());
+ EXPECT_TRUE(! cache.usable());
+}
+
+TEST(RepositoryNameCache, NotGenerated)
+{
+ TestEnvironment env;
+ const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo")
+ )));
+ env.package_database()->add_repository(10, repo);
+
+ RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/not_generated"), repo.get());
+ EXPECT_TRUE(cache.usable());
+ EXPECT_TRUE(! cache.category_names_containing_package(PackageNamePart("foo")));
+ EXPECT_TRUE(! cache.usable());
+}
+
+TEST(RepositoryNameCache, NotExisting)
+{
+ TestEnvironment env;
+ const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo")
+ )));
+ env.package_database()->add_repository(10, repo);
+
+ RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/not_existing"), repo.get());
+ EXPECT_TRUE(cache.usable());
+ EXPECT_TRUE(! cache.category_names_containing_package(PackageNamePart("foo")));
+ EXPECT_TRUE(! cache.usable());
+}
+
+TEST(RepositoryNameCache, OldFormat)
+{
+ TestEnvironment env;
+ const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo")
+ )));
+ env.package_database()->add_repository(10, repo);
+
+ RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/old_format"), repo.get());
+ EXPECT_TRUE(cache.usable());
+ EXPECT_TRUE(! cache.category_names_containing_package(PackageNamePart("foo")));
+ EXPECT_TRUE(! cache.usable());
+}
+
+TEST(RepositoryNameCache, BadRepo)
+{
+ TestEnvironment env;
+ const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo")
+ )));
+ env.package_database()->add_repository(10, repo);
+
+ RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/bad_repo"), repo.get());
+ EXPECT_TRUE(cache.usable());
+ EXPECT_TRUE(! cache.category_names_containing_package(PackageNamePart("foo")));
+ EXPECT_TRUE(! cache.usable());
+}
+
+TEST(RepositoryNameCache, Good)
+{
+ TestEnvironment env;
+ const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo")
+ )));
+ env.package_database()->add_repository(10, repo);
+
+ RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/good_repo"), repo.get());
+ EXPECT_TRUE(cache.usable());
+
+ std::shared_ptr<const CategoryNamePartSet> foo(cache.category_names_containing_package(PackageNamePart("foo")));
+ EXPECT_TRUE(cache.usable());
+ EXPECT_TRUE(bool(foo));
+ EXPECT_EQ("bar baz", join(foo->begin(), foo->end(), " "));
+
+ std::shared_ptr<const CategoryNamePartSet> moo(cache.category_names_containing_package(PackageNamePart("moo")));
+ EXPECT_TRUE(cache.usable());
+ EXPECT_TRUE(bool(moo));
+ EXPECT_TRUE(moo->empty());
+}
+
+TEST(RepositoryNameCache, Generate)
{
- struct NamesCacheEmptyTest : TestCase
- {
- NamesCacheEmptyTest() : TestCase("empty") { }
-
- void run()
- {
- TestEnvironment env;
- const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo")
- )));
- env.package_database()->add_repository(10, repo);
-
- RepositoryNameCache cache(FSPath("/var/empty"), repo.get());
- TEST_CHECK(! cache.usable());
- }
- } test_names_cache_empty;
-
- struct NamesCacheNotGeneratedTest : TestCase
- {
- NamesCacheNotGeneratedTest() : TestCase("not generated") { }
-
- void run()
- {
- TestEnvironment env;
- const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo")
- )));
- env.package_database()->add_repository(10, repo);
-
- RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/not_generated"), repo.get());
- TEST_CHECK(cache.usable());
- TEST_CHECK(! cache.category_names_containing_package(PackageNamePart("foo")));
- TEST_CHECK(! cache.usable());
- }
- } test_names_cache_not_generated;
-
- struct NamesCacheNotExistingTest : TestCase
- {
- NamesCacheNotExistingTest() : TestCase("not existing") { }
-
- void run()
- {
- TestEnvironment env;
- const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo")
- )));
- env.package_database()->add_repository(10, repo);
-
- RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/not_existing"), repo.get());
- TEST_CHECK(cache.usable());
- TEST_CHECK(! cache.category_names_containing_package(PackageNamePart("foo")));
- TEST_CHECK(! cache.usable());
- }
- } test_names_cache_not_existing;
-
- struct NamesCacheOldFormatTest : TestCase
- {
- NamesCacheOldFormatTest() : TestCase("old format") { }
-
- void run()
- {
- TestEnvironment env;
- const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo")
- )));
- env.package_database()->add_repository(10, repo);
-
- RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/old_format"), repo.get());
- TEST_CHECK(cache.usable());
- TEST_CHECK(! cache.category_names_containing_package(PackageNamePart("foo")));
- TEST_CHECK(! cache.usable());
- }
- } test_names_cache_old_format;
-
- struct NamesCacheBadRepoTest : TestCase
- {
- NamesCacheBadRepoTest() : TestCase("bad repo") { }
-
- void run()
- {
- TestEnvironment env;
- const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo")
- )));
- env.package_database()->add_repository(10, repo);
-
- RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/bad_repo"), repo.get());
- TEST_CHECK(cache.usable());
- TEST_CHECK(! cache.category_names_containing_package(PackageNamePart("foo")));
- TEST_CHECK(! cache.usable());
- }
- } test_names_cache_bad_repo;
-
- struct NamesCacheGoodTest : TestCase
- {
- NamesCacheGoodTest() : TestCase("good") { }
-
- void run()
- {
- TestEnvironment env;
- const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo")
- )));
- env.package_database()->add_repository(10, repo);
-
- RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/good_repo"), repo.get());
- TEST_CHECK(cache.usable());
-
- std::shared_ptr<const CategoryNamePartSet> foo(cache.category_names_containing_package(PackageNamePart("foo")));
- TEST_CHECK(cache.usable());
- TEST_CHECK(bool(foo));
- TEST_CHECK_EQUAL(join(foo->begin(), foo->end(), " "), "bar baz");
-
- std::shared_ptr<const CategoryNamePartSet> moo(cache.category_names_containing_package(PackageNamePart("moo")));
- TEST_CHECK(cache.usable());
- TEST_CHECK(bool(moo));
- TEST_CHECK(moo->empty());
- }
- } test_names_cache_good;
-
- struct NamesCacheGenerateTest : TestCase
- {
- NamesCacheGenerateTest() : TestCase("generate") { }
-
- void run()
- {
- TestEnvironment env;
- const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo")
- )));
- env.package_database()->add_repository(10, repo);
-
- RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/generated"), repo.get());
- repo->add_package(QualifiedPackageName("bar/foo"));
- repo->add_package(QualifiedPackageName("baz/foo"));
-
- TEST_CHECK(cache.usable());
- cache.regenerate_cache();
- TEST_CHECK(cache.usable());
-
- std::shared_ptr<const CategoryNamePartSet> foo(cache.category_names_containing_package(PackageNamePart("foo")));
- TEST_CHECK(cache.usable());
- TEST_CHECK(bool(foo));
- TEST_CHECK_EQUAL(join(foo->begin(), foo->end(), " "), "bar baz");
-
- std::shared_ptr<const CategoryNamePartSet> moo(cache.category_names_containing_package(PackageNamePart("moo")));
- TEST_CHECK(cache.usable());
- TEST_CHECK(bool(moo));
- TEST_CHECK(moo->empty());
- }
- } test_names_cache_generate;
+ TestEnvironment env;
+ const std::shared_ptr<FakeRepository> repo(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo")
+ )));
+ env.package_database()->add_repository(10, repo);
+
+ RepositoryNameCache cache(FSPath("repository_name_cache_TEST_dir/generated"), repo.get());
+ repo->add_package(QualifiedPackageName("bar/foo"));
+ repo->add_package(QualifiedPackageName("baz/foo"));
+
+ EXPECT_TRUE(cache.usable());
+ cache.regenerate_cache();
+ EXPECT_TRUE(cache.usable());
+
+ std::shared_ptr<const CategoryNamePartSet> foo(cache.category_names_containing_package(PackageNamePart("foo")));
+ EXPECT_TRUE(cache.usable());
+ EXPECT_TRUE(bool(foo));
+ EXPECT_EQ("bar baz", join(foo->begin(), foo->end(), " "));
+
+ std::shared_ptr<const CategoryNamePartSet> moo(cache.category_names_containing_package(PackageNamePart("moo")));
+ EXPECT_TRUE(cache.usable());
+ EXPECT_TRUE(bool(moo));
+ EXPECT_TRUE(moo->empty());
}