|
76 | 76 | // Must be included last. |
77 | 77 | #include "google/protobuf/port_def.inc" |
78 | 78 |
|
| 79 | +using ::testing::ElementsAre; |
| 80 | +using ::testing::Pair; |
| 81 | + |
79 | 82 | namespace google { |
80 | 83 | namespace protobuf { |
81 | 84 |
|
@@ -3639,6 +3642,35 @@ TEST(WireFormatForMapFieldTest, MapParseHelpers) { |
3639 | 3642 | } |
3640 | 3643 | } |
3641 | 3644 |
|
| 3645 | +std::string WriteVarint(int number, uint64_t v) { |
| 3646 | + uint8_t buf[16]; |
| 3647 | + return std::string(buf, WireFormatLite::WriteUInt64ToArray(number, v, buf)); |
| 3648 | +} |
| 3649 | + |
| 3650 | +std::string WriteString(int number, const std::string& str) { |
| 3651 | + uint8_t buf[100]; |
| 3652 | + return std::string(buf, WireFormatLite::WriteStringToArray(number, str, buf)); |
| 3653 | +} |
| 3654 | + |
| 3655 | +TEST(WireFormatForMapFieldTest, BoolWorksWithOverlongValues) { |
| 3656 | + // map<bool, bool> map_bool_bool = 13; |
| 3657 | + for (uint64_t v : {uint64_t{1}, uint64_t{1000}, uint64_t{100000}, |
| 3658 | + uint64_t{1} << 32, uint64_t{1} << 63}) { |
| 3659 | + SCOPED_TRACE(v); |
| 3660 | + std::string payload = |
| 3661 | + WriteString(13, WriteVarint(1, v) + WriteVarint(2, v)); |
| 3662 | + UNITTEST::TestMap obj; |
| 3663 | + ASSERT_TRUE(obj.ParseFromString(payload)); |
| 3664 | + EXPECT_THAT(obj.map_bool_bool(), ElementsAre(Pair(true, true))); |
| 3665 | + |
| 3666 | + io::ArrayInputStream raw_input(payload.data(), payload.size()); |
| 3667 | + io::CodedInputStream input(&raw_input); |
| 3668 | + obj.Clear(); |
| 3669 | + ASSERT_TRUE(WireFormat::ParseAndMergePartial(&input, &obj)); |
| 3670 | + EXPECT_THAT(obj.map_bool_bool(), ElementsAre(Pair(true, true))); |
| 3671 | + } |
| 3672 | +} |
| 3673 | + |
3642 | 3674 | // Deterministic Serialization Test ========================================== |
3643 | 3675 |
|
3644 | 3676 | template <typename T> |
|
0 commit comments