From d21bd984620e5a095ac94120e4467aeff36788c5 Mon Sep 17 00:00:00 2001 From: "josh.macdonald" Date: Fri, 8 Aug 2008 04:08:12 +0000 Subject: The merge test isn't writing data for 0-byte target files because InMemoryEncodeDecode fails at this where xdelta3-main.h succeeds. This gets back to a TODO in -main.h about zero-size ambiguity. --- xdelta3/testing/file.h | 9 +++++++-- xdelta3/testing/regtest.cc | 29 ++++++++++++++++++++++++----- xdelta3/testing/test.h | 7 ++++--- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h index 1205bc0..d3b9d4a 100644 --- a/xdelta3/testing/file.h +++ b/xdelta3/testing/file.h @@ -117,6 +117,11 @@ public: } uint8_t* Data() const { + if (data_ == NULL) { + CHECK_EQ(0, size_); + data_size_ = 1; + data_ = new uint8_t[1]; + } return data_; } @@ -147,8 +152,8 @@ private: friend class BlockIterator; - uint8_t *data_; - size_t data_size_; + mutable uint8_t *data_; + mutable size_t data_size_; size_t size_; }; diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc index 7da4110..8bfcf51 100644 --- a/xdelta3/testing/regtest.cc +++ b/xdelta3/testing/regtest.cc @@ -107,8 +107,8 @@ void InMemoryEncodeDecode(const TestOptions &options, ret = xd3_decode_input(&decode_stream); } - //DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding", - // xd3_strerror(ret)); + DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding", + xd3_strerror(ret)); switch (ret) { case XD3_OUTPUT: @@ -146,11 +146,15 @@ void InMemoryEncodeDecode(const TestOptions &options, case XD3_INPUT: if (!encoding) { + if (target_block.Size() < target_iterator.BlockSize()) { + done = true; + continue; + } encoding = true; goto process; } else { if (target_block.Size() < target_iterator.BlockSize()) { - done = true; + encoding = false; } else { target_iterator.Next(); } @@ -162,7 +166,7 @@ void InMemoryEncodeDecode(const TestOptions &options, encoding = false; } else { CHECK_EQ(0, CmpDifferentBlockBytes(decoded_block, target_block)); - //DP(RINT "verified block %"Q"u\n", target_iterator.Blkno()); + DP(RINT "verified block %"Q"u\n", target_iterator.Blkno()); decoded_block.Reset(); encoding = true; } @@ -603,6 +607,21 @@ void TestNonBlockingProgress() { InMemoryEncodeDecode(options, spec1, spec2, NULL); } +void TestEmptyInMemory() { + MTRandom rand; + FileSpec spec0(&rand); + FileSpec spec1(&rand); + TestOptions options; + Block delta; + + spec0.GenerateFixedSize(0); + spec1.GenerateFixedSize(0); + + InMemoryEncodeDecode(options, spec0, spec1, &delta); + + CHECK_LT(0, delta.Size()); +} + void FourWayMergeTest(const TestOptions &options, const FileSpec &spec0, const FileSpec &spec1, @@ -633,7 +652,6 @@ void FourWayMergeTest(const TestOptions &options, }; CHECK_EQ(0, xd3_main_cmdline(SIZEOF_ARRAY(argv) - 1, (char**)argv)); - } void TestMergeCommand() { @@ -708,6 +726,7 @@ int main(int argc, char **argv) { // TEST(TestMoveMutator); // TEST(TestOverwriteMutator); // TEST(TestNonBlockingProgress); + TEST(TestEmptyInMemory); TEST(TestMergeCommand); return 0; } diff --git a/xdelta3/testing/test.h b/xdelta3/testing/test.h index 32b62c0..536673b 100644 --- a/xdelta3/testing/test.h +++ b/xdelta3/testing/test.h @@ -15,10 +15,11 @@ extern "C" { #define CHECK_GE(x,y) CHECK_OP(x,y,>=) #define CHECK_OP(x,y,OP) \ -do {if (!((x) OP (y))) { \ + do { typeof((x) OP (y)) _x(x), _y(y); \ + if (!(_x OP _y)) { \ cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x " " #OP " " #y << endl; \ - cerr << __FILE__ << ":" << __LINE__ << " Expected: " << x << endl; \ - cerr << __FILE__ << ":" << __LINE__ << " Actual: " << y << endl; \ + cerr << __FILE__ << ":" << __LINE__ << " Expected: " << _x << endl; \ + cerr << __FILE__ << ":" << __LINE__ << " Actual: " << _y << endl; \ abort(); \ } } while (false) -- cgit v1.2.3