Update tests to use noncontiguous API

PiperOrigin-RevId: 696179419
pull/19242/head
Protobuf Team Bot 2 weeks ago committed by Copybara-Service
parent e4dcf0e521
commit c1a4f28752
  1. 17
      csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs
  2. 13
      upb/message/copy_test.cc
  3. 16
      upb/message/promote_test.cc

@ -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";
}

@ -326,12 +326,13 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) {
upb_Arena_Free(unknown_arena); upb_Arena_Free(unknown_arena);
upb_Arena_Free(encode_arena); upb_Arena_Free(encode_arena);
// Read unknown data from clone and verify. // Read unknown data from clone and verify.
size_t cloned_length; std::string cloned_unknown_data;
const char* cloned_unknown_data = upb_StringView unknown;
upb_Message_GetUnknown(UPB_UPCAST(clone), &cloned_length); uintptr_t iter = kUpb_Message_UnknownBegin;
EXPECT_EQ(cloned_length, len); while (upb_Message_NextUnknown(UPB_UPCAST(clone), &unknown, &iter)) {
EXPECT_EQ(memcmp(cloned_unknown_data, unknown_data.c_str(), cloned_length), cloned_unknown_data.append(unknown.data, unknown.size);
0); }
EXPECT_EQ(unknown_data, cloned_unknown_data);
upb_Arena_Free(clone_arena); upb_Arena_Free(clone_arena);
} }

@ -48,6 +48,16 @@
namespace { 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) { TEST(GeneratedCode, FindUnknown) {
upb_Arena* arena = upb_Arena_New(); upb_Arena* arena = upb_Arena_New();
upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena); upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena);
@ -182,8 +192,7 @@ TEST(GeneratedCode, Extensions) {
arena); arena);
// Get unknown extension bytes before promotion. // Get unknown extension bytes before promotion.
size_t start_len; size_t start_len = GetUnknownLength(UPB_UPCAST(base_msg));
upb_Message_GetUnknown(UPB_UPCAST(base_msg), &start_len);
EXPECT_GT(start_len, 0); EXPECT_GT(start_len, 0);
EXPECT_EQ(0, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); 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(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2));
size_t end_len; size_t end_len = GetUnknownLength(UPB_UPCAST(base_msg));
upb_Message_GetUnknown(UPB_UPCAST(base_msg), &end_len);
EXPECT_LT(end_len, start_len); EXPECT_LT(end_len, start_len);
EXPECT_EQ(6, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); EXPECT_EQ(6, upb_Message_ExtensionCount(UPB_UPCAST(base_msg)));

Loading…
Cancel
Save