From d4cc9126fe175736090b83ada7c6bcec61111bc8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Nov 2024 12:06:23 -0800 Subject: [PATCH] Add more test coverage for arena registration. PiperOrigin-RevId: 696606741 --- .../Reflection/FeatureSetDescriptor.g.cs | 17 ----------------- src/google/protobuf/BUILD.bazel | 2 ++ .../protobuf/compiler/cpp/file_unittest.cc | 1 + src/google/protobuf/message_unittest.inc | 15 +++++++++++++++ src/google/protobuf/unittest.proto | 4 ++++ 5 files changed, 22 insertions(+), 17 deletions(-) delete mode 100644 csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs diff --git a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs b/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs deleted file mode 100644 index 208ce1fcb6..0000000000 --- a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs +++ /dev/null @@ -1,17 +0,0 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd -#endregion - -namespace Google.Protobuf.Reflection; - -internal sealed partial class FeatureSetDescriptor -{ - // Canonical serialized form of the edition defaults, generated by embed_edition_defaults. - private const string DefaultsBase64 = - "ChMYhAciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH"; -} diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 7535d9c6df..c75dfa8bfa 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -1734,6 +1734,7 @@ cc_test( ":cc_lite_test_protos", ":cc_test_protos", ":internal_visibility", + ":lite_test_util", ":port", ":protobuf", ":protobuf_lite", @@ -1766,6 +1767,7 @@ cc_test( ":arena", ":cc_test_protos", ":internal_visibility", + ":lite_test_util", ":port", ":protobuf", ":protobuf_lite", diff --git a/src/google/protobuf/compiler/cpp/file_unittest.cc b/src/google/protobuf/compiler/cpp/file_unittest.cc index ad07b07dfc..16cacf0222 100644 --- a/src/google/protobuf/compiler/cpp/file_unittest.cc +++ b/src/google/protobuf/compiler/cpp/file_unittest.cc @@ -47,6 +47,7 @@ TEST(FileTest, TopologicallyOrderedDescriptors) { "TestVerifyBigFieldNumberUint32.Nested", "TestUnpackedTypes", "TestUnpackedExtensions", + "TestString", "TestReservedFields", "TestRequiredOpenEnum", "TestRequiredOneof.NestedMessage", diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc index 7f61658da1..723b8fd19b 100644 --- a/src/google/protobuf/message_unittest.inc +++ b/src/google/protobuf/message_unittest.inc @@ -41,6 +41,7 @@ #include "absl/strings/cord.h" #include "absl/strings/substitute.h" #include "google/protobuf/arena.h" +#include "google/protobuf/arena_test_util.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/generated_message_reflection.h" @@ -58,6 +59,9 @@ // Must be included last. #include "google/protobuf/port_def.inc" +using ::testing::IsEmpty; +using ::testing::Not; + namespace google { namespace protobuf { @@ -891,6 +895,17 @@ TEST(MESSAGE_TEST_NAME, MessageDebugStringMatchesBehindPointerAndLitePointer) { ASSERT_EQ(test_all_types.DebugString(), msg_lite_pointer->DebugString()); } +TEST(MESSAGE_TEST_NAME, CordFieldGetsProperlyRegisteredInTheArena) { + Arena arena; + auto* msg = Arena::Create(&arena); + // Very large input that needs allocation. + msg->set_optional_bytes_cord(std::string(1000, 'x')); + // Something should be registered for destruction. + EXPECT_THAT(internal::ArenaTestPeer::PeekCleanupListForTesting(&arena), + Not(IsEmpty())); + // We expect memory leaks here if the Cord was not properly destroyed. +} + #if GTEST_HAS_DEATH_TEST // death tests do not work on Windows yet. TEST(MESSAGE_TEST_NAME, SerializeFailsIfNotInitialized) { diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto index b6bb06ed9f..7cdbcd28e4 100644 --- a/src/google/protobuf/unittest.proto +++ b/src/google/protobuf/unittest.proto @@ -2455,6 +2455,10 @@ extend RedactedFields { ]; } +message TestString { + string optional_string = 1; +} + message TestCord { bytes optional_bytes_cord = 1 [ ctype = CORD