aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/simple-test.h726
1 files changed, 642 insertions, 84 deletions
diff --git a/src/simple-test.h b/src/simple-test.h
index e7220ca..0ee556a 100644
--- a/src/simple-test.h
+++ b/src/simple-test.h
@@ -1,28 +1,164 @@
#ifndef _TEST_H_
#define _TEST_H_
+#define _XOPEN_SOURCE 700
+
+#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
+#include <string.h>
+#include <wchar.h>
+
+
+/****************************
+ * INTERNAL FUNCTIONALITY *
+ ****************************/
+
+int _test_mbslen(char *arg)
+{
+ int blen = strlen(arg), clen = 0, i = 0;
+ wchar_t wc;
+ setlocale(LC_ALL, "");
+ while(i < blen) {
+ i += mbtowc(&wc, arg + i, blen - i);
+ clen += wcwidth(wc);
+ }
+ return clen;
+}
+
+void _test_get_escape(char c, char *buf)
+{
+ buf[0] = '\\';
+ buf[2] = '\0';
+
+ switch(c) {
+ case '\a':
+ buf[1] = 'a';
+ break;
+ case '\b':
+ buf[1] = 'b';
+ break;
+ case '\t':
+ buf[1] = 't';
+ break;
+ case '\n':
+ buf[1] = 'n';
+ break;
+ case '\v':
+ buf[1] = 'v';
+ break;
+ case '\f':
+ buf[1] = 'f';
+ break;
+ case '\r':
+ buf[1] = 'r';
+ break;
+ default:
+ buf[0] = c;
+ buf[1] = '\0';
+ }
+}
-/*************
- * REGIONS *
- *************/
+void _test_get_escape_wide(wchar_t c, wchar_t *buf)
+{
+ buf[0] = L'\\';
+ buf[2] = L'\0';
+
+ switch(c) {
+ case L'\a':
+ buf[1] = L'a';
+ break;
+ case L'\b':
+ buf[1] = L'b';
+ break;
+ case L'\t':
+ buf[1] = L't';
+ break;
+ case L'\n':
+ buf[1] = L'n';
+ break;
+ case L'\v':
+ buf[1] = L'v';
+ break;
+ case L'\f':
+ buf[1] = L'f';
+ break;
+ case L'\r':
+ buf[1] = L'r';
+ break;
+ default:
+ buf[0] = c;
+ buf[1] = L'\0';
+ }
+}
/* extra levels of abstraction are necessary
- * to get __COUNTER__ to evaluate before
- * being concatenated */
-#define _TEST_PASTE(x, y) \
-x ## y
+ * to get __LINE__ to evaluate first */
+#define _TEST_STRINGIFY(x) _TEST_STRINGIFY_EVAL(x)
+
+#define _TEST_STRINGIFY_EVAL(x) \
+#x
+
+#define _TEST_LEN_DIFF(arg1, arg2) \
+ ( _test_mbslen(arg1) - _test_mbslen(arg2) )
+
+#define _TEST_FAIL_VAL(summary, format1, format2, expected, actual) \
+do { \
+ _TEST_FAIL_VAL_REAL(summary, format1, format2, #actual, expected, actual); \
+} while(0)
+
+#define _TEST_FAIL_VAL_REAL(summary, format1, format2, sactual, expected, actual) \
+do { \
+ { \
+ int _test_i, _test_diff = _TEST_LEN_DIFF("expected", #actual); \
+ printf("\e[1m :: " __FILE__ ":" _TEST_STRINGIFY(__LINE__) ": \e[31;1mfail:\e[m " summary "\e[m\n"); \
+ printf("\e[1m :: \e[m\e[1m"); \
+ for(_test_i = 0; _test_i < -_test_diff; _test_i++) \
+ printf(" "); \
+ printf("expected:\e[m " format1 "\n", expected);\
+ printf("\e[1m :: \e[m\e[1m"); \
+ for(_test_i = 0; _test_i < _test_diff; _test_i++) \
+ printf(" "); \
+ printf(#actual ":\e[m " format2 "\e[m\n", actual); \
+ return 1; \
+ } \
+} while(0)
+
+#define _TEST_FAIL_EQ(summary, format1, format2, arg1, arg2) \
+do { \
+ _TEST_FAIL_EQ_REAL(summary, format1, format2, #arg1, #arg2, arg1, arg2); \
+} while(0)
+
+#define _TEST_FAIL_EQ_REAL(summary, format1, format2, sarg1, sarg2, arg1, arg2) \
+do { \
+ { \
+ int _test_i, _test_diff = _TEST_LEN_DIFF(sarg1, sarg2); \
+ printf("\e[1m :: " __FILE__ ":" _TEST_STRINGIFY(__LINE__) ": \e[31;1mfail:\e[m " summary "\e[m\n"); \
+ printf("\e[1m :: "); \
+ for(_test_i = 0; _test_i < -_test_diff; _test_i++) \
+ printf(" "); \
+ printf(sarg1 " == \e[m" format1 "\n", arg1); \
+ printf("\e[1m :: "); \
+ for(_test_i = 0; _test_i < _test_diff; _test_i++) \
+ printf(" "); \
+ printf(sarg2 " == \e[m" format2 "\n", arg2); \
+ return 1; \
+ } \
+} while(0)
+
+
+/**********************
+ * TOP-LEVEL MACROS *
+ **********************/
/* the whole thing is inside one
* big function. yay! */
#define BEGIN_TEST \
-typedef void (*_test_cleanup_t)(void); \
-_test_cleanup_t _test_cleanup_current=NULL; \
int _test_count_current=1; \
int main(int argc, char *argv[]) \
-{
+{ \
+ printf("\e[1m" __FILE__ "\n");
/* yaaaay! */
#define END_TEST \
@@ -30,139 +166,561 @@ int main(int argc, char *argv[]) \
return 0; \
}
-/* print a fancy description and
- * reset the cleanup function
- * pointer to NULL so, if it isn't
- * defined again, no cleanup will
- * be called */
#define TEST(description) \
-_test_cleanup_current=NULL; \
printf("\e[1m%3i :: \e[m\e[33m%s\e[m\n", _test_count_current++, description);
-/* pass in statements to be called on test
- * exit. goes after varible declarations and
- * before test body. */
-#define CLEANUP(statements) \
-_TEST_CLEANUP_UNIQ(statements, __COUNTER__)
-
-/* insert a unique cleanup function */
-#define _TEST_CLEANUP_UNIQ(statements, unique_count) \
-void _TEST_PASTE(_test_cleanup_, unique_count)(void) \
-{ \
- statements \
-} \
-_test_cleanup_current=_TEST_PASTE(_test_cleanup_, unique_count);
-
/* pretty printing for the current state within
* a test */
-#define STATE(...) \
+#define ECHO(...) \
do { \
printf("\e[1m :: \e[m\e[34m"); \
printf(__VA_ARGS__); \
printf("...\e[m\n"); \
} while(0)
-/* one of these goes at the end of every test
- * with CLEANUP (unless you want memory leaks).
- * if you want, stick it in those without CLEANUP
- * too. */
-#define RETURN() _TEST_RETURN(false)
-
-/* checks if there is a cleanup function to
- * call and then either continues or terminates
- * the test */
-#define _TEST_RETURN(fail) \
-do { \
- if(_test_cleanup_current != NULL) \
- (*_test_cleanup_current)(); \
- if(fail) \
- exit(1); \
-} while(0)
/***********
* TESTS *
***********/
-#define EXPECT_NULL(summary, arg) \
+#define EXPECT_NULL(arg) \
do { \
if((arg) != NULL) \
- _TEST_FAIL_VAL(summary, "%s", "%p", "NULL", (void*)(arg)); \
+ _TEST_FAIL_VAL("NULL value", "%s", "%p", "NULL", (void*)(arg)); \
} while(0);
-#define EXPECT_NON_NULL(summary, arg) \
+#define EXPECT_NON_NULL(arg) \
do { \
if((arg) == NULL) \
- _TEST_FAIL_VAL(summary, "%s", "%p", "non NULL", (void*)(arg)); \
+ _TEST_FAIL_VAL("non NULL value", "%s", "%p", "non NULL", (void*)(arg)); \
} while(0);
-#define EXPECT_ZERO(summary, arg) \
+#define EXPECT_PNT(arg1, arg2) \
do { \
- if(arg) \
- _TEST_FAIL_VAL(summary, "%i", "%i", 0, arg); \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%p", "%p", arg1, arg2); \
+} while(0);
+
+#define EXPECT_PNT_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%p", "%p", arg1, arg2); \
+} while(0);
+
+#define EXPECT_PNT_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%p", "%p", arg1, arg2); \
} while(0);
-#define EXPECT_ONE(summary, arg) \
+#define EXPECT_PNT_G(arg1, arg2) \
do { \
- if((arg) != 1) \
- _TEST_FAIL_VAL(summary, "%i", "%i", 1, arg); \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %p", "%p", arg1, arg2); \
} while(0);
-#define EXPECT_GREATER_THAN_ZERO(summary, arg) \
+#define EXPECT_PNT_GEQ(arg1, arg2) \
do { \
- if((arg) <= 0) \
- _TEST_FAIL_VAL(summary, "%s", "%i", ">0", arg); \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %p", "%p", arg1, arg2); \
} while(0);
-#define EXPECT_INT(summary, arg1, arg2) \
+#define EXPECT_PNT_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %p", "%p", arg1, arg2); \
+} while(0);
+
+#define EXPECT_PNT_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %p", "%p", arg1, arg2); \
+} while(0);
+
+#define EXPECT_HEX(arg1, arg2) \
do { \
if((arg1) != (arg2)) \
- _TEST_FAIL_VAL(summary, "%i", "%i", arg1, arg2); \
+ _TEST_FAIL_VAL("unexpected value", "0x%X", "0x%X", arg1, arg2); \
} while(0);
-#define EXPECT_EQUAL_INT(summary, arg1, arg2) \
+#define EXPECT_HEX_EQ(arg1, arg2) \
do { \
if((arg1) != (arg2)) \
- _TEST_FAIL_EQUAL(summary, "%i", "%i", arg1, arg2); \
+ _TEST_FAIL_EQ("values do not match", "0x%X", "0x%X", arg1, arg2); \
} while(0);
-#define EXPECT_UNEQUAL_INT(summary, arg1, arg2) \
+#define EXPECT_HEX_NEQ(arg1, arg2) \
do { \
if((arg1) == (arg2)) \
- _TEST_FAIL_EQUAL(summary, "%i", "%i", arg1, arg2); \
+ _TEST_FAIL_EQ("values match", "0x%X", "0x%X", arg1, arg2); \
+} while(0);
+
+#define EXPECT_HEX_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> 0x%X", "0x%X", arg1, arg2); \
+} while(0);
+
+#define EXPECT_HEX_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= 0x%X", "0x%X", arg1, arg2); \
+} while(0);
+
+#define EXPECT_HEX_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< 0x%X", "0x%X", arg1, arg2); \
+} while(0);
+
+#define EXPECT_HEX_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= 0x%X", "0x%X", arg1, arg2); \
+} while(0);
+
+#define EXPECT_INT(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_INT_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%i", "%i", arg1, arg2); \
} while(0);
-#define EXPECT_STR(summary, arg1, arg2) \
+#define EXPECT_INT_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_INT_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_INT_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_INT_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_INT_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LINT(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%li", "%li", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LINT_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%li", "%li", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LINT_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%li", "%li", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LINT_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %li", "%li", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LINT_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %li", "%li", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LINT_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %li", "%li", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LINT_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %li", "%li", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLINT(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%lli", "%lli", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLINT_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%lli", "%lli", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLINT_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%lli", "%lli", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLINT_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %lli", "%lli", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLINT_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %lli", "%lli", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLINT_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %lli", "%lli", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLINT_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %lli", "%lli", arg1, arg2); \
+} while(0);
+
+#define EXPECT_UINT(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%u", "%u", arg1, arg2); \
+} while(0);
+
+#define EXPECT_UINT_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%u", "%u", arg1, arg2); \
+} while(0);
+
+#define EXPECT_UINT_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%u", "%u", arg1, arg2); \
+} while(0);
+
+#define EXPECT_UINT_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %u", "%u", arg1, arg2); \
+} while(0);
+
+#define EXPECT_UINT_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %u", "%u", arg1, arg2); \
+} while(0);
+
+#define EXPECT_UINT_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %u", "%u", arg1, arg2); \
+} while(0);
+
+#define EXPECT_UINT_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %u", "%u", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LUINT(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%lu", "%lu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LUINT_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%lu", "%lu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LUINT_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%lu", "%lu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LUINT_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %lu", "%lu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LUINT_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %lu", "%lu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LUINT_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %lu", "%lu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LUINT_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %lu", "%lu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLUINT(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%llu", "%llu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLUINT_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%llu", "%llu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLUINT_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%llu", "%llu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLUINT_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %llu", "%llu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLUINT_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %llu", "%llu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLUINT_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %llu", "%llu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LLUINT_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %llu", "%llu", arg1, arg2); \
+} while(0);
+
+#define EXPECT_FLOAT(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_FLOAT_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%f", "%f", arg1, arg2); \
+} while(0);
+
+#define EXPECT_FLOAT_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%f", "%f", arg1, arg2); \
+} while(0);
+
+#define EXPECT_FLOAT_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %f", "%f", arg1, arg2); \
+} while(0);
+
+#define EXPECT_FLOAT_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %f", "%f", arg1, arg2); \
+} while(0);
+
+#define EXPECT_FLOAT_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %f", "%f", arg1, arg2); \
+} while(0);
+
+#define EXPECT_FLOAT_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LDOUBLE(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_VAL("unexpected value", "%i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LDOUBLE_EQ(arg1, arg2) \
+do { \
+ if((arg1) != (arg2)) \
+ _TEST_FAIL_EQ("values do not match", "%Lf", "%Lf", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LDOUBLE_NEQ(arg1, arg2) \
+do { \
+ if((arg1) == (arg2)) \
+ _TEST_FAIL_EQ("values match", "%Lf", "%Lf", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LDOUBLE_G(arg1, arg2) \
+do { \
+ if((arg1) <= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %Lf", "%Lf", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LDOUBLE_GEQ(arg1, arg2) \
+do { \
+ if((arg1) < (arg2)) \
+ _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %Lf", "%Lf", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LDOUBLE_L(arg1, arg2) \
+do { \
+ if((arg1) >= (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">=" #arg2, "< %Lf", "%Lf", arg1, arg2); \
+} while(0);
+
+#define EXPECT_LDOUBLE_LEQ(arg1, arg2) \
+do { \
+ if((arg1) > (arg2)) \
+ _TEST_FAIL_VAL(#arg1 ">" #arg2, "<= %i", "%i", arg1, arg2); \
+} while(0);
+
+#define EXPECT_CHAR(arg1, arg2) \
+do { \
+ { \
+ char _test_buf1[3], _test_buf2[3]; \
+ _test_get_escape((arg1), _test_buf1); \
+ _test_get_escape((arg2), _test_buf2); \
+ if( strcmp(_test_buf1, _test_buf2) ) \
+ _TEST_FAIL_VAL_REAL("unexpected char value", \
+ "‘%s’","‘%s’", #arg1, #arg2, _test_buf1, _test_buf2); \
+ } \
+} while(0);
+
+#define EXPECT_CHAR_EQ(arg1, arg2) \
+do { \
+ { \
+ char _test_buf1[3], _test_buf2[3]; \
+ _test_get_escape((arg1), _test_buf1); \
+ _test_get_escape((arg2), _test_buf2); \
+ if( strcmp(_test_buf1, _test_buf2) ) \
+ _TEST_FAIL_EQ_REAL("chars unequal", \
+ "‘%s’", "‘%s’", #arg1, #arg2, _test_buf1, _test_buf2); \
+ } \
+} while(0);
+
+#define EXPECT_CHAR_NEQ(arg1, arg2) \
+do { \
+ { \
+ char _test_buf1[3], _test_buf2[3]; \
+ _test_get_escape((arg1), _test_buf1); \
+ _test_get_escape((arg2), _test_buf2); \
+ if( !strcmp(_test_buf1, _test_buf2) ) \
+ _TEST_FAIL_EQ_REAL("chars equal", \
+ "‘%s’", "‘%s’", #arg1, #arg2, _test_buf1, _test_buf2); \
+ } \
+} while(0);
+
+#define EXPECT_STR(arg1, arg2) \
do { \
if( strcmp(arg1, arg2) ) \
- _TEST_FAIL_VAL(summary, "‘%s’", "‘%s’", arg1, arg2); \
+ _TEST_FAIL_VAL("unexpected string value", "‘%s’", "‘%s’", arg1, arg2); \
} while(0);
-#define EXPECT_EQUAL_STR(summary, arg1, arg2) \
+#define EXPECT_STR_EQ(arg1, arg2) \
do { \
if( strcmp(arg1, arg2) ) \
- _TEST_FAIL_EQUAL(summary, "‘%s’", "‘%s’", arg1, arg2); \
+ _TEST_FAIL_EQ("strings unequal", "‘%s’", "‘%s’", arg1, arg2); \
} while(0);
-#define EXPECT_UNEQUAL_STR(summary, arg1, arg2) \
+#define EXPECT_STR_NEQ(arg1, arg2) \
do { \
if( !strcmp(arg1, arg2) ) \
- _TEST_FAIL_EQUAL(summary, "‘%s’", "‘%s’", arg1, arg2); \
+ _TEST_FAIL_EQ("strings equal", "‘%s’", "‘%s’", arg1, arg2); \
} while(0);
-#define _TEST_FAIL_VAL(summary, format1, format2, expected, actual) \
+#define EXPECT_WCHAR(arg1, arg2) \
do { \
- printf("\e[1m :: \e[m\e[31mFAIL: " summary "\e[m\n"); \
- printf("\e[1m :: \e[m\e[1;32m expected:\e[m " format1 "\n", expected);\
- printf("\e[1m :: \e[m\e[1;31m actual:\e[m " format2 "\n", actual); \
- _TEST_RETURN(true); \
-} while(0)
+ { \
+ wchar_t _test_buf1[3], _test_buf2[3]; \
+ _test_get_escape_wide((arg1), _test_buf1); \
+ _test_get_escape_wide((arg2), _test_buf2); \
+ if( wcscmp(_test_buf1, _test_buf2) ) \
+ _TEST_FAIL_VAL_REAL("unexpected wchar value", \
+ "‘%ls’", "‘%ls’", #arg1, #arg2, _test_buf1, _test_buf2); \
+ } \
+} while(0);
-#define _TEST_FAIL_EQUAL(summary, format1, format2, arg1, arg2) \
+#define EXPECT_WCHAR_EQ(arg1, arg2) \
do { \
- printf("\e[1m :: \e[m\e[31mFAIL: " summary "\e[m\n"); \
- printf("\e[1m :: \e[m arg1 == \e[1;31m" format1 "\e[m\n", arg1); \
- printf("\e[1m :: \e[m arg2 == \e[1;31m" format2 "\e[m\n", arg2); \
- _TEST_RETURN(true); \
-} while(0)
+ { \
+ wchar_t _test_buf1[3], _test_buf2[3]; \
+ _test_get_escape_wide((arg1), _test_buf1); \
+ _test_get_escape_wide((arg2), _test_buf2); \
+ if( wcscmp(_test_buf1, _test_buf2) ) \
+ _TEST_FAIL_EQ_REAL("wchars unequal", \
+ "‘%ls’", "‘%ls’", #arg1, #arg2, _test_buf1, _test_buf2); \
+ } \
+} while(0);
+
+#define EXPECT_WCHAR_NEQ(arg1, arg2) \
+do { \
+ { \
+ wchar_t _test_buf1[3], _test_buf2[3]; \
+ _test_get_escape_wide((arg1), _test_buf1); \
+ _test_get_escape_wide((arg2), _test_buf2); \
+ if( !wcscmp(_test_buf1, _test_buf2) ) \
+ _TEST_FAIL_EQ_REAL("wchars equal", \
+ "‘%ls’", "‘%ls’", #arg1, #arg2, _test_buf1, _test_buf2); \
+ } \
+} while(0);
+
+#define EXPECT_WSTR(arg1, arg2) \
+do { \
+ if( wcscmp(arg1, arg2) ) \
+ _TEST_FAIL_VAL("unexpected wide string value", "‘%ls’", "‘%ls’", arg1, arg2); \
+} while(0);
+
+#define EXPECT_WSTR_EQ(arg1, arg2) \
+do { \
+ if( wcscmp(arg1, arg2) ) \
+ _TEST_FAIL_EQ("wide strings unequal", "‘%ls’", "‘%ls’", arg1, arg2); \
+} while(0);
+
+#define EXPECT_WSTR_NEQ(arg1, arg2) \
+do { \
+ if( !wcscmp(arg1, arg2) ) \
+ _TEST_FAIL_EQ("wide strings equal", "‘%ls’", "‘%ls’", arg1, arg2); \
+} while(0);
#endif