Skip to content

Commit

Permalink
windows: make most tests buildable and use C++ includes
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed Nov 19, 2023
1 parent 46e59dd commit 4880b55
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 48 deletions.
8 changes: 4 additions & 4 deletions libticables/trunk/tests/test_ticables_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include <config.h>
#endif

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#ifndef __WIN32__
#include <unistd.h>
#else
Expand Down
9 changes: 4 additions & 5 deletions libticables/trunk/tests/torture_ticables.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#include <stdio.h>
#include <ticables.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 ""

int main(int argc, char **argv)
{
Expand Down
113 changes: 108 additions & 5 deletions libticalcs/trunk/tests/test_ticalcs_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,115 @@
#include <config.h>
#endif

#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cctype>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#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 <unistd.h>
#endif

// Happens for some reason on MinGW 64 32-bit GCC 8 toolchain.
#ifndef SCNi8
Expand Down
13 changes: 8 additions & 5 deletions libticalcs/trunk/tests/torture_ticalcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
#include <romdump.h>
#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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions libticonv/trunk/tests/test_ticonv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <glib.h>
#ifdef __WIN32__
#include <conio.h>
Expand Down
21 changes: 6 additions & 15 deletions libticonv/trunk/tests/torture_ticonv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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 };
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions libtifiles/trunk/tests/test_tifiles_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#endif

#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#ifdef __WIN32__
#include <direct.h>
#endif
Expand Down Expand Up @@ -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);
Expand All @@ -107,15 +107,15 @@ 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
}

// 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;

Expand All @@ -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;

Expand All @@ -152,6 +152,7 @@ static const char* PATH2(const char *path)
{
str[i] = '\\';
}
}

return str;
#else
Expand Down
9 changes: 4 additions & 5 deletions libtifiles/trunk/tests/torture_tifiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
#include <tifiles.h>
#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[] =
{
Expand Down

0 comments on commit 4880b55

Please sign in to comment.