1*4684ddb6SLionel Sambuc #include <stdio.h>
2*4684ddb6SLionel Sambuc #include <stdlib.h>
3*4684ddb6SLionel Sambuc #include <unistd.h>
4*4684ddb6SLionel Sambuc
5*4684ddb6SLionel Sambuc
6*4684ddb6SLionel Sambuc static int succeeded;
7*4684ddb6SLionel Sambuc static int failed;
8*4684ddb6SLionel Sambuc static bool verbose;
9*4684ddb6SLionel Sambuc
log_test(bool predicate,const char * file,int line,const char * message)10*4684ddb6SLionel Sambuc void log_test(bool predicate, const char *file, int line, const char *message)
11*4684ddb6SLionel Sambuc {
12*4684ddb6SLionel Sambuc if (predicate)
13*4684ddb6SLionel Sambuc {
14*4684ddb6SLionel Sambuc if (verbose)
15*4684ddb6SLionel Sambuc {
16*4684ddb6SLionel Sambuc printf("Test passed: %s:%d: %s\n", file, line, message);
17*4684ddb6SLionel Sambuc }
18*4684ddb6SLionel Sambuc succeeded++;
19*4684ddb6SLionel Sambuc return;
20*4684ddb6SLionel Sambuc }
21*4684ddb6SLionel Sambuc failed++;
22*4684ddb6SLionel Sambuc printf("Test failed: %s:%d: %s\n", file, line, message);
23*4684ddb6SLionel Sambuc }
24*4684ddb6SLionel Sambuc
log_totals(void)25*4684ddb6SLionel Sambuc static void log_totals(void)
26*4684ddb6SLionel Sambuc {
27*4684ddb6SLionel Sambuc printf("\n%d tests, %d passed, %d failed\n", succeeded+failed, succeeded, failed);
28*4684ddb6SLionel Sambuc }
29*4684ddb6SLionel Sambuc
init(void)30*4684ddb6SLionel Sambuc static void __attribute__((constructor)) init(void)
31*4684ddb6SLionel Sambuc {
32*4684ddb6SLionel Sambuc atexit(log_totals);
33*4684ddb6SLionel Sambuc }
34*4684ddb6SLionel Sambuc
35*4684ddb6SLionel Sambuc void test_type_info(void);
36*4684ddb6SLionel Sambuc void test_exceptions();
37*4684ddb6SLionel Sambuc void test_guards(void);
main(int argc,char ** argv)38*4684ddb6SLionel Sambuc int main(int argc, char **argv)
39*4684ddb6SLionel Sambuc {
40*4684ddb6SLionel Sambuc int ch;
41*4684ddb6SLionel Sambuc
42*4684ddb6SLionel Sambuc while ((ch = getopt(argc, argv, "v")) != -1)
43*4684ddb6SLionel Sambuc {
44*4684ddb6SLionel Sambuc switch (ch)
45*4684ddb6SLionel Sambuc {
46*4684ddb6SLionel Sambuc case 'v':
47*4684ddb6SLionel Sambuc verbose = true;
48*4684ddb6SLionel Sambuc default: break;
49*4684ddb6SLionel Sambuc }
50*4684ddb6SLionel Sambuc }
51*4684ddb6SLionel Sambuc
52*4684ddb6SLionel Sambuc test_type_info();
53*4684ddb6SLionel Sambuc test_guards();
54*4684ddb6SLionel Sambuc test_exceptions();
55*4684ddb6SLionel Sambuc return 0;
56*4684ddb6SLionel Sambuc }
57