aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorshmibs <shmibs@gmail.com>2015-12-21 22:52:06 -0700
committershmibs <shmibs@gmail.com>2015-12-21 22:52:06 -0700
commita44c8ce0f213a0891713691ee342a5502548db31 (patch)
tree24a031c0f1fa54c8526a16dccc527bde253ff66f /src
parent011d01f447ae1e6c8ea5c0d7386908968ccdb344 (diff)
downloadsimple-test-a44c8ce0f213a0891713691ee342a5502548db31.tar.gz
implement generic macros
functional for int/uint/float types
Diffstat (limited to 'src')
-rw-r--r--src/simple-test.h1441
1 files changed, 854 insertions, 587 deletions
diff --git a/src/simple-test.h b/src/simple-test.h
index 0ee556a..12401f5 100644
--- a/src/simple-test.h
+++ b/src/simple-test.h
@@ -1,10 +1,12 @@
-#ifndef _TEST_H_
-#define _TEST_H_
+#ifndef SIMPLE_TEST_H
+#define SIMPLE_TEST_H
#define _XOPEN_SOURCE 700
+#include <inttypes.h>
#include <locale.h>
#include <stdlib.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
@@ -15,7 +17,31 @@
* INTERNAL FUNCTIONALITY *
****************************/
-int _test_mbslen(char *arg)
+typedef enum {
+ SIMPLE_TEST_INT,
+ SIMPLE_TEST_LINT,
+ SIMPLE_TEST_UINT,
+ SIMPLE_TEST_LUINT,
+ SIMPLE_TEST_FLOAT,
+ SIMPLE_TEST_PTR,
+ SIMPLE_TEST_CHAR,
+ SIMPLE_TEST_STR,
+ SIMPLE_TEST_WCHAR,
+ SIMPLE_TEST_WSTR,
+ SIMPLE_TEST_DEFAULT,
+} simple_test_type_t;
+
+typedef enum {
+ SIMPLE_TEST_TRUE,
+ SIMPLE_TEST_EQ,
+ SIMPLE_TEST_NEQ,
+ SIMPLE_TEST_G,
+ SIMPLE_TEST_GEQ,
+ SIMPLE_TEST_L,
+ SIMPLE_TEST_LEQ
+} simple_test_cond_t;
+
+int simple_test_mbslen(char *arg)
{
int blen = strlen(arg), clen = 0, i = 0;
wchar_t wc;
@@ -27,7 +53,7 @@ int _test_mbslen(char *arg)
return clen;
}
-void _test_get_escape(char c, char *buf)
+void simple_test_get_escape(char c, char *buf)
{
buf[0] = '\\';
buf[2] = '\0';
@@ -60,7 +86,7 @@ void _test_get_escape(char c, char *buf)
}
}
-void _test_get_escape_wide(wchar_t c, wchar_t *buf)
+void simple_test_get_escape_wide(wchar_t c, wchar_t *buf)
{
buf[0] = L'\\';
buf[2] = L'\0';
@@ -95,57 +121,491 @@ void _test_get_escape_wide(wchar_t c, wchar_t *buf)
/* extra levels of abstraction are necessary
* to get __LINE__ to evaluate first */
-#define _TEST_STRINGIFY(x) _TEST_STRINGIFY_EVAL(x)
+#define SIMPLE_TEST_STRINGIFY(x) SIMPLE_TEST_STRINGIFY_EVAL(x)
-#define _TEST_STRINGIFY_EVAL(x) \
+#define SIMPLE_TEST_STRINGIFY_EVAL(x) \
#x
-#define _TEST_LEN_DIFF(arg1, arg2) \
- ( _test_mbslen(arg1) - _test_mbslen(arg2) )
+#define SIMPLE_TEST_LEN_DIFF(arg1, arg2) \
+ ( simple_test_mbslen(arg1) - simple_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) \
+#define SIMPLE_TEST_FAIL(summary, file, line, fmt, sarg1, sarg2, arg1, arg2) \
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++) \
+ int simple_test_i, simple_test_diff = SIMPLE_TEST_LEN_DIFF(sarg1, sarg2); \
+ printf("\e[1m :: "); \
+ printf(file); \
+ printf(":%i: \e[31;1mfail:\e[m ", line); \
+ printf(summary); \
+ printf("\e[m\n"); \
+ printf("\e[1m :: "); \
+ for(simple_test_i = 0; simple_test_i < -simple_test_diff; simple_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("%s == \e[m" fmt "\n", sarg1, arg1); \
+ printf("\e[1m :: "); \
+ for(simple_test_i = 0; simple_test_i < simple_test_diff; simple_test_i++) \
printf(" "); \
- printf(#actual ":\e[m " format2 "\e[m\n", actual); \
- return 1; \
+ printf("%s == \e[m" fmt "\n", sarg2, arg2); \
+ exit(1); \
} \
} while(0)
-#define _TEST_FAIL_EQ(summary, format1, format2, arg1, arg2) \
+#define SIMPLE_TEST_INTERN_ERR() \
do { \
- _TEST_FAIL_EQ_REAL(summary, format1, format2, #arg1, #arg2, arg1, arg2); \
+ fprintf(stderr, "err: bad call to internal func"); \
+ exit(1); \
} 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)
+void simple_test_assert_int(char *sarg1, char *sarg2,
+ intmax_t arg1, intmax_t arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(!(arg2))
+ SIMPLE_TEST_FAIL("unexpected 0 value", file, line,
+ "%" PRIiMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if(arg1 != arg2)
+ SIMPLE_TEST_FAIL("int values do not match", file, line,
+ "%" PRIiMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if(arg1 == arg2)
+ SIMPLE_TEST_FAIL("int values match", file, line,
+ "%" PRIiMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_G:
+ if(arg1 <= arg2)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "%" PRIiMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if(arg1 < arg2)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "%" PRIiMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_L:
+ if(arg1 >= arg2)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "%" PRIiMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if(arg1 > arg2)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "%" PRIiMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+void simple_test_assert_uint(char *sarg1, char *sarg2,
+ uintmax_t arg1, uintmax_t arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(!(arg2))
+ SIMPLE_TEST_FAIL("unexpected 0 value", file, line,
+ "%" PRIuMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if(arg1 != arg2)
+ SIMPLE_TEST_FAIL("uint values do not match", file, line,
+ "%" PRIuMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if(arg1 == arg2)
+ SIMPLE_TEST_FAIL("uint values match", file, line,
+ "%" PRIuMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_G:
+ if(arg1 <= arg2)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "%" PRIuMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if(arg1 < arg2)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "%" PRIuMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_L:
+ if(arg1 >= arg2)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "%" PRIuMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if(arg1 > arg2)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "%" PRIuMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+void simple_test_assert_hex(char *sarg1, char *sarg2,
+ uintmax_t arg1, uintmax_t arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(!(arg2))
+ SIMPLE_TEST_FAIL("unexpected 0 value", file, line,
+ "%" PRIxMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if(arg1 != arg2)
+ SIMPLE_TEST_FAIL("uint values do not match", file, line,
+ "%" PRIxMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if(arg1 == arg2)
+ SIMPLE_TEST_FAIL("uint values match", file, line,
+ "%" PRIxMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_G:
+ if(arg1 <= arg2)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "%" PRIxMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if(arg1 < arg2)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "%" PRIxMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_L:
+ if(arg1 >= arg2)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "%" PRIxMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if(arg1 > arg2)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "%" PRIxMAX, sarg1, sarg2, arg1, arg2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+void simple_test_assert_float(char *sarg1, char *sarg2,
+ long double arg1, long double arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(!(arg2))
+ SIMPLE_TEST_FAIL("unexpected 0 value", file, line,
+ "%Lg", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if(arg1 != arg2)
+ SIMPLE_TEST_FAIL("float values do not match", file, line,
+ "%Lg", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if(arg1 == arg2)
+ SIMPLE_TEST_FAIL("float values match", file, line,
+ "%Lg", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_G:
+ if(arg1 <= arg2)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "%Lg", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if(arg1 < arg2)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "%Lg", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_L:
+ if(arg1 >= arg2)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "%Lg", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if(arg1 > arg2)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "%Lg", sarg1, sarg2, arg1, arg2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+void simple_test_assert_ptr(char *sarg1, char *sarg2,
+ void *arg1, void *arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(arg2 == NULL)
+ SIMPLE_TEST_FAIL("unexpected NULL value", file, line,
+ "%p", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if(arg1 != arg2)
+ SIMPLE_TEST_FAIL("pointer values do not match", file, line,
+ "%p", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if(arg1 == arg2)
+ SIMPLE_TEST_FAIL("pointer values match", file, line,
+ "%p", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_G:
+ if(arg1 <= arg2)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "%p", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if(arg1 < arg2)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "%p", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_L:
+ if(arg1 >= arg2)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "%p", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if(arg1 > arg2)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "%p", sarg1, sarg2, arg1, arg2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+void simple_test_assert_char(char *sarg1, char *sarg2,
+ char arg1, char arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ char buf1[3];
+ char buf2[3];
+ simple_test_get_escape(arg1, buf1);
+ simple_test_get_escape(arg2, buf2);
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(arg2 == '\0')
+ SIMPLE_TEST_FAIL("unexpected '\\0' value", file, line,
+ "‘%s’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if(arg1 != arg2)
+ SIMPLE_TEST_FAIL("char values do not match", file, line,
+ "‘%s’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if(arg1 == arg2)
+ SIMPLE_TEST_FAIL("char values match", file, line,
+ "‘%s’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_G:
+ if(arg1 <= arg2)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "‘%s’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if(arg1 < arg2)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "‘%s’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_L:
+ if(arg1 >= arg2)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "‘%s’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if(arg1 > arg2)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "‘%s’", sarg1, sarg2, buf1, buf2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+void simple_test_assert_str(char *sarg1, char *sarg2,
+ char *arg1, char *arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(arg2 == NULL)
+ SIMPLE_TEST_FAIL("unexpected NULL string", file, line,
+ "‘%s’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if( strcmp(arg1, arg2) )
+ SIMPLE_TEST_FAIL("strings do not match", file, line,
+ "‘%s’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if( !strcmp(arg1, arg2) )
+ SIMPLE_TEST_FAIL("strings match", file, line,
+ "‘%s’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_G:
+ if( strcmp(arg1, arg2) <= 0)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "‘%s’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if( strcmp(arg1, arg2) < 0)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "‘%s’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_L:
+ if( strcmp(arg1, arg2) >= 0)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "‘%s’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if( strcmp(arg1, arg2) > 0)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "‘%s’", sarg1, sarg2, arg1, arg2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+void simple_test_assert_wchar(char *sarg1, char *sarg2,
+ wchar_t arg1, wchar_t arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ wchar_t buf1[3];
+ wchar_t buf2[3];
+ simple_test_get_escape_wide(arg1, buf1);
+ simple_test_get_escape_wide(arg2, buf2);
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(arg2 == L'\0')
+ SIMPLE_TEST_FAIL("unexpected '\\0' value", file, line,
+ "‘%ls’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if(arg1 != arg2)
+ SIMPLE_TEST_FAIL("char values do not match", file, line,
+ "‘%ls’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if(arg1 == arg2)
+ SIMPLE_TEST_FAIL("char values match", file, line,
+ "‘%ls’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_G:
+ if(arg1 <= arg2)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "‘%ls’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if(arg1 < arg2)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "‘%ls’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_L:
+ if(arg1 >= arg2)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "‘%ls’", sarg1, sarg2, buf1, buf2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if(arg1 > arg2)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "‘%ls’", sarg1, sarg2, buf1, buf2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+void simple_test_assert_wstr(char *sarg1, char *sarg2,
+ wchar_t *arg1, wchar_t *arg2,
+ const char *file, const int line, simple_test_cond_t cond)
+{
+ switch(cond) {
+ case SIMPLE_TEST_TRUE:
+ if(arg2 == NULL)
+ SIMPLE_TEST_FAIL("unexpected NULL string", file, line,
+ "‘%ls’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_EQ:
+ if( wcscmp(arg1, arg2) )
+ SIMPLE_TEST_FAIL("strings do not match", file, line,
+ "‘%ls’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_NEQ:
+ if( !wcscmp(arg1, arg2) )
+ SIMPLE_TEST_FAIL("strings match", file, line,
+ "‘%ls’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_G:
+ if( wcscmp(arg1, arg2) <= 0)
+ SIMPLE_TEST_FAIL("arg1 <= arg2", file, line,
+ "‘%ls’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_GEQ:
+ if( wcscmp(arg1, arg2) < 0)
+ SIMPLE_TEST_FAIL("arg1 < arg2", file, line,
+ "‘%ls’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_L:
+ if( wcscmp(arg1, arg2) >= 0)
+ SIMPLE_TEST_FAIL("arg1 >= arg2", file, line,
+ "‘%ls’", sarg1, sarg2, arg1, arg2);
+ break;
+ case SIMPLE_TEST_LEQ:
+ if( wcscmp(arg1, arg2) > 0)
+ SIMPLE_TEST_FAIL("arg1 > arg2", file, line,
+ "‘%ls’", sarg1, sarg2, arg1, arg2);
+ break;
+ default:
+ SIMPLE_TEST_INTERN_ERR();
+ }
+}
+
+#define SIMPLE_TEST_GENERIC_CAST(arg) \
+ _Generic((arg), \
+ int8_t: (intmax_t)(arg), int16_t: (intmax_t)(arg), int32_t: (intmax_t)(arg), \
+ int64_t: (intmax_t)(arg), \
+ uint8_t: (uintmax_t)(arg), uint16_t: (uintmax_t)(arg), uint32_t: (uintmax_t)(arg), \
+ uint64_t: (uintmax_t)(arg), \
+ float: (long double)(arg), double: (long double)(arg), \
+ long double: (long double)(arg) \
+ )
+
+#define SIMPLE_TEST_GENERIC_NOT(arg) \
+ _Generic((arg), \
+ int8_t: 0, int16_t: 0, int32_t: 0, int64_t: 0, \
+ uint8_t: 0, uint16_t: 0, uint32_t: 0, uint64_t: 0, \
+ float: 0.0, double: 0.0, \
+ long double: 0.0 \
+ )
+
+#define SIMPLE_TEST_GENERIC_NOT_STR(arg) \
+ _Generic((arg), \
+ int8_t: "0", int16_t: "0", int32_t: "0", int64_t: "0", \
+ uint8_t: "0", uint16_t: "0", uint32_t: "0", uint64_t: "0", \
+ float: "0.0", double: "0.0", \
+ long double: "0.0" \
+ )
+
+#define SIMPLE_TEST_GENERIC_FUNCCALL(sarg1, sarg2, arg1, arg2, cond) \
+ _Generic((arg2), \
+ int8_t: simple_test_assert_int, int16_t: simple_test_assert_int, \
+ int32_t: simple_test_assert_int, int64_t: simple_test_assert_int, \
+ uint8_t: simple_test_assert_uint, uint16_t: simple_test_assert_uint, \
+ uint32_t: simple_test_assert_uint, uint64_t: simple_test_assert_uint, \
+ float: simple_test_assert_float, double: simple_test_assert_float, \
+ long double: simple_test_assert_float \
+ )(sarg1, sarg2, SIMPLE_TEST_GENERIC_CAST(arg1), \
+ SIMPLE_TEST_GENERIC_CAST(arg2), __FILE__, __LINE__, cond)
+
/**********************
@@ -155,7 +615,7 @@ do { \
/* the whole thing is inside one
* big function. yay! */
#define BEGIN_TEST \
-int _test_count_current=1; \
+int simple_test_count_current=1; \
int main(int argc, char *argv[]) \
{ \
printf("\e[1m" __FILE__ "\n");
@@ -167,7 +627,7 @@ int main(int argc, char *argv[]) \
}
#define TEST(description) \
-printf("\e[1m%3i :: \e[m\e[33m%s\e[m\n", _test_count_current++, description);
+printf("\e[1m%3i :: \e[m\e[33m%s\e[m\n", simple_test_count_current++, description);
/* pretty printing for the current state within
* a test */
@@ -179,548 +639,355 @@ do { \
} while(0)
-/***********
- * TESTS *
- ***********/
-
-#define EXPECT_NULL(arg) \
-do { \
- if((arg) != NULL) \
- _TEST_FAIL_VAL("NULL value", "%s", "%p", "NULL", (void*)(arg)); \
-} while(0);
-
-#define EXPECT_NON_NULL(arg) \
-do { \
- if((arg) == NULL) \
- _TEST_FAIL_VAL("non NULL value", "%s", "%p", "non NULL", (void*)(arg)); \
-} while(0);
-
-#define EXPECT_PNT(arg1, arg2) \
-do { \
- 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_PNT_G(arg1, arg2) \
-do { \
- if((arg1) <= (arg2)) \
- _TEST_FAIL_VAL(#arg1 "<=" #arg2, "> %p", "%p", arg1, arg2); \
-} while(0);
-
-#define EXPECT_PNT_GEQ(arg1, arg2) \
-do { \
- if((arg1) < (arg2)) \
- _TEST_FAIL_VAL(#arg1 "<" #arg2, ">= %p", "%p", arg1, arg2); \
-} while(0);
-
-#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("unexpected value", "0x%X", "0x%X", arg1, arg2); \
-} while(0);
-
-#define EXPECT_HEX_EQ(arg1, arg2) \
-do { \
- if((arg1) != (arg2)) \
- _TEST_FAIL_EQ("values do not match", "0x%X", "0x%X", arg1, arg2); \
-} while(0);
-
-#define EXPECT_HEX_NEQ(arg1, arg2) \
-do { \
- if((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_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("unexpected string value", "‘%s’", "‘%s’", arg1, arg2); \
-} while(0);
-
-#define EXPECT_STR_EQ(arg1, arg2) \
-do { \
- if( strcmp(arg1, arg2) ) \
- _TEST_FAIL_EQ("strings unequal", "‘%s’", "‘%s’", arg1, arg2); \
-} while(0);
-
-#define EXPECT_STR_NEQ(arg1, arg2) \
-do { \
- if( !strcmp(arg1, arg2) ) \
- _TEST_FAIL_EQ("strings equal", "‘%s’", "‘%s’", arg1, arg2); \
-} while(0);
-
-#define EXPECT_WCHAR(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_VAL_REAL("unexpected wchar value", \
- "‘%ls’", "‘%ls’", #arg1, #arg2, _test_buf1, _test_buf2); \
- } \
-} while(0);
-
-#define EXPECT_WCHAR_EQ(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 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);
+/************************
+ * TYPE-GENERIC TESTS *
+ ************************/
+
+#define ASSERT(arg) \
+ SIMPLE_TEST_GENERIC_FUNCCALL(SIMPLE_TEST_GENERIC_NOT_STR(arg), #arg, \
+ SIMPLE_TEST_GENERIC_NOT(arg), arg, SIMPLE_TEST_TRUE)
+
+#define ASSERT_EQ(arg1, arg2) \
+ SIMPLE_TEST_GENERIC_FUNCCALL(#arg1, #arg2, \
+ arg1, arg2, SIMPLE_TEST_EQ)
+
+#define ASSERT_NEQ(arg1, arg2) \
+ SIMPLE_TEST_GENERIC_FUNCCALL(#arg1, #arg2, \
+ arg1, arg2, SIMPLE_TEST_NEQ)
+
+#define ASSERT_G(arg1, arg2) \
+ SIMPLE_TEST_GENERIC_FUNCCALL(#arg1, #arg2, \
+ arg1, arg2, SIMPLE_TEST_G)
+
+#define ASSERT_GEQ(arg1, arg2) \
+ SIMPLE_TEST_GENERIC_FUNCCALL(#arg1, #arg2, \
+ arg1, arg2, SIMPLE_TEST_GEQ)
+
+#define ASSERT_L(arg1, arg2) \
+ SIMPLE_TEST_GENERIC_FUNCCALL(#arg1, #arg2, \
+ arg1, arg2, SIMPLE_TEST_L)
+
+#define ASSERT_LEQ(arg1, arg2) \
+ SIMPLE_TEST_GENERIC_FUNCCALL(#arg1, #arg2, \
+ arg1, arg2, SIMPLE_TEST_LEQ)
+
+/*************************
+ * TYPE-SPECIFIC TESTS *
+ *************************/
+
+#define ASSERT_INT(arg) \
+ simple_test_assert_int("0", #arg, \
+ (intmax_t)0, (intmax_t)(arg), \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_INT_EQ(arg1, arg2) \
+ simple_test_assert_int(#arg1, #arg2, \
+ (intmax_t)(arg1), (intmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_INT_NEQ(arg1, arg2) \
+ simple_test_assert_int(#arg1, #arg2, \
+ (intmax_t)(arg1), (intmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_INT_G(arg1, arg2) \
+ simple_test_assert_int(#arg1, #arg2, \
+ (intmax_t)(arg1), (intmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_INT_GEQ(arg1, arg2) \
+ simple_test_assert_int(#arg1, #arg2, \
+ (intmax_t)(arg1), (intmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_INT_L(arg1, arg2) \
+ simple_test_assert_int(#arg1, #arg2, \
+ (intmax_t)(arg1), (intmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_INT_LEQ(arg1, arg2) \
+ simple_test_assert_int(#arg1, #arg2, \
+ (intmax_t)(arg1), (intmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
+
+#define ASSERT_UINT(arg) \
+ simple_test_assert_uint("0", #arg, \
+ (uintmax_t)0, (uintmax_t)(arg), \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_UINT_EQ(arg1, arg2) \
+ simple_test_assert_uint(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_UINT_NEQ(arg1, arg2) \
+ simple_test_assert_uint(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_UINT_G(arg1, arg2) \
+ simple_test_assert_uint(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_UINT_GEQ(arg1, arg2) \
+ simple_test_assert_uint(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_UINT_L(arg1, arg2) \
+ simple_test_assert_uint(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_UINT_LEQ(arg1, arg2) \
+ simple_test_assert_uint(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
+
+#define ASSERT_HEX(arg) \
+ simple_test_assert_uint("0", #arg, \
+ (uintmax_t)0, (uintmax_t)(arg), \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_HEX_EQ(arg1, arg2) \
+ simple_test_assert_uint(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_HEX_NEQ(arg1, arg2) \
+ simple_test_assert_hex(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_HEX_G(arg1, arg2) \
+ simple_test_assert_hex(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_HEX_GEQ(arg1, arg2) \
+ simple_test_assert_hex(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_HEX_L(arg1, arg2) \
+ simple_test_assert_hex(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_HEX_LEQ(arg1, arg2) \
+ simple_test_assert_hex(#arg1, #arg2, \
+ (uintmax_t)(arg1), (uintmax_t)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
+
+#define ASSERT_FLOAT(arg) \
+ simple_test_assert_float("0", #arg, \
+ (long double)0, (long double)(arg), \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_FLOAT_EQ(arg1, arg2) \
+ simple_test_assert_float(#arg1, #arg2, \
+ (long double)(arg1), (long double)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_FLOAT_NEQ(arg1, arg2) \
+ simple_test_assert_float(#arg1, #arg2, \
+ (long double)(arg1), (long double)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_FLOAT_G(arg1, arg2) \
+ simple_test_assert_float(#arg1, #arg2, \
+ (long double)(arg1), (long double)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_FLOAT_GEQ(arg1, arg2) \
+ simple_test_assert_float(#arg1, #arg2, \
+ (long double)(arg1), (long double)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_FLOAT_L(arg1, arg2) \
+ simple_test_assert_float(#arg1, #arg2, \
+ (long double)(arg1), (long double)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_FLOAT_LEQ(arg1, arg2) \
+ simple_test_assert_float(#arg1, #arg2, \
+ (long double)(arg1), (long double)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
+
+#define ASSERT_PTR(arg) \
+ simple_test_assert_ptr("NULL", #arg, \
+ NULL, (void *)(arg), \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_PTR_EQ(arg1, arg2) \
+ simple_test_assert_ptr(#arg1, #arg2, \
+ (void *)(arg1), (void *)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_PTR_NEQ(arg1, arg2) \
+ simple_test_assert_ptr(#arg1, #arg2, \
+ (void *)(arg1), (void *)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_PTR_G(arg1, arg2) \
+ simple_test_assert_ptr(#arg1, #arg2, \
+ (void *)(arg1), (void *)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_PTR_GEQ(arg1, arg2) \
+ simple_test_assert_ptr(#arg1, #arg2, \
+ (void *)(arg1), (void *)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_PTR_L(arg1, arg2) \
+ simple_test_assert_ptr(#arg1, #arg2, \
+ (void *)(arg1), (void *)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_PTR_LEQ(arg1, arg2) \
+ simple_test_assert_ptr(#arg1, #arg2, \
+ (void *)(arg1), (void *)(arg2), \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
+
+#define ASSERT_CHAR(arg) \
+ simple_test_assert_char("\\0", #arg, \
+ '\0', arg, \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_CHAR_EQ(arg1, arg2) \
+ simple_test_assert_char(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_CHAR_NEQ(arg1, arg2) \
+ simple_test_assert_char(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_CHAR_G(arg1, arg2) \
+ simple_test_assert_char(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_CHAR_GEQ(arg1, arg2) \
+ simple_test_assert_char(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_CHAR_L(arg1, arg2) \
+ simple_test_assert_char(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_CHAR_LEQ(arg1, arg2) \
+ simple_test_assert_char(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
+
+#define ASSERT_STR(arg) \
+ simple_test_assert_str("0", #arg, \
+ 0, (arg), \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_STR_EQ(arg1, arg2) \
+ simple_test_assert_str(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_STR_NEQ(arg1, arg2) \
+ simple_test_assert_str(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_STR_G(arg1, arg2) \
+ simple_test_assert_str(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_STR_GEQ(arg1, arg2) \
+ simple_test_assert_str(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_STR_L(arg1, arg2) \
+ simple_test_assert_str(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_STR_LEQ(arg1, arg2) \
+ simple_test_assert_str(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
+
+#define ASSERT_WCHAR(arg) \
+ simple_test_assert_wchar("\\0", #arg, \
+ L'\0', arg, \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_WCHAR_EQ(arg1, arg2) \
+ simple_test_assert_wchar(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_WCHAR_NEQ(arg1, arg2) \
+ simple_test_assert_wchar(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_WCHAR_G(arg1, arg2) \
+ simple_test_assert_wchar(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_WCHAR_GEQ(arg1, arg2) \
+ simple_test_assert_wchar(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_WCHAR_L(arg1, arg2) \
+ simple_test_assert_wchar(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_WCHAR_LEQ(arg1, arg2) \
+ simple_test_assert_wchar(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
+
+#define ASSERT_WSTR(arg) \
+ simple_test_assert_wstr("0", #arg, \
+ 0, (arg), \
+ __FILE__, __LINE__, SIMPLE_TEST_TRUE)
+
+#define ASSERT_WSTR_EQ(arg1, arg2) \
+ simple_test_assert_wstr(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_EQ)
+
+#define ASSERT_WSTR_NEQ(arg1, arg2) \
+ simple_test_assert_wstr(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_NEQ)
+
+#define ASSERT_WSTR_G(arg1, arg2) \
+ simple_test_assert_wstr(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_G)
+
+#define ASSERT_WSTR_GEQ(arg1, arg2) \
+ simple_test_assert_wstr(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_GEQ)
+
+#define ASSERT_WSTR_L(arg1, arg2) \
+ simple_test_assert_wstr(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_L)
+
+#define ASSERT_WSTR_LEQ(arg1, arg2) \
+ simple_test_assert_wstr(#arg1, #arg2, \
+ arg1, arg2, \
+ __FILE__, __LINE__, SIMPLE_TEST_LEQ)
#endif