From 8cabc9654cdecc70f068185728dcc500445024ac Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Fri, 10 Jan 2025 15:34:47 +0100 Subject: [PATCH] Remove necessity for defining private=public in tests --- .../ur_client_library/ur/dashboard_client.h | 11 +++--- include/ur_client_library/ur/ur_driver.h | 9 +++-- tests/test_dashboard_client.cpp | 34 ++++++++++++++----- tests/test_ur_driver.cpp | 32 +++++++++++++---- 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/include/ur_client_library/ur/dashboard_client.h b/include/ur_client_library/ur/dashboard_client.h index 579c7bb19..6d4286ed5 100644 --- a/include/ur_client_library/ur/dashboard_client.h +++ b/include/ur_client_library/ur/dashboard_client.h @@ -434,7 +434,6 @@ class DashboardClient : public comm::TCPSocket */ bool commandSaveLog(); -private: /*! * \brief Makes sure that the dashboard_server's version is above the required version * @@ -446,9 +445,6 @@ class DashboardClient : public comm::TCPSocket */ void assertVersion(const std::string& e_series_min_ver, const std::string& cb3_min_ver, const std::string& required_call); - bool send(const std::string& text); - std::string read(); - void rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); /*! * \brief Gets the configured receive timeout. If receive timeout is unconfigured "normal" socket timeout of 1 second @@ -458,7 +454,14 @@ class DashboardClient : public comm::TCPSocket */ timeval getConfiguredReceiveTimeout() const; +protected: VersionInformation polyscope_version_; + +private: + bool send(const std::string& text); + std::string read(); + void rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); + std::string host_; int port_; std::mutex write_mutex_; diff --git a/include/ur_client_library/ur/ur_driver.h b/include/ur_client_library/ur/ur_driver.h index 45d7dd2fc..e9c6395b5 100644 --- a/include/ur_client_library/ur/ur_driver.h +++ b/include/ur_client_library/ur/ur_driver.h @@ -647,8 +647,13 @@ class UrDriver void resetRTDEClient(const std::string& output_recipe_filename, const std::string& input_recipe_filename, double target_frequency = 0.0, bool ignore_unavailable_outputs = false); -private: static std::string readScriptFile(const std::string& filename); + +protected: + std::unique_ptr> primary_stream_; + std::unique_ptr> secondary_stream_; + +private: /*! * \brief Reconnects the secondary stream used to send program to the robot. * @@ -667,8 +672,6 @@ class UrDriver std::unique_ptr trajectory_interface_; std::unique_ptr script_command_interface_; std::unique_ptr script_sender_; - std::unique_ptr> primary_stream_; - std::unique_ptr> secondary_stream_; double force_mode_gain_scale_factor_ = 0.5; double force_mode_damping_factor_ = 0.025; diff --git a/tests/test_dashboard_client.cpp b/tests/test_dashboard_client.cpp index 1ef235c8c..8b67ff84f 100644 --- a/tests/test_dashboard_client.cpp +++ b/tests/test_dashboard_client.cpp @@ -34,19 +34,34 @@ #include #include "ur_client_library/comm/tcp_socket.h" #include "ur_client_library/ur/version_information.h" -#define private public #include using namespace urcl; std::string g_ROBOT_IP = "192.168.56.101"; +class TestableDashboardClient : public DashboardClient +{ +public: + TestableDashboardClient(const std::string& host) : DashboardClient(host) + { + } + void setPolyscopeVersion(const std::string& version) + { + polyscope_version_ = VersionInformation::fromString(version); + } + VersionInformation getPolyscopeVersion() + { + return polyscope_version_; + } +}; + class DashboardClientTest : public ::testing::Test { protected: void SetUp() { - dashboard_client_.reset(new DashboardClient(g_ROBOT_IP)); + dashboard_client_.reset(new TestableDashboardClient(g_ROBOT_IP)); } void TearDown() @@ -54,7 +69,7 @@ class DashboardClientTest : public ::testing::Test dashboard_client_.reset(); } - std::unique_ptr dashboard_client_; + std::unique_ptr dashboard_client_; }; TEST_F(DashboardClientTest, connect) @@ -143,11 +158,11 @@ TEST_F(DashboardClientTest, e_series_version) { std::string msg; EXPECT_TRUE(dashboard_client_->connect()); - if (!dashboard_client_->polyscope_version_.isESeries()) + if (!dashboard_client_->getPolyscopeVersion().isESeries()) GTEST_SKIP(); - dashboard_client_->polyscope_version_ = VersionInformation::fromString("5.0.0"); + dashboard_client_->setPolyscopeVersion("5.0.0"); EXPECT_THROW(dashboard_client_->commandSafetyStatus(msg), UrException); - dashboard_client_->polyscope_version_ = VersionInformation::fromString("5.5.0"); + dashboard_client_->setPolyscopeVersion("5.5.0"); EXPECT_TRUE(dashboard_client_->commandSafetyStatus(msg)); EXPECT_THROW(dashboard_client_->commandSetUserRole("none"), UrException); } @@ -157,11 +172,12 @@ TEST_F(DashboardClientTest, cb3_version) { std::string msg; EXPECT_TRUE(dashboard_client_->connect()); - if (dashboard_client_->polyscope_version_.isESeries()) + if (dashboard_client_->getPolyscopeVersion().isESeries()) GTEST_SKIP(); - dashboard_client_->polyscope_version_ = VersionInformation::fromString("1.6.0"); + + dashboard_client_->setPolyscopeVersion("1.6.0"); EXPECT_THROW(dashboard_client_->commandIsProgramSaved(), UrException); - dashboard_client_->polyscope_version_ = VersionInformation::fromString("1.8.0"); + dashboard_client_->setPolyscopeVersion("1.8.0"); EXPECT_TRUE(dashboard_client_->commandIsProgramSaved()); EXPECT_THROW(dashboard_client_->commandIsInRemoteControl(), UrException); } diff --git a/tests/test_ur_driver.cpp b/tests/test_ur_driver.cpp index 8ec2b989d..5f703bfd7 100644 --- a/tests/test_ur_driver.cpp +++ b/tests/test_ur_driver.cpp @@ -31,7 +31,6 @@ #include #include -#define private public #include using namespace urcl; @@ -42,7 +41,24 @@ const std::string INPUT_RECIPE = "resources/rtde_input_recipe.txt"; const std::string CALIBRATION_CHECKSUM = "calib_12788084448423163542"; std::string g_ROBOT_IP = "192.168.56.101"; -std::unique_ptr g_ur_driver; +class TestableUrDriver : public UrDriver +{ +public: + TestableUrDriver(const std::string& robot_ip, const std::string& script_file, const std::string& output_recipe_file, + const std::string& input_recipe_file, std::function handle_program_state, + bool headless_mode, std::unique_ptr tool_comm_setup, + const std::string& calibration_checksum) + : UrDriver(robot_ip, script_file, output_recipe_file, input_recipe_file, handle_program_state, headless_mode, + std::move(tool_comm_setup), calibration_checksum) + { + } + void closeSecondaryStream() + { + secondary_stream_->close(); + } +}; + +std::unique_ptr g_ur_driver; std::unique_ptr g_dashboard_client; bool g_program_running; @@ -118,16 +134,18 @@ class UrDriverTest : public ::testing::Test const bool headless = true; try { - g_ur_driver.reset(new UrDriver(g_ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, &handleRobotProgramState, - headless, std::move(tool_comm_setup), CALIBRATION_CHECKSUM)); + g_ur_driver.reset(new TestableUrDriver(g_ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, + &handleRobotProgramState, headless, std::move(tool_comm_setup), + CALIBRATION_CHECKSUM)); } catch (UrException& exp) { std::cout << "caught exception " << exp.what() << " while launch driver, retrying once in 10 seconds" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(10)); - g_ur_driver.reset(new UrDriver(g_ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, &handleRobotProgramState, - headless, std::move(tool_comm_setup), CALIBRATION_CHECKSUM)); + g_ur_driver.reset(new TestableUrDriver(g_ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, + &handleRobotProgramState, headless, std::move(tool_comm_setup), + CALIBRATION_CHECKSUM)); } g_ur_driver->startRTDECommunication(); // Setup rtde read thread @@ -367,7 +385,7 @@ TEST_F(UrDriverTest, send_robot_program_retry_on_failure) // Check that sendRobotProgram is robust to the secondary stream being disconnected. This is what happens when // switching from Remote to Local and back to Remote mode for example. - g_ur_driver->secondary_stream_->close(); + g_ur_driver->closeSecondaryStream(); EXPECT_TRUE(g_ur_driver->sendRobotProgram()); }