diff options
author | Byron Yi <byi@connect.ust.hk> | 2017-03-16 20:01:22 +0800 |
---|---|---|
committer | Byron Yi <byi@connect.ust.hk> | 2017-03-16 20:01:22 +0800 |
commit | cb3e84b78edf0725c3ee3e3e00469e1a25fac8b8 (patch) | |
tree | 2b8d3603940e0aa884f4dc2fc56e831828eb21a5 /src/google/protobuf/util/delimited_message_util_test.cc | |
parent | 4842363ee6db57b2edf056708a5688424d1b7abf (diff) |
migrate delimited messages functions to util package
Diffstat (limited to 'src/google/protobuf/util/delimited_message_util_test.cc')
-rw-r--r-- | src/google/protobuf/util/delimited_message_util_test.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/google/protobuf/util/delimited_message_util_test.cc b/src/google/protobuf/util/delimited_message_util_test.cc new file mode 100644 index 00000000..0954773b --- /dev/null +++ b/src/google/protobuf/util/delimited_message_util_test.cc @@ -0,0 +1,57 @@ +// Adapted from the patch of kenton@google.com (Kenton Varda) +// See https://github.com/google/protobuf/pull/710 for details. + +#include <google/protobuf/util/delimited_message_util.h> + +#include <sstream> + +#include <google/protobuf/test_util.h> +#include <google/protobuf/unittest.pb.h> +#include <google/protobuf/testing/googletest.h> +#include <gtest/gtest.h> + +namespace google { +namespace protobuf { +namespace util { + +TEST(MessageTest, DelimitedMessages) { + stringstream stream; + + { + protobuf_unittest::TestAllTypes message1; + TestUtil::SetAllFields(&message1); + EXPECT_TRUE(SerializeDelimitedToOstream(&message1, &stream)); + + protobuf_unittest::TestPackedTypes message2; + TestUtil::SetPackedFields(&message2); + EXPECT_TRUE(SerializeDelimitedToOstream(&message2, &stream)); + } + + { + bool clean_eof; + io::IstreamInputStream zstream(&stream); + + protobuf_unittest::TestAllTypes message1; + clean_eof = true; + EXPECT_TRUE(ParseDelimitedFromZeroCopyStream(&message1, + &zstream, &clean_eof)); + EXPECT_FALSE(clean_eof); + TestUtil::ExpectAllFieldsSet(message1); + + protobuf_unittest::TestPackedTypes message2; + clean_eof = true; + EXPECT_TRUE(ParseDelimitedFromZeroCopyStream(&message2, + &zstream, &clean_eof)); + EXPECT_FALSE(clean_eof); + TestUtil::ExpectPackedFieldsSet(message2); + + clean_eof = false; + EXPECT_FALSE(ParseDelimitedFromZeroCopyStream(&message2, + &zstream, &clean_eof)); + EXPECT_TRUE(clean_eof); + } +} + +} // namespace util +} // namespace protobuf +} // namespace google |