[build] Move headers out of target dirs

The great header shift: It didn't make sense to regenerate headers for
the same module for every target (boot/kernel/user) it appeared in. And
now that core headers are out of src/include, this was going to cause
problems for the new libc changes I've been working on. So I went back
to re-design how module headers work.

Pre-requisites:
- A module's public headers should all be available in one location, not
  tied to target.
- No accidental includes. Another module should not be able to include
  anything (creating an implicit dependency) from a module without
  declaring an explicit dependency.
- Exception to the previous: libc's headers should be available to all,
  at least for the freestanding headers.

New system:
- A new "public_headers" property of module declares all public headers
  that should be available to dependant modules
- All public headers (after possible processing) are installed relative
  to build/include/<module> with the same path as their source
- This also means no "include" dir in modules is necessary. If a header
  should be included as <j6/types.h> then its source should be
  src/libraries/j6/j6/types.h - this caused the most churn as all public
  header sources moved one directory up.
- The "includes" property of a module is local only to that module now,
  it does not create any implicit public interface

Other changes:
- The bonnibel concept of sources changed: instead of sources having
  actions, they themselves are an instance of a (sub)class of Source,
  which provides all the necessary information itself.
- Along with the above, rule names were standardized into <type>.<ext>,
  eg "compile.cpp" or "parse.cog"
- cog and cogflags variables moved from per-target scope to global scope
  in the build files.
- libc gained a more dynamic .module file
This commit is contained in:
Justin C. Miller
2022-02-06 10:18:51 -08:00
parent db23e4966e
commit 4545256b49
103 changed files with 362 additions and 5191 deletions

View File

