aboutsummaryrefslogtreecommitdiff
path: root/paludis/filter_TEST.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-01 13:51:46 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-01 13:51:46 +0000
commit87294dc0c47918934ac032e9a080e8cf386f9bf2 (patch)
tree36dc289aa22200601ec28f2d7b497cd078e34ab6 /paludis/filter_TEST.cc
parent3b9f4ed10c9eb6901f33c7037989f3b67eb5de07 (diff)
downloadpaludis-87294dc0c47918934ac032e9a080e8cf386f9bf2.tar.gz
paludis-87294dc0c47918934ac032e9a080e8cf386f9bf2.tar.xz
New Selection + Filter + Generator interface using Environment, replacing the old PackageDatabase Query. Fixes: ticket:559
Diffstat (limited to 'paludis/filter_TEST.cc')
-rw-r--r--paludis/filter_TEST.cc221
1 files changed, 221 insertions, 0 deletions
diff --git a/paludis/filter_TEST.cc b/paludis/filter_TEST.cc
new file mode 100644
index 000000000..e443ce64f
--- /dev/null
+++ b/paludis/filter_TEST.cc
@@ -0,0 +1,221 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/selection.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/package_database.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 <test/test_runner.hh>
+#include <test/test_framework.hh>
+#include <test/test_concepts.hh>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ TESTCASE_SEMIREGULAR(Filter, filter::All());
+ TESTCASE_STRINGIFYABLE(Filter, filter::All(), "all matches");
+
+ struct FilterTestCaseBase : TestCase
+ {
+ Filter filter;
+ TestEnvironment env;
+ std::tr1::shared_ptr<FakeRepository> repo1;
+ std::tr1::shared_ptr<FakeRepository> repo2;
+ std::tr1::shared_ptr<FakeInstalledRepository> inst_repo1;
+
+ FilterTestCaseBase(const std::string & s, const Filter & f) :
+ TestCase("filter " + s + " with " + stringify(f)),
+ filter(f),
+ repo1(new FakeRepository(&env, RepositoryName("repo1"))),
+ repo2(new FakeRepository(&env, RepositoryName("repo2"))),
+ inst_repo1(new FakeInstalledRepository(&env, RepositoryName("inst_repo1")))
+ {
+ env.package_database()->add_repository(1, repo1);
+ env.package_database()->add_repository(10, repo2);
+ env.package_database()->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;
+
+ void run()
+ {
+ const std::string expected(get_expected());
+ std::tr1::shared_ptr<const PackageIDSequence> got(env[selection::AllVersionsSorted(generator::All() | filter)]);
+
+ TEST_CHECK(got);
+ TEST_CHECK_EQUAL(join(indirect_iterator(got->begin()), indirect_iterator(got->end()), ", "), expected);
+
+ std::tr1::shared_ptr<const PackageIDSequence> got_none(env[selection::AllVersionsSorted(
+ generator::Matches(parse_user_package_dep_spec("not/exist", UserPackageDepSpecOptions())) | filter)]);
+ TEST_CHECK(got_none);
+ TEST_CHECK_EQUAL(join(indirect_iterator(got_none->begin()), indirect_iterator(got_none->end()), ", "), "");
+ }
+ };
+
+ struct AllFilterTestCase : FilterTestCaseBase
+ {
+ AllFilterTestCase() :
+ FilterTestCaseBase("all", filter::All())
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "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>())
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "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;
+
+ struct SupportsInstalledActionFilterTestCase : FilterTestCaseBase
+ {
+ SupportsInstalledActionFilterTestCase() :
+ FilterTestCaseBase("supports installed action", filter::SupportsAction<InstalledAction>())
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "cat/a-1:0::inst_repo1";
+ }
+ } supports_installed_action_filter_test;
+
+ struct SupportsInstalledAtRootFilterTestCase : FilterTestCaseBase
+ {
+ SupportsInstalledAtRootFilterTestCase() :
+ FilterTestCaseBase("installed at root /", filter::InstalledAtRoot(FSEntry("/")))
+ {
+ }
+
+ 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(FSEntry("/blah")))
+ {
+ }
+
+ 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
+ "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;
+
+ struct InstallableAndNotMaskedFilterTestCase : FilterTestCaseBase
+ {
+ InstallableAndNotMaskedFilterTestCase() :
+ FilterTestCaseBase("installable and not masked", filter::And(filter::SupportsAction<InstallAction>(), filter::NotMasked()))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "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;
+
+ struct NotMaskedAndInstallableFilterTestCase : FilterTestCaseBase
+ {
+ NotMaskedAndInstallableFilterTestCase() :
+ FilterTestCaseBase("not masked and installable", filter::And(filter::NotMasked(), filter::SupportsAction<InstallAction>()))
+ {
+ }
+
+ virtual std::string get_expected() const
+ {
+ return
+ "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;
+}
+