1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

some tweaks to the moved tests to make them more suitable for automatic testing

This commit is contained in:
mrdudz 2020-07-13 21:26:07 +02:00
parent 882194c221
commit 5ad365c5df
7 changed files with 108 additions and 64 deletions

View File

@ -1,13 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#if defined(__CC65__) #if defined(__CC65__) && !defined(__SIM6502__) && !defined(__SIM65C02__)
#include <conio.h> #include <conio.h>
#endif #endif
/* Flag to #ifdef the tests out that crash the old implementation */ /* 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 */ /* Alternative form with zero value */
#ifndef NOCRASH #ifndef NOCRASH
OneTest (__LINE__, "0", 1, "%#o", 0U); OneTest (__LINE__, "0", 1, "%#o", 0U);
#endif
OneTest (__LINE__, "0", 1, "%#x", 0U); OneTest (__LINE__, "0", 1, "%#x", 0U);
OneTest (__LINE__, "0", 1, "%#X", 0U); OneTest (__LINE__, "0", 1, "%#X", 0U);
#endif
/* Alternative form with zero value and precision 1 */ /* Alternative form with zero value and precision 1 */
OneTest (__LINE__, "0", 1, "%#.1o", 0U); OneTest (__LINE__, "0", 1, "%#.1o", 0U);
@ -570,8 +570,8 @@ int main (void)
} }
/* Wait for a key so we can read the result */ /* Wait for a key so we can read the result */
#if defined(__CC65__) #if defined(__CC65__) && !defined(__SIM6502__) && !defined(__SIM65C02__)
cgetc (); cgetc ();
#endif #endif
return 0; return Failures;
} }

View File

@ -1,12 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
int signalcounter = 0;
void __fastcall__ sighandler (int sig) void __fastcall__ sighandler (int sig)
{ {
printf ("Got signal #%d\n", sig); printf ("Got signal #%d\n", sig);
signalcounter++;
} }
@ -15,15 +19,18 @@ int main (void)
{ {
if (signal (SIGSEGV, sighandler) == SIG_ERR) { if (signal (SIGSEGV, sighandler) == SIG_ERR) {
printf ("signal failure %d: %s\n", errno, strerror (errno)); printf ("signal failure %d: %s\n", errno, strerror (errno));
return 1; return EXIT_FAILURE;
} }
printf ("About to raise SIGSEGV...\n"); printf ("About to raise SIGSEGV...\n");
raise (SIGSEGV); raise (SIGSEGV);
printf ("Back from signal handler\n"); printf ("Back from signal handler\n");
printf ("About to raise SIGILL...\n"); printf ("About to raise SIGILL...\n");
raise (SIGILL); raise (SIGILL);
printf ("Back from signal handler\n"); printf ("Back from signal handler, signalcounter = %d\n", signalcounter);
return 0; if (signalcounter != 1) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
} }

View File

@ -137,8 +137,9 @@ unsigned char main(void)
} else { } else {
printf("There were no"); printf("There were no");
} }
printf(" failures.\nTap a key. "); printf(" failures.\nTap a key.\n");
#if defined(__CC65__) && !defined(__SIM6502__) && !defined(__SIM65C02__)
cgetc(); cgetc();
#endif
return failures; return failures;
} }

View File

