]> pd.if.org Git - pdclib/commitdiff
Cleaning up TODOs.
authorsolar <unknown>
Thu, 16 Dec 2010 06:00:24 +0000 (06:00 +0000)
committersolar <unknown>
Thu, 16 Dec 2010 06:00:24 +0000 (06:00 +0000)
Makefile
functions/inttypes/strtoumax.c
functions/stdio/fread.c
functions/stdio/ftell.c
functions/stdio/fwrite.c
functions/stdio/setvbuf.c
functions/stdio/vfscanf.c
platform/example/functions/signal/raise.c
platform/example_cygwin/functions/signal/raise.c

index 453172589bc48676bf7404560aa3467063f8f633..2993c25d72757d8cbf66c782ab13732a4472d06f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,6 @@ pdclib.a: $(OBJFILES)
        @echo
 
 test: functions/$(FILE)
-       echo $(TSTDEPFILES)
        functions/$(FILE)
 
 tests: testdrivers
index 9c9833eda92bd367d462f734e1fde975abf0c9b8..c54cfce481ff087c0e234df85a121b37daab6f1e 100644 (file)
@@ -78,20 +78,30 @@ int main( void )
     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
index 52abb73478e05ea19597afb229695e3631164393..9f7d3fa0e9135f57166e656469c6e09f2100dbe2 100644 (file)
@@ -49,9 +49,33 @@ size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PD
 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;
 }
index 29c360a2fd55d82f1d8569c67c6c3332e5f7fef2..27e25ee9e7f209ff247ff5a03417ef538538da5d 100644 (file)
@@ -62,6 +62,13 @@ int main( void )
     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' );
index 8b40551d6598d2ee780f07535d814f798b2c64be..0ea1b02e75fcef534a2ecc132984c2f1ed3a5f7e 100644 (file)
@@ -87,11 +87,7 @@ size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, str
 
 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;
 }
 
index ecb0be5e20f7a4063100f2ac8456e747f92f2dbd..e3f9278aed159a316ab9e3da1883ff52ee12767e 100644 (file)
@@ -21,7 +21,6 @@ int setvbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_res
                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:
index fbf5356d78673667b741fca010ea4af5cfc9adbe..b9a6896ed7a54381b9e95a692486a3e881db0304 100644 (file)
@@ -42,7 +42,7 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma
                 {
                     ++status.i;
                 }
-                if ( ! feof( stream ) ) /* TODO: Check EOF status directly */
+                if ( ! feof( stream ) )
                 {
                     ungetc( c, stream );
                 }
@@ -50,10 +50,10 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma
             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 );
                     }
index 307c87631aac3612cc07e2427ce6b51ff907c78c..8d7080b143e5b2e476e53c0cb0cf2605df49fd76 100644 (file)
@@ -51,8 +51,8 @@ int raise( int sig )
             message = "Termination request (SIGTERM)";
             break;
         default:
-            /* TODO: Implement. */
-            break;
+            fprintf( stderr, "Unknown signal #%d\n", sig );
+            _Exit( EXIT_FAILURE );
     }
     if ( sighandler == SIG_DFL )
     {
index b16249c2ee75c0dc1941b9944a8ef7bbe0f17f38..8d7080b143e5b2e476e53c0cb0cf2605df49fd76 100644 (file)
@@ -10,6 +10,7 @@
 
 #ifndef REGTEST
 
+#include <stdio.h>
 #include <stdlib.h>
 
 extern void (*_PDCLIB_sigabrt)( int );
@@ -22,32 +23,40 @@ extern void (*_PDCLIB_sigterm)( 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 )
@@ -63,9 +72,43 @@ int raise( int sig )
 #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