move a bunch of tests from testcode/lib to test/val (and a failing one to test/todo)

This commit is contained in:
mrdudz
2020-07-13 21:25:13 +02:00
parent d940c9aa85
commit 882194c221
11 changed files with 0 additions and 0 deletions

View File

@@ -1,45 +0,0 @@
/* A small test for atoi. Assumes twos complement */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#define outfile stderr
static unsigned int Failures = 0;
static void CheckAtoi (const char* Str, int Val)
{
int Res = atoi (Str);
if (Res != Val) {
fprintf (outfile, "atoi error in \"%s\":\n"
" result = %d, should be %d\n", Str, Res, Val);
++Failures;
}
}
int main (void)
{
CheckAtoi ("\t +0A", 0);
CheckAtoi ("\t -0.123", 0);
CheckAtoi (" -32 ", -32);
CheckAtoi (" +32 ", 32);
CheckAtoi ("0377", 377);
CheckAtoi (" 0377 ", 377);
CheckAtoi (" +0377 ", 377);
CheckAtoi (" -0377 ", -377);
CheckAtoi ("0x7FFF", 0);
CheckAtoi (" +0x7FFF", 0);
CheckAtoi (" -0x7FFF", 0);
fprintf (outfile, "Failures: %u\n", Failures);
return (Failures != 0);
}

View File

@@ -1,136 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
static unsigned UnsignedShiftLeft1 (unsigned Val)
/* Shift an unsigned left by 1 */
{
__AX__ = Val;
asm ("stx tmp1");
asm ("asl a");
asm ("rol tmp1");
asm ("ldx tmp1");
return __AX__;
}
static unsigned UnsignedShiftRight1 (unsigned Val)
/* Shift an unsigned right by 1 */
{
__AX__ = Val;
asm ("stx tmp1");
asm ("lsr tmp1");
asm ("ror a");
asm ("ldx tmp1");
return __AX__;
}
static int SignedShiftRight1 (int Val)
/* Shift a signed right by 1 */
{
__AX__ = Val;
asm ("stx tmp1");
asm ("cpx #$80");
asm ("ror tmp1");
asm ("ror a");
asm ("ldx tmp1");
return __AX__;
}
static void TestUnsignedLeftShift (void)
/* Test left shift. This is identical for signed and unsigned ints */
{
unsigned L, R, V;
printf ("Testing unsigned left shift:\n");
L = 0;
do {
V = L;
for (R = 0; R < 16; ++R) {
/* Check it */
if ((L << R) != V) {
fprintf (stderr,
"Failed: %u << %u != %u (%u)\n",
L, R, V, L << R);
exit (EXIT_FAILURE);
}
V = UnsignedShiftLeft1 (V);
}
if ((L & 0xFF) == 0) {
printf ("%04X ", L);
}
} while (++L != 0);
printf ("\n");
}
static void TestUnsignedRightShift (void)
/* Test unsigned right shift. */
{
unsigned L, R, V;
printf ("Testing unsigned right shift:\n");
L = 0;
do {
V = L;
for (R = 0; R < 16; ++R) {
/* Check it */
if ((L >> R) != V) {
fprintf (stderr,
"Failed: %u >> %u != %u (%u)\n",
L, R, V, L >> R);
exit (EXIT_FAILURE);
}
V = UnsignedShiftRight1 (V);
}
if ((L & 0xFF) == 0) {
printf ("%04X ", L);
}
} while (++L != 0);
printf ("\n");
}
static void TestSignedRightShift (void)
/* Test signed right shift. */
{
int L, R, V;
printf ("Testing signed right shift:\n");
L = 0;
do {
V = L;
for (R = 0; R < 16; ++R) {
/* Check it */
if ((L >> R) != V) {
fprintf (stderr,
"Failed: %d >> %d != %d (%d)\n",
L, R, V, L >> R);
exit (EXIT_FAILURE);
}
V = SignedShiftRight1 (V);
}
if ((L & 0xFF) == 0) {
printf ("%04X ", L);
}
} while (++L != 0);
printf ("\n");
}
int main (void)
{
TestUnsignedLeftShift ();
TestUnsignedRightShift ();
TestSignedRightShift ();
printf ("\nOk!\n");
return 0;
}

View File

@@ -1,29 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
void __fastcall__ sighandler (int sig)
{
printf ("Got signal #%d\n", sig);
}
int main (void)
{
if (signal (SIGSEGV, sighandler) == SIG_ERR) {
printf ("signal failure %d: %s\n", errno, strerror (errno));
return 1;
}
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;
}

View File

@@ -1,144 +0,0 @@
/*
** Test a function that formats and writes characters into a string buffer.
** This program does not test formatting. It tests some behaviors that are
** specific to the buffer. It tests that certain conditions are handled
** properly.
**
** 2015-07-17, Greg King
*/
#include <conio.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
static const char format[] = "1234567890\nabcdefghijklmnopqrstuvwxyz\n%u\n%s\n\n";
#define FORMAT_SIZE (sizeof format - 2u - 2u - 1u)
#define arg1 12345u
#define ARG1_SIZE (5u)
static const char arg2[] = "!@#$%^&*()-+";
#define ARG2_SIZE (sizeof arg2 - 1u)
#define STRING_SIZE (FORMAT_SIZE + ARG1_SIZE + ARG2_SIZE)
static char buf[256];
static int size;
static void fillbuf(void)
{
memset(buf, 0xFF, sizeof buf - 1u);
buf[sizeof buf - 1u] = '\0';
}
unsigned char main(void)
{
static unsigned char failures = 0;
/* Show what sprintf() should create. */
if ((size = printf(format, arg1, arg2)) != STRING_SIZE) {
++failures;
printf("printf() gave the wrong size: %d.\n", size);
}
/* Test the normal behavior of sprintf(). */
fillbuf();
size = sprintf(buf, format, arg1, arg2);
fputs(buf, stdout);
if (size != STRING_SIZE) {
++failures;
printf("sprintf() gave the wrong size: %d.\n", size);
}
/* Test the normal behavior of snprintf(). */
fillbuf();
size = snprintf(buf, sizeof buf, format, arg1, arg2);
fputs(buf, stdout);
if (size != STRING_SIZE) {
++failures;
printf("snprintf(sizeof buf) gave the wrong size:\n %d.\n", size);
}
/* Does snprintf() return the full-formatted size even when the buffer
** is short? Does it write beyond the end of that buffer?
*/
fillbuf();
size = snprintf(buf, STRING_SIZE - 5u, format, arg1, arg2);
if (size != STRING_SIZE) {
++failures;
printf("snprintf(STRING_SIZE-5) gave the wrong size:\n %d.\n", size);
}
if (buf[STRING_SIZE - 5u - 1u] != '\0' || buf[STRING_SIZE - 5u] != 0xFF) {
++failures;
printf("snprintf(STRING_SIZE-5) wrote beyond\n the end of the buffer.\n");
}
/* Does snprintf() detect a buffer size that is too big? */
fillbuf();
errno = 0;
size = snprintf(buf, 0x8000, format, arg1, arg2);
if (size >= 0) {
++failures;
printf("snprintf(0x8000) didn't give an error:\n %d; errno=%d.\n", size, errno);
} else {
printf("snprintf(0x8000) did give an error:\n errno=%d.\n", errno);
}
if (buf[0] != 0xFF) {
++failures;
printf("snprintf(0x8000) wrote into the buffer.\n");
}
/* snprintf() must measure the length of the formatted output even when the
** buffer size is zero. But, it must not touch the buffer.
*/
fillbuf();
size = snprintf(buf, 0, format, arg1, arg2);
if (size != STRING_SIZE) {
++failures;
printf("snprintf(0) gave the wrong size:\n %d.\n", size);
}
if (buf[0] != 0xFF) {
++failures;
printf("snprintf(0) wrote into the buffer.\n");
}
/* Does sprintf() detect a zero buffer-pointer? */
errno = 0;
size = sprintf(NULL, format, arg1, arg2);
if (size >= 0) {
++failures;
printf("sprintf(NULL) didn't give an error:\n %d; errno=%d.\n", size, errno);
} else {
printf("sprintf(NULL) did give an error:\n errno=%d.\n", errno);
}
/* snprintf() must measure the length of the formatted output even when the
** buffer size is zero. A zero pointer is not an error, in that case.
*/
size = snprintf(NULL, 0, format, arg1, arg2);
if (size != STRING_SIZE) {
++failures;
printf("snprintf(NULL,0) gave the wrong size:\n %d.\n", size);
}
if (failures != 0) {
printf("There were %u", failures);
} else {
printf("There were no");
}
printf(" failures.\nTap a key. ");
cgetc();
return failures;
}