@@ -2,11 +2,14 @@
bp = module("bootproto",
kind = "lib",
includes = [ "include" ],
sources = [
public_headers = [
"bootproto/bootconfig.h",
"bootproto/init.h",
"bootproto/kernel.h",
"bootproto/memory.h.cog",
])
from os.path import join
layout = join(source_root, "definitions/memory_layout.yaml")
bp.add_input("include/bootproto/memory.h.cog", deps=[layout])
bp.add_depends("bootproto/memory.h.cog", deps=[layout])

View File

@@ -2,7 +2,10 @@
module("cpu",
kind = "lib",
includes = ["include"],
sources = [
"cpu_id.cpp",
],
public_headers = [
"cpu/cpu_id.h",
"cpu/features.inc",
])

View File

@@ -2,8 +2,11 @@
module("elf",
kind = "lib",
includes = [ "include" ],
deps = [ "util" ],
sources = [
"file.cpp",
],
public_headers = [
"elf/file.h",
"elf/headers.h",
])

View File

@@ -2,14 +2,25 @@
j6 = module("j6",
kind = "lib",
includes = [ "include" ],
sources = [
"init.cpp",
"include/j6/caps.h.cog",
"include/j6/syscalls.h.cog",
"include/j6/sysconf.h.cog",
"syscalls.s.cog",
"sysconf.cpp.cog",
],
public_headers = [
"j6/caps.h.cog",
"j6/errors.h",
"j6/flags.h",
"j6/init.h",
"j6/signals.h",
"j6/syscalls.h.cog",
"j6/sysconf.h.cog",
"j6/types.h",
"j6/tables/log_areas.inc",
"j6/tables/object_types.inc",
"j6/tables/syscalls.inc",
"j6/tables/vm_flags.inc",
])
from glob import glob
@@ -19,13 +30,13 @@ sysconf = join(source_root, "definitions/sysconf.yaml")
definitions = glob('definitions/**/*.def', recursive=True)
j6.add_depends([
"include/j6/caps.h.cog",
"include/j6/syscalls.h.cog",
"j6/caps.h.cog",
"j6/syscalls.h.cog",
"syscalls.s.cog",
], definitions)
j6.add_depends([
"include/j6/sysconf.h.cog",
"j6/sysconf.h.cog",
"sysconf.cpp.cog",
], [sysconf])

View File

@@ -1,166 +1,33 @@
# vim: ft=python
# Normally I prefer listing every source file so that ninja can pick
# up on added files and regenerate appropriately, but libc has _so_
# many files that it's unweildy. So if a file is added or removed in
# libc, remember to run configure again.
def glob(ext):
from glob import glob
def resolve(path):
from pathlib import Path
return str(Path(path).relative_to(module_root))
return list(map(resolve, glob(f"{module_root}/**/*.{ext}", recursive=True)))
sources = []
for ext in ("c", "cpp", "s"):
sources += glob(ext) + glob(ext + ".cog")
headers = []
for ext in ("h", "inc"):
headers += glob(ext) + glob(ext + ".cog")
libc = module("libc",
kind = "lib",
includes = [ "include" ],
deps = [ "j6" ],
sources = [
"arch/x86_64/_Exit.s",
"arch/x86_64/crt0.s",
"ctype/isalnum.c",
"ctype/isalpha.c",
"ctype/isblank.c",
"ctype/iscntrl.c",
"ctype/isdigit.c",
"ctype/isgraph.c",
"ctype/islower.c",
"ctype/isprint.c",
"ctype/ispunct.c",
"ctype/isspace.c",
"ctype/isupper.c",
"ctype/isxdigit.c",
"ctype/tolower.c",
"ctype/toupper.c",
"inttypes/imaxabs.c",
"inttypes/imaxdiv.c",
"inttypes/strtoimax.c",
"inttypes/strtoumax.c",
"locale/localeconv.c",
"locale/setlocale.c",
"j6libc/assert.c",
"j6libc/errno.c",
"j6libc/allocpages.c",
"j6libc/atomax.c",
"j6libc/closeall.c",
"j6libc/close.c",
"j6libc/digits.c",
"j6libc/filemode.c",
"j6libc/fillbuffer.c",
"j6libc/flushbuffer.c",
"j6libc/is_leap.c",
"j6libc/load_lc_collate.c",
"j6libc/load_lc_ctype.c",
"j6libc/load_lc_messages.c",
"j6libc/load_lc_monetary.c",
"j6libc/load_lc_numeric.c",
"j6libc/load_lc_time.c",
"j6libc/load_lines.c",
"j6libc/open.c",
"j6libc/prepread.c",
"j6libc/prepwrite.c",
"j6libc/print.c",
"j6libc/rename.c",
"j6libc/scan.c",
"j6libc/seed.c",
"j6libc/seek.c",
"j6libc/stdinit.c",
"j6libc/strtox_main.c",
"j6libc/strtox_prelim.c",
"j6libc/sbrk.c",
"signal/raise.c",
"signal/signal.c",
"stdio/clearerr.c",
"stdio/fclose.c",
"stdio/feof.c",
"stdio/ferror.c",
"stdio/fflush.c",
"stdio/fgetc.c",
"stdio/fgetpos.c",
"stdio/fgets.c",
"stdio/fopen.c",
"stdio/fprintf.c",
"stdio/fputc.c",
"stdio/fputs.c",
"stdio/fread.c",
"stdio/freopen.c",
"stdio/fscanf.c",
"stdio/fseek.c",
"stdio/fsetpos.c",
"stdio/ftell.c",
"stdio/fwrite.c",
"stdio/getc.c",
"stdio/getchar.c",
"stdio/perror.c",
"stdio/printf.c",
"stdio/putc.c",
"stdio/putchar.c",
"stdio/puts.c",
"stdio/remove.c",
"stdio/rename.c",
"stdio/rewind.c",
"stdio/scanf.c",
"stdio/setbuf.c",
"stdio/setvbuf.c",
"stdio/snprintf.c",
"stdio/sprintf.c",
"stdio/sscanf.c",
"stdio/tmpfile.c",
"stdio/tmpnam.c",
"stdio/ungetc.c",
"stdio/vfprintf.c",
"stdio/vfscanf.c",
"stdio/vprintf.c",
"stdio/vscanf.c",
"stdio/vsnprintf.c",
"stdio/vsprintf.c",
"stdio/vsscanf.c",
"stdlib/abort.c",
"stdlib/abs.c",
"stdlib/atexit.c",
"stdlib/atoi.c",
"stdlib/atol.c",
"stdlib/atoll.c",
"stdlib/bsearch.c",
"stdlib/div.c",
"stdlib/exit.c",
"stdlib/_Exit.c",
"stdlib/getenv.c",
"stdlib/labs.c",
"stdlib/ldiv.c",
"stdlib/llabs.c",
"stdlib/lldiv.c",
"stdlib/malloc.c",
"stdlib/qsort.c",
"stdlib/rand.c",
"stdlib/srand.c",
"stdlib/strtol.c",
"stdlib/strtoll.c",
"stdlib/strtoul.c",
"stdlib/strtoull.c",
"stdlib/system.c",
"string/memchr.c",
"string/memcmp.c",
"string/memcpy.c",
"string/memmove.c",
"string/memset.c",
"string/strcat.c",
"string/strchr.c",
"string/strcmp.c",
"string/strcoll.c",
"string/strcpy.c",
"string/strcspn.c",
"string/strerror.c",
"string/strlen.c",
"string/strncat.c",
"string/strncmp.c",
"string/strncpy.c",
"string/strpbrk.c",
"string/strrchr.c",
"string/strspn.c",
"string/strstr.c",
"string/strtok.c",
"string/strxfrm.c",
"time/asctime.c",
"time/clock.c",
"time/ctime.c",
"time/difftime.c",
"time/gmtime.c",
"time/localtime.c",
"time/mktime.c",
"time/strftime.c",
"time/time.c",
"time/timespec_get.c",
])
sources = sources,
public_headers = headers,
)
libc.variables["ccflags"] = [
"${ccflags}",

View File

@@ -112,6 +112,8 @@ void free( void * ptr );
*/
void * realloc( void * ptr, size_t size );
int posix_memalign(void**, size_t, size_t);
/* Communication with the environment */
/* These two can be passed to exit() or _Exit() as status values, to signal

View File

@@ -1,169 +0,0 @@
/* PDCLib testing suite <_PDCLIB_test.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
/* -------------------------------------------------------------------------- */
/* Helper macros for printf() / scanf() tests */
/* -------------------------------------------------------------------------- */
/* Tucked away in a seperate header because these are ugly, complex, and not */
/* needed in 95% of all test cases. */
/* -------------------------------------------------------------------------- */
/* ...scanf() tests */
#if defined( _PDCLIB_FILEIO )
#define PREPARE_SOURCE( input_string ) \
rewind( source ); \
fwrite( input_string, 1, sizeof( input_string ), source ); \
rewind( source );
#elif defined( _PDCLIB_STRINGIO )
#define PREPARE_SOURCE( input_string ) \
memcpy( source, input_string, sizeof( input_string ) );
#endif
/* Virtually everything in the printf() / scanf() test drivers is heavily
depending on the platform, i.e. the width of the integer values. To do
proper domain tests, we need the limits of the integers (largest and
smallest value), which we can get from <limits.h>. But we also need the
string representations of these numbers, to the various bases, which of
course vary depending on how the platform defines 'int' and 'long'.
*/
#define sym2v( x ) #x
#define sym2s( x ) sym2v( x )
#if __SIZEOF_INT__ == 2
#define UINT_DIG 5
#define INT_DIG 5
#define INT_DIG_LESS1 "4"
#define INT_DIG_PLUS1 "6"
#define INT_DIG_PLUS2 "7"
#define INT_HEXDIG "FFF"
#define INT_hexdig "fff"
#define INT_OCTDIG "177777"
#define INT_MAX_DEZ_STR "32767"
#define INT_MIN_DEZ_STR "32768"
#define UINT_MAX_DEZ_STR "65535"
#define INT_MAX_OCT_STR
#define INT_MIN_OCT_STR
#define UINT_MAX_OCT_STR
#define INT_MAX_HEX_STR
#define INT_MIN_HEX_STR
#define UINT_MAX_HEX_STR
#elif __SIZEOF_INT__ == 4
#define UINT_DIG 10
#define INT_DIG 10
#define INT_DIG_LESS1 "9"
#define INT_DIG_PLUS1 "11"
#define INT_DIG_PLUS2 "12"
#define INT_HEXDIG "FFFFFFF"
#define INT_hexdig "fffffff"
#define INT_OCTDIG "37777777777"
#define INT_MAX_DEZ_STR "2147483647"
#define INT_MIN_DEZ_STR "2147483648"
#define UINT_MAX_DEZ_STR "4294967295"
#define INT_MAX_OCT_STR
#define INT_MIN_OCT_STR
#define UINT_MAX_OCT_STR
#define INT_MAX_HEX_STR
#define INT_MIN_HEX_STR
#define UINT_MAX_HEX_STR
#elif __SIZEOF_INT__ == 8
#define UINT_DIG 20
#define INT_DIG 19
#define INT_DIG_LESS1 "18"
#define INT_DIG_PLUS1 "20"
#define INT_DIG_PLUS2 "21"
#define INT_HEXDIG "FFFFFFFFFFFFFFF"
#define INT_hexdig "fffffffffffffff"
#define INT_OCTDIG "1777777777777777777777"
#define INT_MAX_DEZ_STR "9223372036854775807"
#define INT_MIN_DEZ_STR "9223372036854775808"
#define UINT_MAX_DEZ_STR "18446744073709551615"
#define INT_MAX_OCT_STR
#define INT_MIN_OCT_STR
#define UINT_MAX_OCT_STR
#define INT_MAX_HEX_STR
#define INT_MIN_HEX_STR
#define UINT_MAX_HEX_STR
#else
#error Unsupported width of 'int' (neither 16, 32, nor 64 bit).
#endif
#if __SIZEOF_LONG__ == 4
#define ULONG_DIG 10
#define LONG_DIG 10
#define LONG_MAX_DEZ_STR "2147483647"
#define LONG_MIN_DEZ_STR "2147483648"
#define ULONG_MAX_DEZ_STR "4294967295"
#define LONG_MAX_OCT_STR
#define LONG_MIN_OCT_STR
#define ULONG_MAX_OCT_STR
#define LONG_MAX_HEX_STR
#define LONG_MIN_HEX_STR
#define ULONG_MAX_HEX_STR
#elif __SIZEOF_LONG__ == 8
#define ULONG_DIG 20
#define LONG_DIG 19
#define LONG_MAX_DEZ_STR "9223372036854775807"
#define LONG_MIN_DEZ_STR "9223372036854775808"
#define ULONG_MAX_DEZ_STR "18446744073709551615"
#define LONG_MAX_OCT_STR
#define LONG_MIN_OCT_STR
#define ULONG_MAX_OCT_STR
#define LONG_MAX_HEX_STR
#define LONG_MIN_HEX_STR
#define ULONG_MAX_HEX_STR
#else
#error Unsupported width of 'long' (neither 32 nor 64 bit).
#endif
#if __SIZEOF_LONG_LONG__ == 8
#define ULLONG_DIG 20
#define LLONG_DIG 19
#define LLONG_MAX_DEZ_STR "9223372036854775807"
#define LLONG_MIN_DEZ_STR "9223372036854775808"
#define ULLONG_MAX_DEZ_STR "18446744073709551615"
#define LLONG_MAX_OCT_STR
#define LLONG_MIN_OCT_STR
#define ULLONG_MAX_OCT_STR
#define LLONG_MAX_HEX_STR
#define LLONG_MIN_HEX_STR
#define ULLONG_MAX_HEX_STR
#elif __SIZEOF_LONG_LONG__ == 16
#define ULLONG_DIG 38
#define LLONG_DIG 38
#define LLONG_MAX_DEZ_STR "170141183460469231731687303715884105727"
#define LLONG_MIN_DEZ_STR "170141183460469231731687303715884105728"
#define ULLONG_MAX_DEZ_STR "340282366920938463463374607431768211455"
#define LLONG_MAX_OCT_STR
#define LLONG_MIN_OCT_STR
#define ULLONG_MAX_OCT_STR
#define LLONG_MAX_HEX_STR
#define LLONG_MIN_HEX_STR
#define ULLONG_MAX_HEX_STR
#else
#error Unsupported width of 'long long' (neither 64 nor 128 bit).
#endif

View File

@@ -1,101 +0,0 @@
/* PDCLib testing suite <_PDCLIB_test.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
/* -------------------------------------------------------------------------- */
/* Helper macros for test drivers */
/* -------------------------------------------------------------------------- */
#define fprintf j6libc_fprintf
#define stderr j6libc_stderr
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#undef stderr
#undef fprintf
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration"
struct _IO_FILE;
extern struct _IO_FILE *stderr;
extern int fprintf(struct _IO_FILE *, const char *, ...);
#pragma clang diagnostic pop
/* Host system sys/types.h */
#include <sys/types.h>
/* Some strings used for <string.h> and <stdlib.h> testing. */
static const char abcde[] = "abcde";
static const char abcdx[] = "abcdx";
static const char teststring[] = "1234567890\nABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n";
/* Temporary file names */
static const char testfile[]="testing/testfile";
static const char testfile1[]="testing/testfile1";
static const char testfile2[]="testing/testfile2";
/* Host system fork(), waitpid(), and _exit() */
pid_t fork(void);
pid_t waitpid(pid_t, int *, int);
void _exit(int);
#define START_SUITE(name) \
int run_suite_ ##name (void) { \
int TEST_RESULTS = 0;
#define END_SUITE \
return TEST_RESULTS; \
}
#define DECLARE_SUITE(name) extern int run_suite_ ##name (void)
#define RUN_TEST(name) TEST_RESULTS += test__ ##name();
#define START_TEST(name) \
int test__ ##name (void) { \
int TEST_RESULTS = 0;
#define END_TEST \
return TEST_RESULTS; \
}
/* TESTCASE() - generic test */
#define TESTCASE( x ) \
do { \
pid_t pid = fork(); \
if ( !pid ) _exit((x) ? 0 : 0xFF); \
else { \
int __rc = 0; \
waitpid(pid, &__rc, 0); \
if ( __rc & 0xff00 ) { \
TEST_RESULTS += 1; \
fprintf( stderr, "FAILED: " __FILE__ ":%s, line %d - %s\n", __func__, __LINE__, #x ); \
} \
} \
} while(0)
/* TESTCASE_REQUIRE() - must-pass test; return early otherwise */
#define TESTCASE_REQUIRE( x ) \
do { \
pid_t pid = fork(); \
if ( !pid ) _exit((x) ? 0 : 0xFF); \
else { \
int __rc = 0; \
waitpid(pid, &__rc, 0); \
if ( __rc & 0xff00 ) { \
TEST_RESULTS += 1; \
fprintf( stderr, "FAILED: " __FILE__ ":%s, line %d - %s\n", __func__, __LINE__, #x ); \
return TEST_RESULTS; \
} \
} \
} while(0)

View File

@@ -1,32 +0,0 @@
#include "_PDCLIB_test.h"
DECLARE_SUITE(internal);
DECLARE_SUITE(assert);
DECLARE_SUITE(ctype);
DECLARE_SUITE(inttypes);
DECLARE_SUITE(locale);
DECLARE_SUITE(stdarg);
DECLARE_SUITE(stdio);
DECLARE_SUITE(stdlib);
DECLARE_SUITE(string);
DECLARE_SUITE(time);
int main(int argc, const char **argv)
{
int result = 0;
result += run_suite_internal();
result += run_suite_assert();
result += run_suite_ctype();
result += run_suite_inttypes();
result += run_suite_locale();
result += run_suite_stdarg();
result += run_suite_stdio();
result += run_suite_stdlib();
result += run_suite_string();
result += run_suite_time();
return result;
}

View File

@@ -1,444 +0,0 @@
#define PRINTF_TEST( expected_rc, expected_string, ... ) do { \
TEST_RESULTS += DO_TESTPRINTF(IMPLFILE, __FILE__, __LINE__, expected_rc, expected_string, __VA_ARGS__); \
} while (0);
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat"
#if CHAR_MIN == -128
assert(CHAR_MIN == -128);
PRINTF_TEST( 4, "-128", "%hhd", CHAR_MIN );
assert(CHAR_MAX == 127);
PRINTF_TEST( 3, "127", "%hhd", CHAR_MAX );
#else
assert(CHAR_MIN == 0);
PRINTF_TEST( 1, "0", "%hhu", CHAR_MIN );
assert(CHAR_MAX == 255);
PRINTF_TEST( 3, "255", "%hhu", CHAR_MAX );
#endif
PRINTF_TEST( 1, "0", "%hhd", 0 );
assert(SHRT_MIN == -32768);
PRINTF_TEST( 6, "-32768", "%hd", SHRT_MIN );
assert(SHRT_MAX == 32767);
PRINTF_TEST( 5, "32767", "%hd", SHRT_MAX );
PRINTF_TEST( 1, "0", "%hd", 0 );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%d", INT_MAX );
PRINTF_TEST( 1, "0", "%d", 0 );
PRINTF_TEST( LONG_DIG + 1, "-" LONG_MIN_DEZ_STR, "%ld", LONG_MIN );
PRINTF_TEST( LONG_DIG, LONG_MAX_DEZ_STR, "%ld", LONG_MAX );
PRINTF_TEST( 1, "0", "%ld", 0l );
PRINTF_TEST( LLONG_DIG + 1, "-" LLONG_MIN_DEZ_STR, "%lld", LLONG_MIN );
PRINTF_TEST( LLONG_DIG, LLONG_MAX_DEZ_STR, "%lld", LLONG_MAX );
PRINTF_TEST( 1, "0", "%lld", 0ll );
PRINTF_TEST( 3, "255", "%hhu", UCHAR_MAX );
PRINTF_TEST( 3, "255", "%hhu", (unsigned char)-1 );
PRINTF_TEST( 5, "65535", "%hu", USHRT_MAX );
PRINTF_TEST( 5, "65535", "%hu", (unsigned short)-1 );
PRINTF_TEST( UINT_DIG, UINT_MAX_DEZ_STR, "%u", UINT_MAX );
PRINTF_TEST( UINT_DIG, UINT_MAX_DEZ_STR, "%u", -1u );
PRINTF_TEST( ULONG_DIG, ULONG_MAX_DEZ_STR, "%lu", ULONG_MAX );
PRINTF_TEST( ULONG_DIG, ULONG_MAX_DEZ_STR, "%lu", -1ul );
PRINTF_TEST( ULLONG_DIG, ULLONG_MAX_DEZ_STR, "%llu", ULLONG_MAX );
PRINTF_TEST( ULLONG_DIG, ULLONG_MAX_DEZ_STR, "%llu", -1ull );
PRINTF_TEST( (int)strlen( INT_HEXDIG ) + 1, "F" INT_HEXDIG, "%X", UINT_MAX );
PRINTF_TEST( (int)strlen( INT_HEXDIG ) + 3, "0XF" INT_HEXDIG, "%#X", -1u );
PRINTF_TEST( (int)strlen( INT_HEXDIG ) + 1, "f" INT_hexdig, "%x", UINT_MAX );
PRINTF_TEST( (int)strlen( INT_HEXDIG ) + 3, "0xf" INT_hexdig, "%#x", -1u );
PRINTF_TEST( (int)strlen( INT_OCTDIG ), INT_OCTDIG, "%o", UINT_MAX );
PRINTF_TEST( (int)strlen( INT_OCTDIG ) + 1, "0" INT_OCTDIG, "%#o", -1u );
#if 0
/* TODO: This test case is broken, doesn't test what it was intended to. */
PRINTF_TEST( 5, "%.0#o", "%.0#o", 0 );
#endif
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%+d", INT_MIN );
PRINTF_TEST( INT_DIG + 1, "+" INT_MAX_DEZ_STR, "%+d", INT_MAX );
PRINTF_TEST( 2, "+0", "%+d", 0 );
PRINTF_TEST( UINT_DIG, UINT_MAX_DEZ_STR, "%+u", UINT_MAX );
PRINTF_TEST( UINT_DIG, UINT_MAX_DEZ_STR, "%+u", -1u );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "% d", INT_MIN );
PRINTF_TEST( INT_DIG + 1, " " INT_MAX_DEZ_STR, "% d", INT_MAX );
PRINTF_TEST( 2, " 0", "% d", 0 );
PRINTF_TEST( UINT_DIG, UINT_MAX_DEZ_STR, "% u", UINT_MAX );
PRINTF_TEST( UINT_DIG, UINT_MAX_DEZ_STR, "% u", -1u );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%" INT_DIG_LESS1 "d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%" INT_DIG_LESS1 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%" sym2s(INT_DIG) "d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%" sym2s(INT_DIG) "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%" INT_DIG_PLUS1 "d", INT_MIN );
PRINTF_TEST( INT_DIG + 1, " " INT_MAX_DEZ_STR, "%" INT_DIG_PLUS1 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 2, " -" INT_MIN_DEZ_STR, "%" INT_DIG_PLUS2 "d", INT_MIN );
PRINTF_TEST( INT_DIG + 2, " " INT_MAX_DEZ_STR, "%" INT_DIG_PLUS2 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%-" INT_DIG_LESS1 "d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%-" INT_DIG_LESS1 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%-" sym2s(INT_DIG) "d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%-" sym2s(INT_DIG) "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%-" INT_DIG_PLUS1 "d", INT_MIN );
PRINTF_TEST( INT_DIG + 1, INT_MAX_DEZ_STR " ", "%-" INT_DIG_PLUS1 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 2, "-" INT_MIN_DEZ_STR " ", "%-" INT_DIG_PLUS2 "d", INT_MIN );
PRINTF_TEST( INT_DIG + 2, INT_MAX_DEZ_STR " ", "%-" INT_DIG_PLUS2 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%0" INT_DIG_LESS1 "d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%0" INT_DIG_LESS1 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%0" sym2s(INT_DIG) "d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%0" sym2s(INT_DIG) "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%0" INT_DIG_PLUS1 "d", INT_MIN );
PRINTF_TEST( INT_DIG + 1, "0" INT_MAX_DEZ_STR, "%0" INT_DIG_PLUS1 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 2, "-0" INT_MIN_DEZ_STR, "%0" INT_DIG_PLUS2 "d", INT_MIN );
PRINTF_TEST( INT_DIG + 2, "00" INT_MAX_DEZ_STR, "%0" INT_DIG_PLUS2 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%-0" INT_DIG_LESS1 "d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%-0" INT_DIG_LESS1 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%-0" sym2s(INT_DIG) "d", INT_MIN );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%-0" sym2s(INT_DIG) "d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%-0" INT_DIG_PLUS1 "d", INT_MIN );
PRINTF_TEST( INT_DIG + 1, INT_MAX_DEZ_STR " ", "%-0" INT_DIG_PLUS1 "d", INT_MAX );
PRINTF_TEST( INT_DIG + 2, "-" INT_MIN_DEZ_STR " ", "%-0" INT_DIG_PLUS2 "d", INT_MIN );
PRINTF_TEST( INT_DIG + 2, INT_MAX_DEZ_STR " ", "%-0" INT_DIG_PLUS2 "d", INT_MAX );
/* FIXME: This test not yet 32/64 bit agnostic */
PRINTF_TEST( 30, " 00000000002147483647", "%030.20d", INT_MAX );
PRINTF_TEST( (int)strlen( INT_HEXDIG ) + 1, "f" INT_hexdig, "%.6x", UINT_MAX );
PRINTF_TEST( (int)strlen( INT_HEXDIG ) + 3, "0xf" INT_hexdig, "%#6.3x", UINT_MAX );
PRINTF_TEST( (int)strlen( INT_HEXDIG ) + 3, "0xf" INT_hexdig, "%#3.6x", UINT_MAX );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%.6d", INT_MIN );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%6.3d", INT_MIN );
PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%3.6d", INT_MIN );
PRINTF_TEST( UINT_DIG, "0xf" INT_hexdig, "%#0.6x", UINT_MAX );
PRINTF_TEST( UINT_DIG, "0xf" INT_hexdig, "%#06.3x", UINT_MAX );
PRINTF_TEST( UINT_DIG, "0xf" INT_hexdig, "%#03.6x", UINT_MAX );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%#0.6d", INT_MAX );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%#06.3d", INT_MAX );
PRINTF_TEST( INT_DIG, INT_MAX_DEZ_STR, "%#03.6d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "+" INT_MAX_DEZ_STR, "%#+.6d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "+" INT_MAX_DEZ_STR, "%#+6.3d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "+" INT_MAX_DEZ_STR, "%#+3.6d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "+" INT_MAX_DEZ_STR, "%+0.6d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "+" INT_MAX_DEZ_STR, "%+06.3d", INT_MAX );
PRINTF_TEST( INT_DIG + 1, "+" INT_MAX_DEZ_STR, "%+03.6d", INT_MAX );
#ifndef TEST_CONVERSION_ONLY
PRINTF_TEST( INT_DIG + 2, "- " INT_MAX_DEZ_STR, "- %d", INT_MAX );
PRINTF_TEST( INT_DIG * 2 + 6, "- " INT_MAX_DEZ_STR " % -" INT_MIN_DEZ_STR, "- %d %% %d", INT_MAX, INT_MIN );
#endif
PRINTF_TEST( 1, "x", "%c", 'x' );
PRINTF_TEST( 6, "abcdef", "%s", "abcdef" );
/* FIXME: This test not yet 32/64 bit agnostic */
PRINTF_TEST( 10, "0xdeadbeef", "%p", (void *)0xdeadbeef );
PRINTF_TEST( 6, " 0x1", "%#6x", 1 );
#ifndef TEST_CONVERSION_ONLY
{
int val1, val2;
PRINTF_TEST( 9, "123456789", "123456%n789%n", &val1, &val2 );
TESTCASE( val1 == 6 );
TESTCASE( val2 == 9 );
}
#endif
}
/* PDCLIB-20: Verify "unusual" combinations of length and signedness */
PRINTF_TEST( 1, "1", "%tu", (ptrdiff_t) 1); /* unsigned prtdiff_t */
PRINTF_TEST( 2, "-1", "%jd", (intmax_t) -1); /* intmax_t */
PRINTF_TEST( 1, "1", "%ju", (uintmax_t) 1); /* uintmax_t */
PRINTF_TEST( 1, "1", "%zd", (size_t) 1); /* signed size_t */
/******************************************************************************
* NOTE: The following test cases are imported from the Tyndur project. They *
* are therefore under the license of said project, not CC0. *
* As said code comprises test cases, it does not form part of the *
* final compiled library, and has no bearing on its licensing. *
* *
* See bug PDCLIB-6 for full details *
******************************************************************************/
/*
* Copyright (c) 2011 The tyndur Project. All rights reserved.
*
* This code is derived from software contributed to the tyndur Project
* by Kevin Wolf.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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.
*/
{
#ifndef TEST_CONVERSION_ONLY
/* Ein String ohne alles */
PRINTF_TEST(12, "Hallo heimur", "Hallo heimur");
#endif
/* Einfache Konvertierungen */
PRINTF_TEST(12, "Hallo heimur", "%s", "Hallo heimur");
PRINTF_TEST(4, "1024", "%d", 1024);
PRINTF_TEST(5, "-1024", "%d", -1024);
PRINTF_TEST(4, "1024", "%i", 1024);
PRINTF_TEST(5, "-1024", "%i", -1024);
PRINTF_TEST(4, "1024", "%u", 1024u);
PRINTF_TEST(10, "4294966272", "%u", -1024u);
PRINTF_TEST(3, "777", "%o", 0777u);
PRINTF_TEST(11, "37777777001", "%o", -0777u);
PRINTF_TEST(8, "1234abcd", "%x", 0x1234abcdu);
PRINTF_TEST(8, "edcb5433", "%x", -0x1234abcdu);
PRINTF_TEST(8, "1234ABCD", "%X", 0x1234abcdu);
PRINTF_TEST(8, "EDCB5433", "%X", -0x1234abcdu);
PRINTF_TEST(1, "x", "%c", 'x');
PRINTF_TEST(1, "%", "%%");
/* Mit %c kann man auch Nullbytes ausgeben */
PRINTF_TEST(1, "\0", "%c", '\0');
/* Vorzeichen erzwingen (Flag +) */
PRINTF_TEST(12, "Hallo heimur", "%+s", "Hallo heimur");
PRINTF_TEST(5, "+1024", "%+d", 1024);
PRINTF_TEST(5, "-1024", "%+d", -1024);
PRINTF_TEST(5, "+1024", "%+i", 1024);
PRINTF_TEST(5, "-1024", "%+i", -1024);
PRINTF_TEST(4, "1024", "%+u", 1024u);
PRINTF_TEST(10, "4294966272", "%+u", -1024u);
PRINTF_TEST(3, "777", "%+o", 0777u);
PRINTF_TEST(11, "37777777001", "%+o", -0777u);
PRINTF_TEST(8, "1234abcd", "%+x", 0x1234abcdu);
PRINTF_TEST(8, "edcb5433", "%+x", -0x1234abcdu);
PRINTF_TEST(8, "1234ABCD", "%+X", 0x1234abcdu);
PRINTF_TEST(8, "EDCB5433", "%+X", -0x1234abcdu);
PRINTF_TEST(1, "x", "%+c", 'x');
/* Vorzeichenplatzhalter erzwingen (Flag <space>) */
PRINTF_TEST(12, "Hallo heimur", "% s", "Hallo heimur");
PRINTF_TEST(5, " 1024", "% d", 1024);
PRINTF_TEST(5, "-1024", "% d", -1024);
PRINTF_TEST(5, " 1024", "% i", 1024);
PRINTF_TEST(5, "-1024", "% i", -1024);
PRINTF_TEST(4, "1024", "% u", 1024u);
PRINTF_TEST(10, "4294966272", "% u", -1024u);
PRINTF_TEST(3, "777", "% o", 0777u);
PRINTF_TEST(11, "37777777001", "% o", -0777u);
PRINTF_TEST(8, "1234abcd", "% x", 0x1234abcdu);
PRINTF_TEST(8, "edcb5433", "% x", -0x1234abcdu);
PRINTF_TEST(8, "1234ABCD", "% X", 0x1234abcdu);
PRINTF_TEST(8, "EDCB5433", "% X", -0x1234abcdu);
PRINTF_TEST(1, "x", "% c", 'x');
/* Flag + hat Vorrang über <space> */
PRINTF_TEST(12, "Hallo heimur", "%+ s", "Hallo heimur");
PRINTF_TEST(5, "+1024", "%+ d", 1024);
PRINTF_TEST(5, "-1024", "%+ d", -1024);
PRINTF_TEST(5, "+1024", "%+ i", 1024);
PRINTF_TEST(5, "-1024", "%+ i", -1024);
PRINTF_TEST(4, "1024", "%+ u", 1024u);
PRINTF_TEST(10, "4294966272", "%+ u", -1024u);
PRINTF_TEST(3, "777", "%+ o", 0777u);
PRINTF_TEST(11, "37777777001", "%+ o", -0777u);
PRINTF_TEST(8, "1234abcd", "%+ x", 0x1234abcdu);
PRINTF_TEST(8, "edcb5433", "%+ x", -0x1234abcdu);
PRINTF_TEST(8, "1234ABCD", "%+ X", 0x1234abcdu);
PRINTF_TEST(8, "EDCB5433", "%+ X", -0x1234abcdu);
PRINTF_TEST(1, "x", "%+ c", 'x');
/* Alternative Form */
PRINTF_TEST(4, "0777", "%#o", 0777u);
PRINTF_TEST(12, "037777777001", "%#o", -0777u);
PRINTF_TEST(10, "0x1234abcd", "%#x", 0x1234abcdu);
PRINTF_TEST(10, "0xedcb5433", "%#x", -0x1234abcdu);
PRINTF_TEST(10, "0X1234ABCD", "%#X", 0x1234abcdu);
PRINTF_TEST(10, "0XEDCB5433", "%#X", -0x1234abcdu);
PRINTF_TEST(1, "0", "%#o", 0u);
PRINTF_TEST(1, "0", "%#x", 0u);
PRINTF_TEST(1, "0", "%#X", 0u);
/* Feldbreite: Kleiner als Ausgabe */
PRINTF_TEST(12, "Hallo heimur", "%1s", "Hallo heimur");
PRINTF_TEST(4, "1024", "%1d", 1024);
PRINTF_TEST(5, "-1024", "%1d", -1024);
PRINTF_TEST(4, "1024", "%1i", 1024);
PRINTF_TEST(5, "-1024", "%1i", -1024);
PRINTF_TEST(4, "1024", "%1u", 1024u);
PRINTF_TEST(10, "4294966272", "%1u", -1024u);
PRINTF_TEST(3, "777", "%1o", 0777u);
PRINTF_TEST(11, "37777777001", "%1o", -0777u);
PRINTF_TEST(8, "1234abcd", "%1x", 0x1234abcdu);
PRINTF_TEST(8, "edcb5433", "%1x", -0x1234abcdu);
PRINTF_TEST(8, "1234ABCD", "%1X", 0x1234abcdu);
PRINTF_TEST(8, "EDCB5433", "%1X", -0x1234abcdu);
PRINTF_TEST(1, "x", "%1c", 'x');
/* Feldbreite: Größer als Ausgabe */
PRINTF_TEST(20, " Hallo", "%20s", "Hallo");
PRINTF_TEST(20, " 1024", "%20d", 1024);
PRINTF_TEST(20, " -1024", "%20d", -1024);
PRINTF_TEST(20, " 1024", "%20i", 1024);
PRINTF_TEST(20, " -1024", "%20i", -1024);
PRINTF_TEST(20, " 1024", "%20u", 1024u);
PRINTF_TEST(20, " 4294966272", "%20u", -1024u);
PRINTF_TEST(20, " 777", "%20o", 0777u);
PRINTF_TEST(20, " 37777777001", "%20o", -0777u);
PRINTF_TEST(20, " 1234abcd", "%20x", 0x1234abcdu);
PRINTF_TEST(20, " edcb5433", "%20x", -0x1234abcdu);
PRINTF_TEST(20, " 1234ABCD", "%20X", 0x1234abcdu);
PRINTF_TEST(20, " EDCB5433", "%20X", -0x1234abcdu);
PRINTF_TEST(20, " x", "%20c", 'x');
/* Feldbreite: Linksbündig */
PRINTF_TEST(20, "Hallo ", "%-20s", "Hallo");
PRINTF_TEST(20, "1024 ", "%-20d", 1024);
PRINTF_TEST(20, "-1024 ", "%-20d", -1024);
PRINTF_TEST(20, "1024 ", "%-20i", 1024);
PRINTF_TEST(20, "-1024 ", "%-20i", -1024);
PRINTF_TEST(20, "1024 ", "%-20u", 1024u);
PRINTF_TEST(20, "4294966272 ", "%-20u", -1024u);
PRINTF_TEST(20, "777 ", "%-20o", 0777u);
PRINTF_TEST(20, "37777777001 ", "%-20o", -0777u);
PRINTF_TEST(20, "1234abcd ", "%-20x", 0x1234abcdu);
PRINTF_TEST(20, "edcb5433 ", "%-20x", -0x1234abcdu);
PRINTF_TEST(20, "1234ABCD ", "%-20X", 0x1234abcdu);
PRINTF_TEST(20, "EDCB5433 ", "%-20X", -0x1234abcdu);
PRINTF_TEST(20, "x ", "%-20c", 'x');
/* Feldbreite: Padding mit 0 */
PRINTF_TEST(20, "00000000000000001024", "%020d", 1024);
PRINTF_TEST(20, "-0000000000000001024", "%020d", -1024);
PRINTF_TEST(20, "00000000000000001024", "%020i", 1024);
PRINTF_TEST(20, "-0000000000000001024", "%020i", -1024);
PRINTF_TEST(20, "00000000000000001024", "%020u", 1024u);
PRINTF_TEST(20, "00000000004294966272", "%020u", -1024u);
PRINTF_TEST(20, "00000000000000000777", "%020o", 0777u);
PRINTF_TEST(20, "00000000037777777001", "%020o", -0777u);
PRINTF_TEST(20, "0000000000001234abcd", "%020x", 0x1234abcdu);
PRINTF_TEST(20, "000000000000edcb5433", "%020x", -0x1234abcdu);
PRINTF_TEST(20, "0000000000001234ABCD", "%020X", 0x1234abcdu);
PRINTF_TEST(20, "000000000000EDCB5433", "%020X", -0x1234abcdu);
/* Feldbreite: Padding und alternative Form */
PRINTF_TEST(20, " 0777", "%#20o", 0777u);
PRINTF_TEST(20, " 037777777001", "%#20o", -0777u);
PRINTF_TEST(20, " 0x1234abcd", "%#20x", 0x1234abcdu);
PRINTF_TEST(20, " 0xedcb5433", "%#20x", -0x1234abcdu);
PRINTF_TEST(20, " 0X1234ABCD", "%#20X", 0x1234abcdu);
PRINTF_TEST(20, " 0XEDCB5433", "%#20X", -0x1234abcdu);
PRINTF_TEST(20, "00000000000000000777", "%#020o", 0777u);
PRINTF_TEST(20, "00000000037777777001", "%#020o", -0777u);
PRINTF_TEST(20, "0x00000000001234abcd", "%#020x", 0x1234abcdu);
PRINTF_TEST(20, "0x0000000000edcb5433", "%#020x", -0x1234abcdu);
PRINTF_TEST(20, "0X00000000001234ABCD", "%#020X", 0x1234abcdu);
PRINTF_TEST(20, "0X0000000000EDCB5433", "%#020X", -0x1234abcdu);
/* Feldbreite: - hat Vorrang vor 0 */
PRINTF_TEST(20, "Hallo ", "%0-20s", "Hallo");
PRINTF_TEST(20, "1024 ", "%0-20d", 1024);
PRINTF_TEST(20, "-1024 ", "%0-20d", -1024);
PRINTF_TEST(20, "1024 ", "%0-20i", 1024);
PRINTF_TEST(20, "-1024 ", "%0-20i", -1024);
PRINTF_TEST(20, "1024 ", "%0-20u", 1024u);
PRINTF_TEST(20, "4294966272 ", "%0-20u", -1024u);
PRINTF_TEST(20, "777 ", "%-020o", 0777u);
PRINTF_TEST(20, "37777777001 ", "%-020o", -0777u);
PRINTF_TEST(20, "1234abcd ", "%-020x", 0x1234abcdu);
PRINTF_TEST(20, "edcb5433 ", "%-020x", -0x1234abcdu);
PRINTF_TEST(20, "1234ABCD ", "%-020X", 0x1234abcdu);
PRINTF_TEST(20, "EDCB5433 ", "%-020X", -0x1234abcdu);
PRINTF_TEST(20, "x ", "%-020c", 'x');
/* Feldbreite: Aus Parameter */
PRINTF_TEST(20, " Hallo", "%*s", 20, "Hallo");
PRINTF_TEST(20, " 1024", "%*d", 20, 1024);
PRINTF_TEST(20, " -1024", "%*d", 20, -1024);
PRINTF_TEST(20, " 1024", "%*i", 20, 1024);
PRINTF_TEST(20, " -1024", "%*i", 20, -1024);
PRINTF_TEST(20, " 1024", "%*u", 20, 1024u);
PRINTF_TEST(20, " 4294966272", "%*u", 20, -1024u);
PRINTF_TEST(20, " 777", "%*o", 20, 0777u);
PRINTF_TEST(20, " 37777777001", "%*o", 20, -0777u);
PRINTF_TEST(20, " 1234abcd", "%*x", 20, 0x1234abcdu);
PRINTF_TEST(20, " edcb5433", "%*x", 20, -0x1234abcdu);
PRINTF_TEST(20, " 1234ABCD", "%*X", 20, 0x1234abcdu);
PRINTF_TEST(20, " EDCB5433", "%*X", 20, -0x1234abcdu);
PRINTF_TEST(20, " x", "%*c", 20, 'x');
/* Präzision / Mindestanzahl von Ziffern */
PRINTF_TEST(12, "Hallo heimur", "%.20s", "Hallo heimur");
PRINTF_TEST(20, "00000000000000001024", "%.20d", 1024);
PRINTF_TEST(21, "-00000000000000001024", "%.20d", -1024);
PRINTF_TEST(20, "00000000000000001024", "%.20i", 1024);
PRINTF_TEST(21, "-00000000000000001024", "%.20i", -1024);
PRINTF_TEST(20, "00000000000000001024", "%.20u", 1024u);
PRINTF_TEST(20, "00000000004294966272", "%.20u", -1024u);
PRINTF_TEST(20, "00000000000000000777", "%.20o", 0777u);
PRINTF_TEST(20, "00000000037777777001", "%.20o", -0777u);
PRINTF_TEST(20, "0000000000001234abcd", "%.20x", 0x1234abcdu);
PRINTF_TEST(20, "000000000000edcb5433", "%.20x", -0x1234abcdu);
PRINTF_TEST(20, "0000000000001234ABCD", "%.20X", 0x1234abcdu);
PRINTF_TEST(20, "000000000000EDCB5433", "%.20X", -0x1234abcdu);
/* Feldbreite und Präzision */
PRINTF_TEST(20, " Hallo", "%20.5s", "Hallo heimur");
PRINTF_TEST(20, " 01024", "%20.5d", 1024);
PRINTF_TEST(20, " -01024", "%20.5d", -1024);
PRINTF_TEST(20, " 01024", "%20.5i", 1024);
PRINTF_TEST(20, " -01024", "%20.5i", -1024);
PRINTF_TEST(20, " 01024", "%20.5u", 1024u);
PRINTF_TEST(20, " 4294966272", "%20.5u", -1024u);
PRINTF_TEST(20, " 00777", "%20.5o", 0777u);
PRINTF_TEST(20, " 37777777001", "%20.5o", -0777u);
PRINTF_TEST(20, " 1234abcd", "%20.5x", 0x1234abcdu);
PRINTF_TEST(20, " 00edcb5433", "%20.10x", -0x1234abcdu);
PRINTF_TEST(20, " 1234ABCD", "%20.5X", 0x1234abcdu);
PRINTF_TEST(20, " 00EDCB5433", "%20.10X", -0x1234abcdu);
/* Präzision: 0 wird ignoriert */
PRINTF_TEST(20, " Hallo", "%020.5s", "Hallo heimur");
PRINTF_TEST(20, " 01024", "%020.5d", 1024);
PRINTF_TEST(20, " -01024", "%020.5d", -1024);
PRINTF_TEST(20, " 01024", "%020.5i", 1024);
PRINTF_TEST(20, " -01024", "%020.5i", -1024);
PRINTF_TEST(20, " 01024", "%020.5u", 1024u);
PRINTF_TEST(20, " 4294966272", "%020.5u", -1024u);
PRINTF_TEST(20, " 00777", "%020.5o", 0777u);
PRINTF_TEST(20, " 37777777001", "%020.5o", -0777u);
PRINTF_TEST(20, " 1234abcd", "%020.5x", 0x1234abcdu);
PRINTF_TEST(20, " 00edcb5433", "%020.10x", -0x1234abcdu);
PRINTF_TEST(20, " 1234ABCD", "%020.5X", 0x1234abcdu);
PRINTF_TEST(20, " 00EDCB5433", "%020.10X", -0x1234abcdu);
/* Präzision 0 */
PRINTF_TEST(0, "", "%.0s", "Hallo heimur");
PRINTF_TEST(20, " ", "%20.0s", "Hallo heimur");
PRINTF_TEST(0, "", "%.s", "Hallo heimur");
PRINTF_TEST(20, " ", "%20.s", "Hallo heimur");
PRINTF_TEST(20, " 1024", "%20.0d", 1024);
PRINTF_TEST(20, " -1024", "%20.d", -1024);
PRINTF_TEST(20, " ", "%20.d", 0);
PRINTF_TEST(20, " 1024", "%20.0i", 1024);
PRINTF_TEST(20, " -1024", "%20.i", -1024);
PRINTF_TEST(20, " ", "%20.i", 0);
PRINTF_TEST(20, " 1024", "%20.u", 1024u);
PRINTF_TEST(20, " 4294966272", "%20.0u", -1024u);
PRINTF_TEST(20, " ", "%20.u", 0u);
PRINTF_TEST(20, " 777", "%20.o", 0777u);
PRINTF_TEST(20, " 37777777001", "%20.0o", -0777u);
PRINTF_TEST(20, " ", "%20.o", 0u);
PRINTF_TEST(20, " 1234abcd", "%20.x", 0x1234abcdu);
PRINTF_TEST(20, " edcb5433", "%20.0x", -0x1234abcdu);
PRINTF_TEST(20, " ", "%20.x", 0u);
PRINTF_TEST(20, " 1234ABCD", "%20.X", 0x1234abcdu);
PRINTF_TEST(20, " EDCB5433", "%20.0X", -0x1234abcdu);
PRINTF_TEST(20, " ", "%20.X", 0u);
/* Negative Präzision wird ignoriert */
/* XXX glibc tut nicht, was ich erwartet habe, vorerst deaktiviert... */
/*
* Präzision und Feldbreite aus Parameter.
* + hat Vorrang vor <space>, - hat Vorrang vor 0 (das eh ignoriert wird,
* weil eine Präzision angegeben ist)
*/
PRINTF_TEST(20, "Hallo ", "% -0+*.*s", 20, 5, "Hallo heimur");
PRINTF_TEST(20, "+01024 ", "% -0+*.*d", 20, 5, 1024);
PRINTF_TEST(20, "-01024 ", "% -0+*.*d", 20, 5, -1024);
PRINTF_TEST(20, "+01024 ", "% -0+*.*i", 20, 5, 1024);
PRINTF_TEST(20, "-01024 ", "% 0-+*.*i", 20, 5, -1024);
PRINTF_TEST(20, "01024 ", "% 0-+*.*u", 20, 5, 1024u);
PRINTF_TEST(20, "4294966272 ", "% 0-+*.*u", 20, 5, -1024u);
PRINTF_TEST(20, "00777 ", "%+ -0*.*o", 20, 5, 0777u);
PRINTF_TEST(20, "37777777001 ", "%+ -0*.*o", 20, 5, -0777u);
PRINTF_TEST(20, "1234abcd ", "%+ -0*.*x", 20, 5, 0x1234abcdu);
PRINTF_TEST(20, "00edcb5433 ", "%+ -0*.*x", 20, 10, -0x1234abcdu);
PRINTF_TEST(20, "1234ABCD ", "% -+0*.*X", 20, 5, 0x1234abcdu);
PRINTF_TEST(20, "00EDCB5433 ", "% -+0*.*X", 20, 10, -0x1234abcdu);
#pragma clang diagnostic pop
}
#undef PRINTF_TEST
/******************************************************************************/

