From 4316e111380fe5ffef80fdec0a2228546ebcae65 Mon Sep 17 00:00:00 2001 From: Shrijit Singh Date: Wed, 26 Feb 2020 22:06:54 +0530 Subject: [PATCH] Update TYPED_TEST_CASE to TYPED_TEST_SUITE with fallback for older GTest versions (#3677) Co-authored-by: Aaryaman Vasishta @jammm Shrijit Singh @shrijitsingh99 --- test/CMakeLists.txt | 2 + test/common/test_common.cpp | 7 +- test/common/test_geometry.cpp | 3 +- test/common/test_transforms.cpp | 3 +- test/common/test_type_traits.cpp | 1 - test/features/test_pfh_estimation.cpp | 3 +- test/features/test_shot_estimation.cpp | 5 +- test/geometry/test_mesh_conversion.cpp | 3 +- test/geometry/test_mesh_get_boundary.cpp | 3 +- test/geometry/test_mesh_indices.cpp | 3 +- test/geometry/test_polygon_mesh.cpp | 3 +- test/geometry/test_quad_mesh.cpp | 3 +- test/geometry/test_triangle_mesh.cpp | 3 +- test/include/pcl/test/gtest.h | 65 +++++++++++++++++++ test/io/test_buffers.cpp | 3 +- test/io/test_io.cpp | 3 +- test/io/test_ply_io.cpp | 7 +- test/octree/test_octree_iterator.cpp | 3 +- .../test_sample_consensus.cpp | 3 +- test/segmentation/test_random_walker.cpp | 3 +- 20 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 test/include/pcl/test/gtest.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 41ce6364052..ad5492cf82b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,6 +26,8 @@ endif() set_target_properties(tests PROPERTIES FOLDER "Tests") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") + add_subdirectory(2d) add_subdirectory(common) add_subdirectory(features) diff --git a/test/common/test_common.cpp b/test/common/test_common.cpp index 1b04074419f..e615ef0d3ff 100644 --- a/test/common/test_common.cpp +++ b/test/common/test_common.cpp @@ -48,6 +48,7 @@ #include #include +#include using namespace pcl; @@ -308,7 +309,7 @@ TEST (PCL, PointTypes) template class XYZPointTypesTest : public ::testing::Test { }; using XYZPointTypes = ::testing::Types; -TYPED_TEST_CASE(XYZPointTypesTest, XYZPointTypes); +TYPED_TEST_SUITE(XYZPointTypesTest, XYZPointTypes); TYPED_TEST(XYZPointTypesTest, GetVectorXfMap) { TypeParam pt; @@ -329,7 +330,7 @@ TYPED_TEST(XYZPointTypesTest, GetArrayXfMap) template class NormalPointTypesTest : public ::testing::Test { }; using NormalPointTypes = ::testing::Types; -TYPED_TEST_CASE(NormalPointTypesTest, NormalPointTypes); +TYPED_TEST_SUITE(NormalPointTypesTest, NormalPointTypes); TYPED_TEST(NormalPointTypesTest, GetNormalVectorXfMap) { TypeParam pt; @@ -341,7 +342,7 @@ TYPED_TEST(NormalPointTypesTest, GetNormalVectorXfMap) template class RGBPointTypesTest : public ::testing::Test { }; using RGBPointTypes = ::testing::Types; -TYPED_TEST_CASE(RGBPointTypesTest, RGBPointTypes); +TYPED_TEST_SUITE(RGBPointTypesTest, RGBPointTypes); TYPED_TEST(RGBPointTypesTest, GetRGBVectorXi) { TypeParam pt; pt.r = 1; pt.g = 2; pt.b = 3; pt.a = 4; diff --git a/test/common/test_geometry.cpp b/test/common/test_geometry.cpp index cc44ff6d493..68ef0cea1e1 100644 --- a/test/common/test_geometry.cpp +++ b/test/common/test_geometry.cpp @@ -40,13 +40,14 @@ #include #include #include +#include using namespace pcl; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template class XYZPointTypesTest : public ::testing::Test { }; using XYZPointTypes = ::testing::Types; -TYPED_TEST_CASE(XYZPointTypesTest, XYZPointTypes); +TYPED_TEST_SUITE(XYZPointTypesTest, XYZPointTypes); TYPED_TEST(XYZPointTypesTest, Distance) { diff --git a/test/common/test_transforms.cpp b/test/common/test_transforms.cpp index a4c7f9b9df1..6934007eda7 100644 --- a/test/common/test_transforms.cpp +++ b/test/common/test_transforms.cpp @@ -46,6 +46,7 @@ #include #include +#include using namespace pcl; @@ -107,7 +108,7 @@ class Transforms : public ::testing::Test PCL_MAKE_ALIGNED_OPERATOR_NEW; }; -TYPED_TEST_CASE (Transforms, TransformTypes); +TYPED_TEST_SUITE (Transforms, TransformTypes); TYPED_TEST (Transforms, PointCloudXYZDense) { diff --git a/test/common/test_type_traits.cpp b/test/common/test_type_traits.cpp index 40f2240d566..3629ff0b1a6 100644 --- a/test/common/test_type_traits.cpp +++ b/test/common/test_type_traits.cpp @@ -36,7 +36,6 @@ */ -#include #include #include diff --git a/test/features/test_pfh_estimation.cpp b/test/features/test_pfh_estimation.cpp index f0ce72f48ef..e807ba8a9e2 100644 --- a/test/features/test_pfh_estimation.cpp +++ b/test/features/test_pfh_estimation.cpp @@ -50,6 +50,7 @@ #include #include #include +#include using PointT = pcl::PointNormal; using KdTreePtr = pcl::search::KdTree::Ptr; @@ -294,7 +295,7 @@ struct FPFHTest > using FPFHEstimatorTypes = ::testing::Types , FPFHEstimationOMP >; -TYPED_TEST_CASE (FPFHTest, FPFHEstimatorTypes); +TYPED_TEST_SUITE (FPFHTest, FPFHEstimatorTypes); // This is a copy of the old FPFHEstimation test which will now // be applied to both FPFHEstimation and FPFHEstimationOMP diff --git a/test/features/test_shot_estimation.cpp b/test/features/test_shot_estimation.cpp index f49ca2c4804..530c6a98a4d 100644 --- a/test/features/test_shot_estimation.cpp +++ b/test/features/test_shot_estimation.cpp @@ -46,6 +46,7 @@ #include "pcl/features/shot_lrf.h" #include #include +#include using namespace pcl; using namespace pcl::io; @@ -371,7 +372,7 @@ struct SHOTShapeTest > using SHOTEstimatorTypes = ::testing::Types , SHOTEstimationOMP >; -TYPED_TEST_CASE (SHOTShapeTest, SHOTEstimatorTypes); +TYPED_TEST_SUITE (SHOTShapeTest, SHOTEstimatorTypes); // This is a copy of the old SHOTShapeEstimation test which will now // be applied to both SHOTEstimation and SHOTEstimationOMP @@ -560,7 +561,7 @@ struct SHOTShapeAndColorTest, SHOTColorEstimationOMP >; -TYPED_TEST_CASE (SHOTShapeAndColorTest, SHOTColorEstimatorTypes); +TYPED_TEST_SUITE (SHOTShapeAndColorTest, SHOTColorEstimatorTypes); // This is a copy of the old SHOTShapeAndColorEstimation test which will now // be applied to both SHOTColorEstimation and SHOTColorEstimationOMP diff --git a/test/geometry/test_mesh_conversion.cpp b/test/geometry/test_mesh_conversion.cpp index 4a04db62228..7eb1feb71ef 100644 --- a/test/geometry/test_mesh_conversion.cpp +++ b/test/geometry/test_mesh_conversion.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include "test_mesh_common_functions.h" @@ -152,7 +153,7 @@ using NonManifoldMeshTraits = MeshTraits; using MeshTraitsTypes = testing::Types ; -TYPED_TEST_CASE (TestMeshConversion, MeshTraitsTypes); +TYPED_TEST_SUITE (TestMeshConversion, MeshTraitsTypes); //////////////////////////////////////////////////////////////////////////////// diff --git a/test/geometry/test_mesh_get_boundary.cpp b/test/geometry/test_mesh_get_boundary.cpp index 6fc82c7f644..8f19258b514 100644 --- a/test/geometry/test_mesh_get_boundary.cpp +++ b/test/geometry/test_mesh_get_boundary.cpp @@ -42,6 +42,7 @@ #include #include +#include #include "test_mesh_common_functions.h" //////////////////////////////////////////////////////////////////////////////// @@ -68,7 +69,7 @@ class TestGetBoundary : public testing::Test using Mesh = MeshT; }; -TYPED_TEST_CASE (TestGetBoundary, MeshTypes); +TYPED_TEST_SUITE (TestGetBoundary, MeshTypes); //////////////////////////////////////////////////////////////////////////////// diff --git a/test/geometry/test_mesh_indices.cpp b/test/geometry/test_mesh_indices.cpp index 39e098cd2a1..52db1085c19 100644 --- a/test/geometry/test_mesh_indices.cpp +++ b/test/geometry/test_mesh_indices.cpp @@ -44,6 +44,7 @@ #include #include +#include //////////////////////////////////////////////////////////////////////////////// @@ -63,7 +64,7 @@ class TestMeshIndicesTyped : public testing::Test using MeshIndexTypes = testing::Types ; -TYPED_TEST_CASE (TestMeshIndicesTyped, MeshIndexTypes); +TYPED_TEST_SUITE (TestMeshIndicesTyped, MeshIndexTypes); //////////////////////////////////////////////////////////////////////////////// diff --git a/test/geometry/test_polygon_mesh.cpp b/test/geometry/test_polygon_mesh.cpp index 160b45e1e8f..236f9016983 100644 --- a/test/geometry/test_polygon_mesh.cpp +++ b/test/geometry/test_polygon_mesh.cpp @@ -44,6 +44,7 @@ #include #include +#include #include "test_mesh_common_functions.h" @@ -82,7 +83,7 @@ class TestPolygonMesh : public testing::Test using Mesh = MeshT; }; -TYPED_TEST_CASE (TestPolygonMesh, PolygonMeshTypes); +TYPED_TEST_SUITE (TestPolygonMesh, PolygonMeshTypes); //////////////////////////////////////////////////////////////////////////////// diff --git a/test/geometry/test_quad_mesh.cpp b/test/geometry/test_quad_mesh.cpp index 09be99a30f5..aa0775779ac 100644 --- a/test/geometry/test_quad_mesh.cpp +++ b/test/geometry/test_quad_mesh.cpp @@ -44,6 +44,7 @@ #include #include +#include #include "test_mesh_common_functions.h" @@ -80,7 +81,7 @@ class TestQuadMesh : public testing::Test using Mesh = MeshT; }; -TYPED_TEST_CASE (TestQuadMesh, QuadMeshTypes); +TYPED_TEST_SUITE (TestQuadMesh, QuadMeshTypes); //////////////////////////////////////////////////////////////////////////////// diff --git a/test/geometry/test_triangle_mesh.cpp b/test/geometry/test_triangle_mesh.cpp index cb1b6a7b3b3..bfbb4af1317 100644 --- a/test/geometry/test_triangle_mesh.cpp +++ b/test/geometry/test_triangle_mesh.cpp @@ -44,6 +44,7 @@ #include #include +#include #include "test_mesh_common_functions.h" @@ -80,7 +81,7 @@ class TestTriangleMesh : public testing::Test using Mesh = MeshT; }; -TYPED_TEST_CASE (TestTriangleMesh, TriangleMeshTypes); +TYPED_TEST_SUITE (TestTriangleMesh, TriangleMeshTypes); //////////////////////////////////////////////////////////////////////////////// diff --git a/test/include/pcl/test/gtest.h b/test/include/pcl/test/gtest.h new file mode 100644 index 00000000000..594b08a4f5b --- /dev/null +++ b/test/include/pcl/test/gtest.h @@ -0,0 +1,65 @@ +/* + * Software License Agreement (BSD License) + * + * Point Cloud Library (PCL) - www.pointclouds.org + * Copyright (c) 2019-, Open Perception, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of the copyright holder(s) nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +/** + * \file pcl/test/gtest.h + * + * \brief Defines all the PCL test macros used + * \ingroup test + */ + +/** + * \brief Macro choose between TYPED_TEST_CASE and TYPED_TEST_SUITE depending on the GTest version + * + * \ingroup test + */ +#if !defined(TYPED_TEST_SUITE) + #define TYPED_TEST_SUITE TYPED_TEST_CASE +#endif + +/** + * \brief Macro choose between INSTANTIATE_TEST_CASE_P and INSTANTIATE_TEST_SUITE_P depending on the GTest version + * + * \ingroup test + */ +#if !defined(INSTANTIATE_TEST_SUITE_P) + #define INSTANTIATE_TEST_SUITE_P INSTANTIATE_TEST_CASE_P +#endif + diff --git a/test/io/test_buffers.cpp b/test/io/test_buffers.cpp index f9eb1fc09d0..8d1c89cf9c0 100644 --- a/test/io/test_buffers.cpp +++ b/test/io/test_buffers.cpp @@ -41,6 +41,7 @@ #include #include +#include using namespace pcl::io; @@ -84,7 +85,7 @@ class BuffersTest : public ::testing::Test }; using DataTypes = ::testing::Types; -TYPED_TEST_CASE (BuffersTest, DataTypes); +TYPED_TEST_SUITE (BuffersTest, DataTypes); TYPED_TEST (BuffersTest, SingleBuffer) { diff --git a/test/io/test_io.cpp b/test/io/test_io.cpp index 8ff839a1cf7..7fe76b939c8 100644 --- a/test/io/test_io.cpp +++ b/test/io/test_io.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -1319,7 +1320,7 @@ TEST (PCL, Locale) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template class AutoIOTest : public testing::Test { }; using PCLXyzNormalPointTypes = ::testing::Types; -TYPED_TEST_CASE (AutoIOTest, PCLXyzNormalPointTypes); +TYPED_TEST_SUITE (AutoIOTest, PCLXyzNormalPointTypes); TYPED_TEST (AutoIOTest, AutoLoadCloudFiles) { PointCloud cloud; diff --git a/test/io/test_ply_io.cpp b/test/io/test_ply_io.cpp index 139e848d050..a4d533d20b4 100644 --- a/test/io/test_ply_io.cpp +++ b/test/io/test_ply_io.cpp @@ -41,6 +41,7 @@ #include #include #include +#include ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TEST (PCL, PLYReaderWriter) @@ -288,7 +289,7 @@ TEST_F (PLYColorTest, LoadPLYFileColoredASCIIIntoPolygonMesh) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template class PLYPointCloudTest : public PLYColorTest { }; using RGBPointTypes = ::testing::Types; -TYPED_TEST_CASE (PLYPointCloudTest, RGBPointTypes); +TYPED_TEST_SUITE (PLYPointCloudTest, RGBPointTypes); TYPED_TEST (PLYPointCloudTest, LoadPLYFileColoredASCIIIntoPointCloud) { int res; @@ -316,7 +317,7 @@ template struct PLYCoordinatesIsDenseTest : public PLYTest {}; using XYZPointTypes = ::testing::Types; -TYPED_TEST_CASE (PLYCoordinatesIsDenseTest, XYZPointTypes); +TYPED_TEST_SUITE (PLYCoordinatesIsDenseTest, XYZPointTypes); TYPED_TEST (PLYCoordinatesIsDenseTest, NaNInCoordinates) { @@ -410,7 +411,7 @@ template struct PLYNormalsIsDenseTest : public PLYTest {}; using NormalPointTypes = ::testing::Types; -TYPED_TEST_CASE (PLYNormalsIsDenseTest, NormalPointTypes); +TYPED_TEST_SUITE (PLYNormalsIsDenseTest, NormalPointTypes); TYPED_TEST (PLYNormalsIsDenseTest, NaNInNormals) { diff --git a/test/octree/test_octree_iterator.cpp b/test/octree/test_octree_iterator.cpp index 6eb6939ebef..7e3db513a97 100644 --- a/test/octree/test_octree_iterator.cpp +++ b/test/octree/test_octree_iterator.cpp @@ -41,6 +41,7 @@ #include #include #include +#include using pcl::octree::OctreeBase; using pcl::octree::OctreeIteratorBase; @@ -154,7 +155,7 @@ using OctreeIteratorTypes = testing::Types OctreeLeafNodeDepthFirstIterator >, OctreeFixedDepthIterator >, OctreeLeafNodeBreadthFirstIterator > >; -TYPED_TEST_CASE (OctreeIteratorTest, OctreeIteratorTypes); +TYPED_TEST_SUITE (OctreeIteratorTest, OctreeIteratorTypes); TYPED_TEST (OctreeIteratorTest, CopyConstructor) { diff --git a/test/sample_consensus/test_sample_consensus.cpp b/test/sample_consensus/test_sample_consensus.cpp index 438f70507f0..fe4e5ef2bbc 100644 --- a/test/sample_consensus/test_sample_consensus.cpp +++ b/test/sample_consensus/test_sample_consensus.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -92,7 +93,7 @@ using sacTypes = ::testing::Types< RandomizedMEstimatorSampleConsensus, MaximumLikelihoodSampleConsensus >; -TYPED_TEST_CASE(SacTest, sacTypes); +TYPED_TEST_SUITE(SacTest, sacTypes); TYPED_TEST(SacTest, InfiniteLoop) { diff --git a/test/segmentation/test_random_walker.cpp b/test/segmentation/test_random_walker.cpp index a968f0f6a7d..acf91c80e4b 100644 --- a/test/segmentation/test_random_walker.cpp +++ b/test/segmentation/test_random_walker.cpp @@ -48,6 +48,7 @@ #include #include +#include std::string TEST_DATA_DIR; @@ -235,7 +236,7 @@ TEST_P (RandomWalkerTest, GetPotentials) } } -INSTANTIATE_TEST_CASE_P (VariousGraphs, +INSTANTIATE_TEST_SUITE_P (VariousGraphs, RandomWalkerTest, ::testing::Values ("graph0.info", "graph1.info",