diff --git a/realtime_tools/CMakeLists.txt b/realtime_tools/CMakeLists.txt index 6e7ab367..74159ac6 100644 --- a/realtime_tools/CMakeLists.txt +++ b/realtime_tools/CMakeLists.txt @@ -65,38 +65,38 @@ endif() # Unit Tests if(BUILD_TESTING) - find_package(ament_cmake_gmock REQUIRED) + find_package(ament_cmake_gtest REQUIRED) find_package(lifecycle_msgs REQUIRED) find_package(rclcpp_lifecycle REQUIRED) find_package(test_msgs REQUIRED) - ament_add_gmock(thread_priority_tests test/thread_priority_tests.cpp) + ament_add_gtest(thread_priority_tests test/thread_priority_tests.cpp) target_link_libraries(thread_priority_tests thread_priority) - ament_add_gmock(realtime_thread_safe_box_tests test/realtime_thread_safe_box_tests.cpp) + ament_add_gtest(realtime_thread_safe_box_tests test/realtime_thread_safe_box_tests.cpp) target_link_libraries(realtime_thread_safe_box_tests realtime_tools) - ament_add_gmock(realtime_buffer_tests test/realtime_buffer_tests.cpp) + ament_add_gtest(realtime_buffer_tests test/realtime_buffer_tests.cpp) target_link_libraries(realtime_buffer_tests realtime_tools) - ament_add_gmock(lock_free_queue_tests test/lock_free_queue_tests.cpp) + ament_add_gtest(lock_free_queue_tests test/lock_free_queue_tests.cpp) target_link_libraries(lock_free_queue_tests realtime_tools Boost::boost) if(UNIX AND NOT APPLE) target_link_libraries(lock_free_queue_tests atomic) endif() - ament_add_gmock(realtime_publisher_tests + ament_add_gtest(realtime_publisher_tests test/realtime_publisher.test test/realtime_publisher_tests.cpp) target_link_libraries(realtime_publisher_tests realtime_tools ${test_msgs_TARGETS}) - ament_add_gmock(realtime_server_goal_handle_tests + ament_add_gtest(realtime_server_goal_handle_tests test/realtime_server_goal_handle.test test/realtime_server_goal_handle_tests.cpp) target_link_libraries(realtime_server_goal_handle_tests realtime_tools ${test_msgs_TARGETS}) - ament_add_gmock(test_async_function_handler test/test_async_function_handler.cpp) + ament_add_gtest(test_async_function_handler test/test_async_function_handler.cpp) target_link_libraries(test_async_function_handler realtime_tools thread_priority @@ -104,7 +104,7 @@ if(BUILD_TESTING) rclcpp_lifecycle::rclcpp_lifecycle) if(NOT WIN32) - ament_add_gmock(realtime_mutex_tests test/realtime_mutex_tests.cpp) + ament_add_gtest(realtime_mutex_tests test/realtime_mutex_tests.cpp) target_link_libraries(realtime_mutex_tests realtime_tools) endif() endif() diff --git a/realtime_tools/package.xml b/realtime_tools/package.xml index 960f2716..04b9a928 100644 --- a/realtime_tools/package.xml +++ b/realtime_tools/package.xml @@ -26,7 +26,7 @@ rclcpp_action libcap-dev - ament_cmake_gmock + ament_cmake_gtest lifecycle_msgs rclcpp_lifecycle test_msgs diff --git a/realtime_tools/test/lock_free_queue_tests.cpp b/realtime_tools/test/lock_free_queue_tests.cpp index a4c26dcd..0908579b 100644 --- a/realtime_tools/test/lock_free_queue_tests.cpp +++ b/realtime_tools/test/lock_free_queue_tests.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include #include diff --git a/realtime_tools/test/realtime_buffer_tests.cpp b/realtime_tools/test/realtime_buffer_tests.cpp index 5ba3839b..62c3c56e 100644 --- a/realtime_tools/test/realtime_buffer_tests.cpp +++ b/realtime_tools/test/realtime_buffer_tests.cpp @@ -26,7 +26,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -#include +#include #include using realtime_tools::RealtimeBuffer; diff --git a/realtime_tools/test/realtime_mutex_tests.cpp b/realtime_tools/test/realtime_mutex_tests.cpp index 691529c2..cacf389e 100644 --- a/realtime_tools/test/realtime_mutex_tests.cpp +++ b/realtime_tools/test/realtime_mutex_tests.cpp @@ -14,7 +14,7 @@ /// \author Sai Kishor Kothakota -#include +#include #include #include diff --git a/realtime_tools/test/realtime_publisher_tests.cpp b/realtime_tools/test/realtime_publisher_tests.cpp index 71ef0c88..cda19f1a 100644 --- a/realtime_tools/test/realtime_publisher_tests.cpp +++ b/realtime_tools/test/realtime_publisher_tests.cpp @@ -26,7 +26,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -#include +#include #include #include diff --git a/realtime_tools/test/realtime_server_goal_handle_tests.cpp b/realtime_tools/test/realtime_server_goal_handle_tests.cpp index bca8df76..8bbf9fc0 100644 --- a/realtime_tools/test/realtime_server_goal_handle_tests.cpp +++ b/realtime_tools/test/realtime_server_goal_handle_tests.cpp @@ -26,7 +26,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -#include +#include #include #include diff --git a/realtime_tools/test/realtime_thread_safe_box_tests.cpp b/realtime_tools/test/realtime_thread_safe_box_tests.cpp index b68f5cbb..70fe8d63 100644 --- a/realtime_tools/test/realtime_thread_safe_box_tests.cpp +++ b/realtime_tools/test/realtime_thread_safe_box_tests.cpp @@ -27,10 +27,12 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -#include +#include #include +#include +#include "realtime_tools/mutex.hpp" #include "realtime_tools/realtime_thread_safe_box.hpp" struct DefaultConstructable @@ -55,40 +57,52 @@ struct FromInitializerList std::array data; }; +// Dummy test fixture to enable parameterized template types +template +class TypedRealtimeThreadSafeBox : public testing::Test +{ +}; + +using TestTypes = ::testing::Types< + std::mutex, realtime_tools::prio_inherit_mutex, realtime_tools::prio_inherit_recursive_mutex>; + +TYPED_TEST_SUITE(TypedRealtimeThreadSafeBox, TestTypes); + using realtime_tools::RealtimeThreadSafeBox; -TEST(RealtimeThreadSafeBox, empty_construct) +TYPED_TEST(TypedRealtimeThreadSafeBox, empty_construct) { - RealtimeThreadSafeBox box; + RealtimeThreadSafeBox box; auto value = box.get(); EXPECT_EQ(value.a, 10); EXPECT_EQ(value.str, "hallo"); } -TEST(RealtimeThreadSafeBox, default_construct) +TYPED_TEST(TypedRealtimeThreadSafeBox, default_construct) { DefaultConstructable data; data.a = 100; - RealtimeThreadSafeBox box(data); + RealtimeThreadSafeBox box(data); auto value = box.get(); EXPECT_EQ(value.a, 100); EXPECT_EQ(value.str, "hallo"); } -TEST(RealtimeThreadSafeBox, non_default_constructable) +TYPED_TEST(TypedRealtimeThreadSafeBox, non_default_constructable) { - RealtimeThreadSafeBox box(NonDefaultConstructable(-10, "hello")); + RealtimeThreadSafeBox box( + NonDefaultConstructable(-10, "hello")); auto value = box.get(); EXPECT_EQ(value.a, -10); EXPECT_EQ(value.str, "hello"); } -TEST(RealtimeThreadSafeBox, standard_get) +TYPED_TEST(TypedRealtimeThreadSafeBox, standard_get) { - RealtimeThreadSafeBox box(DefaultConstructable{1000}); + RealtimeThreadSafeBox box(DefaultConstructable{1000}); DefaultConstructable data; box.get(data); @@ -101,9 +115,9 @@ TEST(RealtimeThreadSafeBox, standard_get) EXPECT_EQ(value.a, 10000); } -TEST(RealtimeThreadSafeBox, initializer_list) +TYPED_TEST(TypedRealtimeThreadSafeBox, initializer_list) { - RealtimeThreadSafeBox box({1, 2, 3}); + RealtimeThreadSafeBox box({1, 2, 3}); auto value = box.get(); EXPECT_EQ(value.data[0], 1); @@ -111,20 +125,20 @@ TEST(RealtimeThreadSafeBox, initializer_list) EXPECT_EQ(value.data[2], 3); } -TEST(RealtimeThreadSafeBox, assignment_operator) +TYPED_TEST(TypedRealtimeThreadSafeBox, assignment_operator) { DefaultConstructable data; data.a = 1000; - RealtimeThreadSafeBox box; + RealtimeThreadSafeBox box; // Assignment operator is always non RT! box = data; auto value = box.get(); EXPECT_EQ(value.a, 1000); } -TEST(RealtimeThreadSafeBox, typecast_operator) +TYPED_TEST(TypedRealtimeThreadSafeBox, typecast_operator) { - RealtimeThreadSafeBox box(DefaultConstructable{100, ""}); + RealtimeThreadSafeBox box(DefaultConstructable{100, ""}); // Use non RT access DefaultConstructable data = box; @@ -139,12 +153,12 @@ TEST(RealtimeThreadSafeBox, typecast_operator) } } -TEST(RealtimeThreadSafeBox, pointer_type) +TYPED_TEST(TypedRealtimeThreadSafeBox, pointer_type) { int a = 100; int * ptr = &a; - RealtimeThreadSafeBox box(ptr); + RealtimeThreadSafeBox box(ptr); // This does not and should not compile! // auto value = box.get(); @@ -159,11 +173,11 @@ TEST(RealtimeThreadSafeBox, pointer_type) box.try_get([](const auto & i) { EXPECT_EQ(*i, 200); }); } -TEST(RealtimeThreadSafeBox, smart_ptr_type) +TYPED_TEST(TypedRealtimeThreadSafeBox, smart_ptr_type) { std::shared_ptr ptr = std::make_shared(100); - RealtimeThreadSafeBox> box(ptr); + RealtimeThreadSafeBox, TypeParam> box(ptr); // Instead access it via a passed function. // This assures that we access the data within the scope of the lock @@ -181,7 +195,7 @@ TEST(RealtimeThreadSafeBox, smart_ptr_type) box.try_get([](const auto & p) { EXPECT_EQ(*p, 10); }); // Test that we are able to set the nullptr for pointer types - RealtimeThreadSafeBox> box2; + RealtimeThreadSafeBox, TypeParam> box2; box2.set(nullptr); } @@ -196,28 +210,28 @@ class DefaultConstructable_existing int number_; }; -TEST(RealtimeThreadSafeBox, default_construct_existing) +TYPED_TEST(TypedRealtimeThreadSafeBox, default_construct_existing) { DefaultConstructable_existing thing; thing.number_ = 5; - RealtimeThreadSafeBox box; + RealtimeThreadSafeBox box; box.get(thing); EXPECT_EQ(42, thing.number_); } -TEST(RealtimeThreadSafeBox, initial_value_existing) +TYPED_TEST(TypedRealtimeThreadSafeBox, initial_value_existing) { - RealtimeThreadSafeBox box(3.14); + RealtimeThreadSafeBox box(3.14); double num = 0.0; box.get(num); EXPECT_DOUBLE_EQ(3.14, num); } -TEST(RealtimeThreadSafeBox, set_and_get_existing) +TYPED_TEST(TypedRealtimeThreadSafeBox, set_and_get_existing) { - RealtimeThreadSafeBox box('a'); + RealtimeThreadSafeBox box('a'); { const char input = 'z'; @@ -229,38 +243,38 @@ TEST(RealtimeThreadSafeBox, set_and_get_existing) EXPECT_EQ('z', output); } -TEST(RealtimeThreadSafeBox, copy_assign) +TYPED_TEST(TypedRealtimeThreadSafeBox, copy_assign) { - RealtimeThreadSafeBox box_a('a'); - RealtimeThreadSafeBox box_b('b'); + RealtimeThreadSafeBox box_a('a'); + RealtimeThreadSafeBox box_b('b'); // Assign b to a -> a should now contain b box_a = box_b; EXPECT_EQ('b', box_a.try_get().value()); } -TEST(RealtimeThreadSafeBox, copy) +TYPED_TEST(TypedRealtimeThreadSafeBox, copy) { - RealtimeThreadSafeBox box_b('b'); - RealtimeThreadSafeBox box_a(box_b); + RealtimeThreadSafeBox box_b('b'); + RealtimeThreadSafeBox box_a(box_b); EXPECT_EQ('b', box_a.try_get().value()); } -TEST(RealtimeThreadSafeBox, move_assign) +TYPED_TEST(TypedRealtimeThreadSafeBox, move_assign) { - RealtimeThreadSafeBox box_a('a'); - RealtimeThreadSafeBox box_b('b'); + RealtimeThreadSafeBox box_a('a'); + RealtimeThreadSafeBox box_b('b'); // Move b to a -> a should now contain b box_a = std::move(box_b); EXPECT_EQ('b', box_a.try_get().value()); } -TEST(RealtimeThreadSafeBox, move) +TYPED_TEST(TypedRealtimeThreadSafeBox, move) { - RealtimeThreadSafeBox box_b('b'); - RealtimeThreadSafeBox box_a(std::move(box_b)); + RealtimeThreadSafeBox box_b('b'); + RealtimeThreadSafeBox box_a(std::move(box_b)); EXPECT_EQ('b', box_a.try_get().value()); } diff --git a/realtime_tools/test/test_async_function_handler.cpp b/realtime_tools/test/test_async_function_handler.cpp index 58578f4b..ae2b9c3c 100644 --- a/realtime_tools/test/test_async_function_handler.cpp +++ b/realtime_tools/test/test_async_function_handler.cpp @@ -15,7 +15,7 @@ #include #include -#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "rclcpp/node.hpp" #include "rclcpp/rclcpp.hpp" #include "test_async_function_handler.hpp" diff --git a/realtime_tools/test/thread_priority_tests.cpp b/realtime_tools/test/thread_priority_tests.cpp index efda108c..e5f9a034 100644 --- a/realtime_tools/test/thread_priority_tests.cpp +++ b/realtime_tools/test/thread_priority_tests.cpp @@ -28,7 +28,7 @@ // Author: Lennart Nachtigall -#include +#include #include #include