From bfbb5282262d8ae0934f2fb1ed6587f0fb97be9c Mon Sep 17 00:00:00 2001 From: TheVice Date: Fri, 21 Jan 2022 19:59:47 +0200 Subject: [PATCH] [snappy_unittest] added test on 'UncompressAsMuchAsPossible' function. --- snappy_unittest.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/snappy_unittest.cc b/snappy_unittest.cc index 292004c..c6591d9 100644 --- a/snappy_unittest.cc +++ b/snappy_unittest.cc @@ -861,6 +861,25 @@ TEST(Snappy, FindMatchLengthRandom) { } } +TEST(Snappy, UncompressAsMuchAsPossible) { + std::string input; + const uint8_t preamble[] = { 128, 192, 206, 254, 1 }; + input.append(reinterpret_cast(preamble), 5); + const uint8_t the_literal[] = { 252, 255, 111, 164, 10 }; + input.append(reinterpret_cast(the_literal), 5); + const uint8_t data[] = { 1, 2, 3, 4, 5 }; + input.append(reinterpret_cast(data), 5); + std::string uncompressed; + uncompressed.resize(input.size()); + snappy::UncheckedByteArraySink sink(string_as_array(&uncompressed)); + DataEndingAtUnreadablePage c(input); + snappy::ByteArraySource source(c.data(), c.size()); + size_t length = snappy::UncompressAsMuchAsPossible(&source, &sink); + CHECK_EQ(5, length); + CHECK_LE(5, uncompressed.size()); + CHECK_EQ(0, memcmp(data, uncompressed.c_str(), 5)); +} + uint16_t MakeEntry(unsigned int extra, unsigned int len, unsigned int copy_offset) { // Check that all of the fields fit within the allocated space