47 lines
1.3 KiB
C
47 lines
1.3 KiB
C
/*
|
|||
|
|
* test_harness.h — minimal assertion-based test harness.
|
||
|
|
*
|
||
|
|
* No third-party test framework, consistent with the project's
|
||
|
|
* static-linking / zero-required-dependency constraint (Section 11.1).
|
||
|
|
*/
|
||
|
|
#ifndef PACKFS_TEST_HARNESS_H
|
||
|
|
#define PACKFS_TEST_HARNESS_H
|
||
|
|
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <string.h>
|
||
|
|
|
||
|
|
static int pfs_test_failures = 0;
|
||
|
|
|
||
|
|
#define CHECK(cond) do { \
|
||
|
|
if (!(cond)) { \
|
||
|
|
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
||
|
|
pfs_test_failures++; \
|
||
|
|
} \
|
||
|
|
} while (0)
|
||
|
|
|
||
|
|
#define CHECK_EQ_INT(a, b) do { \
|
||
|
|
long long _a = (long long)(a), _b = (long long)(b); \
|
||
|
|
if (_a != _b) { \
|
||
|
|
fprintf(stderr, "FAIL %s:%d: %s (%lld) != %s (%lld)\n", __FILE__, __LINE__, #a, _a, #b, _b); \
|
||
|
|
pfs_test_failures++; \
|
||
|
|
} \
|
||
|
|
} while (0)
|
||
|
|
|
||
|
|
#define CHECK_STR_EQ(a, b) do { \
|
||
|
|
const char *_a = (a), *_b = (b); \
|
||
|
|
if (strcmp(_a, _b) != 0) { \
|
||
|
|
fprintf(stderr, "FAIL %s:%d: %s (\"%s\") != %s (\"%s\")\n", __FILE__, __LINE__, #a, _a, #b, _b); \
|
||
|
|
pfs_test_failures++; \
|
||
|
|
} \
|
||
|
|
} while (0)
|
||
|
|
|
||
|
|
#define TEST_MAIN_END() \
|
||
|
|
do { \
|
||
|
|
if (pfs_test_failures) { fprintf(stderr, "%d check(s) failed\n", pfs_test_failures); return 1; } \
|
||
|
|
fprintf(stderr, "OK\n"); \
|
||
|
|
return 0; \
|
||
|
|
} while (0)
|
||
|
|
|
||
|
|
#endif
|