diff --git a/common/include/pcl/pcl_tests.h b/common/include/pcl/pcl_tests.h index f9b8f1366bb..5b378542303 100644 --- a/common/include/pcl/pcl_tests.h +++ b/common/include/pcl/pcl_tests.h @@ -188,6 +188,39 @@ namespace pcl << "Which is: " << p1.getRGBAVector4i ().transpose (); } + template + ::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 (); + } + } } @@ -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 @@ -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 @@ -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 diff --git a/test/common/test_io.cpp b/test/common/test_io.cpp index 7bc6f09b670..63c0242acdb 100644 --- a/test/common/test_io.cpp +++ b/test/common/test_io.cpp @@ -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]); @@ -98,7 +99,7 @@ TEST (PCL, copyPointCloud) vector 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]); @@ -109,7 +110,7 @@ TEST (PCL, copyPointCloud) vector > 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]); @@ -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]);