-/*----- Test rig ----------------------------------------------------------*/
-
-#ifdef TEST_RIG
-
-#include <mLib/report.h>
-#include <mLib/str.h>
-#include <mLib/testrig.h>
-
-static void fixdstr(dstr *d)
-{
- if (d->len > 56)
- die(1, "invalid length for fgoldi");
- else if (d->len < 56) {
- dstr_ensure(d, 56);
- memset(d->buf + d->len, 0, 56 - d->len);
- d->len = 56;
- }
-}
-
-static void cvt_fgoldi(const char *buf, dstr *d)
-{
- dstr dd = DSTR_INIT;
-
- type_hex.cvt(buf, &dd); fixdstr(&dd);
- dstr_ensure(d, sizeof(fgoldi)); d->len = sizeof(fgoldi);
- fgoldi_load((fgoldi *)d->buf, (const octet *)dd.buf);
- dstr_destroy(&dd);
-}
-
-static void dump_fgoldi(dstr *d, FILE *fp)
- { fdump(stderr, "???", (const piece *)d->buf); }
-
-static void cvt_fgoldi_ref(const char *buf, dstr *d)
- { type_hex.cvt(buf, d); fixdstr(d); }
-
-static void dump_fgoldi_ref(dstr *d, FILE *fp)
-{
- fgoldi x;
-
- fgoldi_load(&x, (const octet *)d->buf);
- fdump(stderr, "???", x.P);
-}
-
-static int eq(const fgoldi *x, dstr *d)
- { octet b[56]; fgoldi_store(b, x); return (memcmp(b, d->buf, 56) == 0); }
-
-static const test_type
- type_fgoldi = { cvt_fgoldi, dump_fgoldi },
- type_fgoldi_ref = { cvt_fgoldi_ref, dump_fgoldi_ref };
-
-#define TEST_UNOP(op) \
- static int vrf_##op(dstr dv[]) \
- { \
- fgoldi *x = (fgoldi *)dv[0].buf; \
- fgoldi z, zz; \
- int ok = 1; \
- \
- fgoldi_##op(&z, x); \
- if (!eq(&z, &dv[1])) { \
- ok = 0; \
- fprintf(stderr, "failed!\n"); \
- fdump(stderr, "x", x->P); \
- fdump(stderr, "calc", z.P); \
- fgoldi_load(&zz, (const octet *)dv[1].buf); \
- fdump(stderr, "z", zz.P); \
- } \
- \
- return (ok); \
- }
-
-TEST_UNOP(sqr)
-TEST_UNOP(inv)
-
-#define TEST_BINOP(op) \
- static int vrf_##op(dstr dv[]) \
- { \
- fgoldi *x = (fgoldi *)dv[0].buf, *y = (fgoldi *)dv[1].buf; \
- fgoldi z, zz; \
- int ok = 1; \
- \
- fgoldi_##op(&z, x, y); \
- if (!eq(&z, &dv[2])) { \
- ok = 0; \
- fprintf(stderr, "failed!\n"); \
- fdump(stderr, "x", x->P); \
- fdump(stderr, "y", y->P); \
- fdump(stderr, "calc", z.P); \
- fgoldi_load(&zz, (const octet *)dv[2].buf); \
- fdump(stderr, "z", zz.P); \
- } \
- \
- return (ok); \
- }
-
-TEST_BINOP(add)
-TEST_BINOP(sub)
-TEST_BINOP(mul)