2020-01-20 16:22:37 -06:00
|
|
|
// 27 february 2018
|
2020-01-20 19:52:46 -06:00
|
|
|
#include <inttypes.h>
|
2020-01-20 16:22:37 -06:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "../ui.h"
|
2020-01-20 19:52:46 -06:00
|
|
|
#ifdef libuiOSHeader
|
|
|
|
#include libuiOSHeader
|
2020-01-20 16:22:37 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define testingprivImplName(basename) testingprivImpl ## basename
|
2020-01-20 19:49:33 -06:00
|
|
|
#define testingprivScaffoldName(basename) testingprivScaffold ## basename
|
|
|
|
|
2020-01-20 16:22:37 -06:00
|
|
|
// references:
|
|
|
|
// - https://gitlab.gnome.org/GNOME/glib/blob/master/glib/gconstructor.h
|
|
|
|
// - https://gitlab.gnome.org/GNOME/glib/blob/master/gio/glib-compile-resources.c
|
|
|
|
// - https://msdn.microsoft.com/en-us/library/bb918180.aspx
|
|
|
|
#define testingprivCtorName(basename) testingprivCtor ## basename
|
|
|
|
#define testingprivCtorPtrName(basename) testingprivCtorPtr ## basename
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define testingprivMkCtor(basename) \
|
2020-01-20 19:49:33 -06:00
|
|
|
__attribute__((constructor)) static void testingprivCtorName(basename)(void) { testingprivRegisterTest(#basename, testingprivScaffoldName(basename)); }
|
2020-01-20 16:22:37 -06:00
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#define testingprivMkCtor(basename) \
|
2020-01-20 19:49:33 -06:00
|
|
|
static int testingprivCtorName(basename)(void) { testingprivRegisterTest(#basename, testingprivScaffoldName(basename)); return 0; } \
|
2020-01-20 16:22:37 -06:00
|
|
|
__pragma(section(".CRT$XCU",read)) \
|
|
|
|
__declspec(allocate(".CRT$XCU")) static int (*testingprivCtorPtrName(basename))(void) = testingprivCtorName(basename);
|
|
|
|
#elif defined(__SUNPRO_C)
|
|
|
|
#define testingprivMkCtor(basename) \
|
2020-01-20 19:49:33 -06:00
|
|
|
static void testingprivCtorName(basename)(void) { testingprivRegisterTest(#basename, testingprivScaffoldName(basename)); } \
|
2020-01-20 16:22:37 -06:00
|
|
|
_Pragma(init(testingprivCtorName(basename)))
|
|
|
|
#else
|
|
|
|
#error unknown compiler for making constructors in C; cannot continue
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define Test(Name) \
|
2020-01-23 09:52:41 -06:00
|
|
|
void testingprivImplName(Test ## Name)(void); \
|
|
|
|
static void testingprivScaffoldName(Test ## Name)(void) \
|
2020-01-21 00:16:47 -06:00
|
|
|
{ \
|
|
|
|
uiInitError err; \
|
|
|
|
memset(&err, 0, sizeof (uiInitError)); \
|
|
|
|
err.Size = sizeof (uiInitError); \
|
|
|
|
if (!uiInit(NULL, &err)) { \
|
|
|
|
fprintf(stderr, "error initializing libui for Test" #Name ": %s\n", err.Message); \
|
2020-01-23 09:52:41 -06:00
|
|
|
TestFailNow(); \
|
2020-01-21 00:16:47 -06:00
|
|
|
} \
|
2020-01-23 09:52:41 -06:00
|
|
|
testingprivImplName(Test ## Name)(); \
|
2020-01-21 00:16:47 -06:00
|
|
|
} \
|
|
|
|
testingprivMkCtor(Test ## Name) \
|
2020-01-23 09:52:41 -06:00
|
|
|
void testingprivImplName(Test ## Name)(void)
|
2020-01-21 00:16:47 -06:00
|
|
|
|
|
|
|
#define TestNoInit(Name) \
|
2020-01-23 09:52:41 -06:00
|
|
|
void testingprivImplName(Test ## Name)(void); \
|
|
|
|
static void testingprivScaffoldName(Test ## Name)(void) \
|
2020-01-21 00:16:47 -06:00
|
|
|
{ \
|
2020-01-23 09:52:41 -06:00
|
|
|
testingprivImplName(Test ## Name)(); \
|
2020-01-21 00:16:47 -06:00
|
|
|
} \
|
|
|
|
testingprivMkCtor(Test ## Name) \
|
2020-01-23 09:52:41 -06:00
|
|
|
void testingprivImplName(Test ## Name)(void)
|
2020-01-20 16:22:37 -06:00
|
|
|
|
2020-01-23 09:52:41 -06:00
|
|
|
extern void TestFail(void);
|
|
|
|
extern void TestFailNow(void);
|
|
|
|
extern void TestSkipNow(void);
|
2020-01-20 19:49:33 -06:00
|
|
|
|
|
|
|
#define TestLogf(...) \
|
2020-01-23 09:52:41 -06:00
|
|
|
(testingprivLogfFullThen(stdout, NULL, __FILE__, __LINE__, __VA_ARGS__))
|
2020-01-20 19:49:33 -06:00
|
|
|
#define TestErrorf(...) \
|
2020-01-23 09:52:41 -06:00
|
|
|
(testingprivLogfFullThen(stderr, TestFail, __FILE__, __LINE__, __VA_ARGS__))
|
2020-01-20 19:49:33 -06:00
|
|
|
#define TestFatalf(...) \
|
2020-01-23 09:52:41 -06:00
|
|
|
(testingprivLogfFullThen(stderr, TestFailNow, __FILE__, __LINE__, __VA_ARGS__))
|
2020-01-20 19:49:33 -06:00
|
|
|
// TODO remember if this needs to go to stdout or to stderr
|
|
|
|
#define TestSkipf(...) \
|
2020-01-23 09:52:41 -06:00
|
|
|
(testingprivLogfFullThen(stderr, TestSkipNow, __FILE__, __LINE__, __VA_ARGS__))
|
2020-01-20 16:22:37 -06:00
|
|
|
|
2020-01-23 09:52:41 -06:00
|
|
|
extern void testingprivRegisterTest(const char *name, void (*f)(void));
|
2020-01-20 19:49:33 -06:00
|
|
|
#include "../sharedbits/printfwarn_header.h"
|
|
|
|
sharedbitsPrintfFunc(
|
2020-01-23 09:52:41 -06:00
|
|
|
extern void testingprivLogfFullThen(FILE *f, void (*then)(void), const char *filename, long line, const char *fmt, ...),
|
|
|
|
5, 6);
|
2020-01-20 19:49:33 -06:00
|
|
|
#undef sharedbitsPrintfFunc
|
2020-01-20 16:22:37 -06:00
|
|
|
|
2020-01-20 19:52:46 -06:00
|
|
|
// end of test framework definitions
|
|
|
|
|
|
|
|
#define diff(fmt) "\ngot " fmt "\nwant " fmt
|
|
|
|
|
2020-01-20 16:22:37 -06:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|