Skip to content

Commit

Permalink
Update tests to use noncontiguous API
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 696179419
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 13, 2024
1 parent e4dcf0e commit c1a4f28
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
17 changes: 0 additions & 17 deletions csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs

This file was deleted.

13 changes: 7 additions & 6 deletions upb/message/copy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 12 additions & 4 deletions upb/message/promote_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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)));

Expand Down

0 comments on commit c1a4f28

Please sign in to comment.