Skip to content

Commit

Permalink
Added integration test for primary client
Browse files Browse the repository at this point in the history
  • Loading branch information
urfeex committed Feb 7, 2025
1 parent d400328 commit 1abca39
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ if (INTEGRATION_TESTS)
EXTRA_ARGS --headless true
TEST_SUFFIX _headless
)

# PrimaryClient tests
add_executable(primary_client_test_urcap test_primary_client.cpp)
target_link_libraries(primary_client_test_urcap PRIVATE ur_client_library::urcl GTest::gtest_main)
gtest_add_tests(TARGET primary_client_test_urcap
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
EXTRA_ARGS --headless false
TEST_SUFFIX _urcap
)
add_executable(primary_client_test_headless test_primary_client.cpp)
target_link_libraries(primary_client_test_headless PRIVATE ur_client_library::urcl GTest::gtest_main)
gtest_add_tests(TARGET primary_client_test_headless
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
EXTRA_ARGS --headless true
TEST_SUFFIX _headless
)
else()
message(STATUS "Skipping integration tests.")
endif()
Expand Down
82 changes: 82 additions & 0 deletions tests/test_primary_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2025 Universal Robots A/S
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the {copyright_holder} nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// -- END LICENSE BLOCK ------------------------------------------------

#include <gtest/gtest.h>

#include <ur_client_library/primary/primary_client.h>
#include <ur_client_library/ur/calibration_checker.h>
#include <memory>

using namespace urcl;

std::string g_ROBOT_IP = "192.168.56.101";

class PrimaryClientTest : public ::testing::Test
{
protected:
void SetUp() override
{
client_ = std::make_unique<primary_interface::PrimaryClient>(g_ROBOT_IP, notifier_);
}

std::unique_ptr<primary_interface::PrimaryClient> client_;
comm::INotifier notifier_;
};

TEST_F(PrimaryClientTest, start_communication_succeeds)
{
EXPECT_NO_THROW(client_->start());
}

TEST_F(PrimaryClientTest, add_and_remove_consumer)
{
auto calibration_consumer = std::make_shared<urcl::CalibrationChecker>("test");

client_->addPrimaryConsumer(calibration_consumer);

EXPECT_NO_THROW(client_->start());

auto start_time = std::chrono::system_clock::now();
const auto timeout = std::chrono::seconds(5);
while (!calibration_consumer->isChecked() && std::chrono::system_clock::now() - start_time < timeout)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
EXPECT_TRUE(calibration_consumer->isChecked());

client_->removePrimaryConsumer(calibration_consumer);
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}

0 comments on commit 1abca39

Please sign in to comment.