]> pd.if.org Git - pdclib.old/blobdiff - testing/_PDCLIB_iotest.h
_PDCLIB_iotest.h: the code for determining if the result matched or not was too cleve...
[pdclib.old] / testing / _PDCLIB_iotest.h
index 4cdc6d5c7039a7176da29d37fc8e4a003bf0d992..134a4446809447c1acd1890834d1023cdb97c93e 100644 (file)
 
 /* ...printf() tests */
 #if defined( _PDCLIB_FILEIO )
-    #define RESULT_MISMATCH( act, exp ) \
-        rewind( act ), \
-        result_buffer[ fread( result_buffer, 1, strlen( exp ) + 1, act ) ] = '\0', \
-        rewind( act ), \
-        memcmp( result_buffer, exp, strlen( exp ) )
+   #define GET_RESULT \
+      rewind( target ); \
+      fread( result_buffer, 1, actual_rc, target );
+   #define RESULT_MISMATCH( act, exp ) strcmp( result_buffer, exp ) != 0
    #define RESULT_STRING( tgt ) result_buffer
 #elif defined( _PDCLIB_STRINGIO )
    #define RESULT_MISMATCH( act, exp ) strcmp( act, exp ) != 0
+   #define GET_RESULT
    #define RESULT_STRING( tgt ) tgt
 #endif
 
 #ifdef _PDCLIB_FILEIO
-#define PREP_RESULT_BUFFER char result_buffer[100];
+#define PREP_RESULT_BUFFER char result_buffer[100] = { 0 }; rewind( target );
 #else
 #define PREP_RESULT_BUFFER
 #endif
 
-#define PRINTF_TEST( expected_rc, expected_string, format, ... ) do { \
+#define PRINTF_TEST( expected_rc, expected_string, ... ) do { \
         PREP_RESULT_BUFFER \
-        int actual_rc = testprintf( target, format, __VA_ARGS__ ); \
+        int actual_rc = testprintf( target, __VA_ARGS__ ); \
+        GET_RESULT \
         if ( ( actual_rc != expected_rc ) || \
              ( RESULT_MISMATCH( target, expected_string ) ) ) \
         { \
         memcpy( source, input_string, sizeof( input_string ) );
 #endif
 
-#define SCANF_TEST( expected_rc, input_string, format, ... ) do { \
+#define SCANF_TEST( expected_rc, input_string, ... ) do { \
         int actual_rc; \
         PREPARE_SOURCE( input_string ); \
-        actual_rc = testscanf( source, format, __VA_ARGS__ ); \
+        actual_rc = testscanf( source, __VA_ARGS__ ); \
         if ( actual_rc != expected_rc ) \
         { \
             ++TEST_RESULTS; \