diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2014-11-10 17:34:54 -0800 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2014-11-10 17:34:54 -0800 |
commit | 6ef984af4b0c63c1c33127a12dcfc8e6359f0c9e (patch) | |
tree | d17c61ff9f3ae28224fbddac6d26bfc59e2cf755 /src/google/protobuf/message_unittest.cc | |
parent | baca1a8a1aa180c42de6278d3b8286c4496c6a10 (diff) |
Down-integrate from internal code base.
Diffstat (limited to 'src/google/protobuf/message_unittest.cc')
-rw-r--r-- | src/google/protobuf/message_unittest.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index a5f339f1..ebfb4321 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -242,6 +242,25 @@ TEST(MessageTest, CheckOverflow) { #endif // PROTOBUF_HAS_DEATH_TEST +namespace { + +class NegativeByteSize : public unittest::TestRequired { + public: + virtual int ByteSize() const { return -1; } +}; + +} // namespace + +TEST(MessageTest, SerializationFailsOnNegativeByteSize) { + NegativeByteSize message; + string string_output; + EXPECT_FALSE(message.AppendPartialToString(&string_output)); + + io::ArrayOutputStream coded_raw_output(NULL, 100); + io::CodedOutputStream coded_output(&coded_raw_output); + EXPECT_FALSE(message.SerializePartialToCodedStream(&coded_output)); +} + TEST(MessageTest, BypassInitializationCheckOnSerialize) { unittest::TestRequired message; io::ArrayOutputStream raw_output(NULL, 0); |