1 // -*- mode: C++; c-file-style: "cc-mode" -*- 2 //************************************************************************* 3 // 4 // Copyright 2013-2017 by Wilson Snyder. This program is free software; you can 5 // redistribute it and/or modify it under the terms of either the GNU 6 // Lesser General Public License Version 3 or the Perl Artistic License 7 // Version 2.0. 8 // SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 9 // 10 //************************************************************************* 11 12 #ifndef TEST_CHECK_H_ 13 #define TEST_CHECK_H_ 14 15 extern int errors; 16 17 #ifdef TEST_VERBOSE 18 static const bool verbose = true; 19 #else 20 static const bool verbose = false; 21 #endif 22 23 //====================================================================== 24 25 // Use cout to avoid issues with %d/%lx etc 26 #define TEST_CHECK(got, exp, test) \ 27 do { \ 28 if (!(test)) { \ 29 std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ \ 30 << ": GOT = " << (got) << " EXP = " << (exp) << std::endl; \ 31 ++errors; \ 32 } \ 33 } while (0) 34 35 #define TEST_CHECK_EQ(got, exp) TEST_CHECK(got, exp, ((got) == (exp))); 36 #define TEST_CHECK_NE(got, exp) TEST_CHECK(got, exp, ((got) != (exp))); 37 #define TEST_CHECK_CSTR(got, exp) TEST_CHECK(got, exp, 0 == strcmp((got), (exp))); 38 39 #define TEST_CHECK_HEX_EQ(got, exp) \ 40 do { \ 41 if ((got) != (exp)) { \ 42 std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \ 43 << ": GOT=" << (got) << " EXP=" << (exp) << std::endl; \ 44 ++errors; \ 45 } \ 46 } while (0) 47 48 #define TEST_CHECK_HEX_NE(got, exp) \ 49 do { \ 50 if ((got) == (exp)) { \ 51 std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \ 52 << ": GOT=" << (got) << " EXP!=" << (exp) << std::endl; \ 53 ++errors; \ 54 } \ 55 } while (0) 56 57 #define TEST_CHECK_Z(got) \ 58 do { \ 59 if ((got)) { \ 60 std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \ 61 << ": GOT!= NULL EXP=NULL" << std::endl; \ 62 ++errors; \ 63 } \ 64 } while (0) 65 66 #define TEST_CHECK_NZ(got) \ 67 do { \ 68 if (!(got)) { \ 69 std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \ 70 << ": GOT= NULL EXP!=NULL" << std::endl; \ 71 ++errors; \ 72 } \ 73 } while (0) 74 75 //====================================================================== 76 77 #define TEST_VERBOSE_PRINTF(format, ...) \ 78 do { \ 79 if (verbose) printf(format, ##__VA_ARGS__); \ 80 } while (0) 81 82 #endif // Guard 83