Skip to content

Commit 7db381a

Browse files
committed
Minimal unit tests for manager and monitor
IMHO hard to test outside the ROS execution context as they depend on parameters. So mainly relying on launch tests. Signed-off-by: Nordmann Arne (CR/ADT3) <arne.nordmann@de.bosch.com>
1 parent f0db5f3 commit 7db381a

5 files changed

Lines changed: 90 additions & 5 deletions

File tree

.codecov.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

codecov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ignore:
2+
- "system_modes_examples"
3+
- "system_modes/test"
4+
- "**/*_node.cpp"

system_modes/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ if(BUILD_TESTING)
147147
target_link_libraries(test_mode_inference mode)
148148
endif()
149149

150+
ament_add_gtest(test_mode_manager
151+
test/test_mode_manager.cpp
152+
src/system_modes/mode_manager.cpp)
153+
if(TARGET test_mode_manager)
154+
target_include_directories(test_mode_manager PUBLIC
155+
${rclcpp_INCLUDE_DIRS}
156+
${CMAKE_CURRENT_BINARY_DIR}/system_modes/
157+
)
158+
target_link_libraries(test_mode_manager mode)
159+
endif()
160+
161+
ament_add_gtest(test_mode_monitor
162+
test/test_mode_monitor.cpp
163+
src/system_modes/mode_monitor.cpp)
164+
if(TARGET test_mode_monitor)
165+
target_include_directories(test_mode_monitor PUBLIC
166+
${rclcpp_INCLUDE_DIRS}
167+
${CMAKE_CURRENT_BINARY_DIR}/system_modes/
168+
)
169+
target_link_libraries(test_mode_monitor mode)
170+
endif()
171+
150172
# Launch Tests
151173
find_package(launch_testing_ament_cmake REQUIRED)
152174
set(launch_tests
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021 - for information on the respective copyright owner
2+
// see the NOTICE file and/or the repository https://github.com/microros/system_modes
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
#include <rclcpp/rclcpp.hpp>
16+
17+
#include <gtest/gtest.h>
18+
19+
#include <stdexcept>
20+
21+
#include "system_modes/modefiles.h"
22+
#include "system_modes/mode_manager.hpp"
23+
24+
using system_modes::ModeManager;
25+
26+
TEST(TestModeManager, initialization) {
27+
ModeManager * manager;
28+
29+
EXPECT_THROW(manager = new ModeManager(), std::invalid_argument);
30+
31+
(void) manager;
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021 - for information on the respective copyright owner
2+
// see the NOTICE file and/or the repository https://github.com/microros/system_modes
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
#include <rclcpp/rclcpp.hpp>
16+
17+
#include <gtest/gtest.h>
18+
19+
#include <stdexcept>
20+
21+
#include "system_modes/modefiles.h"
22+
#include "system_modes/mode_monitor.hpp"
23+
24+
using system_modes::ModeMonitor;
25+
26+
TEST(TestModeMonitor, initialization) {
27+
ModeMonitor * monitor;
28+
29+
EXPECT_THROW(monitor = new ModeMonitor(), std::invalid_argument);
30+
31+
(void) monitor;
32+
}

0 commit comments

Comments
 (0)