aboutsummaryrefslogtreecommitdiff
path: root/paludis/resolver/resolver_test.hh
blob: 2a13559b1eabf45ec2e56bec808ac857bef04f22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2009 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
 */

#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_RESOLVER_TEST_HH
#define PALUDIS_GUARD_PALUDIS_RESOLVER_RESOLVER_TEST_HH 1

#include <paludis/resolver/resolvent-fwd.hh>
#include <paludis/resolver/constraint-fwd.hh>
#include <paludis/resolver/resolution-fwd.hh>
#include <paludis/resolver/sanitised_dependencies-fwd.hh>
#include <paludis/resolver/reason-fwd.hh>
#include <paludis/resolver/use_existing-fwd.hh>
#include <paludis/resolver/resolutions-fwd.hh>
#include <paludis/resolver/decision-fwd.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/util/map-fwd.hh>
#include <paludis/dep_spec-fwd.hh>
#include <test/test_framework.hh>
#include <tr1/memory>
#include <string>
#include <map>
#include <list>

namespace paludis
{
    namespace resolver
    {
        namespace resolver_test
        {
            std::string from_keys(const std::tr1::shared_ptr<const Map<std::string, std::string> > & m,
                    const std::string & k);

            typedef std::map<Resolvent, std::tr1::shared_ptr<Constraints> > InitialConstraints;

            bool care_about_dep_fn(const Resolvent &, const std::tr1::shared_ptr<const Resolution> &, const SanitisedDependency &);

            const std::tr1::shared_ptr<Constraints> initial_constraints_for_fn(
                    const InitialConstraints & initial_constraints,
                    const Resolvent & resolvent);

            std::tr1::shared_ptr<Resolvents> get_resolvents_for_fn(const PackageDepSpec & spec,
                    const std::tr1::shared_ptr<const Reason> &);

            bool is_suggestion(const SanitisedDependency & dep);

            bool take_dependency_fn(
                    const Resolvent &,
                    const SanitisedDependency & dep,
                    const std::tr1::shared_ptr<const Reason> &);

            UseExisting get_use_existing_fn(
                    const Resolvent &,
                    const PackageDepSpec &,
                    const std::tr1::shared_ptr<const Reason> &);

            const std::tr1::shared_ptr<const Repository> find_repository_for_fn(
                    const Environment * const,
                    const Resolvent &,
                    const std::tr1::shared_ptr<const Resolution> &);

            Filter make_destination_filter_fn(const Resolvent &);

            struct ResolverTestCase : test::TestCase
            {
                TestEnvironment env;
                std::tr1::shared_ptr<Repository> repo, inst_repo;
                std::tr1::shared_ptr<FakeInstalledRepository> fake_inst_repo;

                ResolverTestCase(const std::string & group, const std::string & test_name, const std::string & eapi,
                        const std::string & layout);

                const std::tr1::shared_ptr<const ResolutionLists> get_resolutions(const PackageDepSpec & target);

                const std::tr1::shared_ptr<const ResolutionLists> get_resolutions(const std::string & target);

                struct ResolutionListChecks
                {
                    typedef std::tr1::function<bool (const std::tr1::shared_ptr<const Resolution> &) > CheckFunction;
                    typedef std::tr1::function<std::string (const std::tr1::shared_ptr<const Resolution> &) > MessageFunction;
                    typedef std::list<std::pair<CheckFunction, MessageFunction> > List;
                    List checks;

                    static bool check_qpn(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Resolution> & r);

                    static std::string check_generic_msg(const std::string & q, const std::tr1::shared_ptr<const Resolution> & r);

                    static std::string check_qpn_msg(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Resolution> & r);

                    static bool check_finished(const std::tr1::shared_ptr<const Resolution> & r);

                    static std::string check_finished_msg(const std::tr1::shared_ptr<const Resolution> & r);

                    static bool check_kind(const DecisionKind, const QualifiedPackageName &, const std::tr1::shared_ptr<const Resolution> & r);

                    static std::string check_kind_msg(const DecisionKind, const QualifiedPackageName &,
                            const std::tr1::shared_ptr<const Resolution> & r);

                    ResolutionListChecks & qpn(const QualifiedPackageName & q);

                    ResolutionListChecks & kind(const DecisionKind, const QualifiedPackageName & q);

                    ResolutionListChecks & finished();
                };

                void check_resolution_list(const std::tr1::shared_ptr<const Resolutions> & list, const ResolutionListChecks & checks);

                void install(const std::string & c, const std::string & p, const std::string & v);
            };
        }
    }
}

#endif