View File

@@ -1,577 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#if defined(__CC65__)
#include <conio.h>
#endif
/* Flag to #ifdef the tests out that crash the old implementation */
/*#define NOCRASH 1 */
/*****************************************************************************/
/* Code */
/*****************************************************************************/
/* Struct used to test the 'n' conversion specifier. It is machine dependent /
** not portable.
*/
typedef union WriteCount WriteCount;
union WriteCount {
signed char C;
int I;
long L;
};
/* Count the number of tests and the number of failures */
static unsigned Tests = 0;
static unsigned Failures = 0;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static void OneTest (int Line, const char* RString, int RCount, const char* Format, ...)
/* Test one conversion. Line is the line number (to make the life of the
** tester easier), RString the expected result and RCount the expected return
** count. The other parameters are used for formatting.
*/
{
int Count;
char Buf[128];
va_list ap;
/* Count the number of tests */
++Tests;
/* Format the string using the given arguments */
va_start (ap, Format);
Count = vsprintf (Buf, Format, ap);
va_end (ap);
/* Check the result */
if (Count != RCount || strcmp (Buf, RString) != 0) {
++Failures;
printf ("%3d: \"%s\" (%d)\n"
" \"%s\" (%d)\n",
Line, Buf, Count, RString, RCount);
}
}
static void WriteTest (int Line, const char* Format, WriteCount* W, long Count)
/* Test one write conversion. Line is the line number (to make the life of the
** tester easier), Format is the format specification. W is a WriteCount
** variable and Count is the expected result.
*/
{
/* Clear the counter in full length */
W->L = 0x5A5A5A5AL;
/* Format the string using the given arguments */
OneTest (Line, "4200", 4, Format, 4200, W);
/* Check the counter */
if (W->L != Count) {
++Failures;
printf ("%3d: n = 0x%08lX\n"
" n = 0x%08lX\n",
Line, W->L, Count);
}
}
int main (void)
{
WriteCount W;
/* The one and only starter to begin with ... */
OneTest (__LINE__, "hello, world", 12, "hello, world");
/* Duplicate percent signs are used to output single ones */
OneTest (__LINE__, "hello % %", 9, "hello %% %%");
/* Simple conversions */
OneTest (__LINE__, "u", 1, "%c", 'u');
OneTest (__LINE__, "4200", 4, "%d", 4200);
OneTest (__LINE__, "-4200", 5, "%d", -4200);
OneTest (__LINE__, "4200", 4, "%i", 4200);
OneTest (__LINE__, "-4200", 5, "%i", -4200);
OneTest (__LINE__, "10150", 5, "%o", 4200U);
OneTest (__LINE__, "167630", 6, "%o", -4200U);
OneTest (__LINE__, "hello, world", 12, "hello, %s", "world");
OneTest (__LINE__, "4200", 4, "%u", 4200U);
OneTest (__LINE__, "61336", 5, "%u", -4200U);
OneTest (__LINE__, "1068", 4, "%x", 4200U);
OneTest (__LINE__, "ef98", 4, "%x", -4200U);
OneTest (__LINE__, "1068", 4, "%X", 4200U);
OneTest (__LINE__, "EF98", 4, "%X", -4200U);
/* Simple conversions with special values */
OneTest (__LINE__, "\0", 1, "%c", '\0');
OneTest (__LINE__, "0", 1, "%d", 0);
OneTest (__LINE__, "0", 1, "%o", 0U);
OneTest (__LINE__, "hello, ", 7, "hello, %s", "");
OneTest (__LINE__, "0", 1, "%u", 0U);
OneTest (__LINE__, "0", 1, "%x", 0U);
/* 'h' modifier */
OneTest (__LINE__, "4200", 4, "%hd", 4200);
OneTest (__LINE__, "-4200", 5, "%hd", -4200);
OneTest (__LINE__, "4200", 4, "%hi", 4200);
OneTest (__LINE__, "-4200", 5, "%hi", -4200);
OneTest (__LINE__, "10150", 5, "%ho", 4200U);
OneTest (__LINE__, "167630", 6, "%ho", -4200U);
OneTest (__LINE__, "4200", 4, "%hu", 4200U);
OneTest (__LINE__, "61336", 5, "%hu", -4200U);
OneTest (__LINE__, "1068", 4, "%hx", 4200U);
OneTest (__LINE__, "ef98", 4, "%hx", -4200U);
OneTest (__LINE__, "1068", 4, "%hX", 4200U);
OneTest (__LINE__, "EF98", 4, "%hX", -4200U);
/* 'hh' modifier */
OneTest (__LINE__, "104", 3, "%hhd", 4200);
OneTest (__LINE__, "-104", 4, "%hhd", -4200);
OneTest (__LINE__, "104", 3, "%hhi", 4200);
OneTest (__LINE__, "-104", 4, "%hhi", -4200);
OneTest (__LINE__, "150", 3, "%hho", 4200U);
OneTest (__LINE__, "230", 3, "%hho", -4200U);
OneTest (__LINE__, "104", 3, "%hhu", 4200U);
OneTest (__LINE__, "152", 3, "%hhu", -4200U);
OneTest (__LINE__, "68", 2, "%hhx", 4200U);
OneTest (__LINE__, "98", 2, "%hhx", -4200U);
OneTest (__LINE__, "68", 2, "%hhX", 4200U);
OneTest (__LINE__, "98", 2, "%hhX", -4200U);
/* 'j' modifier */
OneTest (__LINE__, "4200123", 7, "%jd", 4200123L);
OneTest (__LINE__, "-4200123", 8, "%jd", -4200123L);
OneTest (__LINE__, "4200123", 7, "%ji", 4200123L);
OneTest (__LINE__, "-4200123", 8, "%ji", -4200123L);
OneTest (__LINE__, "20013273", 8, "%jo", 4200123UL);
OneTest (__LINE__, "37757764505", 11, "%jo", -4200123UL);
OneTest (__LINE__, "4200123", 7, "%ju", 4200123UL);
OneTest (__LINE__, "4290767173", 10, "%ju", -4200123UL);
OneTest (__LINE__, "4016bb", 6, "%jx", 4200123UL);
OneTest (__LINE__, "ffbfe945", 8, "%jx", -4200123UL);
OneTest (__LINE__, "4016BB", 6, "%jX", 4200123UL);
OneTest (__LINE__, "FFBFE945", 8, "%jX", -4200123UL);
/* 'l' modifier */
OneTest (__LINE__, "4200123", 7, "%ld", 4200123L);
OneTest (__LINE__, "-4200123", 8, "%ld", -4200123L);
OneTest (__LINE__, "4200123", 7, "%li", 4200123L);
OneTest (__LINE__, "-4200123", 8, "%li", -4200123L);
OneTest (__LINE__, "20013273", 8, "%lo", 4200123UL);
OneTest (__LINE__, "37757764505", 11, "%lo", -4200123UL);
OneTest (__LINE__, "4200123", 7, "%lu", 4200123UL);
OneTest (__LINE__, "4290767173", 10, "%lu", -4200123UL);
OneTest (__LINE__, "4016bb", 6, "%lx", 4200123UL);
OneTest (__LINE__, "ffbfe945", 8, "%lx", -4200123UL);
OneTest (__LINE__, "4016BB", 6, "%lX", 4200123UL);
OneTest (__LINE__, "FFBFE945", 8, "%lX", -4200123UL);
/* 't' modifier */
OneTest (__LINE__, "4200", 4, "%td", 4200);
OneTest (__LINE__, "-4200", 5, "%td", -4200);
OneTest (__LINE__, "4200", 4, "%ti", 4200);
OneTest (__LINE__, "-4200", 5, "%ti", -4200);
OneTest (__LINE__, "10150", 5, "%to", 4200U);
OneTest (__LINE__, "167630", 6, "%to", -4200U);
OneTest (__LINE__, "4200", 4, "%tu", 4200U);
OneTest (__LINE__, "61336", 5, "%tu", -4200U);
OneTest (__LINE__, "1068", 4, "%tx", 4200U);
OneTest (__LINE__, "ef98", 4, "%tx", -4200U);
OneTest (__LINE__, "1068", 4, "%tX", 4200U);
OneTest (__LINE__, "EF98", 4, "%tX", -4200U);
/* 'z' modifier */
OneTest (__LINE__, "4200", 4, "%zd", 4200);
OneTest (__LINE__, "-4200", 5, "%zd", -4200);
OneTest (__LINE__, "4200", 4, "%zi", 4200);
OneTest (__LINE__, "-4200", 5, "%zi", -4200);
OneTest (__LINE__, "10150", 5, "%zo", 4200U);
OneTest (__LINE__, "167630", 6, "%zo", -4200U);
OneTest (__LINE__, "4200", 4, "%zu", 4200U);
OneTest (__LINE__, "61336", 5, "%zu", -4200U);
OneTest (__LINE__, "1068", 4, "%zx", 4200U);
OneTest (__LINE__, "ef98", 4, "%zx", -4200U);
OneTest (__LINE__, "1068", 4, "%zX", 4200U);
OneTest (__LINE__, "EF98", 4, "%zX", -4200U);
/* '+' forces a sign for signed conversions */
OneTest (__LINE__, "u", 1, "%+c", 'u');
OneTest (__LINE__, "+4200", 5, "%+d", 4200);
OneTest (__LINE__, "-4200", 5, "%+d", -4200);
OneTest (__LINE__, "+4200", 5, "%+i", 4200);
OneTest (__LINE__, "-4200", 5, "%+i", -4200);
OneTest (__LINE__, "10150", 5, "%+o", 4200U);
OneTest (__LINE__, "167630", 6, "%+o", -4200U);
OneTest (__LINE__, "hello, world", 12, "%+s", "hello, world");
OneTest (__LINE__, "4200", 4, "%+u", 4200U);
OneTest (__LINE__, "61336", 5, "%+u", -4200U);
OneTest (__LINE__, "1068", 4, "%+x", 4200U);
OneTest (__LINE__, "ef98", 4, "%+x", -4200U);
OneTest (__LINE__, "1068", 4, "%+X", 4200U);
OneTest (__LINE__, "EF98", 4, "%+X", -4200U);
/* ' ': If the first character of a signed conversion is not a sign, or if
** a signed conversion results in no characters, a space is prefixed
** to the result.
*/
OneTest (__LINE__, "u", 1, "% c", 'u');
OneTest (__LINE__, " 4200", 5, "% d", 4200);
OneTest (__LINE__, "-4200", 5, "% d", -4200);
OneTest (__LINE__, " 4200", 5, "% i", 4200);
OneTest (__LINE__, "-4200", 5, "% i", -4200);
OneTest (__LINE__, "10150", 5, "% o", 4200U);
OneTest (__LINE__, "167630", 6, "% o", -4200U);
OneTest (__LINE__, "hello, world", 12, "% s", "hello, world");
OneTest (__LINE__, "4200", 4, "% u", 4200U);
OneTest (__LINE__, "61336", 5, "% u", -4200U);
OneTest (__LINE__, "1068", 4, "% x", 4200U);
OneTest (__LINE__, "ef98", 4, "% x", -4200U);
OneTest (__LINE__, "1068", 4, "% X", 4200U);
OneTest (__LINE__, "EF98", 4, "% X", -4200U);
/* If the ' ' and '+' flags both appear, the ' ' flag is ignored */
OneTest (__LINE__, "u", 1, "% +c", 'u');
OneTest (__LINE__, "+4200", 5, "% +d", 4200);
OneTest (__LINE__, "-4200", 5, "% +d", -4200);
OneTest (__LINE__, "+4200", 5, "% +i", 4200);
OneTest (__LINE__, "-4200", 5, "% +i", -4200);
OneTest (__LINE__, "10150", 5, "% +o", 4200U);
OneTest (__LINE__, "167630", 6, "% +o", -4200U);
OneTest (__LINE__, "hello, world", 12, "% +s", "hello, world");
OneTest (__LINE__, "4200", 4, "% +u", 4200U);
OneTest (__LINE__, "61336", 5, "% +u", -4200U);
OneTest (__LINE__, "1068", 4, "% +x", 4200U);
OneTest (__LINE__, "ef98", 4, "% +x", -4200U);
OneTest (__LINE__, "1068", 4, "% +X", 4200U);
OneTest (__LINE__, "EF98", 4, "% +X", -4200U);
/* Field width given */
OneTest (__LINE__, " u", 15, "%15c", 'u');
OneTest (__LINE__, " 4200", 15, "%15d", 4200);
OneTest (__LINE__, " -4200", 15, "%15d", -4200);
OneTest (__LINE__, " 4200", 15, "%15i", 4200);
OneTest (__LINE__, " -4200", 15, "%15i", -4200);
OneTest (__LINE__, " 10150", 15, "%15o", 4200U);
OneTest (__LINE__, " 167630", 15, "%15o", -4200U);
OneTest (__LINE__, " hello, world", 15, "%15s", "hello, world");
OneTest (__LINE__, " 4200", 15, "%15u", 4200U);
OneTest (__LINE__, " 61336", 15, "%15u", -4200U);
OneTest (__LINE__, " 1068", 15, "%15x", 4200U);
OneTest (__LINE__, " ef98", 15, "%15x", -4200U);
OneTest (__LINE__, " 1068", 15, "%15X", 4200U);
OneTest (__LINE__, " EF98", 15, "%15X", -4200U);
/* Field width given as separate argument */
OneTest (__LINE__, " u", 15, "%*c", 15, 'u');
OneTest (__LINE__, " 4200", 15, "%*d", 15, 4200);
OneTest (__LINE__, " -4200", 15, "%*d", 15, -4200);
OneTest (__LINE__, " 4200", 15, "%*i", 15, 4200);
OneTest (__LINE__, " -4200", 15, "%*i", 15, -4200);
OneTest (__LINE__, " 10150", 15, "%*o", 15, 4200U);
OneTest (__LINE__, " 167630", 15, "%*o", 15, -4200U);
OneTest (__LINE__, " hello, world", 15, "%*s", 15, "hello, world");
OneTest (__LINE__, " 4200", 15, "%*u", 15, 4200U);
OneTest (__LINE__, " 61336", 15, "%*u", 15, -4200U);
OneTest (__LINE__, " 1068", 15, "%*x", 15, 4200U);
OneTest (__LINE__, " ef98", 15, "%*x", 15, -4200U);
OneTest (__LINE__, " 1068", 15, "%*X", 15, 4200U);
OneTest (__LINE__, " EF98", 15, "%*X", 15, -4200U);
/* Field width and '-' flag given */
OneTest (__LINE__, "u ", 15, "%-15c", 'u');
OneTest (__LINE__, "4200 ", 15, "%-15d", 4200);
OneTest (__LINE__, "-4200 ", 15, "%-15d", -4200);
OneTest (__LINE__, "4200 ", 15, "%-15i", 4200);
OneTest (__LINE__, "-4200 ", 15, "%-15i", -4200);
OneTest (__LINE__, "10150 ", 15, "%-15o", 4200U);
OneTest (__LINE__, "167630 ", 15, "%-15o", -4200U);
OneTest (__LINE__, "hello, world ", 15, "%-15s", "hello, world");
OneTest (__LINE__, "4200 ", 15, "%-15u", 4200U);
OneTest (__LINE__, "61336 ", 15, "%-15u", -4200U);
OneTest (__LINE__, "1068 ", 15, "%-15x", 4200U);
OneTest (__LINE__, "ef98 ", 15, "%-15x", -4200U);
OneTest (__LINE__, "1068 ", 15, "%-15X", 4200U);
OneTest (__LINE__, "EF98 ", 15, "%-15X", -4200U);
/* A negative field width specified via an argument is treated as if the
** '-' flag and a positive field width were given.
**
** Beware: These tests will crash the old printf routine!
*/
#ifndef NOCRASH
OneTest (__LINE__, "u ", 15, "%*c", -15, 'u');
OneTest (__LINE__, "4200 ", 15, "%*d", -15, 4200);
OneTest (__LINE__, "-4200 ", 15, "%*d", -15, -4200);
OneTest (__LINE__, "4200 ", 15, "%*i", -15, 4200);
OneTest (__LINE__, "-4200 ", 15, "%*i", -15, -4200);
OneTest (__LINE__, "10150 ", 15, "%*o", -15, 4200U);
OneTest (__LINE__, "167630 ", 15, "%*o", -15, -4200U);
OneTest (__LINE__, "hello, world ", 15, "%*s", -15, "hello, world");
OneTest (__LINE__, "4200 ", 15, "%*u", -15, 4200U);
OneTest (__LINE__, "61336 ", 15, "%*u", -15, -4200U);
OneTest (__LINE__, "1068 ", 15, "%*x", -15, 4200U);
OneTest (__LINE__, "ef98 ", 15, "%*x", -15, -4200U);
OneTest (__LINE__, "1068 ", 15, "%*X", -15, 4200U);
OneTest (__LINE__, "EF98 ", 15, "%*X", -15, -4200U);
#endif
/* Field width smaller than converted value */
OneTest (__LINE__, "u", 1, "%1c", 'u');
OneTest (__LINE__, "4200", 4, "%1d", 4200);
OneTest (__LINE__, "-4200", 5, "%1d", -4200);
OneTest (__LINE__, "4200", 4, "%1i", 4200);
OneTest (__LINE__, "-4200", 5, "%1i", -4200);
OneTest (__LINE__, "10150", 5, "%1o", 4200U);
OneTest (__LINE__, "167630", 6, "%1o", -4200U);
OneTest (__LINE__, "hello, world", 12, "%1s", "hello, world");
OneTest (__LINE__, "4200", 4, "%1u", 4200U);
OneTest (__LINE__, "61336", 5, "%1u", -4200U);
OneTest (__LINE__, "1068", 4, "%1x", 4200U);
OneTest (__LINE__, "ef98", 4, "%1x", -4200U);
OneTest (__LINE__, "1068", 4, "%1X", 4200U);
OneTest (__LINE__, "EF98", 4, "%1X", -4200U);
/* Field width specified and '0' flag given */
OneTest (__LINE__, "000000000004200", 15, "%015d", 4200);
OneTest (__LINE__, "-00000000004200", 15, "%015d", -4200);
OneTest (__LINE__, "000000000004200", 15, "%015i", 4200);
OneTest (__LINE__, "-00000000004200", 15, "%015i", -4200);
OneTest (__LINE__, "000000000010150", 15, "%015o", 4200U);
OneTest (__LINE__, "000000000167630", 15, "%015o", -4200U);
OneTest (__LINE__, "000000000004200", 15, "%015u", 4200U);
OneTest (__LINE__, "000000000061336", 15, "%015u", -4200U);
OneTest (__LINE__, "000000000001068", 15, "%015x", 4200U);
OneTest (__LINE__, "00000000000ef98", 15, "%015x", -4200U);
OneTest (__LINE__, "000000000001068", 15, "%015X", 4200U);
OneTest (__LINE__, "00000000000EF98", 15, "%015X", -4200U);
/* If the '-' and '0' flags are both specified, '0' is ignored */
OneTest (__LINE__, "4200 ", 15, "%-015d", 4200);
OneTest (__LINE__, "-4200 ", 15, "%-015d", -4200);
OneTest (__LINE__, "4200 ", 15, "%-015i", 4200);
OneTest (__LINE__, "-4200 ", 15, "%-015i", -4200);
OneTest (__LINE__, "10150 ", 15, "%-015o", 4200U);
OneTest (__LINE__, "167630 ", 15, "%-015o", -4200U);
OneTest (__LINE__, "4200 ", 15, "%-015u", 4200U);
OneTest (__LINE__, "61336 ", 15, "%-015u", -4200U);
OneTest (__LINE__, "1068 ", 15, "%-015x", 4200U);
OneTest (__LINE__, "ef98 ", 15, "%-015x", -4200U);
OneTest (__LINE__, "1068 ", 15, "%-015X", 4200U);
OneTest (__LINE__, "EF98 ", 15, "%-015X", -4200U);
/* Precision given */
OneTest (__LINE__, "u", 1, "%.15c", 'u');
OneTest (__LINE__, "000000000004200", 15, "%.15d", 4200);
OneTest (__LINE__, "-000000000004200", 16, "%.15d", -4200);
OneTest (__LINE__, "000000000004200", 15, "%.15i", 4200);
OneTest (__LINE__, "-000000000004200", 16, "%.15i", -4200);
OneTest (__LINE__, "000000000010150", 15, "%.15o", 4200U);
OneTest (__LINE__, "000000000167630", 15, "%.15o", -4200U);
OneTest (__LINE__, "hello, world", 12, "%.15s", "hello, world");
OneTest (__LINE__, "000000000004200", 15, "%.15u", 4200U);
OneTest (__LINE__, "000000000061336", 15, "%.15u", -4200U);
OneTest (__LINE__, "000000000001068", 15, "%.15x", 4200U);
OneTest (__LINE__, "00000000000ef98", 15, "%.15x", -4200U);
OneTest (__LINE__, "000000000001068", 15, "%.15X", 4200U);
OneTest (__LINE__, "00000000000EF98", 15, "%.15X", -4200U);
/* Precision given via argument */
OneTest (__LINE__, "u", 1, "%.*c", 15, 'u');
OneTest (__LINE__, "000000000004200", 15, "%.*d", 15, 4200);
OneTest (__LINE__, "-000000000004200", 16, "%.*d", 15, -4200);
OneTest (__LINE__, "000000000004200", 15, "%.*i", 15, 4200);
OneTest (__LINE__, "-000000000004200", 16, "%.*i", 15, -4200);
OneTest (__LINE__, "000000000010150", 15, "%.*o", 15, 4200U);
OneTest (__LINE__, "000000000167630", 15, "%.*o", 15, -4200U);
OneTest (__LINE__, "hello, world", 12, "%.*s", 15, "hello, world");
OneTest (__LINE__, "000000000004200", 15, "%.*u", 15, 4200U);
OneTest (__LINE__, "000000000061336", 15, "%.*u", 15, -4200U);
OneTest (__LINE__, "000000000001068", 15, "%.*x", 15, 4200U);
OneTest (__LINE__, "00000000000ef98", 15, "%.*x", 15, -4200U);
OneTest (__LINE__, "000000000001068", 15, "%.*X", 15, 4200U);
OneTest (__LINE__, "00000000000EF98", 15, "%.*X", 15, -4200U);
/* Negative precision is treated as if the precision were omitted */
#ifndef NOCRASH
OneTest (__LINE__, "u", 1, "%.*c", -15, 'u');
OneTest (__LINE__, "4200", 4, "%.*d", -15, 4200);
OneTest (__LINE__, "-4200", 5, "%.*d", -15, -4200);
OneTest (__LINE__, "4200", 4, "%.*i", -15, 4200);
OneTest (__LINE__, "-4200", 5, "%.*i", -15, -4200);
OneTest (__LINE__, "10150", 5, "%.*o", -15, 4200U);
OneTest (__LINE__, "167630", 6, "%.*o", -15, -4200U);
OneTest (__LINE__, "hello, world", 12, "%.*s", -15, "hello, world");
OneTest (__LINE__, "4200", 4, "%.*u", -15, 4200U);
OneTest (__LINE__, "61336", 5, "%.*u", -15, -4200U);
OneTest (__LINE__, "1068", 4, "%.*x", -15, 4200U);
OneTest (__LINE__, "ef98", 4, "%.*x", -15, -4200U);
OneTest (__LINE__, "1068", 4, "%.*X", -15, 4200U);
OneTest (__LINE__, "EF98", 4, "%.*X", -15, -4200U);
#endif
/* Field width and precision given */
OneTest (__LINE__, " u", 15, "%15.10c", 'u');
OneTest (__LINE__, " 0000004200", 15, "%15.10d", 4200);
OneTest (__LINE__, " -0000004200", 15, "%15.10d", -4200);
OneTest (__LINE__, " 0000004200", 15, "%15.10i", 4200);
OneTest (__LINE__, " -0000004200", 15, "%15.10i", -4200);
OneTest (__LINE__, " 0000010150", 15, "%15.10o", 4200U);
OneTest (__LINE__, " 0000167630", 15, "%15.10o", -4200U);
OneTest (__LINE__, " hello, wor", 15, "%15.10s", "hello, world");
OneTest (__LINE__, " 0000004200", 15, "%15.10u", 4200U);
OneTest (__LINE__, " 0000061336", 15, "%15.10u", -4200U);
OneTest (__LINE__, " 0000001068", 15, "%15.10x", 4200U);
OneTest (__LINE__, " 000000ef98", 15, "%15.10x", -4200U);
OneTest (__LINE__, " 0000001068", 15, "%15.10X", 4200U);
OneTest (__LINE__, " 000000EF98", 15, "%15.10X", -4200U);
/* For d, i, o, u, x and X conversions, if a precision is specified, the
** '0' flag is ignored.
*/
OneTest (__LINE__, " 0000004200", 15, "%015.10d", 4200);
OneTest (__LINE__, " -0000004200", 15, "%015.10d", -4200);
OneTest (__LINE__, " 0000004200", 15, "%015.10i", 4200);
OneTest (__LINE__, " -0000004200", 15, "%015.10i", -4200);
OneTest (__LINE__, " 0000010150", 15, "%015.10o", 4200U);
OneTest (__LINE__, " 0000167630", 15, "%015.10o", -4200U);
OneTest (__LINE__, " 0000004200", 15, "%015.10u", 4200U);
OneTest (__LINE__, " 0000061336", 15, "%015.10u", -4200U);
OneTest (__LINE__, " 0000001068", 15, "%015.10x", 4200U);
OneTest (__LINE__, " 000000ef98", 15, "%015.10x", -4200U);
OneTest (__LINE__, " 0000001068", 15, "%015.10X", 4200U);
OneTest (__LINE__, " 000000EF98", 15, "%015.10X", -4200U);
/* Zero precision, explicitly specified */
OneTest (__LINE__, "u", 1, "%.0c", 'u');
OneTest (__LINE__, "4200", 4, "%.0d", 4200);
OneTest (__LINE__, "-4200", 5, "%.0d", -4200);
OneTest (__LINE__, "4200", 4, "%.0i", 4200);
OneTest (__LINE__, "-4200", 5, "%.0i", -4200);
OneTest (__LINE__, "10150", 5, "%.0o", 4200U);
OneTest (__LINE__, "167630", 6, "%.0o", -4200U);
OneTest (__LINE__, "", 0, "%.0s", "hello, world");
OneTest (__LINE__, "4200", 4, "%.0u", 4200U);
OneTest (__LINE__, "61336", 5, "%.0u", -4200U);
OneTest (__LINE__, "1068", 4, "%.0x", 4200U);
OneTest (__LINE__, "ef98", 4, "%.0x", -4200U);
OneTest (__LINE__, "1068", 4, "%.0X", 4200U);
OneTest (__LINE__, "EF98", 4, "%.0X", -4200U);
/* Zero precision, dot only */
OneTest (__LINE__, "u", 1, "%.c", 'u');
OneTest (__LINE__, "4200", 4, "%.d", 4200);
OneTest (__LINE__, "-4200", 5, "%.d", -4200);
OneTest (__LINE__, "4200", 4, "%.i", 4200);
OneTest (__LINE__, "-4200", 5, "%.i", -4200);
OneTest (__LINE__, "10150", 5, "%.o", 4200U);
OneTest (__LINE__, "167630", 6, "%.o", -4200U);
OneTest (__LINE__, "", 0, "%.s", "hello, world");
OneTest (__LINE__, "4200", 4, "%.u", 4200U);
OneTest (__LINE__, "61336", 5, "%.u", -4200U);
OneTest (__LINE__, "1068", 4, "%.x", 4200U);
OneTest (__LINE__, "ef98", 4, "%.x", -4200U);
OneTest (__LINE__, "1068", 4, "%.X", 4200U);
OneTest (__LINE__, "EF98", 4, "%.X", -4200U);
/* Zero precision, zero value */
OneTest (__LINE__, "", 0, "%.0d", 0);
OneTest (__LINE__, "", 0, "%.0i", 0);
OneTest (__LINE__, "", 0, "%.0o", 0U);
OneTest (__LINE__, "", 0, "%.0u", 0U);
OneTest (__LINE__, "", 0, "%.0x", 0U);
OneTest (__LINE__, "", 0, "%.0X", 0U);
/* Field width and zero precision given */
OneTest (__LINE__, " u", 15, "%15.0c", 'u');
OneTest (__LINE__, " 4200", 15, "%15.0d", 4200);
OneTest (__LINE__, " -4200", 15, "%15.0d", -4200);
OneTest (__LINE__, " 4200", 15, "%15.0i", 4200);
OneTest (__LINE__, " -4200", 15, "%15.0i", -4200);
OneTest (__LINE__, " 10150", 15, "%15.0o", 4200U);
OneTest (__LINE__, " 167630", 15, "%15.0o", -4200U);
OneTest (__LINE__, " ", 15, "%15.0s", "hello, world");
OneTest (__LINE__, " 4200", 15, "%15.0u", 4200U);
OneTest (__LINE__, " 61336", 15, "%15.0u", -4200U);
OneTest (__LINE__, " 1068", 15, "%15.0x", 4200U);
OneTest (__LINE__, " ef98", 15, "%15.0x", -4200U);
OneTest (__LINE__, " 1068", 15, "%15.0X", 4200U);
OneTest (__LINE__, " EF98", 15, "%15.0X", -4200U);
/* Field width, zero precision and zero value */
OneTest (__LINE__, " ", 15, "%15.0d", 0);
OneTest (__LINE__, " ", 15, "%15.0i", 0);
OneTest (__LINE__, " ", 15, "%15.0o", 0U);
OneTest (__LINE__, " ", 15, "%15.0u", 0U);
OneTest (__LINE__, " ", 15, "%15.0x", 0U);
OneTest (__LINE__, " ", 15, "%15.0X", 0U);
/* Alternative form */
OneTest (__LINE__, "010150", 6, "%#o", 4200U);
OneTest (__LINE__, "0167630", 7, "%#o", -4200U);
OneTest (__LINE__, "0x1068", 6, "%#x", 4200U);
OneTest (__LINE__, "0xef98", 6, "%#x", -4200U);
OneTest (__LINE__, "0X1068", 6, "%#X", 4200U);
OneTest (__LINE__, "0XEF98", 6, "%#X", -4200U);
/* Alternative form with zero value */
#ifndef NOCRASH
OneTest (__LINE__, "0", 1, "%#o", 0U);
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);
OneTest (__LINE__, "0", 1, "%#.1x", 0U);
OneTest (__LINE__, "0", 1, "%#.1X", 0U);
/* Alternative form with non zero value and precision 1 */
OneTest (__LINE__, "01", 2, "%#.1o", 1U);
OneTest (__LINE__, "0x1", 3, "%#.1x", 1U);
OneTest (__LINE__, "0X1", 3, "%#.1X", 1U);
/* Alternative form and width given */
OneTest (__LINE__, " 010150", 15, "%#15o", 4200U);
OneTest (__LINE__, " 0x1068", 15, "%#15x", 4200U);
OneTest (__LINE__, " 0X1068", 15, "%#15X", 4200U);
/* Alternative form, width and zero padding */
OneTest (__LINE__, "000000000010150", 15, "%#015o", 4200U);
OneTest (__LINE__, "0x0000000001068", 15, "%#015x", 4200U);
OneTest (__LINE__, "0X0000000001068", 15, "%#015X", 4200U);
/* n conversion specifier */
WriteTest (__LINE__, "%d%n", &W, 0x5A5A0004L);
WriteTest (__LINE__, "%d%hn", &W, 0x5A5A0004L);
WriteTest (__LINE__, "%d%hhn", &W, 0x5A5A5A04L);
WriteTest (__LINE__, "%d%ln", &W, 0x00000004L);
/* Output the result */
if (Failures) {
printf ("%u tests, %u failures\n", Tests, Failures);
} else {
printf ("%u tests: Ok\n", Tests);
}
/* Wait for a key so we can read the result */
#if defined(__CC65__)
cgetc ();
#endif
return 0;
}

