aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-16 20:22:22 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-16 20:22:22 +0000
commit104072f57bad7fecc2b7ecdffdad2684d3c0b6a6 (patch)
tree4d6128bde7c65ee931b2dddc45d5e2360333d251
parentbea30fc2186c94ebab97eb1dd65c3cf1894726ac (diff)
downloadpaludis-104072f57bad7fecc2b7ecdffdad2684d3c0b6a6.tar.gz
paludis-104072f57bad7fecc2b7ecdffdad2684d3c0b6a6.tar.xz
Move old FakeRepository code into a new FakeRepositoryBase class. Create FakeRepository and FakeInstalledRepository. Add a dep list test case for forced downgrades.
-rw-r--r--paludis/dep_list_TEST.cc29
-rw-r--r--paludis/repositories/fake/Makefile.am14
-rw-r--r--paludis/repositories/fake/fake_installed_repository.cc49
-rw-r--r--paludis/repositories/fake/fake_installed_repository.hh41
-rw-r--r--paludis/repositories/fake/fake_repository.cc229
-rw-r--r--paludis/repositories/fake/fake_repository.hh117
-rw-r--r--paludis/repositories/fake/fake_repository_base.cc247
-rw-r--r--paludis/repositories/fake/fake_repository_base.hh144
8 files changed, 538 insertions, 332 deletions
diff --git a/paludis/dep_list_TEST.cc b/paludis/dep_list_TEST.cc
index e9039a0..3e40d93 100644
--- a/paludis/dep_list_TEST.cc
+++ b/paludis/dep_list_TEST.cc
@@ -19,6 +19,7 @@
#include <paludis/paludis.hh>
#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>
#include <string>
@@ -1373,5 +1374,33 @@ namespace test_cases
"cat/four-1:0::repo cat/two-1:0::repo cat/three-1:0::repo cat/one-1:0::repo");
}
} test_dep_list_transactional_add_post;
+
+ /**
+ * \test Test DepList transactional forced downgrade of installed package behaviour.
+ *
+ * \ingroup Test
+ */
+ struct DepListTestCaseForcedDowngradeOfInstalled : TestCase
+ {
+ DepListTestCaseForcedDowngradeOfInstalled() : TestCase("dep list forced downgrade of installed") { }
+
+ void run()
+ {
+ TestEnvironment env;
+
+ FakeRepository::Pointer repo(new FakeRepository(RepositoryName("repo")));
+ env.package_database()->add_repository(repo);
+ repo->add_version("cat", "one", "1");
+
+ FakeInstalledRepository::Pointer installed_repo(
+ new FakeInstalledRepository(RepositoryName("installed_repo")));
+ env.package_database()->add_repository(installed_repo);
+ installed_repo->add_version("cat", "one", "2");
+
+ DepList d(&env);
+ d.add(PortageDepParser::parse("cat/one"));
+ TEST_CHECK_EQUAL(join(d.begin(), d.end(), " "), "cat/one-1:0::repo");
+ }
+ } test_dep_list_forced_downgrade_of_installed;
}
diff --git a/paludis/repositories/fake/Makefile.am b/paludis/repositories/fake/Makefile.am
index 4a918d5..b0f0817 100644
--- a/paludis/repositories/fake/Makefile.am
+++ b/paludis/repositories/fake/Makefile.am
@@ -9,8 +9,18 @@ DEFS= \
paludis_repositories_libdir = $(libdir)/paludis/repositories
paludis_repositories_lib_LTLIBRARIES = libpaludisfakerepository.la
-libpaludisfakerepository_la_SOURCES = fake_repository.cc fake_repository.hh
+
+libpaludisfakerepository_la_SOURCES = \
+ fake_repository_base.cc fake_repository_base.hh \
+ fake_repository.cc fake_repository.hh \
+ fake_installed_repository.cc fake_installed_repository.hh
+
libpaludisfakerepository_la_LDFLAGS = -version-info @VERSION_LIB_CURRENT@:@VERSION_LIB_REVISION@:0
+
paludis_repositories_fake_includedir = $(includedir)/paludis/repositories/fake/
-paludis_repositories_fake_include_HEADERS = fake_repository.hh
+paludis_repositories_fake_include_HEADERS = \
+ fake_repository.hh \
+ fake_repository_base.hh \
+ fake_installed_repository.hh
+
diff --git a/paludis/repositories/fake/fake_installed_repository.cc b/paludis/repositories/fake/fake_installed_repository.cc
new file mode 100644
index 0000000..f6b953b
--- /dev/null
+++ b/paludis/repositories/fake/fake_installed_repository.cc
@@ -0,0 +1,49 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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 "fake_installed_repository.hh"
+
+using namespace paludis;
+
+FakeInstalledRepository::FakeInstalledRepository(const RepositoryName & name) :
+ FakeRepositoryBase(name, RepositoryCapabilities::create()
+ .installable_interface(0)
+ .installed_interface(this)
+ .mask_interface(this)
+ .news_interface(0)
+ .sets_interface(0)
+ .syncable_interface(0)
+ .uninstallable_interface(0)
+ .use_interface(this)
+ .world_interface(0)
+ .mirrors_interface(0)
+ .environment_variable_interface(0)
+ .provides_interface(0)
+ .virtuals_interface(0))
+{
+}
+
+Contents::ConstPointer
+FakeInstalledRepository::do_contents(const QualifiedPackageName &,
+ const VersionSpec &) const
+{
+ Contents::ConstPointer result(new Contents);
+ return result;
+}
+
diff --git a/paludis/repositories/fake/fake_installed_repository.hh b/paludis/repositories/fake/fake_installed_repository.hh
new file mode 100644
index 0000000..9196280
--- /dev/null
+++ b/paludis/repositories/fake/fake_installed_repository.hh
@@ -0,0 +1,41 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_FAKE_FAKE_INSTALLED_REPOSITORY_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_FAKE_FAKE_INSTALLED_REPOSITORY_HH 1
+
+#include <paludis/repositories/fake/fake_repository_base.hh>
+
+namespace paludis
+{
+ class FakeInstalledRepository :
+ public FakeRepositoryBase,
+ public RepositoryInstalledInterface
+ {
+ protected:
+ virtual Contents::ConstPointer do_contents(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ public:
+ FakeInstalledRepository(const RepositoryName &);
+ };
+}
+
+#endif
diff --git a/paludis/repositories/fake/fake_repository.cc b/paludis/repositories/fake/fake_repository.cc
index d54dea4..16be71c 100644
--- a/paludis/repositories/fake/fake_repository.cc
+++ b/paludis/repositories/fake/fake_repository.cc
@@ -17,61 +17,13 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <map>
-#include <paludis/repositories/fake/fake_repository.hh>
-#include <paludis/util/stringify.hh>
-#include <paludis/util/collection_concrete.hh>
-#include <paludis/version_metadata.hh>
-#include <paludis/portage_dep_parser.hh>
-
-/** \file
- * Implementation for FakeRepository.
- *
- * \ingroup grpfakerepository
- */
+#include "fake_repository.hh"
using namespace paludis;
-namespace paludis
-{
- /**
- * Implementation data for FakeRepository.
- *
- * \ingroup grpfakerepository
- */
- template<>
- struct Implementation<FakeRepository> :
- private InstantiationPolicy<Implementation<FakeRepository>, instantiation_method::NonCopyableTag>,
- InternalCounted<Implementation<FakeRepository> >
- {
- /// Our category names.
- CategoryNamePartCollection::Pointer category_names;
-
- /// Our package names.
- std::map<CategoryNamePart, PackageNamePartCollection::Pointer > package_names;
-
- /// Our versions.
- std::map<QualifiedPackageName, VersionSpecCollection::Pointer > versions;
-
- /// Our metadata.
- std::map<std::string, VersionMetadata::Pointer > metadata;
-
- /// (Empty) provides map.
- const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
-
- /// Constructor.
- Implementation();
- };
-
- Implementation<FakeRepository>::Implementation() :
- category_names(new CategoryNamePartCollection::Concrete)
- {
- }
-}
-
FakeRepository::FakeRepository(const RepositoryName & name) :
- Repository(name, RepositoryCapabilities::create()
- .installable_interface(0)
+ FakeRepositoryBase(name, RepositoryCapabilities::create()
+ .installable_interface(this)
.installed_interface(0)
.mask_interface(this)
.news_interface(0)
@@ -80,181 +32,16 @@ FakeRepository::FakeRepository(const RepositoryName & name) :
.uninstallable_interface(0)
.use_interface(this)
.world_interface(0)
- .environment_variable_interface(0)
.mirrors_interface(0)
- .virtuals_interface(0)
- .provides_interface(0)),
- RepositoryMaskInterface(),
- RepositoryUseInterface(),
- PrivateImplementationPattern<FakeRepository>(new Implementation<FakeRepository>)
-{
- RepositoryInfoSection::Pointer config_info(new RepositoryInfoSection("Configuration information"));
- config_info->add_kv("format", "fake");
-
- _info->add_section(config_info);
-}
-
-FakeRepository::~FakeRepository()
-{
-}
-
-bool
-FakeRepository::do_has_category_named(const CategoryNamePart & c) const
-{
- return (_imp->category_names->end() != _imp->category_names->find(c));
-}
-
-bool
-FakeRepository::do_has_package_named(const QualifiedPackageName & q) const
-{
- return has_category_named(q.category) &&
- (_imp->package_names.find(q.category)->second->end() !=
- _imp->package_names.find(q.category)->second->find(q.package));
-}
-
-CategoryNamePartCollection::ConstPointer
-FakeRepository::do_category_names() const
-{
- return _imp->category_names;
-}
-
-QualifiedPackageNameCollection::ConstPointer
-FakeRepository::do_package_names(const CategoryNamePart & c) const
-{
- if (! has_category_named(c))
- throw InternalError(PALUDIS_HERE, "no category named " + stringify(c));
- QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection::Concrete);
- PackageNamePartCollection::Iterator p(_imp->package_names.find(c)->second->begin()),
- p_end(_imp->package_names.find(c)->second->end());
- for ( ; p != p_end ; ++p)
- result->insert(c + *p);
- return result;
-}
-
-VersionSpecCollection::ConstPointer
-FakeRepository::do_version_specs(const QualifiedPackageName & n) const
-{
- if (! has_category_named(n.category))
- throw InternalError(PALUDIS_HERE, "no category");
- if (! has_package_named(n))
- throw InternalError(PALUDIS_HERE, "no package");
- return _imp->versions.find(n)->second;
-}
-
-bool
-FakeRepository::do_has_version(const QualifiedPackageName & q, const VersionSpec & v) const
-{
- if (! has_category_named(q.category))
- throw InternalError(PALUDIS_HERE, "no category");
- if (! has_package_named(q))
- throw InternalError(PALUDIS_HERE, "no package");
- return _imp->versions.find(q)->second->find(v) !=
- _imp->versions.find(q)->second->end();
-}
-
-void
-FakeRepository::add_category(const CategoryNamePart & c)
-{
- _imp->category_names->insert(c);
- _imp->package_names.insert(std::make_pair(c, new PackageNamePartCollection::Concrete));
-}
-
-void
-FakeRepository::add_package(const QualifiedPackageName & q)
-{
- add_category(q.category);
- _imp->package_names.find(q.category)->second->insert(q.package);
- _imp->versions.insert(std::make_pair(q, new VersionSpecCollection::Concrete));
-}
-
-VersionMetadata::Pointer
-FakeRepository::add_version(const QualifiedPackageName & q, const VersionSpec & v)
-{
- add_package(q);
- _imp->versions.find(q)->second->insert(v);
- _imp->metadata.insert(
- std::make_pair(stringify(q) + "-" + stringify(v),
- VersionMetadata::Pointer(new VersionMetadata::Ebuild(PortageDepParser::parse_depend))));
- VersionMetadata::Pointer r(_imp->metadata.find(stringify(q) + "-" + stringify(v))->second);
- r->slot = SlotName("0");
- r->eapi = "0";
- r->get_ebuild_interface()->keywords = "test";
- return r;
-}
-
-VersionMetadata::ConstPointer
-FakeRepository::do_version_metadata(
- const QualifiedPackageName & q, const VersionSpec & v) const
-{
- if (! has_version(q, v))
- throw InternalError(PALUDIS_HERE, "no version");
- return _imp->metadata.find(stringify(q) + "-" + stringify(v))->second;
-}
-
-bool
-FakeRepository::do_query_repository_masks(const QualifiedPackageName &,
- const VersionSpec &) const
-{
- return false;
-}
-
-bool
-FakeRepository::do_query_profile_masks(const QualifiedPackageName &, const VersionSpec &) const
-{
- return false;
-}
-
-UseFlagState
-FakeRepository::do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const
-{
- return use_unspecified;
-}
-
-bool
-FakeRepository::do_query_use_mask(const UseFlagName &, const PackageDatabaseEntry *) const
-{
- return false;
-}
-
-bool
-FakeRepository::do_query_use_force(const UseFlagName &, const PackageDatabaseEntry *) const
-{
- return false;
-}
-
-bool
-FakeRepository::do_is_arch_flag(const UseFlagName &) const
-{
- return false;
-}
-
-bool
-FakeRepository::do_is_expand_flag(const UseFlagName &) const
-{
- return false;
-}
-
-
-bool
-FakeRepository::do_is_expand_hidden_flag(const UseFlagName &) const
-{
- return false;
-}
-
-std::string::size_type
-FakeRepository::do_expand_flag_delim_pos(const UseFlagName &) const
-{
- return 0;
-}
-
-bool
-FakeRepository::do_is_licence(const std::string &) const
+ .environment_variable_interface(0)
+ .provides_interface(0)
+ .virtuals_interface(0))
{
- return false;
}
void
-FakeRepository::invalidate() const
+FakeRepository::do_install(const QualifiedPackageName &, const VersionSpec &,
+ const InstallOptions &) const
{
}
diff --git a/paludis/repositories/fake/fake_repository.hh b/paludis/repositories/fake/fake_repository.hh
index ca0792f..6054444 100644
--- a/paludis/repositories/fake/fake_repository.hh
+++ b/paludis/repositories/fake/fake_repository.hh
@@ -17,125 +17,24 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef PALUDIS_GUARD_PALUDIS_FAKE_REPOSITORY_HH
-#define PALUDIS_GUARD_PALUDIS_FAKE_REPOSITORY_HH 1
+#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_FAKE_FAKE_REPOSITORY_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_FAKE_FAKE_REPOSITORY_HH 1
-#include <paludis/repository.hh>
-#include <paludis/util/private_implementation_pattern.hh>
-
-/** \file
- * Declarations for the FakeRepository class.
- *
- * \ingroup grpfakerepository
- */
+#include <paludis/repositories/fake/fake_repository_base.hh>
namespace paludis
{
- /**
- * A FakeRepository is a Repository subclass that is used for
- * various test cases.
- *
- * \ingroup grpfakerepository
- */
class FakeRepository :
- public Repository,
- public RepositoryMaskInterface,
- public RepositoryUseInterface,
- private PrivateImplementationPattern<FakeRepository>
+ public FakeRepositoryBase,
+ public RepositoryInstallableInterface
{
protected:
- virtual bool do_has_category_named(const CategoryNamePart &) const;
-
- virtual bool do_has_package_named(const QualifiedPackageName &) const;
-
- virtual CategoryNamePartCollection::ConstPointer do_category_names() const;
-
- virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
- const CategoryNamePart &) const;
-
- virtual VersionSpecCollection::ConstPointer do_version_specs(
- const QualifiedPackageName &) const;
-
- virtual bool do_has_version(const QualifiedPackageName &,
- const VersionSpec &) const;
-
- virtual VersionMetadata::ConstPointer do_version_metadata(
- const QualifiedPackageName &,
- const VersionSpec &) const;
-
- virtual bool do_query_repository_masks(const QualifiedPackageName &,
- const VersionSpec &) const;
-
- virtual bool do_query_profile_masks(const QualifiedPackageName &,
- const VersionSpec &) const;
-
- virtual UseFlagState do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const;
-
- virtual bool do_query_use_mask(const UseFlagName &, const PackageDatabaseEntry *) const;
-
- virtual bool do_query_use_force(const UseFlagName &, const PackageDatabaseEntry *) const;
-
- virtual bool do_is_arch_flag(const UseFlagName &) const;
-
- virtual bool do_is_expand_flag(const UseFlagName &) const;
- virtual bool do_is_expand_hidden_flag(const UseFlagName &) const;
- virtual std::string::size_type do_expand_flag_delim_pos(const UseFlagName &) const;
-
- virtual bool do_is_licence(const std::string &) const;
+ virtual void do_install(const QualifiedPackageName &, const VersionSpec &,
+ const InstallOptions &) const;
public:
- /**
- * Constructor.
- */
- FakeRepository(const RepositoryName & name);
-
- /**
- * Destructor.
- */
-
- ~FakeRepository();
-
- /**
- * Add a category.
- */
- void add_category(const CategoryNamePart &);
-
- /**
- * Add a package, and a category if necessary.
- */
- void add_package(const QualifiedPackageName &);
-
- /**
- * Add a version, and a package and category if necessary, and set some
- * default values for its metadata, and return said metadata.
- */
- VersionMetadata::Pointer add_version(
- const QualifiedPackageName &, const VersionSpec &);
-
- /**
- * Add a version, and a package and category if necessary, and set some
- * default values for its metadata, and return said metadata (convenience
- * overload taking strings).
- */
- VersionMetadata::Pointer add_version(
- const std::string & c, const std::string & p, const std::string & v)
- {
- return add_version(CategoryNamePart(c) + PackageNamePart(p), VersionSpec(v));
- }
-
- /**
- * A non-constant smart pointer to ourself.
- */
- typedef CountedPtr<FakeRepository, count_policy::InternalCountTag> Pointer;
-
- /**
- * A constant smart pointer to ourself.
- */
- typedef CountedPtr<const FakeRepository, count_policy::InternalCountTag> ConstPointer;
-
- virtual void invalidate() const;
+ FakeRepository(const RepositoryName &);
};
}
-
#endif
diff --git a/paludis/repositories/fake/fake_repository_base.cc b/paludis/repositories/fake/fake_repository_base.cc
new file mode 100644
index 0000000..725e193
--- /dev/null
+++ b/paludis/repositories/fake/fake_repository_base.cc
@@ -0,0 +1,247 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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 <map>
+#include <paludis/repositories/fake/fake_repository_base.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/version_metadata.hh>
+#include <paludis/portage_dep_parser.hh>
+
+/** \file
+ * Implementation for FakeRepositoryBase.
+ *
+ * \ingroup grpfakerepository
+ */
+
+using namespace paludis;
+
+namespace paludis
+{
+ /**
+ * Implementation data for FakeRepositoryBase.
+ *
+ * \ingroup grpfakerepository
+ */
+ template<>
+ struct Implementation<FakeRepositoryBase> :
+ private InstantiationPolicy<Implementation<FakeRepositoryBase>, instantiation_method::NonCopyableTag>,
+ InternalCounted<Implementation<FakeRepositoryBase> >
+ {
+ /// Our category names.
+ CategoryNamePartCollection::Pointer category_names;
+
+ /// Our package names.
+ std::map<CategoryNamePart, PackageNamePartCollection::Pointer > package_names;
+
+ /// Our versions.
+ std::map<QualifiedPackageName, VersionSpecCollection::Pointer > versions;
+
+ /// Our metadata.
+ std::map<std::string, VersionMetadata::Pointer > metadata;
+
+ /// (Empty) provides map.
+ const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+
+ /// Constructor.
+ Implementation();
+ };
+
+ Implementation<FakeRepositoryBase>::Implementation() :
+ category_names(new CategoryNamePartCollection::Concrete)
+ {
+ }
+}
+
+FakeRepositoryBase::FakeRepositoryBase(const RepositoryName & name, const RepositoryCapabilities & caps) :
+ Repository(name, caps),
+ RepositoryMaskInterface(),
+ RepositoryUseInterface(),
+ PrivateImplementationPattern<FakeRepositoryBase>(new Implementation<FakeRepositoryBase>)
+{
+ RepositoryInfoSection::Pointer config_info(new RepositoryInfoSection("Configuration information"));
+ config_info->add_kv("format", "fake");
+
+ _info->add_section(config_info);
+}
+
+FakeRepositoryBase::~FakeRepositoryBase()
+{
+}
+
+bool
+FakeRepositoryBase::do_has_category_named(const CategoryNamePart & c) const
+{
+ return (_imp->category_names->end() != _imp->category_names->find(c));
+}
+
+bool
+FakeRepositoryBase::do_has_package_named(const QualifiedPackageName & q) const
+{
+ return has_category_named(q.category) &&
+ (_imp->package_names.find(q.category)->second->end() !=
+ _imp->package_names.find(q.category)->second->find(q.package));
+}
+
+CategoryNamePartCollection::ConstPointer
+FakeRepositoryBase::do_category_names() const
+{
+ return _imp->category_names;
+}
+
+QualifiedPackageNameCollection::ConstPointer
+FakeRepositoryBase::do_package_names(const CategoryNamePart & c) const
+{
+ if (! has_category_named(c))
+ throw InternalError(PALUDIS_HERE, "no category named " + stringify(c));
+ QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection::Concrete);
+ PackageNamePartCollection::Iterator p(_imp->package_names.find(c)->second->begin()),
+ p_end(_imp->package_names.find(c)->second->end());
+ for ( ; p != p_end ; ++p)
+ result->insert(c + *p);
+ return result;
+}
+
+VersionSpecCollection::ConstPointer
+FakeRepositoryBase::do_version_specs(const QualifiedPackageName & n) const
+{
+ if (! has_category_named(n.category))
+ throw InternalError(PALUDIS_HERE, "no category");
+ if (! has_package_named(n))
+ throw InternalError(PALUDIS_HERE, "no package");
+ return _imp->versions.find(n)->second;
+}
+
+bool
+FakeRepositoryBase::do_has_version(const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ if (! has_category_named(q.category))
+ throw InternalError(PALUDIS_HERE, "no category");
+ if (! has_package_named(q))
+ throw InternalError(PALUDIS_HERE, "no package");
+ return _imp->versions.find(q)->second->find(v) !=
+ _imp->versions.find(q)->second->end();
+}
+
+void
+FakeRepositoryBase::add_category(const CategoryNamePart & c)
+{
+ _imp->category_names->insert(c);
+ _imp->package_names.insert(std::make_pair(c, new PackageNamePartCollection::Concrete));
+}
+
+void
+FakeRepositoryBase::add_package(const QualifiedPackageName & q)
+{
+ add_category(q.category);
+ _imp->package_names.find(q.category)->second->insert(q.package);
+ _imp->versions.insert(std::make_pair(q, new VersionSpecCollection::Concrete));
+}
+
+VersionMetadata::Pointer
+FakeRepositoryBase::add_version(const QualifiedPackageName & q, const VersionSpec & v)
+{
+ add_package(q);
+ _imp->versions.find(q)->second->insert(v);
+ _imp->metadata.insert(
+ std::make_pair(stringify(q) + "-" + stringify(v),
+ VersionMetadata::Pointer(new VersionMetadata::Ebuild(PortageDepParser::parse_depend))));
+ VersionMetadata::Pointer r(_imp->metadata.find(stringify(q) + "-" + stringify(v))->second);
+ r->slot = SlotName("0");
+ r->eapi = "0";
+ r->get_ebuild_interface()->keywords = "test";
+ return r;
+}
+
+VersionMetadata::ConstPointer
+FakeRepositoryBase::do_version_metadata(
+ const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ if (! has_version(q, v))
+ throw InternalError(PALUDIS_HERE, "no version");
+ return _imp->metadata.find(stringify(q) + "-" + stringify(v))->second;
+}
+
+bool
+FakeRepositoryBase::do_query_repository_masks(const QualifiedPackageName &,
+ const VersionSpec &) const
+{
+ return false;
+}
+
+bool
+FakeRepositoryBase::do_query_profile_masks(const QualifiedPackageName &, const VersionSpec &) const
+{
+ return false;
+}
+
+UseFlagState
+FakeRepositoryBase::do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const
+{
+ return use_unspecified;
+}
+
+bool
+FakeRepositoryBase::do_query_use_mask(const UseFlagName &, const PackageDatabaseEntry *) const
+{
+ return false;
+}
+
+bool
+FakeRepositoryBase::do_query_use_force(const UseFlagName &, const PackageDatabaseEntry *) const
+{
+ return false;
+}
+
+bool
+FakeRepositoryBase::do_is_arch_flag(const UseFlagName &) const
+{
+ return false;
+}
+
+bool
+FakeRepositoryBase::do_is_expand_flag(const UseFlagName &) const
+{
+ return false;
+}
+
+
+bool
+FakeRepositoryBase::do_is_expand_hidden_flag(const UseFlagName &) const
+{
+ return false;
+}
+
+std::string::size_type
+FakeRepositoryBase::do_expand_flag_delim_pos(const UseFlagName &) const
+{
+ return 0;
+}
+
+bool
+FakeRepositoryBase::do_is_licence(const std::string &) const
+{
+ return false;
+}
+
+void
+FakeRepositoryBase::invalidate() const
+{
+}
+
diff --git a/paludis/repositories/fake/fake_repository_base.hh b/paludis/repositories/fake/fake_repository_base.hh
new file mode 100644
index 0000000..d4a6ab0
--- /dev/null
+++ b/paludis/repositories/fake/fake_repository_base.hh
@@ -0,0 +1,144 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_FAKE_REPOSITORY_BASE_HH
+#define PALUDIS_GUARD_PALUDIS_FAKE_REPOSITORY_BASE_HH 1
+
+#include <paludis/repository.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+
+/** \file
+ * Declarations for the FakeRepositoryBase class.
+ *
+ * \ingroup grpfakerepository
+ */
+
+namespace paludis
+{
+ /**
+ * A FakeRepositoryBase is a Repository subclass whose subclasses are used for
+ * various test cases.
+ *
+ * \see FakeRepository
+ * \see FakeInstalledRepository
+ * \ingroup grpfakerepository
+ */
+ class FakeRepositoryBase :
+ public Repository,
+ public RepositoryMaskInterface,
+ public RepositoryUseInterface,
+ private PrivateImplementationPattern<FakeRepositoryBase>
+ {
+ protected:
+ virtual bool do_has_category_named(const CategoryNamePart &) const;
+
+ virtual bool do_has_package_named(const QualifiedPackageName &) const;
+
+ virtual CategoryNamePartCollection::ConstPointer do_category_names() const;
+
+ virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
+ const CategoryNamePart &) const;
+
+ virtual VersionSpecCollection::ConstPointer do_version_specs(
+ const QualifiedPackageName &) const;
+
+ virtual bool do_has_version(const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual VersionMetadata::ConstPointer do_version_metadata(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual bool do_query_repository_masks(const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual bool do_query_profile_masks(const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual UseFlagState do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const;
+
+ virtual bool do_query_use_mask(const UseFlagName &, const PackageDatabaseEntry *) const;
+
+ virtual bool do_query_use_force(const UseFlagName &, const PackageDatabaseEntry *) const;
+
+ virtual bool do_is_arch_flag(const UseFlagName &) const;
+
+ virtual bool do_is_expand_flag(const UseFlagName &) const;
+ virtual bool do_is_expand_hidden_flag(const UseFlagName &) const;
+ virtual std::string::size_type do_expand_flag_delim_pos(const UseFlagName &) const;
+
+ virtual bool do_is_licence(const std::string &) const;
+
+ protected:
+ /**
+ * Constructor.
+ */
+ FakeRepositoryBase(const RepositoryName & name, const RepositoryCapabilities & caps);
+
+ public:
+ /**
+ * Destructor.
+ */
+
+ ~FakeRepositoryBase();
+
+ /**
+ * Add a category.
+ */
+ void add_category(const CategoryNamePart &);
+
+ /**
+ * Add a package, and a category if necessary.
+ */
+ void add_package(const QualifiedPackageName &);
+
+ /**
+ * Add a version, and a package and category if necessary, and set some
+ * default values for its metadata, and return said metadata.
+ */
+ VersionMetadata::Pointer add_version(
+ const QualifiedPackageName &, const VersionSpec &);
+
+ /**
+ * Add a version, and a package and category if necessary, and set some
+ * default values for its metadata, and return said metadata (convenience
+ * overload taking strings).
+ */
+ VersionMetadata::Pointer add_version(
+ const std::string & c, const std::string & p, const std::string & v)
+ {
+ return add_version(CategoryNamePart(c) + PackageNamePart(p), VersionSpec(v));
+ }
+
+ /**
+ * A non-constant smart pointer to ourself.
+ */
+ typedef CountedPtr<FakeRepositoryBase, count_policy::InternalCountTag> Pointer;
+
+ /**
+ * A constant smart pointer to ourself.
+ */
+ typedef CountedPtr<const FakeRepositoryBase, count_policy::InternalCountTag> ConstPointer;
+
+ virtual void invalidate() const;
+ };
+}
+
+
+#endif