| 125 | } |
| 126 | |
| 127 | void CheckCompressedOutputStream(Codec* codec, const std::vector<uint8_t>& data, |
| 128 | bool do_flush) { |
| 129 | // Create compressed output stream |
| 130 | ASSERT_OK_AND_ASSIGN(auto buffer_writer, BufferOutputStream::Create()); |
| 131 | ASSERT_OK_AND_ASSIGN(auto stream, CompressedOutputStream::Make(codec, buffer_writer)); |
| 132 | ASSERT_OK_AND_EQ(0, stream->Tell()); |
| 133 | |
| 134 | const uint8_t* input = data.data(); |
| 135 | int64_t input_len = data.size(); |
| 136 | const int64_t chunk_size = 1111; |
| 137 | while (input_len > 0) { |
| 138 | int64_t nbytes = std::min(chunk_size, input_len); |
| 139 | ASSERT_OK(stream->Write(input, nbytes)); |
| 140 | input += nbytes; |
| 141 | input_len -= nbytes; |
| 142 | if (do_flush) { |
| 143 | ASSERT_OK(stream->Flush()); |
| 144 | } |
| 145 | } |
| 146 | ASSERT_OK_AND_EQ(static_cast<int64_t>(data.size()), stream->Tell()); |
| 147 | ASSERT_OK(stream->Close()); |
| 148 | |
| 149 | // Get compressed data and decompress it |
| 150 | ASSERT_OK_AND_ASSIGN(auto compressed, buffer_writer->Finish()); |
| 151 | std::vector<uint8_t> decompressed(data.size()); |
| 152 | ASSERT_OK(codec->Decompress(compressed->size(), compressed->data(), decompressed.size(), |
| 153 | decompressed.data())); |
| 154 | ASSERT_EQ(decompressed, data); |
| 155 | } |
| 156 | |
| 157 | class CompressedInputStreamTest : public ::testing::TestWithParam<Compression::type> { |
| 158 | protected: |