View File

@@ -1,24 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static const char S1[] = {
'h', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '\0', 'A'
};
static const char S2[] = {
'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\0', 'B'
};
int main (void)
{
char I;
for (I = 0; I < 20; ++I) {
printf ("%02d: %d\n", I, strncmp (S1, S2, I));
}
return 0;
}

View File

@@ -1,72 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
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);
}
int main(void)
{
int ret;
ret = do_test("Wurzl", "wURZL", 5);
if (ret)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("Wurzl", "wURZL", 6);
if (ret)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("Wurzl", "wURZL", 10);
if (ret)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("Wurzla", "wURZLB", 10);
if (ret >= 0)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("Wurzla", "wURZLb", 5);
if (ret)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("BLI", "bla", 5);
if (ret <= 0)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("", "bla", 5);
if (ret >= 0)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("BLI", "", 5);
if (ret <= 0)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
ret = do_test("", "", 5);
if (ret)
printf("fail (%d)\n", ret);
else
printf("OK (%d)\n", ret);
cgetc();
return 0;
}

View File

@@ -1,26 +0,0 @@
#include <stdio.h>
#include <string.h>
static const char fox[] = "The quick brown fox jumped over the lazy dogs.";
void main (void)
{
printf ("Testing strpbrk():\n");
if (strpbrk (fox, "qwerty") != &fox[2]) {
printf ("\nThe first 'e' wasn't found.\n");
}
if (strpbrk (fox, "QWERTY") != &fox[0]) {
printf ("The 'T' wasn't found.\n");
}
if (strpbrk (fox, "asdfg") != &fox[16]) {
printf ("The 'f' wasn't found.\n");
}
if (strpbrk (fox, "nxv,zmb") != &fox[10]) {
printf ("The 'b' wasn't found.\n");
}
if (strpbrk (fox, "!@#$%^&*()-+=[];:',/?<>.") != &fox[45]) {
printf ("The '.' wasn't found.\n");
}
printf ("\nFinished.\n");
}

