1.1 --- a/test-driver.c Thu Feb 21 14:58:39 2008 -0500
1.2 +++ b/test-driver.c Tue Mar 04 10:55:01 2008 -0500
1.3 @@ -24,15 +24,17 @@
1.4 XML_SetElementHandler(parser, start, end);
1.5 XML_SetUserData(parser, data);
1.6
1.7 - buffer = XML_GetBuffer(parser, XML_BUFFER_SIZE);
1.8 -
1.9 fd = open(filename, O_RDONLY);
1.10 if (fd < 0) {
1.11 fprintf(stderr, "failed to open %s: %m\n", filename);
1.12 exit(-1);
1.13 }
1.14
1.15 - while (len = read(fd, buffer, XML_BUFFER_SIZE), len > 0) {
1.16 + while (1) {
1.17 + buffer = XML_GetBuffer(parser, XML_BUFFER_SIZE);
1.18 + len = read(fd, buffer, XML_BUFFER_SIZE);
1.19 + if (len == 0)
1.20 + break;
1.21 err = XML_ParseBuffer(parser, len, len == 0);
1.22 if (err == XML_STATUS_ERROR) {
1.23 fprintf(stderr, "parse error at line %lu:\n%s\n",
1.24 @@ -56,11 +58,15 @@
1.25 struct razor_importer *importer;
1.26 struct razor_set **importer_set;
1.27
1.28 + struct razor_transaction *trans;
1.29 + struct razor_transaction_package *unsat;
1.30 +
1.31 char *install_pkgs[3], *remove_pkgs[3];
1.32 int n_install_pkgs, n_remove_pkgs;
1.33
1.34 int in_result, result_errors;
1.35 - int in_unsatisfiable;
1.36 +
1.37 + int debug;
1.38 };
1.39
1.40 static void
1.41 @@ -87,11 +93,11 @@
1.42 {
1.43 if (!rel_str)
1.44 return -1;
1.45 - if (rel_str[0] == 'l')
1.46 - return rel_str[1] == 'e' ? RAZOR_VERSION_LESS_OR_EQUAL : RAZOR_VERSION_LESS;
1.47 - else if (rel_str[0] == 'g')
1.48 - return rel_str[1] == 'e' ? RAZOR_VERSION_GREATER_OR_EQUAL : RAZOR_VERSION_GREATER;
1.49 - else if (rel_str[0] == 'e' || rel_str[1] == 'q')
1.50 + if (rel_str[0] == 'L')
1.51 + return rel_str[1] == 'E' ? RAZOR_VERSION_LESS_OR_EQUAL : RAZOR_VERSION_LESS;
1.52 + else if (rel_str[0] == 'G')
1.53 + return rel_str[1] == 'E' ? RAZOR_VERSION_GREATER_OR_EQUAL : RAZOR_VERSION_GREATER;
1.54 + else if (rel_str[0] == 'E' || rel_str[1] == 'Q')
1.55 return RAZOR_VERSION_EQUAL;
1.56 else
1.57 return -1;
1.58 @@ -125,6 +131,10 @@
1.59 razor_set_destroy(ctx->result_set);
1.60 ctx->result_set = NULL;
1.61 }
1.62 + if (ctx->trans) {
1.63 + razor_transaction_destroy(ctx->trans);
1.64 + ctx->trans = NULL;
1.65 + }
1.66 }
1.67
1.68 static void
1.69 @@ -177,15 +187,43 @@
1.70 }
1.71
1.72 static void
1.73 +add_property(struct test_context *ctx, enum razor_property_type type, const char *name, enum razor_version_relation rel, const char *version)
1.74 +{
1.75 + razor_importer_add_property(ctx->importer, name,
1.76 + rel, version, type);
1.77 +}
1.78 +
1.79 +static void
1.80 +check_unsatisfiable_property(struct test_context *ctx, enum razor_property_type type, const char *name, enum razor_version_relation rel, const char *version)
1.81 +{
1.82 + if (!version)
1.83 + version = "";
1.84 +
1.85 + for (; ctx->unsat < ctx->trans->packages + ctx->trans->package_count; ctx->unsat++) {
1.86 + if (ctx->unsat->state != RAZOR_PACKAGE_INSTALL_UNSATISFIABLE)
1.87 + continue;
1.88 + if (strcmp(name, ctx->unsat->req_property) != 0 ||
1.89 + rel != ctx->unsat->req_relation ||
1.90 + strcmp(version, ctx->unsat->req_version) != 0)
1.91 + continue;
1.92 +
1.93 + /* OK, found it, so skip over it and continue */
1.94 + ctx->unsat++;
1.95 + return;
1.96 + }
1.97 +
1.98 + fprintf(stderr, " didn't get unsatisfiable '%s %s %s'\n",
1.99 + name, razor_version_relations[rel], version);
1.100 + exit(1);
1.101 +}
1.102 +
1.103 +static void
1.104 start_property(struct test_context *ctx, enum razor_property_type type, const char **atts)
1.105 {
1.106 const char *name = NULL, *rel_str = NULL, *version = NULL;
1.107 enum razor_version_relation rel;
1.108
1.109 - if (ctx->in_unsatisfiable)
1.110 - return;
1.111 -
1.112 - get_atts(atts, "name", &name, "rel", &rel_str, "version", &version, NULL);
1.113 + get_atts(atts, "name", &name, "relation", &rel_str, "version", &version, NULL);
1.114 if (name == NULL) {
1.115 fprintf(stderr, " no name specified for property\n");
1.116 exit(1);
1.117 @@ -199,8 +237,10 @@
1.118 } else
1.119 rel = RAZOR_VERSION_EQUAL;
1.120
1.121 - razor_importer_add_property(ctx->importer, name,
1.122 - rel, version, type);
1.123 + if (ctx->unsat)
1.124 + check_unsatisfiable_property(ctx, type, name, rel, version);
1.125 + else
1.126 + add_property(ctx, type, name, rel, version);
1.127 }
1.128
1.129 static void
1.130 @@ -213,22 +253,27 @@
1.131 static void
1.132 end_transaction(struct test_context *ctx)
1.133 {
1.134 - if (ctx->n_install_pkgs) {
1.135 - ctx->system_set = razor_set_update(ctx->system_set,
1.136 - ctx->repo_set,
1.137 - ctx->n_install_pkgs,
1.138 - (const char **)ctx->install_pkgs);
1.139 - }
1.140 - if (ctx->n_remove_pkgs && ctx->system_set) {
1.141 - ctx->system_set = razor_set_remove(ctx->system_set,
1.142 - ctx->n_remove_pkgs,
1.143 - (const char **)ctx->remove_pkgs);
1.144 + ctx->trans = razor_transaction_create(ctx->system_set, ctx->repo_set,
1.145 + ctx->n_install_pkgs,
1.146 + (const char **)ctx->install_pkgs,
1.147 + ctx->n_remove_pkgs,
1.148 + (const char **)ctx->remove_pkgs);
1.149 + if (ctx->debug) {
1.150 + razor_transaction_describe(ctx->trans);
1.151 + printf("\n");
1.152 }
1.153
1.154 while (ctx->n_install_pkgs--)
1.155 free(ctx->install_pkgs[ctx->n_install_pkgs]);
1.156 while (ctx->n_remove_pkgs--)
1.157 free(ctx->remove_pkgs[ctx->n_remove_pkgs]);
1.158 +
1.159 + if (!ctx->trans->errors) {
1.160 + struct razor_set *new;
1.161 + new = razor_transaction_run(ctx->trans);
1.162 + razor_set_destroy(ctx->system_set);
1.163 + ctx->system_set = new;
1.164 + }
1.165 }
1.166
1.167 static void
1.168 @@ -301,20 +346,18 @@
1.169 static void
1.170 start_unsatisfiable(struct test_context *ctx, const char **atts)
1.171 {
1.172 - if (ctx->system_set) {
1.173 + if (ctx->result_set) {
1.174 fprintf(stderr, "Expected to fail, but didn't\n");
1.175 exit(1);
1.176 }
1.177
1.178 - /* FIXME */
1.179 - fprintf(stderr, " Not actually checking <unsatisfiable>\n");
1.180 - ctx->in_unsatisfiable = 1;
1.181 + ctx->unsat = ctx->trans->packages;
1.182 }
1.183
1.184 static void
1.185 end_unsatisfiable(struct test_context *ctx)
1.186 {
1.187 - ctx->in_unsatisfiable = 0;
1.188 + ctx->unsat = NULL;
1.189 }
1.190
1.191 static void
1.192 @@ -379,14 +422,26 @@
1.193 int main(int argc, char *argv[])
1.194 {
1.195 struct test_context ctx;
1.196 + const char *test_file;
1.197
1.198 - if (argc != 2) {
1.199 - fprintf(stderr, "usage: %s TESTS-FILE\n", argv[0]);
1.200 + memset(&ctx, 0, sizeof ctx);
1.201 +
1.202 + if (argc > 3) {
1.203 + fprintf(stderr, "usage: %s [-d] [TESTS-FILE]\n", argv[0]);
1.204 exit(-1);
1.205 }
1.206
1.207 - memset(&ctx, 0, sizeof ctx);
1.208 - parse_xml_file(argv[1], start_test_element, end_test_element, &ctx);
1.209 + if (argc >= 2 && !strcmp (argv[1], "-d")) {
1.210 + ctx.debug = 1;
1.211 + argc--;
1.212 + argv++;
1.213 + }
1.214 + if (argc == 2)
1.215 + test_file = argv[1];
1.216 + else
1.217 + test_file = "test.xml";
1.218 +
1.219 + parse_xml_file(test_file, start_test_element, end_test_element, &ctx);
1.220
1.221 return 0;
1.222 }