diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/test.h | 154 |
1 files changed, 113 insertions, 41 deletions
diff --git a/tools/test.h b/tools/test.h index 4a12d85..f470162 100644 --- a/tools/test.h +++ b/tools/test.h @@ -55,9 +55,9 @@ TEST_num_fails++; \ } -#define TEST_FATAL(m) { \ - fprintf(stderr, "FATAL: "m"\t\t\t<============\n"); \ - TEST_num_fails++; \ +#define TEST_FATAL(m) { \ + fprintf(stderr, "FATAL: %s\t\t\t<============\n", m); \ + TEST_num_fails++; \ { TEST_END; } #define TEST_MSG(fmt...) { \ @@ -95,11 +95,25 @@ else { TEST_FAIL(#x" and "#y" are equal.") } \ } +#define TEST_GREATER_THAN(x, y, fmt...) { \ + TEST_BASE(fmt); \ + if(x > y) { TEST_OK(#x" are greater than "#y".") } \ + else { TEST_FAIL(#x" are not greater than "#y".") } \ + } + +#define TEST_LESS_THAN(x, y, fmt...) { \ + TEST_BASE(fmt); \ + if(x < y) { TEST_OK(#x" are less than "#y".") } \ + else { TEST_FAIL(#x" are not less than "#y".") } \ + } + #define TEST_EQUAL_STR(x, y, fmt...) { \ TEST_BASE(fmt); \ + std::string s1 = x; \ + std::string s2 = y; \ fprintf(stderr, "Comparing: \"%s\" == \"%s\"\n", \ - std::string(x).c_str(), std::string(y).c_str()); \ - if(x == y) { \ + s1.c_str(), s2.c_str()); \ + if(s1 == s2) { \ TEST_OK(#x" and "#y" are equal."); \ } else { \ TEST_FAIL(#x" and "#y" are not equal."); \ @@ -108,53 +122,111 @@ #define TEST_NOTEQUAL_STR(x, y, fmt...) { \ TEST_BASE(fmt); \ + std::string s1 = x; \ + std::string s2 = y; \ fprintf(stderr, "Comparing: \"%s\" != \"%s\"\n", \ - std::string(x).c_str(), std::string(y).c_str()); \ - if(x != y) { \ - TEST_OK(#x" and "#y" are equal."); \ + s1.c_str(), s2.c_str()); \ + if(s1 != s2) { \ + TEST_OK(#x" and "#y" not are equal."); \ } else { \ - TEST_FAIL(#x" and "#y" are not equal."); \ + TEST_FAIL(#x" and "#y" are equal."); \ } \ } -#define TEST_EQUAL_INT(x, y, fmt...) { \ - TEST_BASE(fmt); \ - fprintf(stderr, "Comparing: \"%d\" == \"%d\"\n", x, y); \ - if(x == y) { \ - TEST_OK(#x" and "#y" are equal."); \ - } else { \ - TEST_FAIL(#x" and "#y" are not equal."); \ - } \ +#define TEST_EQUAL_INT(x, y, fmt...) { \ + TEST_BASE(fmt); \ + int i1 = x; \ + int i2 = y; \ + fprintf(stderr, "Comparing: \"%d\" == \"%d\"\n", i1, i2); \ + if(i1 == i2) { \ + TEST_OK(#x" and "#y" are equal."); \ + } else { \ + TEST_FAIL(#x" and "#y" are not equal."); \ + } \ } -#define TEST_NOTEQUAL_INT(x, y, fmt...) { \ - TEST_BASE(fmt); \ - fprintf(stderr, "Comparing: \"%d\" != \"%d\"\n", x, y); \ - if(x != y) { \ - TEST_OK(#x" and "#y" are equal."); \ - } else { \ - TEST_FAIL(#x" and "#y" are not equal."); \ - } \ +#define TEST_NOTEQUAL_INT(x, y, fmt...) { \ + TEST_BASE(fmt); \ + int i1 = x; \ + int i2 = y; \ + fprintf(stderr, "Comparing: \"%d\" != \"%d\"\n", i1, i2); \ + if(i1 != i2) { \ + TEST_OK(#x" and "#y" are not equal."); \ + } else { \ + TEST_FAIL(#x" and "#y" are equal."); \ + } \ } -#define TEST_EQUAL_FLOAT(x, y, fmt...) { \ - TEST_BASE(fmt); \ - fprintf(stderr, "Comparing: \"%f\" == \"%f\"\n", x, y); \ - if(x == y) { \ - TEST_OK(#x" and "#y" are equal."); \ - } else { \ - TEST_FAIL(#x" and "#y" are not equal."); \ - } \ +#define TEST_EQUAL_FLOAT(x, y, fmt...) { \ + TEST_BASE(fmt); \ + double d1 = x; \ + double d2 = y; \ + fprintf(stderr, "Comparing: \"%f\" == \"%f\"\n", d1, d2); \ + if(d1 == d2) { \ + TEST_OK(#x" and "#y" are equal."); \ + } else { \ + TEST_FAIL(#x" and "#y" are not equal."); \ + } \ } -#define TEST_NOTEQUAL_FLOAT(x, y, fmt...) { \ - TEST_BASE(fmt); \ - fprintf(stderr, "Comparing: \"%f\" != \"%f\"\n", x, y); \ - if(x != y) { \ - TEST_OK(#x" and "#y" are equal."); \ - } else { \ - TEST_FAIL(#x" and "#y" are not equal."); \ - } \ +#define TEST_NOTEQUAL_FLOAT(x, y, fmt...) { \ + TEST_BASE(fmt); \ + double d1 = x; \ + double d2 = y; \ + fprintf(stderr, "Comparing: \"%f\" != \"%f\"\n", d1, d2); \ + if(d1 != d2) { \ + TEST_OK(#x" and "#y" are not equal."); \ + } else { \ + TEST_FAIL(#x" and "#y" are equal."); \ + } \ + } + +#define TEST_GREATER_THAN_INT(x, y, fmt...) { \ + TEST_BASE(fmt); \ + int i1 = x; \ + int i2 = y; \ + fprintf(stderr, "Comparing: \"%d\" > \"%d\"\n", i1, i2); \ + if(i1 > i2) { \ + TEST_OK(#x" are greater than "#y"."); \ + } else { \ + TEST_FAIL(#x" are not greater than "#y"."); \ + } \ + } + +#define TEST_LESS_THAN_INT(x, y, fmt...) { \ + TEST_BASE(fmt); \ + int i1 = x; \ + int i2 = y; \ + fprintf(stderr, "Comparing: \"%d\" < \"%d\"\n", i1, i2); \ + if(i1 < i2) { \ + TEST_OK(#x" are less than "#y"."); \ + } else { \ + TEST_FAIL(#x" are not less than "#y"."); \ + } \ + } + +#define TEST_GREATER_THAN_FLOAT(x, y, fmt...) { \ + TEST_BASE(fmt); \ + double d1 = x; \ + double d2 = y; \ + fprintf(stderr, "Comparing: \"%f\" > \"%f\"\n", d1, d2); \ + if(d1 > d2) { \ + TEST_OK(#x" are greater than "#y"."); \ + } else { \ + TEST_FAIL(#x" are not greater than "#y"."); \ + } \ + } + +#define TEST_LESS_THAN_FLOAT(x, y, fmt...) { \ + TEST_BASE(fmt); \ + double d1 = x; \ + double d2 = y; \ + fprintf(stderr, "Comparing: \"%f\" < \"%f\"\n", d1, d2); \ + if(d1 < d2) { \ + TEST_OK(#x" are less than "#y"."); \ + } else { \ + TEST_FAIL(#x" are not less than "#y"."); \ + } \ } #define TEST_EXCEPTION(x, y, fmt...) { \ |