Skip to content

Commit

Permalink
Adding tests for type-traits
Browse files Browse the repository at this point in the history
  • Loading branch information
kunaltyagi committed Oct 12, 2019
1 parent 9d15e99 commit ad1a116
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common/include/pcl/point_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ namespace pcl
has_field<PointT, boost::mpl::_2> > >::type
{ };

/** \brief Traits defined for ease of use with fields
/** \brief Traits defined for ease of use with fields already registered before
*
* has_<fields to be detected>: struct with `value` datamember defined at compiletime
* has_<fields to be detected>_v: constexpr boolean
Expand Down
75 changes: 66 additions & 9 deletions test/common/test_type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,83 @@

#include <pcl/pcl_macros.h>
#include <pcl/point_traits.h>
#include <pcl/point_types.h>

#include <gtest/gtest.h>

TEST (TypeTraits, HasCustomAllocatorTrait)
{
struct Foo
{
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};

struct Bar
{
};

EXPECT_TRUE(pcl::has_custom_allocator<Foo>::value);
EXPECT_FALSE(pcl::has_custom_allocator<Bar>::value);
}

struct Foo
TEST (TypeTraits, HasXY)
{
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
static_assert(!pcl::traits::has_xy_v<pcl::Normal>,
"has_xy<> should detect lack of x and y fields");
static_assert(pcl::traits::has_xy_v<pcl::PointXYZ>,
"has_xy<> should detect x and y fields");
}

struct Bar
TEST (TypeTraits, HasXYZ)
{
};
static_assert(!pcl::traits::has_xyz_v<pcl::Normal>,
"has_xyz<> should detect lack of x or y or z fields");
static_assert(pcl::traits::has_xyz_v<pcl::PointXYZ>,
"has_xyz<> should detect x, y and z fields");
}

TEST (TypeTraits, HasCustomAllocatorTrait)
TEST (TypeTraits, HasNormal)
{
EXPECT_TRUE(pcl::has_custom_allocator<Foo>::value);
EXPECT_FALSE(pcl::has_custom_allocator<Bar>::value);
static_assert(!pcl::traits::has_normal_v<pcl::PointXYZ>,
"has_normal<> should detect lack of normal_{x or y or z} fields");
static_assert(pcl::traits::has_normal_v<pcl::Axis>,
"has_normal<> should detect normal_{x, y and z} fields");
}

TEST (TypeTraits, HasCurvature)
{
static_assert(!pcl::traits::has_curvature_v<pcl::PointXYZ>,
"has_curvature<> should detect lack of curvature field");
static_assert(pcl::traits::has_curvature_v<pcl::Normal>,
"has_curvature<> should detect curvature field");
}

TEST (TypeTraits, HasIntensity)
{
static_assert(!pcl::traits::has_intensity_v<pcl::InterestPoint>,
"has_intensity<> should detect lack of intensity field");
static_assert(pcl::traits::has_intensity_v<pcl::PointXYZI>,
"has_intensity<> should detect intensity field");
}

TEST (TypeTraits, HasColor)
{
static_assert(!pcl::traits::has_color_v<pcl::PointXYZ>,
"has_color<> should detect lack of rgb field");
static_assert(pcl::traits::has_color_v<pcl::PointXYZRGB>,
"has_color<> should detect rgb field");
static_assert(pcl::traits::has_color_v<pcl::PointXYZRGBA>,
"has_color<> should detect rgb field");
}

TEST (TypeTraits, HasLabel)
{
static_assert(!pcl::traits::has_label_v<pcl::PointXYZRGB>,
"has_label<> should detect lack of label field");
static_assert(pcl::traits::has_label_v<pcl::PointXYZRGBL>,
"has_label<> should detect label field");
}

int
main (int argc, char** argv)
Expand Down

0 comments on commit ad1a116

Please sign in to comment.