XBPS Library API 20250615
The X Binary Package System
pkgdb/main.c
1/*-
2 * Copyright (c) 2013 Juan Romero Pardines.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *-
25 */
26#include <atf-c.h>
27#include <xbps.h>
28
29ATF_TC(pkgdb_get_pkg_test);
30ATF_TC_HEAD(pkgdb_get_pkg_test, tc)
31{
32 atf_tc_set_md_var(tc, "descr", "Test xbps_pkgdb_get_pkg()");
33}
34
35ATF_TC_BODY(pkgdb_get_pkg_test, tc)
36{
37 xbps_dictionary_t pkgd;
38 struct xbps_handle xh;
39 const char *tcsdir, *pkgver;
40
41 /* get test source dir */
42 tcsdir = atf_tc_get_config_var(tc, "srcdir");
43
44 memset(&xh, 0, sizeof(xh));
45 xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
46 xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
47 xh.flags = XBPS_FLAG_DEBUG;
48 ATF_REQUIRE_EQ(xbps_init(&xh), 0);
49
50 pkgd = xbps_pkgdb_get_pkg(&xh, "mixed");
51 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
52 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
53 ATF_REQUIRE_STREQ(pkgver, "mixed-0.1_1");
54
55 pkgd = xbps_pkgdb_get_pkg(&xh, "mixed>0");
56 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
57 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
58 ATF_REQUIRE_STREQ(pkgver, "mixed-0.1_1");
59
60 pkgd = xbps_pkgdb_get_pkg(&xh, "mixed<2");
61 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
62 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
63 ATF_REQUIRE_STREQ(pkgver, "mixed-0.1_1");
64
65 pkgd = xbps_pkgdb_get_pkg(&xh, "mixed-0.1_1");
66 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
67 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
68 ATF_REQUIRE_STREQ(pkgver, "mixed-0.1_1");
69}
70
71ATF_TC(pkgdb_get_virtualpkg_test);
72ATF_TC_HEAD(pkgdb_get_virtualpkg_test, tc)
73{
74 atf_tc_set_md_var(tc, "descr", "Test xbps_pkgdb_get_virtualpkg()");
75}
76
77ATF_TC_BODY(pkgdb_get_virtualpkg_test, tc)
78{
79 xbps_dictionary_t pkgd;
80 struct xbps_handle xh;
81 const char *tcsdir, *pkgver;
82
83 /* get test source dir */
84 tcsdir = atf_tc_get_config_var(tc, "srcdir");
85
86 memset(&xh, 0, sizeof(xh));
87 xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
88 xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
89 xh.flags = XBPS_FLAG_DEBUG;
90 ATF_REQUIRE_EQ(xbps_init(&xh), 0);
91
92 pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed");
93 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
94 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
95 ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");
96
97 pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed>0");
98 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
99 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
100 ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");
101
102 pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed<2");
103 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
104 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
105 ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");
106
107 pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed-0.1_1");
108 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
109 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
110 ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");
111}
112
113ATF_TC(pkgdb_get_pkg_revdeps_test);
114ATF_TC_HEAD(pkgdb_get_pkg_revdeps_test, tc)
115{
116 atf_tc_set_md_var(tc, "descr", "Test xbps_pkgdb_get_pkg_revdeps()");
117}
118
119ATF_TC_BODY(pkgdb_get_pkg_revdeps_test, tc)
120{
121 struct xbps_handle xh;
122 xbps_array_t res;
123 xbps_string_t pstr;
124 const char *tcsdir, *str;
125 const char *eout = "four-0.1_1\ntwo-0.1_1\n";
126 unsigned int i;
127
128 /* get test source dir */
129 tcsdir = atf_tc_get_config_var(tc, "srcdir");
130
131 memset(&xh, 0, sizeof(xh));
132 xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
133 xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
134 xh.flags = XBPS_FLAG_DEBUG;
135 ATF_REQUIRE_EQ(xbps_init(&xh), 0);
136
137 res = xbps_pkgdb_get_pkg_revdeps(&xh, "virtual-mixed");
138 ATF_REQUIRE_EQ(xbps_object_type(res), XBPS_TYPE_ARRAY);
139
140 pstr = xbps_string_create();
141 for (i = 0; i < xbps_array_count(res); i++) {
142 xbps_array_get_cstring_nocopy(res, i, &str);
143 xbps_string_append_cstring(pstr, str);
144 xbps_string_append_cstring(pstr, "\n");
145 }
146 ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), eout);
147}
148
149ATF_TC(pkgdb_pkg_reverts_test);
150ATF_TC_HEAD(pkgdb_pkg_reverts_test, tc)
151{
152 atf_tc_set_md_var(tc, "descr", "Test xbps_pkg_reverts()");
153}
154
155ATF_TC_BODY(pkgdb_pkg_reverts_test, tc)
156{
157 struct xbps_handle xh;
158 const char *tcsdir;
159 xbps_dictionary_t pkgd;
160
161 /* get test source dir */
162 tcsdir = atf_tc_get_config_var(tc, "srcdir");
163
164 memset(&xh, 0, sizeof(xh));
165 xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
166 xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
167 xh.flags = XBPS_FLAG_DEBUG;
168 ATF_REQUIRE_EQ(xbps_init(&xh), 0);
169
170 pkgd = xbps_pkgdb_get_pkg(&xh, "reverts");
171 ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
172
173 ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.2_1"), 0);
174 ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.3_1"), 1);
175 ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.4_1"), 1);
176 ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.5_1"), 0);
177}
178
179ATF_TP_ADD_TCS(tp)
180{
181 ATF_TP_ADD_TC(tp, pkgdb_get_pkg_test);
182 ATF_TP_ADD_TC(tp, pkgdb_get_virtualpkg_test);
183 ATF_TP_ADD_TC(tp, pkgdb_get_pkg_revdeps_test);
184 ATF_TP_ADD_TC(tp, pkgdb_pkg_reverts_test);
185
186 return atf_no_error();
187}
Generic XBPS structure handler for initialization.
Definition xbps.h:559
void void void void void int xbps_init(struct xbps_handle *xhp)
Definition initend.c:46
xbps_dictionary_t xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp, const char *pkg)
Definition pkgdb.c:430
xbps_array_t xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
Definition pkgdb.c:517
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
Definition pkgdb.c:416
size_t xbps_strlcpy(char *dst, const char *src, size_t dstsize)
Definition util.c:575
bool xbps_pkg_reverts(xbps_dictionary_t pkg, const char *pkgver)
Definition util.c:587