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