test_dashboard_client.cpp
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
2 // Copyright 2022 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>
33 #include <chrono>
34 #include <thread>
36 #define private public
38 
39 using namespace urcl;
40 
41 std::string ROBOT_IP = "192.168.56.101";
42 
43 class DashboardClientTest : public ::testing::Test
44 {
45 protected:
46  void SetUp()
47  {
48  dashboard_client_.reset(new DashboardClient(ROBOT_IP));
49  }
50 
51  void TearDown()
52  {
53  dashboard_client_.reset();
54  }
55 
56  std::unique_ptr<DashboardClient> dashboard_client_;
57 };
58 
60 {
61  EXPECT_TRUE(dashboard_client_->connect());
62  dashboard_client_->commandCloseSafetyPopup();
63 }
64 
66 {
67  EXPECT_TRUE(dashboard_client_->connect());
68  EXPECT_TRUE(dashboard_client_->commandLoadProgram("wait_program.urp"));
69  EXPECT_TRUE(dashboard_client_->commandPowerOff());
70  dashboard_client_->commandClosePopup(); // Necessary for CB3 test
71  EXPECT_TRUE(dashboard_client_->commandPowerOn());
72  EXPECT_TRUE(dashboard_client_->commandBrakeRelease());
73  EXPECT_TRUE(dashboard_client_->commandPlay());
74  EXPECT_TRUE(dashboard_client_->commandPause());
75  EXPECT_TRUE(dashboard_client_->commandPlay());
76  EXPECT_TRUE(dashboard_client_->commandStop());
77  EXPECT_TRUE(dashboard_client_->commandPowerOff());
78  dashboard_client_->commandClosePopup(); // Necessary for CB3 test
79 }
80 
81 TEST_F(DashboardClientTest, load_installation)
82 {
83  EXPECT_TRUE(dashboard_client_->connect());
84  EXPECT_TRUE(dashboard_client_->commandLoadInstallation("default.installation"));
85 }
86 
87 TEST_F(DashboardClientTest, not_connected)
88 {
89  EXPECT_THROW(dashboard_client_->commandPowerOff(), UrException);
90 }
91 
93 {
94  EXPECT_TRUE(dashboard_client_->connect());
95  EXPECT_TRUE(dashboard_client_->commandPopup("Test Popup"));
96  std::this_thread::sleep_for(std::chrono::milliseconds(500)); // Give time for popup to pop up
97  EXPECT_TRUE(dashboard_client_->commandClosePopup());
98 }
99 
100 TEST_F(DashboardClientTest, log_and_getters)
101 {
102  std::string msg;
103  EXPECT_TRUE(dashboard_client_->connect());
104  EXPECT_TRUE(dashboard_client_->commandAddToLog("Testing Log:"));
105  EXPECT_TRUE(dashboard_client_->commandPolyscopeVersion(msg));
106  EXPECT_TRUE(dashboard_client_->commandAddToLog("Polyscope Version: " + msg));
107  EXPECT_TRUE(dashboard_client_->commandRobotMode(msg));
108  EXPECT_TRUE(dashboard_client_->commandAddToLog("Robot mode: " + msg));
109  EXPECT_TRUE(dashboard_client_->commandGetLoadedProgram(msg));
110  EXPECT_TRUE(dashboard_client_->commandAddToLog("Loaded program: " + msg));
111  EXPECT_TRUE(dashboard_client_->commandProgramState(msg));
112  EXPECT_TRUE(dashboard_client_->commandAddToLog("Program state: " + msg));
113 }
114 
115 TEST_F(DashboardClientTest, flight_report_and_support_file)
116 {
117  EXPECT_TRUE(dashboard_client_->connect());
118  bool correct_polyscope_version = true;
119  try
120  {
121  dashboard_client_->assertVersion("5.6.0", "3.13", "test_function");
122  }
123  catch (const UrException& e)
124  {
125  correct_polyscope_version = false;
126  }
127 
128  if (correct_polyscope_version)
129  {
130  EXPECT_TRUE(dashboard_client_->commandGenerateFlightReport(""));
131  EXPECT_TRUE(dashboard_client_->commandGenerateSupportFile("."));
132  }
133  else
134  {
135  EXPECT_THROW(dashboard_client_->commandGenerateFlightReport(""), UrException);
136  EXPECT_THROW(dashboard_client_->commandGenerateSupportFile("."), UrException);
137  }
138 }
139 
140 // Only runs this test if robot is e-series
141 TEST_F(DashboardClientTest, e_series_version)
142 {
143  std::string msg;
144  EXPECT_TRUE(dashboard_client_->connect());
145  if (!dashboard_client_->polyscope_version_.isESeries())
146  GTEST_SKIP();
147  dashboard_client_->polyscope_version_ = VersionInformation::fromString("5.0.0");
148  EXPECT_THROW(dashboard_client_->commandSafetyStatus(msg), UrException);
149  dashboard_client_->polyscope_version_ = VersionInformation::fromString("5.5.0");
150  EXPECT_TRUE(dashboard_client_->commandSafetyStatus(msg));
151  EXPECT_THROW(dashboard_client_->commandSetUserRole("none"), UrException);
152 }
153 
154 // Only runs this test if robot is CB3
156 {
157  std::string msg;
158  EXPECT_TRUE(dashboard_client_->connect());
159  if (dashboard_client_->polyscope_version_.isESeries())
160  GTEST_SKIP();
161  dashboard_client_->polyscope_version_ = VersionInformation::fromString("1.6.0");
162  EXPECT_THROW(dashboard_client_->commandIsProgramSaved(), UrException);
163  dashboard_client_->polyscope_version_ = VersionInformation::fromString("1.8.0");
164  EXPECT_TRUE(dashboard_client_->commandIsProgramSaved());
165  EXPECT_THROW(dashboard_client_->commandIsInRemoteControl(), UrException);
166 }
167 
168 int main(int argc, char* argv[])
169 {
170  ::testing::InitGoogleTest(&argc, argv);
171 
172  return RUN_ALL_TESTS();
173 }
TEST_F(DashboardClientTest, connect)
std::string ROBOT_IP
This class is a wrapper around the dashboard server.
std::unique_ptr< DashboardClient > dashboard_client_
int main(int argc, char *argv[])
Our base class for exceptions. Specialized exceptions should inherit from those.
Definition: exceptions.h:41
static VersionInformation fromString(const std::string &str)
Parses a version string into a VersionInformation object.


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47