7684972a |
/* Copyright (C) CJ Affiliate
*
* You may use, distribute and modify this code under the
* terms of the GNU General Public License version 2 or
* later.
*
* You should have received a copy of the license with this
* file. If not, you will find a copy in the "LICENSE" file
* at https://github.com/cjdev/dual-control.
*/
|
a26b1d7c |
#ifndef _TESTUTIL_H
#define _TESTUTIL_H
|
8ab94c71 |
#include <cstring>
#include <cstdio>
|
1f796eb6 |
#define RESET_COLORS "\x1b[0m"
#define FOREGROUND_GREEN "\x1b[32m"
#define FOREGROUND_RED "\x1b[31m"
|
a26b1d7c |
#define check(assertion, msg) \
if (!(assertion)) { \
|
1f796eb6 |
fprintf(stderr, "> assertion failed: %s\n", msg); \
|
a26b1d7c |
return 0; \
}
#define checkint(expected, actual, name) \
check(expected == actual, name " should be " #expected)
#define checkstr(expected, actual, name) \
|
469d5639 |
check(!strcmp(expected, actual), name " should be '" expected "'")
|
a26b1d7c |
|
704ed597 |
#define RESET_VARS_START void __reset_vars() {
#define RESET_VARS_END }
|
d509a3b6 |
|
e4bb67f3 |
#define test(NAME) \
{ \
|
9b03a29b |
int result = NAME (); \
if (!result) { \
|
1f796eb6 |
fprintf(stderr, "%s! <%s:%d> test failed: %s\n%s", FOREGROUND_RED, __FILE__, __LINE__, #NAME, RESET_COLORS); \
|
4da6e6f4 |
return 0; \
|
9b03a29b |
} else { \
|
1f796eb6 |
fprintf (stderr, "%s> test passed: %s\n%s", FOREGROUND_GREEN, #NAME, RESET_COLORS); \
|
9b03a29b |
} \
|
e69a107b |
fflush(stderr); \
|
e4bb67f3 |
}
|
a26b1d7c |
#define succeed() return 1
|
035722d8 |
#define fail(MSG) {\
fprintf(stderr, "%s! <%s:%d> test failed: %s\n%s", FOREGROUND_RED, __FILE__, __LINE__, MSG, RESET_COLORS); \
return 0; \
}
|
a26b1d7c |
#endif
|
88c14201 |
|