File: fixtures.cpp

package info (click to toggle)
libdnf 0.75.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,468 kB
  • sloc: cpp: 48,297; xml: 1,638; python: 1,537; ansic: 1,223; sql: 227; sh: 54; makefile: 39
file content (209 lines) | stat: -rw-r--r-- 5,355 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (C) 2012-2015 Red Hat, Inc.
 *
 * Licensed under the GNU Lesser General Public License Version 2.1
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libdnf/hy-package.h"
#include "libdnf/hy-repo.h"
#include "libdnf/hy-iutil.h"
#include "libdnf/dnf-sack-private.hpp"

#include "fixtures.h"
#include "testsys.h"

#include <check.h>
#include <stdarg.h>
#include <unistd.h>

/* define the global variable */
struct TestGlobals_s test_globals;

static DnfSack *
create_ut_sack(void)
{
    DnfSack *sack = dnf_sack_new();
    dnf_sack_set_cachedir(sack, test_globals.tmpdir);
    dnf_sack_set_arch(sack, TEST_FIXED_ARCH, NULL);
    dnf_sack_setup(sack, DNF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL);
    test_globals.sack = sack;
    g_debug("DnfSack for UT created: %p", sack);
    return sack;
}

static int
setup_with(DnfSack *sack, ...)
{
    Pool *pool = dnf_sack_get_pool(sack);
    va_list names;
    int ret = 0;

    va_start(names, sack);
    const char *name = va_arg(names, const char *);
    while (name) {
        const char *path = pool_tmpjoin(pool, test_globals.repo_dir,
                                        name, ".repo");
        int installed = !strncmp(name, HY_SYSTEM_REPO_NAME,
                                 strlen(HY_SYSTEM_REPO_NAME));

        ret |= load_repo(pool, name, path, installed);
        name = va_arg(names, const char *);
    }
    va_end(names);
    return ret;
}

static
void add_cmdline(DnfSack *sack)
{
    Pool *pool = dnf_sack_get_pool(sack);
    const char *path = pool_tmpjoin(pool, test_globals.repo_dir,
                                    "yum/tour-4-6.noarch.rpm", NULL);
    DnfPackage *pkg = dnf_sack_add_cmdline_package(sack, path);
    g_object_unref(pkg);
}

void
fixture_cmdline_only(void)
{
    DnfSack *sack = create_ut_sack();
    add_cmdline(sack);
}

void
fixture_empty(void)
{
    create_ut_sack();
}

void
fixture_greedy_only(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, "greedy", NULL));
}

void
fixture_installonly(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, "@System-k", "installonly", NULL));
}

void
fixture_system_only(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, HY_SYSTEM_REPO_NAME, NULL));
}

void
fixture_verify(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, "@System-broken", NULL));
}

void
fixture_with_change(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, HY_SYSTEM_REPO_NAME, "change", NULL));
}

void
fixture_with_cmdline(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, HY_SYSTEM_REPO_NAME, NULL));
    add_cmdline(sack);
}

void
fixture_with_forcebest(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, HY_SYSTEM_REPO_NAME, "forcebest", NULL));
}

void
fixture_with_main(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, HY_SYSTEM_REPO_NAME, "main", NULL));
}

void
fixture_with_updates(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, HY_SYSTEM_REPO_NAME, "updates", NULL));
}

void
fixture_with_vendor(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, HY_SYSTEM_REPO_NAME, "vendor", NULL));
}

void
fixture_all(void)
{
    DnfSack *sack = create_ut_sack();
    fail_if(setup_with(sack, HY_SYSTEM_REPO_NAME, "main", "updates", NULL));
}

void fixture_yum(void)
{
    DnfSack *sack = create_ut_sack();
    setup_yum_sack(sack, YUM_REPO_NAME);
}

void fixture_reset(void)
{
    DnfSack *sack = test_globals.sack;
    dnf_sack_set_installonly(sack, NULL);
    dnf_sack_set_installonly_limit(sack, 0);
    dnf_sack_set_excludes(sack, NULL);
    dnf_sack_repo_enabled(sack, "main", 1);
    dnf_sack_repo_enabled(sack, "updates", 1);
}

void setup_yum_sack(DnfSack *sack, const char *yum_repo_name)
{
    Pool *pool = dnf_sack_get_pool(sack);
    const char *repo_path = pool_tmpjoin(pool, test_globals.repo_dir,
                                         YUM_DIR_SUFFIX, NULL);
    fail_if(access(repo_path, X_OK));
    HyRepo repo = glob_for_repofiles(pool, yum_repo_name, repo_path);

    fail_if(!dnf_sack_load_repo(sack, repo,
                               DNF_SACK_LOAD_FLAG_BUILD_CACHE |
                               DNF_SACK_LOAD_FLAG_USE_FILELISTS |
                               DNF_SACK_LOAD_FLAG_USE_UPDATEINFO |
                               DNF_SACK_LOAD_FLAG_USE_PRESTO, NULL));
    fail_unless(dnf_sack_count(sack) == TEST_EXPECT_YUM_NSOLVABLES);
    hy_repo_free(repo);
}

void
teardown(void)
{
    g_object_unref(test_globals.sack);
    test_globals.sack = NULL;
}