| 254 | } |
| 255 | |
| 256 | void TestSkipNBytes(CompressionOptions input_options, |
| 257 | CompressionOptions output_options) { |
| 258 | Env* env = Env::Default(); |
| 259 | string fname = testing::TmpDir() + "/zlib_buffers_test"; |
| 260 | for (auto file_size : NumCopies()) { |
| 261 | string data = GenTestString(file_size); |
| 262 | for (auto input_buf_size : InputBufferSizes()) { |
| 263 | for (auto output_buf_size : OutputBufferSizes()) { |
| 264 | // Write the compressed file. |
| 265 | WriteCompressedFile(env, fname, input_buf_size, output_buf_size, |
| 266 | output_options, data); |
| 267 | |
| 268 | // Boiler-plate to set up ZlibInputStream. |
| 269 | std::unique_ptr<RandomAccessFile> file_reader; |
| 270 | TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file_reader)); |
| 271 | std::unique_ptr<RandomAccessInputStream> input_stream( |
| 272 | new RandomAccessInputStream(file_reader.get())); |
| 273 | ZlibInputStream in(input_stream.get(), input_buf_size, output_buf_size, |
| 274 | input_options); |
| 275 | |
| 276 | size_t data_half_size = data.size() / 2; |
| 277 | string second_half(data, data_half_size, data.size() - data_half_size); |
| 278 | |
| 279 | // Skip past the first half of the file and expect Tell() returns |
| 280 | // correctly. |
| 281 | TF_ASSERT_OK(in.SkipNBytes(data_half_size)); |
| 282 | EXPECT_EQ(in.Tell(), data_half_size); |
| 283 | |
| 284 | // Expect that second half is read correctly and Tell() returns past |
| 285 | // end of file after reading complete file. |
| 286 | string bytes_read; |
| 287 | TF_ASSERT_OK(in.ReadNBytes(second_half.size(), &bytes_read)); |
| 288 | EXPECT_EQ(bytes_read, second_half); |
| 289 | EXPECT_EQ(in.Tell(), data.size()); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | TEST(ZlibInputStream, TellDefaultOptions) { |
| 296 | TestTell(CompressionOptions::DEFAULT(), CompressionOptions::DEFAULT()); |
no test coverage detected