2018-01-01 09:26:34 +01:00
|
|
|
#ifndef TESTS_H
|
|
|
|
#define TESTS_H
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
2018-03-19 21:07:18 +01:00
|
|
|
#include <assert.h>
|
2018-05-06 13:11:03 +02:00
|
|
|
#include <wchar.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2018-01-01 09:26:34 +01:00
|
|
|
|
|
|
|
#define WHEN(...)
|
|
|
|
#define THEN(...)
|
2018-03-20 18:57:50 +01:00
|
|
|
#define SCENARIO(...)
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2019-08-29 08:12:58 +02:00
|
|
|
#if !defined(FT_CONGIG_DISABLE_WCHAR)
|
2018-05-06 13:11:03 +02:00
|
|
|
#define FT_HAVE_WCHAR
|
|
|
|
#endif
|
|
|
|
|
2018-05-06 16:04:34 +02:00
|
|
|
struct test_case {
|
2018-03-17 19:53:38 +01:00
|
|
|
char name [128];
|
2018-03-19 21:07:18 +01:00
|
|
|
void (*test)(void);
|
2018-03-17 19:53:38 +01:00
|
|
|
};
|
|
|
|
|
2018-03-19 21:07:18 +01:00
|
|
|
/*
|
|
|
|
* Test utility funcitons
|
|
|
|
*/
|
|
|
|
|
2018-03-17 19:53:38 +01:00
|
|
|
#define assert_true(args) assert(args)
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2019-08-10 10:40:12 +02:00
|
|
|
#define d_assert_str_equal(description, str1, str2) \
|
2018-03-23 19:16:06 +01:00
|
|
|
if (strcmp(str1, str2) != 0) \
|
|
|
|
{ \
|
2019-08-10 10:40:12 +02:00
|
|
|
fprintf(stderr, "%s:%d(%s):Abort! %s failed. Not equals strings:\n",__FILE__,__LINE__, __func__, description); \
|
2018-11-02 14:00:58 +01:00
|
|
|
fprintf(stderr, "Left string(len = %d):\n%s\n", (int)strlen(str1), str1); \
|
|
|
|
fprintf(stderr, "Right string(len = %d):\n%s\n", (int)strlen(str2), str2); \
|
2018-03-23 19:16:06 +01:00
|
|
|
exit(EXIT_FAILURE); \
|
|
|
|
}
|
|
|
|
|
2019-08-10 10:40:12 +02:00
|
|
|
#define assert_str_equal(str1, str2) \
|
|
|
|
d_assert_str_equal("Test", str1, str2)
|
|
|
|
|
2018-03-23 19:16:06 +01:00
|
|
|
#define assert_wcs_equal(str1, str2) \
|
|
|
|
if (wcscmp(str1, str2) != 0) \
|
|
|
|
{ \
|
2018-05-08 20:46:24 +02:00
|
|
|
fprintf(stderr, "%s:%d(%s):Abort! Not equals strings:\n",__FILE__,__LINE__, __func__); \
|
2018-03-23 19:16:06 +01:00
|
|
|
setlocale(LC_CTYPE, ""); \
|
2018-11-02 14:00:58 +01:00
|
|
|
fwprintf(stdout, L"Left string(len = %d):\n%ls\n", (int)wcslen(str1), str1); \
|
|
|
|
fwprintf(stdout, L"Right string(len = %d):\n%ls\n", (int)wcslen(str2), str2); \
|
2018-03-31 12:33:37 +02:00
|
|
|
fflush(stdout); \
|
2018-03-23 19:16:06 +01:00
|
|
|
exit(EXIT_FAILURE); \
|
2018-03-24 15:01:29 +01:00
|
|
|
}
|
|
|
|
|
2018-11-21 18:50:56 +01:00
|
|
|
#define assert_string_equal(str1, str2) assert_str_equal(str1.c_str(), str2.c_str())
|
|
|
|
|
2018-11-24 21:14:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2018-07-25 21:37:10 +02:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
2018-12-29 16:32:40 +01:00
|
|
|
void run_test_suite(const char *test_suite_name, int n_tests, struct test_case test_suite[]);
|
2018-07-25 21:37:10 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2018-03-23 19:16:06 +01:00
|
|
|
|
2018-11-24 21:14:26 +01:00
|
|
|
|
2018-01-01 09:26:34 +01:00
|
|
|
#endif // TESTS_H
|