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:
authorJacques Lucke <jacques@blender.org>2022-03-19 12:57:40 +0300
committerJacques Lucke <jacques@blender.org>2022-03-19 12:57:40 +0300
commit8711483632823524019a6cc95575c5a4ba5aa831 (patch)
tree76c2f8355d0fce66f4f9e35b5ec1282960e51209 /source/blender/blenlib/tests
parent3e16f3b3ef4b8f385b30fe4a1e00860620f610ee (diff)
BLI: generalize converting CPPType to static type
Previously, the conversion was done manually for a fixed set of types. Now, there is a more general utility that can be used in other contexts (outside of geometry nodes attribute processing) as well.
Diffstat (limited to 'source/blender/blenlib/tests')
-rw-r--r--source/blender/blenlib/tests/BLI_cpp_type_test.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_cpp_type_test.cc b/source/blender/blenlib/tests/BLI_cpp_type_test.cc
index c7e6ed47b24..94456e1ee28 100644
--- a/source/blender/blenlib/tests/BLI_cpp_type_test.cc
+++ b/source/blender/blenlib/tests/BLI_cpp_type_test.cc
@@ -323,4 +323,28 @@ TEST(cpp_type, DebugPrint)
EXPECT_EQ(text, "42");
}
+TEST(cpp_type, ToStaticType)
+{
+ Vector<const CPPType *> types;
+ bool found_unsupported_type = false;
+ auto fn = [&](auto type_tag) {
+ using T = typename decltype(type_tag)::type;
+ if constexpr (!std::is_same_v<T, void>) {
+ types.append(&CPPType::get<T>());
+ }
+ else {
+ found_unsupported_type = true;
+ }
+ };
+ CPPType::get<std::string>().to_static_type_tag<int, float, std::string>(fn);
+ CPPType::get<float>().to_static_type_tag<int, float, std::string>(fn);
+ EXPECT_FALSE(found_unsupported_type);
+ CPPType::get<int64_t>().to_static_type_tag<int, float, std::string>(fn);
+ EXPECT_TRUE(found_unsupported_type);
+
+ EXPECT_EQ(types.size(), 2);
+ EXPECT_EQ(types[0], &CPPType::get<std::string>());
+ EXPECT_EQ(types[1], &CPPType::get<float>());
+}
+
} // namespace blender::tests