Skip to content

Commit

Permalink
Merge pull request #2237 from taketwo/pcl-tests
Browse files Browse the repository at this point in the history
Fixes and new assertion macro in "pcl_tests.h"
  • Loading branch information
SergioRAgostinho authored Mar 2, 2018
2 parents 366d8b6 + f50ad76 commit 637ba7e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
51 changes: 49 additions & 2 deletions common/include/pcl/pcl_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,39 @@ namespace pcl
<< "Which is: " << p1.getRGBAVector4i ().transpose ();
}

template <typename PointCloud1T, typename PointCloud2T>
::testing::AssertionResult MetaDataEQ (const char* expr1,
const char* expr2,
const PointCloud1T& p1,
const PointCloud2T& p2)
{
if (!(p1.header == p2.header))
return ::testing::AssertionFailure () << "Headers are different";
if (p1.width != p2.width)
return ::testing::AssertionFailure ()
<< "Value of: " << expr2 << ".width" << std::endl
<< " Actual: " << p2.width << std::endl
<< "Expected: " << expr1 << ".width" << std::endl
<< "Which is: " << p1.width << std::endl;
if (p1.height != p2.height)
return ::testing::AssertionFailure ()
<< "Value of: " << expr2 << ".height" << std::endl
<< " Actual: " << p2.height << std::endl
<< "Expected: " << expr1 << ".height" << std::endl
<< "Which is: " << p1.height << std::endl;
if (p1.is_dense != p2.is_dense)
return ::testing::AssertionFailure ()
<< "Value of: " << expr2 << ".is_dense" << std::endl
<< " Actual: " << p2.is_dense << std::endl
<< "Expected: " << expr1 << ".is_dense" << std::endl
<< "Which is: " << p1.is_dense << std::endl;
if (p1.sensor_origin_ != p2.sensor_origin_)
return ::testing::AssertionFailure () << "Sensor origins are different";
if (p1.sensor_orientation_.coeffs () != p2.sensor_orientation_.coeffs ())
return ::testing::AssertionFailure () << "Sensor orientations are different";
return ::testing::AssertionSuccess ();
}

}

}
Expand Down Expand Up @@ -215,7 +248,7 @@ namespace pcl
/// Assert that differences between x, y, and z fields in
/// two points are each within abs_error.
#define ASSERT_XYZ_NEAR(expected, actual, abs_error) \
EXPECT_PRED_FORMAT3(::pcl::test::internal::XYZNear, \
ASSERT_PRED_FORMAT3(::pcl::test::internal::XYZNear, \
(expected), (actual), abs_error)

/// Expect that each of normal_x, normal_y, and normal_z
Expand All @@ -241,7 +274,7 @@ namespace pcl
/// and normal_z fields in two points are each within
/// abs_error.
#define ASSERT_NORMAL_NEAR(expected, actual, abs_error) \
EXPECT_PRED_FORMAT3(::pcl::test::internal::NormalNear, \
ASSERT_PRED_FORMAT3(::pcl::test::internal::NormalNear, \
(expected), (actual), abs_error)

/// Expect that each of r, g, and b fields are equal in
Expand All @@ -268,4 +301,18 @@ namespace pcl
ASSERT_PRED_FORMAT2(::pcl::test::internal::RGBAEQ, \
(expected), (actual))

/// Assert that the metadata (header, width, height,
/// is_dense, sensor origin and orientation) are equal
/// in two point clouds.
#define ASSERT_METADATA_EQ(expected, actual) \
ASSERT_PRED_FORMAT2(::pcl::test::internal::MetaDataEQ, \
expected, actual)

/// Expect that the metadata (header, width, height,
/// is_dense, sensor origin and orientation) are equal
/// in two point clouds.
#define EXPECT_METADATA_EQ(expected, actual) \
EXPECT_PRED_FORMAT2(::pcl::test::internal::MetaDataEQ, \
expected, actual)

#endif
9 changes: 5 additions & 4 deletions test/common/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ TEST (PCL, copyPointCloud)

CloudXYZRGBNormal cloud_xyz_rgb_normal;
pcl::copyPointCloud (cloud_xyz_rgba, cloud_xyz_rgb_normal);
EXPECT_EQ (int (cloud_xyz_rgb_normal.size ()), 5);
ASSERT_METADATA_EQ (cloud_xyz_rgba, cloud_xyz_rgb_normal);
ASSERT_EQ (int (cloud_xyz_rgb_normal.size ()), 5);
for (int i = 0; i < 5; ++i)
{
EXPECT_XYZ_EQ (cloud_xyz_rgba[i], cloud_xyz_rgb_normal[i]);
Expand All @@ -98,7 +99,7 @@ TEST (PCL, copyPointCloud)
vector<int> indices;
indices.push_back (0); indices.push_back (1);
pcl::copyPointCloud (cloud_xyz_rgba, indices, cloud_xyz_rgb_normal);
EXPECT_EQ (int (cloud_xyz_rgb_normal.size ()), 2);
ASSERT_EQ (int (cloud_xyz_rgb_normal.size ()), 2);
for (int i = 0; i < 2; ++i)
{
EXPECT_XYZ_EQ (cloud_xyz_rgba[i], cloud_xyz_rgb_normal[i]);
Expand All @@ -109,7 +110,7 @@ TEST (PCL, copyPointCloud)
vector<int, Eigen::aligned_allocator<int> > indices_aligned;
indices_aligned.push_back (1); indices_aligned.push_back (2); indices_aligned.push_back (3);
pcl::copyPointCloud (cloud_xyz_rgba, indices_aligned, cloud_xyz_rgb_normal);
EXPECT_EQ (int (cloud_xyz_rgb_normal.size ()), 3);
ASSERT_EQ (int (cloud_xyz_rgb_normal.size ()), 3);
for (int i = 0; i < 3; ++i)
{
EXPECT_XYZ_EQ (cloud_xyz_rgba[i], cloud_xyz_rgb_normal[i]);
Expand All @@ -119,7 +120,7 @@ TEST (PCL, copyPointCloud)

PointIndices pindices;
pindices.indices.push_back (0); pindices.indices.push_back (2); pindices.indices.push_back (4);
EXPECT_EQ (int (cloud_xyz_rgb_normal.size ()), 3);
ASSERT_EQ (int (cloud_xyz_rgb_normal.size ()), 3);
for (int i = 0; i < 3; ++i)
{
EXPECT_XYZ_EQ (cloud_xyz_rgba[i], cloud_xyz_rgb_normal[i]);
Expand Down

0 comments on commit 637ba7e

Please sign in to comment.