| 210 | } |
| 211 | |
| 212 | void TestTell(CompressionOptions input_options, |
| 213 | CompressionOptions output_options) { |
| 214 | Env* env = Env::Default(); |
| 215 | string fname = testing::TmpDir() + "/zlib_buffers_test"; |
| 216 | for (auto file_size : NumCopies()) { |
| 217 | string data = GenTestString(file_size); |
| 218 | for (auto input_buf_size : InputBufferSizes()) { |
| 219 | for (auto output_buf_size : OutputBufferSizes()) { |
| 220 | // Write the compressed file. |
| 221 | WriteCompressedFile(env, fname, input_buf_size, output_buf_size, |
| 222 | output_options, data); |
| 223 | |
| 224 | // Boiler-plate to set up ZlibInputStream. |
| 225 | std::unique_ptr<RandomAccessFile> file_reader; |
| 226 | TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file_reader)); |
| 227 | std::unique_ptr<RandomAccessInputStream> input_stream( |
| 228 | new RandomAccessInputStream(file_reader.get())); |
| 229 | ZlibInputStream in(input_stream.get(), input_buf_size, output_buf_size, |
| 230 | input_options); |
| 231 | |
| 232 | string first_half(data, 0, data.size() / 2); |
| 233 | string bytes_read; |
| 234 | |
| 235 | // Read the first half of the uncompressed file and expect that Tell() |
| 236 | // returns half the uncompressed length of the file. |
| 237 | TF_ASSERT_OK(in.ReadNBytes(first_half.size(), &bytes_read)); |
| 238 | EXPECT_EQ(in.Tell(), first_half.size()); |
| 239 | EXPECT_EQ(bytes_read, first_half); |
| 240 | |
| 241 | // Read the remaining half of the uncompressed file and expect that |
| 242 | // Tell() points past the end of file. |
| 243 | string second_half; |
| 244 | TF_ASSERT_OK( |
| 245 | in.ReadNBytes(data.size() - first_half.size(), &second_half)); |
| 246 | EXPECT_EQ(in.Tell(), data.size()); |
| 247 | bytes_read.append(second_half); |
| 248 | |
| 249 | // Expect that the file is correctly read. |
| 250 | EXPECT_EQ(bytes_read, data); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | void TestSkipNBytes(CompressionOptions input_options, |
| 257 | CompressionOptions output_options) { |
no test coverage detected