Skip to content

Commit

Permalink
Test part: upb CopyFrom the default empty message should just clear i…
Browse files Browse the repository at this point in the history
…nstead of deep copy

from memory

fix #13485

PiperOrigin-RevId: 559888172
  • Loading branch information
anandolee authored and copybara-github committed Aug 24, 2023
1 parent 06c25f5 commit 836fb65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions protobuf_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ def protobuf_deps():
_github_archive(
name = "upb",
repo = "https://github.com/protocolbuffers/upb",
commit = "823a12e80934f9c8fb9178191d69f06a1bbfd604",
sha256 = "165f425714d32018a1a856b1935cfa24206878f8a469384808d2dce1d7c4003a",
commit = "57636ce03ac1e2aab3a362a61a6664981e21cda5",
sha256 = "75da534db927e165cb550d232c35e2dec4b5153b3b47989b250d75febbfc1710",
)
16 changes: 16 additions & 0 deletions python/google/protobuf/internal/message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,22 @@ def testUnknownFieldPrinting(self, message_module):
empty.ParseFromString(populated.SerializeToString())
self.assertEqual(str(empty), '')

def testCopyFromEmpty(self, message_module):
msg = message_module.NestedTestAllTypes()
test_msg = message_module.NestedTestAllTypes()
test_util.SetAllFields(test_msg.payload)
self.assertTrue(test_msg.HasField('payload'))
# Copy from empty message
test_msg.CopyFrom(msg)
self.assertEqual(0, len(test_msg.ListFields()))

test_util.SetAllFields(test_msg.payload)
self.assertTrue(test_msg.HasField('payload'))
# Copy from a non exist message
test_msg.CopyFrom(msg.child)
self.assertFalse(test_msg.HasField('payload'))
self.assertEqual(0, len(test_msg.ListFields()))

def testAppendRepeatedCompositeField(self, message_module):
msg = message_module.TestAllTypes()
msg.repeated_nested_message.append(
Expand Down

0 comments on commit 836fb65

Please sign in to comment.