Skip to content

Commit

Permalink
Add basic unit test for PF localization core
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Aug 25, 2023
1 parent d373d6a commit f627c14
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
30 changes: 25 additions & 5 deletions mrpt_pf_localization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,24 @@ ENDIF()
###########

## Declare a cpp executable
add_executable(${PROJECT_NAME}_node
src/${PROJECT_NAME}_node.cpp
add_library(${PROJECT_NAME}_core
src/${PROJECT_NAME}/${PROJECT_NAME}_core.cpp
include/${PROJECT_NAME}/${PROJECT_NAME}_core.h
)

target_include_directories(${PROJECT_NAME}_core
PUBLIC
include
)

target_link_libraries(${PROJECT_NAME}_core
mrpt::gui
mrpt::slam
mrpt::ros2bridge
)

add_executable(${PROJECT_NAME}_node
src/${PROJECT_NAME}_node.cpp
include/${PROJECT_NAME}_node.h
)

Expand All @@ -66,6 +80,7 @@ target_include_directories(${PROJECT_NAME}_node

## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}_node
${PROJECT_NAME}_core
mrpt::gui
mrpt::slam
mrpt::ros2bridge
Expand All @@ -77,6 +92,7 @@ target_link_libraries(${PROJECT_NAME}_node

install(
TARGETS
${PROJECT_NAME}_core
${PROJECT_NAME}_node
DESTINATION
lib/${PROJECT_NAME}
Expand All @@ -88,12 +104,16 @@ install(
)


#find_package(ament_cmake_gtest REQUIRED)
#ament_add_gtest(${PROJECT_NAME}-test test/test_pose_cov_ops.cpp)

ament_export_dependencies()

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(
${PROJECT_NAME}-test test/test_pf_localization.cpp
APPEND_ENV MRPT_LOCALIZATION_SOURCE_DIR=${CMAKE_SOURCE_DIR}
)
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}_core)

find_package(ament_lint_auto REQUIRED)

# the following line skips the linter which checks for copyrights
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class PFLocalizationCore : public mrpt::system::COutputLogger
const std::string& simplemap_file);

// TODO: Getters
State getState() const { return state_.fsm_state; }

/** @} */

Expand Down
27 changes: 27 additions & 0 deletions mrpt_pf_localization/test/test_pf_localization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* +------------------------------------------------------------------------+
| mrpt_navigation |
| |
| Copyright (c) 2014-2023, Individual contributors, see commit authors |
| See: https://github.com/mrpt-ros-pkg/mrpt_navigation |
| All rights reserved. Released under BSD 3-Clause license. See LICENSE |
+------------------------------------------------------------------------+ */

#include <gtest/gtest.h>
#include <mrpt_pf_localization/mrpt_pf_localization_core.h>

TEST(PF_Localization, InitState)
{
PFLocalizationCore loc;

for (int i = 0; i < 10; i++)
{
EXPECT_EQ(loc.getState(), PFLocalizationCore::State::UNINITIALIZED);
loc.step();
}
}

int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit f627c14

Please sign in to comment.