From c1a4f28752e18703471160fdfa7606d0e8fec234 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 13 Nov 2024 10:12:38 -0800 Subject: [PATCH] Update tests to use noncontiguous API PiperOrigin-RevId: 696179419 --- .../Reflection/FeatureSetDescriptor.g.cs | 17 ----------------- upb/message/copy_test.cc | 13 +++++++------ upb/message/promote_test.cc | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 27 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/upb/message/copy_test.cc b/upb/message/copy_test.cc index 1bdb3a3099..af0c4a96b1 100644 --- a/upb/message/copy_test.cc +++ b/upb/message/copy_test.cc @@ -326,12 +326,13 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) { upb_Arena_Free(unknown_arena); upb_Arena_Free(encode_arena); // Read unknown data from clone and verify. - size_t cloned_length; - const char* cloned_unknown_data = - upb_Message_GetUnknown(UPB_UPCAST(clone), &cloned_length); - EXPECT_EQ(cloned_length, len); - EXPECT_EQ(memcmp(cloned_unknown_data, unknown_data.c_str(), cloned_length), - 0); + std::string cloned_unknown_data; + upb_StringView unknown; + uintptr_t iter = kUpb_Message_UnknownBegin; + while (upb_Message_NextUnknown(UPB_UPCAST(clone), &unknown, &iter)) { + cloned_unknown_data.append(unknown.data, unknown.size); + } + EXPECT_EQ(unknown_data, cloned_unknown_data); upb_Arena_Free(clone_arena); } diff --git a/upb/message/promote_test.cc b/upb/message/promote_test.cc index 19ca17d61d..a6aab32179 100644 --- a/upb/message/promote_test.cc +++ b/upb/message/promote_test.cc @@ -48,6 +48,16 @@ namespace { +size_t GetUnknownLength(const upb_Message* msg) { + size_t len = 0; + upb_StringView data; + uintptr_t iter = kUpb_Message_UnknownBegin; + while (upb_Message_NextUnknown(msg, &data, &iter)) { + len += data.size; + } + return len; +} + TEST(GeneratedCode, FindUnknown) { upb_Arena* arena = upb_Arena_New(); upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena); @@ -182,8 +192,7 @@ TEST(GeneratedCode, Extensions) { arena); // Get unknown extension bytes before promotion. - size_t start_len; - upb_Message_GetUnknown(UPB_UPCAST(base_msg), &start_len); + size_t start_len = GetUnknownLength(UPB_UPCAST(base_msg)); EXPECT_GT(start_len, 0); EXPECT_EQ(0, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); @@ -236,8 +245,7 @@ TEST(GeneratedCode, Extensions) { EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2)); - size_t end_len; - upb_Message_GetUnknown(UPB_UPCAST(base_msg), &end_len); + size_t end_len = GetUnknownLength(UPB_UPCAST(base_msg)); EXPECT_LT(end_len, start_len); EXPECT_EQ(6, upb_Message_ExtensionCount(UPB_UPCAST(base_msg)));