Changeset 6757

Show
Ignore:
Timestamp:
04/09/10 11:43:48 (17 months ago)
Author:
westram
Message:
  • moved file compare to test_unit.h
Location:
branches/refactor
Files:
2 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")); 
  • branches/refactor/UNIT_TESTER/test_unit.h

    r6751 r6757  
    178178    } 
    179179 
     180    inline bool files_are_equal(const char *file1, const char *file2) { 
     181        const char *error = NULL; 
     182        FILE       *fp1   = fopen(file1, "rb"); 
     183 
     184        if (!fp1) { 
     185            FlushedOutput::printf("can't open '%s'", file1); 
     186            error = "i/o error"; 
     187        } 
     188        else { 
     189            FILE *fp2 = fopen(file2, "rb"); 
     190            if (!fp2) { 
     191                FlushedOutput::printf("can't open '%s'", file2); 
     192                error = "i/o error"; 
     193            } 
     194            else { 
     195                const int BLOCKSIZE = 4096; 
     196                char *buf1 = (char*)malloc(BLOCKSIZE); 
     197                char *buf2 = (char*)malloc(BLOCKSIZE); 
     198 
     199                while (!error) { 
     200                    int read1 = fread(buf1, 1, BLOCKSIZE, fp1); 
     201                    int read2 = fread(buf2, 1, BLOCKSIZE, fp2); 
     202 
     203                    if (read1 != read2) error = "filesizes differ"; 
     204                    else { 
     205                        if (!read1) break; // done 
     206                        if (memcmp(buf1, buf2, read1) != 0) error = "content differs"; 
     207                    } 
     208                } 
     209                free(buf2); 
     210                free(buf1); 
     211                fclose(fp2); 
     212            } 
     213            fclose(fp1); 
     214        } 
     215 
     216        if (error) FlushedOutput::printf("files_are_equal(%s, %s) fails: %s\n", file1, file2, error); 
     217        return !error; 
     218    } 
     219     
    180220}; 
    181221 
     
    350390#define TEST_ASSERT_SIMILAR__BROKEN(t1,t2,epsilon) TEST_ASSERT__BROKEN(arb_test::is_similar(t1, t2, epsilon)) 
    351391 
     392#define TEST_ASSERT_FILES_EQUAL(f1,f2) TEST_ASSERT(arb_test::files_are_equal(f1,f2)) 
     393 
    352394#else 
    353395#error test_unit.h included twice