diff options
Diffstat (limited to 'abseil-cpp/absl/functional/function_ref_test.cc')
-rw-r--r-- | abseil-cpp/absl/functional/function_ref_test.cc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/abseil-cpp/absl/functional/function_ref_test.cc b/abseil-cpp/absl/functional/function_ref_test.cc index 3aa5974..c61117e 100644 --- a/abseil-cpp/absl/functional/function_ref_test.cc +++ b/abseil-cpp/absl/functional/function_ref_test.cc @@ -14,11 +14,13 @@ #include "absl/functional/function_ref.h" +#include <functional> #include <memory> #include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/container/internal/test_instance_tracker.h" +#include "absl/functional/any_invocable.h" #include "absl/memory/memory.h" namespace absl { @@ -156,6 +158,25 @@ TEST(FunctionRef, NullMemberPtrAssertFails) { EXPECT_DEBUG_DEATH({ FunctionRef<int(const S& s)> ref(mem_ptr); }, ""); } +TEST(FunctionRef, NullStdFunctionAssertPasses) { + std::function<void()> function = []() {}; + FunctionRef<void()> ref(function); +} + +TEST(FunctionRef, NullStdFunctionAssertFails) { + std::function<void()> function = nullptr; + EXPECT_DEBUG_DEATH({ FunctionRef<void()> ref(function); }, ""); +} + +TEST(FunctionRef, NullAnyInvocableAssertPasses) { + AnyInvocable<void() const> invocable = []() {}; + FunctionRef<void()> ref(invocable); +} +TEST(FunctionRef, NullAnyInvocableAssertFails) { + AnyInvocable<void() const> invocable = nullptr; + EXPECT_DEBUG_DEATH({ FunctionRef<void()> ref(invocable); }, ""); +} + #endif // GTEST_HAS_DEATH_TEST TEST(FunctionRef, CopiesAndMovesPerPassByValue) { @@ -236,7 +257,7 @@ TEST(FunctionRef, PassByValueTypes) { "Reference types should be preserved"); // Make sure the address of an object received by reference is the same as the - // addess of the object passed by the caller. + // address of the object passed by the caller. { LargeTrivial obj; auto test = [&obj](LargeTrivial& input) { ASSERT_EQ(&input, &obj); }; @@ -252,6 +273,16 @@ TEST(FunctionRef, PassByValueTypes) { } } +TEST(FunctionRef, ReferenceToIncompleteType) { + struct IncompleteType; + auto test = [](IncompleteType&) {}; + absl::FunctionRef<void(IncompleteType&)> ref(test); + + struct IncompleteType {}; + IncompleteType obj; + ref(obj); +} + } // namespace ABSL_NAMESPACE_END } // namespace absl |