diff options
Diffstat (limited to 'paludis/repositories/gentoo/vdb_repository_TEST.cc')
-rw-r--r-- | paludis/repositories/gentoo/vdb_repository_TEST.cc | 249 |
1 files changed, 249 insertions, 0 deletions
diff --git a/paludis/repositories/gentoo/vdb_repository_TEST.cc b/paludis/repositories/gentoo/vdb_repository_TEST.cc new file mode 100644 index 0000000..c684ee0 --- /dev/null +++ b/paludis/repositories/gentoo/vdb_repository_TEST.cc @@ -0,0 +1,249 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org> + * + * 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/repositories/vdb/vdb_repository.hh> +#include <paludis/util/collection_concrete.hh> +#include <paludis/environment/test/test_environment.hh> +#include <test/test_framework.hh> +#include <test/test_runner.hh> +#include <fstream> +#include <iterator> + +using namespace test; +using namespace paludis; + +/** \file + * Test cases for VDBRepository. + * + */ + +namespace test_cases +{ + /** + * \test Test VDBRepository repo names + * + */ + struct VDBRepositoryRepoNameTest : TestCase + { + VDBRepositoryRepoNameTest() : TestCase("repo name") { } + + void run() + { + TestEnvironment env; + std::tr1::shared_ptr<AssociativeCollection<std::string, std::string> > keys( + new AssociativeCollection<std::string, std::string>::Concrete); + keys->insert("format", "vdb"); + keys->insert("names_cache", "/var/empty"); + keys->insert("provides_cache", "/var/empty"); + keys->insert("location", "vdb_repository_TEST_dir/repo1"); + std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository(&env, keys)); + TEST_CHECK_STRINGIFY_EQUAL(repo->name(), "installed"); + } + } test_vdb_repository_repo_name; + + /** + * \test Test VDBRepository has_category_named + * + */ + struct VDBRepositoryHasCategoryNamedTest : TestCase + { + VDBRepositoryHasCategoryNamedTest() : TestCase("has category named") { } + + void run() + { + TestEnvironment env; + std::tr1::shared_ptr<AssociativeCollection<std::string, std::string> > keys( + new AssociativeCollection<std::string, std::string>::Concrete); + keys->insert("format", "vdb"); + keys->insert("names_cache", "/var/empty"); + keys->insert("provides_cache", "/var/empty"); + keys->insert("location", "vdb_repository_TEST_dir/repo1"); + std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository( + &env, keys)); + + TEST_CHECK(repo->has_category_named(CategoryNamePart("cat-one"))); + TEST_CHECK(repo->has_category_named(CategoryNamePart("cat-two"))); + TEST_CHECK(! repo->has_category_named(CategoryNamePart("cat-three"))); + } + } test_vdb_repository_has_category_named; + + /** + * \test Test VDBRepository query_use + * + */ + struct VDBRepositoryQueryUseTest : TestCase + { + VDBRepositoryQueryUseTest() : TestCase("query USE") { } + + void run() + { + TestEnvironment env; + std::tr1::shared_ptr<AssociativeCollection<std::string, std::string> > keys( + new AssociativeCollection<std::string, std::string>::Concrete); + keys->insert("format", "vdb"); + keys->insert("names_cache", "/var/empty"); + keys->insert("provides_cache", "/var/empty"); + keys->insert("location", "vdb_repository_TEST_dir/repo1"); + std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository( + &env, keys)); + + PackageDatabaseEntry e1(CategoryNamePart("cat-one") + PackageNamePart("pkg-one"), + VersionSpec("1"), RepositoryName("installed")); + PackageDatabaseEntry e2(CategoryNamePart("cat-one") + PackageNamePart("pkg-neither"), + VersionSpec("1"), RepositoryName("installed")); + + TEST_CHECK(repo->use_interface->query_use(UseFlagName("flag1"), &e1) == use_enabled); + TEST_CHECK(repo->use_interface->query_use(UseFlagName("flag2"), &e1) == use_enabled); + TEST_CHECK(repo->use_interface->query_use(UseFlagName("flag3"), &e1) == use_disabled); + + TEST_CHECK(repo->use_interface->query_use(UseFlagName("flag4"), &e2) == use_unspecified); + } + } test_vdb_repository_query_use; + + /** + * \test Test VDBRepository add_to_world. + */ + struct VDBRepositoryAddToWorldNewFileTest : TestCase + { + VDBRepositoryAddToWorldNewFileTest() : TestCase("add to world (new file)") { } + + void run() + { + TestEnvironment env; + std::tr1::shared_ptr<AssociativeCollection<std::string, std::string> > keys( + new AssociativeCollection<std::string, std::string>::Concrete); + keys->insert("format", "vdb"); + keys->insert("names_cache", "/var/empty"); + keys->insert("provides_cache", "/var/empty"); + keys->insert("location", "vdb_repository_TEST_dir/repo1"); + keys->insert("world", "vdb_repository_TEST_dir/world-new-file"); + std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository( + &env, keys)); + repo->world_interface->add_to_world(QualifiedPackageName("cat-one/foofoo")); + std::ifstream world("vdb_repository_TEST_dir/world-new-file"); + std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>()); + TEST_CHECK_EQUAL(world_content, "cat-one/foofoo\n"); + } + } test_vdb_repository_add_to_world_new_file; + + /** + * \test Test VDBRepository add_to_world. + */ + struct VDBRepositoryAddToWorldEmptyFileTest : TestCase + { + VDBRepositoryAddToWorldEmptyFileTest() : TestCase("add to world (empty file)") { } + + void run() + { + TestEnvironment env; + std::tr1::shared_ptr<AssociativeCollection<std::string, std::string> > keys( + new AssociativeCollection<std::string, std::string>::Concrete); + keys->insert("format", "vdb"); + keys->insert("names_cache", "/var/empty"); + keys->insert("provides_cache", "/var/empty"); + keys->insert("location", "vdb_repository_TEST_dir/repo1"); + keys->insert("world", "vdb_repository_TEST_dir/world-empty"); + std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository( + &env, keys)); + repo->world_interface->add_to_world(QualifiedPackageName("cat-one/foofoo")); + std::ifstream world("vdb_repository_TEST_dir/world-empty"); + std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>()); + TEST_CHECK_EQUAL(world_content, "cat-one/foofoo\n"); + } + } test_vdb_repository_add_to_world_empty_file; + + /** + * \test Test VDBRepository add_to_world. + */ + struct VDBRepositoryAddToWorldNoMatchTest : TestCase + { + VDBRepositoryAddToWorldNoMatchTest() : TestCase("add to world (no match)") { } + + void run() + { + TestEnvironment env; + std::tr1::shared_ptr<AssociativeCollection<std::string, std::string> > keys( + new AssociativeCollection<std::string, std::string>::Concrete); + keys->insert("format", "vdb"); + keys->insert("names_cache", "/var/empty"); + keys->insert("provides_cache", "/var/empty"); + keys->insert("location", "vdb_repository_TEST_dir/repo1"); + keys->insert("world", "vdb_repository_TEST_dir/world-no-match"); + std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository( + &env, keys)); + repo->world_interface->add_to_world(QualifiedPackageName("cat-one/foofoo")); + std::ifstream world("vdb_repository_TEST_dir/world-no-match"); + std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>()); + TEST_CHECK_EQUAL(world_content, "cat-one/foo\ncat-one/bar\ncat-one/oink\ncat-one/foofoo\n"); + } + } test_vdb_repository_add_to_world_no_match; + + /** + * \test Test VDBRepository add_to_world. + */ + struct VDBRepositoryAddToWorldMatchTest : TestCase + { + VDBRepositoryAddToWorldMatchTest() : TestCase("add to world (match)") { } + + void run() + { + TestEnvironment env; + std::tr1::shared_ptr<AssociativeCollection<std::string, std::string> > keys( + new AssociativeCollection<std::string, std::string>::Concrete); + keys->insert("format", "vdb"); + keys->insert("names_cache", "/var/empty"); + keys->insert("provides_cache", "/var/empty"); + keys->insert("location", "vdb_repository_TEST_dir/repo1"); + keys->insert("world", "vdb_repository_TEST_dir/world-match"); + std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository( + &env, keys)); + repo->world_interface->add_to_world(QualifiedPackageName("cat-one/foofoo")); + std::ifstream world("vdb_repository_TEST_dir/world-match"); + std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>()); + TEST_CHECK_EQUAL(world_content, "cat-one/foo\ncat-one/foofoo\ncat-one/bar\n"); + } + } test_vdb_repository_add_to_world_match; + + /** + * \test Test VDBRepository add_to_world. + */ + struct VDBRepositoryAddToWorldNoMatchNoEOLTest : TestCase + { + VDBRepositoryAddToWorldNoMatchNoEOLTest() : TestCase("add to world (no match, no trailing eol)") { } + + void run() + { + TestEnvironment env; + std::tr1::shared_ptr<AssociativeCollection<std::string, std::string> > keys( + new AssociativeCollection<std::string, std::string>::Concrete); + keys->insert("format", "vdb"); + keys->insert("names_cache", "/var/empty"); + keys->insert("provides_cache", "/var/empty"); + keys->insert("location", "vdb_repository_TEST_dir/repo1"); + keys->insert("world", "vdb_repository_TEST_dir/world-no-match-no-eol"); + std::tr1::shared_ptr<Repository> repo(VDBRepository::make_vdb_repository( + &env, keys)); + repo->world_interface->add_to_world(QualifiedPackageName("cat-one/foofoo")); + std::ifstream world("vdb_repository_TEST_dir/world-no-match-no-eol"); + std::string world_content((std::istreambuf_iterator<char>(world)), std::istreambuf_iterator<char>()); + TEST_CHECK_EQUAL(world_content, "cat-one/foo\ncat-one/bar\ncat-one/oink\ncat-one/foofoo\n"); + } + } test_vdb_repository_add_to_world_no_match_no_eol; +} + |