MCPcopy Create free account
hub / github.com/apache/thrift / test_read_write_mix

Function test_read_write_mix

lib/cpp/test/ZlibTest.cpp:211–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211void 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
250void test_invalid_checksum(const boost::shared_array<uint8_t> buf, uint32_t buf_len) {
251 // Verify checksum checking.

Callers

nothing calls this directly

Calls 6

verifyChecksumMethod · 0.80
writeMethod · 0.65
readMethod · 0.65
getSizeMethod · 0.45
getMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected