Show
Ignore:
Timestamp:
09/09/10 22:40:57 (21 months ago)
Author:
westram
Message:
  • unit-test improvements (merged [6757] [6758] [6759] [6760] [6761] [6762] [6764] [6791] [6795] [6798] [6799] [6800] [6801] [6802] [6809] [6810])
    • moved file compare to test_unit.h
    • fake report for skipped tests
    • added templates for char compare
    • perform minihexdump
    • flush output
    • added
      • TEST_ASSERT_FILES_EQUAL__BROKEN
      • TEST_ASSERT_ZERO_OR_SHOW_ERRNO
    • create a fake.patch if there are no changes
    • all code affecting assertions in UNIT_TESTS-mode went to test_global.h
      • overwrites arb_assert()
    • undefine UNIT_TESTS for GDE submakefiles (foreign code there)
    • arb_test::FlushedOutput::errorf raises assertion itself
    • test against I/O errors
    • moved test code
    • refactored message printing
    • unit-tester switches to run directory itself
      • eliminates path hack for valgrind
    • control leak-check by variable
    • added global test-environment (does nothing yet)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ARBDB/ad_save_load.cxx

    r6682 r6816  
    12931293#include <test_unit.h> 
    12941294 
    1295 static bool files_are_equal(const char *file1, const char *file2) { 
    1296     GB_ERROR   error     = NULL; 
    1297     FILE      *fp1       = fopen(file1, "rb"); 
    1298  
    1299     // @@@ FIXME:  use GB_IO_error() here later 
    1300     if (!fp1) error = GBS_global_string("can't open '%s'", file1); 
    1301     else { 
    1302         FILE *fp2 = fopen(file2, "rb"); 
    1303         if (!fp2) error = GBS_global_string("can't open '%s'", file2); 
    1304         else { 
    1305             const int BLOCKSIZE = 4096; 
    1306             char *buf1 = (char*)malloc(BLOCKSIZE); 
    1307             char *buf2 = (char*)malloc(BLOCKSIZE); 
    1308  
    1309             while (!error) { 
    1310                 int read1 = fread(buf1, 1, BLOCKSIZE, fp1); 
    1311                 int read2 = fread(buf2, 1, BLOCKSIZE, fp2); 
    1312  
    1313                 if (read1 != read2) error = "filesizes differ"; 
    1314                 else { 
    1315                     if (!read1) break; // done 
    1316                     if (memcmp(buf1, buf2, read1) != 0) error = "content differs"; 
    1317                 } 
    1318             } 
    1319             free(buf2); 
    1320             free(buf1); 
    1321             fclose(fp2); 
    1322         } 
    1323         fclose(fp1); 
    1324     } 
    1325  
    1326     if (error) TEST_WARNING("%s", GBS_global_string("files_are_equal(%s, %s): %s", file1, file2, error)); 
    1327     return !error; 
    1328 } 
    1329  
    13301295#define SAVE_AND_COMPARE(gbd, save_as, savetype, compare_with) \ 
    13311296    TEST_ASSERT_NO_ERROR(GB_save_as(gbd, save_as, savetype));  \ 
    1332     TEST_ASSERT(files_are_equal(save_as, compare_with)) 
     1297    TEST_ASSERT_FILES_EQUAL(save_as, compare_with) 
    13331298 
    13341299static GB_ERROR modify_db(GBDATA *gb_main) { 
     
    13421307        if (!gb_entry) error = GB_await_error(); 
    13431308        else    error        = GB_write_string(gb_entry, "text"); 
     1309        // else    error        = GB_write_string(gb_entry, "bla"); // provoke error in file compare 
    13441310    } 
    13451311    return error; 
     
    14251391#endif // TEST_AUTO_UPDATE 
    14261392 
    1427         TEST_ASSERT(files_are_equal("TEST_loadsave_quick.a00", "a2b.a00")); 
    1428         TEST_ASSERT(files_are_equal("a2b.a00", "b2b.a00")); 
     1393        TEST_ASSERT_FILES_EQUAL("TEST_loadsave_quick.a00", "a2b.a00"); 
     1394        TEST_ASSERT_FILES_EQUAL("a2b.a00", "b2b.a00"); 
    14291395 
    14301396        TEST_ASSERT_NO_ERROR(GB_save_quick_as(gb_a2b, "a2b.arb"));