View File

@@ -1,96 +0,0 @@
#define SCANF_TEST( expected_rc, input_string, ... ) do { \
TEST_RESULTS += DO_TESTSCANF(IMPLFILE, __FILE__, __LINE__, expected_rc, input_string, __VA_ARGS__); \
} while (0);
{
char buffer[100];
int i;
unsigned int u;
int * p;
/* basic: reading of three-char string */
SCANF_TEST( 1, "foo", "%3c", buffer );
TESTCASE( memcmp( buffer, "foo", 3 ) == 0 );
#ifndef TEST_CONVERSION_ONLY
/* %% for single % */
SCANF_TEST( 1, "%x", "%%%c", buffer );
TESTCASE( buffer[0] == 'x' );
/* * to skip assignment */
SCANF_TEST( 1, "3xfoo", "%*dx%3c", buffer );
TESTCASE( memcmp( buffer, "foo", 3 ) == 0 );
#endif
/* domain testing on 'int' type */
SCANF_TEST( 1, "-" INT_MIN_DEZ_STR, "%d", &i );
TESTCASE( i == INT_MIN );
SCANF_TEST( 1, INT_MAX_DEZ_STR, "%d", &i );
TESTCASE( i == INT_MAX );
SCANF_TEST( 1, "-1", "%d", &i );
TESTCASE( i == -1 );
SCANF_TEST( 1, "0", "%d", &i );
TESTCASE( i == 0 );
SCANF_TEST( 1, "1", "%d", &i );
TESTCASE( i == 1 );
SCANF_TEST( 1, "-" INT_MIN_DEZ_STR, "%i", &i );
TESTCASE( i == INT_MIN );
SCANF_TEST( 1, INT_MAX_DEZ_STR, "%i", &i );
TESTCASE( i == INT_MAX );
SCANF_TEST( 1, "-1", "%i", &i );
TESTCASE( i == -1 );
SCANF_TEST( 1, "0", "%i", &i );
TESTCASE( i == 0 );
SCANF_TEST( 1, "1", "%i", &i );
TESTCASE( i == 1 );
SCANF_TEST( 1, "0x7" INT_HEXDIG, "%i", &i );
TESTCASE( i == INT_MAX );
SCANF_TEST( 1, "0x0", "%i", &i );
TESTCASE( i == 0 );
#ifndef TEST_CONVERSION_ONLY
SCANF_TEST( 1, "00", "%i%n", &i, &u );
TESTCASE( i == 0 );
TESTCASE( u == 2 );
#endif
/* domain testing on 'unsigned int' type */
SCANF_TEST( 1, UINT_MAX_DEZ_STR, "%u", &u );
TESTCASE( u == UINT_MAX );
SCANF_TEST( 1, "0", "%u", &u );
TESTCASE( u == 0 );
SCANF_TEST( 1, "f" INT_HEXDIG, "%x", &u );
TESTCASE( u == UINT_MAX );
SCANF_TEST( 1, "7" INT_HEXDIG, "%x", &u );
TESTCASE( u == INT_MAX );
SCANF_TEST( 1, "0", "%o", &u );
TESTCASE( u == 0 );
SCANF_TEST( 1, INT_OCTDIG, "%o", &u );
TESTCASE( u == UINT_MAX );
/* testing %c */
memset( buffer, '\0', 100 );
SCANF_TEST( 1, "x", "%c", buffer );
TESTCASE( memcmp( buffer, "x\0", 2 ) == 0 );
/* testing %s */
memset( buffer, '\0', 100 );
SCANF_TEST( 1, "foo bar", "%s", buffer );
TESTCASE( memcmp( buffer, "foo\0", 4 ) == 0 );
#ifndef TEST_CONVERSION_ONLY
SCANF_TEST( 2, "foo bar baz", "%s %s %n", buffer, buffer + 4, &u );
TESTCASE( u == 9 );
TESTCASE( memcmp( buffer, "foo\0bar\0", 8 ) == 0 );
#endif
/* testing %[ */
SCANF_TEST( 1, "abcdefg", "%[cba]", buffer );
TESTCASE( memcmp( buffer, "abc\0", 4 ) == 0 );
/* testing %p */
p = NULL;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-pedantic"
sprintf( buffer, "%p", p );
p = &i;
SCANF_TEST( 1, buffer, "%p", &p );
TESTCASE( p == NULL );
p = &i;
sprintf( buffer, "%p", p );
p = NULL;
SCANF_TEST( 1, buffer, "%p", &p );
TESTCASE( p == &i );
#pragma clang diagnostic pop
}
#undef SCANF_TEST

View File

@@ -1,50 +0,0 @@
#include "_PDCLIB_test.h"
#define NDEBUG
#include <assert.h>
#define enabled_assert( expression ) ( ( expression ) ? (void) 0 \
: _PDCLIB_assert( "Assertion failed: " #expression \
", function ", __func__, \
", file " __FILE__ \
", line " _PDCLIB_symbol2string( __LINE__ ) \
"." _PDCLIB_endl ) )
static int EXPECTED = 0;
static void aborthandler( int sig )
{
_exit(!EXPECTED);
}
static int assert_disabled_test( void )
{
int i = 0;
assert( i == 0 ); /* NDEBUG set, condition met */
assert( i == 1 ); /* NDEBUG set, condition fails */
return i;
}
int assert_enabled_test(int val)
{
enabled_assert(val);
return val;
}
START_TEST( assert )
{
sighandler_t sh = signal(SIGABRT, &aborthandler);
TESTCASE( sh != SIG_ERR );
TESTCASE( assert_disabled_test() == 0 );
TESTCASE( assert_enabled_test(1) ); /* NDEBUG not set, condition met */
EXPECTED = 1;
TESTCASE( assert_enabled_test(0) ); /* NDEBUG not set, condition fails - should abort */
}
END_TEST
START_SUITE( assert )
{
RUN_TEST( assert );
}
END_SUITE

View File

