diff --git a/CMakeLists.txt b/CMakeLists.txt index 1443b1d1..1c287d48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,6 +153,7 @@ target_link_libraries(lkf_example # ) add_executable(vector_converter_example src/vector_converter/example.cpp) + target_link_libraries(vector_converter_example # MrsLib_VectorConverter ${catkin_LIBRARIES} @@ -170,6 +171,7 @@ target_link_libraries(ukf_example ) add_executable(nckf_tests src/nckf/nckf_tests.cpp) + target_link_libraries(nckf_tests ${catkin_LIBRARIES} ${Eigen_LIBRARIES} @@ -363,6 +365,19 @@ target_link_libraries(cyclic_example ${Eigen_LIBRARIES} ) +## -------------------------------------------------------------- +## | Testing | +## -------------------------------------------------------------- + +if(CATKIN_ENABLE_TESTING) + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + + add_subdirectory(test) + +endif() + ## -------------------------------------------------------------- ## | Install | ## -------------------------------------------------------------- @@ -381,263 +396,3 @@ install(DIRECTORY DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} FILES_MATCHING PATTERN "*.xml" ) - -## -------------------------------------------------------------- -## | Testing | -## -------------------------------------------------------------- - -if(CATKIN_ENABLE_TESTING) - - find_package(rostest REQUIRED) - - add_rostest_gtest( - TimeoutManagerTest - test/timeout_manager/timeout_manager.test - test/timeout_manager/test.cpp - ) - target_link_libraries( - TimeoutManagerTest - MrsLib_TimeoutManager - MrsLib_Utils - ${catkin_LIBRARIES} - ) - add_dependencies( - TimeoutManagerTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest(MathTest - test/math/math.test - test/math/test.cpp - ) - - target_link_libraries(MathTest - MrsLib_Math - ${catkin_LIBRARIES} - ) - - add_dependencies(MathTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - GeometryTest - test/geometry/geometry.test - test/geometry/test.cpp - ) - - target_link_libraries( - GeometryTest - MrsLib_Geometry - ${catkin_LIBRARIES} - ) - - add_dependencies( - GeometryTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - AttitudeConverterTest - test/attitude_converter/attitude_converter.test - test/attitude_converter/test.cpp - ) - - target_link_libraries( - AttitudeConverterTest - MrsLib_AttitudeConverter - ${catkin_LIBRARIES} - ) - - add_dependencies( - AttitudeConverterTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - UtilsTest - test/utils/utils.test - test/utils/test.cpp - ) - - target_link_libraries( - UtilsTest - MrsLib_Utils - ${catkin_LIBRARIES} - ) - - add_dependencies( - UtilsTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - UkfTest - test/ukf/ukf.test - test/ukf/test.cpp - ) - - target_link_libraries( - UkfTest - ${catkin_LIBRARIES} - ) - - add_dependencies( - UkfTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - TransformerTest - test/transformer/transformer.test - test/transformer/test.cpp - ) - - target_link_libraries( - TransformerTest - MrsLib_Transformer - MrsLib_Geometry - ${catkin_LIBRARIES} - ) - - add_dependencies( - TransformerTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - ParamLoaderTest - test/param_loader/param_loader.test - test/param_loader/test.cpp - ) - target_link_libraries( - ParamLoaderTest - MrsLib_ParamLoader - ${catkin_LIBRARIES} - ) - add_dependencies( - ParamLoaderTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - SubscribeHandlerTest - test/subscribe_handler/subscribe_handler.test - test/subscribe_handler/test.cpp - ) - target_link_libraries( - SubscribeHandlerTest - MrsLib_TimeoutManager - ${catkin_LIBRARIES} - ) - add_dependencies( - SubscribeHandlerTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - RepredictorTest - test/repredictor/repredictor.test - test/repredictor/test.cpp - ) - target_link_libraries( - RepredictorTest - ${catkin_LIBRARIES} - ) - add_dependencies( - RepredictorTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - TimerTest - test/timer/timer.test - test/timer/test.cpp - ) - target_link_libraries( - TimerTest - MrsLib_Timer - MrsLib_Utils - ${catkin_LIBRARIES} - ) - add_dependencies( - TimerTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - MedianFilterTest - test/median_filter/median_filter.test - test/median_filter/test.cpp - ) - target_link_libraries( - MedianFilterTest - MrsLib_MedianFilter - ${catkin_LIBRARIES} - ) - add_dependencies( - MedianFilterTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - ServiceClientHandlerTest - test/service_client_handler/service_client_handler.test - test/service_client_handler/test.cpp - ) - target_link_libraries( - ServiceClientHandlerTest - ${catkin_LIBRARIES} - ) - add_dependencies( - ServiceClientHandlerTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - add_rostest_gtest( - PublisherHandlerTest - test/publisher_handler/publisher_handler.test - test/publisher_handler/test.cpp - ) - target_link_libraries( - PublisherHandlerTest - ${catkin_LIBRARIES} - ) - add_dependencies( - PublisherHandlerTest - ${${PROJECT_NAME}_EXPORTED_TARGETS} - ${catkin_EXPORTED_TARGETS} - ) - - # add_rostest_gtest( - # VectorConverterTest - # test/vector_converter/vector_converter.test - # test/vector_converter/test.cpp - # ) - # target_link_libraries( - # VectorConverterTest - # ${catkin_LIBRARIES} - # ) - # target_include_directories(VectorConverterTest PRIVATE - # ${pcl_ros_INCLUDE_DIRS} - # ) - # add_dependencies( - # VectorConverterTest - # ${${PROJECT_NAME}_EXPORTED_TARGETS} - # ${catkin_EXPORTED_TARGETS} - # ) - -endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..868167f4 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,256 @@ +find_package(rostest REQUIRED) + +# TimeoutManager + +add_rostest_gtest(TimeoutManagerTest + timeout_manager/timeout_manager.test + timeout_manager/test.cpp + ) + +target_link_libraries(TimeoutManagerTest + MrsLib_TimeoutManager + MrsLib_Utils + ${catkin_LIBRARIES} + ) + +add_dependencies(TimeoutManagerTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# MathTest + +add_rostest_gtest(MathTest + math/math.test + math/test.cpp + ) + +target_link_libraries(MathTest + MrsLib_Math + ${catkin_LIBRARIES} + ) + +add_dependencies(MathTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# GeometryTest + +add_rostest_gtest(GeometryTest + geometry/geometry.test + geometry/test.cpp + ) + +target_link_libraries(GeometryTest + MrsLib_Geometry + ${catkin_LIBRARIES} + ) + +add_dependencies(GeometryTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# AttitudeConverterTest + +add_rostest_gtest(AttitudeConverterTest + attitude_converter/attitude_converter.test + attitude_converter/test.cpp + ) + +target_link_libraries(AttitudeConverterTest + MrsLib_AttitudeConverter + ${catkin_LIBRARIES} + ) + +add_dependencies(AttitudeConverterTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# UtilsTest + +add_rostest_gtest(UtilsTest + utils/utils.test + utils/test.cpp + ) + +target_link_libraries(UtilsTest + MrsLib_Utils + ${catkin_LIBRARIES} + ) + +add_dependencies(UtilsTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# UkfTest + +add_rostest_gtest(UkfTest + ukf/ukf.test + ukf/test.cpp + ) + +target_link_libraries(UkfTest + ${catkin_LIBRARIES} + ) + +add_dependencies(UkfTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# TransformerTest + +add_rostest_gtest(TransformerTest + transformer/transformer.test + transformer/test.cpp + ) + +target_link_libraries(TransformerTest + MrsLib_Transformer + MrsLib_Geometry + ${catkin_LIBRARIES} + ) + +add_dependencies(TransformerTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# ParamLoaderTest + +add_rostest_gtest(ParamLoaderTest + param_loader/param_loader.test + param_loader/test.cpp + ) + +target_link_libraries(ParamLoaderTest + MrsLib_ParamLoader + ${catkin_LIBRARIES} + ) + +add_dependencies(ParamLoaderTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# SubscribeHandlerTest + +add_rostest_gtest(SubscribeHandlerTest + subscribe_handler/subscribe_handler.test + subscribe_handler/test.cpp + ) + +target_link_libraries(SubscribeHandlerTest + MrsLib_TimeoutManager + ${catkin_LIBRARIES} + ) + +add_dependencies(SubscribeHandlerTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# RepredictorTest + +add_rostest_gtest(RepredictorTest + repredictor/repredictor.test + repredictor/test.cpp + ) + +target_link_libraries(RepredictorTest + ${catkin_LIBRARIES} + ) + +add_dependencies(RepredictorTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# TimerTest + +add_rostest_gtest(TimerTest + timer/timer.test + timer/test.cpp + ) + +target_link_libraries(TimerTest + MrsLib_Timer + MrsLib_Utils + ${catkin_LIBRARIES} + ) + +add_dependencies(TimerTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# MedianFilterTest + +add_rostest_gtest(MedianFilterTest + median_filter/median_filter.test + median_filter/test.cpp + ) + +target_link_libraries(MedianFilterTest + MrsLib_MedianFilter + ${catkin_LIBRARIES} + ) + +add_dependencies(MedianFilterTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# ServiceClientHandlerTest + +add_rostest_gtest(ServiceClientHandlerTest + service_client_handler/service_client_handler.test + service_client_handler/test.cpp + ) + +target_link_libraries(ServiceClientHandlerTest + ${catkin_LIBRARIES} + ) + +add_dependencies(ServiceClientHandlerTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# PublisherHandlerTest + +add_rostest_gtest(PublisherHandlerTest + publisher_handler/publisher_handler.test + publisher_handler/test.cpp + ) + +target_link_libraries(PublisherHandlerTest + ${catkin_LIBRARIES} + ) + +add_dependencies(PublisherHandlerTest + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +# add_rostest_gtest(VectorConverterTest +# vector_converter/vector_converter.test +# vector_converter/test.cpp +# ) +# +# target_link_libraries(VectorConverterTest +# ${catkin_LIBRARIES} +# ) +# +# target_include_directories(VectorConverterTest PRIVATE +# ${pcl_ros_INCLUDE_DIRS} +# ) +# +# add_dependencies(VectorConverterTest +# ${${PROJECT_NAME}_EXPORTED_TARGETS} +# ${catkin_EXPORTED_TARGETS} +# ) diff --git a/test/mrs_lib.test b/test/mrs_lib.test deleted file mode 100644 index 87febc0d..00000000 --- a/test/mrs_lib.test +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/run_tests.sh b/test/run_tests.sh deleted file mode 100755 index 59cbe789..00000000 --- a/test/run_tests.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -set -e - -trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG -trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR - -PACKAGE="mrs_lib" -VERBOSE=1 - -[ "$VERBOSE" = "0" ] && TEXT_OUTPUT="" -[ "$VERBOSE" = "1" ] && TEXT_OUTPUT="-t" - -# build the package -catkin build $PACKAGE # it has to be fully built normally before building with --catkin-make-args tests -catkin build $PACKAGE --catkin-make-args tests - -# folder for test results -TEST_RESULT_PATH=$(realpath /tmp/$RANDOM) -mkdir -p $TEST_RESULT_PATH - -# run the test -rostest $PACKAGE mrs_lib.test $TEXT_OUTPUT --results-filename=$PACKAGE.test --results-base-dir="$TEST_RESULT_PATH" - -# evaluate the test results -echo test result path is $TEST_RESULT_PATH -catkin_test_results "$TEST_RESULT_PATH" -success=$? - -echo "" -if [ $success = "0" ]; then - echo -e "\033[0;32mSuccess! \033[1;" -else - echo -e "\033[0;31mFailed some tests! \033[1;" -fi