Add unit test enum showing allocation in repeated enum lists

TestPackedTypes' field is unused, it's just there to make the messages symmetric between packed and unpacked versions.

PiperOrigin-RevId: 628913968
pull/16586/head
Protobuf Team Bot 10 months ago committed by Copybara-Service
parent ea4c77ca48
commit b3e7a00774
  1. 4
      python/google/protobuf/internal/descriptor_test.py
  2. 30
      python/google/protobuf/internal/reflection_test.py
  3. 4
      src/google/protobuf/compiler/cpp/unittest.inc
  4. 1
      src/google/protobuf/unittest.proto
  5. 3
      src/google/protobuf/unittest_proto3.proto
  6. 1
      src/google/protobuf/unittest_proto3_arena.proto

@ -884,6 +884,10 @@ class DescriptorCopyToProtoTest(unittest.TestCase):
name: 'FOREIGN_BAX'
number: 32
>
value: <
name: 'FOREIGN_LARGE'
number: 123456
>
"""
self._InternalTestCopyToProto(

@ -594,19 +594,37 @@ class ReflectionTest(unittest.TestCase):
def testEnum_KeysAndValues(self, message_module):
if message_module == unittest_pb2:
keys = ['FOREIGN_FOO', 'FOREIGN_BAR', 'FOREIGN_BAZ', 'FOREIGN_BAX']
values = [4, 5, 6, 32]
keys = [
'FOREIGN_FOO',
'FOREIGN_BAR',
'FOREIGN_BAZ',
'FOREIGN_BAX',
'FOREIGN_LARGE',
]
values = [4, 5, 6, 32, 123456]
items = [
('FOREIGN_FOO', 4),
('FOREIGN_BAR', 5),
('FOREIGN_BAZ', 6),
('FOREIGN_BAX', 32),
('FOREIGN_LARGE', 123456),
]
else:
keys = ['FOREIGN_ZERO', 'FOREIGN_FOO', 'FOREIGN_BAR', 'FOREIGN_BAZ']
values = [0, 4, 5, 6]
items = [('FOREIGN_ZERO', 0), ('FOREIGN_FOO', 4),
('FOREIGN_BAR', 5), ('FOREIGN_BAZ', 6)]
keys = [
'FOREIGN_ZERO',
'FOREIGN_FOO',
'FOREIGN_BAR',
'FOREIGN_BAZ',
'FOREIGN_LARGE',
]
values = [0, 4, 5, 6, 123456]
items = [
('FOREIGN_ZERO', 0),
('FOREIGN_FOO', 4),
('FOREIGN_BAR', 5),
('FOREIGN_BAZ', 6),
('FOREIGN_LARGE', 123456),
]
self.assertEqual(keys,
list(message_module.ForeignEnum.keys()))
self.assertEqual(values,

@ -1022,8 +1022,8 @@ TEST(GENERATED_ENUM_TEST_NAME, MinAndMax) {
EXPECT_EQ(4, UNITTEST::TestAllTypes::NestedEnum_ARRAYSIZE);
EXPECT_EQ(UNITTEST::FOREIGN_FOO, UNITTEST::ForeignEnum_MIN);
EXPECT_EQ(UNITTEST::FOREIGN_BAX, UNITTEST::ForeignEnum_MAX);
EXPECT_EQ(33, UNITTEST::ForeignEnum_ARRAYSIZE);
EXPECT_EQ(UNITTEST::FOREIGN_LARGE, UNITTEST::ForeignEnum_MAX);
EXPECT_EQ(123457, UNITTEST::ForeignEnum_ARRAYSIZE);
EXPECT_EQ(1, UNITTEST::TestEnumWithDupValue_MIN);
EXPECT_EQ(3, UNITTEST::TestEnumWithDupValue_MAX);

@ -198,6 +198,7 @@ enum ForeignEnum {
FOREIGN_BAR = 5;
FOREIGN_BAZ = 6;
FOREIGN_BAX = 32; // (1 << 32) to generate a 64b bitmask would be incorrect.
FOREIGN_LARGE = 123456; // Large enough to escape the Boxed Integer cache.
}
message TestReservedFields {

@ -114,7 +114,7 @@ message TestAllTypes {
repeated string repeated_string_piece = 54 [ctype = STRING_PIECE];
repeated string repeated_cord = 55 [ctype = CORD];
repeated NestedMessage repeated_lazy_message = 57 ;
repeated NestedMessage repeated_lazy_message = 57;
oneof oneof_field {
uint32 oneof_uint32 = 111;
@ -178,6 +178,7 @@ enum ForeignEnum {
FOREIGN_FOO = 4;
FOREIGN_BAR = 5;
FOREIGN_BAZ = 6;
FOREIGN_LARGE = 123456; // Large enough to escape the Boxed Integer cache.
}
// TestEmptyMessage is used to test behavior of unknown fields.

@ -197,6 +197,7 @@ enum ForeignEnum {
FOREIGN_FOO = 4;
FOREIGN_BAR = 5;
FOREIGN_BAZ = 6;
FOREIGN_LARGE = 123456; // Large enough to escape the Boxed Integer cache.
}
// TestEmptyMessage is used to test behavior of unknown fields.

Loading…
Cancel
Save