blob: a2e36a3a11512e1b67f2ec61044947e8a20074d5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
|