Imported Upstream version 0.7.27
[platform/upstream/libsolv.git] / ext / testcase.c
index 8edf58f..f46f738 100644 (file)
 #include "ext/repo_helix.h"
 #endif
 
-#define DISABLE_JOIN2
-#include "tools_util.h"
+#ifdef _WIN32
+  #include <direct.h>
+#endif
+
+/* see repo_testcase.c */
+struct oplist {
+  Id flags;
+  const char *opname;
+};
+extern struct oplist oplist[];
+
 
 static struct job2str {
   Id job;
@@ -50,6 +59,8 @@ static struct job2str {
   { SOLVER_ALLOWUNINSTALL, "allowuninstall" },
   { SOLVER_FAVOR,          "favor" },
   { SOLVER_DISFAVOR,       "disfavor" },
+  { SOLVER_BLACKLIST,      "blacklist" },
+  { SOLVER_EXCLUDEFROMWEAK,   "excludefromweak" },
   { 0, 0 }
 };
 
@@ -88,6 +99,10 @@ static struct resultflags2str {
   { TESTCASE_RESULT_REASON,            "reason" },
   { TESTCASE_RESULT_CLEANDEPS,         "cleandeps" },
   { TESTCASE_RESULT_JOBS,              "jobs" },
+  { TESTCASE_RESULT_USERINSTALLED,     "userinstalled" },
+  { TESTCASE_RESULT_ORDER,             "order" },
+  { TESTCASE_RESULT_ORDEREDGES,                "orderedges" },
+  { TESTCASE_RESULT_PROOF,             "proof" },
   { 0, 0 }
 };
 
@@ -123,6 +138,7 @@ static struct solverflags2str {
   { SOLVER_FLAG_STRONG_RECOMMENDS,          "strongrecommends", 0 },
   { SOLVER_FLAG_INSTALL_ALSO_UPDATES,       "installalsoupdates", 0 },
   { SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, "onlynamespacerecommended", 0 },
+  { SOLVER_FLAG_STRICT_REPO_PRIORITY,       "strictrepopriority", 0 },
   { 0, 0, 0 }
 };
 
@@ -142,6 +158,7 @@ static struct poolflags2str {
   { POOL_FLAG_NOOBSOLETESMULTIVERSION,      "noobsoletesmultiversion", 0 },
   { POOL_FLAG_ADDFILEPROVIDESFILTERED,      "addfileprovidesfiltered", 0 },
   { POOL_FLAG_NOWHATPROVIDESAUX,            "nowhatprovidesaux", 0 },
+  { POOL_FLAG_WHATPROVIDESWITHDISABLED,     "whatprovideswithdisabled", 0 },
   { 0, 0, 0 }
 };
 
@@ -322,347 +339,6 @@ strqueue_diff(Strqueue *sq1, Strqueue *sq2, Strqueue *osq)
     strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
 }
 
