Use the cpio headers instead of the rpm headers when unpacking.
The files in the cpio payload doesn't actually follow the file order
in the rpm headers, so we need to decode the cpio header and use the
information there.
11 #define XML_BUFFER_SIZE 4096
14 parse_xml_file(const char *filename,
15 XML_StartElementHandler start,
16 XML_EndElementHandler end,
23 parser = XML_ParserCreate(NULL);
24 XML_SetElementHandler(parser, start, end);
25 XML_SetUserData(parser, data);
27 fd = open(filename, O_RDONLY);
29 fprintf(stderr, "failed to open %s: %m\n", filename);
34 buffer = XML_GetBuffer(parser, XML_BUFFER_SIZE);
35 len = read(fd, buffer, XML_BUFFER_SIZE);
38 err = XML_ParseBuffer(parser, len, len == 0);
39 if (err == XML_STATUS_ERROR) {
40 fprintf(stderr, "parse error at line %lu:\n%s\n",
41 XML_GetCurrentLineNumber(parser),
42 XML_ErrorString(XML_GetErrorCode(parser)));
48 fprintf(stderr, "read: %m\n");
56 struct razor_set *system_set, *repo_set, *result_set;
58 struct razor_importer *importer;
59 struct razor_set **importer_set;
61 struct razor_transaction *trans;
63 char *install_pkgs[3], *remove_pkgs[3];
64 int n_install_pkgs, n_remove_pkgs;
73 get_atts(const char **atts, ...)
76 const char *name, **ptr;
80 while (name = va_arg(ap, const char *), name != NULL) {
81 ptr = va_arg(ap, const char **);
83 for (i = 0; atts[i]; i += 2) {
84 if (strcmp(atts[i], name) == 0)
91 static enum razor_version_relation
92 parse_relation (const char *rel_str)
96 if (rel_str[0] == 'L')
97 return rel_str[1] == 'E' ? RAZOR_VERSION_LESS_OR_EQUAL : RAZOR_VERSION_LESS;
98 else if (rel_str[0] == 'G')
99 return rel_str[1] == 'E' ? RAZOR_VERSION_GREATER_OR_EQUAL : RAZOR_VERSION_GREATER;
100 else if (rel_str[0] == 'E' || rel_str[1] == 'Q')
101 return RAZOR_VERSION_EQUAL;
107 start_test(struct test_context *ctx, const char **atts)
109 const char *name = NULL;
111 get_atts(atts, "name", &name, NULL);
113 fprintf(stderr, "Test with no name\n");
116 printf("%s\n", name);
120 end_test(struct test_context *ctx)
122 if (ctx->system_set) {
123 razor_set_destroy(ctx->system_set);
124 ctx->system_set = NULL;
127 razor_set_destroy(ctx->repo_set);
128 ctx->repo_set = NULL;
130 if (ctx->result_set) {
131 razor_set_destroy(ctx->result_set);
132 ctx->result_set = NULL;
135 razor_transaction_destroy(ctx->trans);
141 start_set(struct test_context *ctx, const char **atts)
143 const char *name = NULL;
145 ctx->importer = razor_importer_new();
146 get_atts(atts, "name", &name, NULL);
148 ctx->importer_set = &ctx->result_set;
149 else if (!strcmp(name, "system"))
150 ctx->importer_set = &ctx->system_set;
151 else if (!strcmp(name, "repo"))
152 ctx->importer_set = &ctx->repo_set;
154 fprintf(stderr, " bad set name '%s'\n", name);
160 end_set(struct test_context *ctx)
162 *ctx->importer_set = razor_importer_finish(ctx->importer);
163 ctx->importer = NULL;
167 start_package(struct test_context *ctx, const char **atts)
169 const char *name = NULL, *version = NULL, *arch = NULL;
171 get_atts(atts, "name", &name,
177 fprintf(stderr, " package with no name\n");
181 razor_importer_begin_package(ctx->importer, name, version, arch);
182 razor_importer_add_property(ctx->importer, name,
183 RAZOR_VERSION_EQUAL, version,
184 RAZOR_PROPERTY_PROVIDES);
188 end_package(struct test_context *ctx)
190 razor_importer_finish_package(ctx->importer);
194 add_property(struct test_context *ctx, enum razor_property_type type, const char *name, enum razor_version_relation rel, const char *version)
196 razor_importer_add_property(ctx->importer, name,
201 check_unsatisfiable_property(struct test_context *ctx,
202 enum razor_property_type type,
204 enum razor_version_relation rel,
210 if (razor_transaction_unsatisfied_property(ctx->trans,
214 fprintf(stderr, " didn't get unsatisfiable '%s %s %s'\n",
215 name, razor_version_relations[rel], version);
220 start_property(struct test_context *ctx, enum razor_property_type type, const char **atts)
222 const char *name = NULL, *rel_str = NULL, *version = NULL;
223 enum razor_version_relation rel;
225 get_atts(atts, "name", &name, "relation", &rel_str, "version", &version, NULL);
227 fprintf(stderr, " no name specified for property\n");
231 rel = parse_relation(rel_str);
233 fprintf(stderr, " bad or missing version relation for property %s\n", name);
237 rel = RAZOR_VERSION_EQUAL;
240 check_unsatisfiable_property(ctx, type, name, rel, version);
242 add_property(ctx, type, name, rel, version);
246 start_transaction(struct test_context *ctx, const char **atts)
248 ctx->n_install_pkgs = 0;
249 ctx->n_remove_pkgs = 0;
253 end_transaction(struct test_context *ctx)
255 struct razor_package *pkg;
258 ctx->trans = razor_transaction_create(ctx->system_set, ctx->repo_set);
259 for (i = 0; i < ctx->n_install_pkgs; i++) {
260 pkg = razor_set_get_package(ctx->repo_set,
261 ctx->install_pkgs[i]);
262 razor_transaction_install_package(ctx->trans, pkg);
264 for (i = 0; i < ctx->n_remove_pkgs; i++) {
265 pkg = razor_set_get_package(ctx->repo_set,
266 ctx->remove_pkgs[i]);
267 razor_transaction_remove_package(ctx->trans, pkg);
270 errors = razor_transaction_resolve(ctx->trans);
273 while (ctx->n_install_pkgs--)
274 free(ctx->install_pkgs[ctx->n_install_pkgs]);
275 while (ctx->n_remove_pkgs--)
276 free(ctx->remove_pkgs[ctx->n_remove_pkgs]);
279 struct razor_set *new;
280 new = razor_transaction_finish(ctx->trans);
281 ctx->system_set = new;
286 start_install_or_update(struct test_context *ctx, const char **atts)
288 const char *name = NULL;
290 get_atts(atts, "name", &name, NULL);
292 fprintf(stderr, " install/update with no name\n");
296 ctx->install_pkgs[ctx->n_install_pkgs++] = strdup(name);
300 start_remove(struct test_context *ctx, const char **atts)
302 const char *name = NULL;
304 get_atts(atts, "name", &name, NULL);
306 fprintf(stderr, " remove with no name\n");
310 ctx->remove_pkgs[ctx->n_remove_pkgs++] = strdup(name);
314 start_result(struct test_context *ctx, const char **atts)
320 diff_callback(const char *name,
321 const char *old_version,
322 const char *new_version,
326 struct test_context *ctx = data;
330 fprintf(stderr, " result set should not contain %s %s\n",
333 fprintf(stderr, " result set should contain %s %s\n",
339 end_result(struct test_context *ctx)
343 if (ctx->result_set) {
344 if (!ctx->system_set)
345 ctx->system_set = razor_set_create();
346 razor_set_diff(ctx->system_set, ctx->result_set,
352 start_unsatisfiable(struct test_context *ctx, const char **atts)
354 if (ctx->result_set) {
355 fprintf(stderr, "Expected to fail, but didn't\n");
363 end_unsatisfiable(struct test_context *ctx)
369 start_test_element(void *data, const char *element, const char **atts)
371 struct test_context *ctx = data;
373 if (strcmp(element, "tests") == 0) {
375 } else if (strcmp(element, "test") == 0) {
376 start_test(ctx, atts);
377 } else if (strcmp(element, "set") == 0) {
378 start_set(ctx, atts);
379 } else if (strcmp(element, "transaction") == 0) {
380 start_transaction(ctx, atts);
381 } else if (strcmp(element, "install") == 0) {
382 start_install_or_update(ctx, atts);
383 } else if (strcmp(element, "install") == 0) {
384 start_install_or_update(ctx, atts);
385 } else if (strcmp(element, "remove") == 0) {
386 start_remove(ctx, atts);
387 } else if (strcmp(element, "result") == 0) {
388 start_result(ctx, atts);
389 } else if (strcmp(element, "unsatisfiable") == 0) {
390 start_unsatisfiable(ctx, atts);
391 } else if (strcmp(element, "package") == 0) {
392 start_package(ctx, atts);
393 } else if (strcmp(element, "requires") == 0) {
394 start_property(ctx, RAZOR_PROPERTY_REQUIRES, atts);
395 } else if (strcmp(element, "provides") == 0) {
396 start_property(ctx, RAZOR_PROPERTY_PROVIDES, atts);
397 } else if (strcmp(element, "conflicts") == 0) {
398 start_property(ctx, RAZOR_PROPERTY_CONFLICTS, atts);
399 } else if (strcmp(element, "obsoletes") == 0) {
400 start_property(ctx, RAZOR_PROPERTY_OBSOLETES, atts);
402 fprintf(stderr, "Unrecognized element '%s'\n", element);
408 end_test_element (void *data, const char *element)
410 struct test_context *ctx = data;
412 if (strcmp(element, "test") == 0) {
414 } else if (strcmp(element, "set") == 0) {
416 } else if (strcmp(element, "package") == 0) {
418 } else if (strcmp(element, "transaction") == 0) {
419 end_transaction(ctx);
420 } else if (strcmp(element, "result") == 0) {
422 } else if (strcmp(element, "unsatisfiable") == 0) {
423 end_unsatisfiable(ctx);
427 int main(int argc, char *argv[])
429 struct test_context ctx;
430 const char *test_file;
432 memset(&ctx, 0, sizeof ctx);
435 fprintf(stderr, "usage: %s [-d] [TESTS-FILE]\n", argv[0]);
439 if (argc >= 2 && !strcmp (argv[1], "-d")) {
447 test_file = "test.xml";
449 parse_xml_file(test_file, start_test_element, end_test_element, &ctx);
452 fprintf(stderr, "\n%d errors\n", ctx.errors);