Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/tests/BLI_function_ref_test.cc')
-rw-r--r--source/blender/blenlib/tests/BLI_function_ref_test.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_function_ref_test.cc b/source/blender/blenlib/tests/BLI_function_ref_test.cc
index cdcbccc72e8..74f5014142c 100644
--- a/source/blender/blenlib/tests/BLI_function_ref_test.cc
+++ b/source/blender/blenlib/tests/BLI_function_ref_test.cc
@@ -99,4 +99,29 @@ TEST(function_ref, ReferenceAnotherFunctionRef)
EXPECT_EQ(y(), 2);
}
+TEST(function_ref, CallSafe)
+{
+ FunctionRef<int()> f;
+ EXPECT_FALSE(f.call_safe().has_value());
+ auto func = []() { return 10; };
+ f = func;
+ EXPECT_TRUE(f.call_safe().has_value());
+ EXPECT_EQ(*f.call_safe(), 10);
+ f = {};
+ EXPECT_FALSE(f.call_safe().has_value());
+ BLI_STATIC_ASSERT((std::is_same_v<decltype(f.call_safe()), std::optional<int>>), "");
+}
+
+TEST(function_ref, CallSafeVoid)
+{
+ FunctionRef<void()> f;
+ BLI_STATIC_ASSERT((std::is_same_v<decltype(f.call_safe()), void>), "");
+ f.call_safe();
+ int value = 0;
+ auto func = [&]() { value++; };
+ f = func;
+ f.call_safe();
+ EXPECT_EQ(value, 1);
+}
+
} // namespace blender::tests