Skip to content

Commit 8cabc96

Browse files
committed
Remove necessity for defining private=public in tests
1 parent 10602c0 commit 8cabc96

File tree

4 files changed

+63
-23
lines changed

4 files changed

+63
-23
lines changed

include/ur_client_library/ur/dashboard_client.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ class DashboardClient : public comm::TCPSocket
434434
*/
435435
bool commandSaveLog();
436436

437-
private:
438437
/*!
439438
* \brief Makes sure that the dashboard_server's version is above the required version
440439
*
@@ -446,9 +445,6 @@ class DashboardClient : public comm::TCPSocket
446445
*/
447446
void assertVersion(const std::string& e_series_min_ver, const std::string& cb3_min_ver,
448447
const std::string& required_call);
449-
bool send(const std::string& text);
450-
std::string read();
451-
void rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
452448

453449
/*!
454450
* \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
458454
*/
459455
timeval getConfiguredReceiveTimeout() const;
460456

457+
protected:
461458
VersionInformation polyscope_version_;
459+
460+
private:
461+
bool send(const std::string& text);
462+
std::string read();
463+
void rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
464+
462465
std::string host_;
463466
int port_;
464467
std::mutex write_mutex_;

include/ur_client_library/ur/ur_driver.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,13 @@ class UrDriver
647647
void resetRTDEClient(const std::string& output_recipe_filename, const std::string& input_recipe_filename,
648648
double target_frequency = 0.0, bool ignore_unavailable_outputs = false);
649649