-
-static const char *
-testcase_id2str(Pool *pool, Id id, int isname)
-{
-  const char *s = pool_id2str(pool, id);
-  const char *ss;
-  char *s2, *s2p;
-  int bad = 0, paren = 0, parenbad = 0;
-
-  if (id == 0)
-    return "<NULL>";
-  if (id == 1)
-    return "\\00";
-  if (strchr("[(<=>!", *s))
-    bad++;
-  if (!strncmp(s, "namespace:", 10))
-    bad++;
-  for (ss = s + bad; *ss; ss++)
-    {
-      if (*ss == ' ' || *ss == '\\' || *(unsigned char *)ss < 32 || *ss == '(' || *ss == ')')
-        bad++;
-      if (*ss == '(')
-       paren = paren == 0 ? 1 : -1;
-      else if (*ss == ')')
-       {
-         paren = paren == 1 ? 0 : -1;
-         if (!paren)
-           parenbad += 2;
-       }
-    }
-  if (isname && ss - s > 4 && !strcmp(ss - 4, ":any"))
-    bad++;
-  if (!paren && !(bad - parenbad))
-    return s;
-
-  /* we need escaping! */
-  s2 = s2p = pool_alloctmpspace(pool, strlen(s) + bad * 2 + 1);
-  if (!strncmp(s, "namespace:", 10))
-    {
-      strcpy(s2p, "namespace\\3a");
-      s2p += 12;
-      s += 10;
-    }
-  ss = s;
-  for (; *ss; ss++)
-    {
-      *s2p++ = *ss;
-      if ((ss == s && strchr("[(<=>!", *s)) || *ss == ' ' || *ss == '\\' || *(unsigned char *)ss < 32 || *ss == '(' || *ss == ')')
-       {
-         s2p[-1] = '\\';
-         solv_bin2hex((unsigned char *)ss, 1, s2p);
-         s2p += 2;
-       }
-    }
-  *s2p = 0;
-  if (isname && s2p - s2 > 4 && !strcmp(s2p - 4, ":any"))
-    strcpy(s2p - 4, "\\3aany");
-  return s2;
-}
-
-struct oplist {
-  Id flags;
-  const char *opname;
-} oplist[] = {
-  { REL_EQ, "=" },
-  { REL_GT | REL_LT | REL_EQ, "<=>" },
-  { REL_LT | REL_EQ, "<=" },
-  { REL_GT | REL_EQ, ">=" },
-  { REL_GT, ">" },
-  { REL_GT | REL_LT, "<>" },
-  { REL_AND,   "&" },
-  { REL_OR ,   "|" },
-  { REL_WITH , "+" },
-  { REL_WITHOUT , "-" },
-  { REL_NAMESPACE , "<NAMESPACE>" },
-  { REL_ARCH,       "." },
-  { REL_MULTIARCH,  "<MULTIARCH>" },
-  { REL_FILECONFLICT,  "<FILECONFLICT>" },
-  { REL_COND,  "<IF>" },
-  { REL_COMPAT,  "compat >=" },
-  { REL_KIND,  "<KIND>" },
-  { REL_ELSE, "<ELSE>" },
-  { REL_ERROR, "<ERROR>" },
-  { REL_UNLESS, "<UNLESS>" },
-  { REL_CONDA, "<CONDA>" },
-  { REL_LT, "<" },
-  { 0, 0 }
-};
-
-static char *
-testcase_dep2str_complex(Pool *pool, char *s, Id id, int addparens)
-{
-  Reldep *rd;
-  const char *s2;
-  int needparens;
-  struct oplist *op;
-
-  if (!ISRELDEP(id))
-    {
-      s2 = testcase_id2str(pool, id, 1);
-      s = pool_tmpappend(pool, s, s2, 0);
-      pool_freetmpspace(pool, s2);
-      return s;
-    }
-  rd = GETRELDEP(pool, id);
-
-  /* check for special shortcuts */
-  if (rd->flags == REL_NAMESPACE && !ISRELDEP(rd->name) && !strncmp(pool_id2str(pool, rd->name), "namespace:", 10))
-    {
-      s = pool_tmpappend(pool, s, pool_id2str(pool, rd->name), "(");
-      s = testcase_dep2str_complex(pool, s, rd->evr, 0);
-      return pool_tmpappend(pool, s, ")", 0);
-    }
-  if (rd->flags == REL_MULTIARCH && !ISRELDEP(rd->name) && rd->evr == ARCH_ANY)
-    {
-      /* append special :any suffix */
-      s2 = testcase_id2str(pool, rd->name, 1);
-      s = pool_tmpappend(pool, s, s2, ":any");
-      pool_freetmpspace(pool, s2);
-      return s;
-    }
-
-  needparens = 0;
-  if (ISRELDEP(rd->name))
-    {
-      Reldep *rd2 = GETRELDEP(pool, rd->name);
-      needparens = 1;
-      if (rd->flags > 7 && rd->flags != REL_COMPAT && rd2->flags && rd2->flags <= 7)
-       needparens = 0;
-    }
-
-  if (addparens)
-    s = pool_tmpappend(pool, s, "(", 0);
-  s = testcase_dep2str_complex(pool, s, rd->name, needparens);
-
-  for (op = oplist; op->flags; op++)
-    if (rd->flags == op->flags)
-      break;
-  if (op->flags)
-    {
-      s = pool_tmpappend(pool, s, " ", op->opname);
-      s = pool_tmpappend(pool, s, " ", 0);
-    }
-  else
-    {
-      char buf[64];
-      sprintf(buf, " <%u> ", rd->flags);
-      s = pool_tmpappend(pool, s, buf, 0);
-    }
-
-  needparens = 0;
-  if (ISRELDEP(rd->evr))
-    {
-      Reldep *rd2 = GETRELDEP(pool, rd->evr);
-      needparens = 1;
-      if (rd->flags > 7 && rd2->flags && rd2->flags <= 7)
-       needparens = 0;
-      if (rd->flags == REL_AND && rd2->flags == REL_AND)
-       needparens = 0; /* chain */
-      if (rd->flags == REL_OR && rd2->flags == REL_OR)
-       needparens = 0; /* chain */
-      if (rd->flags > 0 && rd->flags < 8 && rd2->flags == REL_COMPAT)
-       needparens = 0; /* chain */
-    }
-  if (!ISRELDEP(rd->evr))
-    {
-      s2 = testcase_id2str(pool, rd->evr, 0);
-      s = pool_tmpappend(pool, s, s2, 0);
-      pool_freetmpspace(pool, s2);
-    }
-  else
-    s = (char *)testcase_dep2str_complex(pool, s, rd->evr, needparens);
-  if (addparens)
-    s = pool_tmpappend(pool, s, ")", 0);
-  return s;
-}
-
-const char *
-testcase_dep2str(Pool *pool, Id id)
-{
-  char *s;
-  if (!ISRELDEP(id))
-    return testcase_id2str(pool, id, 1);
-  s = pool_alloctmpspace(pool, 1);
-  *s = 0;
-  return testcase_dep2str_complex(pool, s, id, 0);
-}
-
-
-/* Convert a simple string. Also handle the :any suffix */
-static Id
-testcase_str2dep_simple(Pool *pool, const char **sp, int isname)
-{
-  int haveesc = 0;
-  int paren = 0;
-  int isany = 0;
-  Id id;
-  const char *s;
-  for (s = *sp; *s; s++)
-    {
-      if (*s == '\\')
-       haveesc++;
-      if (*s == ' ' || *(unsigned char *)s < 32)
-       break;
-      if (*s == '(')
-       paren++;
-      if (*s == ')' && paren-- <= 0)
-       break;
-    }
-  if (isname && s - *sp > 4 && !strncmp(s - 4, ":any", 4))
-    {
-      isany = 1;
-      s -= 4;
-    }
-  if (!haveesc)
-    {
-      if (s - *sp == 6 && !strncmp(*sp, "<NULL>", 6))
-       id = 0;
-      else
-        id = pool_strn2id(pool, *sp, s - *sp, 1);
-    }
-  else if (s - *sp == 3 && !strncmp(*sp, "\\00", 3))
-    id = 1;
-  else
-    {
-      char buf[128], *bp, *bp2;
-      const char *sp2;
-      bp = s - *sp >= 128 ? solv_malloc(s - *sp + 1) : buf;
-      for (bp2 = bp, sp2 = *sp; sp2 < s;)
-       {
-         *bp2++ = *sp2++;
-         if (bp2[-1] == '\\')
-           solv_hex2bin(&sp2, (unsigned char *)bp2 - 1, 1);
-       }
-      *bp2 = 0;
-      id = pool_str2id(pool, bp, 1);
-      if (bp != buf)
-       solv_free(bp);
-    }
-  if (isany)
-    {
-      id = pool_rel2id(pool, id, ARCH_ANY, REL_MULTIARCH, 1);
-      s += 4;
-    }
-  *sp = s;
-  return id;
-}
-
-
-static Id
-testcase_str2dep_complex(Pool *pool, const char **sp, int relop)
-{
-  const char *s = *sp;
-  Id flags, id, id2, namespaceid = 0;
-  struct oplist *op;
-
-  if (!s)
-    return 0;
-  while (*s == ' ' || *s == '\t')
-    s++;
-  if (!strncmp(s, "namespace:", 10))
-    {
-      /* special namespace hack */
-      const char *s2;
-      for (s2 = s + 10; *s2 && *s2 != '('; s2++)
-       ;
-      if (*s2 == '(')
-       {
-         namespaceid = pool_strn2id(pool, s, s2 - s, 1);
-         s = s2;
-       }
-    }
-  if (*s == '(')
-    {
-      s++;
-      id = testcase_str2dep_complex(pool, &s, 0);
-      if (!s || *s != ')')
-       {
-         *sp = 0;
-         return 0;
-       }
-      s++;
-    }
-  else
-    id = testcase_str2dep_simple(pool, &s, relop ? 0 : 1);
-  if (namespaceid)
-    id = pool_rel2id(pool, namespaceid, id, REL_NAMESPACE, 1);
-    
-  for (;;)
-    {
-      while (*s == ' ' || *s == '\t')
-       s++;
-      if (!*s || *s == ')' || (relop && strncmp(s, "compat >= ", 10) != 0))
-       {
-         *sp = s;
-         return id;
-       }
-
-      /* we have an op! Find the end */
-      flags = -1;
-      if (s[0] == '<' && (s[1] >= '0' && s[1] <= '9'))
-       {
-         const char *s2;
-         for (s2 = s + 1; *s2 >= '0' && *s2 <= '9'; s2++)
-           ;
-         if (*s2 == '>')
-           {
-             flags = strtoul(s + 1, 0, 10);
-             s = s2 + 1;
-           }
-       }
-      if (flags == -1)
-       {
-         for (op = oplist; op->flags; op++)
-           if (!strncmp(s, op->opname, strlen(op->opname)))
-             break;
-         if (!op->flags)
-           {
-             *sp = 0;
-             return 0;
-           }
-         flags = op->flags;
-         s += strlen(op->opname);
-       }
-      id2 = testcase_str2dep_complex(pool, &s, flags > 0 && flags < 8);
-      if (!s)
-       {
-         *sp = 0;
-         return 0;
-       }
-      id = pool_rel2id(pool, id, id2, flags, 1);
-    }
-}
-
-Id
-testcase_str2dep(Pool *pool, const char *s)
-{
-  Id id = testcase_str2dep_complex(pool, &s, 0);
-  return s && !*s ? id : 0;
-}
-
 /**********************************************************/
 
 const char *
