diff --git a/test/common/test_type_traits.cpp b/test/common/test_type_traits.cpp index 8eedfcdd33b..40f2240d566 100644 --- a/test/common/test_type_traits.cpp +++ b/test/common/test_type_traits.cpp @@ -38,26 +38,129 @@ #include #include +#include #include +TEST (TypeTraits, HasCustomAllocatorTrait) +{ + struct Foo + { + public: + PCL_MAKE_ALIGNED_OPERATOR_NEW + }; + + struct Bar + { + }; -struct Foo + EXPECT_TRUE(pcl::has_custom_allocator::value); + EXPECT_FALSE(pcl::has_custom_allocator::value); +} + +TEST (TypeTraits, HasXY) { -public: - PCL_MAKE_ALIGNED_OPERATOR_NEW -}; + static_assert(!pcl::traits::has_xy_v, + "has_xy<> should detect lack of x and y fields"); + static_assert(pcl::traits::has_xy_v, + "has_xy<> should detect x and y fields"); +} -struct Bar +TEST (TypeTraits, HasXYZ) { -}; + static_assert(!pcl::traits::has_xyz_v, + "has_xyz<> should detect lack of x or y or z fields"); + static_assert(pcl::traits::has_xyz_v, + "has_xyz<> should detect x, y and z fields"); +} -TEST (TypeTraits, HasCustomAllocatorTrait) +TEST (TypeTraits, HasNormal) { - EXPECT_TRUE(pcl::has_custom_allocator::value); - EXPECT_FALSE(pcl::has_custom_allocator::value); + static_assert(!pcl::traits::has_normal_v, + "has_normal<> should detect lack of normal_{x or y or z} fields"); + static_assert(pcl::traits::has_normal_v, + "has_normal<> should detect normal_{x, y and z} fields"); +} + +TEST (TypeTraits, HasCurvature) +{ + static_assert(!pcl::traits::has_curvature_v, + "has_curvature<> should detect lack of curvature field"); + static_assert(pcl::traits::has_curvature_v, + "has_curvature<> should detect curvature field"); +} + +TEST (TypeTraits, HasIntensity) +{ + static_assert(!pcl::traits::has_intensity_v, + "has_intensity<> should detect lack of intensity field"); + static_assert(pcl::traits::has_intensity_v, + "has_intensity<> should detect intensity field"); +} + +TEST (TypeTraits, HasColor) +{ + static_assert(!pcl::traits::has_color_v, + "has_color<> should detect lack of rgb field"); + static_assert(pcl::traits::has_color_v, + "has_color<> should detect rgb field"); + static_assert(pcl::traits::has_color_v, + "has_color<> should detect rgb field"); } +TEST (TypeTraits, HasLabel) +{ + static_assert(!pcl::traits::has_label_v, + "has_label<> should detect lack of label field"); + static_assert(pcl::traits::has_label_v, + "has_label<> should detect label field"); +} + +TEST (TypeTests, IsXYFinite) +{ + EXPECT_TRUE(pcl::isXYFinite(pcl::RGB {})); + EXPECT_TRUE(pcl::isXYFinite(pcl::PointXYZ {2,3,4})); + + EXPECT_TRUE(pcl::isXYFinite(pcl::PointXYZ {std::numeric_limits::max(), 3, 4})); + EXPECT_TRUE(pcl::isXYFinite(pcl::PointXYZ {std::numeric_limits::min(), 3, 4})); + + EXPECT_FALSE(pcl::isXYFinite(pcl::PointXYZ {std::numeric_limits::infinity(), 3, 4})); + EXPECT_FALSE(pcl::isXYFinite(pcl::PointXYZ {-std::numeric_limits::infinity(), 3, 4})); + + EXPECT_FALSE(pcl::isXYFinite(pcl::PointXYZ {std::numeric_limits::quiet_NaN(), 3, 4})); + EXPECT_FALSE(pcl::isXYFinite(pcl::PointXYZ {-std::numeric_limits::signaling_NaN(), 3, 4})); +} + + +TEST (TypeTests, IsXYZFinite) +{ + EXPECT_TRUE(pcl::isXYZFinite(pcl::RGB {})); + EXPECT_TRUE(pcl::isXYZFinite(pcl::PointXYZ {2,3,4})); + + EXPECT_TRUE(pcl::isXYZFinite(pcl::PointXYZ {std::numeric_limits::max(), 3, 4})); + EXPECT_TRUE(pcl::isXYZFinite(pcl::PointXYZ {std::numeric_limits::min(), 3, 4})); + + EXPECT_FALSE(pcl::isXYZFinite(pcl::PointXYZ {std::numeric_limits::infinity(), 3, 4})); + EXPECT_FALSE(pcl::isXYZFinite(pcl::PointXYZ {-std::numeric_limits::infinity(), 3, 4})); + + EXPECT_FALSE(pcl::isXYZFinite(pcl::PointXYZ {std::numeric_limits::quiet_NaN(), 3, 4})); + EXPECT_FALSE(pcl::isXYZFinite(pcl::PointXYZ {-std::numeric_limits::signaling_NaN(), 3, 4})); +} + +TEST (TypeTests, IsNormalFinite) +{ + EXPECT_TRUE(pcl::isNormalFinite(pcl::RGB {})); + EXPECT_TRUE(pcl::isNormalFinite(pcl::Normal {2,3,4})); + + EXPECT_TRUE(pcl::isNormalFinite(pcl::Normal {std::numeric_limits::max(), 3, 4})); + EXPECT_TRUE(pcl::isNormalFinite(pcl::Normal {std::numeric_limits::min(), 3, 4})); + + EXPECT_FALSE(pcl::isNormalFinite(pcl::Normal {std::numeric_limits::infinity(), 3, 4})); + EXPECT_FALSE(pcl::isNormalFinite(pcl::Normal {-std::numeric_limits::infinity(), 3, 4})); + + EXPECT_FALSE(pcl::isNormalFinite(pcl::Normal {std::numeric_limits::quiet_NaN(), 3, 4})); + EXPECT_FALSE(pcl::isNormalFinite(pcl::Normal {-std::numeric_limits::signaling_NaN(), 3, 4})); +} int main (int argc, char** argv)