From 03ed5d970b66fd3429311497192e6b44ecb4f193 Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Fri, 25 Oct 2024 09:54:03 -0700 Subject: [PATCH] Directly test calling ByteSizeLong() on default instances. These instances may be in `.rodata`, so ByteSizeLong() cannot write to the _cached_size_. The call itself should succeed. PiperOrigin-RevId: 689822451 --- src/google/protobuf/message_unittest.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc index b518c0bb40..832e3feddb 100644 --- a/src/google/protobuf/message_unittest.inc +++ b/src/google/protobuf/message_unittest.inc @@ -420,6 +420,12 @@ TEST(MESSAGE_TEST_NAME, UnparsedEmpty) { EXPECT_EQ(message.lazy_child().ByteSizeLong(), 0); } +TEST(MESSAGE_TEST_NAME, DefaultInstanceByteSizeLong) { + EXPECT_EQ(UNITTEST::NestedTestAllTypes::default_instance().ByteSizeLong(), 0); + EXPECT_EQ(UNITTEST::NestedTestAllTypes::default_instance().GetCachedSize(), + 0); +} + TEST(MESSAGE_TEST_NAME, ParseFailNonCanonicalZeroTag) { const char encoded[] = {"\n\x3\x80\0\0"}; UNITTEST::NestedTestAllTypes parsed;