View File

@@ -1,145 +0,0 @@
/* A small test for strtol. Assumes twos complement */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#define outfile stderr
#define ERROR 0
#define OK 1
static unsigned int Failures = 0;
static void IncStr (char* Buf)
/* Increment a number represented as a string by one. The string MUST not
** start with a '9', we cannot handle overflow in this case.
*/
{
int Len = strlen (Buf);
while (--Len >= 0) {
switch (Buf[Len]) {
case '9':
Buf[Len] = '0';
break;
default:
++(Buf[Len]);
return;
}
}
}
static void CheckStrToL (const char* Str, int Base, long Val, unsigned char Ok)
{
char* EndPtr;
long Res = strtol (Str, &EndPtr, Base);
if (Ok) {
if (Res != Val) {
fprintf (outfile,
"strtol error in \"%s\":\n"
" result = %ld, should be %ld, chars = %d\n",
Str, Res, Val, EndPtr - Str);
++Failures;
}
} else {
if (errno != ERANGE) {
fprintf (outfile,
"strtol error in \"%s\":\n"
" should not convert, but errno = %d\n",
Str, errno);
++Failures;
}
if (Res != Val) {
fprintf (outfile,
"strtol error in \"%s\":\n"
" result = %ld, should be %ld, chars = %d\n",
Str, Res, Val, EndPtr - Str);
++Failures;
}
}
}
int main (void)
{
char Buf[80];
/* Prefixed allowed if base = 0 */
CheckStrToL ("\t 0x10G ", 0, 16L, OK);
CheckStrToL ("\t 0X10G ", 0, 16L, OK);
CheckStrToL (" \t0377\t", 0, 255L, OK);
CheckStrToL (" 377", 0, 377L, OK);
CheckStrToL ("\t -0x10G ", 0, -16L, OK);
CheckStrToL ("\t -0X10G ", 0, -16L, OK);
CheckStrToL (" \t-0377\t", 0, -255L, OK);
CheckStrToL (" -377", 0, -377L, OK);
/* No prefixes if base = 10 */
CheckStrToL ("\t 1234 ", 10, 1234L, OK);
CheckStrToL ("\t -1234 ", 10, -1234L, OK);
CheckStrToL ("\t -0x10G ", 10, 0L, OK);
CheckStrToL ("\t -0X10G ", 10, 0L, OK);
CheckStrToL (" \t-0377\t", 10, -377L, OK);
CheckStrToL (" 0377", 10, 377L, OK);
/* 0x prefix is allowed if base = 16 */
CheckStrToL ("\t 0x1234 ", 16, 0x1234L, OK);
CheckStrToL ("\t -0x1234 ", 16, -0x1234L, OK);
CheckStrToL ("\t -010G ", 16, -16L, OK);
CheckStrToL ("\t 10G ", 16, 16L, OK);
/* Check LONG_MIN and LONG_MAX */
sprintf (Buf, "%ld", LONG_MIN);
CheckStrToL (Buf, 0, LONG_MIN, OK);
sprintf (Buf, "%ld", LONG_MAX);
CheckStrToL (Buf, 0, LONG_MAX, OK);
/* Check value one smaller */
sprintf (Buf+1, "%ld", LONG_MIN);
Buf[1] = '0'; /* Overwrite '-' */
IncStr (Buf+1);
if (Buf[1] == '0') {
Buf[1] = '-';
Buf[0] = ' ';
} else {
Buf[0] = '-';
}
CheckStrToL (Buf, 0, LONG_MIN, ERROR);
/* Check value one larger */
sprintf (Buf+1, "%ld", LONG_MAX);
Buf[0] = '0';
IncStr (Buf);
if (Buf[0] == '0') {
Buf[0] = ' ';
}
CheckStrToL (Buf, 0, LONG_MAX, ERROR);
/* Check numbers that are much too large or small */
CheckStrToL ("-999999999999999999999999999999999999999999999999999999999", 0, LONG_MIN, ERROR);
CheckStrToL ("+999999999999999999999999999999999999999999999999999999999", 0, LONG_MAX, ERROR);
CheckStrToL (" 999999999999999999999999999999999999999999999999999999999", 0, LONG_MAX, ERROR);
/* Check a few other bases */
CheckStrToL ("aBcD", 36, 481261L, OK);
CheckStrToL ("zyaB", 35, 0L, ERROR);
CheckStrToL ("zyaB", 36, 1677395L, ERROR);
fprintf (outfile, "Failures: %u\n", Failures);
return (Failures != 0);
}