@@ -699,17 +375,30 @@ testcase_solvid2str(Pool *pool, Id p)
   e = pool_id2str(pool, s->evr);
   a = pool_id2str(pool, s->arch);
   str = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3);
-  sprintf(str, "%s-%s.%s", n, e, a);
+  sprintf(str, "%s-%s", n, e);
+  if (solvable_lookup_type(s, SOLVABLE_BUILDFLAVOR))
+    {
+      Queue flavorq;
+      int i;
+
+      queue_init(&flavorq);
+      solvable_lookup_idarray(s, SOLVABLE_BUILDFLAVOR, &flavorq);
+      for (i = 0; i < flavorq.count; i++)
+       str = pool_tmpappend(pool, str, "-", pool_id2str(pool, flavorq.elements[i]));
+      queue_free(&flavorq);
+    }
+  if (s->arch)
+    str = pool_tmpappend(pool, str, ".", a);
   if (!s->repo)
     return pool_tmpappend(pool, str, "@", 0);
   if (s->repo->name)
     {
       int l = strlen(str);
-      char *str2 = pool_tmpappend(pool, str, "@", s->repo->name);
-      for (; str2[l]; l++)
-       if (str2[l] == ' ' || str2[l] == '\t')
-         str2[l] = '_';
-      return str2;
+      str = pool_tmpappend(pool, str, "@", s->repo->name);
+      for (; str[l]; l++)
+       if (str[l] == ' ' || str[l] == '\t')
+         str[l] = '_';
+      return str;
     }
   sprintf(buf, "@#%d", s->repo->repoid);
   return pool_tmpappend(pool, str, buf, 0);
@@ -754,6 +443,86 @@ testcase_str2repo(Pool *pool, const char *str)
   return repo;
 }
 
+static const char *
+testcase_escape(Pool *pool, const char *str)
+{
+  size_t nbad = 0;
+  const char *p;
+  char *new, *np;
+  for (p = str; *p; p++)
+    if (*p == '\\' || *p == ' ' || *p == '\t')
+      nbad++;
+  if (!nbad)
+    return str;
+  new = pool_alloctmpspace(pool, strlen(str) + 1 + nbad * 2);
+  for (np = new, p = str; *p; p++)
+    {
+      *np++ = *p;
+      if (*p == '\\' || *p == ' ' || *p == '\t')
+       {
+         np[-1] = '\\';
+         solv_bin2hex((unsigned char *)p, 1, np);
+         np += 2;
+       }
+    }
+  *np = 0;
+  return new;
+}
+
+static void
+testcase_unescape_inplace(char *str)
+{
+  char *p, *q;
+  for (p = q = str; *p;)
+    {
+      *q++ = *p++;
+      if (p[-1] == '\\')
+       solv_hex2bin((const char **)&p, (unsigned char *)q - 1, 1);
+    }
+  *q = 0;
+}
+
+/* check evr and buildflavors */
+static int
+str2solvid_check(Pool *pool, Solvable *s, const char *start, const char *end, Id evrid)
+{
+  if (!solvable_lookup_type(s, SOLVABLE_BUILDFLAVOR))
+    {
+      /* just check the evr */
+      return evrid && s->evr == evrid;
+    }
+  else
+    {
+      Queue flavorq;
+      int i;
+
+      queue_init(&flavorq);
+      solvable_lookup_idarray(s, SOLVABLE_BUILDFLAVOR, &flavorq);
+      queue_unshift(&flavorq, s->evr);
+      for (i = 0; i < flavorq.count; i++)
+       {
+         const char *part = pool_id2str(pool, flavorq.elements[i]);
+         size_t partl = strlen(part);
+         if (start + partl > end || strncmp(start, part, partl) != 0)
+           break;
+         start += partl;
+         if (i + 1 < flavorq.count)
+           {
+             if (start >= end || *start != '-')
+               break;
+             start++;
+           }
+       }
+      if (i < flavorq.count)
+       {
+         queue_free(&flavorq);
+         return 0;
+       }
+      queue_free(&flavorq);
+      return start == end;
+    }
+}
+
 Id
 testcase_str2solvid(Pool *pool, const char *str)
 {
@@ -793,19 +562,18 @@ testcase_str2solvid(Pool *pool, const char *str)
          if (!nid)
            continue;
          evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
-         if (!evrid)
-           continue;
          /* first check whatprovides */
          FOR_PROVIDES(p, pp, nid)
            {
              Solvable *s = pool->solvables + p;
-             if (s->name != nid || s->evr != evrid)
+             if (s->name != nid)
                continue;
              if (repo && s->repo != repo)
                continue;
              if (arch && s->arch != arch)
                continue;
-             return p;
+             if (str2solvid_check(pool, s, str + i + 1, str + repostart, evrid))
+               return p;
            }
          /* maybe it's not installable and thus not in whatprovides. do a slow search */
          if (repo)
@@ -813,11 +581,12 @@ testcase_str2solvid(Pool *pool, const char *str)
              Solvable *s;
              FOR_REPO_SOLVABLES(repo, p, s)
                {
-                 if (s->name != nid || s->evr != evrid)
+                 if (s->name != nid)
                    continue;
                  if (arch && s->arch != arch)
                    continue;
-                 return p;
+                 if (str2solvid_check(pool, s, str + i + 1, str + repostart, evrid))
+                   return p;
                }
            }
          else
@@ -825,11 +594,12 @@ testcase_str2solvid(Pool *pool, const char *str)
              FOR_POOL_SOLVABLES(p)
                {
                  Solvable *s = pool->solvables + p;
-                 if (s->name != nid || s->evr != evrid)
+                 if (s->name != nid)
                    continue;
                  if (arch && s->arch != arch)
                    continue;
-                 return p;
+                 if (str2solvid_check(pool, s, str + i + 1, str + repostart, evrid))
+                   return p;
                }
            }
        }
