aboutsummaryrefslogtreecommitdiff
path: root/paludis/resolver/resolver_test.hh
blob: af2ddec7dc9c1570be17927d515a7dcb4e88667a (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2009, 2010 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/decision-fwd.hh>
#include <paludis/resolver/destination_types-fwd.hh>
#include <paludis/resolver/resolver-fwd.hh>
#include <paludis/resolver/resolver_functions-fwd.hh>
#include <paludis/resolver/required_confirmations-fwd.hh>
#include <paludis/resolver/package_or_block_dep_spec-fwd.hh>
#include <paludis/resolver/resolved-fwd.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/util/map-fwd.hh>
#include <paludis/dep_spec-fwd.hh>
#include <paludis/filtered_generator-fwd.hh>
#include <paludis/generator-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;

            SpecInterest interest_in_spec_fn(
                    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);

            const std::tr1::shared_ptr<ConstraintSequence>
            get_constraints_for_dependent_fn(
                    const std::tr1::shared_ptr<const Resolution> &,
                    const std::tr1::shared_ptr<const PackageID> & id,
                    const std::tr1::shared_ptr<const PackageIDSequence> & ids);

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

            bool is_just_suggestion(const SanitisedDependency & dep);

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

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

            FilteredGenerator make_destination_filtered_generator_fn(const Generator &, const Resolvent &);

            DestinationTypes get_destination_types_for_fn(const PackageDepSpec &,
                    const std::tr1::shared_ptr<const PackageID> &,
                    const std::tr1::shared_ptr<const Reason> &);

            bool allowed_to_remove_fn(
                    const std::tr1::shared_ptr<const QualifiedPackageNameSet> &,
                    const std::tr1::shared_ptr<const Resolution> &,
                    const std::tr1::shared_ptr<const PackageID> &);

            bool remove_if_dependent_fn(
                    const std::tr1::shared_ptr<const QualifiedPackageNameSet> &,
                    const std::tr1::shared_ptr<const PackageID> &);

            Tribool prefer_or_avoid_fn(
                        const std::tr1::shared_ptr<const Map<QualifiedPackageName, bool> > &,
                        const QualifiedPackageName &);

            bool confirm_fn(
                    const std::tr1::shared_ptr<const Resolution> &,
                    const std::tr1::shared_ptr<const RequiredConfirmation> &);

            struct ResolverTestCase : test::TestCase
            {
                TestEnvironment env;
                std::tr1::shared_ptr<Repository> repo, inst_repo;
                std::tr1::shared_ptr<FakeInstalledRepository> fake_inst_repo;
                std::tr1::shared_ptr<QualifiedPackageNameSet> allowed_to_remove_names;
                std::tr1::shared_ptr<QualifiedPackageNameSet> remove_if_dependent_names;
                std::tr1::shared_ptr<Map<QualifiedPackageName, bool> > prefer_or_avoid_names;

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

                const std::tr1::shared_ptr<const Resolved> get_resolved(const PackageOrBlockDepSpec & target);
                const std::tr1::shared_ptr<const Resolved> get_resolved(const std::string & target);

                virtual ResolverFunctions get_resolver_functions(InitialConstraints &);

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

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

                    static bool check_change(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Decision> & r);
                    static std::string check_change_msg(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Decision> & r);

                    static bool check_remove(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Decision> & r);
                    static std::string check_remove_msg(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Decision> & r);

                    static bool check_unable(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Decision> & r);
                    static std::string check_unable_msg(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Decision> & r);

                    static bool check_breaking(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Decision> & r);
                    static std::string check_breaking_msg(const QualifiedPackageName & q, const std::tr1::shared_ptr<const Decision> & r);

                    static bool check_finished(const std::tr1::shared_ptr<const Decision> & r);
                    static std::string check_finished_msg(const std::tr1::shared_ptr<const Decision> & r);

                    DecisionChecks & change(const QualifiedPackageName & q);
                    DecisionChecks & remove(const QualifiedPackageName & q);
                    DecisionChecks & unable(const QualifiedPackageName & q);
                    DecisionChecks & breaking(const QualifiedPackageName & q);
                    DecisionChecks & finished();
                };

                template <typename Decisions_>
                void check_resolved_one(
                        const std::tr1::shared_ptr<Decisions_> &,
                        const std::tr1::shared_ptr<const DecisionChecks> &);

                void check_resolved(
                        const std::tr1::shared_ptr<const Resolved> &,
                        const NamedValue<n::taken_change_or_remove_decisions, const std::tr1::shared_ptr<const DecisionChecks> > &,
                        const NamedValue<n::taken_unable_to_make_decisions, const std::tr1::shared_ptr<const DecisionChecks> > &,
                        const NamedValue<n::taken_unconfirmed_decisions, const std::tr1::shared_ptr<const DecisionChecks> > &,
                        const NamedValue<n::taken_unorderable_decisions, const std::tr1::shared_ptr<const DecisionChecks> > &,
                        const NamedValue<n::untaken_change_or_remove_decisions, const std::tr1::shared_ptr<const DecisionChecks> > &,
                        const NamedValue<n::untaken_unable_to_make_decisions, const std::tr1::shared_ptr<const DecisionChecks> > &
                        );

                const std::tr1::shared_ptr<FakePackageID> install(
                        const std::string & c, const std::string & p, const std::string & v);
            };
        }
    }
}

#endif