1 #ifndef INCLUDED_TEST_H 2 #define INCLUDED_TEST_H 3 /* vim: set ts=8 sts=4 sw=4 tw=80 noet: */ 4 /*====================================================================== 5 Copyright (C) 2004,2005,2009,2013 Walter Doekes <walter+tthsum@wjd.nu> 6 This file is part of tthsum. 7 8 tthsum is free software: you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 tthsum is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with tthsum. If not, see <http://www.gnu.org/licenses/>. 20 ======================================================================*/ 21 22 /** 23 * Utility macros for the test suite. You'll find some duplicate code 24 * below because macro varargs are not portable. 25 */ 26 27 #include <stdio.h> 28 29 #define TESTS(title) \ 30 void title(unsigned* success, unsigned *failure, unsigned *warning) { \ 31 printf("+ " #title ": "); 32 #define TEST(func) \ 33 do { \ 34 if (func() == 0) { \ 35 printf("."); \ 36 ++*success; \ 37 } else { \ 38 printf("F"); \ 39 ++*failure; \ 40 } \ 41 } while (0) 42 #define TEST_WARN(func) \ 43 do { \ 44 if (func() == 0) { \ 45 printf("."); \ 46 ++*success; \ 47 } else { \ 48 printf("w"); \ 49 ++*warning; \ 50 } \ 51 } while (0) 52 #define ENDTESTS \ 53 printf("\n"); \ 54 } 55 56 #define FAIL(msg) \ 57 do { \ 58 fprintf(stderr, ">>> %s:%i: " msg "\n", __FILE__, __LINE__); \ 59 return 1; \ 60 } while(0) 61 62 #define FAIL1(msg, a) \ 63 do { \ 64 fprintf(stderr, ">>> %s:%i: " msg "\n", __FILE__, __LINE__, a); \ 65 return 1; \ 66 } while(0) 67 68 #define FAIL2(msg, a, b) \ 69 do { \ 70 fprintf(stderr, ">>> %s:%i: " msg "\n", __FILE__, __LINE__, a, b); \ 71 return 1; \ 72 } while(0) 73 74 #define FAIL3(msg, a, b, c) \ 75 do { \ 76 fprintf(stderr, ">>> %s:%i: " msg "\n", __FILE__, __LINE__, a, b, c); \ 77 return 1; \ 78 } while(0) 79 80 #define TEST_PASS(test, msg) \ 81 do { \ 82 if (!(test)) \ 83 FAIL(msg); \ 84 } while(0) 85 86 #define TEST_PASS1(test, msg, a) \ 87 do { \ 88 if (!(test)) \ 89 FAIL1(msg, a); \ 90 } while(0) 91 92 #define TEST_PASS2(test, msg, a, b) \ 93 do { \ 94 if (!(test)) \ 95 FAIL2(msg, a, b); \ 96 } while(0) 97 98 #define TEST_PASS3(test, msg, a, b, c) \ 99 do { \ 100 if (!(test)) \ 101 FAIL3(msg, a, b, c); \ 102 } while(0) 103 104 #endif /* INCLUDED_TEST_H */ 105