summaryrefslogtreecommitdiff
path: root/test/backupdiff/testbackupdiff.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/backupdiff/testbackupdiff.cpp')
-rw-r--r--test/backupdiff/testbackupdiff.cpp83
1 files changed, 52 insertions, 31 deletions
diff --git a/test/backupdiff/testbackupdiff.cpp b/test/backupdiff/testbackupdiff.cpp
index a91d6dfe..816f50d1 100644
--- a/test/backupdiff/testbackupdiff.cpp
+++ b/test/backupdiff/testbackupdiff.cpp
@@ -64,7 +64,7 @@ bool files_identical(const char *file1, const char *file2)
return true;
}
-void make_file_of_zeros(const char *filename, size_t size)
+bool make_file_of_zeros(const char *filename, size_t size)
{
#ifdef WIN32
HANDLE handle = openfile(filename, O_WRONLY | O_CREAT | O_EXCL, 0);
@@ -75,7 +75,9 @@ void make_file_of_zeros(const char *filename, size_t size)
BOOL result = SetEndOfFile(handle);
if (result != TRUE)
{
- printf("Error %u\n", GetLastError());
+ BOX_ERROR("Failed to create large file " << filename <<
+ " (" << (size >> 20) << " MB): " <<
+ GetErrorMessage(GetLastError()));
}
TEST_THAT(result == TRUE);
TEST_THAT(CloseHandle(handle) == TRUE);
@@ -87,7 +89,16 @@ void make_file_of_zeros(const char *filename, size_t size)
TEST_THAT(close(fd) == 0);
#endif
- TEST_THAT((size_t)TestGetFileSize(filename) == size);
+ bool correct_size = ((size_t)TestGetFileSize(filename) == size);
+ TEST_THAT(correct_size);
+ if (!correct_size)
+ {
+ BOX_ERROR("Failed to create large file " << filename <<
+ " (" << (size >> 20) << " MB): " <<
+ "got " << (TestGetFileSize(filename) >> 20) <<
+ " MB instead");
+ }
+ return correct_size;
}
@@ -110,8 +121,10 @@ void check_encoded_file(const char *filename, int64_t OtherFileID, int new_block
TEST_THAT((uint64_t)box_ntoh64(hdr.mOtherFileID) == (uint64_t)OtherFileID);
// number of blocks
int64_t nblocks = box_ntoh64(hdr.mNumBlocks);
- TRACE2("Reading index from '%s', has %lld blocks\n", filename, nblocks);
- TRACE0("======== ===== ========== ======== ========\n Index Where EncSz/Idx Size WChcksm\n");
+ BOX_TRACE("Reading index from '" << filename << "', has " <<
+ nblocks << " blocks");
+ BOX_TRACE("======== ===== ========== ======== ========");
+ BOX_TRACE(" Index Where EncSz/Idx Size WChcksm");
// Read them all in
int64_t nnew = 0, nold = 0;
for(int64_t b = 0; b < nblocks; ++b)
@@ -119,35 +132,36 @@ void check_encoded_file(const char *filename, int64_t OtherFileID, int new_block
file_BlockIndexEntry en;
TEST_THAT(enc.ReadFullBuffer(&en, sizeof(en), 0));
int64_t s = box_ntoh64(en.mEncodedSize);
+
+ // Decode the rest
+ uint64_t iv = box_ntoh64(hdr.mEntryIVBase);
+ iv += b;
+ sBlowfishDecryptBlockEntry.SetIV(&iv);
+ file_BlockIndexEntryEnc entryEnc;
+ sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc,
+ sizeof(entryEnc), en.mEnEnc, sizeof(en.mEnEnc));
+
+
if(s > 0)
{
nnew++;
- #ifdef WIN32
- TRACE2("%8I64d this s=%8I64d", b, s);
- #else
- TRACE2("%8lld this s=%8lld", b, s);
- #endif
+ BOX_TRACE(std::setw(8) << b << " this s=" <<
+ std::setw(8) << s << " " <<
+ std::setw(8) << ntohl(entryEnc.mSize) << " " <<
+ std::setw(8) << std::setfill('0') <<
+ std::hex << ntohl(entryEnc.mWeakChecksum));
}
else
{
nold++;
- #ifdef WIN32
- TRACE2("%8I64d other i=%8I64d", b, 0 - s);
- #else
- TRACE2("%8lld other i=%8lld", b, 0 - s);
- #endif
+ BOX_TRACE(std::setw(8) << b << " other i=" <<
+ std::setw(8) << (0-s) << " " <<
+ std::setw(8) << ntohl(entryEnc.mSize) << " " <<
+ std::setw(8) << std::setfill('0') <<
+ std::hex << ntohl(entryEnc.mWeakChecksum));
}
- // Decode the rest
- uint64_t iv = box_ntoh64(hdr.mEntryIVBase);
- iv += b;
- sBlowfishDecryptBlockEntry.SetIV(&iv);
- file_BlockIndexEntryEnc entryEnc;
- sBlowfishDecryptBlockEntry.TransformBlock(&entryEnc, sizeof(entryEnc),
- en.mEnEnc, sizeof(en.mEnEnc));
- TRACE2(" %8d %08x\n", ntohl(entryEnc.mSize), ntohl(entryEnc.mWeakChecksum));
-
}
- TRACE0("======== ===== ========== ======== ========\n");
+ BOX_TRACE("======== ===== ========== ======== ========");
TEST_THAT(new_blocks_expected == nnew);
TEST_THAT(old_blocks_expected == nold);
}
@@ -374,7 +388,7 @@ void test_combined_diffs()
int test(int argc, const char *argv[])
{
// Want to trace out all the details
- #ifndef NDEBUG
+ #ifndef BOX_RELEASE_BUILD
#ifndef WIN32
BackupStoreFile::TraceDetailsOfDiffProcess = true;
#endif
@@ -512,13 +526,20 @@ int test(int argc, const char *argv[])
// found. Check this out!
#ifdef WIN32
- ::fprintf(stdout, "Testing diffing two large streams, "
- "may take a while!\n");
- ::fflush(stdout);
+ BOX_WARNING("Testing diffing two large streams, may take a while!");
+ ::fflush(stderr);
#endif
- make_file_of_zeros("testfiles/zero.0", 20*1024*1024);
- make_file_of_zeros("testfiles/zero.1", 200*1024*1024);
+ if (!make_file_of_zeros("testfiles/zero.0", 20*1024*1024))
+ {
+ return 1;
+ }
+
+ if (!make_file_of_zeros("testfiles/zero.1", 200*1024*1024))
+ {
+ remove("testfiles/zero.0");
+ return 1;
+ }
// Generate a first encoded file
{