From 5ad365c5df9bf743f5672516358d2bf41cdf196c Mon Sep 17 00:00:00 2001 From: mrdudz Date: Mon, 13 Jul 2020 21:26:07 +0200 Subject: [PATCH] some tweaks to the moved tests to make them more suitable for automatic testing --- test/todo/sprintf-test.c | 10 ++--- test/val/signal-test.c | 13 ++++-- test/val/snprintf-test.c | 5 ++- test/val/strncmp-test.c | 14 ++++--- test/val/strnicmp-test.c | 85 ++++++++++++++++++++++------------------ test/val/strpbrk-test.c | 12 +++++- test/val/time-test.c | 33 +++++++++++----- 7 files changed, 108 insertions(+), 64 deletions(-) diff --git a/test/todo/sprintf-test.c b/test/todo/sprintf-test.c index 55354be20..bd5de44b4 100644 --- a/test/todo/sprintf-test.c +++ b/test/todo/sprintf-test.c @@ -1,13 +1,13 @@ #include #include #include -#if defined(__CC65__) +#if defined(__CC65__) && !defined(__SIM6502__) && !defined(__SIM65C02__) #include #endif /* Flag to #ifdef the tests out that crash the old implementation */ -/*#define NOCRASH 1 */ +#define NOCRASH 1 @@ -532,9 +532,9 @@ int main (void) /* Alternative form with zero value */ #ifndef NOCRASH OneTest (__LINE__, "0", 1, "%#o", 0U); +#endif OneTest (__LINE__, "0", 1, "%#x", 0U); OneTest (__LINE__, "0", 1, "%#X", 0U); -#endif /* Alternative form with zero value and precision 1 */ OneTest (__LINE__, "0", 1, "%#.1o", 0U); @@ -570,8 +570,8 @@ int main (void) } /* Wait for a key so we can read the result */ -#if defined(__CC65__) +#if defined(__CC65__) && !defined(__SIM6502__) && !defined(__SIM65C02__) cgetc (); #endif - return 0; + return Failures; } diff --git a/test/val/signal-test.c b/test/val/signal-test.c index 4e34a281d..31dd8ed5c 100644 --- a/test/val/signal-test.c +++ b/test/val/signal-test.c @@ -1,12 +1,16 @@ #include +#include #include #include #include +int signalcounter = 0; + void __fastcall__ sighandler (int sig) { printf ("Got signal #%d\n", sig); + signalcounter++; } @@ -15,15 +19,18 @@ int main (void) { if (signal (SIGSEGV, sighandler) == SIG_ERR) { printf ("signal failure %d: %s\n", errno, strerror (errno)); - return 1; + return EXIT_FAILURE; } printf ("About to raise SIGSEGV...\n"); raise (SIGSEGV); printf ("Back from signal handler\n"); printf ("About to raise SIGILL...\n"); raise (SIGILL); - printf ("Back from signal handler\n"); - return 0; + printf ("Back from signal handler, signalcounter = %d\n", signalcounter); + if (signalcounter != 1) { + return EXIT_FAILURE; + } + return EXIT_SUCCESS; } diff --git a/test/val/snprintf-test.c b/test/val/snprintf-test.c index d3af47d78..e3a60d99b 100644 --- a/test/val/snprintf-test.c +++ b/test/val/snprintf-test.c @@ -137,8 +137,9 @@ unsigned char main(void) } else { printf("There were no"); } - printf(" failures.\nTap a key. "); + printf(" failures.\nTap a key.\n"); +#if defined(__CC65__) && !defined(__SIM6502__) && !defined(__SIM65C02__) cgetc(); - +#endif return failures; } diff --git a/test/val/strncmp-test.c b/test/val/strncmp-test.c index b15565036..7dbbb4b8c 100644 --- a/test/val/strncmp-test.c +++ b/test/val/strncmp-test.c @@ -10,15 +10,19 @@ static const char S2[] = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\0', 'B' }; - - +int fails = 0; int main (void) { char I; + int ret; for (I = 0; I < 20; ++I) { - printf ("%02d: %d\n", I, strncmp (S1, S2, I)); + ret = strncmp (S1, S2, I); + printf ("%02d: %d\n", I, ret); + if ((ret != 0) && (I < 7)) { + fails++; + } } - return 0; + printf("fails: %d\n", fails); + return fails; } - diff --git a/test/val/strnicmp-test.c b/test/val/strnicmp-test.c index b2d942a97..6376a39bb 100644 --- a/test/val/strnicmp-test.c +++ b/test/val/strnicmp-test.c @@ -3,70 +3,79 @@ #include #include +int fails = 0; + static int do_test(const char *s1, const char *s2, size_t n) { printf("strnicmp(\"%s\", \"%s\", %d): ", s1, s2, (int)n); return strncasecmp(s1, s2, n); } +static void printresult(int ret) +{ + if (ret) { + printf("fail (%d)\n", ret); + fails++; + } else { + printf("OK (%d)\n", ret); + } +} + +static void printresultgt(int ret) +{ + if (ret >= 0) { + printf("fail (%d)\n", ret); + fails++; + } else { + printf("OK (%d)\n", ret); + } +} + +static void printresultlt(int ret) +{ + if (ret <= 0) { + printf("fail (%d)\n", ret); + fails++; + } else { + printf("OK (%d)\n", ret); + } +} + int main(void) { int ret; ret = do_test("Wurzl", "wURZL", 5); - if (ret) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); + printresult(ret); ret = do_test("Wurzl", "wURZL", 6); - if (ret) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); + printresult(ret); ret = do_test("Wurzl", "wURZL", 10); - if (ret) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); + printresult(ret); ret = do_test("Wurzla", "wURZLB", 10); - if (ret >= 0) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); + printresultgt(ret); ret = do_test("Wurzla", "wURZLb", 5); - if (ret) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); + printresult(ret); ret = do_test("BLI", "bla", 5); - if (ret <= 0) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); + printresultlt(ret); ret = do_test("", "bla", 5); - if (ret >= 0) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); + printresultgt(ret); ret = do_test("BLI", "", 5); - if (ret <= 0) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); + printresultlt(ret); ret = do_test("", "", 5); - if (ret) - printf("fail (%d)\n", ret); - else - printf("OK (%d)\n", ret); - + printresult(ret); + + printf("fails: %d\n", fails); + +#if defined(__CC65__) && !defined(__SIM6502__) && !defined(__SIM65C02__) cgetc(); - return 0; +#endif + return fails; } diff --git a/test/val/strpbrk-test.c b/test/val/strpbrk-test.c index 25c2c2fbe..6a688732d 100644 --- a/test/val/strpbrk-test.c +++ b/test/val/strpbrk-test.c @@ -3,24 +3,32 @@ static const char fox[] = "The quick brown fox jumped over the lazy dogs."; -void main (void) +int fails = 0; + +int main (void) { printf ("Testing strpbrk():\n"); if (strpbrk (fox, "qwerty") != &fox[2]) { printf ("\nThe first 'e' wasn't found.\n"); + fails++; } if (strpbrk (fox, "QWERTY") != &fox[0]) { printf ("The 'T' wasn't found.\n"); + fails++; } if (strpbrk (fox, "asdfg") != &fox[16]) { printf ("The 'f' wasn't found.\n"); + fails++; } if (strpbrk (fox, "nxv,zmb") != &fox[10]) { printf ("The 'b' wasn't found.\n"); + fails++; } if (strpbrk (fox, "!@#$%^&*()-+=[];:',/?<>.") != &fox[45]) { printf ("The '.' wasn't found.\n"); + fails++; } - printf ("\nFinished.\n"); + printf ("\nFinished. fails = %d\n", fails); + return fails; } diff --git a/test/val/time-test.c b/test/val/time-test.c index 99d16be01..304238fa0 100644 --- a/test/val/time-test.c +++ b/test/val/time-test.c @@ -1,7 +1,11 @@ #include +#include #include +#define EXPECTSTR "3DD173D1 - Tue Nov 12 21:34:09 2002\n" +char result[0x100]; +int fails = 0; int main (void) { @@ -23,16 +27,27 @@ int main (void) t = mktime (&tm); printf ("Test passes if the following lines are\n" "all identical:\n"); - printf ("3DD173D1 - Tue Nov 12 21:34:09 2002\n"); - printf ("%08lX - %s", t, asctime (&tm)); - printf ("%08lX - %s", t, asctime (gmtime (&t))); + printf (EXPECTSTR); + + sprintf (result, "%08lX - %s", t, asctime (&tm)); + printf (result); + if (strcmp(result, EXPECTSTR) != 0) { fails++; } + + sprintf (result, "%08lX - %s", t, asctime (gmtime (&t))); + printf (result); + if (strcmp(result, EXPECTSTR) != 0) { fails++; } + strftime (buf, sizeof (buf), "%c", &tm); - printf ("%08lX - %s\n", t, buf); + sprintf (result, "%08lX - %s\n", t, buf); + printf (result); + if (strcmp(result, EXPECTSTR) != 0) { fails++; } + strftime (buf, sizeof (buf), "%a %b %d %H:%M:%S %Y", &tm); - printf ("%08lX - %s\n", t, buf); + sprintf (result, "%08lX - %s\n", t, buf); + printf (result); + if (strcmp(result, EXPECTSTR) != 0) { fails++; } + + printf("fails: %d\n", fails); - return 0; + return fails; } - - -