View File

@@ -1,132 +0,0 @@
/* A small test for strtuol. Assumes twos complement */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#define outfile stderr
#define ERROR 0
#define OK 1
static unsigned int Failures = 0;
static void IncStr (char* Buf)
/* Increment a number represented as a string by one. The string MUST not
** start with a '9', we cannot handle overflow in this case.
*/
{
int Len = strlen (Buf);
while (--Len >= 0) {
switch (Buf[Len]) {
case '9':
Buf[Len] = '0';
break;
default:
++(Buf[Len]);
return;
}
}
}
static void CheckStrToUL (const char* Str, int Base, unsigned long Val, unsigned char Ok)
{
char* EndPtr;
unsigned long Res = strtoul (Str, &EndPtr, Base);
if (Ok) {
if (Res != Val) {
fprintf (outfile,
"strtol error in \"%s\":\n"
" result = %lu, should be %lu, chars = %d\n",
Str, Res, Val, EndPtr - Str);
++Failures;
}
} else {
if (errno != ERANGE) {
fprintf (outfile,
"strtol error in \"%s\":\n"
" should not convert, but errno = %d\n",
Str, errno);
++Failures;
}
if (Res != Val) {
fprintf (outfile,
"strtol error in \"%s\":\n"
" result = %lu, should be %lu, chars = %d\n",
Str, Res, Val, EndPtr - Str);
++Failures;
}
}
}
int main (void)
{
char Buf[80];
/* Prefixed allowed if base = 0 */
CheckStrToUL ("\t 0x10G ", 0, 16UL, OK);
CheckStrToUL ("\t 0X10G ", 0, 16UL, OK);
CheckStrToUL (" \t0377\t", 0, 255UL, OK);
CheckStrToUL (" 377", 0, 377UL, OK);
CheckStrToUL ("\t -0x10G ", 0, (unsigned long) -16L, OK);
CheckStrToUL ("\t -0X10G ", 0, (unsigned long) -16L, OK);
CheckStrToUL (" \t-0377\t", 0, (unsigned long) -255L, OK);
CheckStrToUL (" -377", 0, (unsigned long) -377L, OK);
/* No prefixes if base = 10 */
CheckStrToUL ("\t 1234 ", 10, 1234UL, OK);
CheckStrToUL ("\t -1234 ", 10, (unsigned long) -1234L, OK);
CheckStrToUL ("\t -0x10G ", 10, 0UL, OK);
CheckStrToUL ("\t -0X10G ", 10, 0UL, OK);
CheckStrToUL (" \t-0377\t", 10, (unsigned long) -377L, OK);
CheckStrToUL (" 0377", 10, 377UL, OK);
/* 0x prefix is allowed if base = 16 */
CheckStrToUL ("\t 0x1234 ", 16, 0x1234UL, OK);
CheckStrToUL ("\t -0x1234 ", 16, (unsigned long) -0x1234L, OK);
CheckStrToUL ("\t -010G ", 16, (unsigned long) -16L, OK);
CheckStrToUL ("\t 10G ", 16, 16UL, OK);
/* Check ULONG_MAX */
sprintf (Buf, "%lu", ULONG_MAX);
CheckStrToUL (Buf, 0, ULONG_MAX, OK);
/* Check value one larger */
sprintf (Buf+1, "%lu", ULONG_MAX);
Buf[0] = '0';
IncStr (Buf);
if (Buf[0] == '0') {
Buf[0] = ' ';
}
CheckStrToUL (Buf, 0, ULONG_MAX, ERROR);
/* Check numbers that are much too large or small */
CheckStrToUL ("-999999999999999999999999999999999999999999999999999999999", 0, ULONG_MAX, ERROR);
CheckStrToUL ("+999999999999999999999999999999999999999999999999999999999", 0, ULONG_MAX, ERROR);
CheckStrToUL (" 999999999999999999999999999999999999999999999999999999999", 0, ULONG_MAX, ERROR);
/* Check a few other bases */
CheckStrToUL ("aBcD", 36, 481261UL, OK);
CheckStrToUL ("zyaB", 35, 0UL, ERROR);
CheckStrToUL ("zyaB", 36, 1677395UL, ERROR);
fprintf (outfile, "Failures: %u\n", Failures);
return (Failures != 0);
}

View File

@@ -1,38 +0,0 @@
#include <stdio.h>
#include <time.h>
int main (void)
{
struct tm tm;
time_t t;
char buf[64];
tm.tm_sec = 9;
tm.tm_min = 34;
tm.tm_hour = 21;
tm.tm_mday = 12;
tm.tm_mon = 10; /* 0..11, so this is november */
tm.tm_year = 102; /* year - 1900, so this is 2002 */
tm.tm_wday = 2; /* Tuesday */
tm.tm_isdst = 0;
/* Convert this broken down time into a time_t and back */
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)));
strftime (buf, sizeof (buf), "%c", &tm);
printf ("%08lX - %s\n", t, buf);
strftime (buf, sizeof (buf), "%a %b %d %H:%M:%S %Y", &tm);
printf ("%08lX - %s\n", t, buf);
return 0;
}