From 4880b55166dcc3b44ca18d850b99e13c9a75c368 Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Mon, 16 Jan 2023 10:47:13 +0100 Subject: [PATCH] windows: make most tests buildable and use C++ includes --- libticables/trunk/tests/test_ticables_2.cc | 8 +- libticables/trunk/tests/torture_ticables.c | 9 +- libticalcs/trunk/tests/test_ticalcs_2.cc | 113 ++++++++++++++++++++- libticalcs/trunk/tests/torture_ticalcs.c | 13 ++- libticonv/trunk/tests/test_ticonv.cc | 4 +- libticonv/trunk/tests/torture_ticonv.c | 21 ++-- libtifiles/trunk/tests/test_tifiles_2.cc | 15 +-- libtifiles/trunk/tests/torture_tifiles.c | 9 +- 8 files changed, 144 insertions(+), 48 deletions(-) diff --git a/libticables/trunk/tests/test_ticables_2.cc b/libticables/trunk/tests/test_ticables_2.cc index 80e7ff9d7..6ad8a4627 100644 --- a/libticables/trunk/tests/test_ticables_2.cc +++ b/libticables/trunk/tests/test_ticables_2.cc @@ -20,10 +20,10 @@ #include #endif -#include -#include -#include -#include +#include +#include +#include +#include #ifndef __WIN32__ #include #else diff --git a/libticables/trunk/tests/torture_ticables.c b/libticables/trunk/tests/torture_ticables.c index 2b03383fa..f8c443a9b 100644 --- a/libticables/trunk/tests/torture_ticables.c +++ b/libticables/trunk/tests/torture_ticables.c @@ -1,17 +1,16 @@ #include #include -#define PRINTF(FUNCTION, TYPE, args...) \ -fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(args)) +#define PRINTF(FUNCTION, TYPE, ...) \ +fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(__VA_ARGS__)) -#define PRINTFVOID(FUNCTION, args...) \ -FUNCTION(args); fprintf(stderr, "%d\n", __LINE__) +#define PRINTFVOID(FUNCTION, ...) \ +FUNCTION(__VA_ARGS__); fprintf(stderr, "%d\n", __LINE__) #define INT "%d" #define UINT "%u" #define PTR "%p" #define STR "\"%s\"" -#define VOID "" int main(int argc, char **argv) { diff --git a/libticalcs/trunk/tests/test_ticalcs_2.cc b/libticalcs/trunk/tests/test_ticalcs_2.cc index fd63e3c04..eab741b24 100644 --- a/libticalcs/trunk/tests/test_ticalcs_2.cc +++ b/libticalcs/trunk/tests/test_ticalcs_2.cc @@ -27,12 +27,115 @@ #include #endif -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + +#ifdef __WIN32__ +/* simple getopt implementation - https://gist.github.com/superwills/5815344 */ +/* +* Copyright (c) 1987, 1993, 1994 +* The Regents of the University of California. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* 3. All advertising materials mentioning features or use of this software +* must display the following acknowledgement: +* This product includes software developed by the University of +* California, Berkeley and its contributors. +* 4. Neither the name of the University nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +*/ + +static int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +static char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +int getopt(int nargc, char * const nargv[], const char *ostr) +{ + static char* place = (char*)EMSG; /* option letter processing */ + const char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = (char*)EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = (char*)EMSG; + return (-1); + } + } + /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)printf("illegal option -- %c\n", optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = (char*)EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)printf("option requires an argument -- %c\n", optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = (char*)EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} +#else #include +#endif // Happens for some reason on MinGW 64 32-bit GCC 8 toolchain. #ifndef SCNi8 diff --git a/libticalcs/trunk/tests/torture_ticalcs.c b/libticalcs/trunk/tests/torture_ticalcs.c index 71942a097..db1407337 100644 --- a/libticalcs/trunk/tests/torture_ticalcs.c +++ b/libticalcs/trunk/tests/torture_ticalcs.c @@ -12,17 +12,16 @@ #include #include "../src/error.h" -#define PRINTF(FUNCTION, TYPE, args...) \ -fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(args)) +#define PRINTF(FUNCTION, TYPE, ...) \ +fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(__VA_ARGS__)) -#define PRINTFVOID(FUNCTION, args...) \ -FUNCTION(args); fprintf(stderr, "%d\n", __LINE__) +#define PRINTFVOID(FUNCTION, ...) \ +FUNCTION(__VA_ARGS__); fprintf(stderr, "%d\n", __LINE__) #define INT "%d" #define UINT "%u" #define PTR "%p" #define STR "\"%s\"" -#define VOID "" static void torture_ticalcs(void) { @@ -539,6 +538,7 @@ static void torture_dbus(void) static void torture_cmdz80(void) { +#ifndef __WIN32__ // cmdz80.c PRINTF(ti73_send_VAR, INT, NULL, 0, 0, (void *)0x12345678, 0, 0); PRINTF(ti73_send_VAR, INT, (void *)0x12345678, 0, 0, NULL, 0, 0); @@ -664,10 +664,12 @@ static void torture_cmdz80(void) PRINTF(ti85_recv_RTS, INT, (void *)0x12345678, NULL, (void *)0x12345678, (void *)0x12345678); PRINTF(ti85_recv_RTS, INT, (void *)0x12345678, (void *)0x12345678, NULL, (void *)0x12345678); PRINTF(ti85_recv_RTS, INT, (void *)0x12345678, (void *)0x12345678, (void *)0x12345678, NULL); +#endif } static void torture_cmd68k(void) { +#ifndef __WIN32__ // cmd68k.c PRINTF(ti89_send_VAR, INT, NULL, 0, 0, (void *)0x12345678); PRINTF(ti89_send_CTS, INT, NULL); @@ -743,6 +745,7 @@ static void torture_cmd68k(void) PRINTF(ti92_recv_RTS, INT, (void *)0x12345678, NULL, (void *)0x12345678, (void *)0x12345678); PRINTF(ti92_recv_RTS, INT, (void *)0x12345678, (void *)0x12345678, NULL, (void *)0x12345678); PRINTF(ti92_recv_RTS, INT, (void *)0x12345678, (void *)0x12345678, (void *)0x12345678, NULL); +#endif } static void torture_romdump(void) diff --git a/libticonv/trunk/tests/test_ticonv.cc b/libticonv/trunk/tests/test_ticonv.cc index 6f1ee3030..ac84de976 100644 --- a/libticonv/trunk/tests/test_ticonv.cc +++ b/libticonv/trunk/tests/test_ticonv.cc @@ -28,8 +28,8 @@ #include #endif -#include -#include +#include +#include #include #ifdef __WIN32__ #include diff --git a/libticonv/trunk/tests/torture_ticonv.c b/libticonv/trunk/tests/torture_ticonv.c index a5a40d5da..c438575ad 100644 --- a/libticonv/trunk/tests/torture_ticonv.c +++ b/libticonv/trunk/tests/torture_ticonv.c @@ -7,11 +7,11 @@ #define str(s) #s #define xstr(s) str(s) -#define PRINTF(FUNCTION, TYPE, args...) \ -fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(args)) +#define PRINTF(FUNCTION, TYPE, ...) \ +fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(__VA_ARGS__)) -#define PRINTFVOID(FUNCTION, args...) \ -FUNCTION(args); fprintf(stderr, "%d\n", __LINE__) +#define PRINTFVOID(FUNCTION, ...) \ +FUNCTION(__VA_ARGS__); fprintf(stderr, "%d\n", __LINE__) #define INT "%d" #ifndef __WIN32__ @@ -21,7 +21,6 @@ FUNCTION(args); fprintf(stderr, "%d\n", __LINE__) #endif #define PTR "%p" #define STR "\"%s\"" -#define VOID "" static const uint16_t utf16_xbar[] = { 0x0078, 0x0305, 0x0000 }; static const uint16_t utf16_ybar[] = { 0x0079, 0x0305, 0x0000 }; @@ -63,11 +62,7 @@ int main(int argc, char **argv) ticonv_iconv_t ticonv_iconv_instance; // ticonv.h - PRINTF( -#ifdef __WIN32__ - (unsigned long) -#endif - ticonv_utf16_strlen, SIZE, NULL); + PRINTF(ticonv_utf16_strlen, SIZE, NULL); PRINTF(ticonv_utf8_to_utf16, PTR, NULL); PRINTFVOID(ticonv_utf16_free, NULL); PRINTF(ticonv_utf16_to_utf8, PTR, NULL); @@ -147,11 +142,7 @@ int main(int argc, char **argv) PRINTF(ticonv_environment_is_utf8, INT); PRINTF(ticonv_environment_has_utf8_filenames, INT); ticonv_iconv_instance = ticonv_iconv_open(NULL, NULL); - PRINTF( -#ifdef __WIN32__ - (unsigned long) -#endif - ticonv_iconv, SIZE, ticonv_iconv_instance, NULL, NULL, NULL, NULL); + PRINTF(ticonv_iconv, SIZE, ticonv_iconv_instance, NULL, NULL, NULL, NULL); PRINTF(ticonv_iconv_close, INT, ticonv_iconv_instance); // charset.h PRINTF(ticonv_ti73_to_utf16, PTR, NULL, (void *)0x12345678); diff --git a/libtifiles/trunk/tests/test_tifiles_2.cc b/libtifiles/trunk/tests/test_tifiles_2.cc index 3099a8ec4..16f967d6e 100644 --- a/libtifiles/trunk/tests/test_tifiles_2.cc +++ b/libtifiles/trunk/tests/test_tifiles_2.cc @@ -29,9 +29,9 @@ #endif #include -#include -#include -#include +#include +#include +#include #ifdef __WIN32__ #include #endif @@ -97,7 +97,7 @@ static int compare_files(const char *src, const char *dst) // Rename file static int move_file(const char *oldpath, const char *newpath) { -#if defined(__WIN32__) && !defined(__MINGW32__) +#if 0 && defined(__WIN32__) && !defined(__MINGW32__) return 0; #else return rename(oldpath, newpath); @@ -107,7 +107,7 @@ static int move_file(const char *oldpath, const char *newpath) // Set output directory static void change_dir(const char *path) { -#if defined(__WIN32__) && !defined(__MINGW32__) +#if 0 && defined(__WIN32__) && !defined(__MINGW32__) _chdir(path); #endif } @@ -115,7 +115,7 @@ static void change_dir(const char *path) // Build a portable path for Linux/Win32 static const char* PATH(const char *path) { -#if defined(__WIN32__) && !defined(__MINGW32__) +#if 0 && defined(__WIN32__) && !defined(__MINGW32__) static char str[1024]; unsigned int i; @@ -139,7 +139,7 @@ static const char* PATH(const char *path) // Build a portable path for Linux/Win32 static const char* PATH2(const char *path) { -#if defined(__WIN32__) && !defined(__MINGW32__) +#if 0 && defined(__WIN32__) && !defined(__MINGW32__) static char str[1024]; unsigned int i; @@ -152,6 +152,7 @@ static const char* PATH2(const char *path) { str[i] = '\\'; } + } return str; #else diff --git a/libtifiles/trunk/tests/torture_tifiles.c b/libtifiles/trunk/tests/torture_tifiles.c index 1c5a53df0..29584c051 100644 --- a/libtifiles/trunk/tests/torture_tifiles.c +++ b/libtifiles/trunk/tests/torture_tifiles.c @@ -3,16 +3,15 @@ #include #include "../src/error.h" -#define PRINTF(FUNCTION, TYPE, args...) \ -fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(args)) +#define PRINTF(FUNCTION, TYPE, ...) \ +fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(__VA_ARGS__)) -#define PRINTFVOID(FUNCTION, args...) \ -FUNCTION(args); fprintf(stderr, "%d\n", __LINE__) +#define PRINTFVOID(FUNCTION, ...) \ +FUNCTION(__VA_ARGS__); fprintf(stderr, "%d\n", __LINE__) #define INT "%d" #define PTR "%p" #define STR "\"%s\"" -#define VOID "" static const uint8_t certdata[] = {