]> pd.if.org Git - pdclib/commitdiff
Some testcases for scanf(). Fixed bug with %*... . Fixed artifact in Makefile.
authorsolar <unknown>
Mon, 20 Dec 2010 05:17:35 +0000 (05:17 +0000)
committersolar <unknown>
Mon, 20 Dec 2010 05:17:35 +0000 (05:17 +0000)
Makefile
functions/_PDCLIB/scan.c
testing/scanf_testcases.h

index 2993c25d72757d8cbf66c782ab13732a4472d06f..2d1fa6dedd5b1de1fde02367e9d2f94d18033c54 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 # $Id$
 
 # This is where you chose which platform to compile for (see 'make links' / './platform')
 # $Id$
 
 # This is where you chose which platform to compile for (see 'make links' / './platform')
-PLATFORM := example_cygwin
+PLATFORM := example
 
 # This is a list of all non-source files that are part of the distribution.
 AUXFILES := Makefile Readme.txt
 
 # This is a list of all non-source files that are part of the distribution.
 AUXFILES := Makefile Readme.txt
index 6bef32ec54ceb6b56cb6a27dc4419ec5248fa870..15b1d503c32a5fa9481c48f65d625a08922508bb 100644 (file)
@@ -519,67 +519,70 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
             return NULL;
         }
         /* convert value to target type and assign to parameter */
             return NULL;
         }
         /* convert value to target type and assign to parameter */
-        switch ( status->flags & ( E_char | E_short | E_long | E_llong |
-                                   E_intmax | E_size | E_ptrdiff |
-                                   E_unsigned ) )
+        if ( ! ( status->flags & E_suppressed ) )
         {
         {
-            case E_char:
-                *( va_arg( status->arg,               char * ) ) =               (char)( value * sign );
-                break;
-            case E_char | E_unsigned:
-                *( va_arg( status->arg,      unsigned char * ) ) =      (unsigned char)( value * sign );
-                break;
+            switch ( status->flags & ( E_char | E_short | E_long | E_llong |
+                                       E_intmax | E_size | E_ptrdiff |
+                                       E_unsigned ) )
+            {
+                case E_char:
+                    *( va_arg( status->arg,               char * ) ) =               (char)( value * sign );
+                    break;
+                case E_char | E_unsigned:
+                    *( va_arg( status->arg,      unsigned char * ) ) =      (unsigned char)( value * sign );
+                    break;
 
 
-            case E_short:
-                *( va_arg( status->arg,              short * ) ) =              (short)( value * sign );
-                break;
-            case E_short | E_unsigned:
-                *( va_arg( status->arg,     unsigned short * ) ) =     (unsigned short)( value * sign );
-                break;
+                case E_short:
+                    *( va_arg( status->arg,              short * ) ) =              (short)( value * sign );
+                    break;
+                case E_short | E_unsigned:
+                    *( va_arg( status->arg,     unsigned short * ) ) =     (unsigned short)( value * sign );
+                    break;
 
 
-            case 0:
-                *( va_arg( status->arg,                int * ) ) =                (int)( value * sign );
-                break;
-            case E_unsigned:
-                *( va_arg( status->arg,       unsigned int * ) ) =       (unsigned int)( value * sign );
-                break;
+                case 0:
+                    *( va_arg( status->arg,                int * ) ) =                (int)( value * sign );
+                    break;
+                case E_unsigned:
+                    *( va_arg( status->arg,       unsigned int * ) ) =       (unsigned int)( value * sign );
+                    break;
 
 
-            case E_long:
-                *( va_arg( status->arg,               long * ) ) =               (long)( value * sign );
-                break;
-            case E_long | E_unsigned:
-                *( va_arg( status->arg,      unsigned long * ) ) =      (unsigned long)( value * sign );
-                break;
+                case E_long:
+                    *( va_arg( status->arg,               long * ) ) =               (long)( value * sign );
+                    break;
+                case E_long | E_unsigned:
+                    *( va_arg( status->arg,      unsigned long * ) ) =      (unsigned long)( value * sign );
+                    break;
 
 
-            case E_llong:
-                *( va_arg( status->arg,          long long * ) ) =          (long long)( value * sign );
-                break;
-            case E_llong | E_unsigned:
-                *( va_arg( status->arg, unsigned long long * ) ) = (unsigned long long)( value * sign );
-                break;
+                case E_llong:
+                    *( va_arg( status->arg,          long long * ) ) =          (long long)( value * sign );
+                    break;
+                case E_llong | E_unsigned:
+                    *( va_arg( status->arg, unsigned long long * ) ) = (unsigned long long)( value * sign );
+                    break;
 
 
-            case E_intmax:
-                *( va_arg( status->arg,           intmax_t * ) ) =           (intmax_t)( value * sign );
-                break;
-            case E_intmax | E_unsigned:
-                *( va_arg( status->arg,          uintmax_t * ) ) =          (uintmax_t)( value * sign );
-                break;
+                case E_intmax:
+                    *( va_arg( status->arg,           intmax_t * ) ) =           (intmax_t)( value * sign );
+                    break;
+                case E_intmax | E_unsigned:
+                    *( va_arg( status->arg,          uintmax_t * ) ) =          (uintmax_t)( value * sign );
+                    break;
 
 
-            case E_size:
-                /* E_size always implies unsigned */
-                *( va_arg( status->arg,             size_t * ) ) =             (size_t)( value * sign );
-                break;
+                case E_size:
+                    /* E_size always implies unsigned */
+                    *( va_arg( status->arg,             size_t * ) ) =             (size_t)( value * sign );
+                    break;
 
 
-            case E_ptrdiff:
-                /* E_ptrdiff always implies signed */
-                *( va_arg( status->arg,          ptrdiff_t * ) ) =          (ptrdiff_t)( value * sign );
-                break;
+                case E_ptrdiff:
+                    /* E_ptrdiff always implies signed */
+                    *( va_arg( status->arg,          ptrdiff_t * ) ) =          (ptrdiff_t)( value * sign );
+                    break;
 
 
-            default:
-                puts( "UNSUPPORTED SCANF FLAG COMBINATION" );
-                return NULL; /* behaviour unspecified */
+                default:
+                    puts( "UNSUPPORTED SCANF FLAG COMBINATION" );
+                    return NULL; /* behaviour unspecified */
+            }
+            ++(status->n);
         }
         }
-        ++(status->n);
         return ++spec;
     }
     /* TODO: Floats. */
         return ++spec;
     }
     /* TODO: Floats. */
index f8d3b0f84f3f6e060acf493026cb1e5c544c9cf5..a1521fee3e2f04fb9dd362bf81f39ca0fd1fbd9a 100644 (file)
@@ -1,5 +1,59 @@
 {
     char buffer[100];
 {
     char buffer[100];
+    int i;
+    unsigned int u;
+    /* basic: reading of three-char string */
     SCANF_TEST( 1, "foo", "%3c", buffer );
     TESTCASE( memcmp( buffer, "foo", 3 ) == 0 );
     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 );
 }
 }