@ -10,15 +10,19 @@ static const char S2[] = {
'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\0', 'B' 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\0', 'B'
}; };
int fails = 0;
int main (void) int main (void)
{ {
char I; char I;
int ret;
for (I = 0; I < 20; ++I) { 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;
} }

View File

@ -3,70 +3,79 @@
#include <string.h> #include <string.h>
#include <conio.h> #include <conio.h>
int fails = 0;
static int do_test(const char *s1, const char *s2, size_t n) static int do_test(const char *s1, const char *s2, size_t n)
{ {
printf("strnicmp(\"%s\", \"%s\", %d): ", s1, s2, (int)n); printf("strnicmp(\"%s\", \"%s\", %d): ", s1, s2, (int)n);
return strncasecmp(s1, s2, 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 main(void)
{ {
int ret; int ret;
ret = do_test("Wurzl", "wURZL", 5); ret = do_test("Wurzl", "wURZL", 5);
if (ret) printresult(ret);
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("Wurzl", "wURZL", 6); ret = do_test("Wurzl", "wURZL", 6);
if (ret) printresult(ret);
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("Wurzl", "wURZL", 10); ret = do_test("Wurzl", "wURZL", 10);
if (ret) printresult(ret);
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("Wurzla", "wURZLB", 10); ret = do_test("Wurzla", "wURZLB", 10);
if (ret >= 0) printresultgt(ret);
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("Wurzla", "wURZLb", 5); ret = do_test("Wurzla", "wURZLb", 5);
if (ret) printresult(ret);
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("BLI", "bla", 5); ret = do_test("BLI", "bla", 5);
if (ret <= 0) printresultlt(ret);
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("", "bla", 5); ret = do_test("", "bla", 5);
if (ret >= 0) printresultgt(ret);
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("BLI", "", 5); ret = do_test("BLI", "", 5);
if (ret <= 0) printresultlt(ret);
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("", "", 5); ret = do_test("", "", 5);
if (ret) printresult(ret);
printf("fail (%d)\n", ret);
else printf("fails: %d\n", fails);
printf("OK (%d)\n", ret);
#if defined(__CC65__) && !defined(__SIM6502__) && !defined(__SIM65C02__)
cgetc(); cgetc();
return 0; #endif
return fails;
} }

View File

@ -3,24 +3,32 @@
static const char fox[] = "The quick brown fox jumped over the lazy dogs."; 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"); printf ("Testing strpbrk():\n");
if (strpbrk (fox, "qwerty") != &fox[2]) { if (strpbrk (fox, "qwerty") != &fox[2]) {
printf ("\nThe first 'e' wasn't found.\n"); printf ("\nThe first 'e' wasn't found.\n");
fails++;
} }
if (strpbrk (fox, "QWERTY") != &fox[0]) { if (strpbrk (fox, "QWERTY") != &fox[0]) {
printf ("The 'T' wasn't found.\n"); printf ("The 'T' wasn't found.\n");
fails++;
} }
if (strpbrk (fox, "asdfg") != &fox[16]) { if (strpbrk (fox, "asdfg") != &fox[16]) {
printf ("The 'f' wasn't found.\n"); printf ("The 'f' wasn't found.\n");
fails++;
} }
if (strpbrk (fox, "nxv,zmb") != &fox[10]) { if (strpbrk (fox, "nxv,zmb") != &fox[10]) {
printf ("The 'b' wasn't found.\n"); printf ("The 'b' wasn't found.\n");
fails++;
} }
if (strpbrk (fox, "!@#$%^&*()-+=[];:',/?<>.") != &fox[45]) { if (strpbrk (fox, "!@#$%^&*()-+=[];:',/?<>.") != &fox[45]) {
printf ("The '.' wasn't found.\n"); printf ("The '.' wasn't found.\n");
fails++;
} }
printf ("\nFinished.\n"); printf ("\nFinished. fails = %d\n", fails);
return fails;
} }

View File

@ -1,7 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <time.h> #include <time.h>
#define EXPECTSTR "3DD173D1 - Tue Nov 12 21:34:09 2002\n"
char result[0x100];
int fails = 0;
int main (void) int main (void)
{ {
@ -23,16 +27,27 @@ int main (void)
t = mktime (&tm); t = mktime (&tm);
printf ("Test passes if the following lines are\n" printf ("Test passes if the following lines are\n"
"all identical:\n"); "all identical:\n");
printf ("3DD173D1 - Tue Nov 12 21:34:09 2002\n"); printf (EXPECTSTR);
printf ("%08lX - %s", t, asctime (&tm));
printf ("%08lX - %s", t, asctime (gmtime (&t))); 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); 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); 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;
} }