@@ -1180,347 +950,6 @@ addselectionjob(Pool *pool, char **pieces, int npieces, Queue *jobqueue, int typ
   return r;
 }
 
-static void
-writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
-{
-  Pool *pool = repo->pool;
-  Id id, *dp;
-  int tagwritten = 0;
-  const char *idstr;
-
-  if (!off)
-    return;
-  dp = repo->idarraydata + off;
-  while ((id = *dp++) != 0)
-    {
-      if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER)
-       {
-         if (tagwritten)
-           fprintf(fp, "-%s\n", tag);
-         tagwritten = 0;
-         tag = "Prq:";
-         continue;
-       }
-      if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER)
-       continue;
-      idstr = testcase_dep2str(pool, id);
-      if (!tagwritten)
-       {
-         fprintf(fp, "+%s\n", tag);
-         tagwritten = 1;
-       }
-      fprintf(fp, "%s\n", idstr);
-    }
-  if (tagwritten)
-    fprintf(fp, "-%s\n", tag);
-}
-
-static void
-writefilelist(Repo *repo, FILE *fp, const char *tag, Solvable *s)
-{
-  Pool *pool = repo->pool;
-  int tagwritten = 0;
-  Dataiterator di;
-
-  dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0);
-  while (dataiterator_step(&di))
-    {
-      const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str);
-      if (!tagwritten)
-       {
-         fprintf(fp, "+%s\n", tag);
-         tagwritten = 1;
-       }
-      fprintf(fp, "%s\n", s);
-    }
-  if (tagwritten)
-    fprintf(fp, "-%s\n", tag);
-  dataiterator_free(&di);
-}
-
-int
-testcase_write_testtags(Repo *repo, FILE *fp)
-{
-  Pool *pool = repo->pool;
-  Solvable *s;
-  Id p;
-  const char *name;
-  const char *evr;
-  const char *arch;
-  const char *release;
-  const char *tmp;
-  unsigned int ti;
-  Queue q;
-
-  fprintf(fp, "=Ver: 3.0\n");
-  queue_init(&q);
-  FOR_REPO_SOLVABLES(repo, p, s)
-    {
-      name = pool_id2str(pool, s->name);
-      evr = pool_id2str(pool, s->evr);
-      arch = pool_id2str(pool, s->arch);
-      release = strrchr(evr, '-');
-      if (!release)
-       release = evr + strlen(evr);
-      fprintf(fp, "=Pkg: %s %.*s %s %s\n", name, (int)(release - evr), evr, *release && release[1] ? release + 1 : "-", arch);
-      tmp = solvable_lookup_str(s, SOLVABLE_SUMMARY);
-      if (tmp)
-        fprintf(fp, "=Sum: %s\n", tmp);
-      writedeps(repo, fp, "Req:", SOLVABLE_REQUIRES, s, s->requires);
-      writedeps(repo, fp, "Prv:", SOLVABLE_PROVIDES, s, s->provides);
-      writedeps(repo, fp, "Obs:", SOLVABLE_OBSOLETES, s, s->obsoletes);
-      writedeps(repo, fp, "Con:", SOLVABLE_CONFLICTS, s, s->conflicts);
-      writedeps(repo, fp, "Rec:", SOLVABLE_RECOMMENDS, s, s->recommends);
-      writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements);
-      writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests);
-      writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances);
-      if (solvable_lookup_idarray(s, SOLVABLE_PREREQ_IGNOREINST, &q))
-       {
-         int i;
-         fprintf(fp, "+Ipr:\n");
-         for (i = 0; i < q.count; i++)
-           fprintf(fp, "%s\n", testcase_dep2str(pool, q.elements[i]));
-         fprintf(fp, "-Ipr:\n");
-       }
-      if (s->vendor)
-       fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
-      ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
-      if (ti)
-       fprintf(fp, "=Tim: %u\n", ti);
-      writefilelist(repo, fp, "Fls:", s);
-    }
-  queue_free(&q);
-  return 0;
-}
-
-static inline Offset
-adddep(Repo *repo, Offset olddeps, char *str, Id marker)
-{
-  Id id = *str == '/' ? pool_str2id(repo->pool, str, 1) : testcase_str2dep(repo->pool, str);
-  return repo_addid_dep(repo, olddeps, id, marker);
-}
-
-static void
-finish_v2_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist)
-{
-  if (nfilelist)
-    {
-      int l;
-      Id did;
-      for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
-       {
-         char *p = strrchr(filelist + l, '/');
-         if (!p)
-           continue;
-         *p++ = 0;
-         did = repodata_str2dir(data, filelist + l, 1);
-         p[-1] = '/';
-         if (!did)
-           did = repodata_str2dir(data, "/", 1);
-         repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
-       }
-    }
-  repo_rewrite_suse_deps(s, 0);
-}
-
-/* stripped down version of susetags parser used for testcases */
-int
-testcase_add_testtags(Repo *repo, FILE *fp, int flags)
-{
-  Pool *pool = repo->pool;
-  char *line, *linep;
-  int aline;
-  int tag;
-  Repodata *data;
-  Solvable *s;
-  char *sp[5];
-  unsigned int t;
-  int intag;
-  char *filelist = 0;
-  int afilelist = 0;
-  int nfilelist = 0;
-  int tagsversion = 0;
-  int addselfprovides = 1;     /* for compat reasons */
-
-  data = repo_add_repodata(repo, flags);
-  s = 0;
-  intag = 0;
-
-  aline = 1024;
-  line = solv_malloc(aline);
-  linep = line;
-  for (;;)
-    {
-      if (linep - line + 16 > aline)
-       {
-         aline = linep - line;
-         line = solv_realloc(line, aline + 512);
-         linep = line + aline;
-         aline += 512;
-       }
-      if (!fgets(linep, aline - (linep - line), fp))
-       break;
-      linep += strlen(linep);
-      if (linep == line || linep[-1] != '\n')
-       continue;
-      linep[-1] = 0;
-      linep = line + intag;
-      if (intag)
-       {
-         if (line[intag] == '-' && !strncmp(line + 1, line + intag + 1, intag - 2))
-           {
-             intag = 0;
-             linep = line;
-             continue;
-           }
-       }
-      else if (line[0] == '+' && line[1] && line[1] != ':')
-       {
-         char *tagend = strchr(line, ':');
-         if (!tagend)
-           continue;
-         line[0] = '=';
-         tagend[1] = ' ';
-         intag = tagend + 2 - line;
-         linep = line + intag;
-         continue;
-       }
-      if (*line != '=' || !line[1] || !line[2] || !line[3] || line[4] != ':')
-       continue;
-      tag = line[1] << 16 | line[2] << 8 | line[3];
-      /* tags that do not need a solvable */
-      switch(tag)
-       {
-       case 'V' << 16 | 'e' << 8 | 'r':
-         tagsversion = atoi(line + 6);
-         addselfprovides = tagsversion < 3 || strstr(line + 6, "addselfprovides") != 0;
-         continue;
-       case 'P' << 16 | 'k' << 8 | 'g':
-         if (s)
-           {
-             if (tagsversion == 2)
-               finish_v2_solvable(pool, data, s, filelist, nfilelist);
-             if (addselfprovides && s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
-               s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
-           }
-         nfilelist = 0;
-         if (split(line + 5, sp, 5) != 4)
-           break;
-         s = pool_id2solvable(pool, repo_add_solvable(repo));
-         s->name = pool_str2id(pool, sp[0], 1);
-         /* join back version and release */
-         if (sp[2] && !(sp[2][0] == '-' && !sp[2][1]))
-           sp[2][-1] = '-';
-         s->evr = makeevr(pool, sp[1]);
-         s->arch = pool_str2id(pool, sp[3], 1);
-         continue;
-       default:
-         break;
-       }
-      if (!s)
-       continue;
-      /* tags that need a solvable */
-      switch(tag)
-       {
-       case 'S' << 16 | 'u' << 8 | 'm':
-         repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, line + 6);
-         break;
-       case 'V' << 16 | 'n' << 8 | 'd':
-         s->vendor = pool_str2id(pool, line + 6, 1);
-         break;
-       case 'T' << 16 | 'i' << 8 | 'm':
-         t = atoi(line + 6);
-         if (t)
-           repodata_set_num(data, s - pool->solvables, SOLVABLE_BUILDTIME, t);
-         break;
-       case 'R' << 16 | 'e' << 8 | 'q':
-         s->requires = adddep(repo, s->requires, line + 6, -SOLVABLE_PREREQMARKER);
-         break;
-       case 'P' << 16 | 'r' << 8 | 'q':
-         s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER);
-         break;
-       case 'P' << 16 | 'r' << 8 | 'v':
-         /* version 2 had the file list at the end of the provides */
-         if (tagsversion == 2)
-           {
-             if (line[6] == '/')
-               {
-                 int l = strlen(line + 6) + 1;
-                 if (nfilelist + l > afilelist)
-                   {
-                     afilelist = nfilelist + l + 512;
-                     filelist = solv_realloc(filelist, afilelist);
-                   }
-                 memcpy(filelist + nfilelist, line + 6, l);
-                 nfilelist += l;
-                 break;
-               }
-             if (nfilelist)
-               {
-                 int l;
-                 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
-                   s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0);
-                 nfilelist = 0;
-               }
-           }
-         s->provides = adddep(repo, s->provides, line + 6, 0);
-         break;
-       case 'F' << 16 | 'l' << 8 | 's':
-         {
-           char *p = strrchr(line + 6, '/');
-           Id did;
-           if (!p)
-             break;
-           *p++ = 0;
-           did = repodata_str2dir(data, line + 6, 1);
-           if (!did)
-             did = repodata_str2dir(data, "/", 1);
-           repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
-           break;
-         }
-       case 'O' << 16 | 'b' << 8 | 's':
-         s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0);
-         break;
-       case 'C' << 16 | 'o' << 8 | 'n':
-         s->conflicts = adddep(repo, s->conflicts, line + 6, 0);
-         break;
-       case 'R' << 16 | 'e' << 8 | 'c':
-         s->recommends = adddep(repo, s->recommends, line + 6, 0);
-         break;
-       case 'S' << 16 | 'u' << 8 | 'p':
-         s->supplements = adddep(repo, s->supplements, line + 6, 0);
-         break;
-       case 'S' << 16 | 'u' << 8 | 'g':
-         s->suggests = adddep(repo, s->suggests, line + 6, 0);
-         break;
-       case 'E' << 16 | 'n' << 8 | 'h':
-         s->enhances = adddep(repo, s->enhances, line + 6, 0);
-         break;
-       case 'I' << 16 | 'p' << 8 | 'r':
-         {
-           Id id = line[6] == '/' ? pool_str2id(pool, line + 6, 1) : testcase_str2dep(pool, line + 6);
-           repodata_add_idarray(data, s - pool->solvables, SOLVABLE_PREREQ_IGNOREINST, id);
-           break;
-         }
-        default:
-         break;
-        }
-    }
-  if (s)
-    {
-      if (tagsversion == 2)
-       finish_v2_solvable(pool, data, s, filelist, nfilelist);
-      if (addselfprovides && s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
-        s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
-    }
-  solv_free(line);
-  solv_free(filelist);
-  repodata_free_dircache(data);
-  if (!(flags & REPO_NO_INTERNALIZE))
-    repodata_internalize(data);
-  return 0;
-}
-
 const char *
 testcase_getpoolflags(Pool *pool)
 {
@@ -1806,7 +1235,9 @@ static struct rclass2str {
   { SOLVER_RULE_LEARNT, "learnt" },
   { SOLVER_RULE_BEST, "best" },
   { SOLVER_RULE_YUMOBS, "yumobs" },
+  { SOLVER_RULE_BLACK, "black" },
   { SOLVER_RULE_RECOMMENDS, "recommends" },
+  { SOLVER_RULE_STRICT_REPO_PRIORITY, "strictrepoprio" },
   { 0, 0 }
 };
 
@@ -1929,6 +1360,82 @@ testcase_solverresult(Solver *solv, int resultflags)
        }
     }
 
