Skip to content

Commit cbe6555

Browse files
committed
Add tests for particle cloud display plugin
1 parent fdfaec9 commit cbe6555

19 files changed

+1237
-2
lines changed

nav2_rviz_plugins/CMakeLists.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,37 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1010
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
1111
endif()
1212

13+
# Tests currently only run on OS X @ OSRF jenkins
14+
# Enable on Linux by providing a displays, enable on Windows via EnableDisplayTests=True
15+
option(EnableDisplayTests "EnableDisplayTests")
16+
set(DisplayTests "False" CACHE STRING "DisplayTestsVariable")
17+
18+
if(DEFINED ENV{DISPLAY})
19+
set(DISPLAYPRESENT TRUE)
20+
endif()
21+
22+
if(APPLE OR DISPLAYPRESENT OR EnableDisplayTests STREQUAL "True")
23+
message(STATUS "Enabling tests requiring a display")
24+
else()
25+
set(SKIP_DISPLAY_TESTS "SKIP_TEST")
26+
endif()
27+
28+
# options and directories for visual tests (see visual_testing_framework documentation)
29+
option(EnableVisualTests "decides whether or not to enable the tests")
30+
31+
add_definitions(-D_BUILD_DIR_PATH="${CMAKE_CURRENT_BINARY_DIR}")
32+
add_definitions(-D_SRC_DIR_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
33+
34+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_images)
35+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test/reference_images)
36+
37+
# Run visual tests only if "EnableVisualTests=True"
38+
if(EnableVisualTests STREQUAL "True")
39+
message(STATUS "Enabling visual tests")
40+
else()
41+
set(SKIP_VISUAL_TESTS "SKIP_TEST")
42+
endif()
43+
1344
# Qt5 boilerplate options from http://doc.qt.io/qt-5/cmake-manual.html
1445
set(CMAKE_INCLUDE_CURRENT_DIR ON)
1546
set(CMAKE_AUTOMOC ON)
@@ -112,7 +143,55 @@ install(
112143

113144
if(BUILD_TESTING)
114145
find_package(ament_lint_auto REQUIRED)
146+
# the following line skips the linter which checks for copyrights
147+
set(ament_cmake_copyright_FOUND TRUE)
115148
ament_lint_auto_find_test_dependencies()
149+
150+
find_package(ament_cmake_gtest REQUIRED)
151+
find_package(ament_cmake_gmock REQUIRED)
152+
find_package(ament_index_cpp REQUIRED)
153+
find_package(rviz_visual_testing_framework REQUIRED)
154+
155+
set(TEST_INCLUDE_DIRS
156+
${OGRE_INCLUDE_DIRS}
157+
${Qt5Widgets_INCLUDE_DIRS}
158+
)
159+
ament_include_directories_order(TEST_INCLUDE_DIRS ${TEST_INCLUDE_DIRS})
160+
161+
set(TEST_LINK_LIBRARIES
162+
${library_name}
163+
)
164+
165+
set(TEST_TARGET_DEPENDENCIES
166+
nav2_msgs
167+
rclcpp
168+
)
169+
170+
ament_add_gmock(particle_cloud_display_test
171+
test/displays/particle_cloud/particle_cloud_display_test.cpp
172+
test/displays/display_test_fixture.cpp
173+
test/scene_graph_introspection_helper.cpp
174+
${SKIP_DISPLAY_TESTS})
175+
if(TARGET particle_cloud_display_test)
176+
target_include_directories(particle_cloud_display_test PUBLIC ${TEST_INCLUDE_DIRS})
177+
target_link_libraries(particle_cloud_display_test ${TEST_LINK_LIBRARIES})
178+
ament_target_dependencies(particle_cloud_display_test ${TEST_TARGET_DEPENDENCIES})
179+
endif()
180+
181+
ament_add_gtest(particle_cloud_display_visual_test
182+
test/displays/particle_cloud/particle_cloud_display_visual_test.cpp
183+
test/displays/particle_cloud/particle_cloud_display_page_object.cpp
184+
test/displays/particle_cloud/particle_cloud_publisher.hpp
185+
${SKIP_VISUAL_TESTS}
186+
TIMEOUT 30)
187+
if(TARGET particle_cloud_display_visual_test)
188+
target_include_directories(particle_cloud_display_visual_test PUBLIC
189+
${TEST_INCLUDE_DIRS}
190+
${rviz_visual_testing_framework_INCLUDE_DIRS})
191+
target_link_libraries(particle_cloud_display_visual_test
192+
${TEST_LINK_LIBRARIES}
193+
rviz_visual_testing_framework::rviz_visual_testing_framework)
194+
endif()
116195
endif()
117196

118197
ament_export_include_directories(include)
@@ -123,6 +202,7 @@ ament_export_dependencies(
123202
geometry_msgs
124203
map_msgs
125204
nav_msgs
205+
nav2_msgs
126206
rclcpp
127207
)
128208

nav2_rviz_plugins/plugins_description.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<description>The Navigation2 rviz panel.</description>
1313
</class>
1414

15-
<class name="nav2_rviz_plugins/ParticleCloudDisplay"
15+
<class name="nav2_rviz_plugins/ParticleCloud"
1616
type="nav2_rviz_plugins::ParticleCloudDisplay"
1717
base_class_type="rviz_common::Display">
1818
<description>The Particle Cloud rviz display.</description>

nav2_rviz_plugins/src/particle_cloud_display/particle_cloud_display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ParticleCloudDisplay::ParticleCloudDisplay(
9797
}
9898

9999
ParticleCloudDisplay::ParticleCloudDisplay()
100-
: min_length_(0.02f), max_length_(0.1f)
100+
: min_length_(0.02f), max_length_(0.3f)
101101
{
102102
initializeProperties();
103103

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2018, Bosch Software Innovations GmbH.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted (subject to the limitations in the disclaimer
7+
* below) provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* * Neither the name of the copyright holder nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
19+
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
* POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
#include "display_test_fixture.hpp"
33+
34+
#include <memory>
35+
36+
#include <OgreSceneNode.h>
37+
38+
void DisplayTestFixture::SetUpTestCase()
39+
{
40+
testing_environment_ = std::make_shared<rviz_rendering::OgreTestingEnvironment>();
41+
testing_environment_->setUpOgreTestEnvironment();
42+
43+
scene_manager_ = Ogre::Root::getSingletonPtr()->createSceneManager();
44+
}
45+
46+
DisplayTestFixture::DisplayTestFixture()
47+
{
48+
context_ = std::make_shared<testing::NiceMock<MockDisplayContext>>();
49+
frame_manager_ = std::make_shared<testing::NiceMock<MockFrameManager>>();
50+
selection_manager_ = std::make_shared<testing::NiceMock<MockSelectionManager>>();
51+
handler_manager_ = std::make_shared<testing::NiceMock<MockHandlerManager>>();
52+
clock_ = std::make_shared<rclcpp::Clock>();
53+
54+
EXPECT_CALL(*frame_manager_, getFixedFrame()).WillRepeatedly(testing::ReturnRef(fixed_frame));
55+
56+
EXPECT_CALL(*context_, getClock()).WillRepeatedly(testing::Return(clock_));
57+
EXPECT_CALL(*context_, getSceneManager()).WillRepeatedly(
58+
testing::Invoke([]() {return scene_manager_;}));
59+
EXPECT_CALL(*context_, getFrameManager()).WillRepeatedly(testing::Return(frame_manager_.get()));
60+
EXPECT_CALL(*context_, getSelectionManager()).WillRepeatedly(
61+
testing::Return(selection_manager_));
62+
EXPECT_CALL(*context_, getHandlerManager()).WillRepeatedly(
63+
testing::Return(handler_manager_));
64+
}
65+
66+
DisplayTestFixture::~DisplayTestFixture()
67+
{
68+
scene_manager_->getRootSceneNode()->removeAndDestroyAllChildren();
69+
}
70+
71+
void DisplayTestFixture::TearDownTestCase()
72+
{
73+
Ogre::Root::getSingletonPtr()->destroySceneManager(scene_manager_);
74+
}
75+
76+
void DisplayTestFixture::mockValidTransform()
77+
{
78+
Ogre::Vector3 position(0, 1, 0);
79+
Ogre::Quaternion orientation(0, 0, 1, 0);
80+
mockValidTransform(position, orientation);
81+
}
82+
83+
void DisplayTestFixture::mockValidTransform(Ogre::Vector3 position, Ogre::Quaternion orientation)
84+
{
85+
EXPECT_CALL(
86+
*frame_manager_,
87+
transform(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) // NOLINT
88+
.WillRepeatedly(
89+
// NOLINT
90+
::testing::DoAll(
91+
::testing::SetArgReferee<3>(position),
92+
::testing::SetArgReferee<4>(orientation),
93+
::testing::Return(true)
94+
));
95+
96+
EXPECT_CALL(
97+
*frame_manager_,
98+
getTransform(::testing::_, ::testing::_, ::testing::_, ::testing::_))
99+
.WillRepeatedly(
100+
// NOLINT
101+
::testing::DoAll(
102+
::testing::SetArgReferee<2>(position),
103+
::testing::SetArgReferee<3>(orientation),
104+
::testing::Return(true)
105+
));
106+
}
107+
108+
Ogre::SceneManager * DisplayTestFixture::scene_manager_ = nullptr;
109+
std::shared_ptr<rviz_rendering::OgreTestingEnvironment>
110+
DisplayTestFixture::testing_environment_ = nullptr;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2018, Bosch Software Innovations GmbH.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted (subject to the limitations in the disclaimer
7+
* below) provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* * Neither the name of the copyright holder nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
19+
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
* POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
#ifndef DISPLAYS__DISPLAY_TEST_FIXTURE_HPP_
33+
#define DISPLAYS__DISPLAY_TEST_FIXTURE_HPP_
34+
35+
#include <gmock/gmock.h>
36+
37+
#include <memory>
38+
#include <string>
39+
40+
#include <QApplication> // NOLINT
41+
42+
#include <OgreRoot.h>
43+
44+
#include "rclcpp/clock.hpp"
45+
46+
#include "test/rviz_rendering/ogre_testing_environment.hpp"
47+
48+
#include "../mock_display_context.hpp"
49+
#include "../mock_frame_manager.hpp"
50+
#include "../mock_selection_manager.hpp"
51+
#include "../mock_handler_manager.hpp"
52+
53+
class DisplayTestFixture : public testing::Test
54+
{
55+
public:
56+
static void SetUpTestCase();
57+
58+
DisplayTestFixture();
59+
60+
~DisplayTestFixture() override;
61+
62+
static void TearDownTestCase();
63+
64+
void mockValidTransform();
65+
66+
void mockValidTransform(Ogre::Vector3 position, Ogre::Quaternion orientation);
67+
68+
static std::shared_ptr<rviz_rendering::OgreTestingEnvironment> testing_environment_;
69+
static Ogre::SceneManager * scene_manager_;
70+
71+
std::shared_ptr<MockDisplayContext> context_;
72+
std::shared_ptr<MockFrameManager> frame_manager_;
73+
std::shared_ptr<MockSelectionManager> selection_manager_;
74+
std::shared_ptr<MockHandlerManager> handler_manager_;
75+
std::shared_ptr<rclcpp::Clock> clock_;
76+
77+
std::string fixed_frame = "fixed_frame";
78+
};
79+
80+
81+
#endif // DISPLAYS__DISPLAY_TEST_FIXTURE_HPP_
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2018, Bosch Software Innovations GmbH.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* * Neither the name of the copyright holder nor the names of its contributors
14+
* may be used to endorse or promote products derived from
15+
* this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
#include "particle_cloud_display_page_object.hpp"
31+
32+
#include <memory>
33+
#include <vector>
34+
35+
ParticleCloudDisplayPageObject::ParticleCloudDisplayPageObject()
36+
: BasePageObject(0, "ParticleCloud")
37+
{
38+
}
39+
40+
void ParticleCloudDisplayPageObject::setTopic(QString topic)
41+
{
42+
setComboBox("Topic", topic);
43+
waitForFirstMessage();
44+
}
45+
46+
void ParticleCloudDisplayPageObject::setShape(QString shape)
47+
{
48+
setComboBox("Shape", shape);
49+
}
50+
51+
void ParticleCloudDisplayPageObject::setColor(int red, int green, int blue)
52+
{
53+
setColorCode("Color", red, green, blue);
54+
}
55+
56+
void ParticleCloudDisplayPageObject::setAlpha(float alpha)
57+
{
58+
setFloat("Alpha", alpha);
59+
}
60+
61+
void ParticleCloudDisplayPageObject::setMaxArrowLength(float max_arrow_length)
62+
{
63+
setFloat("Max Arrow Length", max_arrow_length);
64+
}
65+
66+
void ParticleCloudDisplayPageObject::setMinArrowLength(float min_arrow_length)
67+
{
68+
setFloat("Min Arrow Length", min_arrow_length);
69+
}

0 commit comments

Comments
 (0)