From 10637bbb75c8cfd21956a289674a73702f46d3e9 Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Tue, 21 Nov 2023 15:41:18 +0100 Subject: [PATCH] make it buildable FIXUP --- libticalcs/trunk/tests/CMakeLists.txt | 8 + libticalcs/trunk/tests/test_ticalcs_2.cc | 102 +---------- libticalcs/trunk/tests/torture_ticalcs.c | 2 +- libtifiles/trunk/tests/test_tifiles_2.cc | 212 ++++++++--------------- 4 files changed, 87 insertions(+), 237 deletions(-) diff --git a/libticalcs/trunk/tests/CMakeLists.txt b/libticalcs/trunk/tests/CMakeLists.txt index 649eebf7..6477c0b6 100644 --- a/libticalcs/trunk/tests/CMakeLists.txt +++ b/libticalcs/trunk/tests/CMakeLists.txt @@ -16,6 +16,10 @@ else() set(TICABLES_LIBUSB_REQUIRES_PRIVATE "libusb-1.0") endif() +if(WIN32 AND NOT MINGW) + find_library(GETOPT_LIB getopt REQUIRED) +endif() + if(USE_ICONV) find_package(Iconv REQUIRED) # flags/link for external deps @@ -28,6 +32,10 @@ foreach(tar torture_ticalcs test_ticalcs_2) target_link_libraries(${tar} ${Iconv_LIBRARIES}) endif() + if(GETOPT_LIB) + target_link_libraries(${tar} ${GETOPT_LIB}) + endif() + target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) target_include_directories(${tar} PRIVATE diff --git a/libticalcs/trunk/tests/test_ticalcs_2.cc b/libticalcs/trunk/tests/test_ticalcs_2.cc index eab741b2..07a901a7 100644 --- a/libticalcs/trunk/tests/test_ticalcs_2.cc +++ b/libticalcs/trunk/tests/test_ticalcs_2.cc @@ -33,106 +33,8 @@ #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 */ -} +#ifdef _MSC_VER +#include #else #include #endif diff --git a/libticalcs/trunk/tests/torture_ticalcs.c b/libticalcs/trunk/tests/torture_ticalcs.c index db140733..4883a1c0 100644 --- a/libticalcs/trunk/tests/torture_ticalcs.c +++ b/libticalcs/trunk/tests/torture_ticalcs.c @@ -538,7 +538,7 @@ static void torture_dbus(void) static void torture_cmdz80(void) { -#ifndef __WIN32__ +#ifndef _MSC_VER // 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); diff --git a/libtifiles/trunk/tests/test_tifiles_2.cc b/libtifiles/trunk/tests/test_tifiles_2.cc index 16f967d6..008ef737 100644 --- a/libtifiles/trunk/tests/test_tifiles_2.cc +++ b/libtifiles/trunk/tests/test_tifiles_2.cc @@ -94,70 +94,10 @@ static int compare_files(const char *src, const char *dst) return 0; } -// Rename file -static int move_file(const char *oldpath, const char *newpath) -{ -#if 0 && defined(__WIN32__) && !defined(__MINGW32__) - return 0; -#else - return rename(oldpath, newpath); -#endif -} - // Set output directory static void change_dir(const char *path) { -#if 0 && defined(__WIN32__) && !defined(__MINGW32__) _chdir(path); -#endif -} - -// Build a portable path for Linux/Win32 -static const char* PATH(const char *path) -{ -#if 0 && defined(__WIN32__) && !defined(__MINGW32__) - static char str[1024]; - unsigned int i; - - strcpy(str, "C:\\sources\\roms\\tifiles2\\tests\\"); - strcat(str, path); - - for(i = 0; i < strlen(str); i++) - { - if(str[i] == '/') - { - str[i] = '\\'; - } - } - - return str; -#else - return path; -#endif -} - -// Build a portable path for Linux/Win32 -static const char* PATH2(const char *path) -{ -#if 0 && defined(__WIN32__) && !defined(__MINGW32__) - static char str[1024]; - unsigned int i; - - strcpy(str, "C:\\sources\\roms\\tifiles2\\tests\\"); - strcat(str, path); - - for(i = 0; i < strlen(str); i++) - { - if(str[i] == '/') - { - str[i] = '\\'; - } - } - - return str; -#else - return path; -#endif } /* @@ -189,18 +129,18 @@ static int test_tixx_backup_support(const char * message, int ret = -1; printf("%s", message); - tifiles_file_display(PATH(input_file)); + tifiles_file_display(input_file); content = tifiles_content_create_backup(calculator); if (content != NULL) { - ret = tifiles_file_read_backup(PATH(input_file), content); + ret = tifiles_file_read_backup(input_file, content); if (!ret) { - ret = tifiles_file_write_backup(PATH(output_file), content); + ret = tifiles_file_write_backup(output_file, content); if (!ret) { - ret = compare_files(PATH(input_file), PATH2(output_file)); + ret = compare_files(input_file, output_file); } tifiles_content_delete_backup(content); } @@ -219,18 +159,18 @@ static int test_tixx_regular_support_single(const char * message, int ret = -1; printf("%s", message); - tifiles_file_display(PATH(input_file)); + tifiles_file_display(input_file); content = tifiles_content_create_regular(calculator); if (content != NULL) { - ret = tifiles_file_read_regular(PATH(input_file), content); + ret = tifiles_file_read_regular(input_file, content); if (!ret) { - ret = tifiles_file_write_regular(PATH(output_file), content, &unused); + ret = tifiles_file_write_regular(output_file, content, &unused); if (!ret) { - ret = compare_files(PATH(input_file), PATH2(output_file)); + ret = compare_files(input_file, output_file); } tifiles_filename_free(unused); tifiles_content_delete_regular(content); @@ -250,18 +190,18 @@ static int test_tixx_regular_support_group(const char * message, int ret = -1; printf("%s", message); - tifiles_file_display(PATH(input_group)); + tifiles_file_display(input_group); content = tifiles_content_create_regular(calculator); if (content != NULL) { - ret = tifiles_file_read_regular(PATH(input_group), content); + ret = tifiles_file_read_regular(input_group, content); if (!ret) { - ret = tifiles_file_write_regular(PATH(output_group), content, &unused); + ret = tifiles_file_write_regular(output_group, content, &unused); if (!ret) { - compare_files(PATH(input_group), PATH2(output_group)); + compare_files(input_group, output_group); } tifiles_filename_free(unused); tifiles_content_delete_regular(content); @@ -281,19 +221,19 @@ static int test_tixx_group_support(const char * message, char *array[3] = { 0 }; int ret = -1; - strncpy(files[0], PATH(input_file_1), 1023); + strncpy(files[0], input_file_1, 1023); files[0][1023] = 0; - strncpy(files[1], PATH(input_file_2), 1023); + strncpy(files[1], input_file_2, 1023); files[1][1023] = 0; array[0] = files[0]; array[1] = files[1]; printf("%s", message); - ret = tifiles_group_files(array, PATH(output_group_file)); + ret = tifiles_group_files(array, output_group_file); if (!ret) { - tifiles_file_display(PATH(output_group_file)); - ret = compare_files(PATH(input_group_file), PATH2(output_group_file)); + tifiles_file_display(output_group_file); + ret = compare_files(input_group_file, output_group_file); } return ret; @@ -310,15 +250,15 @@ static int test_tixx_ungroup_support(const char * message, { int ret; printf("%s", message); - ret = tifiles_ungroup_file(PATH(input_group), NULL); + ret = tifiles_ungroup_file(input_group, NULL); if (!ret) { - move_file(input_file_1, dest_file_1); - move_file(input_file_2, dest_file_2); - ret = compare_files(PATH(dest_file_1), PATH2(input_file_3)); + rename(input_file_1, dest_file_1); + rename(input_file_2, dest_file_2); + ret = compare_files(dest_file_1, input_file_3); if (!ret) { - ret = compare_files(PATH(dest_file_2), PATH2(input_file_3)); + ret = compare_files(dest_file_2, input_file_3); } } @@ -334,18 +274,18 @@ static int test_tixx_flash_support(const char * message, int ret = -1; printf("%s", message); - tifiles_file_display(PATH(input_file)); + tifiles_file_display(input_file); content = tifiles_content_create_flash(calculator); if (content != NULL) { - ret = tifiles_file_read_flash(PATH(input_file), content); + ret = tifiles_file_read_flash(input_file, content); if (!ret) { - ret = tifiles_file_write_flash(PATH(output_file), content); + ret = tifiles_file_write_flash(output_file, content); if (!ret) { - ret = compare_files(PATH(input_file), PATH2(output_file)); + ret = compare_files(input_file, output_file); } tifiles_content_delete_flash(content); } @@ -804,20 +744,20 @@ static int test_ti8x_group_merge() int ret; printf("--> Testing add/del from group support (r/w)...\n"); - ret = tifiles_group_add_file(PATH("misc/group1.8Xg"), PATH2("misc/group2.8Xg")); + ret = tifiles_group_add_file("misc/group1.8Xg", "misc/group2.8Xg"); if (!ret) { strncpy(ve.name, "A", sizeof(ve.name) - 1); ve.name[sizeof(ve.name) - 1] = 0; - ret = tifiles_group_del_file(&ve, PATH("misc/group2.8Xg")); + ret = tifiles_group_del_file(&ve, "misc/group2.8Xg"); if (!ret) { strncpy(ve.name, "B", sizeof(ve.name) - 1); ve.name[sizeof(ve.name) - 1] = 0; - ret = tifiles_group_del_file(&ve, PATH("misc/group2.8Xg")); + ret = tifiles_group_del_file(&ve, "misc/group2.8Xg"); if (!ret) { - ret = compare_files(PATH("misc/group1.8Xg"), PATH2("misc/group2.8Xg")); + ret = compare_files("misc/group1.8Xg", "misc/group2.8Xg"); } } } @@ -839,15 +779,15 @@ static int test_tigroup() char files[2][1024]; printf("--> Testing TiGroup support (r/w)...\n"); - tifiles_file_display_tigroup(PATH("tig/test.tig")); + tifiles_file_display_tigroup("tig/test.tig"); content = tifiles_content_create_tigroup(CALC_NONE, 0); if (content != NULL) { - ret = tifiles_file_read_tigroup(PATH("tig/test2.tig"), content); + ret = tifiles_file_read_tigroup("tig/test2.tig", content); if (!ret) { - ret = tifiles_file_write_tigroup(PATH("tig/test2_.tig"), content); + ret = tifiles_file_write_tigroup("tig/test2_.tig", content); } tifiles_content_delete_tigroup(content); } @@ -857,13 +797,13 @@ static int test_tigroup() content = tifiles_content_create_tigroup(CALC_NONE, 0); if (content != NULL) { - ret = tifiles_file_read_tigroup(PATH("tig/test.tig"), content); + ret = tifiles_file_read_tigroup("tig/test.tig", content); if (!ret) { - ret = tifiles_file_write_tigroup(PATH("tig/test_.tig"), content); + ret = tifiles_file_write_tigroup("tig/test_.tig", content); if (!ret) { - ret = compare_files(PATH("tig/test.tig"), PATH2("tig/test_.tig")); + ret = compare_files("tig/test.tig", "tig/test_.tig"); } } tifiles_content_delete_tigroup(content); @@ -873,22 +813,22 @@ static int test_tigroup() if (!ret) { printf("--> Testing add/del from TiGroup support (r/w)...\n"); - ret = tifiles_tigroup_add_file(PATH("tig/C.8Xn"), PATH2("tig/test2.tig")); + ret = tifiles_tigroup_add_file("tig/C.8Xn", "tig/test2.tig"); if (!ret) { - ret = tifiles_tigroup_add_file(PATH("tig/D.8Xn"), PATH2("tig/test2.tig")); + ret = tifiles_tigroup_add_file("tig/D.8Xn", "tig/test2.tig"); if (!ret) { te.filename = strdup("C.8Xn"); - ret = tifiles_tigroup_del_file(&te, PATH("tig/test2.tig")); + ret = tifiles_tigroup_del_file(&te, "tig/test2.tig"); if (!ret) { te.filename = strdup("D.8Xn"); - ret = tifiles_tigroup_del_file(&te, PATH("tig/test2.tig")); + ret = tifiles_tigroup_del_file(&te, "tig/test2.tig"); if (!ret) { - tifiles_file_display_tigroup(PATH("tig/test2.tig")); - ret = compare_files(PATH("tig/test.tig"), PATH2("tig/test2.tig")); + tifiles_file_display_tigroup("tig/test2.tig"); + ret = compare_files("tig/test.tig", "tig/test2.tig"); } } } @@ -899,25 +839,25 @@ static int test_tigroup() { printf("--> Testing TiGroup support (group/ungroup)...\n"); - strncpy(files[0], PATH("tig/str.89s"), 1023); + strncpy(files[0], "tig/str.89s", 1023); files[0][1023] = 0; - strncpy(files[1], PATH("tig/ticabfra.89k"), 1023); + strncpy(files[1], "tig/ticabfra.89k", 1023); files[1][1023] = 0; array[0] = files[0]; array[1] = files[1]; - ret = tifiles_tigroup_files(array, PATH("tig/test_.tig")); + ret = tifiles_tigroup_files(array, "tig/test_.tig"); if (!ret) { - tifiles_file_display(PATH("tig/test_.tig")); - ret = tifiles_untigroup_file(PATH("tig/test.tig"), NULL); + tifiles_file_display("tig/test_.tig"); + ret = tifiles_untigroup_file("tig/test.tig", NULL); if (!ret) { - move_file("A.8Xn", "tig/AA.8Xn"); - move_file("B.8Xn", "tig/BB.8Xn"); - ret = compare_files(PATH("tig/A.8Xn"), PATH2("tig/AA.8Xn")); + rename("A.8Xn", "tig/AA.8Xn"); + rename("B.8Xn", "tig/BB.8Xn"); + ret = compare_files("tig/A.8Xn", "tig/AA.8Xn"); if (!ret) { - ret = compare_files(PATH("tig/B.8Xn"), PATH2("tig/BB.8Xn")); + ret = compare_files("tig/B.8Xn", "tig/BB.8Xn"); } } } @@ -986,48 +926,48 @@ int main(int argc, char **argv) printf("<%s> <%s>\n", "foo.bar", tifiles_fext_get("foo.bar")); - ret = tifiles_file_is_ti(PATH("misc/str.92s")); + ret = tifiles_file_is_ti("misc/str.92s"); printf("tifiles_file_is_ti: %i\n", ret); - ret = tifiles_file_is_single(PATH("misc/str.92s")); + ret = tifiles_file_is_single("misc/str.92s"); printf("tifiles_file_is_single: %i\n", ret); - ret = tifiles_file_is_group(PATH("misc/group.92g")); + ret = tifiles_file_is_group("misc/group.92g"); printf("tifiles_file_is_group: %i\n", ret); - ret = tifiles_file_is_regular(PATH("misc/str.92s")); + ret = tifiles_file_is_regular("misc/str.92s"); printf("tifiles_file_is_regular: %i\n", ret); - ret = tifiles_file_is_regular(PATH("misc/group.92g")); + ret = tifiles_file_is_regular("misc/group.92g"); printf("tifiles_file_is_regular: %i\n", ret); - ret = tifiles_file_is_backup(PATH("misc/backup.83b")); + ret = tifiles_file_is_backup("misc/backup.83b"); printf("tifiles_file_is_backup: %i\n", ret); - ret = tifiles_file_is_flash(PATH("misc/ticabfra.89k")); + ret = tifiles_file_is_flash("misc/ticabfra.89k"); printf("tifiles_file_is_flash: %i\n", ret); - ret = tifiles_file_is_flash(PATH("misc/TI73_OS160.73U")); + ret = tifiles_file_is_flash("misc/TI73_OS160.73U"); printf("tifiles_file_is_flash: %i\n", ret); - ret = tifiles_file_is_tib(PATH("misc/ams100.tib")); + ret = tifiles_file_is_tib("misc/ams100.tib"); printf("tifiles_file_is_tib: %i\n", ret); - ret = tifiles_file_is_tigroup(PATH("misc/test.tig")); + ret = tifiles_file_is_tigroup("misc/test.tig"); printf("tifiles_file_is_tigroup: %i\n", ret); printf("--\n"); // test typesxx.c printf("tifiles_file_get_model: %s\n", - tifiles_model_to_string(tifiles_file_get_model(PATH("misc/str.92s")))); + tifiles_model_to_string(tifiles_file_get_model("misc/str.92s"))); printf("tifiles_file_get_class: %s\n", - tifiles_class_to_string(tifiles_file_get_class(PATH("misc/group.92g")))); + tifiles_class_to_string(tifiles_file_get_class("misc/group.92g"))); printf("tifiles_file_get_type: %s\n", - tifiles_file_get_type(PATH("misc/TI73_OS160.73U"))); + tifiles_file_get_type("misc/TI73_OS160.73U")); printf("tifiles_file_get_icon: %s\n", - tifiles_file_get_icon(PATH("misc/str.92s"))); + tifiles_file_get_icon("misc/str.92s")); printf("--\n"); // test misc.c @@ -1048,67 +988,67 @@ int main(int argc, char **argv) do { // TI73 support - change_dir(PATH("ti73")); + change_dir("ti73"); ret = test_ti73_backup_support(); if (ret) break; ret = test_ti73_regular_support(); if (ret) break; ret = test_ti73_group_support(); if (ret) break; ret = test_ti73_ungroup_support(); if (ret) break; // TI82 support - change_dir(PATH("ti82")); + change_dir("ti82"); ret = test_ti82_backup_support(); if (ret) break; ret = test_ti82_regular_support(); if (ret) break; ret = test_ti82_group_support(); if (ret) break; ret = test_ti82_ungroup_support(); if (ret) break; // TI83 support - change_dir(PATH("ti83")); + change_dir("ti83"); ret = test_ti83_backup_support(); if (ret) break; ret = test_ti83_regular_support(); if (ret) break; ret = test_ti83_group_support(); if (ret) break; ret = test_ti83_ungroup_support(); if (ret) break; // TI84+ support - change_dir(PATH("ti84p")); + change_dir("ti84p"); ret = test_ti84p_regular_support(); if (ret) break; ret = test_ti84p_group_support(); if (ret) break; ret = test_ti84p_ungroup_support(); if (ret) break; ret = test_ti84p_flash_support(); if (ret) break; // TI85 support - change_dir(PATH("ti85")); + change_dir("ti85"); ret = test_ti85_regular_support(); if (ret) break; // TI86 support - change_dir(PATH("ti86")); + change_dir("ti86"); ret = test_ti86_backup_support(); if (ret) break; ret = test_ti86_regular_support(); if (ret) break; ret = test_ti86_group_support(); if (ret) break; ret = test_ti86_ungroup_support(); if (ret) break; // TI89 support - change_dir(PATH("ti89")); + change_dir("ti89"); ret = test_ti89_regular_support(); if (ret) break; ret = test_ti89_flash_support(); if (ret) break; ret = test_v200_regular_support(); if (ret) break; // TI92 support - change_dir(PATH("ti92")); + change_dir("ti92"); ret = test_ti92_backup_support(); if (ret) break; ret = test_ti92_regular_support(); if (ret) break; ret = test_ti92_group_support(); if (ret) break; ret = test_ti92_ungroup_support(); if (ret) break; // TIXX certificates - change_dir(PATH("certs")); + change_dir("certs"); ret = test_ti8x_cert_support(); if (ret) break; ret = test_ti9x_cert_support(); if (ret) break; // Add/Del files - change_dir(PATH("misc")); + change_dir("misc"); ret = test_ti8x_group_merge(); if (ret) break; - change_dir(PATH("tig")); + change_dir("tig"); ret = test_tigroup(); } while(0);