/* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* * Copyright (c) 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 * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace paludis; namespace { struct TestInfo { std::shared_ptr generator; std::string expected; }; struct GeneratorTestCaseBase : testing::TestWithParam { TestInfo info; void SetUp() { info = GetParam(); } void TearDown() { } }; } TEST_P(GeneratorTestCaseBase, Works) { TestEnvironment env; auto repo1(std::make_shared(make_named_values( n::environment() = &env, n::name() = RepositoryName("repo1")))); auto repo2(std::make_shared(make_named_values( n::environment() = &env, n::name() = RepositoryName("repo2")))); auto inst_repo1(std::make_shared( make_named_values( 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 got(env[selection::AllVersionsSorted(*info.generator)]); ASSERT_TRUE(bool(got)); EXPECT_EQ(info.expected, join(indirect_iterator(got->begin()), indirect_iterator(got->end()), ", ")); std::shared_ptr got_none(env[selection::AllVersionsSorted(*info.generator | filter::SupportsAction() | filter::SupportsAction())]); ASSERT_TRUE(bool(got_none)); EXPECT_EQ("", join(indirect_iterator(got_none->begin()), indirect_iterator(got_none->end()), ", ")); } INSTANTIATE_TEST_CASE_P(GeneratorTest, GeneratorTestCaseBase, testing::Values( TestInfo{ std::make_shared(), 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" ) }, TestInfo{ std::make_shared( 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") }, TestInfo{ std::make_shared( 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") }, TestInfo{ std::make_shared( 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") }, TestInfo{ std::make_shared( 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") }, TestInfo{ std::make_shared(QualifiedPackageName("cat/a")), std::string( "cat/a-1:0::inst_repo1, " "cat/a-1:0::repo1, " "cat/a-1:0::repo2, " "cat/a-2:0::repo2") }, TestInfo{ std::make_shared(QualifiedPackageName("cat/d")), std::string( "") }, TestInfo{ std::make_shared(RepositoryName("repo1")), std::string( "cat/a-1:0::repo1, " "cat/b-2:0::repo1") }, TestInfo{ std::make_shared(RepositoryName("repo3")), std::string( "") }, TestInfo{ std::make_shared(CategoryNamePart("cat")), 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") }, TestInfo{ std::make_shared(CategoryNamePart("a")), std::string( "") }, TestInfo{ std::make_shared( generator::Matches(envless_parse_package_dep_spec_for_tests("*/a"), make_null_shared_ptr(), MatchPackageOptions()), generator::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") }, TestInfo{ std::make_shared >(), 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") } ));