+  if ((resultflags & TESTCASE_RESULT_PROOF) != 0)
+    {
+      char *probprefix;
+      int pcnt, problem;
+      Queue q, lq;
+
+      queue_init(&q);
+      queue_init(&lq);
+      pcnt = solver_problem_count(solv);
+      for (problem = 1; problem <= pcnt + lq.count; problem++)
+       {
+         if (problem <= pcnt)
+           {
+             s = testcase_problemid(solv, problem);
+             solver_get_decisionlist(solv, problem, SOLVER_DECISIONLIST_PROBLEM, &q);
+           }
+         else
+           {
+             s = testcase_ruleid(solv, lq.elements[problem - pcnt - 1]);
+             solver_get_decisionlist(solv, lq.elements[problem - pcnt - 1], SOLVER_DECISIONLIST_LEARNTRULE, &q);
+           }
+         probprefix = solv_dupjoin("proof ", s, 0);
+         for (i = 0; i < q.count; i += 3)
+           {
+             SolverRuleinfo rclass;
+             Queue rq;
+             Id truelit = q.elements[i];
+             Id rid = q.elements[i + 2];
+             char *rprefix;
+             char nbuf[16];
+
+             rclass = solver_ruleclass(solv, rid);
+             if (rclass == SOLVER_RULE_LEARNT)
+               queue_pushunique(&lq, rid);
+             queue_init(&rq);
+             solver_ruleliterals(solv, rid, &rq);
+             sprintf(nbuf, "%3d", i / 3);
+             rprefix = solv_dupjoin(probprefix, " ", nbuf);
+             if (q.elements[i + 1] == SOLVER_REASON_PREMISE)
+               {
+                 rprefix = solv_dupappend(rprefix, " premise", 0);
+                 queue_empty(&rq);
+                 queue_push(&rq, truelit);
+               }
+             else
+               {
+                 rprefix = solv_dupappend(rprefix, " ", testcase_rclass2str(rclass));
+                 rprefix = solv_dupappend(rprefix, " ", testcase_ruleid(solv, rid));
+               }
+             strqueue_push(&sq, rprefix);
+             solv_free(rprefix);
+             rprefix = solv_dupjoin(probprefix, " ", nbuf);
+             rprefix = solv_dupappend(rprefix, ": ", 0);
+             for (j = 0; j < rq.count; j++)
+               {
+                 const char *s;
+                 Id p = rq.elements[j];
+                 if (p == truelit)
+                   s = pool_tmpjoin(pool, rprefix, "-->", 0);
+                 else
+                   s = pool_tmpjoin(pool, rprefix, "   ", 0);
+                 if (p < 0)
+                   s = pool_tmpappend(pool, s, " -", testcase_solvid2str(pool, -p));
+                 else
+                   s = pool_tmpappend(pool, s, "  ", testcase_solvid2str(pool, p));
+                 strqueue_push(&sq, s);
+               }
+             solv_free(rprefix);
+             queue_free(&rq);
+           }
+         solv_free(probprefix);
+       }
+      queue_free(&q);
+      queue_free(&lq);
+    }
+
   if ((resultflags & TESTCASE_RESULT_ORPHANED) != 0)
     {
       Queue q;
@@ -1987,54 +1494,84 @@ testcase_solverresult(Solver *solv, int resultflags)
       queue_free(&q);
       queue_free(&qf);
     }
