| 209 | } |
| 210 | |
| 211 | void test_read_write_mix(const boost::shared_array<uint8_t> buf, |
| 212 | uint32_t buf_len, |
| 213 | const shared_ptr<SizeGenerator>& write_gen, |
| 214 | const shared_ptr<SizeGenerator>& read_gen) { |
| 215 | // Try it with a mix of read/write sizes. |
| 216 | shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer()); |
| 217 | shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf)); |
| 218 | unsigned int tot; |
| 219 | |
| 220 | tot = 0; |
| 221 | while (tot < buf_len) { |
| 222 | uint32_t write_len = write_gen->getSize(); |
| 223 | if (tot + write_len > buf_len) { |
| 224 | write_len = buf_len - tot; |
| 225 | } |
| 226 | zlib_trans->write(buf.get() + tot, write_len); |
| 227 | tot += write_len; |
| 228 | } |
| 229 | |
| 230 | zlib_trans->finish(); |
| 231 | |
| 232 | tot = 0; |
| 233 | boost::shared_array<uint8_t> mirror(new uint8_t[buf_len]); |
| 234 | while (tot < buf_len) { |
| 235 | uint32_t read_len = read_gen->getSize(); |
| 236 | uint32_t expected_read_len = read_len; |
| 237 | if (tot + read_len > buf_len) { |
| 238 | expected_read_len = buf_len - tot; |
| 239 | } |
| 240 | uint32_t got = zlib_trans->read(mirror.get() + tot, read_len); |
| 241 | BOOST_REQUIRE_LE(got, expected_read_len); |
| 242 | BOOST_REQUIRE_NE(got, (uint32_t)0); |
| 243 | tot += got; |
| 244 | } |
| 245 | |
| 246 | BOOST_CHECK_EQUAL(memcmp(mirror.get(), buf.get(), buf_len), 0); |
| 247 | zlib_trans->verifyChecksum(); |
| 248 | } |
| 249 | |
| 250 | void test_invalid_checksum(const boost::shared_array<uint8_t> buf, uint32_t buf_len) { |
| 251 | // Verify checksum checking. |