summaryrefslogtreecommitdiff
path: root/regress/lib/libradius/main.c
blob: a3968c70f81624cc736dc00923782e2655db96eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "incs.h"

#define TEST_MAX 100

struct test_entry {
	testfunc func;
	const char *name;
} entries[TEST_MAX];

int ntests = 0;

int test_entry_cmp(const void *a, const void *b)
{
	return strcmp(
		((struct test_entry *)a)->name,
		((struct test_entry *)b)->name);
}

int main(void)
{
	srandom_deterministic(time(NULL));

	qsort(entries, ntests, sizeof(struct test_entry), test_entry_cmp);

	for (int i = 0; i < ntests; i++) {
		fprintf(stderr, "running test %s\n", entries[i].name);
		entries[i].func();
	}

	fprintf(stderr, "tests are successfully completed.\n");
	return 0;
}

void check_failed(const char *expr, const char *file, int line)
{
	fprintf(stderr, "CHECK FAILED: %s at file %s line %d\n", expr, file, line);
	exit(1);
}

void add_test(testfunc fn, const char *name)
{
	entries[ntests].func = fn;
	entries[ntests].name = name;
	ntests++;
}