+  if ((resultflags & TESTCASE_RESULT_USERINSTALLED) != 0)
+    {
+      Queue q;
+      solver_get_userinstalled(solv, &q, 0);
+      for (i = 0; i < q.count; i++)
+       {
+         s = pool_tmpjoin(pool, "userinstalled pkg ", testcase_solvid2str(pool, q.elements[i]), 0);
+         strqueue_push(&sq, s);
+       }
+      queue_empty(&q);
+      solver_get_userinstalled(solv, &q, GET_USERINSTALLED_NAMES | GET_USERINSTALLED_INVERTED);
+      for (i = 0; i < q.count; i++)
+       {
+         s = pool_tmpjoin(pool, "autoinst name ", pool_id2str(pool, q.elements[i]), 0);
+         strqueue_push(&sq, s);
+       }
+      queue_free(&q);
+    }
+  if ((resultflags & TESTCASE_RESULT_ORDER) != 0)
+    {
+      int i;
+      char buf[256];
+      Id p;
+      Transaction *trans = solver_create_transaction(solv);
+      transaction_order(trans, 0);
+      for (i = 0; i < trans->steps.count; i++)
+       {
+         p = trans->steps.elements[i];
+         if (pool->installed && pool->solvables[p].repo == pool->installed)
+           sprintf(buf, "%4d erase ", i + 1);
+         else
+           sprintf(buf, "%4d install ", i + 1);
+         s = pool_tmpjoin(pool, "order ", buf, testcase_solvid2str(pool, p));
+         strqueue_push(&sq, s);
+       }
+      transaction_free(trans);
+    }
+  if ((resultflags & TESTCASE_RESULT_ORDEREDGES) != 0)
+    {
+      Queue q;
+      int i, j;
+      Id p, p2;
+      Transaction *trans = solver_create_transaction(solv);
+      transaction_order(trans, SOLVER_TRANSACTION_KEEP_ORDEREDGES);
+      queue_init(&q);
+      for (i = 0; i < trans->steps.count; i++)
+       {
+         p = trans->steps.elements[i];
+         transaction_order_get_edges(trans, p, &q, 1);
+         for (j = 0; j < q.count; j += 2)
+           {
+             char typebuf[32], *s;
+             p2 = q.elements[j];
+             sprintf(typebuf, " -%x-> ", q.elements[j + 1]);
+             s = pool_tmpjoin(pool, "orderedge ", testcase_solvid2str(pool, p), typebuf);
+             s = pool_tmpappend(pool, s, testcase_solvid2str(pool, p2), 0);
+             strqueue_push(&sq, s);
+           }
+       }
+      queue_free(&q);
+      transaction_free(trans);
+    }
   if ((resultflags & TESTCASE_RESULT_ALTERNATIVES) != 0)
     {
-      char *altprefix;
-      Queue q, rq;
+      Queue q;
       int cnt;
       Id alternative;
       queue_init(&q);
-      queue_init(&rq);
       cnt = solver_alternatives_count(solv);
       for (alternative = 1; alternative <= cnt; alternative++)
        {
          Id id, from, chosen;
-         char num[20];
+         char num[20], *s;
          int type = solver_get_alternative(solv, alternative, &id, &from, &chosen, &q, 0);
-         altprefix = solv_dupjoin("alternative ", testcase_alternativeid(solv, type, id, from), " ");
+         char *altprefix = solv_dupjoin("alternative ", testcase_alternativeid(solv, type, id, from), " ");
          strcpy(num, " 0 ");
-         if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS)
-           {
-             char *s = pool_tmpjoin(pool, altprefix, num, testcase_solvid2str(pool, from));
-             s = pool_tmpappend(pool, s, " recommends ", testcase_dep2str(pool, id));
-             strqueue_push(&sq, s);
-           }
-         else if (type == SOLVER_ALTERNATIVE_TYPE_RULE)
-           {
-             /* map choice rules back to pkg rules */
-             if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
-               id = solver_rule2pkgrule(solv, id);
-             if (solver_ruleclass(solv, id) == SOLVER_RULE_RECOMMENDS)
-               id = solver_rule2pkgrule(solv, id);
-             solver_allruleinfos(solv, id, &rq);
-             for (i = 0; i < rq.count; i += 4)
-               {
-                 int rtype = rq.elements[i];
-                 if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB)
-                   {
-                     const char *js = testcase_job2str(pool, rq.elements[i + 2], rq.elements[i + 3]);
-                     char *s = pool_tmpjoin(pool, altprefix, num, " job ");
-                     s = pool_tmpappend(pool, s, js, 0);
-                     strqueue_push(&sq, s);
-                   }
-                 else if (rtype == SOLVER_RULE_PKG_REQUIRES)
-                   {
-                     char *s = pool_tmpjoin(pool, altprefix, num, testcase_solvid2str(pool, rq.elements[i + 1]));
-                     s = pool_tmpappend(pool, s, " requires ", testcase_dep2str(pool, rq.elements[i + 3]));
-                     strqueue_push(&sq, s);
-                   }
-               }
-           }
+          s = pool_tmpjoin(pool, altprefix, num, solver_alternative2str(solv, type, id, from));
+         strqueue_push(&sq, s);
          for (i = 0; i < q.count; i++)
            {
              Id p = q.elements[i];
@@ -2053,7 +1590,6 @@ testcase_solverresult(Solver *solv, int resultflags)
          solv_free(altprefix);
        }
       queue_free(&q);
