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/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