Skip to content

Commit

Permalink
Remove necessity for defining private=public in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
urfeex committed Jan 10, 2025
1 parent ad2004b commit d8eecf9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 19 deletions.
4 changes: 3 additions & 1 deletion include/ur_client_library/ur/dashboard_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +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);
VersionInformation polyscope_version_;

/*!
* \brief Gets the configured receive timeout. If receive timeout is unconfigured "normal" socket timeout of 1 second
Expand All @@ -455,6 +454,9 @@ class DashboardClient : public comm::TCPSocket
*/
timeval getConfiguredReceiveTimeout() const;

protected:
VersionInformation polyscope_version_;

private:
bool send(const std::string& text);
std::string read();
Expand Down
9 changes: 6 additions & 3 deletions include/ur_client_library/ur/ur_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<comm::URStream<primary_interface::PrimaryPackage>> primary_stream_;
std::unique_ptr<comm::URStream<primary_interface::PrimaryPackage>> secondary_stream_;

private:
/*!
* \brief Reconnects the secondary stream used to send program to the robot.
*
Expand All @@ -667,8 +672,6 @@ class UrDriver
std::unique_ptr<control::TrajectoryPointInterface> trajectory_interface_;
std::unique_ptr<control::ScriptCommandInterface> script_command_interface_;
std::unique_ptr<control::ScriptSender> script_sender_;
std::unique_ptr<comm::URStream<primary_interface::PrimaryPackage>> primary_stream_;
std::unique_ptr<comm::URStream<primary_interface::PrimaryPackage>> secondary_stream_;

double force_mode_gain_scale_factor_ = 0.5;
double force_mode_damping_factor_ = 0.025;
Expand Down
33 changes: 25 additions & 8 deletions tests/test_dashboard_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,36 @@ 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()
{
dashboard_client_.reset();
}

std::unique_ptr<DashboardClient> dashboard_client_;
std::unique_ptr<TestableDashboardClient> dashboard_client_;
};

TEST_F(DashboardClientTest, connect)
Expand Down Expand Up @@ -142,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);
}
Expand All @@ -156,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);
}
Expand Down
32 changes: 25 additions & 7 deletions tests/test_ur_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <gtest/gtest.h>

#include <ur_client_library/ur/dashboard_client.h>
#define private public
#include <ur_client_library/ur/ur_driver.h>

using namespace urcl;
Expand All @@ -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<UrDriver> 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<void(bool)> handle_program_state,
bool headless_mode, std::unique_ptr<ToolCommSetup> 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<TestableUrDriver> g_ur_driver;
std::unique_ptr<DashboardClient> g_dashboard_client;

bool g_program_running;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -370,7 +388,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());
}
Expand Down

0 comments on commit d8eecf9

Please sign in to comment.