-      queue_free(&rq);
     }
   if ((resultflags & TESTCASE_RESULT_RULES) != 0)
     {
@@ -2062,15 +1598,16 @@ testcase_solverresult(Solver *solv, int resultflags)
       SolverRuleinfo rclass;
       Queue q;
       int i;
+      char *prefix;
 
       queue_init(&q);
       for (rid = 1; (rclass = solver_ruleclass(solv, rid)) != SOLVER_RULE_UNKNOWN; rid++)
        {
-         char *prefix = solv_dupjoin("rule ", testcase_rclass2str(rclass), " ");
-         prefix = solv_dupappend(prefix, testcase_ruleid(solv, rid), 0);
          solver_ruleliterals(solv, rid, &q);
          if (rclass == SOLVER_RULE_FEATURE && q.count == 1 && q.elements[0] == -SYSTEMSOLVABLE)
            continue;
+         prefix = solv_dupjoin("rule ", testcase_rclass2str(rclass), " ");
+         prefix = solv_dupappend(prefix, testcase_ruleid(solv, rid), 0);
          for (i = 0; i < q.count; i++)
            {
              Id p = q.elements[i];
@@ -2169,6 +1706,43 @@ testcase_solverresult(Solver *solv, int resultflags)
   return result;
 }
 
+static void
+dump_custom_vendorcheck(Pool *pool, Strqueue *sq, int (*vendorcheck)(Pool *, Solvable *, Solvable *))
+{
+  Id p, lastvendor = 0;
+  Queue vq;
+  int i, j;
+  char *cmd;
+
+  queue_init(&vq);
+  FOR_POOL_SOLVABLES(p)
+    {
+      Id vendor = pool->solvables[p].vendor;
+      if (!vendor || vendor == lastvendor)
+       continue;
+      lastvendor = vendor;
+      for (i = 0; i < vq.count; i += 2)
+       if (vq.elements[i] == vendor)
+         break;
+      if (i == vq.count)
+        queue_push2(&vq, vendor, p);
+    }
+  for (i = 0; i < vq.count; i += 2)
+    {
+      Solvable *s1 = pool->solvables + vq.elements[i + 1];
+      for (j = i + 2; j < vq.count; j += 2)
+       {
+         Solvable *s2 = pool->solvables + vq.elements[j + 1];
+         if (vendorcheck(pool, s1, s2) || vendorcheck(pool, s2, s1))
+           continue;
+         cmd = pool_tmpjoin(pool, "vendorclass", 0, 0);
+         cmd = pool_tmpappend(pool, cmd, " ", testcase_escape(pool, pool_id2str(pool, vq.elements[i])));
+         cmd = pool_tmpappend(pool, cmd, " ", testcase_escape(pool, pool_id2str(pool, vq.elements[j])));
+         strqueue_push(sq, cmd);
+       }
+    }
+  queue_free(&vq);
+}
 
 static int
 testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const char *testcasename, const char *resultname)
@@ -2182,13 +1756,18 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
   Strqueue sq;
   char *cmd, *out, *result;
   const char *s;
+  int (*vendorcheck)(Pool *, Solvable *, Solvable *);
 
   if (!testcasename)
     testcasename = "testcase.t";
   if (!resultname)
     resultname = "solver.result";
 
+#ifdef _WIN32
+  if (mkdir(dir) && errno != EEXIST)
+#else
   if (mkdir(dir, 0777) && errno != EEXIST)
+#endif
     return pool_error(solv->pool, 0, "testcase_write: could not create directory '%s'", dir);
   strqueue_init(&sq);
   FOR_REPOS(repoid, repo)
@@ -2199,7 +1778,11 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
        sprintf(priobuf, "%d.%d", repo->priority, repo->subpriority);
       else
        sprintf(priobuf, "%d", repo->priority);
+#if !defined(WITHOUT_COOKIEOPEN) && defined(ENABLE_ZLIB_COMPRESSION)
       out = pool_tmpjoin(pool, name, ".repo", ".gz");
+#else
+      out = pool_tmpjoin(pool, name, ".repo", 0);
+#endif
       for (i = 0; out[i]; i++)
        if (out[i] == '/')
          out[i] = '_';
@@ -2235,7 +1818,7 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
          lowscore = pool->id2arch[i];
        }
     }
-  cmd = pool_tmpjoin(pool, "system ", pool->lastarch ? pool_id2str(pool, arch) : "unset", 0);
+  cmd = pool_tmpjoin(pool, "system ", pool->lastarch ? pool_id2str(pool, arch) : "-", 0);
   for (i = 0; disttype2str[i].str != 0; i++)
     if (pool->disttype == disttype2str[i].type)
       break;
@@ -2250,12 +1833,15 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
       strqueue_push(&sq, cmd);
     }
 
