aboutsummaryrefslogtreecommitdiff
path: root/python/additional_tests.cc
blob: 9bc2859bcf168685039c662f39e17bcab78e8f50 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007 Piotr JaroszyƄski
 *
 * 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 "additional_tests.hh"

#include <python/paludis_python.hh>

#include <paludis/util/tr1_memory.hh>
#include <paludis/util/set.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/environment.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/package_database.hh>
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
#include <paludis/mask.hh>
#include <paludis/hook.hh>
#include <paludis/util/options.hh>
#include <paludis/formatter.hh>
#include <paludis/stringify_formatter-impl.hh>
#include <paludis/util/clone-impl.hh>

using namespace paludis;
namespace bp = boost::python;

namespace environment
{
    void test_env(Environment & e)
    {
        tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&e, RepositoryName("fakerepo")));
        tr1::shared_ptr<PackageID> pid(repo->add_version("cat", "pkg", "1.0"));
        e.package_database()->add_repository(0, repo);

        UseFlagName u("use");
        bool PALUDIS_ATTRIBUTE((unused)) b1(e.query_use(u, *pid));

        e.known_use_expand_names(u, *pid);

        bool PALUDIS_ATTRIBUTE((unused)) b2(e.accept_license("l", *pid));

        tr1::shared_ptr<KeywordNameSet> kns(new KeywordNameSet);
        kns->insert(KeywordName("keyword"));
        bool PALUDIS_ATTRIBUTE((unused)) b3(e.accept_keywords(kns, *pid));

        e.mask_for_breakage(*pid);

        e.mask_for_user(*pid);

        bool PALUDIS_ATTRIBUTE((unused)) b4(e.unmasked_by_user(*pid));

        e.package_database();

        e.bashrc_files();

        e.syncers_dirs();

        e.fetchers_dirs();

        e.hook_dirs();

        e.paludis_command();

        e.set_paludis_command("paludis");

        e.root();

        e.reduced_uid();

        e.reduced_gid();

        e.mirrors("mirror");

        e.set_names();

        e.set(SetName("set"));

        e.default_destinations();

        e.perform_hook(Hook("test"));

        e.default_distribution();
    }
}

namespace mask
{
    void test_mask(Mask & m)
    {
        m.key();
        m.description();
    }

    void test_user_mask(UserMask & m)
    {
        test_mask(m);
    }

    void test_unaccepted_mask(UnacceptedMask & m)
    {
        test_mask(m);
        m.unaccepted_key();
    }

    void test_repository_mask(RepositoryMask & m)
    {
        test_mask(m);
        m.mask_key();
    }

    void test_unsupported_mask(UnsupportedMask & m)
    {
        test_mask(m);
        m.explanation();
    }

    void test_association_mask(AssociationMask & m)
    {
        test_mask(m);
        m.associated_package();
    }
}

namespace metadata_key
{
    void test_metadata_key(const MetadataKey & m)
    {
        m.raw_name();
        m.human_name();
        MetadataKeyType foo(m.type());
    }

    void test_metadata_package_id_key(const MetadataValueKey<tr1::shared_ptr<const PackageID> > & m)
    {
        test_metadata_key(m);
        m.value();
    }

    void test_metadata_string_key(const MetadataValueKey<std::string> & m)
    {
        test_metadata_key(m);
        m.value();
    }

    void test_metadata_section_key(const MetadataSectionKey & m)
    {
        test_metadata_key(m);
        std::for_each(indirect_iterator(m.begin_metadata()), indirect_iterator(m.end_metadata()),
                &test_metadata_key);
    }

    void test_metadata_time_key(const MetadataTimeKey & m)
    {
        test_metadata_key(m);
        time_t PALUDIS_ATTRIBUTE((unused)) t(m.value());
    }

    void test_metadata_contents_key(const MetadataValueKey<tr1::shared_ptr<const Contents> > & m)
    {
        test_metadata_key(m);
        m.value();
    }

