| Index: third_party/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc
|
| index 8229ee6db8af4213aa5992bf79071fd139be9e31..5196d905b4a8e9ff5a87e5df899b62f45ea7526c 100644
|
| --- a/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc
|
| @@ -61,6 +61,7 @@
|
| #include <sstream>
|
|
|
| #include <google/protobuf/io/zero_copy_stream_impl.h>
|
| +#include <google/protobuf/io/coded_stream.h>
|
|
|
| #if HAVE_ZLIB
|
| #include <google/protobuf/io/gzip_stream.h>
|
| @@ -285,6 +286,57 @@ TEST_F(IoTest, ArrayIo) {
|
| }
|
| }
|
|
|
| +TEST_F(IoTest, TwoSessionWrite) {
|
| + // Test that two concatenated write sessions read correctly
|
| +
|
| + static const char* strA = "0123456789";
|
| + static const char* strB = "WhirledPeas";
|
| + const int kBufferSize = 2*1024;
|
| + uint8* buffer = new uint8[kBufferSize];
|
| + char* temp_buffer = new char[40];
|
| +
|
| + for (int i = 0; i < kBlockSizeCount; i++) {
|
| + for (int j = 0; j < kBlockSizeCount; j++) {
|
| + ArrayOutputStream* output =
|
| + new ArrayOutputStream(buffer, kBufferSize, kBlockSizes[i]);
|
| + CodedOutputStream* coded_output = new CodedOutputStream(output);
|
| + coded_output->WriteVarint32(strlen(strA));
|
| + coded_output->WriteRaw(strA, strlen(strA));
|
| + delete coded_output; // flush
|
| + int64 pos = output->ByteCount();
|
| + delete output;
|
| + output = new ArrayOutputStream(
|
| + buffer + pos, kBufferSize - pos, kBlockSizes[i]);
|
| + coded_output = new CodedOutputStream(output);
|
| + coded_output->WriteVarint32(strlen(strB));
|
| + coded_output->WriteRaw(strB, strlen(strB));
|
| + delete coded_output; // flush
|
| + int64 size = pos + output->ByteCount();
|
| + delete output;
|
| +
|
| + ArrayInputStream* input =
|
| + new ArrayInputStream(buffer, size, kBlockSizes[j]);
|
| + CodedInputStream* coded_input = new CodedInputStream(input);
|
| + uint32 insize;
|
| + EXPECT_TRUE(coded_input->ReadVarint32(&insize));
|
| + EXPECT_EQ(strlen(strA), insize);
|
| + EXPECT_TRUE(coded_input->ReadRaw(temp_buffer, insize));
|
| + EXPECT_EQ(0, memcmp(temp_buffer, strA, insize));
|
| +
|
| + EXPECT_TRUE(coded_input->ReadVarint32(&insize));
|
| + EXPECT_EQ(strlen(strB), insize);
|
| + EXPECT_TRUE(coded_input->ReadRaw(temp_buffer, insize));
|
| + EXPECT_EQ(0, memcmp(temp_buffer, strB, insize));
|
| +
|
| + delete coded_input;
|
| + delete input;
|
| + }
|
| + }
|
| +
|
| + delete [] temp_buffer;
|
| + delete [] buffer;
|
| +}
|
| +
|
| #if HAVE_ZLIB
|
| TEST_F(IoTest, GzipIo) {
|
| const int kBufferSize = 2*1024;
|
| @@ -296,8 +348,12 @@ TEST_F(IoTest, GzipIo) {
|
| int size;
|
| {
|
| ArrayOutputStream output(buffer, kBufferSize, kBlockSizes[i]);
|
| - GzipOutputStream gzout(
|
| - &output, GzipOutputStream::GZIP, gzip_buffer_size);
|
| + GzipOutputStream::Options options;
|
| + options.format = GzipOutputStream::GZIP;
|
| + if (gzip_buffer_size != -1) {
|
| + options.buffer_size = gzip_buffer_size;
|
| + }
|
| + GzipOutputStream gzout(&output, options);
|
| WriteStuff(&gzout);
|
| gzout.Close();
|
| size = output.ByteCount();
|
| @@ -324,8 +380,12 @@ TEST_F(IoTest, ZlibIo) {
|
| int size;
|
| {
|
| ArrayOutputStream output(buffer, kBufferSize, kBlockSizes[i]);
|
| - GzipOutputStream gzout(
|
| - &output, GzipOutputStream::ZLIB, gzip_buffer_size);
|
| + GzipOutputStream::Options options;
|
| + options.format = GzipOutputStream::ZLIB;
|
| + if (gzip_buffer_size != -1) {
|
| + options.buffer_size = gzip_buffer_size;
|
| + }
|
| + GzipOutputStream gzout(&output, options);
|
| WriteStuff(&gzout);
|
| gzout.Close();
|
| size = output.ByteCount();
|
| @@ -348,7 +408,9 @@ TEST_F(IoTest, ZlibIoInputAutodetect) {
|
| int size;
|
| {
|
| ArrayOutputStream output(buffer, kBufferSize);
|
| - GzipOutputStream gzout(&output, GzipOutputStream::ZLIB);
|
| + GzipOutputStream::Options options;
|
| + options.format = GzipOutputStream::ZLIB;
|
| + GzipOutputStream gzout(&output, options);
|
| WriteStuff(&gzout);
|
| gzout.Close();
|
| size = output.ByteCount();
|
| @@ -360,7 +422,9 @@ TEST_F(IoTest, ZlibIoInputAutodetect) {
|
| }
|
| {
|
| ArrayOutputStream output(buffer, kBufferSize);
|
| - GzipOutputStream gzout(&output, GzipOutputStream::GZIP);
|
| + GzipOutputStream::Options options;
|
| + options.format = GzipOutputStream::GZIP;
|
| + GzipOutputStream gzout(&output, options);
|
| WriteStuff(&gzout);
|
| gzout.Close();
|
| size = output.ByteCount();
|
| @@ -432,6 +496,71 @@ TEST_F(IoTest, CompressionOptions) {
|
| EXPECT_TRUE(Uncompress(gzip_compressed) == golden);
|
| EXPECT_TRUE(Uncompress(zlib_compressed) == golden);
|
| }
|
| +
|
| +TEST_F(IoTest, TwoSessionWriteGzip) {
|
| + // Test that two concatenated gzip streams can be read correctly
|
| +
|
| + static const char* strA = "0123456789";
|
| + static const char* strB = "QuickBrownFox";
|
| + const int kBufferSize = 2*1024;
|
| + uint8* buffer = new uint8[kBufferSize];
|
| + char* temp_buffer = new char[40];
|
| +
|
| + for (int i = 0; i < kBlockSizeCount; i++) {
|
| + for (int j = 0; j < kBlockSizeCount; j++) {
|
| + ArrayOutputStream* output =
|
| + new ArrayOutputStream(buffer, kBufferSize, kBlockSizes[i]);
|
| + GzipOutputStream* gzout = new GzipOutputStream(output);
|
| + CodedOutputStream* coded_output = new CodedOutputStream(gzout);
|
| + int32 outlen = strlen(strA) + 1;
|
| + coded_output->WriteVarint32(outlen);
|
| + coded_output->WriteRaw(strA, outlen);
|
| + delete coded_output; // flush
|
| + delete gzout; // flush
|
| + int64 pos = output->ByteCount();
|
| + delete output;
|
| + output = new ArrayOutputStream(
|
| + buffer + pos, kBufferSize - pos, kBlockSizes[i]);
|
| + gzout = new GzipOutputStream(output);
|
| + coded_output = new CodedOutputStream(gzout);
|
| + outlen = strlen(strB) + 1;
|
| + coded_output->WriteVarint32(outlen);
|
| + coded_output->WriteRaw(strB, outlen);
|
| + delete coded_output; // flush
|
| + delete gzout; // flush
|
| + int64 size = pos + output->ByteCount();
|
| + delete output;
|
| +
|
| + ArrayInputStream* input =
|
| + new ArrayInputStream(buffer, size, kBlockSizes[j]);
|
| + GzipInputStream* gzin = new GzipInputStream(input);
|
| + CodedInputStream* coded_input = new CodedInputStream(gzin);
|
| + uint32 insize;
|
| + EXPECT_TRUE(coded_input->ReadVarint32(&insize));
|
| + EXPECT_EQ(strlen(strA) + 1, insize);
|
| + EXPECT_TRUE(coded_input->ReadRaw(temp_buffer, insize));
|
| + EXPECT_EQ(0, memcmp(temp_buffer, strA, insize))
|
| + << "strA=" << strA << " in=" << temp_buffer;
|
| +
|
| + EXPECT_TRUE(coded_input->ReadVarint32(&insize));
|
| + EXPECT_EQ(strlen(strB) + 1, insize);
|
| + EXPECT_TRUE(coded_input->ReadRaw(temp_buffer, insize));
|
| + EXPECT_EQ(0, memcmp(temp_buffer, strB, insize))
|
| + << " out_block_size=" << kBlockSizes[i]
|
| + << " in_block_size=" << kBlockSizes[j]
|
| + << " pos=" << pos
|
| + << " size=" << size
|
| + << " strB=" << strB << " in=" << temp_buffer;
|
| +
|
| + delete coded_input;
|
| + delete gzin;
|
| + delete input;
|
| + }
|
| + }
|
| +
|
| + delete [] temp_buffer;
|
| + delete [] buffer;
|
| +}
|
| #endif
|
|
|
| // There is no string input, only string output. Also, it doesn't support
|
|
|