@@@ all the mess ever
[mLib] / utils / t / versioncmp-test.c
index 0927f46..789565d 100644 (file)
  * MA 02111-1307, USA.
  */
 
-#include "testrig.h"
+#include "tvec.h"
 #include "versioncmp.h"
 
-static int t_vcmp(dstr *v)
+enum {
+  RRC, NROUT,
+  RV0 = NROUT, RV1, NREG
+};
+
+static void test_versioncmp(const struct tvec_reg *in, struct tvec_reg *out,
+                           void *ctx)
+  { out[RRC].v.i = versioncmp(in[RV0].v.str.p, in[RV1].v.str.p); }
+
+static void swap_test(struct tvec_state *tv)
 {
-  int ok = 1;
-  int rc = versioncmp(v[0].buf, v[1].buf);
-  if (rc != *(int *)v[2].buf) {
-    fprintf(stderr, "\nversioncmp(%s, %s) returns %d != %d\n",
-           v[0].buf, v[1].buf, rc, *(int *)v[2].buf);
-    ok = 0;
-  }
-  return (ok);
+  struct tvec_reg rt;
+
+  tv->st = '.';
+  tv->test->fn(tv->in, tv->out, 0); tvec_check(tv, "vanilla");
+  rt = tv->in[RV0]; tv->in[RV0] = tv->in[RV1]; tv->in[RV1] = rt;
+  tv->in[RRC].v.i = -tv->in[RRC].v.i;
+  tv->test->fn(tv->in, tv->out, 0); tvec_check(tv, "swapped");
 }
 
-static const test_chunk tests[] = {
-  { "versioncmp", t_vcmp, { &type_string, &type_string, &type_int } },
-  { 0 }
+static const struct tvec_irange cmp_range = { -1, +1 };
+static const struct tvec_regdef versioncmp_regs[] = {
+  { "v0", RV0, &tvty_string, 0 },
+  { "v1", RV1, &tvty_string, 0 },
+  { "rc", RRC, &tvty_int, 0, { &cmp_range } },
+  { 0, 0, 0 }
 };
 
+static const struct tvec_test tests[] = {
+  { "versioncmp", versioncmp_regs, 0, swap_test, test_versioncmp },
+  { 0, 0, 0, 0 }
+};
+
+static const struct tvec_info testinfo =
+  { tests, NROUT, NREG, sizeof(struct tvec_reg) };
+
 int main(int argc, char *argv[])
-  { test_run(argc, argv, tests, SRCDIR "/versioncmp.in"); return (1); }
+  { return (tvec_main(argc, argv, &testinfo, 0)); }
 
 /*----- That's all, folks -------------------------------------------------*/