    void test_metadata_repository_mask_info_key(const MetadataValueKey<tr1::shared_ptr<const RepositoryMaskInfo> > & m)
    {
        test_metadata_key(m);
        m.value();
    }

    template <typename C_>
    void test_metadata_set_key(const MetadataCollectionKey<C_> & m)
    {
        test_metadata_key(m);
        m.value();
        StringifyFormatter ff;
        m.pretty_print_flat(ff);
    }

    template <>
    void test_metadata_set_key(const MetadataCollectionKey<IUseFlagSet> & m)
    {
        test_metadata_key(m);
        m.value();
        StringifyFormatter ff;
        m.pretty_print_flat(ff);

        TestEnvironment e;
        tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&e, RepositoryName("fakerepo")));
        tr1::shared_ptr<PackageID> pid(repo->add_version("cat", "pkg", "1.0"));

        m.pretty_print_flat_with_comparison(&e, pid, ff);
    }

    template <typename C_>
    void test_metadata_spec_tree_key(const MetadataSpecTreeKey<C_> & m)
    {
        test_metadata_key(m);
        m.value();
        StringifyFormatter ff;
        m.pretty_print(ff);
        m.pretty_print_flat(ff);
    }

    template <>
    void test_metadata_spec_tree_key(const MetadataSpecTreeKey<FetchableURISpecTree> & m)
    {
        test_metadata_key(m);
        m.value();
        StringifyFormatter ff;
        m.pretty_print(ff);
        m.pretty_print_flat(ff);
        m.initial_label();
    }
}

namespace formatter
{
    using namespace format;

    // CanFormat for PlainRoles
    void test_plain_roles(CanFormat<PlainTextDepSpec> & f)
    {
        PlainTextDepSpec d("foo");
        f.format(d, Plain());
    }

    // CanFormat for AcceptableRoles
    void test_acceptable_roles(CanFormat<KeywordName> & f)
    {
        KeywordName k("keyword");
        f.format(k, Plain());
        f.format(k, Accepted());
        f.format(k, Unaccepted());
    }

    // CanFormat for UseRoles
    void test_use_roles(CanFormat<UseFlagName> & f)
    {
        UseFlagName u("use");
        f.format(u, Plain());
        f.format(u, Enabled());
        f.format(u, Disabled());
        f.format(u, Forced());
        f.format(u, Masked());
    }

    // CanFormat for IUseRoles
    void test_iuse_roles(CanFormat<IUseFlag> & f)
    {
        IUseFlag u("iuse_flag", IUseFlagParseOptions(), 1);
        f.format(u, Plain());
        f.format(u, Enabled());
        f.format(u, Disabled());
        f.format(u, Forced());
        f.format(u, Masked());
        f.decorate(u, "%", Added());
        f.decorate(u, "*", Changed());
    }

    // CanFormat for PackageRoles
    void test_package_roles(CanFormat<PackageDepSpec> & f)
    {
        PackageDepSpec p(parse_user_package_dep_spec("cat/pkg", UserPackageDepSpecOptions()));
        f.format(p, Plain());
        f.format(p, Installed());
        f.format(p, Installable());
    }

    // CanSpace
    void test_can_space(CanSpace & f)
    {
        f.newline();
        f.indent(1);
    }

    void test_formatter_string(const Formatter<std::string> &)
    {
    }

    void test_formmater_keyword_name(const Formatter<KeywordName> &)
    {
    }

    void test_formatter_use_flag_name(const Formatter<UseFlagName> &)
    {
    }

    void test_formatter_iuse_flag(const Formatter<IUseFlag> &)
    {
    }

    void test_formatter_license_spec_tree(const LicenseSpecTree::ItemFormatter &)
    {
    }

    void test_formatter_provide_spec_tree(const ProvideSpecTree::ItemFormatter &)
    {
    }

    void test_formatter_dependency_spec_tree(const DependencySpecTree::ItemFormatter &)
    {
    }

