diff options
author | Jacques Lucke <jacques@blender.org> | 2021-06-28 14:13:52 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-06-28 14:16:32 +0300 |
commit | 7d281a4f7d354d270fc9c9f3c7a65b4409362aa0 (patch) | |
tree | 6a749a4833bdf543a10d95881fcca52ba310248b /source/blender/functions/tests | |
parent | f7e2559fd649610881b1749b6d30cc2ba9fcbdb6 (diff) |
Functions: improve CPPType
* Reduce code duplication.
* Give methods more standardized names (e.g. `move_to_initialized` -> `move_assign`).
* Support wrapping arbitrary C++ types, even those that e.g. are not copyable.
Diffstat (limited to 'source/blender/functions/tests')
-rw-r--r-- | source/blender/functions/tests/FN_cpp_type_test.cc | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/source/blender/functions/tests/FN_cpp_type_test.cc b/source/blender/functions/tests/FN_cpp_type_test.cc index 3f92d2e1ac6..ffa3050f5a4 100644 --- a/source/blender/functions/tests/FN_cpp_type_test.cc +++ b/source/blender/functions/tests/FN_cpp_type_test.cc @@ -76,7 +76,7 @@ struct TestType { } // namespace blender::fn::tests -MAKE_CPP_TYPE(TestType, blender::fn::tests::TestType) +MAKE_CPP_TYPE(TestType, blender::fn::tests::TestType, CPPTypeFlags::BasicType) namespace blender::fn::tests { @@ -101,15 +101,15 @@ TEST(cpp_type, Is) TEST(cpp_type, DefaultConstruction) { int buffer[10] = {0}; - CPPType_TestType.construct_default((void *)buffer); + CPPType_TestType.default_construct((void *)buffer); EXPECT_EQ(buffer[0], default_constructed_value); EXPECT_EQ(buffer[1], 0); - CPPType_TestType.construct_default_n((void *)buffer, 3); + CPPType_TestType.default_construct_n((void *)buffer, 3); EXPECT_EQ(buffer[0], default_constructed_value); EXPECT_EQ(buffer[1], default_constructed_value); EXPECT_EQ(buffer[2], default_constructed_value); EXPECT_EQ(buffer[3], 0); - CPPType_TestType.construct_default_indices((void *)buffer, {2, 5, 7}); + CPPType_TestType.default_construct_indices((void *)buffer, {2, 5, 7}); EXPECT_EQ(buffer[2], default_constructed_value); EXPECT_EQ(buffer[4], 0); EXPECT_EQ(buffer[5], default_constructed_value); @@ -142,10 +142,10 @@ TEST(cpp_type, CopyToUninitialized) { int buffer1[10] = {0}; int buffer2[10] = {0}; - CPPType_TestType.copy_to_uninitialized((void *)buffer1, (void *)buffer2); + CPPType_TestType.copy_construct((void *)buffer1, (void *)buffer2); EXPECT_EQ(buffer1[0], copy_constructed_from_value); EXPECT_EQ(buffer2[0], copy_constructed_value); - CPPType_TestType.copy_to_uninitialized_n((void *)buffer1, (void *)buffer2, 3); + CPPType_TestType.copy_construct_n((void *)buffer1, (void *)buffer2, 3); EXPECT_EQ(buffer1[0], copy_constructed_from_value); EXPECT_EQ(buffer2[0], copy_constructed_value); EXPECT_EQ(buffer1[1], copy_constructed_from_value); @@ -154,7 +154,7 @@ TEST(cpp_type, CopyToUninitialized) EXPECT_EQ(buffer2[2], copy_constructed_value); EXPECT_EQ(buffer1[3], 0); EXPECT_EQ(buffer2[3], 0); - CPPType_TestType.copy_to_uninitialized_indices((void *)buffer1, (void *)buffer2, {2, 5, 7}); + CPPType_TestType.copy_construct_indices((void *)buffer1, (void *)buffer2, {2, 5, 7}); EXPECT_EQ(buffer1[2], copy_constructed_from_value); EXPECT_EQ(buffer2[2], copy_constructed_value); EXPECT_EQ(buffer1[4], 0); @@ -173,10 +173,10 @@ TEST(cpp_type, CopyToInitialized) { int buffer1[10] = {0}; int buffer2[10] = {0}; - CPPType_TestType.copy_to_initialized((void *)buffer1, (void *)buffer2); + CPPType_TestType.copy_assign((void *)buffer1, (void *)buffer2); EXPECT_EQ(buffer1[0], copy_assigned_from_value); EXPECT_EQ(buffer2[0], copy_assigned_value); - CPPType_TestType.copy_to_initialized_n((void *)buffer1, (void *)buffer2, 3); + CPPType_TestType.copy_assign_n((void *)buffer1, (void *)buffer2, 3); EXPECT_EQ(buffer1[0], copy_assigned_from_value); EXPECT_EQ(buffer2[0], copy_assigned_value); EXPECT_EQ(buffer1[1], copy_assigned_from_value); @@ -185,7 +185,7 @@ TEST(cpp_type, CopyToInitialized) EXPECT_EQ(buffer2[2], copy_assigned_value); EXPECT_EQ(buffer1[3], 0); EXPECT_EQ(buffer2[3], 0); - CPPType_TestType.copy_to_initialized_indices((void *)buffer1, (void *)buffer2, {2, 5, 7}); + CPPType_TestType.copy_assign_indices((void *)buffer1, (void *)buffer2, {2, 5, 7}); EXPECT_EQ(buffer1[2], copy_assigned_from_value); EXPECT_EQ(buffer2[2], copy_assigned_value); EXPECT_EQ(buffer1[4], 0); @@ -204,10 +204,10 @@ TEST(cpp_type, RelocateToUninitialized) { int buffer1[10] = {0}; int buffer2[10] = {0}; - CPPType_TestType.relocate_to_uninitialized((void *)buffer1, (void *)buffer2); + CPPType_TestType.relocate_construct((void *)buffer1, (void *)buffer2); EXPECT_EQ(buffer1[0], destructed_value); EXPECT_EQ(buffer2[0], move_constructed_value); - CPPType_TestType.relocate_to_uninitialized_n((void *)buffer1, (void *)buffer2, 3); + CPPType_TestType.relocate_construct_n((void *)buffer1, (void *)buffer2, 3); EXPECT_EQ(buffer1[0], destructed_value); EXPECT_EQ(buffer2[0], move_constructed_value); EXPECT_EQ(buffer1[1], destructed_value); @@ -216,7 +216,7 @@ TEST(cpp_type, RelocateToUninitialized) EXPECT_EQ(buffer2[2], move_constructed_value); EXPECT_EQ(buffer1[3], 0); EXPECT_EQ(buffer2[3], 0); - CPPType_TestType.relocate_to_uninitialized_indices((void *)buffer1, (void *)buffer2, {2, 5, 7}); + CPPType_TestType.relocate_construct_indices((void *)buffer1, (void *)buffer2, {2, 5, 7}); EXPECT_EQ(buffer1[2], destructed_value); EXPECT_EQ(buffer2[2], move_constructed_value); EXPECT_EQ(buffer1[4], 0); @@ -235,10 +235,10 @@ TEST(cpp_type, RelocateToInitialized) { int buffer1[10] = {0}; int buffer2[10] = {0}; - CPPType_TestType.relocate_to_initialized((void *)buffer1, (void *)buffer2); + CPPType_TestType.relocate_assign((void *)buffer1, (void *)buffer2); EXPECT_EQ(buffer1[0], destructed_value); EXPECT_EQ(buffer2[0], move_assigned_value); - CPPType_TestType.relocate_to_initialized_n((void *)buffer1, (void *)buffer2, 3); + CPPType_TestType.relocate_assign_n((void *)buffer1, (void *)buffer2, 3); EXPECT_EQ(buffer1[0], destructed_value); EXPECT_EQ(buffer2[0], move_assigned_value); EXPECT_EQ(buffer1[1], destructed_value); @@ -247,7 +247,7 @@ TEST(cpp_type, RelocateToInitialized) EXPECT_EQ(buffer2[2], move_assigned_value); EXPECT_EQ(buffer1[3], 0); EXPECT_EQ(buffer2[3], 0); - CPPType_TestType.relocate_to_initialized_indices((void *)buffer1, (void *)buffer2, {2, 5, 7}); + CPPType_TestType.relocate_assign_indices((void *)buffer1, (void *)buffer2, {2, 5, 7}); EXPECT_EQ(buffer1[2], destructed_value); EXPECT_EQ(buffer2[2], move_assigned_value); EXPECT_EQ(buffer1[4], 0); @@ -266,7 +266,7 @@ TEST(cpp_type, FillInitialized) { int buffer1 = 0; int buffer2[10] = {0}; - CPPType_TestType.fill_initialized((void *)&buffer1, (void *)buffer2, 3); + CPPType_TestType.fill_assign_n((void *)&buffer1, (void *)buffer2, 3); EXPECT_EQ(buffer1, copy_assigned_from_value); EXPECT_EQ(buffer2[0], copy_assigned_value); EXPECT_EQ(buffer2[1], copy_assigned_value); @@ -274,7 +274,7 @@ TEST(cpp_type, FillInitialized) EXPECT_EQ(buffer2[3], 0); buffer1 = 0; - CPPType_TestType.fill_initialized_indices((void *)&buffer1, (void *)buffer2, {1, 6, 8}); + CPPType_TestType.fill_assign_indices((void *)&buffer1, (void *)buffer2, {1, 6, 8}); EXPECT_EQ(buffer1, copy_assigned_from_value); EXPECT_EQ(buffer2[0], copy_assigned_value); EXPECT_EQ(buffer2[1], copy_assigned_value); @@ -292,7 +292,7 @@ TEST(cpp_type, FillUninitialized) { int buffer1 = 0; int buffer2[10] = {0}; - CPPType_TestType.fill_uninitialized((void *)&buffer1, (void *)buffer2, 3); + CPPType_TestType.fill_construct_n((void *)&buffer1, (void *)buffer2, 3); EXPECT_EQ(buffer1, copy_constructed_from_value); EXPECT_EQ(buffer2[0], copy_constructed_value); EXPECT_EQ(buffer2[1], copy_constructed_value); @@ -300,7 +300,7 @@ TEST(cpp_type, FillUninitialized) EXPECT_EQ(buffer2[3], 0); buffer1 = 0; - CPPType_TestType.fill_uninitialized_indices((void *)&buffer1, (void *)buffer2, {1, 6, 8}); + CPPType_TestType.fill_construct_indices((void *)&buffer1, (void *)buffer2, {1, 6, 8}); EXPECT_EQ(buffer1, copy_constructed_from_value); EXPECT_EQ(buffer2[0], copy_constructed_value); EXPECT_EQ(buffer2[1], copy_constructed_value); @@ -318,7 +318,7 @@ TEST(cpp_type, DebugPrint) { int value = 42; std::stringstream ss; - CPPType::get<int32_t>().debug_print((void *)&value, ss); + CPPType::get<int32_t>().print((void *)&value, ss); std::string text = ss.str(); EXPECT_EQ(text, "42"); } |