From: David Reiss Date: Wed, 6 Oct 2010 17:10:20 +0000 (+0000) Subject: THRIFT-929. cpp: Fix a couple minor issues in ZlibTest X-Git-Tag: 0.6.0~113 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=56cb796bcecb1e2fef8ab23d8f3f60418502ba10;p=common%2Fthrift.git THRIFT-929. cpp: Fix a couple minor issues in ZlibTest - Add a necessary cast. - Check buffer sizes more carefully to allow for different read/write size distributions. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1005147 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/test/ZlibTest.cpp b/lib/cpp/test/ZlibTest.cpp index 45d3ecc4..59e91f27 100644 --- a/lib/cpp/test/ZlibTest.cpp +++ b/lib/cpp/test/ZlibTest.cpp @@ -170,7 +170,7 @@ int main() { char *file_names[] = { // Highly compressible. - "./gen-cpp/DebugProtoTest_types.cpp", + "./gen-cpp/DebugProtoTest_types.tcc", // Uncompressible. "/dev/urandom", // Null-terminated. @@ -237,7 +237,9 @@ int main() { string tmp_buf; membuf->appendBufferToString(tmp_buf); tmp_buf.erase(tmp_buf.length() - 1); - membuf->resetFromString(tmp_buf); + membuf->resetBuffer(const_cast( + reinterpret_cast(tmp_buf.data())), + tmp_buf.length()); mirror.resize(content.size()); uint32_t got = zlib_trans->read(&mirror[0], mirror.size()); assert(got == content.size()); @@ -262,8 +264,12 @@ int main() { idx = 0; tot = 0; while (tot < content.size()) { - zlib_trans->write(&content[tot], dist[d1][idx]); - tot += dist[d1][idx]; + uint32_t write_len = dist[d1][idx]; + if (tot + write_len > content.size()) { + write_len = content.size() - tot; + } + zlib_trans->write(&content[tot], write_len); + tot += write_len; idx++; } @@ -273,9 +279,14 @@ int main() { idx = 0; tot = 0; while (tot < mirror.size()) { - uint32_t got = zlib_trans->read(&mirror[tot], dist[d2][idx]); - assert(got == dist[d2][idx]); - tot += dist[d2][idx]; + uint32_t read_len = dist[d2][idx]; + uint32_t expected_read_len = read_len; + if (tot + read_len > content.size()) { + expected_read_len = content.size() - tot; + } + uint32_t got = zlib_trans->read(&mirror[tot], read_len); + assert(got == expected_read_len); + tot += got; idx++; } @@ -294,7 +305,9 @@ int main() { string tmp_buf; membuf->appendBufferToString(tmp_buf); tmp_buf[57]++; - membuf->resetFromString(tmp_buf); + membuf->resetBuffer(const_cast( + reinterpret_cast(tmp_buf.data())), + tmp_buf.length()); mirror.resize(content.size()); try { zlib_trans->read(&mirror[0], mirror.size());