    void test_formatter_restrict_spec_tree(const RestrictSpecTree::ItemFormatter &)
    {
    }

    void test_formatter_simple_uri_spec_tree(const SimpleURISpecTree::ItemFormatter &)
    {
    }

    void test_formatter_fetchable_uri_spec_tree(const FetchableURISpecTree::ItemFormatter &)
    {
    }
}

void expose_additional_tests()
{
    /**
     * Environemnt tests
     */
    bp::def("test_env", &environment::test_env);

    /**
     * Mask tests
     */
    bp::def("test_user_mask", &mask::test_user_mask);
    bp::def("test_unaccepted_mask", &mask::test_unaccepted_mask);
    bp::def("test_repository_mask", &mask::test_repository_mask);
    bp::def("test_unsupported_mask", &mask::test_unsupported_mask);
    bp::def("test_association_mask", &mask::test_association_mask);

    /**
     * MetadataKey tests
     */
    bp::def("test_metadata_package_id_key", &metadata_key::test_metadata_package_id_key);
    bp::def("test_metadata_string_key", &metadata_key::test_metadata_string_key);
    bp::def("test_metadata_time_key", &metadata_key::test_metadata_time_key);
    bp::def("test_metadata_contents_key", &metadata_key::test_metadata_contents_key);
    bp::def("test_metadata_repository_mask_info_key", &metadata_key::test_metadata_repository_mask_info_key);
    bp::def("test_metadata_keyword_name_set_key", &metadata_key::test_metadata_set_key<KeywordNameSet>);
    bp::def("test_metadata_use_flag_name_set_key", &metadata_key::test_metadata_set_key<UseFlagNameSet>);
    bp::def("test_metadata_iuse_flag_set_key", &metadata_key::test_metadata_set_key<IUseFlagSet>);
    bp::def("test_metadata_string_set_key", &metadata_key::test_metadata_set_key<Set<std::string> >);
    bp::def("test_metadata_license_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<LicenseSpecTree>);
    bp::def("test_metadata_provide_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<ProvideSpecTree>);
    bp::def("test_metadata_dependency_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<DependencySpecTree>);
    bp::def("test_metadata_restrict_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<RestrictSpecTree>);
    bp::def("test_metadata_fetchable_uri_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<FetchableURISpecTree>);
    bp::def("test_metadata_simple_uri_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<SimpleURISpecTree>);
    bp::def("test_metadata_section_key", &metadata_key::test_metadata_section_key);

    /**
     * Formatter tests
     */
    bp::def("test_plain_roles", &formatter::test_plain_roles);
    bp::def("test_acceptable_roles", &formatter::test_acceptable_roles);
    bp::def("test_use_roles", &formatter::test_use_roles);
    bp::def("test_iuse_roles", &formatter::test_iuse_roles);
    bp::def("test_package_roles", &formatter::test_package_roles);
    bp::def("test_can_space", &formatter::test_can_space);

    bp::def("test_formatter_string", &formatter::test_formatter_string);
    bp::def("test_formmater_keyword_name", &formatter::test_formmater_keyword_name);
    bp::def("test_formatter_use_flag_name", &formatter::test_formatter_use_flag_name);
    bp::def("test_formatter_iuse_flag", &formatter::test_formatter_iuse_flag);
    bp::def("test_formatter_license_spec_tree", &formatter::test_formatter_license_spec_tree);
    bp::def("test_formatter_provide_spec_tree", &formatter::test_formatter_provide_spec_tree);
    bp::def("test_formatter_dependency_spec_tree", &formatter::test_formatter_dependency_spec_tree);
    bp::def("test_formatter_restrict_spec_tree", &formatter::test_formatter_restrict_spec_tree);
    bp::def("test_formatter_simple_uri_spec_tree", &formatter::test_formatter_simple_uri_spec_tree);
    bp::def("test_formatter_fetchable_uri_spec_tree", &formatter::test_formatter_fetchable_uri_spec_tree);
}