]> pd.if.org Git - pdclib/blobdiff - testing/_PDCLIB_iotest.h
Tyndur tests
[pdclib] / testing / _PDCLIB_iotest.h
index 7e0e80b50077f2b0cc67c7808d9bfe9438b58fdb..155ac16d51036c3935227ec85df331186403aee7 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 ); \
+      if ( (int)fread( result_buffer, 1, actual_rc, target ) != actual_rc ) \
+      { \
+          fprintf( stderr, "GET_RESULT failed." ); \
+      }
+   #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 GETFMT( fmt, ... ) (fmt)
+#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 ) ) ) \
         { \
             ++TEST_RESULTS; \
-            fprintf( stderr, "FAILED: " __FILE__ " (" _PDCLIB_FILEID "), line %d\n        expected %2d, \"%s\"\n        actual   %2d, \"%s\"\n", __LINE__, expected_rc, expected_string, actual_rc, RESULT_STRING( target ) ); \
+            fprintf( stderr, \
+                "FAILED: " __FILE__ " (" _PDCLIB_FILEID "), line %d\n" \
+                "        format string \"%s\"\n" \
+                "        expected %2d, \"%s\"\n" \
+                "        actual   %2d, \"%s\"\n", \
+                 __LINE__, GETFMT(__VA_ARGS__, 0), expected_rc, \
+                 expected_string, actual_rc, RESULT_STRING( target ) ); \
         } \
     } while ( 0 )
 
         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; \