Fix test to not return null from functions that are not supposed to.
The value on the test is irrelevant because we only care to know that the
dispatcher called the right function. However, it violates the `nonnull`
annotation so it should be fixed.
PiperOrigin-RevId: 810090306
diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc
index 265977e..e433a62 100644
--- a/src/google/protobuf/arena_unittest.cc
+++ b/src/google/protobuf/arena_unittest.cc
@@ -532,7 +532,8 @@
using InternalArenaConstructable_ = void;
using DestructorSkippable_ = void;
// For the test below to construct.
- explicit DispatcherTestProto(absl::in_place_t) : Message(nullptr, nullptr) {}
+ explicit constexpr DispatcherTestProto(absl::in_place_t)
+ : Message(static_cast<internal::ClassData*>(nullptr)) {}
explicit DispatcherTestProto(Arena*) : Message(nullptr, nullptr) {
ABSL_LOG(FATAL);
}
@@ -544,6 +545,8 @@
ABSL_LOG(FATAL);
}
};
+DispatcherTestProto dispatcher_test_proto_instance(absl::in_place);
+
// We use a specialization to inject behavior for the test.
// This test is very intrusive and will have to be fixed if we change the
// implementation of CreateMessage.
@@ -551,18 +554,18 @@
template <>
void* Arena::DefaultConstruct<DispatcherTestProto>(Arena*) {
hook_called = "default";
- return nullptr;
+ return &dispatcher_test_proto_instance;
}
template <>
void* Arena::CopyConstruct<DispatcherTestProto>(Arena*, const void*) {
hook_called = "copy";
- return nullptr;
+ return &dispatcher_test_proto_instance;
}
template <>
DispatcherTestProto* Arena::CreateArenaCompatible<DispatcherTestProto, int>(
Arena*, int&&) {
hook_called = "fallback";
- return nullptr;
+ return &dispatcher_test_proto_instance;
}
TEST(ArenaTest, CreateArenaConstructable) {
@@ -605,7 +608,7 @@
Arena::Create<DispatcherTestProto>(nullptr);
EXPECT_EQ(hook_called, "default");
- DispatcherTestProto ref(absl::in_place);
+ DispatcherTestProto& ref = dispatcher_test_proto_instance;
const DispatcherTestProto& cref = ref;
hook_called = "";