-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
73 lines (56 loc) · 1.36 KB
/
test.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* The makefile calls cc so that the effective first line is of the form
#include "*_test.h"
And includes the relevant test header and test.h */
#include "test.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define UNUSED __attribute__ ((unused))
int main(UNUSED int argc, UNUSED char **argv)
{
srand(clock());
size_t t = sizeof(tests) / sizeof(test_t);
size_t total = t;
int fail = 0;
#ifdef PARAM_T
size_t pt = sizeof(ptests) / sizeof(ptest_t);
size_t fc = sizeof(factories) / sizeof(factory_t);
total += pt;
if(!pt && fc)
printf("[WARN] Found factories but no parameterized tests!\n");
else if(!fc && pt)
printf("[WARN] Found parameterized tests but no factories!\n");
#endif
if(total == 0)
{
printf("No tests found!\n");
return EXIT_SUCCESS;
}
for (size_t i = 0; i < t; i++)
{
// from test.h
testInfo.testNumber = i + 1;
tests[i]();
printf("Finished test %zu/%zu\n", i + 1, total);
}
#ifdef PARAM_T
for (size_t i = 0; i < pt; i++)
{
size_t num = i + t + 1;
for (size_t j = 0; j < fc; j++)
{
PARAM_T v = factories[j].create();
testInfo = (struct testInfo){
.testNumber = num,
.factoryNumber = j+1,
.factory = factories[j],
.value = v
};
ptests[i](v);
factories[j].destroy(v);
printf("Finished test %zu/%zu with factory %zu/%zu\n", num, total, j + 1, fc);
}
}
#endif
return fail;
}