@echo
test: functions/$(FILE)
- echo $(TSTDEPFILES)
functions/$(FILE)
tests: testdrivers
errno = 0;
/* uintmax_t -> long long -> 64 bit */
#if UINTMAX_MAX >> 63 == 1
- /* testing "even" overflow, i.e. base is power of two */
+ /* testing "odd" overflow, i.e. base is not power of two */
TESTCASE( strtoumax( "18446744073709551615", NULL, 0 ) == UINTMAX_MAX );
TESTCASE( errno == 0 );
TESTCASE( strtoumax( "18446744073709551616", NULL, 0 ) == UINTMAX_MAX );
TESTCASE( errno == ERANGE );
- /* TODO: test "odd" overflow, i.e. base is not power of two */
+ /* testing "even" overflow, i.e. base is power of two */
+ errno = 0;
+ TESTCASE( strtoumax( "0xFFFFFFFFFFFFFFFF", NULL, 0 ) == UINTMAX_MAX );
+ TESTCASE( errno == 0 );
+ TESTCASE( strtoumax( "0x10000000000000000", NULL, 0 ) == UINTMAX_MAX );
+ TESTCASE( errno == ERANGE );
/* uintmax_t -> long long -> 128 bit */
#elif UINTMAX_MAX >> 127 == 1
- /* testing "even" overflow, i.e. base is power of two */
+ /* testing "odd" overflow, i.e. base is not power of two */
TESTCASE( strtoumax( "340282366920938463463374607431768211455", NULL, 0 ) == UINTMAX_MAX );
TESTCASE( errno == 0 );
TESTCASE( strtoumax( "340282366920938463463374607431768211456", NULL, 0 ) == UINTMAX_MAX );
TESTCASE( errno == ERANGE );
- /* TODO: test "odd" overflow, i.e. base is not power of two */
+ /* testing "even" everflow, i.e. base is power of two */
+ errno = 0;
+ TESTCASE( strtoumax( "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NULL, 0 ) == UINTMAX_MAX );
+ TESTCASE( errno == 0 );
+ TESTCASE( strtoumax( "0x100000000000000000000000000000000", NULL, 0 ) == UINTMAX_MAX );
+ TESTCASE( errno == ERANGE );
#else
#error Unsupported width of 'uintmax_t' (neither 64 nor 128 bit).
#endif
int main( void )
{
FILE * fh;
+ char const * message = "Testing fwrite()...\n";
+ char buffer[21];
+ buffer[20] = 'x';
TESTCASE( ( fh = tmpfile() ) != NULL );
- TESTCASE( fwrite( "SUCCESS testing fwrite()\n", 1, 25, fh ) == 25 );
- /* TODO: Add readback test. */
+ /* 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 );
return TEST_RESULTS;
}
FILE * fh;
TESTCASE( ( 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' );
int main( void )
{
- FILE * fh;
- TESTCASE( ( fh = tmpfile() ) != NULL );
- TESTCASE( fwrite( "SUCCESS testing fwrite()\n", 1, 25, fh ) == 25 );
- /* TODO: Add readback test. */
- TESTCASE( fclose( fh ) == 0 );
+ /* Testing covered by fread(). */
return TEST_RESULTS;
}
we don't want to e.g. flush the stream for every character of a
stream being printed.
*/
- /* TODO: Check this */
break;
case _IOFBF:
case _IOLBF:
{
++status.i;
}
- if ( ! feof( stream ) ) /* TODO: Check EOF status directly */
+ if ( ! feof( stream ) )
{
ungetc( c, stream );
}
else
{
/* Non-whitespace char in format string: Match verbatim */
- if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) ) /* TODO: Check EOF status directly */
+ if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) )
{
/* Matching error */
- if ( ! feof( stream ) && ! ferror( stream ) ) /* TODO: Check EOF status directly */
+ if ( ! feof( stream ) && ! ferror( stream ) )
{
ungetc( c, stream );
}
message = "Termination request (SIGTERM)";
break;
default:
- /* TODO: Implement. */
- break;
+ fprintf( stderr, "Unknown signal #%d\n", sig );
+ _Exit( EXIT_FAILURE );
}
if ( sighandler == SIG_DFL )
{
#ifndef REGTEST
+#include <stdio.h>
#include <stdlib.h>
extern void (*_PDCLIB_sigabrt)( int );
int raise( int sig )
{
void (*sighandler)( int );
+ char const * message;
switch ( sig )
{
case SIGABRT:
sighandler = _PDCLIB_sigabrt;
+ message = "Abnormal termination (SIGABRT)";
break;
case SIGFPE:
sighandler = _PDCLIB_sigfpe;
+ message = "Arithmetic exception (SIGFPE)";
break;
case SIGILL:
sighandler = _PDCLIB_sigill;
+ message = "Illegal instruction (SIGILL)";
break;
case SIGINT:
sighandler = _PDCLIB_sigint;
+ message = "Interactive attention signal (SIGINT)";
break;
case SIGSEGV:
sighandler = _PDCLIB_sigsegv;
+ message = "Invalid memory access (SIGSEGV)";
break;
case SIGTERM:
sighandler = _PDCLIB_sigterm;
+ message = "Termination request (SIGTERM)";
break;
default:
- /* TODO: Implement. */
- break;
+ fprintf( stderr, "Unknown signal #%d\n", sig );
+ _Exit( EXIT_FAILURE );
}
if ( sighandler == SIG_DFL )
{
+ fputs( message, stderr );
_Exit( EXIT_FAILURE );
}
else if ( sighandler != SIG_IGN )
#ifdef TEST
#include <_PDCLIB_test.h>
+#include <stdlib.h>
+
+static volatile sig_atomic_t flag = 0;
+
+static int expected_signal = 0;
+
+static void test_handler( int sig )
+{
+ TESTCASE( sig == expected_signal );
+ flag = 1;
+}
+
int main( void )
{
- TESTCASE( NO_TESTDRIVER );
+ /* 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 );
+ /* 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 );
+ /* 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 );
return TEST_RESULTS;
}
#endif