Changeset 7975
- Timestamp:
- 22/09/11 14:37:23 (8 months ago)
- Location:
- branches/dev
- Files:
-
- 3 modified
-
ARBDB/ad_prot.h (modified) (1 diff)
-
ARBDB/adfile.cxx (modified) (3 diffs)
-
UNIT_TESTER/test_unit.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/dev/ARBDB/ad_prot.h
r7960 r7975 169 169 void GBS_read_dir(StrArray &names, const char *dir, const char *mask); 170 170 bool GB_test_textfile_difflines(const char *file1, const char *file2, int expected_difflines, int special_mode); 171 size_t GB_test_mem_equal(const unsigned char *buf1, const unsigned char *buf2, size_t common); 171 172 bool GB_test_files_equal(const char *file1, const char *file2); 172 173 void GBT_transform_names(StrArray &dest, const StrArray &source, char *transform (const char *, void *), void *client_data); -
branches/dev/ARBDB/adfile.cxx
r7954 r7975 566 566 } 567 567 568 size_t GB_test_mem_equal(const unsigned char *buf1, const unsigned char *buf2, size_t common) { 569 size_t equal_bytes; 570 if (memcmp(buf1, buf2, common) == 0) { 571 equal_bytes = common; 572 } 573 else { 574 equal_bytes = 0; 575 size_t x = 0; // position inside memory 576 while (buf1[x] == buf2[x]) { 577 x++; 578 equal_bytes++; 579 } 580 581 const size_t DUMP = 7; 582 size_t y1 = x >= DUMP ? x-DUMP : 0; 583 size_t y2 = (x+DUMP)>common ? common : (x+DUMP); 584 size_t blockstart = equal_bytes-x; 585 586 for (size_t y = y1; y <= y2; y++) { 587 fprintf(stderr, "[0x%04zx]", blockstart+y); 588 arb_test::print_pair(buf1[y], buf2[y]); 589 fputc(' ', stderr); 590 arb_test::print_hex_pair(buf1[y], buf2[y]); 591 if (x == y) fputs(" <- diff", stderr); 592 fputc('\n', stderr); 593 } 594 if (y2 == common) { 595 fputs("[end of block - truncated]\n", stderr); 596 } 597 } 598 return equal_bytes; 599 } 600 568 601 bool GB_test_files_equal(const char *file1, const char *file2) { 569 602 const char *error = NULL; … … 587 620 588 621 while (!error) { 589 int read1 = fread(buf1, 1, BLOCKSIZE, fp1);590 int read2 = fread(buf2, 1, BLOCKSIZE, fp2);591 int common = read1<read2 ? read1 : read2;622 int read1 = fread(buf1, 1, BLOCKSIZE, fp1); 623 int read2 = fread(buf2, 1, BLOCKSIZE, fp2); 624 size_t common = read1<read2 ? read1 : read2; 592 625 593 626 if (!common) { … … 596 629 } 597 630 598 if (memcmp(buf1, buf2, common) == 0) { 599 equal_bytes += common; 600 } 601 else { 602 int x = 0; 603 while (buf1[x] == buf2[x]) { 604 x++; 605 equal_bytes++; 606 } 631 size_t thiseq = GB_test_mem_equal(buf1, buf2, common); 632 if (thiseq != common) { 607 633 error = "content differs"; 608 609 // x is the position inside the current block 610 const int DUMP = 7; 611 int y1 = x >= DUMP ? x-DUMP : 0; 612 int y2 = (x+DUMP)>common ? common : (x+DUMP); 613 int blockstart = equal_bytes-x; 614 615 for (int y = y1; y <= y2; y++) { 616 fprintf(stderr, "[0x%04x]", blockstart+y); 617 arb_test::print_pair(buf1[y], buf2[y]); 618 fputc(' ', stderr); 619 arb_test::print_hex_pair(buf1[y], buf2[y]); 620 if (x == y) fputs(" <- diff", stderr); 621 fputc('\n', stderr); 622 } 623 if (y2 == common) { 624 fputs("[end of block - truncated]\n", stderr); 625 } 626 } 634 } 635 equal_bytes += thiseq; 627 636 } 628 637 -
branches/dev/UNIT_TESTER/test_unit.h
r7867 r7975 574 574 575 575 namespace arb_test { 576 inline bool test_mem_equal(const void *mem1, const void *mem2, size_t size) { 577 FlushedOutputNoLF yes; 578 return GB_test_mem_equal(reinterpret_cast<const unsigned char *>(mem1), 579 reinterpret_cast<const unsigned char *>(mem2), size) == size; 580 } 576 581 inline bool test_files_equal(const char *file1, const char *file2) { 577 582 FlushedOutputNoLF yes; … … 596 601 #define TEST_ASSERT_FILES_EQUAL(f1,f2) TEST_ASSERT(arb_test::test_files_equal(f1,f2)) 597 602 #define TEST_ASSERT_FILES_EQUAL__BROKEN(f1,f2) TEST_ASSERT__BROKEN(arb_test::test_files_equal(f1,f2)) 603 604 #define TEST_ASSERT_MEM_EQUAL(m1,m2,size) TEST_ASSERT(arb_test::test_mem_equal(m1,m2,size)) 605 #define TEST_ASSERT_MEM_EQUAL__BROKEN(m1,m2,size) TEST_ASSERT__BROKEN(arb_test::test_mem_equal(m1,m2,size)) 598 606 599 607 #define TEST_ASSERT_TEXTFILES_EQUAL(f1,f2) TEST_ASSERT_TEXTFILE_DIFFLINES(f1,f2,0)
