diff options
author | Chris Wilson <chris+github@qwirx.com> | 2015-08-07 21:40:44 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2015-08-07 21:40:44 +0000 |
commit | b70b4b4429e00a42bf7f652d8eeef59c57a741b6 (patch) | |
tree | f19ff2b988fe02c261675e091eb425acd76828fd /test/backupstore | |
parent | 8db4e69bca1dd7543d407222d25de6ded808ef88 (diff) |
Add a BackupStoreFile encoding streaming verifier
Diffstat (limited to 'test/backupstore')
-rw-r--r-- | test/backupstore/testbackupstore.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index 3a219091..f30fd42a 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -2323,6 +2323,42 @@ bool test_encoding() { FileStream enc("testfiles/testenc1_enc"); TEST_THAT(BackupStoreFile::VerifyEncodedFileFormat(enc) == true); + + // And using the stream-based interface, writing different + // block sizes at a time. + CollectInBufferStream contents; + enc.Seek(0, IOStream::SeekType_Absolute); + enc.CopyStreamTo(contents); + contents.SetForReading(); + + enc.Seek(0, IOStream::SeekType_End); + size_t file_size = enc.GetPosition(); + TEST_EQUAL(file_size, contents.GetSize()); + + for(int buffer_size = 1; ; buffer_size <<= 1) + { + enc.Seek(0, IOStream::SeekType_Absolute); + CollectInBufferStream temp_copy; + BackupStoreFile::VerifyStream verifier(&temp_copy); + enc.CopyStreamTo(verifier, IOStream::TimeOutInfinite, + buffer_size); + + // The block index is only validated on Close(), which + // CopyStreamTo() doesn't do. + verifier.Close(); + + temp_copy.SetForReading(); + TEST_EQUAL(file_size, temp_copy.GetSize()); + TEST_THAT(memcmp(contents.GetBuffer(), + temp_copy.GetBuffer(), file_size) == 0); + + // Keep doubling buffer size until we've copied the + // entire encoded file in a single pass, then stop. + if(buffer_size > file_size) + { + break; + } + } } // Decode it |