From 47e1ee496e7cd9409b281dcd422f2dde16aecf00 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 8 Feb 2020 00:25:39 +0100 Subject: [PATCH] tests: build for win32 --- src/Makefile | 2 ++ src/tests/testmain.c | 22 ++++++++++++++++++++++ src/tests/tests.c | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/src/Makefile b/src/Makefile index b00bf2c1..d4124768 100644 --- a/src/Makefile +++ b/src/Makefile @@ -107,6 +107,7 @@ ifdef COMSPEC RMDIR = rmdir --ignore-fail-on-non-empty CP = cp BIN = ../bin/grafx2-$(API).exe + TESTSBIN = ../bin/tests-$(API).exe GENERATEDOCBIN = ../bin/generatedoc.exe COPT = -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -g -ggdb COPT += $(LUACOPT) @@ -502,6 +503,7 @@ endif CROSS_STRIP ?= $(shell which i686-w64-mingw32-strip || which mingw32-strip) STRIP = $(CROSS_STRIP) BIN = ../bin/grafx2-$(API).exe + TESTSBIN = ../bin/tests-$(API).exe COPT = -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -g -ggdb $(TTFCOPT) LOPT = -mwindows -lmingw32 -lshlwapi -lmpr $(TTFLOPT) ifeq ($(API),sdl) diff --git a/src/tests/testmain.c b/src/tests/testmain.c index b49e23a9..74ebaa87 100644 --- a/src/tests/testmain.c +++ b/src/tests/testmain.c @@ -37,6 +37,28 @@ #include "../gfx2log.h" #include "tests.h" +// random()/srandom() not available with mingw32 +#if defined(WIN32) +#define srandom srand +#endif + + +// mkdtemp() not available with mingw32 +#if defined(WIN32) +#define mkdtemp my_mkdtemp + +char * my_mkdtemp(char *template) +{ + char * p = strstr(template, "XXXXXX"); + if (p == NULL) + return NULL; + snprintf(p, 7, "%06x", rand()); + if (!CreateDirectoryA(template, NULL)) + return NULL; + return template; +} +#endif + #ifdef ENABLE_FILENAMES_ICONV iconv_t cd; // FROMCODE => TOCODE iconv_t cd_inv; // TOCODE => FROMCODE diff --git a/src/tests/tests.c b/src/tests/tests.c index 908e2549..920c6ddc 100644 --- a/src/tests/tests.c +++ b/src/tests/tests.c @@ -36,6 +36,11 @@ #include "../packbits.h" #include "../gfx2log.h" +// random()/srandom() not available with mingw32 +#if defined(WIN32) +#define random (long)rand +#endif + unsigned int MOTO_MAP_pack(byte * packed, const byte * unpacked, unsigned int unpacked_len); /**