Show
Ignore:
Timestamp:
04/09/10 11:43:48 (21 months ago)
Author:
westram
Message:
  • moved file compare to test_unit.h
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/refactor/ARBDB/ad_save_load.cxx

    r6682 r6757  
    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"));