/* This software was written by Dirk Engling It is considered beerware. Prost. Skol. Cheers or whatever. $id$ */ /* System */ #include #include /* Opentracker */ #include "test.h" unsigned long test_checks; unsigned long test_failures; static const char *current_module = ""; static const char *current_case = ""; void test_module(const char *name) { current_module = name; current_case = ""; printf("%s\n", name); } void test_case(const char *name) { current_case = name; } static void test_where(const char *file, int line) { ++test_failures; printf(" FAIL %s/%s (%s:%d)\n ", current_module, current_case, file, line); } void test_failf(const char *file, int line, const char *fmt, ...) { va_list ap; test_where(file, line); va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf("\n"); } void test_failmem(const char *file, int line, const char *what, const void *got, const void *want, size_t len) { const unsigned char *g = got, *w = want; size_t i; test_where(file, line); printf("%s: %zu bytes differ\n got ", what, len); for (i = 0; i < len; ++i) printf("%02x", g[i]); printf("\n want "); for (i = 0; i < len; ++i) printf("%02x", w[i]); printf("\n"); } int test_summary(void) { printf("\n%lu checks, %lu failures\n", test_checks, test_failures); return test_failures != 0; }