Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/tests/BLI_cpp_type_test.cc
| Show First 20 Lines • Show All 317 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| int value = 42; | int value = 42; | ||||
| std::stringstream ss; | std::stringstream ss; | ||||
| CPPType::get<int32_t>().print((void *)&value, ss); | CPPType::get<int32_t>().print((void *)&value, ss); | ||||
| std::string text = ss.str(); | std::string text = ss.str(); | ||||
| EXPECT_EQ(text, "42"); | 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 | } // namespace blender::tests | ||||