X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/7cf5c72a6d353ed5a7e340562c11e54c21c85e5e..98ff9295493ed2b990f30768e11b18b6bc65eaa4:/utils/t/versioncmp-test.c?ds=sidebyside diff --git a/utils/t/versioncmp-test.c b/utils/t/versioncmp-test.c index 0927f46..f0df250 100644 --- a/utils/t/versioncmp-test.c +++ b/utils/t/versioncmp-test.c @@ -25,27 +25,48 @@ * MA 02111-1307, USA. */ -#include "testrig.h" +#include "tvec.h" +#include "tvec-types.h" + #include "versioncmp.h" -static int t_vcmp(dstr *v) +enum { + RRC, NROUT, + RV0 = NROUT, RV1, NREG +}; + +static const struct tvec_regdef versioncmp_regs[] = { + { "v0", &tvty_text, RV0, 0 }, + { "v1", &tvty_text, RV1, 0 }, + { "rc", &tvty_ienum, RRC, 0, { &tvenum_cmp } }, + TVEC_ENDREGS +}; + +static void swap_test(struct tvec_state *tv, tvec_testfn *fn, void *ctx) { - 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; + + fn(tv->in, tv->out, 0); tvec_check(tv, "vanilla"); + tvec_resetoutputs(tv); + rt = tv->in[RV0]; tv->in[RV0] = tv->in[RV1]; tv->in[RV1] = rt; + tv->in[RRC].v.i = -tv->in[RRC].v.i; + 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 void test_versioncmp(const struct tvec_reg *in, struct tvec_reg *out, + void *ctx) + { out[RRC].v.i = versioncmp(in[RV0].v.text.p, in[RV1].v.text.p); } + +static const struct tvec_env swap_testenv = { 0, 0, 0, 0, swap_test, 0, 0 }; +static const struct tvec_test versioncmp_test = + { "versioncmp", versioncmp_regs, &swap_testenv, test_versioncmp }; + +static const struct tvec_test *const tests[] = { &versioncmp_test, 0 }; + +static const struct tvec_config testconfig = + { 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, &testconfig, 0)); } /*----- That's all, folks -------------------------------------------------*/