File: testsys.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 (112 lines) | stat: -rw-r--r-- 3,230 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
/*
 * Copyright (C) 2012-2013 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-goal.h"
#include "libdnf/hy-package.h"
#include "libdnf/hy-package-private.hpp"
#include "libdnf/hy-query.h"
#include "libdnf/dnf-sack-private.hpp"
#include "libdnf/hy-util.h"

#include "testsys.h"

#include <solv/repo.h>
#include <solv/util.h>

#include <check.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

void
assert_nevra_eq(DnfPackage *pkg, const char *nevra)
{
    const char *pkg_nevra = dnf_package_get_nevra(pkg);
    ck_assert_str_eq(pkg_nevra, nevra);
}

DnfPackage *
by_name(DnfSack *sack, const char *name)
{
    HyQuery q = hy_query_create(sack);
    hy_query_filter(q, HY_PKG_NAME, HY_EQ, name);
    GPtrArray *plist = hy_query_run(q);
    hy_query_free(q);
    auto pkg = static_cast<DnfPackage *>(g_object_ref(g_ptr_array_index(plist, 0)));
    g_ptr_array_unref(plist);

    return pkg;
}

DnfPackage *
by_name_repo(DnfSack *sack, const char *name, const char *repo)
{
    HyQuery q = hy_query_create(sack);
    hy_query_filter(q, HY_PKG_NAME, HY_EQ, name);
    hy_query_filter(q, HY_PKG_REPONAME, HY_EQ, repo);
    GPtrArray *plist = hy_query_run(q);
    hy_query_free(q);
    auto pkg = static_cast<DnfPackage *>(g_object_ref(g_ptr_array_index(plist, 0)));
    g_ptr_array_unref(plist);

    return pkg;
}

void
dump_packagelist(GPtrArray *plist, int free)
{
    for (guint i = 0; i < plist->len; ++i) {
        auto pkg = static_cast<DnfPackage *>(g_ptr_array_index(plist, i));
        Solvable *s = pool_id2solvable(dnf_package_get_pool(pkg), dnf_package_get_id(pkg));
        const char *nvra = dnf_package_get_nevra(pkg);
        printf("\t%s @%s\n", nvra, s->repo->name);
    }
    if (free)
        g_ptr_array_unref(plist);
}

void
dump_query_results(HyQuery query)
{
    GPtrArray *plist = hy_query_run(query);
    dump_packagelist(plist, 1);
}

void
dump_goal_results(HyGoal goal)
{
    printf("installs:\n");
    dump_packagelist(hy_goal_list_installs(goal, NULL), 1);
    printf("upgrades:\n");
    dump_packagelist(hy_goal_list_upgrades(goal, NULL), 1);
    printf("erasures:\n");
    dump_packagelist(hy_goal_list_erasures(goal, NULL), 1);
    printf("reinstalls:\n");
    dump_packagelist(hy_goal_list_reinstalls(goal, NULL), 1);
}

int
query_count_results(HyQuery query)
{
    GPtrArray *plist = hy_query_run(query);
    int ret = plist->len;
    g_ptr_array_unref(plist);
    return ret;
}