@@ -1,186 +0,0 @@
#include "_PDCLIB_test.h"
START_TEST( isalnum )
{
TESTCASE( isalnum( 'a' ) );
TESTCASE( isalnum( 'z' ) );
TESTCASE( isalnum( 'A' ) );
TESTCASE( isalnum( 'Z' ) );
TESTCASE( isalnum( '0' ) );
TESTCASE( isalnum( '9' ) );
TESTCASE( ! isalnum( ' ' ) );
TESTCASE( ! isalnum( '\n' ) );
TESTCASE( ! isalnum( '@' ) );
}
END_TEST
START_TEST( isalpha )
{
TESTCASE( isalpha( 'a' ) );
TESTCASE( isalpha( 'z' ) );
TESTCASE( ! isalpha( ' ' ) );
TESTCASE( ! isalpha( '1' ) );
TESTCASE( ! isalpha( '@' ) );
}
END_TEST
START_TEST( isblank )
{
TESTCASE( isblank( ' ' ) );
TESTCASE( isblank( '\t' ) );
TESTCASE( ! isblank( '\v' ) );
TESTCASE( ! isblank( '\r' ) );
TESTCASE( ! isblank( 'x' ) );
TESTCASE( ! isblank( '@' ) );
}
END_TEST
START_TEST( iscntrl )
{
TESTCASE( iscntrl( '\a' ) );
TESTCASE( iscntrl( '\b' ) );
TESTCASE( iscntrl( '\n' ) );
TESTCASE( ! iscntrl( ' ' ) );
}
END_TEST
START_TEST( isdigit )
{
TESTCASE( isdigit( '0' ) );
TESTCASE( isdigit( '9' ) );
TESTCASE( ! isdigit( ' ' ) );
TESTCASE( ! isdigit( 'a' ) );
TESTCASE( ! isdigit( '@' ) );
}
END_TEST
START_TEST( isgraph )
{
TESTCASE( isgraph( 'a' ) );
TESTCASE( isgraph( 'z' ) );
TESTCASE( isgraph( 'A' ) );
TESTCASE( isgraph( 'Z' ) );
TESTCASE( isgraph( '@' ) );
TESTCASE( ! isgraph( '\t' ) );
TESTCASE( ! isgraph( '\0' ) );
TESTCASE( ! isgraph( ' ' ) );
}
END_TEST
START_TEST( islower )
{
TESTCASE( islower( 'a' ) );
TESTCASE( islower( 'z' ) );
TESTCASE( ! islower( 'A' ) );
TESTCASE( ! islower( 'Z' ) );
TESTCASE( ! islower( ' ' ) );
TESTCASE( ! islower( '@' ) );
}
END_TEST
START_TEST( isprint )
{
TESTCASE( isprint( 'a' ) );
TESTCASE( isprint( 'z' ) );
TESTCASE( isprint( 'A' ) );
TESTCASE( isprint( 'Z' ) );
TESTCASE( isprint( '@' ) );
TESTCASE( ! isprint( '\t' ) );
TESTCASE( ! isprint( '\0' ) );
TESTCASE( isprint( ' ' ) );
}
END_TEST
START_TEST( ispunct )
{
TESTCASE( ! ispunct( 'a' ) );
TESTCASE( ! ispunct( 'z' ) );
TESTCASE( ! ispunct( 'A' ) );
TESTCASE( ! ispunct( 'Z' ) );
TESTCASE( ispunct( '@' ) );
TESTCASE( ispunct( '.' ) );
TESTCASE( ! ispunct( '\t' ) );
TESTCASE( ! ispunct( '\0' ) );
TESTCASE( ! ispunct( ' ' ) );
}
END_TEST
START_TEST( isspace )
{
TESTCASE( isspace( ' ' ) );
TESTCASE( isspace( '\f' ) );
TESTCASE( isspace( '\n' ) );
TESTCASE( isspace( '\r' ) );
TESTCASE( isspace( '\t' ) );
TESTCASE( isspace( '\v' ) );
TESTCASE( ! isspace( 'a' ) );
}
END_TEST
START_TEST( isupper )
{
TESTCASE( isupper( 'A' ) );
TESTCASE( isupper( 'Z' ) );
TESTCASE( ! isupper( 'a' ) );
TESTCASE( ! isupper( 'z' ) );
TESTCASE( ! isupper( ' ' ) );
TESTCASE( ! isupper( '@' ) );
}
END_TEST
START_TEST( isxdigit )
{
TESTCASE( isxdigit( '0' ) );
TESTCASE( isxdigit( '9' ) );
TESTCASE( isxdigit( 'a' ) );
TESTCASE( isxdigit( 'f' ) );
TESTCASE( ! isxdigit( 'g' ) );
TESTCASE( isxdigit( 'A' ) );
TESTCASE( isxdigit( 'F' ) );
TESTCASE( ! isxdigit( 'G' ) );
TESTCASE( ! isxdigit( '@' ) );
TESTCASE( ! isxdigit( ' ' ) );
}
END_TEST
START_TEST( tolower )
{
TESTCASE( tolower( 'A' ) == 'a' );
TESTCASE( tolower( 'Z' ) == 'z' );
TESTCASE( tolower( 'a' ) == 'a' );
TESTCASE( tolower( 'z' ) == 'z' );
TESTCASE( tolower( '@' ) == '@' );
TESTCASE( tolower( '[' ) == '[' );
}
END_TEST
START_TEST( toupper )
{
TESTCASE( toupper( 'a' ) == 'A' );
TESTCASE( toupper( 'z' ) == 'Z' );
TESTCASE( toupper( 'A' ) == 'A' );
TESTCASE( toupper( 'Z' ) == 'Z' );
TESTCASE( toupper( '@' ) == '@' );
TESTCASE( toupper( '[' ) == '[' );
}
END_TEST
START_SUITE( ctype )
{
RUN_TEST( isalnum );
RUN_TEST( isalpha );
RUN_TEST( isblank );
RUN_TEST( iscntrl );
RUN_TEST( isdigit );
RUN_TEST( isgraph );
RUN_TEST( islower );
RUN_TEST( isprint );
RUN_TEST( ispunct );
RUN_TEST( isspace );
RUN_TEST( isupper );
RUN_TEST( isxdigit );
RUN_TEST( tolower );
RUN_TEST( toupper );
}
END_SUITE

View File

@@ -1,724 +0,0 @@
#include "_PDCLIB_test.h"
#include "_PDCLIB_iotest.h"
#include <assert.h>
START_TEST( atomax )
{
/* basic functionality */
TESTCASE( _PDCLIB_atomax( "123" ) == 123 );
/* testing skipping of leading whitespace and trailing garbage */
TESTCASE( _PDCLIB_atomax( " \n\v\t\f123xyz" ) == 123 );
}
END_TEST
START_TEST( digits )
{
TESTCASE( strcmp( _PDCLIB_digits, "0123456789abcdefghijklmnopqrstuvwxyz" ) == 0 );
TESTCASE( strcmp( _PDCLIB_Xdigits, "0123456789ABCDEF" ) == 0 );
}
END_TEST
START_TEST( filemode )
{
TESTCASE( _PDCLIB_filemode( "r" ) == _PDCLIB_FREAD );
TESTCASE( _PDCLIB_filemode( "w" ) == _PDCLIB_FWRITE );
TESTCASE( _PDCLIB_filemode( "a" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE ) );
TESTCASE( _PDCLIB_filemode( "r+" ) == ( _PDCLIB_FREAD | _PDCLIB_FRW ) );
TESTCASE( _PDCLIB_filemode( "w+" ) == ( _PDCLIB_FWRITE | _PDCLIB_FRW ) );
TESTCASE( _PDCLIB_filemode( "a+" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE | _PDCLIB_FRW ) );
TESTCASE( _PDCLIB_filemode( "rb" ) == ( _PDCLIB_FREAD | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "wb" ) == ( _PDCLIB_FWRITE | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "ab" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "r+b" ) == ( _PDCLIB_FREAD | _PDCLIB_FRW | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "w+b" ) == ( _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "a+b" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "rb+" ) == ( _PDCLIB_FREAD | _PDCLIB_FRW | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "wb+" ) == ( _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "ab+" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_FBIN ) );
TESTCASE( _PDCLIB_filemode( "x" ) == 0 );
TESTCASE( _PDCLIB_filemode( "r++" ) == 0 );
TESTCASE( _PDCLIB_filemode( "wbb" ) == 0 );
TESTCASE( _PDCLIB_filemode( "a+bx" ) == 0 );
}
END_TEST
START_TEST( is_leap )
{
/* 1901 not leap */
TESTCASE( ! _PDCLIB_is_leap( 1 ) );
/* 1904 leap */
TESTCASE( _PDCLIB_is_leap( 4 ) );
/* 1900 not leap */
TESTCASE( ! _PDCLIB_is_leap( 0 ) );
/* 2000 leap */
TESTCASE( _PDCLIB_is_leap( 100 ) );
}
END_TEST
START_TEST( load_lc_ctype )
{
FILE * fh = fopen( "test_ctype.dat", "wb" );
TESTCASE_REQUIRE( fh != NULL );
/* For test purposes, let's set up a charset that only has the hex digits */
/* 0x00..0x09 - digits */
/* 0x11..0x16 - Xdigits */
/* 0x21..0x26 - xdigits */
TESTCASE( j6libc_fprintf( fh, "%x %x\n", 0x00, 0x09 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x %x\n", 0x11, 0x16, 0x21, 0x26 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x00, 0x00 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x01, 0x01 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x02, 0x02 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x03, 0x03 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x04, 0x04 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x05, 0x05 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x06, 0x06 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x07, 0x07 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x08, 0x08 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x09, 0x09 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x0A, 0x0A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x0B, 0x0B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x0C, 0x0C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x0D, 0x0D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x0E, 0x0E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x0F, 0x0F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x10, 0x10 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x11, 0x11 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x12, 0x12 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x13, 0x13 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x14, 0x14 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x15, 0x15 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x16, 0x16 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x17, 0x17 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x18, 0x18 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x19, 0x19 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x1A, 0x1A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x1B, 0x1B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x1C, 0x1C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x1D, 0x1D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x1E, 0x1E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x1F, 0x1F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x20, 0x20 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x21, 0x21 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x22, 0x22 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x23, 0x23 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x24, 0x24 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x25, 0x25 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x26, 0x26 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x27, 0x27 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x28, 0x28 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x29, 0x29 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x2A, 0x2A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x2B, 0x2B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x2C, 0x2C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x2D, 0x2D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x2E, 0x2E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x2F, 0x2F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x30, 0x30 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x31, 0x31 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x32, 0x32 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x33, 0x33 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x34, 0x34 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x35, 0x35 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x36, 0x36 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x37, 0x37 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x38, 0x38 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x39, 0x39 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x3A, 0x3A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x3B, 0x3B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x3C, 0x3C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x3D, 0x3D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x3E, 0x3E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x3F, 0x3F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x40, 0x40 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x41, 0x41 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x42, 0x42 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x43, 0x43 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x44, 0x44 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x45, 0x45 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x46, 0x46 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x47, 0x47 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x48, 0x48 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x49, 0x49 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x4A, 0x4A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x4B, 0x4B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x4C, 0x4C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x4D, 0x4D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x4E, 0x4E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x4F, 0x4F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x50, 0x50 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x51, 0x51 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x52, 0x52 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x53, 0x53 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x54, 0x54 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x55, 0x55 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x56, 0x56 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x57, 0x57 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x58, 0x58 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x59, 0x59 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x5A, 0x5A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x5B, 0x5B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x5C, 0x5C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x5D, 0x5D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x5E, 0x5E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x5F, 0x5F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x60, 0x60 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x61, 0x61 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x62, 0x62 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x63, 0x63 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x64, 0x64 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x65, 0x65 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x66, 0x66 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x67, 0x67 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x68, 0x68 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x69, 0x69 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x6A, 0x6A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x6B, 0x6B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x6C, 0x6C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x6D, 0x6D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x6E, 0x6E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x6F, 0x6F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x70, 0x70 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x71, 0x71 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x72, 0x72 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x73, 0x73 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x74, 0x74 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x75, 0x75 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x76, 0x76 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x77, 0x77 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x78, 0x78 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x79, 0x79 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x7A, 0x7A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x7B, 0x7B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x7C, 0x7C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x7D, 0x7D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x7E, 0x7E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x7F, 0x7F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x80, 0x80 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x81, 0x81 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x82, 0x82 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x83, 0x83 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x84, 0x84 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x85, 0x85 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x86, 0x86 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x87, 0x87 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x88, 0x88 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x89, 0x89 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x8A, 0x8A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x8B, 0x8B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x8C, 0x8C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x8D, 0x8D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x8E, 0x8E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x8F, 0x8F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x90, 0x90 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x91, 0x91 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x92, 0x92 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x93, 0x93 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x94, 0x94 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x95, 0x95 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x96, 0x96 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x97, 0x97 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x98, 0x98 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x99, 0x99 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x9A, 0x9A ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x9B, 0x9B ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x9C, 0x9C ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x9D, 0x9D ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x9E, 0x9E ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0x9F, 0x9F ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA0, 0xA0 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA1, 0xA1 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA2, 0xA2 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA3, 0xA3 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA4, 0xA4 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA5, 0xA5 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA6, 0xA6 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA7, 0xA7 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA8, 0xA8 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xA9, 0xA9 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xAA, 0xAA ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xAB, 0xAB ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xAC, 0xAC ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xAD, 0xAD ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xAE, 0xAE ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xAF, 0xAF ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB0, 0xB0 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB1, 0xB1 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB2, 0xB2 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB3, 0xB3 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB4, 0xB4 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB5, 0xB5 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB6, 0xB6 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB7, 0xB7 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB8, 0xB8 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xB9, 0xB9 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xBA, 0xBA ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xBB, 0xBB ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xBC, 0xBC ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xBD, 0xBD ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xBE, 0xBE ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xBF, 0xBF ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC0, 0xC0 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC1, 0xC1 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC2, 0xC2 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC3, 0xC3 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC4, 0xC4 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC5, 0xC5 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC6, 0xC6 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC7, 0xC7 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC8, 0xC8 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xC9, 0xC9 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xCA, 0xCA ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xCB, 0xCB ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xCC, 0xCC ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xCD, 0xCD ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xCE, 0xCE ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xCF, 0xCF ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD0, 0xD0 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD1, 0xD1 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD2, 0xD2 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD3, 0xD3 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD4, 0xD4 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD5, 0xD5 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD6, 0xD6 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD7, 0xD7 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD8, 0xD8 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xD9, 0xD9 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xDA, 0xDA ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xDB, 0xDB ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xDC, 0xDC ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xDD, 0xDD ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xDE, 0xDE ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xDF, 0xDF ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE0, 0xE0 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE1, 0xE1 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE2, 0xE2 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE3, 0xE3 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE4, 0xE4 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE5, 0xE5 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE6, 0xE6 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE7, 0xE7 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE8, 0xE8 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xE9, 0xE9 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xEA, 0xEA ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xEB, 0xEB ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xEC, 0xEC ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xED, 0xED ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xEE, 0xEE ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xEF, 0xEF ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF0, 0xF0 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF1, 0xF1 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF2, 0xF2 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF3, 0xF3 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF4, 0xF4 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF5, 0xF5 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF6, 0xF6 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF7, 0xF7 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF8, 0xF8 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xF9, 0xF9 ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xFA, 0xFA ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xFB, 0xFB ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xFC, 0xFC ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xFD, 0xFD ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xFE, 0xFE ) );
TESTCASE( j6libc_fprintf( fh, "%x %x %x\n", 0x00, 0xFF, 0xFF) );
fclose( fh );
TESTCASE( _PDCLIB_load_lc_ctype( "./", "test" ) != NULL );
remove( "test_ctype.dat" );
/*
TESTCASE( isdigit( 0x00 ) && ! isxdigit( 0x00 ) && ! isalpha( 0x00 ) );
TESTCASE( ! isdigit( 0x11 ) && isxdigit( 0x11 ) && isalpha( 0x11 ) && isupper( 0x11 ) && ! islower( 0x11 ) );
TESTCASE( ! isdigit( 0x21 ) && isxdigit( 0x21 ) && isalpha( 0x21 ) && ! isupper( 0x11 ) && islower( 0x11 ) );
*/
}
END_TEST
START_TEST( load_lc_messages )
{
FILE * fh = fopen( "test_numeric.dat", "wb" );
struct _PDCLIB_lc_lconv_numeric_t * lc;
TESTCASE_REQUIRE( fh != NULL );
TESTCASE( fputs( ",\n.\n\n", fh ) != EOF );
fclose( fh );
TESTCASE( ( lc = _PDCLIB_load_lc_numeric( "./", "test" ) ) );
remove( "test_numeric.dat" );
TESTCASE( strcmp( lc->decimal_point, "," ) == 0 );
TESTCASE( strcmp( lc->thousands_sep, "." ) == 0 );
TESTCASE( strcmp( lc->grouping, "" ) == 0 );
}
END_TEST
START_TEST( load_lc_monetary )
{
FILE * fh = fopen( "test_monetary.dat", "wb" );
struct _PDCLIB_lc_lconv_monetary_t * lc;
TESTCASE_REQUIRE( fh != NULL );
j6libc_fprintf( fh, "%s\n", "," ); /* mon_decimal_point */
j6libc_fprintf( fh, "%s\n", "." ); /* mon_thousands_sep */
j6libc_fprintf( fh, "%s\n", "3" ); /* mon_grouping */
j6libc_fprintf( fh, "%s\n", "" ); /* positive_sign */
j6libc_fprintf( fh, "%s\n", "-" ); /* negative_sign */
j6libc_fprintf( fh, "%s\n", "\xa4" ); /* currency_symbol */
j6libc_fprintf( fh, "%s\n", "EUR" ); /* int_curr_symbol */
fputc( 2, fh ); /* frac_digits */
fputc( 0, fh ); /* p_cs_precedes */
fputc( 0, fh ); /* n_cs_precedes */
fputc( 1, fh ); /* p_sep_by_space */
fputc( 1, fh ); /* n_sep_by_space */
fputc( 1, fh ); /* p_sign_posn */
fputc( 1, fh ); /* n_sign_posn */
fputc( 2, fh ); /* int_frac_digits */
fputc( 0, fh ); /* int_p_cs_precedes */
fputc( 0, fh ); /* int_n_cs_precedes */
fputc( 1, fh ); /* int_p_sep_by_space */
fputc( 1, fh ); /* int_n_sep_by_space */
fputc( 1, fh ); /* int_p_sign_posn */
fputc( 1, fh ); /* int_n_sign_posn */
j6libc_fprintf( fh, "\n" );
fclose( fh );
TESTCASE( ( lc = _PDCLIB_load_lc_monetary( "./", "test" ) ) );
remove( "test_monetary.dat" );
TESTCASE( strcmp( lc->mon_decimal_point, "," ) == 0 );
TESTCASE( strcmp( lc->mon_thousands_sep, "." ) == 0 );
TESTCASE( strcmp( lc->mon_grouping, "3" ) == 0 );
TESTCASE( strcmp( lc->positive_sign, "" ) == 0 );
TESTCASE( strcmp( lc->negative_sign, "-" ) == 0 );
TESTCASE( strcmp( lc->currency_symbol, "\xa4" ) == 0 );
TESTCASE( strcmp( lc->int_curr_symbol, "EUR" ) == 0 );
TESTCASE( lc->frac_digits == 2 );
TESTCASE( lc->p_cs_precedes == 0 );
TESTCASE( lc->n_cs_precedes == 0 );
TESTCASE( lc->p_sep_by_space == 1 );
TESTCASE( lc->n_sep_by_space == 1 );
TESTCASE( lc->p_sign_posn == 1 );
TESTCASE( lc->n_sign_posn == 1 );
TESTCASE( lc->int_frac_digits == 2 );
TESTCASE( lc->int_p_cs_precedes == 0 );
TESTCASE( lc->int_n_cs_precedes == 0 );
TESTCASE( lc->int_p_sep_by_space == 1 );
TESTCASE( lc->int_n_sep_by_space == 1 );
TESTCASE( lc->int_p_sign_posn == 1 );
TESTCASE( lc->int_n_sign_posn == 1 );
}
END_TEST
START_TEST( load_lc_numeric )
{
FILE * fh = fopen( "test_numeric.dat", "wb" );
struct _PDCLIB_lc_lconv_numeric_t * lc;
TESTCASE_REQUIRE( fh != NULL );
TESTCASE( fputs( ",\n.\n\n", fh ) != EOF );
fclose( fh );
TESTCASE( ( lc = _PDCLIB_load_lc_numeric( "./", "test" ) ) );
remove( "test_numeric.dat" );
TESTCASE( strcmp( lc->decimal_point, "," ) == 0 );
TESTCASE( strcmp( lc->thousands_sep, "." ) == 0 );
TESTCASE( strcmp( lc->grouping, "" ) == 0 );
}
END_TEST
START_TEST( load_lc_time )
{
FILE * fh = fopen( "test_time.dat", "wb" );
struct _PDCLIB_lc_time_t * lc;
TESTCASE_REQUIRE( fh != NULL );
/* month name abbreviation */
TESTCASE( j6libc_fprintf( fh, "%s\n", "Jan" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Feb" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "M\xe4r" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Apr" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Mai" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Jun" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Jul" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Aug" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Sep" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Okt" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Nov" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Dez" ) == 4 );
/* month name full */
TESTCASE( j6libc_fprintf( fh, "%s\n", "Januar" ) == 7 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Februar" ) == 8 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "M\xe4rz" ) == 5 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "April" ) == 6 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Mai" ) == 4 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Juni" ) == 5 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Juli" ) == 5 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "August" ) == 7 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "September" ) == 10 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Oktober" ) == 8 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "November" ) == 9 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Dezember" ) == 9 );
/* day name abbreviation */
TESTCASE( j6libc_fprintf( fh, "%s\n", "So" ) == 3 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Mo" ) == 3 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Di" ) == 3 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Mi" ) == 3 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Do" ) == 3 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Fr" ) == 3 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Sa" ) == 3 );
/* day name full */
TESTCASE( j6libc_fprintf( fh, "%s\n", "Sonntag" ) == 8 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Montag" ) == 7 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Dienstag" ) == 9 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Mittwoch" ) == 9 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Donnerstag" ) == 11 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Freitag" ) == 8 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "Samstag" ) == 8 );
TESTCASE( j6libc_fprintf( fh, "%s\n", "%a %d %b %Y %T %Z" ) == 18 ); /* date time format (%c) */
TESTCASE( j6libc_fprintf( fh, "%s\n", "%I:%M:%S" ) == 9 ); /* 12-hour time format (%r) */
TESTCASE( j6libc_fprintf( fh, "%s\n", "%d.%m.%Y" ) == 9 ); /* date format (%x) */
TESTCASE( j6libc_fprintf( fh, "%s\n", "%H:%M:%S" ) == 9 ); /* time format (%X) */
TESTCASE( j6libc_fprintf( fh, "%s\n", "" ) == 1 ); /* AM */
TESTCASE( j6libc_fprintf( fh, "%s\n", "" ) == 1 ); /* PM */
fclose( fh );
TESTCASE( ( lc = _PDCLIB_load_lc_time( "./", "test" ) ) );
remove( "test_time.dat" );
TESTCASE( strcmp( lc->month_name_abbr[ 0 ], "Jan" ) == 0 );
TESTCASE( strcmp( lc->month_name_abbr[ 11 ], "Dez" ) == 0 );
TESTCASE( strcmp( lc->month_name_full[ 0 ], "Januar" ) == 0 );
TESTCASE( strcmp( lc->month_name_full[ 11 ], "Dezember" ) == 0 );
TESTCASE( strcmp( lc->day_name_abbr[ 0 ], "So" ) == 0 );
TESTCASE( strcmp( lc->day_name_abbr[ 6 ], "Sa" ) == 0 );
TESTCASE( strcmp( lc->day_name_full[ 0 ], "Sonntag" ) == 0 );
TESTCASE( strcmp( lc->day_name_full[ 6 ], "Samstag" ) == 0 );
}
END_TEST
START_TEST( load_lines )
{
FILE * fh = fopen( "test_lines.txt", "w+" );
char * rc;
TESTCASE_REQUIRE( fh != NULL );
TESTCASE( fputs( "Foo\n\nBar\n", fh ) != EOF );
rewind( fh );
rc = _PDCLIB_load_lines( fh, 3 );
fclose( fh );
remove( "test_lines.txt" );
TESTCASE( rc != NULL );
TESTCASE( strcmp( rc, "Foo" ) == 0 );
TESTCASE( strcmp( rc + 4, "" ) == 0 );
TESTCASE( strcmp( rc + 5, "Bar" ) == 0 );
}
END_TEST
static int testprintf(
const char *implfile,
const char *file,
int line,
size_t expected_rc,
const char *expected_out,
const char *format,
... )
{
char buffer[100];
/* Members: base, flags, n, i, current, s, width, prec, stream, arg */
struct _PDCLIB_status_t status;
status.base = 0;
status.flags = 0;
status.n = 100;
status.i = 0;
status.current = 0;
status.s = buffer;
status.width = 0;
status.prec = EOF;
status.stream = NULL;
va_start( status.arg, format );
memset( buffer, '\0', 100 );
if ( *(_PDCLIB_print( format, &status )) != '\0' )
{
fprintf( stderr, "_PDCLIB_print() did not return end-of-specifier on '%s'.\n", format );
return 1;
}
va_end( status.arg );
if (status.i != expected_rc ||
strcmp(buffer, expected_out))
{
fprintf( stderr,
"FAILED: %s (%s), line %d\n"
" format string \"%s\"\n"
" expected %2lu, \"%s\"\n"
" actual %2lu, \"%s\"\n",
file, implfile, line, format, expected_rc,
expected_out, status.i, buffer );
return 1;
}
return 0;
}
START_TEST( print )
{
#define IMPLFILE "_PDCLIB/print.c"
#define DO_TESTPRINTF testprintf
#define TEST_CONVERSION_ONLY
#include "printf_testcases.h"
#undef TEST_CONVERSION_ONLY
#undef DO_TESTPRINTF
#undef IMPLFILE
}
END_TEST
static int testscanf(
const char *implfile,
const char *file,
int line,
size_t expected_rc,
const char *input_string,
const char *format,
... )
{
char buffer[100];
memcpy( buffer, input_string, strlen(input_string)+1 );
struct _PDCLIB_status_t status;
status.n = 0;
status.i = 0;
status.s = (char *)buffer;
status.stream = NULL;
va_start( status.arg, format );
if ( *(_PDCLIB_scan( format, &status )) != '\0' )
{
fprintf( stderr, "_PDCLIB_scan() did not return end-of-specifier on '%s'.\n", format );
return 1;
}
va_end( status.arg );
if ( status.n != expected_rc )
{
fprintf( stderr,
"FAILED: %s (%s), line %d\n"
" expected %2lu,\n"
" actual %2lu\n",
file, implfile, line, expected_rc, status.n );
return 1;
}
return 0;
}
START_TEST( scan )
{
#define IMPLFILE "_PDCLIB/scan.c"
#define DO_TESTSCANF testscanf
#define TEST_CONVERSION_ONLY
#include "scanf_testcases.h"
#undef TEST_CONVERSION_ONLY
#undef DO_TESTSCANF
#undef IMPLFILE
}
END_TEST
START_TEST( strtox_main )
{
const char * p;
char test[] = "123_";
char fail[] = "xxx";
char sign = '-';
errno = 0;
p = test;
/* basic functionality */
TESTCASE(
(_PDCLIB_strtox_main(&p, 10u, (uintmax_t)999, (uintmax_t)12, 3, &sign) == 123) &&
(errno == 0) &&
(p == &test[3]) );
/* proper functioning to smaller base */
TESTCASE(
(_PDCLIB_strtox_main(&p, 8u, (uintmax_t)999, (uintmax_t)12, 3, &sign) == 0123) &&
(errno == 0) &&
(p == &test[3]) );
/* overflowing subject sequence must still return proper endptr */
TESTCASE(
(_PDCLIB_strtox_main(&p, 4u, (uintmax_t)999, (uintmax_t)1, 2, &sign) == 999) &&
(errno == ERANGE) &&
(p == &test[3]) &&
(sign == '+') );
/* testing conversion failure */
p = fail;
sign = '-';
TESTCASE(
(_PDCLIB_strtox_main(&p, 10u, (uintmax_t)999, (uintmax_t)99, 8, &sign) == 0) &&
(p == NULL) );
}
END_TEST
START_TEST( strtox_prelim )
{
int base = 0;
char sign = '\0';
char test1[] = " 123";
char test2[] = "\t+0123";
char test3[] = "\v-0x123";
TESTCASE(
(_PDCLIB_strtox_prelim(test1, &sign, &base) == &test1[2]) &&
(sign == '+') &&
(base == 10) );
TESTCASE(
(_PDCLIB_strtox_prelim(test2, &sign, &base) == &test2[3]) &&
(sign == '+') &&
(base == 8) );
TESTCASE(
(_PDCLIB_strtox_prelim(test3, &sign, &base) == &test3[4]) &&
(sign == '-') &&
(base == 16) );
base = 10;
TESTCASE(
(_PDCLIB_strtox_prelim(test3, &sign, &base) == &test3[2]) &&
(sign == '-') &&
(base == 10) );
base = 1;
TESTCASE( _PDCLIB_strtox_prelim(test3, &sign, &base) == NULL );
base = 37;
TESTCASE( _PDCLIB_strtox_prelim(test3, &sign, &base) == NULL );
}
END_TEST
START_SUITE( internal )
{
RUN_TEST( atomax );
RUN_TEST( digits );
RUN_TEST( filemode );
RUN_TEST( is_leap );
RUN_TEST( print );
RUN_TEST( scan );
RUN_TEST( strtox_main );
RUN_TEST( strtox_prelim );
// These fail due to lack of open()
/*
RUN_TEST( load_lc_ctype );
RUN_TEST( load_lc_messages );
RUN_TEST( load_lc_monetary );
RUN_TEST( load_lc_numeric );
RUN_TEST( load_lc_time );
RUN_TEST( load_lines );
*/
}
END_SUITE

