Skip to content

Commit 1abca39

Browse files
committed
Added integration test for primary client
1 parent d400328 commit 1abca39

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

tests/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ if (INTEGRATION_TESTS)
7878
EXTRA_ARGS --headless true
7979
TEST_SUFFIX _headless
8080
)
81+
82+
# PrimaryClient tests
83+
add_executable(primary_client_test_urcap test_primary_client.cpp)
84+
target_link_libraries(primary_client_test_urcap PRIVATE ur_client_library::urcl GTest::gtest_main)
85+
gtest_add_tests(TARGET primary_client_test_urcap
86+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
87+
EXTRA_ARGS --headless false
88+
TEST_SUFFIX _urcap
89+
)
90+
add_executable(primary_client_test_headless test_primary_client.cpp)
91+
target_link_libraries(primary_client_test_headless PRIVATE ur_client_library::urcl GTest::gtest_main)
92+
gtest_add_tests(TARGET primary_client_test_headless
93+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
94+
EXTRA_ARGS --headless true
95+
TEST_SUFFIX _headless
96+
)
8197
else()
8298
message(STATUS "Skipping integration tests.")
8399
endif()

tests/test_primary_client.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
2+
// Copyright 2025 Universal Robots A/S
3+
//
4+
// Redistribution and use in source and binary forms, with or without
5+
// modification, are permitted provided that the following conditions are met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
//
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+
//
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+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
// POSSIBILITY OF SUCH DAMAGE.
29+
// -- END LICENSE BLOCK ------------------------------------------------
30+
31+
#include <gtest/gtest.h>
32+
33+
#include <ur_client_library/primary/primary_client.h>
34+
#include <ur_client_library/ur/calibration_checker.h>
35+
#include <memory>
36+
37+
using namespace urcl;
38+
39+
std::string g_ROBOT_IP = "192.168.56.101";
40+
41+
class PrimaryClientTest : public ::testing::Test
42+
{
43+
protected:
44+
void SetUp() override
45+
{
46+
client_ = std::make_unique<primary_interface::PrimaryClient>(g_ROBOT_IP, notifier_);
47+
}
48+
49+
std::unique_ptr<primary_interface::PrimaryClient> client_;
50+
comm::INotifier notifier_;
51+
};
52+
53+
TEST_F(PrimaryClientTest, start_communication_succeeds)
54+
{
55+
EXPECT_NO_THROW(client_->start());
56+
}
57+
58+
TEST_F(PrimaryClientTest, add_and_remove_consumer)
59+
{
60+
auto calibration_consumer = std::make_shared<urcl::CalibrationChecker>("test");
61+
62+
client_->addPrimaryConsumer(calibration_consumer);
63+
64+
EXPECT_NO_THROW(client_->start());
65+
66+
auto start_time = std::chrono::system_clock::now();
67+
const auto timeout = std::chrono::seconds(5);
68+
while (!calibration_consumer->isChecked() && std::chrono::system_clock::now() - start_time < timeout)
69+
{
70+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
71+
}
72+
EXPECT_TRUE(calibration_consumer->isChecked());
73+
74+
client_->removePrimaryConsumer(calibration_consumer);
75+
}
76+
77+
int main(int argc, char* argv[])
78+
{
79+
::testing::InitGoogleTest(&argc, argv);
80+
81+
return RUN_ALL_TESTS();
82+
}

0 commit comments

Comments
 (0)