Skip to content

Commit ddfdff4

Browse files
sbenzaquencopybara-github
authored andcommitted
Add missing test definition.
PiperOrigin-RevId: 871318619
1 parent 1074b28 commit ddfdff4

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/google/protobuf/BUILD.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,6 +2393,37 @@ cc_test(
23932393
],
23942394
)
23952395

2396+
cc_test(
2397+
name = "repeated_ptr_field_unittest",
2398+
srcs = [
2399+
"repeated_ptr_field_unittest.cc",
2400+
],
2401+
copts = COPTS + select({
2402+
"//build_defs:config_msvc": [],
2403+
"//conditions:default": [
2404+
"-Wno-deprecated-declarations",
2405+
],
2406+
}),
2407+
deps = [
2408+
":arena",
2409+
":cc_test_protos",
2410+
":lite_test_util",
2411+
":port",
2412+
":protobuf",
2413+
":protobuf_lite",
2414+
":test_util",
2415+
"//src/google/protobuf/io",
2416+
"@abseil-cpp//absl/flags:flag",
2417+
"@abseil-cpp//absl/log:absl_check",
2418+
"@abseil-cpp//absl/numeric:bits",
2419+
"@abseil-cpp//absl/strings",
2420+
"@abseil-cpp//absl/types:optional",
2421+
"@abseil-cpp//absl/types:span",
2422+
"@googletest//:gtest",
2423+
"@googletest//:gtest_main",
2424+
],
2425+
)
2426+
23962427
cc_test(
23972428
name = "text_format_unittest",
23982429
srcs = ["text_format_unittest.cc"],

src/google/protobuf/repeated_ptr_field_unittest.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,12 +897,15 @@ TEST(RepeatedPtrFieldTest, SmallOptimization) {
897897
EXPECT_EQ(array->SpaceUsedExcludingSelf(), 0);
898898
std::string str;
899899
auto usage_before = arena.SpaceUsed();
900+
901+
using H = internal::GenericTypeHandler<std::string>;
902+
900903
// We use UnsafeArenaAddAllocated just to grow the array without creating
901904
// objects or causing extra cleanup costs in the arena to make the
902905
// measurements simpler.
903906
array->UnsafeArenaAddAllocated(&str);
904907
// No backing array, just the string.
905-
EXPECT_EQ(array->SpaceUsedExcludingSelf(), sizeof(str));
908+
EXPECT_EQ(array->SpaceUsedExcludingSelf(), H::SpaceUsedLong(str));
906909
// We have not used any arena space.
907910
EXPECT_EQ(usage_before, arena.SpaceUsed());
908911
// Verify the string is where we think it is.
@@ -923,9 +926,9 @@ TEST(RepeatedPtrFieldTest, SmallOptimization) {
923926
// Backing array and the strings. sizeof(Rep) = 2 * sizeof(int) for capacity
924927
// and allocated_size. Each element of the Rep contributes sizeof(void*),
925928
// and each string contributes sizeof(str) to arena memory.
926-
EXPECT_EQ(
927-
array->SpaceUsedExcludingSelf(),
928-
2 * sizeof(int) + array->Capacity() * sizeof(void*) + 2 * sizeof(str));
929+
EXPECT_EQ(array->SpaceUsedExcludingSelf(),
930+
2 * sizeof(int) + array->Capacity() * sizeof(void*) +
931+
H::SpaceUsedLong(str) + H::SpaceUsedLong(str2));
929932
// We used some arena space now.
930933
EXPECT_LT(usage_before, arena.SpaceUsed());
931934
// And the pointer_begin is not in the sso anymore.

0 commit comments

Comments
 (0)