View File

@@ -1,194 +0,0 @@
#include "_PDCLIB_test.h"
START_TEST( imaxabs )
{
TESTCASE( imaxabs( (intmax_t)0 ) == 0 );
TESTCASE( imaxabs( INTMAX_MAX ) == INTMAX_MAX );
TESTCASE( imaxabs( INTMAX_MIN + 1 ) == -( INTMAX_MIN + 1 ) );
}
END_TEST
START_TEST( imaxdiv )
{
imaxdiv_t result;
result = imaxdiv( (intmax_t)5, (intmax_t)2 );
TESTCASE( result.quot == 2 && result.rem == 1 );
result = imaxdiv( (intmax_t)-5, (intmax_t)2 );
TESTCASE( result.quot == -2 && result.rem == -1 );
result = imaxdiv( (intmax_t)5, (intmax_t)-2 );
TESTCASE( result.quot == -2 && result.rem == 1 );
TESTCASE( sizeof( result.quot ) == sizeof( intmax_t ) );
TESTCASE( sizeof( result.rem ) == sizeof( intmax_t ) );
}
END_TEST
START_TEST( strtoimax )
{
char * endptr;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
/* tricky border case */
char tricky[] = "+0xz";
errno = 0;
/* basic functionality */
TESTCASE( strtoimax( "123", NULL, 10 ) == 123 );
/* proper detecting of default base 10 */
TESTCASE( strtoimax( "456", NULL, 0 ) == 456 );
/* proper functioning to smaller base */
TESTCASE( strtoimax( "14", NULL, 8 ) == 12 );
/* proper autodetecting of octal */
TESTCASE( strtoimax( "016", NULL, 0 ) == 14 );
/* proper autodetecting of hexadecimal, lowercase 'x' */
TESTCASE( strtoimax( "0xFF", NULL, 0 ) == 255 );
/* proper autodetecting of hexadecimal, uppercase 'X' */
TESTCASE( strtoimax( "0Xa1", NULL, 0 ) == 161 );
/* proper handling of border case: 0x followed by non-hexdigit */
TESTCASE(
(strtoimax(tricky, &endptr, 0) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* proper handling of border case: 0 followed by non-octdigit */
TESTCASE(
(strtoimax(tricky, &endptr, 8) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* overflowing subject sequence must still return proper endptr */
TESTCASE(
(strtoimax(overflow, &endptr, 36) == INTMAX_MIN) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* same for positive */
TESTCASE(
(strtoimax(overflow + 1, &endptr, 36) == INTMAX_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* testing skipping of leading whitespace */
TESTCASE( strtoimax( " \n\v\t\f789", NULL, 0 ) == 789 );
/* testing conversion failure */
TESTCASE( (strtoimax(overflow, &endptr, 10) == 0) && (endptr == overflow) );
TESTCASE( (strtoimax(overflow, &endptr, 0) == 0) && (endptr == overflow) );
/* These tests assume two-complement, but conversion should work for */
/* one-complement and signed magnitude just as well. Anyone having a */
/* platform to test this on? */
#if INTMAX_MAX >> 62 == 1
/* testing "odd" overflow, i.e. base is not a power of two */
TESTCASE( (strtoimax("9223372036854775807", NULL, 0) == INTMAX_MAX) && (errno == 0) );
TESTCASE( (strtoimax("9223372036854775808", NULL, 0) == INTMAX_MAX) && (errno == ERANGE) );
TESTCASE( (strtoimax("-9223372036854775807", NULL, 0) == (INTMAX_MIN + 1)) && (errno == 0) );
TESTCASE( (strtoimax("-9223372036854775808", NULL, 0) == INTMAX_MIN) && (errno == 0) );
TESTCASE( (strtoimax("-9223372036854775809", NULL, 0) == INTMAX_MIN) && (errno == ERANGE) );
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoimax("0x7fffffffffffffff", NULL, 0) == INTMAX_MAX) && (errno == 0) );
TESTCASE( (strtoimax("0x8000000000000000", NULL, 0 ) == INTMAX_MAX) && (errno == ERANGE) );
TESTCASE( (strtoimax("-0x7fffffffffffffff", NULL, 0 ) == (INTMAX_MIN + 1)) && (errno == 0) );
TESTCASE( (strtoimax("-0x8000000000000000", NULL, 0 ) == INTMAX_MIN) && (errno == 0) );
TESTCASE( (strtoimax("-0x8000000000000001", NULL, 0 ) == INTMAX_MIN) && (errno == ERANGE) );
#elif LLONG_MAX >> 126 == 1
/* testing "odd" overflow, i.e. base is not a power of two */
TESTCASE( (strtoimax("170141183460469231731687303715884105728", NULL, 0 ) == INTMAX_MAX) && (errno == 0) );
TESTCASE( (strtoimax("170141183460469231731687303715884105729", NULL, 0 ) == INTMAX_MAX) && (errno == ERANGE) );
TESTCASE( (strtoimax("-170141183460469231731687303715884105728", NULL, 0 ) == (INTMAX_MIN + 1)) && (errno == 0) );
TESTCASE( (strtoimax("-170141183460469231731687303715884105729", NULL, 0 ) == INTMAX_MIN) && (errno == 0) );
TESTCASE( (strtoimax("-170141183460469231731687303715884105730", NULL, 0 ) == INTMAX_MIN) && (errno == ERANGE) );
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoimax("0x7fffffffffffffffffffffffffffffff", NULL, 0 ) == INTMAX_MAX) && (errno == 0) );
TESTCASE( (strtoimax("0x80000000000000000000000000000000", NULL, 0 ) == INTMAX_MAX) && (errno == ERANGE) );
TESTCASE( (strtoimax("-0x7fffffffffffffffffffffffffffffff", NULL, 0 ) == (INTMAX_MIN + 1)) && (errno == 0) );
TESTCASE( (strtoimax("-0x80000000000000000000000000000000", NULL, 0 ) == INTMAX_MIN) && (errno == 0) );
TESTCASE( (strtoimax("-0x80000000000000000000000000000001", NULL, 0 ) == INTMAX_MIN) && (errno == ERANGE) );
#else
#error Unsupported width of 'intmax_t' (neither 64 nor 128 bit).
#endif
}
END_TEST
START_TEST( strtoumax )
{
char * endptr;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
/* tricky border case */
char tricky[] = "+0xz";
errno = 0;
/* basic functionality */
TESTCASE( strtoumax( "123", NULL, 10 ) == 123 );
/* proper detecting of default base 10 */
TESTCASE( strtoumax( "456", NULL, 0 ) == 456 );
/* proper functioning to smaller base */
TESTCASE( strtoumax( "14", NULL, 8 ) == 12 );
/* proper autodetecting of octal */
TESTCASE( strtoumax( "016", NULL, 0 ) == 14 );
/* proper autodetecting of hexadecimal, lowercase 'x' */
TESTCASE( strtoumax( "0xFF", NULL, 0 ) == 255 );
/* proper autodetecting of hexadecimal, uppercase 'X' */
TESTCASE( strtoumax( "0Xa1", NULL, 0 ) == 161 );
/* proper handling of border case: 0x followed by non-hexdigit */
TESTCASE(
(strtoumax(tricky, &endptr, 0) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* proper handling of border case: 0 followed by non-octdigit */
TESTCASE(
(strtoumax(tricky, &endptr, 8) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* overflowing subject sequence must still return proper endptr */
TESTCASE(
(strtoumax(overflow, &endptr, 36) == UINTMAX_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* same for positive */
TESTCASE(
(strtoumax(overflow + 1, &endptr, 36) == UINTMAX_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* testing skipping of leading whitespace */
TESTCASE( strtoumax( " \n\v\t\f789", NULL, 0 ) == 789 );
/* testing conversion failure */
TESTCASE( (strtoumax(overflow, &endptr, 10) == 0) && (endptr == overflow) );
TESTCASE( (strtoumax(overflow, &endptr, 0) == 0) && (endptr == overflow) );
/* uintmax_t -> long long -> 64 bit */
#if UINTMAX_MAX >> 63 == 1
/* testing "odd" overflow, i.e. base is not power of two */
TESTCASE( (strtoumax("18446744073709551615", NULL, 0) == UINTMAX_MAX) && (errno == 0) );
TESTCASE( (strtoumax("18446744073709551616", NULL, 0) == UINTMAX_MAX) && (errno == ERANGE) );
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoumax("0xFFFFFFFFFFFFFFFF", NULL, 0) == UINTMAX_MAX) && (errno == 0) );
TESTCASE( (strtoumax("0x10000000000000000", NULL, 0) == UINTMAX_MAX) && (errno == ERANGE) );
/* uintmax_t -> long long -> 128 bit */
#elif UINTMAX_MAX >> 127 == 1
/* testing "odd" overflow, i.e. base is not power of two */
TESTCASE( (strtoumax("340282366920938463463374607431768211455", NULL, 0) == UINTMAX_MAX) && (errno == 0) );
TESTCASE( (strtoumax("340282366920938463463374607431768211456", NULL, 0) == UINTMAX_MAX) && (errno == ERANGE) );
/* testing "even" everflow, i.e. base is power of two */
TESTCASE( (strtoumax("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NULL, 0) == UINTMAX_MAX) && (errno == 0) );
TESTCASE( (strtoumax("0x100000000000000000000000000000000", NULL, 0) == UINTMAX_MAX) && (errno == ERANGE) );
#else
#error Unsupported width of 'uintmax_t' (neither 64 nor 128 bit).
#endif
}
END_TEST
START_SUITE( inttypes )
{
RUN_TEST( imaxabs );
RUN_TEST( imaxdiv );
RUN_TEST( strtoimax );
RUN_TEST( strtoumax );
}
END_SUITE

View File

@@ -1,7 +0,0 @@
#include "_PDCLIB_test.h"
START_SUITE( locale )
{
}
END_SUITE

View File

@@ -1,49 +0,0 @@
#include "_PDCLIB_test.h"
#include <stdlib.h>
static volatile sig_atomic_t flag = 0;
static int expected_signal = 0;
static int received_signal = 0;
static void test_handler( int sig )
{
flag = 1;
}
START_TEST( raise )
{
/* Could be other than SIG_DFL if you changed the implementation. */
TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL );
/* Should be ignored. */
TESTCASE( raise( SIGABRT ) == 0 );
/* Installing test handler, old handler should be returned */
TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN );
/* Raising and checking SIGABRT */
expected_signal = SIGABRT;
TESTCASE( raise( SIGABRT ) == 0 );
TESTCASE( flag == 1 );
TESTCASE( received_signal == SIGABRT );
/* Re-installing test handler, should have been reset to default */
/* Could be other than SIG_DFL if you changed the implementation. */
TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL );
/* Raising and checking SIGABRT */
flag = 0;
TESTCASE( raise( SIGABRT ) == 0 );
TESTCASE( flag == 1 );
TESTCASE( received_signal == SIGABRT );
/* Installing test handler for different signal... */
TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL );
/* Raising and checking SIGTERM */
expected_signal = SIGTERM;
TESTCASE( raise( SIGTERM ) == 0 );
TESTCASE( flag == 1 );
TESTCASE( received_signal == SIGTERM );
}
END_TEST
START_SUITE( signal )
{
RUN_TEST( raise );
}
END_SUITE

View File

@@ -1,67 +0,0 @@
#include <stdarg.h>
#include <limits.h>
#include <float.h>
#include "_PDCLIB_test.h"
typedef int (*intfunc_t)( void );
enum tag_t
{
TAG_END,
TAG_INT,
TAG_LONG,
TAG_LLONG,
TAG_DBL,
TAG_LDBL,
TAG_INTPTR,
TAG_LDBLPTR,
TAG_FUNCPTR
};
static int dummy( void )
{
return INT_MAX;
}
static int test( enum tag_t s, ... )
{
enum tag_t tag = s;
va_list ap;
va_start( ap, s );
for (;;)
{
switch ( tag )
{
case TAG_INT: if( va_arg( ap, int ) != INT_MAX ) return 0; break;
case TAG_LONG: if( va_arg( ap, long ) != LONG_MAX ) return 0; break;
case TAG_LLONG: if( va_arg( ap, long long ) != LLONG_MAX ) return 0; break;
case TAG_DBL: if( va_arg( ap, double ) != DBL_MAX ) return 0; break;
case TAG_LDBL: if( va_arg( ap, long double ) != LDBL_MAX ) return 0; break;
case TAG_INTPTR: if( *( va_arg( ap, int * ) ) != INT_MAX ) return 0; break;
case TAG_LDBLPTR: if( *( va_arg( ap, long double * ) ) != LDBL_MAX ) return 0; break;
case TAG_FUNCPTR: if( va_arg( ap, intfunc_t ) != dummy ) return 0; break;
case TAG_END: va_end( ap ); return 1;
}
tag = va_arg( ap, enum tag_t );
}
}
START_TEST( stdarg )
{
int x = INT_MAX;
long double d = LDBL_MAX;
TESTCASE( test(TAG_END) );
TESTCASE( test(TAG_INT, INT_MAX, TAG_END) );
TESTCASE( test(TAG_LONG, LONG_MAX, TAG_LLONG, LLONG_MAX, TAG_END) );
TESTCASE( test(TAG_DBL, DBL_MAX, TAG_LDBL, LDBL_MAX, TAG_END) );
TESTCASE( test(TAG_INTPTR, &x, TAG_LDBLPTR, &d, TAG_FUNCPTR, dummy, TAG_END) );
}
END_TEST
START_SUITE( stdarg )
{
RUN_TEST( stdarg );
}
END_SUITE

View File

@@ -1,649 +0,0 @@
#include "_PDCLIB_test.h"
#include "_PDCLIB_iotest.h"
#include <assert.h>
extern struct _PDCLIB_file_t *_PDCLIB_filelist;
START_TEST( clearerr )
{
FILE * fh = tmpfile();
TESTCASE_REQUIRE( fh != NULL );
/* Flags should be clear */
TESTCASE( ! ferror( fh ) );
TESTCASE( ! feof( fh ) );
/* Reading from empty stream - should provoke EOF */
rewind( fh );
TESTCASE( fgetc( fh ) == EOF );
TESTCASE( ! ferror( fh ) );
TESTCASE( feof( fh ) );
/* clearerr() should clear flags */
clearerr( fh );
TESTCASE( ! ferror( fh ) );
TESTCASE( ! feof( fh ) );
/* reopen() the file write-only */
TESTCASE( ( fh = freopen( NULL, "w", fh ) ) != NULL );
/* Reading from write-only stream - should provoke error */
TESTCASE( fgetc( fh ) == EOF );
TESTCASE( ferror( fh ) );
TESTCASE( ! feof( fh ) );
/* clearerr() should clear flags */
clearerr( fh );
TESTCASE( ! ferror( fh ) );
TESTCASE( ! feof( fh ) );
TESTCASE( fclose( fh ) == 0 );
}
END_TEST
START_TEST( fclose )
{
struct _PDCLIB_file_t * file1 = NULL;
struct _PDCLIB_file_t * file2 = NULL;
remove( testfile1 );
remove( testfile2 );
TESTCASE( _PDCLIB_filelist == stdin );
TESTCASE( ( file1 = fopen( testfile1, "w" ) ) != NULL );
TESTCASE( _PDCLIB_filelist == file1 );
TESTCASE( ( file2 = fopen( testfile2, "w" ) ) != NULL );
TESTCASE( _PDCLIB_filelist == file2 );
TESTCASE( fclose( file2 ) == 0 );
TESTCASE( _PDCLIB_filelist == file1 );
TESTCASE( ( file2 = fopen( testfile2, "w" ) ) != NULL );
TESTCASE( _PDCLIB_filelist == file2 );
TESTCASE( fclose( file1 ) == 0 );
TESTCASE( _PDCLIB_filelist == file2 );
TESTCASE( fclose( file2 ) == 0 );
TESTCASE( _PDCLIB_filelist == stdin );
TESTCASE( remove( testfile1 ) == 0 );
TESTCASE( remove( testfile2 ) == 0 );
}
END_TEST
START_TEST( fgetpos )
{
FILE * fh = tmpfile();
fpos_t pos1, pos2;
TESTCASE_REQUIRE( fh != NULL );
TESTCASE( fgetpos( fh, &pos1 ) == 0 );
TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );
TESTCASE( fgetpos( fh, &pos2 ) == 0 );
TESTCASE( fsetpos( fh, &pos1 ) == 0 );
TESTCASE( ftell( fh ) == 0 );
TESTCASE( fsetpos( fh, &pos2 ) == 0 );
TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
TESTCASE( fclose( fh ) == 0 );
}
END_TEST
START_TEST( fgets )
{
FILE * fh = NULL;
char buffer[10];
const char * fgets_test = "foo\nbar\0baz\nweenie";
TESTCASE_REQUIRE( ( fh = fopen( testfile, "wb+" ) ) != NULL );
TESTCASE( fwrite( fgets_test, 1, 18, fh ) == 18 );
rewind( fh );
TESTCASE( fgets( buffer, 10, fh ) == buffer );
TESTCASE( strcmp( buffer, "foo\n" ) == 0 );
TESTCASE( fgets( buffer, 10, fh ) == buffer );
TESTCASE( memcmp( buffer, "bar\0baz\n", 8 ) == 0 );
TESTCASE( fgets( buffer, 10, fh ) == buffer );
TESTCASE( strcmp( buffer, "weenie" ) == 0 );
TESTCASE( feof( fh ) );
TESTCASE( fseek( fh, -1, SEEK_END ) == 0 );
TESTCASE( fgets( buffer, 1, fh ) == buffer );
TESTCASE( strcmp( buffer, "" ) == 0 );
TESTCASE( fgets( buffer, 0, fh ) == NULL );
TESTCASE( ! feof( fh ) );
TESTCASE( fgets( buffer, 1, fh ) == buffer );
TESTCASE( strcmp( buffer, "" ) == 0 );
TESTCASE( ! feof( fh ) );
TESTCASE( fgets( buffer, 2, fh ) == buffer );
TESTCASE( strcmp( buffer, "e" ) == 0 );
TESTCASE( fseek( fh, 0, SEEK_END ) == 0 );
TESTCASE( fgets( buffer, 2, fh ) == NULL );
TESTCASE( feof( fh ) );
TESTCASE( fclose( fh ) == 0 );
TESTCASE( remove( testfile ) == 0 );
}
END_TEST
START_TEST( fopen )
{
/* Some of the tests are not executed for regression tests, as the libc on
my system is at once less forgiving (segfaults on mode NULL) and more
forgiving (accepts undefined modes).
*/
FILE * fh = NULL;
remove( testfile );
TESTCASE( fopen( NULL, NULL ) == NULL );
TESTCASE( fopen( NULL, "w" ) == NULL );
TESTCASE( fopen( "", NULL ) == NULL );
TESTCASE( fopen( "", "w" ) == NULL );
TESTCASE( fopen( "foo", "" ) == NULL );
TESTCASE( fopen( testfile, "wq" ) == NULL ); /* Undefined mode */
TESTCASE( fopen( testfile, "wr" ) == NULL ); /* Undefined mode */
TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL );
TESTCASE( fclose( fh ) == 0 );
TESTCASE( remove( testfile ) == 0 );
}
END_TEST
START_TEST( fputs )
{
const char * const message = "SUCCESS testing fputs()";
FILE * fh = tmpfile();
size_t i;
TESTCASE_REQUIRE( fh != NULL );
TESTCASE( fputs( message, fh ) >= 0 );
rewind( fh );
for ( i = 0; i < 23; ++i )
{
TESTCASE( fgetc( fh ) == message[i] );
}
TESTCASE( fclose( fh ) == 0 );
}
END_TEST
START_TEST( fread )
{
FILE * fh = NULL;
const char * message = "Testing fwrite()...\n";
char buffer[21];
buffer[20] = 'x';
TESTCASE_REQUIRE( ( fh = tmpfile() ) != NULL );
/* fwrite() / readback */
TESTCASE( fwrite( message, 1, 20, fh ) == 20 );
rewind( fh );
TESTCASE( fread( buffer, 1, 20, fh ) == 20 );
TESTCASE( memcmp( buffer, message, 20 ) == 0 );
TESTCASE( buffer[20] == 'x' );
/* same, different nmemb / size settings */
rewind( fh );
TESTCASE( memset( buffer, '\0', 20 ) == buffer );
TESTCASE( fwrite( message, 5, 4, fh ) == 4 );
rewind( fh );
TESTCASE( fread( buffer, 5, 4, fh ) == 4 );
TESTCASE( memcmp( buffer, message, 20 ) == 0 );
TESTCASE( buffer[20] == 'x' );
/* same... */
rewind( fh );
TESTCASE( memset( buffer, '\0', 20 ) == buffer );
TESTCASE( fwrite( message, 20, 1, fh ) == 1 );
rewind( fh );
TESTCASE( fread( buffer, 20, 1, fh ) == 1 );
TESTCASE( memcmp( buffer, message, 20 ) == 0 );
TESTCASE( buffer[20] == 'x' );
/* Done. */
TESTCASE( fclose( fh ) == 0 );
}
END_TEST
START_TEST( freopen )
{
FILE * fin = NULL;
FILE * fout = NULL;
TESTCASE_REQUIRE( ( fin = fopen( testfile1, "wb+" ) ) != NULL );
TESTCASE( fputc( 'x', fin ) == 'x' );
TESTCASE( fclose( fin ) == 0 );
TESTCASE( ( fin = freopen( testfile1, "rb", stdin ) ) != NULL );
TESTCASE( getchar() == 'x' );
TESTCASE( ( fout = freopen( testfile2, "wb+", stdout ) ) != NULL );
TESTCASE( putchar( 'x' ) == 'x' );
rewind( fout );
TESTCASE( fgetc( fout ) == 'x' );
TESTCASE( fclose( fin ) == 0 );
TESTCASE( fclose( fout ) == 0 );
TESTCASE( remove( testfile1 ) == 0 );
TESTCASE( remove( testfile2 ) == 0 );
}
END_TEST
START_TEST( fseek )
{
FILE * fh = NULL;
TESTCASE( ( fh = tmpfile() ) != NULL );
TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );
/* General functionality */
TESTCASE( fseek( fh, -1, SEEK_END ) == 0 );
TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) - 1 );
TESTCASE( fseek( fh, 0, SEEK_END ) == 0 );
TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
TESTCASE( fseek( fh, 0, SEEK_SET ) == 0 );
TESTCASE( ftell( fh ) == 0 );
TESTCASE( fseek( fh, 5, SEEK_CUR ) == 0 );
TESTCASE( ftell( fh ) == 5 );
TESTCASE( fseek( fh, -3, SEEK_CUR ) == 0 );
TESTCASE( ftell( fh ) == 2 );
/* Checking behaviour around EOF */
TESTCASE( fseek( fh, 0, SEEK_END ) == 0 );
TESTCASE( ! feof( fh ) );
TESTCASE( fgetc( fh ) == EOF );
TESTCASE( feof( fh ) );
TESTCASE( fseek( fh, 0, SEEK_END ) == 0 );
TESTCASE( ! feof( fh ) );
/* Checking undo of ungetc() */
TESTCASE( fseek( fh, 0, SEEK_SET ) == 0 );
TESTCASE( fgetc( fh ) == teststring[0] );
TESTCASE( fgetc( fh ) == teststring[1] );
TESTCASE( fgetc( fh ) == teststring[2] );
TESTCASE( ftell( fh ) == 3 );
TESTCASE( ungetc( teststring[2], fh ) == teststring[2] );
TESTCASE( ftell( fh ) == 2 );
TESTCASE( fgetc( fh ) == teststring[2] );
TESTCASE( ftell( fh ) == 3 );
TESTCASE( ungetc( 'x', fh ) == 'x' );
TESTCASE( ftell( fh ) == 2 );
TESTCASE( fgetc( fh ) == 'x' );
TESTCASE( ungetc( 'x', fh ) == 'x' );
TESTCASE( ftell( fh ) == 2 );
TESTCASE( fseek( fh, 2, SEEK_SET ) == 0 );
TESTCASE( fgetc( fh ) == teststring[2] );
/* Checking error handling */
TESTCASE( fseek( fh, -5, SEEK_SET ) == -1 );
TESTCASE( fseek( fh, 0, SEEK_END ) == 0 );
TESTCASE( fclose( fh ) == 0 );
}
END_TEST
START_TEST( ftell )
{
/* Testing all the basic I/O functions individually would result in lots
of duplicated code, so I took the liberty of lumping it all together
here.
*/
/* The following functions delegate their tests to here:
fgetc fflush rewind fputc ungetc fseek
flushbuffer seek fillbuffer prepread prepwrite
*/
char * buffer = (char*)malloc( 4 );
FILE * fh = NULL;
TESTCASE_REQUIRE( ( fh = tmpfile() ) != NULL );
TESTCASE( setvbuf( fh, buffer, _IOLBF, 4 ) == 0 );
/* Testing ungetc() at offset 0 */
rewind( fh );
TESTCASE( ungetc( 'x', fh ) == 'x' );
TESTCASE( ftell( fh ) == -1l );
rewind( fh );
TESTCASE( ftell( fh ) == 0l );
/* Commence "normal" tests */
TESTCASE( fputc( '1', fh ) == '1' );
TESTCASE( fputc( '2', fh ) == '2' );
TESTCASE( fputc( '3', fh ) == '3' );
/* Positions incrementing as expected? */
TESTCASE( ftell( fh ) == 3l );
TESTCASE( fh->pos.offset == 0l );
TESTCASE( fh->bufidx == 3l );
/* Buffer properly flushed when full? */
TESTCASE( fputc( '4', fh ) == '4' );
TESTCASE( fh->pos.offset == 4l );
TESTCASE( fh->bufidx == 0 );
/* fflush() resetting positions as expected? */
TESTCASE( fputc( '5', fh ) == '5' );
TESTCASE( fflush( fh ) == 0 );
TESTCASE( ftell( fh ) == 5l );
TESTCASE( fh->pos.offset == 5l );
TESTCASE( fh->bufidx == 0l );
/* rewind() resetting positions as expected? */
rewind( fh );
TESTCASE( ftell( fh ) == 0l );
TESTCASE( fh->pos.offset == 0 );
TESTCASE( fh->bufidx == 0 );
/* Reading back first character after rewind for basic read check */
TESTCASE( fgetc( fh ) == '1' );
/* TODO: t.b.c. */
TESTCASE( fclose( fh ) == 0 );
}
END_TEST
START_TEST( perror )
{
FILE * fh = NULL;
unsigned long long max = ULLONG_MAX;
char buffer[100];
sprintf( buffer, "%llu", max );
TESTCASE_REQUIRE( ( fh = freopen( testfile, "wb+", j6libc_stderr ) ) != NULL );
TESTCASE( strtol( buffer, NULL, 10 ) == LONG_MAX );
perror( "Test" );
rewind( fh );
TESTCASE( fread( buffer, 1, 7, fh ) == 7 );
TESTCASE( memcmp( buffer, "Test: ", 6 ) == 0 );
TESTCASE( fclose( fh ) == 0 );
TESTCASE( remove( testfile ) == 0 );
}
END_TEST
START_TEST( puts )
{
FILE * fh = NULL;
const char * message = "SUCCESS testing puts()";
char buffer[23];
buffer[22] = 'x';
TESTCASE_REQUIRE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
TESTCASE( puts( message ) >= 0 );
rewind( fh );
TESTCASE( fread( buffer, 1, 22, fh ) == 22 );
TESTCASE( memcmp( buffer, message, 22 ) == 0 );
TESTCASE( buffer[22] == 'x' );
TESTCASE( fclose( fh ) == 0 );
TESTCASE( remove( testfile ) == 0 );
}
END_TEST
START_TEST( rename )
{
FILE * file = NULL;
remove( testfile1 );
remove( testfile2 );
/* make sure that neither file exists */
TESTCASE( fopen( testfile1, "r" ) == NULL );
TESTCASE( fopen( testfile2, "r" ) == NULL );
/* rename file 1 to file 2 - expected to fail */
TESTCASE( rename( testfile1, testfile2 ) == -1 );
/* create file 1 */
TESTCASE_REQUIRE( ( file = fopen( testfile1, "w" ) ) != NULL );
TESTCASE( fputs( "x", file ) != EOF );
TESTCASE( fclose( file ) == 0 );
/* check that file 1 exists */
TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL );
TESTCASE( fclose( file ) == 0 );
/* rename file 1 to file 2 */
TESTCASE( rename( testfile1, testfile2 ) == 0 );
/* check that file 2 exists, file 1 does not */
TESTCASE( fopen( testfile1, "r" ) == NULL );
TESTCASE( ( file = fopen( testfile2, "r" ) ) != NULL );
TESTCASE( fclose( file ) == 0 );
/* create another file 1 */
TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL );
TESTCASE( fputs( "x", file ) != EOF );
TESTCASE( fclose( file ) == 0 );
/* check that file 1 exists */
TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL );
TESTCASE( fclose( file ) == 0 );
/* rename file 1 to file 2 - expected to fail, see comment in
_PDCLIB_rename() itself.
*/
/* NOREG as glibc overwrites existing destination file. */
TESTCASE( rename( testfile1, testfile2 ) == -1 );
/* remove both files */
TESTCASE( remove( testfile1 ) == 0 );
TESTCASE( remove( testfile2 ) == 0 );
/* check that they're gone */
TESTCASE( fopen( testfile1, "r" ) == NULL );
TESTCASE( fopen( testfile2, "r" ) == NULL );
}
END_TEST
START_TEST( setbuf )
{
/* TODO: Extend testing once setvbuf() is finished. */
char buffer[ BUFSIZ + 1 ];
FILE * fh = NULL;
/* full buffered */
TESTCASE_REQUIRE( ( fh = tmpfile() ) != NULL );
setbuf( fh, buffer );
TESTCASE( fh->buffer == buffer );
TESTCASE( fh->bufsize == BUFSIZ );
TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF );
TESTCASE( fclose( fh ) == 0 );
/* not buffered */
TESTCASE( ( fh = tmpfile() ) != NULL );
setbuf( fh, NULL );
TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF );
TESTCASE( fclose( fh ) == 0 );
}
END_TEST
START_TEST( setvbuf )
{
#define BUFFERSIZE 500
char buffer[ BUFFERSIZE ];
FILE * fh = NULL;
/* full buffered, user-supplied buffer */
TESTCASE_REQUIRE( ( fh = tmpfile() ) != NULL );
TESTCASE( setvbuf( fh, buffer, _IOFBF, BUFFERSIZE ) == 0 );
TESTCASE( fh->buffer == buffer );
TESTCASE( fh->bufsize == BUFFERSIZE );
TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF );
TESTCASE( fclose( fh ) == 0 );
/* line buffered, lib-supplied buffer */
TESTCASE( ( fh = tmpfile() ) != NULL );
TESTCASE( setvbuf( fh, NULL, _IOLBF, BUFFERSIZE ) == 0 );
TESTCASE( fh->buffer != NULL );
TESTCASE( fh->bufsize == BUFFERSIZE );
TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOLBF );
TESTCASE( fclose( fh ) == 0 );
/* not buffered, user-supplied buffer */
TESTCASE( ( fh = tmpfile() ) != NULL );
TESTCASE( setvbuf( fh, buffer, _IONBF, BUFFERSIZE ) == 0 );
TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF );
TESTCASE( fclose( fh ) == 0 );
#undef BUFFERSIZE
}
END_TEST
START_TEST( tmpnam )
{
TESTCASE( strlen( tmpnam( NULL ) ) < L_tmpnam );
}
END_TEST
FILE * test_vfprintf_stream = NULL;
static int test_vfprintf(
const char *implfile,
const char *file,
int line,
size_t expected_rc,
const char *expected_out,
const char *format,
... )
{
size_t i;
va_list arg;
va_start( arg, format );
i = vfprintf( test_vfprintf_stream, format, arg );
va_end( arg );
char result_buffer[100];
rewind(test_vfprintf_stream);
if ( fread( result_buffer, 1, i, test_vfprintf_stream ) != i )
{
fprintf( stderr,
"FAILED: %s (%s), line %d\n"
" GET RESULT FAILURE",
file, implfile, line);
return 1;
}
if (i != expected_rc ||
strcmp(result_buffer, expected_out))
{
fprintf( stderr,
"FAILED: %s (%s), line %d\n"
" format string \"%s\"\n"
" expected %2lu, \"%s\"\n"
" actual %2lu, \"%s\"\n",
file, implfile, line, format, expected_rc,
expected_out, i, result_buffer );
return 1;
}
return 0;
}
START_TEST( vfprintf )
{
TESTCASE_REQUIRE( ( test_vfprintf_stream = tmpfile() ) != NULL );
#define IMPLFILE "stdio/vfprintf.c"
#define DO_TESTPRINTF test_vfprintf
#include "printf_testcases.h"
#undef DO_TESTPRINTF
#undef IMPLFILE
TESTCASE( fclose( test_vfprintf_stream ) == 0 );
}
END_TEST
FILE * test_vfscanf_stream = NULL;
static int test_vfscanf(
const char *implfile,
const char *file,
int line,
size_t expected_rc,
const char *input_string,
const char *format,
... )
{
rewind( test_vfscanf_stream );
fwrite( input_string, 1, strlen(input_string)+1, test_vfscanf_stream );
rewind( test_vfscanf_stream );
va_list ap;
size_t result;
va_start( ap, format );
result = vfscanf( test_vfscanf_stream, format, ap );
va_end( ap );
if (result != expected_rc )
{
fprintf( stderr,
"FAILED: %s (%s), line %d\n"
" format string \"%s\"\n"
" expected %2lu\n"
" actual %2lu\n",
file, implfile, line, format,
expected_rc, result);
return 1;
}
return 0;
}
START_TEST( vfscanf )
{
TESTCASE_REQUIRE( ( test_vfscanf_stream = tmpfile() ) != NULL );
#define IMPLFILE "stdio/vfscanf.c"
#define DO_TESTSCANF test_vfscanf
#include "scanf_testcases.h"
#undef DO_TESTSCANF
#undef IMPLFILE
TESTCASE( fclose( test_vfprintf_stream ) == 0 );
}
END_TEST
static int test_vsnprintf(
const char *implfile,
const char *file,
int line,
size_t expected_rc,
const char *expected_out,
const char *format,
... )
{
char buffer[100];
size_t i;
va_list arg;
va_start( arg, format );
i = vsnprintf( buffer, 100, format, arg );
va_end( arg );
if (i != expected_rc ||
strcmp(buffer, expected_out))
{
fprintf( stderr,
"FAILED: %s (%s), line %d\n"
" format string \"%s\"\n"
" expected %2lu, \"%s\"\n"
" actual %2lu, \"%s\"\n",
file, implfile, line, format, expected_rc,
expected_out, i, buffer );
return 1;
}
return 0;
}
START_TEST( vsnprintf )
{
#define IMPLFILE "stdio/vsnprintf.c"
#define DO_TESTPRINTF test_vsnprintf
#include "printf_testcases.h"
#undef DO_TESTPRINTF
#undef IMPLFILE
}
END_TEST
static int test_vsscanf(
const char *implfile,
const char *file,
int line,
size_t expected_rc,
const char *input_string,
const char *format,
... )
{
va_list ap;
size_t result;
va_start( ap, format );
result = vsscanf( input_string, format, ap );
va_end( ap );
if (result != expected_rc )
{
fprintf( stderr,
"FAILED: %s (%s), line %d\n"
" format string \"%s\"\n"
" expected %2lu\n"
" actual %2lu\n",
file, implfile, line, format,
expected_rc, result);
return 1;
}
return 0;
}
START_TEST( vsscanf )
{
#define IMPLFILE "stdio/vsscanf.c"
#define DO_TESTSCANF test_vsscanf
#include "scanf_testcases.h"
#undef DO_TESTSCANF
#undef IMPLFILE
}
END_TEST
START_SUITE( stdio )
{
/* TODO: File IO not yet implemented
RUN_TEST( clearerr );
RUN_TEST( fclose );
RUN_TEST( fgetpos );
RUN_TEST( fgets );
RUN_TEST( fopen );
RUN_TEST( fputs );
RUN_TEST( fread );
RUN_TEST( freopen );
RUN_TEST( fseek );
RUN_TEST( ftell );
RUN_TEST( perror );
RUN_TEST( puts );
RUN_TEST( rename );
RUN_TEST( setbuf );
RUN_TEST( setvbuf );
RUN_TEST( vfprintf );
RUN_TEST( vfscanf );
*/
RUN_TEST( tmpnam );
RUN_TEST( vsnprintf );
RUN_TEST( vsscanf );
}
END_SUITE