-  if (pool->vendorclasses)
+  vendorcheck = pool_get_custom_vendorcheck(pool);
+  if (vendorcheck)
+    dump_custom_vendorcheck(pool, &sq, vendorcheck);
+  else if (pool->vendorclasses)
     {
       cmd = 0;
       for (i = 0; pool->vendorclasses[i]; i++)
        {
-         cmd = pool_tmpappend(pool, cmd ? cmd : "vendorclass", " ", pool->vendorclasses[i]);
+         cmd = pool_tmpappend(pool, cmd ? cmd : "vendorclass", " ", testcase_escape(pool, pool->vendorclasses[i]));
          if (!pool->vendorclasses[i + 1])
            {
              strqueue_push(&sq, cmd);
@@ -2292,7 +1878,7 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
       for (rid = 1; rid < pool->nrels; rid++)
        {
          Reldep *rd = pool->rels + rid;
-         if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
+         if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS || rd->name == NAMESPACE_SPLITPROVIDES)
            continue;
          /* evaluate all namespace ids, skip empty results */
          d = pool_whatprovides(pool, MAKERELDEP(rid));
@@ -2390,49 +1976,63 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
   return 1;
 }
 
-int
-testcase_write(Solver *solv, const char *dir, int resultflags, const char *testcasename, const char *resultname)
+const char **
+testcase_mangle_repo_names(Pool *pool)
 {
-  Pool *pool = solv->pool;
-  int i, r, repoid;
-  int mangle = 1;
-  const char **orignames;
-
-  /* mangle repo names so that there are no conflicts */
-  orignames = solv_calloc(pool->nrepos, sizeof(char *));
-  for (repoid = 1; repoid < pool->nrepos; repoid++)
+  int i, repoid, mangle = 1;
+  Repo *repo;
+  const char **names = solv_calloc(pool->nrepos, sizeof(char *));
+  FOR_REPOS(repoid, repo)
     {
-      Repo *repo = pool_id2repo(pool, repoid);
-      char *buf = solv_malloc((repo->name ? strlen(repo->name) : 0) + 40);
-      char *mp;
-      orignames[repoid] = repo->name;
+      char *buf, *mp;
+      buf = solv_malloc((repo->name ? strlen(repo->name) : 0) + 40);
       if (!repo->name || !repo->name[0])
         sprintf(buf, "#%d", repoid);
       else
        strcpy(buf, repo->name);
-      for (i = 0; buf[i]; i++)
-       if (buf[i] == ' ' || buf[i] == '\t' || buf[i] == '/')
-         buf[i] = '_';
-      mp = buf + strlen(buf);
-      for (;;)
-       {
-         for (i = 1; i < repoid; i++)
-           if (!strcmp(buf, pool_id2repo(pool, i)->name))
-             break;
-         if (i == repoid)
-           break;
+      for (mp = buf; *mp; mp++)
+       if (*mp == ' ' || *mp == '\t' || *mp == '/')
+         *mp = '_';
+      for (i = 1; i < repoid; i++)
+        {
+         if (!names[i] || strcmp(buf, names[i]) != 0)
+           continue;
           sprintf(mp, "_%d", mangle++);
+         i = 0;        /* restart conflict check */
        }
-      repo->name = buf;
+      names[repoid] = buf;
     }
-  r = testcase_write_mangled(solv, dir, resultflags, testcasename, resultname);
-  for (repoid = 1; repoid < pool->nrepos; repoid++)
+  return names;
+}
+
+static void
+swap_repo_names(Pool *pool, const char **names)
+{
+  int repoid;
+  Repo *repo;
+  FOR_REPOS(repoid, repo)
     {
-      Repo *repo = pool_id2repo(pool, repoid);
-      solv_free((void *)repo->name);
-      repo->name = orignames[repoid];
+      const char *n = repo->name;
+      repo->name = names[repoid];
+      names[repoid] = n;
     }
-  solv_free(orignames);
+}
+
+int
+testcase_write(Solver *solv, const char *dir, int resultflags, const char *testcasename, const char *resultname)
+{
+  Pool *pool = solv->pool;
+  int r, repoid;
+  const char **names;
+
+  /* mangle repo names so that there are no conflicts */
+  names = testcase_mangle_repo_names(pool);
+  swap_repo_names(pool, names);
+  r = testcase_write_mangled(solv, dir, resultflags, testcasename, resultname);
+  swap_repo_names(pool, names);
+  for (repoid = 1; repoid < pool->nrepos; repoid++)
+    solv_free((void *)names[repoid]);
+  solv_free((void *)names);
   return r;
 }
 
@@ -2558,6 +2158,7 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
   Id *genid = 0;
   int ngenid = 0;
   Queue autoinstq;
+  int oldjobsize = job ? job->count : 0;
 
   if (resultp)
     *resultp = 0;
@@ -2569,7 +2170,13 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
       return 0;
     }
   testcasedir = solv_strdup(testcase);
-  if ((s = strrchr(testcasedir, '/')) != 0)
+  s = strrchr(testcasedir, '/');
+#ifdef _WIN32
+  buf = strrchr(testcasedir, '\\');
+  if (!s || (buf && buf > s))
+    s = buf;
+#endif
+  if (s)
     s[1] = 0;
   else
     *testcasedir = 0;
@@ -2626,6 +2233,21 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
          int prio, subprio;
          const char *rdata;
 
+         if (pool->considered)
+           {
+             pool_error(pool, 0, "testcase_read: cannot add repos after packages were disabled");
+             continue;
+           }
+         if (solv)
+           {
+             pool_error(pool, 0, "testcase_read: cannot add repos after the solver was created");
+             continue;
+           }
+         if (job && job->count != oldjobsize)
+           {
+             pool_error(pool, 0, "testcase_read: cannot add repos after jobs have been created");
+             continue;
+           }
          prepared = 0;
           if (!poolflagsreset)
            {
@@ -2639,14 +2261,14 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
            }
           repo->priority = prio;
           repo->subpriority = subprio;
-         if (strcmp(pieces[3], "empty") != 0)
+         if (strcmp(pieces[3], "empty") != 0 && npieces > 4)
            {
              const char *repotype = pool_tmpjoin(pool, pieces[3], 0, 0);       /* gets overwritten in <inline> case */
              if (!strcmp(pieces[4], "<inline>"))
                {
                  char *idata = read_inline_file(fp, &buf, &bufp, &bufl);
                  rdata = "<inline>";
-                 rfp = solv_xfopen_buf(rdata, &idata, 0, "rf");
+                 rfp = solv_fmemopen(idata, strlen(idata), "rf");
                }
              else
                {
@@ -2686,6 +2308,11 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
          int i;
 
          /* must set the disttype before the arch */
+         if (job && job->count != oldjobsize)
+           {
+             pool_error(pool, 0, "testcase_read: cannot change the system after jobs have been created");
+             continue;
+           }
          prepared = 0;
          if (strcmp(pieces[2], "*") != 0)
            {
@@ -2717,7 +2344,7 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
                  missing_features = 1;
                }
            }
-         if (strcmp(pieces[1], "unset") == 0)
+         if (strcmp(pieces[1], "unset") == 0 || strcmp(pieces[1], "-") == 0)
            pool_setarch(pool, 0);
          else if (pieces[1][0] == ':')
            pool_setarchpolicy(pool, pieces[1] + 1);
@@ -2775,6 +2402,9 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
        }
       else if (!strcmp(pieces[0], "vendorclass") && npieces > 1)
        {
+         int i;
+         for (i = 1; i < npieces; i++)
+           testcase_unescape_inplace(pieces[i]);
          pool_addvendorclass(pool, (const char **)(pieces + 1));
        }
       else if (!strcmp(pieces[0], "namespace") && npieces > 1)
@@ -2855,7 +2485,10 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
                }
            }
          if (resultp)
+         {
+           solv_free(*resultp);
            *resultp = result;
+         }
          else
            solv_free(result);
          if (resultflagsp)