650-
private:
651650
static std::string readScriptFile(const std::string& filename);
651+
652+
protected:
653+
std::unique_ptr<comm::URStream<primary_interface::PrimaryPackage>> primary_stream_;
654+
std::unique_ptr<comm::URStream<primary_interface::PrimaryPackage>> secondary_stream_;
655+
656+
private:
652657
/*!
653658
* \brief Reconnects the secondary stream used to send program to the robot.
654659
*
@@ -667,8 +672,6 @@ class UrDriver
667672
std::unique_ptr<control::TrajectoryPointInterface> trajectory_interface_;
668673
std::unique_ptr<control::ScriptCommandInterface> script_command_interface_;
669674
std::unique_ptr<control::ScriptSender> script_sender_;
670-
std::unique_ptr<comm::URStream<primary_interface::PrimaryPackage>> primary_stream_;
671-
std::unique_ptr<comm::URStream<primary_interface::PrimaryPackage>> secondary_stream_;
672675

673676
double force_mode_gain_scale_factor_ = 0.5;
674677
double force_mode_damping_factor_ = 0.025;

tests/test_dashboard_client.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,42 @@
3434
#include <thread>
3535
#include "ur_client_library/comm/tcp_socket.h"
3636
#include "ur_client_library/ur/version_information.h"
37-
#define private public
3837
#include <ur_client_library/ur/dashboard_client.h>
3938

4039
using namespace urcl;
4140

4241
std::string g_ROBOT_IP = "192.168.56.101";
4342

43+
class TestableDashboardClient : public DashboardClient
44+
{
45+
public:
46+
TestableDashboardClient(const std::string& host) : DashboardClient(host)
47+
{
48+
}
49+
void setPolyscopeVersion(const std::string& version)
50+
{
51+
polyscope_version_ = VersionInformation::fromString(version);
52+
}
53+
VersionInformation getPolyscopeVersion()
54+
{
55+
return polyscope_version_;
56+
}
57+
};
58+
4459
class DashboardClientTest : public ::testing::Test
4560
{
4661
protected:
4762
void SetUp()
4863
{
49-
dashboard_client_.reset(new DashboardClient(g_ROBOT_IP));
64+
dashboard_client_.reset(new TestableDashboardClient(g_ROBOT_IP));
5065
}
5166

5267
void TearDown()
5368
{
5469
dashboard_client_.reset();
5570
}
5671

57-
std::unique_ptr<DashboardClient> dashboard_client_;
72+
std::unique_ptr<TestableDashboardClient> dashboard_client_;
5873
};
5974

6075
TEST_F(DashboardClientTest, connect)
@@ -143,11 +158,11 @@ TEST_F(DashboardClientTest, e_series_version)
143158
{
144159
std::string msg;
145160
EXPECT_TRUE(dashboard_client_->connect());
146-
if (!dashboard_client_->polyscope_version_.isESeries())
161+
if (!dashboard_client_->getPolyscopeVersion().isESeries())
147162
GTEST_SKIP();
148-
dashboard_client_->polyscope_version_ = VersionInformation::fromString("5.0.0");
163+
dashboard_client_->setPolyscopeVersion("5.0.0");
149164
EXPECT_THROW(dashboard_client_->commandSafetyStatus(msg), UrException);
150-
dashboard_client_->polyscope_version_ = VersionInformation::fromString("5.5.0");
165+
dashboard_client_->setPolyscopeVersion("5.5.0");
151166
EXPECT_TRUE(dashboard_client_->commandSafetyStatus(msg));
152167
EXPECT_THROW(dashboard_client_->commandSetUserRole("none"), UrException);
153168
}
@@ -157,11 +172,12 @@ TEST_F(DashboardClientTest, cb3_version)
157172
{
158173
std::string msg;
159174
EXPECT_TRUE(dashboard_client_->connect());
160-
if (dashboard_client_->polyscope_version_.isESeries())
175+
if (dashboard_client_->getPolyscopeVersion().isESeries())
161176
GTEST_SKIP();
162-
dashboard_client_->polyscope_version_ = VersionInformation::fromString("1.6.0");
177+
178+
dashboard_client_->setPolyscopeVersion("1.6.0");
163179
EXPECT_THROW(dashboard_client_->commandIsProgramSaved(), UrException);
164-
dashboard_client_->polyscope_version_ = VersionInformation::fromString("1.8.0");
180+
dashboard_client_->setPolyscopeVersion("1.8.0");
165181
EXPECT_TRUE(dashboard_client_->commandIsProgramSaved());
166182
EXPECT_THROW(dashboard_client_->commandIsInRemoteControl(), UrException);
167183
}

tests/test_ur_driver.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <gtest/gtest.h>
3232

3333
#include <ur_client_library/ur/dashboard_client.h>
34-
#define private public
3534
#include <ur_client_library/ur/ur_driver.h>
3635

3736
using namespace urcl;
@@ -42,7 +41,24 @@ const std::string INPUT_RECIPE = "resources/rtde_input_recipe.txt";
4241
const std::string CALIBRATION_CHECKSUM = "calib_12788084448423163542";
4342
std::string g_ROBOT_IP = "192.168.56.101";
4443

45-
std::unique_ptr<UrDriver> g_ur_driver;
44+
class TestableUrDriver : public UrDriver
45+
{
46+
public:
47+
TestableUrDriver(const std::string& robot_ip, const std::string& script_file, const std::string& output_recipe_file,
48+
const std::string& input_recipe_file, std::function<void(bool)> handle_program_state,
49+
bool headless_mode, std::unique_ptr<ToolCommSetup> tool_comm_setup,
50+
const std::string& calibration_checksum)
51+
: UrDriver(robot_ip, script_file, output_recipe_file, input_recipe_file, handle_program_state, headless_mode,
52+
std::move(tool_comm_setup), calibration_checksum)
53+
{
54+
}
55+
void closeSecondaryStream()
56+
{
57+
secondary_stream_->close();
58+
}
59+
};
60+
61+
std::unique_ptr<TestableUrDriver> g_ur_driver;
4662
std::unique_ptr<DashboardClient> g_dashboard_client;
4763

4864
bool g_program_running;
@@ -118,16 +134,18 @@ class UrDriverTest : public ::testing::Test
118134
const bool headless = true;
119135
try
120136
{
121-
g_ur_driver.reset(new UrDriver(g_ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, &handleRobotProgramState,
122-
headless, std::move(tool_comm_setup), CALIBRATION_CHECKSUM));
137+
g_ur_driver.reset(new TestableUrDriver(g_ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE,
138+
&handleRobotProgramState, headless, std::move(tool_comm_setup),
139+
CALIBRATION_CHECKSUM));
123140
}
124141
catch (UrException& exp)
125142
{
126143
std::cout << "caught exception " << exp.what() << " while launch driver, retrying once in 10 seconds"
127144
<< std::endl;
128145
std::this_thread::sleep_for(std::chrono::seconds(10));
129-
g_ur_driver.reset(new UrDriver(g_ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, &handleRobotProgramState,
130-
headless, std::move(tool_comm_setup), CALIBRATION_CHECKSUM));
146+
g_ur_driver.reset(new TestableUrDriver(g_ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE,
147+
&handleRobotProgramState, headless, std::move(tool_comm_setup),
148+
CALIBRATION_CHECKSUM));
131149
}
132150
g_ur_driver->startRTDECommunication();
133151
// Setup rtde read thread
@@ -367,7 +385,7 @@ TEST_F(UrDriverTest, send_robot_program_retry_on_failure)
367385

368386
// Check that sendRobotProgram is robust to the secondary stream being disconnected. This is what happens when
369387
// switching from Remote to Local and back to Remote mode for example.
370-
g_ur_driver->secondary_stream_->close();
388+
g_ur_driver->closeSecondaryStream();
371389

372390
EXPECT_TRUE(g_ur_driver->sendRobotProgram());
373391
}

0 commit comments

Comments
 (0)