|
richard@300
|
1 |
/*
|
|
richard@300
|
2 |
* Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
|
|
richard@300
|
3 |
* Copyright (C) 2008 Red Hat, Inc
|
|
ali@369
|
4 |
* Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
|
|
richard@300
|
5 |
*
|
|
richard@300
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
richard@300
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
richard@300
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
richard@300
|
9 |
* (at your option) any later version.
|
|
richard@300
|
10 |
*
|
|
richard@300
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
richard@300
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
richard@300
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
richard@300
|
14 |
* GNU General Public License for more details.
|
|
richard@300
|
15 |
*
|
|
richard@300
|
16 |
* You should have received a copy of the GNU General Public License along
|
|
richard@300
|
17 |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
richard@300
|
18 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
richard@300
|
19 |
*/
|
|
richard@300
|
20 |
|
|
rhughes@241
|
21 |
#include <stdio.h>
|
|
rhughes@241
|
22 |
#include <string.h>
|
|
rhughes@241
|
23 |
#include <stdarg.h>
|
|
rhughes@241
|
24 |
#include <unistd.h>
|
|
rhughes@241
|
25 |
#include <fcntl.h>
|
|
rhughes@241
|
26 |
#include <errno.h>
|
|
rhughes@241
|
27 |
#include <expat.h>
|
|
rhughes@241
|
28 |
|
|
rhughes@241
|
29 |
#include "razor.h"
|
|
rhughes@241
|
30 |
|
|
rhughes@241
|
31 |
#define XML_BUFFER_SIZE 4096
|
|
rhughes@241
|
32 |
|
|
rhughes@241
|
33 |
static void
|
|
rhughes@241
|
34 |
parse_xml_file(const char *filename,
|
|
rhughes@241
|
35 |
XML_StartElementHandler start,
|
|
rhughes@241
|
36 |
XML_EndElementHandler end,
|
|
rhughes@241
|
37 |
void *data)
|
|
rhughes@241
|
38 |
{
|
|
rhughes@241
|
39 |
XML_Parser parser;
|
|
rhughes@241
|
40 |
char *buffer;
|
|
rhughes@241
|
41 |
int fd, len, err;
|
|
rhughes@241
|
42 |
|
|
rhughes@241
|
43 |
parser = XML_ParserCreate(NULL);
|
|
rhughes@241
|
44 |
XML_SetElementHandler(parser, start, end);
|
|
rhughes@241
|
45 |
XML_SetUserData(parser, data);
|
|
rhughes@241
|
46 |
|
|
rhughes@241
|
47 |
fd = open(filename, O_RDONLY);
|
|
rhughes@241
|
48 |
if (fd < 0) {
|
|
ali@339
|
49 |
fprintf(stderr, "failed to open %s: %s\n", filename,
|
|
ali@339
|
50 |
strerror(errno));
|
|
rhughes@241
|
51 |
exit(-1);
|
|
rhughes@241
|
52 |
}
|
|
rhughes@241
|
53 |
|
|
rhughes@241
|
54 |
while (1) {
|
|
rhughes@241
|
55 |
buffer = XML_GetBuffer(parser, XML_BUFFER_SIZE);
|
|
rhughes@241
|
56 |
len = read(fd, buffer, XML_BUFFER_SIZE);
|
|
rhughes@241
|
57 |
if (len == 0)
|
|
rhughes@241
|
58 |
break;
|
|
rhughes@241
|
59 |
err = XML_ParseBuffer(parser, len, len == 0);
|
|
rhughes@241
|
60 |
if (err == XML_STATUS_ERROR) {
|
|
rhughes@241
|
61 |
fprintf(stderr, "parse error at line %lu:\n%s\n",
|
|
rhughes@241
|
62 |
XML_GetCurrentLineNumber(parser),
|
|
rhughes@241
|
63 |
XML_ErrorString(XML_GetErrorCode(parser)));
|
|
rhughes@241
|
64 |
exit(-1);
|
|
rhughes@241
|
65 |
}
|
|
rhughes@241
|
66 |
}
|
|
rhughes@241
|
67 |
|
|
rhughes@241
|
68 |
if (fd < 0) {
|
|
ali@339
|
69 |
perror("read");
|
|
rhughes@241
|
70 |
exit(-1);
|
|
rhughes@241
|
71 |
}
|
|
rhughes@241
|
72 |
|
|
rhughes@241
|
73 |
close(fd);
|
|
rhughes@241
|
74 |
}
|
|
rhughes@241
|
75 |
|
|
rhughes@241
|
76 |
struct test_context {
|
|
rhughes@241
|
77 |
struct razor_set *system_set, *repo_set, *result_set;
|
|
rhughes@241
|
78 |
|
|
rhughes@241
|
79 |
struct razor_importer *importer;
|
|
rhughes@241
|
80 |
struct razor_set **importer_set;
|
|
rhughes@241
|
81 |
|
|
rhughes@241
|
82 |
struct razor_transaction *trans;
|
|
rhughes@241
|
83 |
|
|
rhughes@241
|
84 |
char *install_pkgs[3], *remove_pkgs[3];
|
|
rhughes@241
|
85 |
int n_install_pkgs, n_remove_pkgs;
|
|
rhughes@241
|
86 |
|
|
rhughes@241
|
87 |
int unsat;
|
|
rhughes@241
|
88 |
int in_result;
|
|
rhughes@241
|
89 |
|
|
rhughes@241
|
90 |
int debug, errors;
|
|
rhughes@241
|
91 |
};
|
|
rhughes@241
|
92 |
|
|
rhughes@241
|
93 |
static void
|
|
rhughes@241
|
94 |
get_atts(const char **atts, ...)
|
|
rhughes@241
|
95 |
{
|
|
rhughes@241
|
96 |
va_list ap;
|
|
rhughes@241
|
97 |
const char *name, **ptr;
|
|
rhughes@241
|
98 |
int i;
|
|
rhughes@241
|
99 |
|
|
rhughes@241
|
100 |
va_start(ap, atts);
|
|
rhughes@241
|
101 |
while (name = va_arg(ap, const char *), name != NULL) {
|
|
rhughes@241
|
102 |
ptr = va_arg(ap, const char **);
|
|
rhughes@241
|
103 |
*ptr = NULL;
|
|
rhughes@241
|
104 |
for (i = 0; atts[i]; i += 2) {
|
|
rhughes@241
|
105 |
if (strcmp(atts[i], name) == 0)
|
|
rhughes@241
|
106 |
*ptr = atts[i + 1];
|
|
rhughes@241
|
107 |
}
|
|
rhughes@241
|
108 |
}
|
|
rhughes@241
|
109 |
va_end(ap);
|
|
rhughes@241
|
110 |
}
|
|
rhughes@241
|
111 |
|
|
jbowes@284
|
112 |
static enum razor_property_flags
|
|
rhughes@241
|
113 |
parse_relation (const char *rel_str)
|
|
rhughes@241
|
114 |
{
|
|
rhughes@241
|
115 |
if (!rel_str)
|
|
rhughes@241
|
116 |
return -1;
|
|
rhughes@241
|
117 |
if (rel_str[0] == 'L')
|
|
jbowes@284
|
118 |
return rel_str[1] == 'E' ? RAZOR_PROPERTY_LESS | RAZOR_PROPERTY_EQUAL : RAZOR_PROPERTY_LESS;
|
|
rhughes@241
|
119 |
else if (rel_str[0] == 'G')
|
|
jbowes@284
|
120 |
return rel_str[1] == 'E' ? RAZOR_PROPERTY_GREATER | RAZOR_PROPERTY_EQUAL : RAZOR_PROPERTY_GREATER;
|
|
rhughes@241
|
121 |
else if (rel_str[0] == 'E' || rel_str[1] == 'Q')
|
|
jbowes@284
|
122 |
return RAZOR_PROPERTY_EQUAL;
|
|
rhughes@241
|
123 |
else
|
|
rhughes@241
|
124 |
return -1;
|
|
rhughes@241
|
125 |
}
|
|
rhughes@241
|
126 |
|
|
rhughes@241
|
127 |
static void
|
|
rhughes@241
|
128 |
start_test(struct test_context *ctx, const char **atts)
|
|
rhughes@241
|
129 |
{
|
|
rhughes@241
|
130 |
const char *name = NULL;
|
|
rhughes@241
|
131 |
|
|
rhughes@241
|
132 |
get_atts(atts, "name", &name, NULL);
|
|
rhughes@241
|
133 |
if (!name) {
|
|
rhughes@241
|
134 |
fprintf(stderr, "Test with no name\n");
|
|
rhughes@241
|
135 |
exit(1);
|
|
rhughes@241
|
136 |
}
|
|
rhughes@241
|
137 |
printf("%s\n", name);
|
|
rhughes@241
|
138 |
}
|
|
rhughes@241
|
139 |
|
|
rhughes@241
|
140 |
static void
|
|
rhughes@241
|
141 |
end_test(struct test_context *ctx)
|
|
rhughes@241
|
142 |
{
|
|
rhughes@241
|
143 |
if (ctx->system_set) {
|
|
rhughes@241
|
144 |
razor_set_destroy(ctx->system_set);
|
|
rhughes@241
|
145 |
ctx->system_set = NULL;
|
|
rhughes@241
|
146 |
}
|
|
rhughes@241
|
147 |
if (ctx->repo_set) {
|
|
rhughes@241
|
148 |
razor_set_destroy(ctx->repo_set);
|
|
rhughes@241
|
149 |
ctx->repo_set = NULL;
|
|
rhughes@241
|
150 |
}
|
|
rhughes@241
|
151 |
if (ctx->result_set) {
|
|
rhughes@241
|
152 |
razor_set_destroy(ctx->result_set);
|
|
rhughes@241
|
153 |
ctx->result_set = NULL;
|
|
rhughes@241
|
154 |
}
|
|
rhughes@241
|
155 |
if (ctx->trans) {
|
|
rhughes@241
|
156 |
razor_transaction_destroy(ctx->trans);
|
|
rhughes@241
|
157 |
ctx->trans = NULL;
|
|
rhughes@241
|
158 |
}
|
|
rhughes@241
|
159 |
}
|
|
rhughes@241
|
160 |
|
|
rhughes@241
|
161 |
static void
|
|
rhughes@241
|
162 |
start_set(struct test_context *ctx, const char **atts)
|
|
rhughes@241
|
163 |
{
|
|
rhughes@241
|
164 |
const char *name = NULL;
|
|
rhughes@241
|
165 |
|
|
jbowes@284
|
166 |
ctx->importer = razor_importer_create();
|
|
rhughes@241
|
167 |
get_atts(atts, "name", &name, NULL);
|
|
rhughes@241
|
168 |
if (!name)
|
|
rhughes@241
|
169 |
ctx->importer_set = &ctx->result_set;
|
|
rhughes@241
|
170 |
else if (!strcmp(name, "system"))
|
|
rhughes@241
|
171 |
ctx->importer_set = &ctx->system_set;
|
|
rhughes@241
|
172 |
else if (!strcmp(name, "repo"))
|
|
rhughes@241
|
173 |
ctx->importer_set = &ctx->repo_set;
|
|
rhughes@241
|
174 |
else {
|
|
rhughes@241
|
175 |
fprintf(stderr, " bad set name '%s'\n", name);
|
|
rhughes@241
|
176 |
exit(1);
|
|
rhughes@241
|
177 |
}
|
|
rhughes@241
|
178 |
}
|
|
rhughes@241
|
179 |
|
|
rhughes@241
|
180 |
static void
|
|
rhughes@241
|
181 |
end_set(struct test_context *ctx)
|
|
rhughes@241
|
182 |
{
|
|
rhughes@241
|
183 |
*ctx->importer_set = razor_importer_finish(ctx->importer);
|
|
rhughes@241
|
184 |
ctx->importer = NULL;
|
|
rhughes@241
|
185 |
}
|
|
rhughes@241
|
186 |
|
|
rhughes@241
|
187 |
static void
|
|
rhughes@241
|
188 |
start_package(struct test_context *ctx, const char **atts)
|
|
rhughes@241
|
189 |
{
|
|
rhughes@241
|
190 |
const char *name = NULL, *version = NULL, *arch = NULL;
|
|
rhughes@241
|
191 |
|
|
rhughes@241
|
192 |
get_atts(atts, "name", &name,
|
|
rhughes@241
|
193 |
"version", &version,
|
|
rhughes@241
|
194 |
"arch", &arch,
|
|
rhughes@241
|
195 |
NULL);
|
|
rhughes@241
|
196 |
|
|
rhughes@241
|
197 |
if (!name) {
|
|
rhughes@241
|
198 |
fprintf(stderr, " package with no name\n");
|
|
rhughes@241
|
199 |
exit(1);
|
|
rhughes@241
|
200 |
}
|
|
rhughes@241
|
201 |
|
|
rhughes@241
|
202 |
razor_importer_begin_package(ctx->importer, name, version, arch);
|
|
rhughes@241
|
203 |
razor_importer_add_property(ctx->importer, name,
|
|
jbowes@284
|
204 |
RAZOR_PROPERTY_EQUAL | RAZOR_PROPERTY_PROVIDES,
|
|
jbowes@284
|
205 |
version);
|
|
rhughes@241
|
206 |
}
|
|
rhughes@241
|
207 |
|
|
rhughes@241
|
208 |
static void
|
|
rhughes@241
|
209 |
end_package(struct test_context *ctx)
|
|
rhughes@241
|
210 |
{
|
|
rhughes@241
|
211 |
razor_importer_finish_package(ctx->importer);
|
|
rhughes@241
|
212 |
}
|
|
rhughes@241
|
213 |
|
|
rhughes@241
|
214 |
static void
|
|
jbowes@284
|
215 |
add_property(struct test_context *ctx, enum razor_property_flags type, const char *name, enum razor_property_flags rel, const char *version)
|
|
rhughes@241
|
216 |
{
|
|
rhughes@241
|
217 |
razor_importer_add_property(ctx->importer, name,
|
|
jbowes@284
|
218 |
rel | type, version);
|
|
jbowes@284
|
219 |
}
|
|
jbowes@284
|
220 |
|
|
jbowes@284
|
221 |
static const char*
|
|
jbowes@284
|
222 |
razor_property_flags_relation_to_string(enum razor_property_flags rel)
|
|
jbowes@284
|
223 |
{
|
|
jbowes@284
|
224 |
if (rel == RAZOR_PROPERTY_LESS)
|
|
jbowes@284
|
225 |
return "<";
|
|
jbowes@284
|
226 |
if (rel == (RAZOR_PROPERTY_EQUAL | RAZOR_PROPERTY_LESS))
|
|
jbowes@284
|
227 |
return "<=";
|
|
jbowes@284
|
228 |
if (rel == RAZOR_PROPERTY_EQUAL)
|
|
jbowes@284
|
229 |
return "=";
|
|
jbowes@284
|
230 |
if (rel == (RAZOR_PROPERTY_EQUAL | RAZOR_PROPERTY_GREATER))
|
|
jbowes@284
|
231 |
return ">=";
|
|
jbowes@284
|
232 |
if (rel == RAZOR_PROPERTY_GREATER)
|
|
jbowes@284
|
233 |
return ">";
|
|
jbowes@284
|
234 |
|
|
jbowes@284
|
235 |
return "";
|
|
rhughes@241
|
236 |
}
|
|
rhughes@241
|
237 |
|
|
rhughes@241
|
238 |
static void
|
|
rhughes@241
|
239 |
check_unsatisfiable_property(struct test_context *ctx,
|
|
jbowes@284
|
240 |
enum razor_property_flags type,
|
|
rhughes@241
|
241 |
const char *name,
|
|
jbowes@284
|
242 |
enum razor_property_flags rel,
|
|
rhughes@241
|
243 |
const char *version)
|
|
rhughes@241
|
244 |
{
|
|
rhughes@241
|
245 |
if (!version)
|
|
rhughes@241
|
246 |
version = "";
|
|
rhughes@241
|
247 |
|
|
rhughes@241
|
248 |
if (razor_transaction_unsatisfied_property(ctx->trans,
|
|
jbowes@284
|
249 |
name, rel | type, version))
|
|
rhughes@241
|
250 |
return;
|
|
rhughes@241
|
251 |
|
|
rhughes@241
|
252 |
fprintf(stderr, " didn't get unsatisfiable '%s %s %s'\n",
|
|
jbowes@284
|
253 |
name, razor_property_flags_relation_to_string(rel), version);
|
|
rhughes@241
|
254 |
ctx->errors++;
|
|
rhughes@241
|
255 |
}
|
|
rhughes@241
|
256 |
|
|
rhughes@241
|
257 |
static void
|
|
jbowes@284
|
258 |
start_property(struct test_context *ctx, enum razor_property_flags type, const char **atts)
|
|
rhughes@241
|
259 |
{
|
|
rhughes@241
|
260 |
const char *name = NULL, *rel_str = NULL, *version = NULL;
|
|
jbowes@284
|
261 |
enum razor_property_flags rel;
|
|
rhughes@241
|
262 |
|
|
rhughes@241
|
263 |
get_atts(atts, "name", &name, "relation", &rel_str, "version", &version, NULL);
|
|
rhughes@241
|
264 |
if (name == NULL) {
|
|
rhughes@241
|
265 |
fprintf(stderr, " no name specified for property\n");
|
|
rhughes@241
|
266 |
exit(1);
|
|
rhughes@241
|
267 |
}
|
|
rhughes@241
|
268 |
if (version) {
|
|
rhughes@241
|
269 |
rel = parse_relation(rel_str);
|
|
rhughes@241
|
270 |
if (rel == -1) {
|
|
rhughes@241
|
271 |
fprintf(stderr, " bad or missing version relation for property %s\n", name);
|
|
rhughes@241
|
272 |
exit(1);
|
|
rhughes@241
|
273 |
}
|
|
rhughes@241
|
274 |
} else
|
|
jbowes@284
|
275 |
rel = RAZOR_PROPERTY_EQUAL;
|
|
rhughes@241
|
276 |
|
|
rhughes@241
|
277 |
if (ctx->unsat)
|
|
rhughes@241
|
278 |
check_unsatisfiable_property(ctx, type, name, rel, version);
|
|
rhughes@241
|
279 |
else
|
|
rhughes@241
|
280 |
add_property(ctx, type, name, rel, version);
|
|
rhughes@241
|
281 |
}
|
|
rhughes@241
|
282 |
|
|
rhughes@241
|
283 |
static void
|
|
rhughes@241
|
284 |
start_transaction(struct test_context *ctx, const char **atts)
|
|
rhughes@241
|
285 |
{
|
|
rhughes@241
|
286 |
ctx->n_install_pkgs = 0;
|
|
rhughes@241
|
287 |
ctx->n_remove_pkgs = 0;
|
|
rhughes@241
|
288 |
}
|
|
rhughes@241
|
289 |
|
|
krh@306
|
290 |
static struct razor_package *
|
|
krh@306
|
291 |
get_package(struct razor_set *set, const char *package)
|
|
krh@306
|
292 |
{
|
|
krh@306
|
293 |
struct razor_package_iterator *pi;
|
|
krh@306
|
294 |
struct razor_package *p;
|
|
krh@306
|
295 |
const char *name, *version, *arch;
|
|
krh@306
|
296 |
|
|
krh@306
|
297 |
pi = razor_package_iterator_create(set);
|
|
richard@307
|
298 |
while (razor_package_iterator_next(pi, &p, RAZOR_DETAIL_NAME, &name,
|
|
richard@307
|
299 |
RAZOR_DETAIL_VERSION, &version,
|
|
richard@307
|
300 |
RAZOR_DETAIL_ARCH, &arch,
|
|
richard@307
|
301 |
RAZOR_DETAIL_LAST)) {
|
|
krh@306
|
302 |
if (strcmp(package, name) == 0)
|
|
krh@306
|
303 |
break;
|
|
krh@306
|
304 |
}
|
|
krh@306
|
305 |
razor_package_iterator_destroy(pi);
|
|
krh@306
|
306 |
|
|
krh@306
|
307 |
return p;
|
|
krh@306
|
308 |
}
|
|
krh@306
|
309 |
|
|
rhughes@241
|
310 |
static void
|
|
rhughes@241
|
311 |
end_transaction(struct test_context *ctx)
|
|
rhughes@241
|
312 |
{
|
|
rhughes@241
|
313 |
struct razor_package *pkg;
|
|
rhughes@241
|
314 |
int errors, i;
|
|
rhughes@241
|
315 |
|
|
rhughes@241
|
316 |
ctx->trans = razor_transaction_create(ctx->system_set, ctx->repo_set);
|
|
rhughes@241
|
317 |
for (i = 0; i < ctx->n_install_pkgs; i++) {
|
|
krh@306
|
318 |
pkg = get_package(ctx->repo_set, ctx->install_pkgs[i]);
|
|
rhughes@241
|
319 |
razor_transaction_install_package(ctx->trans, pkg);
|
|
rhughes@241
|
320 |
}
|
|
rhughes@241
|
321 |
for (i = 0; i < ctx->n_remove_pkgs; i++) {
|
|
krh@306
|
322 |
pkg = get_package(ctx->system_set, ctx->remove_pkgs[i]);
|
|
jbowes@258
|
323 |
if (!pkg)
|
|
krh@306
|
324 |
pkg = get_package(ctx->repo_set, ctx->remove_pkgs[i]);
|
|
jbowes@258
|
325 |
|
|
rhughes@241
|
326 |
razor_transaction_remove_package(ctx->trans, pkg);
|
|
rhughes@241
|
327 |
}
|
|
rhughes@241
|
328 |
|
|
jbowes@284
|
329 |
razor_transaction_resolve(ctx->trans);
|
|
jbowes@284
|
330 |
errors = razor_transaction_describe(ctx->trans);
|
|
rhughes@241
|
331 |
printf("\n");
|
|
rhughes@241
|
332 |
|
|
rhughes@241
|
333 |
while (ctx->n_install_pkgs--)
|
|
rhughes@241
|
334 |
free(ctx->install_pkgs[ctx->n_install_pkgs]);
|
|
rhughes@241
|
335 |
while (ctx->n_remove_pkgs--)
|
|
rhughes@241
|
336 |
free(ctx->remove_pkgs[ctx->n_remove_pkgs]);
|
|
rhughes@241
|
337 |
|
|
rhughes@241
|
338 |
if (!errors) {
|
|
rhughes@241
|
339 |
struct razor_set *new;
|
|
ali@369
|
340 |
new = razor_transaction_commit(ctx->trans);
|
|
ali@369
|
341 |
razor_transaction_destroy(ctx->trans);
|
|
jbowes@258
|
342 |
ctx->trans = NULL;
|
|
rhughes@241
|
343 |
ctx->system_set = new;
|
|
rhughes@241
|
344 |
}
|
|
rhughes@241
|
345 |
}
|
|
rhughes@241
|
346 |
|
|
rhughes@241
|
347 |
static void
|
|
rhughes@241
|
348 |
start_install_or_update(struct test_context *ctx, const char **atts)
|
|
rhughes@241
|
349 |
{
|
|
rhughes@241
|
350 |
const char *name = NULL;
|
|
rhughes@241
|
351 |
|
|
rhughes@241
|
352 |
get_atts(atts, "name", &name, NULL);
|
|
rhughes@241
|
353 |
if (!name) {
|
|
rhughes@241
|
354 |
fprintf(stderr, " install/update with no name\n");
|
|
rhughes@241
|
355 |
exit(1);
|
|
rhughes@241
|
356 |
}
|
|
rhughes@241
|
357 |
|
|
rhughes@241
|
358 |
ctx->install_pkgs[ctx->n_install_pkgs++] = strdup(name);
|
|
rhughes@241
|
359 |
}
|
|
rhughes@241
|
360 |
|
|
rhughes@241
|
361 |
static void
|
|
rhughes@241
|
362 |
start_remove(struct test_context *ctx, const char **atts)
|
|
rhughes@241
|
363 |
{
|
|
rhughes@241
|
364 |
const char *name = NULL;
|
|
rhughes@241
|
365 |
|
|
rhughes@241
|
366 |
get_atts(atts, "name", &name, NULL);
|
|
rhughes@241
|
367 |
if (!name) {
|
|
rhughes@241
|
368 |
fprintf(stderr, " remove with no name\n");
|
|
rhughes@241
|
369 |
exit(1);
|
|
rhughes@241
|
370 |
}
|
|
rhughes@241
|
371 |
|
|
rhughes@241
|
372 |
ctx->remove_pkgs[ctx->n_remove_pkgs++] = strdup(name);
|
|
rhughes@241
|
373 |
}
|
|
rhughes@241
|
374 |
|
|
rhughes@241
|
375 |
static void
|
|
rhughes@241
|
376 |
start_result(struct test_context *ctx, const char **atts)
|
|
rhughes@241
|
377 |
{
|
|
rhughes@241
|
378 |
ctx->in_result = 1;
|
|
rhughes@241
|
379 |
}
|
|
rhughes@241
|
380 |
|
|
rhughes@241
|
381 |
static void
|
|
jbowes@284
|
382 |
diff_callback(enum razor_diff_action action,
|
|
jbowes@284
|
383 |
struct razor_package *package,
|
|
jbowes@284
|
384 |
const char *name,
|
|
jbowes@284
|
385 |
const char *version,
|
|
rhughes@241
|
386 |
const char *arch,
|
|
rhughes@241
|
387 |
void *data)
|
|
rhughes@241
|
388 |
{
|
|
rhughes@241
|
389 |
struct test_context *ctx = data;
|
|
rhughes@241
|
390 |
|
|
rhughes@241
|
391 |
ctx->errors++;
|
|
jbowes@284
|
392 |
if (action == RAZOR_DIFF_ACTION_REMOVE) {
|
|
rhughes@241
|
393 |
fprintf(stderr, " result set should not contain %s %s\n",
|
|
jbowes@284
|
394 |
name, version);
|
|
rhughes@241
|
395 |
} else {
|
|
rhughes@241
|
396 |
fprintf(stderr, " result set should contain %s %s\n",
|
|
jbowes@284
|
397 |
name, version);
|
|
rhughes@241
|
398 |
}
|
|
rhughes@241
|
399 |
}
|
|
rhughes@241
|
400 |
|
|
rhughes@241
|
401 |
static void
|
|
rhughes@241
|
402 |
end_result(struct test_context *ctx)
|
|
rhughes@241
|
403 |
{
|
|
rhughes@241
|
404 |
ctx->in_result = 0;
|
|
rhughes@241
|
405 |
|
|
rhughes@241
|
406 |
if (ctx->result_set) {
|
|
rhughes@241
|
407 |
if (!ctx->system_set)
|
|
rhughes@241
|
408 |
ctx->system_set = razor_set_create();
|
|
rhughes@241
|
409 |
razor_set_diff(ctx->system_set, ctx->result_set,
|
|
rhughes@241
|
410 |
diff_callback, ctx);
|
|
rhughes@241
|
411 |
}
|
|
rhughes@241
|
412 |
}
|
|
rhughes@241
|
413 |
|
|
rhughes@241
|
414 |
static void
|
|
rhughes@241
|
415 |
start_unsatisfiable(struct test_context *ctx, const char **atts)
|
|
rhughes@241
|
416 |
{
|
|
rhughes@241
|
417 |
if (ctx->result_set) {
|
|
rhughes@241
|
418 |
fprintf(stderr, "Expected to fail, but didn't\n");
|
|
rhughes@241
|
419 |
exit(1);
|
|
rhughes@241
|
420 |
}
|
|
rhughes@241
|
421 |
|
|
rhughes@241
|
422 |
ctx->unsat = 1;
|
|
rhughes@241
|
423 |
}
|
|
rhughes@241
|
424 |
|
|
rhughes@241
|
425 |
static void
|
|
rhughes@241
|
426 |
end_unsatisfiable(struct test_context *ctx)
|
|
rhughes@241
|
427 |
{
|
|
rhughes@241
|
428 |
ctx->unsat = 0;
|
|
rhughes@241
|
429 |
}
|
|
rhughes@241
|
430 |
|
|
rhughes@241
|
431 |
static void
|
|
rhughes@241
|
432 |
start_test_element(void *data, const char *element, const char **atts)
|
|
rhughes@241
|
433 |
{
|
|
rhughes@241
|
434 |
struct test_context *ctx = data;
|
|
rhughes@241
|
435 |
|
|
rhughes@241
|
436 |
if (strcmp(element, "tests") == 0) {
|
|
rhughes@241
|
437 |
;
|
|
rhughes@241
|
438 |
} else if (strcmp(element, "test") == 0) {
|
|
rhughes@241
|
439 |
start_test(ctx, atts);
|
|
rhughes@241
|
440 |
} else if (strcmp(element, "set") == 0) {
|
|
rhughes@241
|
441 |
start_set(ctx, atts);
|
|
rhughes@241
|
442 |
} else if (strcmp(element, "transaction") == 0) {
|
|
rhughes@241
|
443 |
start_transaction(ctx, atts);
|
|
rhughes@241
|
444 |
} else if (strcmp(element, "install") == 0) {
|
|
rhughes@241
|
445 |
start_install_or_update(ctx, atts);
|
|
rhughes@241
|
446 |
} else if (strcmp(element, "install") == 0) {
|
|
rhughes@241
|
447 |
start_install_or_update(ctx, atts);
|
|
rhughes@241
|
448 |
} else if (strcmp(element, "remove") == 0) {
|
|
rhughes@241
|
449 |
start_remove(ctx, atts);
|
|
rhughes@241
|
450 |
} else if (strcmp(element, "result") == 0) {
|
|
rhughes@241
|
451 |
start_result(ctx, atts);
|
|
rhughes@241
|
452 |
} else if (strcmp(element, "unsatisfiable") == 0) {
|
|
rhughes@241
|
453 |
start_unsatisfiable(ctx, atts);
|
|
rhughes@241
|
454 |
} else if (strcmp(element, "package") == 0) {
|
|
rhughes@241
|
455 |
start_package(ctx, atts);
|
|
rhughes@241
|
456 |
} else if (strcmp(element, "requires") == 0) {
|
|
rhughes@241
|
457 |
start_property(ctx, RAZOR_PROPERTY_REQUIRES, atts);
|
|
rhughes@241
|
458 |
} else if (strcmp(element, "provides") == 0) {
|
|
rhughes@241
|
459 |
start_property(ctx, RAZOR_PROPERTY_PROVIDES, atts);
|
|
rhughes@241
|
460 |
} else if (strcmp(element, "conflicts") == 0) {
|
|
rhughes@241
|
461 |
start_property(ctx, RAZOR_PROPERTY_CONFLICTS, atts);
|
|
rhughes@241
|
462 |
} else if (strcmp(element, "obsoletes") == 0) {
|
|
rhughes@241
|
463 |
start_property(ctx, RAZOR_PROPERTY_OBSOLETES, atts);
|
|
rhughes@241
|
464 |
} else {
|
|
rhughes@241
|
465 |
fprintf(stderr, "Unrecognized element '%s'\n", element);
|
|
rhughes@241
|
466 |
exit(1);
|
|
rhughes@241
|
467 |
}
|
|
rhughes@241
|
468 |
}
|
|
rhughes@241
|
469 |
|
|
rhughes@241
|
470 |
static void
|
|
rhughes@241
|
471 |
end_test_element (void *data, const char *element)
|
|
rhughes@241
|
472 |
{
|
|
rhughes@241
|
473 |
struct test_context *ctx = data;
|
|
rhughes@241
|
474 |
|
|
rhughes@241
|
475 |
if (strcmp(element, "test") == 0) {
|
|
rhughes@241
|
476 |
end_test(ctx);
|
|
rhughes@241
|
477 |
} else if (strcmp(element, "set") == 0) {
|
|
rhughes@241
|
478 |
end_set(ctx);
|
|
rhughes@241
|
479 |
} else if (strcmp(element, "package") == 0) {
|
|
rhughes@241
|
480 |
end_package(ctx);
|
|
rhughes@241
|
481 |
} else if (strcmp(element, "transaction") == 0) {
|
|
rhughes@241
|
482 |
end_transaction(ctx);
|
|
rhughes@241
|
483 |
} else if (strcmp(element, "result") == 0) {
|
|
rhughes@241
|
484 |
end_result(ctx);
|
|
rhughes@241
|
485 |
} else if (strcmp(element, "unsatisfiable") == 0) {
|
|
rhughes@241
|
486 |
end_unsatisfiable(ctx);
|
|
rhughes@241
|
487 |
}
|
|
rhughes@241
|
488 |
}
|
|
rhughes@241
|
489 |
|
|
rhughes@241
|
490 |
int main(int argc, char *argv[])
|
|
rhughes@241
|
491 |
{
|
|
rhughes@241
|
492 |
struct test_context ctx;
|
|
rhughes@241
|
493 |
const char *test_file;
|
|
rhughes@241
|
494 |
|
|
rhughes@241
|
495 |
memset(&ctx, 0, sizeof ctx);
|
|
rhughes@241
|
496 |
|
|
rhughes@241
|
497 |
if (argc > 3) {
|
|
rhughes@241
|
498 |
fprintf(stderr, "usage: %s [-d] [TESTS-FILE]\n", argv[0]);
|
|
rhughes@241
|
499 |
exit(-1);
|
|
rhughes@241
|
500 |
}
|
|
rhughes@241
|
501 |
|
|
rhughes@241
|
502 |
if (argc >= 2 && !strcmp (argv[1], "-d")) {
|
|
rhughes@241
|
503 |
ctx.debug = 1;
|
|
rhughes@241
|
504 |
argc--;
|
|
rhughes@241
|
505 |
argv++;
|
|
rhughes@241
|
506 |
}
|
|
rhughes@241
|
507 |
if (argc == 2)
|
|
rhughes@241
|
508 |
test_file = argv[1];
|
|
rhughes@241
|
509 |
else
|
|
rhughes@241
|
510 |
test_file = "test.xml";
|
|
rhughes@241
|
511 |
|
|
rhughes@241
|
512 |
parse_xml_file(test_file, start_test_element, end_test_element, &ctx);
|
|
rhughes@241
|
513 |
|
|
rhughes@241
|
514 |
if (ctx.errors) {
|
|
rhughes@241
|
515 |
fprintf(stderr, "\n%d errors\n", ctx.errors);
|
|
rhughes@241
|
516 |
return 1;
|
|
rhughes@241
|
517 |
} else
|
|
rhughes@241
|
518 |
return 0;
|
|
rhughes@241
|
519 |
}
|