View File

@@ -1,515 +0,0 @@
#include "_PDCLIB_test.h"
#include <assert.h>
static int test_exit() { _Exit(0); return 0; }
START_TEST( _Exit )
{
TESTCASE( test_exit() );
}
END_TEST
static void aborthandler(int s) { _exit(0); }
static int test_abort() { abort(); return 0; }
START_TEST( abort )
{
TESTCASE( signal( SIGABRT, &aborthandler ) != SIG_ERR );
TESTCASE( test_abort() );
}
END_TEST
START_TEST( abs )
{
TESTCASE( abs( 0 ) == 0 );
TESTCASE( abs( INT_MAX ) == INT_MAX );
TESTCASE( abs( INT_MIN + 1 ) == -( INT_MIN + 1 ) );
}
END_TEST
static int flags[ 32 ];
static void counthandler( void )
{
static int count = 0;
flags[ count ] = count;
++count;
}
static void checkhandler( void )
{
for ( int i = 0; i < 31; ++i )
assert( flags[ i ] == i );
}
int test_atexit()
{
if( atexit( &checkhandler ) != 0 )
return 0;
for ( int i = 0; i < 31; ++i )
if( atexit( &counthandler ) != 0 )
return 0;
return 1;
}
START_TEST( atexit )
{
TESTCASE( test_atexit() );
}
END_TEST
static int compare( const void * left, const void * right )
{
return *( (unsigned char *)left ) - *( (unsigned char *)right );
}
START_TEST( bsearch )
{
TESTCASE( bsearch( "e", abcde, 4, 1, compare ) == NULL );
TESTCASE( bsearch( "e", abcde, 5, 1, compare ) == &abcde[4] );
TESTCASE( bsearch( "a", abcde + 1, 4, 1, compare ) == NULL );
TESTCASE( bsearch( "0", abcde, 1, 1, compare ) == NULL );
TESTCASE( bsearch( "a", abcde, 1, 1, compare ) == &abcde[0] );
TESTCASE( bsearch( "a", abcde, 0, 1, compare ) == NULL );
TESTCASE( bsearch( "e", abcde, 3, 2, compare ) == &abcde[4] );
TESTCASE( bsearch( "b", abcde, 3, 2, compare ) == NULL );
}
END_TEST
START_TEST( div )
{
div_t result = div( 5, 2 );
TESTCASE( result.quot == 2 && result.rem == 1 );
result = div( -5, 2 );
TESTCASE( result.quot == -2 && result.rem == -1 );
result = div( 5, -2 );
TESTCASE( result.quot == -2 && result.rem == 1 );
TESTCASE( sizeof( result.quot ) == sizeof( int ) );
TESTCASE( sizeof( result.rem ) == sizeof( int ) );
}
END_TEST
START_TEST( getenv )
{
TESTCASE( strcmp( getenv( "SHELL" ), "/bin/bash" ) == 0 );
}
END_TEST
START_TEST( labs )
{
TESTCASE( labs( 0 ) == 0 );
TESTCASE( labs( LONG_MAX ) == LONG_MAX );
TESTCASE( labs( LONG_MIN + 1 ) == -( LONG_MIN + 1 ) );
}
END_TEST
START_TEST( ldiv )
{
ldiv_t result = ldiv( 5, 2 );
TESTCASE( result.quot == 2 && result.rem == 1 );
result = ldiv( -5, 2 );
TESTCASE( result.quot == -2 && result.rem == -1 );
result = ldiv( 5, -2 );
TESTCASE( result.quot == -2 && result.rem == 1 );
TESTCASE( sizeof( result.quot ) == sizeof( long ) );
TESTCASE( sizeof( result.rem ) == sizeof( long ) );
}
END_TEST
START_TEST( llabs )
{
TESTCASE( llabs( 0ll ) == 0 );
TESTCASE( llabs( LLONG_MAX ) == LLONG_MAX );
TESTCASE( llabs( LLONG_MIN + 1 ) == -( LLONG_MIN + 1 ) );
}
END_TEST
START_TEST( lldiv )
{
lldiv_t result = lldiv( 5ll, 2ll );
TESTCASE( result.quot == 2 && result.rem == 1 );
result = lldiv( -5ll, 2ll );
TESTCASE( result.quot == -2 && result.rem == -1 );
result = lldiv( 5ll, -2ll );
TESTCASE( result.quot == -2 && result.rem == 1 );
TESTCASE( sizeof( result.quot ) == sizeof( long long ) );
TESTCASE( sizeof( result.rem ) == sizeof( long long ) );
}
END_TEST
START_TEST( qsort )
{
char presort[] = { "shreicnyjqpvozxmbt" };
char sorted1[] = { "bcehijmnopqrstvxyz" };
char sorted2[] = { "bticjqnyozpvreshxm" };
char s[19];
strcpy( s, presort );
qsort( s, 18, 1, compare );
TESTCASE( strcmp( s, sorted1 ) == 0 );
strcpy( s, presort );
qsort( s, 9, 2, compare );
TESTCASE( strcmp( s, sorted2 ) == 0 );
strcpy( s, presort );
qsort( s, 1, 1, compare );
TESTCASE( strcmp( s, presort ) == 0 );
qsort( s, 100, 0, compare );
TESTCASE( strcmp( s, presort ) == 0 );
}
END_TEST
START_TEST( rand )
{
int rnd1 = RAND_MAX, rnd2 = RAND_MAX;
TESTCASE( ( rnd1 = rand() ) < RAND_MAX );
TESTCASE( ( rnd2 = rand() ) < RAND_MAX );
srand( 1 );
TESTCASE( rand() == rnd1 );
TESTCASE( rand() == rnd2 );
}
END_TEST
START_TEST( strtol )
{
char * endptr = NULL;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
/* tricky border case */
char tricky[] = "+0xz";
errno = 0;
/* basic functionality */
TESTCASE( strtol( "123", NULL, 10 ) == 123 );
/* proper detecting of default base 10 */
TESTCASE( strtol( "456", NULL, 0 ) == 456 );
/* proper functioning to smaller base */
TESTCASE( strtol( "14", NULL, 8 ) == 12 );
/* proper autodetecting of octal */
TESTCASE( strtol( "016", NULL, 0 ) == 14 );
/* proper autodetecting of hexadecimal, lowercase 'x' */
TESTCASE( strtol( "0xFF", NULL, 0 ) == 255 );
/* proper autodetecting of hexadecimal, uppercase 'X' */
TESTCASE( strtol( "0Xa1", NULL, 0 ) == 161 );
/* proper handling of border case: 0x followed by non-hexdigit */
TESTCASE(
(strtol(tricky, &endptr, 0) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* proper handling of border case: 0 followed by non-octdigit */
TESTCASE(
(strtol(tricky, &endptr, 8) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* overflowing subject sequence must still return proper endptr */
TESTCASE(
(strtol(overflow, &endptr, 36) == LONG_MIN) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* same for positive */
TESTCASE(
(strtol(overflow + 1, &endptr, 36) == LONG_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* testing skipping of leading whitespace */
TESTCASE( strtol( " \n\v\t\f789", NULL, 0 ) == 789 );
/* testing conversion failure */
TESTCASE(
(strtol(overflow, &endptr, 10) == 0) &&
(endptr == overflow) );
TESTCASE(
(strtol(overflow, &endptr, 0) == 0) &&
(endptr == overflow) );
#if __SIZEOF_LONG__ == 4
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtol("2147483647", NULL, 0) == 0x7fffffff) && (errno == 0) );
TESTCASE( (strtol("2147483648", NULL, 0) == LONG_MAX) && (errno == ERANGE) );
TESTCASE( (strtol("-2147483647", NULL, 0) == (long)0x80000001) && (errno == 0) );
TESTCASE( (strtol("-2147483648", NULL, 0) == LONG_MIN) && (errno == 0) );
TESTCASE( (strtol("-2147483649", NULL, 0) == LONG_MIN) && (errno == ERANGE) );
/* TODO: test "odd" overflow, i.e. base is not power of two */
#elif __SIZEOF_LONG__ == 8
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtol("9223372036854775807", NULL, 0) == 0x7fffffffffffffff) && (errno == 0) );
TESTCASE( (strtol("9223372036854775808", NULL, 0) == LONG_MAX) && (errno == ERANGE) );
TESTCASE( (strtol("-9223372036854775807", NULL, 0) == (long)0x8000000000000001) && (errno == 0) );
TESTCASE( (strtol("-9223372036854775808", NULL, 0) == LONG_MIN) && (errno == 0) );
TESTCASE( (strtol("-9223372036854775809", NULL, 0) == LONG_MIN) && (errno == ERANGE) );
/* TODO: test "odd" overflow, i.e. base is not power of two */
#else
#error Unsupported width of 'long' (neither 32 nor 64 bit).
#endif
}
END_TEST
START_TEST( strtoll )
{
char * endptr = NULL;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
/* tricky border case */
char tricky[] = "+0xz";
errno = 0;
/* basic functionality */
TESTCASE( strtoll( "123", NULL, 10 ) == 123 );
/* proper detecting of default base 10 */
TESTCASE( strtoll( "456", NULL, 0 ) == 456 );
/* proper functioning to smaller base */
TESTCASE( strtoll( "14", NULL, 8 ) == 12 );
/* proper autodetecting of octal */
TESTCASE( strtoll( "016", NULL, 0 ) == 14 );
/* proper autodetecting of hexadecimal, lowercase 'x' */
TESTCASE( strtoll( "0xFF", NULL, 0 ) == 255 );
/* proper autodetecting of hexadecimal, uppercase 'X' */
TESTCASE( strtoll( "0Xa1", NULL, 0 ) == 161 );
/* proper handling of border case: 0x followed by non-hexdigit */
TESTCASE(
(strtoll(tricky, &endptr, 0) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* proper handling of border case: 0 followed by non-octdigit */
TESTCASE(
(strtoll(tricky, &endptr, 8) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* overflowing subject sequence must still return proper endptr */
TESTCASE(
(strtoll(overflow, &endptr, 36) == LLONG_MIN) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* same for positive */
TESTCASE(
(strtoll(overflow + 1, &endptr, 36) == LLONG_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* testing skipping of leading whitespace */
TESTCASE( strtoll( " \n\v\t\f789", NULL, 0 ) == 789 );
/* testing conversion failure */
TESTCASE( (strtoll(overflow, &endptr, 10) == 0) && (endptr == overflow) );
TESTCASE( (strtoll(overflow, &endptr, 0) == 0) && (endptr == overflow) );
/* TODO: These tests assume two-complement, but conversion should work */
/* for one-complement and signed magnitude just as well. Anyone having */
/* a platform to test this on? */
#if __SIZEOF_LONG_LONG__ == 8
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoll("9223372036854775807", NULL, 0) == 0x7fffffffffffffff) && (errno == 0) );
TESTCASE( (strtoll("9223372036854775808", NULL, 0) == LLONG_MAX) && (errno == ERANGE) );
TESTCASE( (strtoll("-9223372036854775807", NULL, 0) == (long long)0x8000000000000001) && (errno == 0) );
TESTCASE( (strtoll("-9223372036854775808", NULL, 0) == LLONG_MIN) && (errno == 0) );
TESTCASE( (strtoll("-9223372036854775809", NULL, 0) == LLONG_MIN) && (errno == ERANGE) );
/* TODO: test "odd" overflow, i.e. base is not power of two */
#elif __SIZEOF_LONG_LONG__ == 16
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoll("170141183460469231731687303715884105728", NULL, 0) == 0x7fffffffffffffffffffffffffffffff) && (errno == 0) );
TESTCASE( (strtoll("170141183460469231731687303715884105729", NULL, 0) == LLONG_MAX) && (errno == ERANGE) );
TESTCASE( (strtoll("-170141183460469231731687303715884105728", NULL, 0) == -0x80000000000000000000000000000001) && (errno == 0) );
TESTCASE( (strtoll("-170141183460469231731687303715884105729", NULL, 0) == LLONG_MIN) && (errno == 0) );
TESTCASE( (strtoll("-170141183460469231731687303715884105730", NULL, 0) == LLONG_MIN) && (errno == ERANGE) );
/* TODO: test "odd" overflow, i.e. base is not power of two */
#else
#error Unsupported width of 'long long' (neither 64 nor 128 bit).
#endif
}
END_TEST
START_TEST( strtoul )
{
char * endptr = NULL;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
/* tricky border case */
char tricky[] = "+0xz";
errno = 0;
/* basic functionality */
TESTCASE( strtoul( "123", NULL, 10 ) == 123 );
/* proper detecting of default base 10 */
TESTCASE( strtoul( "456", NULL, 0 ) == 456 );
/* proper functioning to smaller base */
TESTCASE( strtoul( "14", NULL, 8 ) == 12 );
/* proper autodetecting of octal */
TESTCASE( strtoul( "016", NULL, 0 ) == 14 );
/* proper autodetecting of hexadecimal, lowercase 'x' */
TESTCASE( strtoul( "0xFF", NULL, 0 ) == 255 );
/* proper autodetecting of hexadecimal, uppercase 'X' */
TESTCASE( strtoul( "0Xa1", NULL, 0 ) == 161 );
/* proper handling of border case: 0x followed by non-hexdigit */
TESTCASE(
(strtoul(tricky, &endptr, 0) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* proper handling of border case: 0 followed by non-octdigit */
TESTCASE(
(strtoul(tricky, &endptr, 8) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* overflowing subject sequence must still return proper endptr */
TESTCASE(
(strtoul(overflow, &endptr, 36) == ULONG_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* same for positive */
TESTCASE(
(strtoul(overflow + 1, &endptr, 36) == ULONG_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* testing skipping of leading whitespace */
TESTCASE( strtoul( " \n\v\t\f789", NULL, 0 ) == 789 );
/* testing conversion failure */
TESTCASE( (strtoul(overflow, &endptr, 10) == 0) && (endptr == overflow) );
TESTCASE( (strtoul(overflow, &endptr, 0) == 0) && (endptr == overflow) );
/* TODO: These tests assume two-complement, but conversion should work */
/* for one-complement and signed magnitude just as well. Anyone having */
/* a platform to test this on? */
/* long -> 32 bit */
#if __SIZEOF_LONG__ == 4
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoul("4294967295", NULL, 0) == ULONG_MAX) && (errno == 0) );
TESTCASE( (strtoul("4294967296", NULL, 0) == ULONG_MAX) && (errno == ERANGE) );
/* TODO: test "odd" overflow, i.e. base is not power of two */
/* long -> 64 bit */
#elif __SIZEOF_LONG__ == 8
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoul("18446744073709551615", NULL, 0) == ULONG_MAX) && (errno == 0) );
TESTCASE( (strtoul("18446744073709551616", NULL, 0) == ULONG_MAX) && (errno == ERANGE) );
/* TODO: test "odd" overflow, i.e. base is not power of two */
#else
#error Unsupported width of 'long' (neither 32 nor 64 bit).
#endif
}
END_TEST
START_TEST( strtoull )
{
char * endptr = NULL;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
/* tricky border case */
char tricky[] = "+0xz";
errno = 0;
/* basic functionality */
TESTCASE( strtoull( "123", NULL, 10 ) == 123 );
/* proper detecting of default base 10 */
TESTCASE( strtoull( "456", NULL, 0 ) == 456 );
/* proper functioning to smaller base */
TESTCASE( strtoull( "14", NULL, 8 ) == 12 );
/* proper autodetecting of octal */
TESTCASE( strtoull( "016", NULL, 0 ) == 14 );
/* proper autodetecting of hexadecimal, lowercase 'x' */
TESTCASE( strtoull( "0xFF", NULL, 0 ) == 255 );
/* proper autodetecting of hexadecimal, uppercase 'X' */
TESTCASE( strtoull( "0Xa1", NULL, 0 ) == 161 );
/* proper handling of border case: 0x followed by non-hexdigit */
TESTCASE(
(strtoull(tricky, &endptr, 0) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* proper handling of border case: 0 followed by non-octdigit */
TESTCASE(
(strtoull(tricky, &endptr, 8) == 0) &&
(endptr == tricky + 2) &&
(errno == 0) );
/* overflowing subject sequence must still return proper endptr */
TESTCASE(
(strtoull(overflow, &endptr, 36) == ULLONG_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* same for positive */
TESTCASE(
(strtoull(overflow + 1, &endptr, 36) == ULLONG_MAX) &&
(errno == ERANGE) &&
((endptr - overflow) == 53) );
/* testing skipping of leading whitespace */
TESTCASE( strtoull( " \n\v\t\f789", NULL, 0 ) == 789 );
/* testing conversion failure */
TESTCASE( (strtoull(overflow, &endptr, 10) == 0) && (endptr == overflow) );
TESTCASE( (strtoull(overflow, &endptr, 0) == 0) && (endptr == overflow) );
/* long long -> 64 bit */
#if __SIZEOF_LONG_LONG__ == 8
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoull("18446744073709551615", NULL, 0) == ULLONG_MAX) && (errno == 0) );
TESTCASE( (strtoull("18446744073709551616", NULL, 0) == ULLONG_MAX) && (errno == ERANGE) );
/* TODO: test "odd" overflow, i.e. base is not power of two */
/* long long -> 128 bit */
#elif __SIZEOF_LONG_LONG__ == 16
/* testing "even" overflow, i.e. base is power of two */
TESTCASE( (strtoull("340282366920938463463374607431768211455", NULL, 0) == ULLONG_MAX) && (errno == 0) );
TESTCASE( (strtoull("340282366920938463463374607431768211456", NULL, 0) == ULLONG_MAX) && (errno == ERANGE) );
/* TODO: test "odd" overflow, i.e. base is not power of two */
#else
#error Unsupported width of 'long long' (neither 64 nor 128 bit).
#endif
}
END_TEST
#define SYSTEM_MESSAGE "SUCCESS testing system()"
#define SYSTEM_COMMAND "echo '" SYSTEM_MESSAGE "'"
START_TEST( system )
{
FILE * fh;
char buffer[25];
buffer[24] = 'x';
TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
TESTCASE( system( SYSTEM_COMMAND ) );
rewind( fh );
TESTCASE( fread( buffer, 1, 24, fh ) == 24 );
TESTCASE( memcmp( buffer, SYSTEM_MESSAGE, 24 ) == 0 );
TESTCASE( buffer[24] == 'x' );
TESTCASE( fclose( fh ) == 0 );
TESTCASE( remove( testfile ) == 0 );
}
END_TEST
START_SUITE( stdlib )
{
RUN_TEST( _Exit );
RUN_TEST( abort );
RUN_TEST( abs );
RUN_TEST( atexit );
RUN_TEST( bsearch );
RUN_TEST( div );
RUN_TEST( getenv );
RUN_TEST( labs );
RUN_TEST( ldiv );
RUN_TEST( llabs );
RUN_TEST( lldiv );
RUN_TEST( qsort );
RUN_TEST( strtol );
RUN_TEST( strtoll );
RUN_TEST( strtoul );
RUN_TEST( strtoull );
RUN_TEST( system );
}
END_SUITE

View File

@@ -1,386 +0,0 @@
#include "_PDCLIB_test.h"
START_TEST( memchr )
{
TESTCASE( memchr( abcde, 'c', 5 ) == &abcde[2] );
TESTCASE( memchr( abcde, 'a', 1 ) == &abcde[0] );
TESTCASE( memchr( abcde, 'a', 0 ) == NULL );
TESTCASE( memchr( abcde, '\0', 5 ) == NULL );
TESTCASE( memchr( abcde, '\0', 6 ) == &abcde[5] );
}
END_TEST
START_TEST( memcmp )
{
const char xxxxx[] = "xxxxx";
TESTCASE( memcmp( abcde, abcdx, 5 ) < 0 );
TESTCASE( memcmp( abcde, abcdx, 4 ) == 0 );
TESTCASE( memcmp( abcde, xxxxx, 0 ) == 0 );
TESTCASE( memcmp( xxxxx, abcde, 1 ) > 0 );
}
END_TEST
START_TEST( memcpy )
{
char s[] = "xxxxxxxxxxx";
char *r = memcpy(s, abcde, 6);
TESTCASE( r == s );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
r = memcpy(s + 5, abcde, 5);
TESTCASE( r == s + 5 );
TESTCASE( s[9] == 'e' );
TESTCASE( s[10] == 'x' );
}
END_TEST
START_TEST( memmove )
{
char s[] = "xxxxabcde";
char *r = memmove(s, s + 4, 5);
TESTCASE( r == s );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == 'b' );
r = memmove(s + 4, s, 5);
TESTCASE( r == s + 4 );
TESTCASE( s[4] == 'a' );
}
END_TEST
START_TEST( memset )
{
char s[] = "xxxxxxxxx";
void *r = memset(s, 'o', 10);
TESTCASE( r == s );
TESTCASE( s[9] == 'o' );
r = memset(s, '_', 0);
TESTCASE( r == s );
TESTCASE( s[0] == 'o' );
r = memset(s, '_', 1);
TESTCASE( r == s );
TESTCASE( s[0] == '_' );
TESTCASE( s[1] == 'o' );
}
END_TEST
START_TEST( strcat )
{
char s[] = "xx\0xxxxxx";
char *r = strcat(s, abcde);
TESTCASE( r == s );
TESTCASE( s[2] == 'a' );
TESTCASE( s[6] == 'e' );
TESTCASE( s[7] == '\0' );
TESTCASE( s[8] == 'x' );
s[0] = '\0';
r = strcat(s, abcdx);
TESTCASE( r == s );
TESTCASE( s[4] == 'x' );
TESTCASE( s[5] == '\0' );
r = strcat(s, "\0");
TESTCASE( r == s );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
}
END_TEST
START_TEST( strchr )
{
char abccd[] = "abccd";
TESTCASE( strchr( abccd, 'x' ) == NULL );
TESTCASE( strchr( abccd, 'a' ) == &abccd[0] );
TESTCASE( strchr( abccd, 'd' ) == &abccd[4] );
TESTCASE( strchr( abccd, '\0' ) == &abccd[5] );
TESTCASE( strchr( abccd, 'c' ) == &abccd[2] );
}
END_TEST
START_TEST( strcmp )
{
char cmpabcde[] = "abcde";
char cmpabcd_[] = "abcd\xfc";
char empty[] = "";
TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
TESTCASE( strcmp( abcde, abcdx ) < 0 );
TESTCASE( strcmp( abcdx, abcde ) > 0 );
TESTCASE( strcmp( empty, abcde ) < 0 );
TESTCASE( strcmp( abcde, empty ) > 0 );
TESTCASE( strcmp( abcde, cmpabcd_ ) < 0 );
}
END_TEST
START_TEST( strcoll )
{
char cmpabcde[] = "abcde";
char empty[] = "";
TESTCASE( strcoll( abcde, cmpabcde ) == 0 );
TESTCASE( strcoll( abcde, abcdx ) < 0 );
TESTCASE( strcoll( abcdx, abcde ) > 0 );
TESTCASE( strcoll( empty, abcde ) < 0 );
TESTCASE( strcoll( abcde, empty ) > 0 );
}
END_TEST
START_TEST( strcpy )
{
char s[] = "xxxxx";
char *r = strcpy(s, "");
TESTCASE( r == s );
TESTCASE( s[0] == '\0' );
TESTCASE( s[1] == 'x' );
r = strcpy(s, abcde);
TESTCASE( r == s );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
}
END_TEST
START_TEST( strcspn )
{
TESTCASE( strcspn( abcde, "x" ) == 5 );
TESTCASE( strcspn( abcde, "xyz" ) == 5 );
TESTCASE( strcspn( abcde, "zyx" ) == 5 );
TESTCASE( strcspn( abcdx, "x" ) == 4 );
TESTCASE( strcspn( abcdx, "xyz" ) == 4 );
TESTCASE( strcspn( abcdx, "zyx" ) == 4 );
TESTCASE( strcspn( abcde, "a" ) == 0 );
TESTCASE( strcspn( abcde, "abc" ) == 0 );
TESTCASE( strcspn( abcde, "cba" ) == 0 );
}
END_TEST
START_TEST( strerror )
{
TESTCASE( strerror(ERANGE) != strerror(EDOM) );
}
END_TEST
START_TEST( strlen )
{
TESTCASE( strlen( abcde ) == 5 );
TESTCASE( strlen( "" ) == 0 );
}
END_TEST
START_TEST( strncat )
{
char s[] = "xx\0xxxxxx";
char *r = strncat(s, abcde, 10);
TESTCASE( r == s );
TESTCASE( s[2] == 'a' );
TESTCASE( s[6] == 'e' );
TESTCASE( s[7] == '\0' );
TESTCASE( s[8] == 'x' );
s[0] = '\0';
r = strncat(s, abcdx, 10);
TESTCASE( r == s );
TESTCASE( s[4] == 'x' );
TESTCASE( s[5] == '\0' );
r = strncat(s, "\0", 10);
TESTCASE( r == s );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
r = strncat(s, abcde, 0);
TESTCASE( r == s );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'e' );
r = strncat(s, abcde, 3);
TESTCASE( r == s );
TESTCASE( s[5] == 'a' );
TESTCASE( s[7] == 'c' );
TESTCASE( s[8] == '\0' );
}
END_TEST
START_TEST( strncmp )
{
char cmpabcde[] = "abcde\0f";
char cmpabcd_[] = "abcde\xfc";
char empty[] = "";
char x[] = "x";
TESTCASE( strncmp( abcde, cmpabcde, 5 ) == 0 );
TESTCASE( strncmp( abcde, cmpabcde, 10 ) == 0 );
TESTCASE( strncmp( abcde, abcdx, 5 ) < 0 );
TESTCASE( strncmp( abcdx, abcde, 5 ) > 0 );
TESTCASE( strncmp( empty, abcde, 5 ) < 0 );
TESTCASE( strncmp( abcde, empty, 5 ) > 0 );
TESTCASE( strncmp( abcde, abcdx, 4 ) == 0 );
TESTCASE( strncmp( abcde, x, 0 ) == 0 );
TESTCASE( strncmp( abcde, x, 1 ) < 0 );
TESTCASE( strncmp( abcde, cmpabcd_, 10 ) < 0 );
}
END_TEST
START_TEST( strncpy )
{
char s[] = "xxxxxxx";
char *r = strncpy(s, "", 1);
TESTCASE( r == s );
TESTCASE( s[0] == '\0' );
TESTCASE( s[1] == 'x' );
r = strncpy(s, abcde, 6);
TESTCASE( r == s );
TESTCASE( s[0] == 'a' );
TESTCASE( s[4] == 'e' );
TESTCASE( s[5] == '\0' );
TESTCASE( s[6] == 'x' );
r = strncpy(s, abcde, 7);
TESTCASE( r == s );
TESTCASE( s[6] == '\0' );
r = strncpy(s, "xxxx", 3);
TESTCASE( r == s );
TESTCASE( s[0] == 'x' );
TESTCASE( s[2] == 'x' );
TESTCASE( s[3] == 'd' );
}
END_TEST
START_TEST( strpbrk )
{
TESTCASE( strpbrk( abcde, "x" ) == NULL );
TESTCASE( strpbrk( abcde, "xyz" ) == NULL );
TESTCASE( strpbrk( abcdx, "x" ) == &abcdx[4] );
TESTCASE( strpbrk( abcdx, "xyz" ) == &abcdx[4] );
TESTCASE( strpbrk( abcdx, "zyx" ) == &abcdx[4] );
TESTCASE( strpbrk( abcde, "a" ) == &abcde[0] );
TESTCASE( strpbrk( abcde, "abc" ) == &abcde[0] );
TESTCASE( strpbrk( abcde, "cba" ) == &abcde[0] );
}
END_TEST
START_TEST( strrchr )
{
char abccd[] = "abccd";
TESTCASE( strrchr( abcde, '\0' ) == &abcde[5] );
TESTCASE( strrchr( abcde, 'e' ) == &abcde[4] );
TESTCASE( strrchr( abcde, 'a' ) == &abcde[0] );
TESTCASE( strrchr( abccd, 'c' ) == &abccd[3] );
}
END_TEST
START_TEST( strspn )
{
TESTCASE( strspn( abcde, "abc" ) == 3 );
TESTCASE( strspn( abcde, "b" ) == 0 );
TESTCASE( strspn( abcde, abcde ) == 5 );
}
END_TEST
START_TEST( strstr )
{
char s[] = "abcabcabcdabcde";
TESTCASE( strstr( s, "x" ) == NULL );
TESTCASE( strstr( s, "xyz" ) == NULL );
TESTCASE( strstr( s, "a" ) == &s[0] );
TESTCASE( strstr( s, "abc" ) == &s[0] );
TESTCASE( strstr( s, "abcd" ) == &s[6] );
TESTCASE( strstr( s, "abcde" ) == &s[10] );
}
END_TEST
START_TEST( strtok )
{
char s[] = "_a_bc__d_";
char *r = strtok(s, "_");
TESTCASE( r == &s[1] );
TESTCASE( s[1] == 'a' );
TESTCASE( s[2] == '\0' );
r = strtok(NULL, "_");
TESTCASE( r == &s[3] );
TESTCASE( s[3] == 'b' );
TESTCASE( s[4] == 'c' );
TESTCASE( s[5] == '\0' );
r = strtok(NULL, "_");
TESTCASE( r == &s[7] );
TESTCASE( s[6] == '_' );
TESTCASE( s[7] == 'd' );
TESTCASE( s[8] == '\0' );
r = strtok(NULL, "_");
TESTCASE( r == NULL );
strcpy( s, "ab_cd" );
r = strtok(s, "_");
TESTCASE( r == &s[0] );
TESTCASE( s[0] == 'a' );
TESTCASE( s[1] == 'b' );
TESTCASE( s[2] == '\0' );
r = strtok(NULL, "_");
TESTCASE( r == &s[3] );
TESTCASE( s[3] == 'c' );
TESTCASE( s[4] == 'd' );
TESTCASE( s[5] == '\0' );
r = strtok(NULL, "_");
TESTCASE( r == NULL );
}
END_TEST
START_TEST( strxfrm )
{
char s[] = "xxxxxxxxxxx";
size_t r = strxfrm(NULL, "123456789012", 0);
TESTCASE( r == 12 );
r = strxfrm(s, "123456789012", 12);
TESTCASE( r == 12 );
/*
The following test case is true in *this* implementation, but doesn't have to.
TESTCASE( s[0] == 'x' );
*/
r = strxfrm(s, "1234567890", 11);
TESTCASE( r == 10 );
TESTCASE( s[0] == '1' );
TESTCASE( s[9] == '0' );
TESTCASE( s[10] == '\0' );
}
END_TEST
START_SUITE( string )
{
RUN_TEST( memchr );
RUN_TEST( memcmp );
RUN_TEST( memcpy );
RUN_TEST( memmove );
RUN_TEST( memset );
RUN_TEST( strcat );
RUN_TEST( strchr );
RUN_TEST( strcmp );
RUN_TEST( strcoll );
RUN_TEST( strcpy );
RUN_TEST( strcspn );
RUN_TEST( strerror );
RUN_TEST( strlen );
RUN_TEST( strncat );
RUN_TEST( strncmp );
RUN_TEST( strncpy );
RUN_TEST( strpbrk );
RUN_TEST( strrchr );
RUN_TEST( strspn );
RUN_TEST( strstr );
RUN_TEST( strtok );
RUN_TEST( strxfrm );
}
END_SUITE

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,24 @@
module("util",
kind = "lib",
includes = [ "include" ],
sources = [
"bip_buffer.cpp",
"spinlock.cpp",
],
public_headers = [
"util/basic_types.h",
"util/bip_buffer.h",
"util/constexpr_hash.h",
"util/counted.h",
"util/deque.h",
"util/enum_bitfields.h",
"util/hash.h",
"util/linked_list.h",
"util/map.h",
"util/misc.h",
"util/no_construct.h",
"util/pointers.h",
"util/spinlock.h",
"util/util.h",
"util/vector.h",
])