aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 14:55:18 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 14:55:18 +0100
commit4ba198eb4423a20e9e0acb06afffb0844be92e3e (patch)
treebaa773185a851ac477533ad9e27b631f1b8fb03f
parentae48f2a2683ba8451d9dcf2fec8420439ee9c629 (diff)
downloadpaludis-4ba198eb4423a20e9e0acb06afffb0844be92e3e.tar.gz
paludis-4ba198eb4423a20e9e0acb06afffb0844be92e3e.tar.xz
gtest more
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/filter_TEST.cc295
2 files changed, 89 insertions, 208 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index da806a3..e0bfdc7 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -44,7 +44,7 @@ add(`environment', `hh', `fwd', `cc')
add(`environment_factory', `hh', `fwd', `cc')
add(`environment_implementation', `hh', `cc', `gtest')
add(`file_output_manager', `hh', `cc', `fwd')
-add(`filter', `hh', `cc', `fwd', `test')
+add(`filter', `hh', `cc', `fwd', `gtest')
add(`filter_handler', `hh', `cc', `fwd')
add(`filtered_generator', `hh', `cc', `fwd', `test')
add(`format_messages_output_manager', `hh', `fwd', `cc')
diff --git a/paludis/filter_TEST.cc b/paludis/filter_TEST.cc
index f4f0942..3065198 100644
--- a/paludis/filter_TEST.cc
+++ b/paludis/filter_TEST.cc
@@ -22,276 +22,157 @@
#include <paludis/selection.hh>
#include <paludis/filtered_generator.hh>
#include <paludis/user_dep_spec.hh>
+
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/repositories/fake/fake_package_id.hh>
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
+
#include <paludis/util/sequence.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/make_null_shared_ptr.hh>
#include <paludis/util/join.hh>
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
-#include <test/test_concepts.hh>
+#include <paludis/util/stringify.hh>
+
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
-namespace test_cases
+namespace
{
- TESTCASE_SEMIREGULAR(Filter, filter::All());
- TESTCASE_STRINGIFYABLE(Filter, filter::All(), "all matches");
+ struct TestInfo
+ {
+ std::shared_ptr<Filter> filter;
+ std::string expected;
+ };
- struct FilterTestCaseBase : TestCase
+ struct FilterTestCaseBase :
+ testing::TestWithParam<TestInfo>
{
- Filter filter;
TestEnvironment env;
- std::shared_ptr<FakeRepository> repo1;
- std::shared_ptr<FakeRepository> repo2;
- std::shared_ptr<FakeInstalledRepository> inst_repo1;
-
- FilterTestCaseBase(const std::string & s, const Filter & f) :
- TestCase("filter " + s + " with " + stringify(f)),
- filter(f),
- repo1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo1")
- ))),
- repo2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo2")
- ))),
- inst_repo1(std::make_shared<FakeInstalledRepository>(
- make_named_values<FakeInstalledRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("inst_repo1"),
- n::suitable_destination() = true,
- n::supports_uninstall() = true
- )))
- {
- env.add_repository(1, repo1);
- env.add_repository(10, repo2);
- env.add_repository(0, inst_repo1);
-
- repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
- repo1->add_version(CategoryNamePart("cat") + PackageNamePart("b"), VersionSpec("2", { }));
-
- repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
- repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("2", { }))->keywords_key()->set_from_string("");
- repo2->add_version(CategoryNamePart("cat") + PackageNamePart("c"), VersionSpec("3", { }));
-
- inst_repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
- }
-
- virtual std::string get_expected() const = 0;
+ TestInfo info;
- void run()
+ void SetUp()
{
- const std::string expected(get_expected());
- std::shared_ptr<const PackageIDSequence> got(env[selection::AllVersionsSorted(generator::All() | filter)]);
-
- TEST_CHECK(bool(got));
- TEST_CHECK_EQUAL(join(indirect_iterator(got->begin()), indirect_iterator(got->end()), ", "), expected);
-
- std::shared_ptr<const PackageIDSequence> got_none(env[selection::AllVersionsSorted(
- generator::Matches(parse_user_package_dep_spec("not/exist", &env,
- { }), make_null_shared_ptr(), { }) | filter)]);
- TEST_CHECK(bool(got_none));
- TEST_CHECK_EQUAL(join(indirect_iterator(got_none->begin()), indirect_iterator(got_none->end()), ", "), "");
+ info = GetParam();
}
};
+}
- struct AllFilterTestCase : FilterTestCaseBase
- {
- AllFilterTestCase() :
- FilterTestCaseBase("all", filter::All())
- {
- }
+TEST_P(FilterTestCaseBase, Works)
+{
+ auto repo1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo1")
+ )));
+ auto repo2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo2")
+ )));
+ auto inst_repo1(std::make_shared<FakeInstalledRepository>(
+ make_named_values<FakeInstalledRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("inst_repo1"),
+ n::suitable_destination() = true,
+ n::supports_uninstall() = true
+ )));
+
+ env.add_repository(1, repo1);
+ env.add_repository(10, repo2);
+ env.add_repository(0, inst_repo1);
+
+ repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
+ repo1->add_version(CategoryNamePart("cat") + PackageNamePart("b"), VersionSpec("2", { }));
+
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("2", { }))->keywords_key()->set_from_string("");
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("c"), VersionSpec("3", { }));
+
+ inst_repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
+
+ std::shared_ptr<const PackageIDSequence> got(env[selection::AllVersionsSorted(generator::All() | *info.filter)]);
+
+ ASSERT_TRUE(bool(got));
+ EXPECT_EQ(info.expected, join(indirect_iterator(got->begin()), indirect_iterator(got->end()), ", "));
+
+ std::shared_ptr<const PackageIDSequence> got_none(env[selection::AllVersionsSorted(
+ generator::Matches(parse_user_package_dep_spec("not/exist", &env,
+ { }), make_null_shared_ptr(), { }) | *info.filter)]);
+ ASSERT_TRUE(bool(got_none));
+ EXPECT_EQ("", join(indirect_iterator(got_none->begin()), indirect_iterator(got_none->end()), ", "));
+}
- virtual std::string get_expected() const
- {
- return
+INSTANTIATE_TEST_CASE_P(FilterTest, FilterTestCaseBase, testing::Values(
+ TestInfo{ std::make_shared<filter::All>(), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } all_filter_test;
-
- struct SupportsInstallActionFilterTestCase : FilterTestCaseBase
- {
- SupportsInstallActionFilterTestCase() :
- FilterTestCaseBase("supports install action", filter::SupportsAction<InstallAction>())
- {
- }
+ "cat/c-3:0::repo2") },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<filter::SupportsAction<InstallAction> >(), std::string(
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } supports_install_action_filter_test;
+ "cat/c-3:0::repo2") },
- struct SupportsInstalledAtRootFilterTestCase : FilterTestCaseBase
- {
- SupportsInstalledAtRootFilterTestCase() :
- FilterTestCaseBase("installed at root /", filter::InstalledAtRoot(FSPath("/")))
- {
- }
+ TestInfo{ std::make_shared<filter::InstalledAtRoot>(FSPath("/")), std::string(
+ "cat/a-1:0::inst_repo1") },
- virtual std::string get_expected() const
- {
- return
- "cat/a-1:0::inst_repo1";
- }
- } supports_installed_at_root_slash;
-
- struct SupportsInstalledAtRootOtherFilterTestCase : FilterTestCaseBase
- {
- SupportsInstalledAtRootOtherFilterTestCase() :
- FilterTestCaseBase("installed at root /blah", filter::InstalledAtRoot(FSPath("/blah")))
- {
- }
+ TestInfo{ std::make_shared<filter::InstalledAtRoot>(FSPath("/blah")), std::string(
+ "") },
- virtual std::string get_expected() const
- {
- return "";
- }
- } supports_installed_at_root_other;
-
- struct NotMaskedFilterTestCase : FilterTestCaseBase
- {
- NotMaskedFilterTestCase() :
- FilterTestCaseBase("not masked", filter::NotMasked())
- {
- }
-
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<filter::NotMasked>(), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } not_masked_filter_test;
+ "cat/c-3:0::repo2") },
- struct InstallableAndNotMaskedFilterTestCase : FilterTestCaseBase
- {
- InstallableAndNotMaskedFilterTestCase() :
- FilterTestCaseBase("installable and not masked", filter::And(filter::SupportsAction<InstallAction>(), filter::NotMasked()))
- {
- }
-
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<filter::And>(filter::SupportsAction<InstallAction>(), filter::NotMasked()), std::string(
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } installable_and_not_masked_filter_test;
+ "cat/c-3:0::repo2") },
- struct NotMaskedAndInstallableFilterTestCase : FilterTestCaseBase
- {
- NotMaskedAndInstallableFilterTestCase() :
- FilterTestCaseBase("not masked and installable", filter::And(filter::NotMasked(), filter::SupportsAction<InstallAction>()))
- {
- }
-
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<filter::And>(filter::NotMasked(), filter::SupportsAction<InstallAction>()), std::string(
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } not_masked_and_installable_filter_test;
+ "cat/c-3:0::repo2") },
- struct MatchesFilterTestCase : FilterTestCaseBase
- {
- MatchesFilterTestCase() :
- FilterTestCaseBase("matches", filter::Matches(parse_user_package_dep_spec("cat/a",
- &env, { }), make_null_shared_ptr(), { }))
- {
- }
-
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<filter::Matches>(envless_parse_package_dep_spec_for_tests(
+ "cat/a"), make_null_shared_ptr(), MatchPackageOptions()), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
- "cat/a-2:0::repo2";
- }
- } matches_filter_test;
-
- struct MatchesCatWildcardFilterTestCase : FilterTestCaseBase
- {
- MatchesCatWildcardFilterTestCase() :
- FilterTestCaseBase("matches cat wildcard", filter::Matches(parse_user_package_dep_spec("*/a",
- &env, { updso_allow_wildcards }), make_null_shared_ptr(), { }))
- {
- }
+ "cat/a-2:0::repo2") },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<filter::Matches>(envless_parse_package_dep_spec_for_tests(
+ "*/a"), make_null_shared_ptr(), MatchPackageOptions()), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
- "cat/a-2:0::repo2";
- }
- } matches_cat_wildcard_filter_test;
-
- struct MatchesPkgWildcardFilterTestCase : FilterTestCaseBase
- {
- MatchesPkgWildcardFilterTestCase() :
- FilterTestCaseBase("matches pkg wildcard", filter::Matches(parse_user_package_dep_spec("cat/*",
- &env, { updso_allow_wildcards }), make_null_shared_ptr(), { }))
- {
- }
+ "cat/a-2:0::repo2") },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<filter::Matches>(envless_parse_package_dep_spec_for_tests(
+ "cat/*"), make_null_shared_ptr(), MatchPackageOptions()), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } matches_pkg_wildcard_filter_test;
-
- struct MatchesAllWildcardFilterTestCase : FilterTestCaseBase
- {
- MatchesAllWildcardFilterTestCase() :
- FilterTestCaseBase("matches all wildcard", filter::Matches(
- parse_user_package_dep_spec(">=*/*-2",
- &env, { updso_allow_wildcards }), make_null_shared_ptr(), { }))
- {
- }
+ "cat/c-3:0::repo2" ) },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<filter::Matches>(envless_parse_package_dep_spec_for_tests(
+ ">=*/*-2"), make_null_shared_ptr(), MatchPackageOptions()), std::string(
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } matches_all_wildcard_filter_test;
-
-}
+ "cat/c-3:0::repo2" ) }
+ ));