test_rtde_parser.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2020 FZI Forschungszentrum Informatik
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 // -- END LICENSE BLOCK ------------------------------------------------
18 
19 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 
28 #include <gtest/gtest.h>
29 
33 
34 using namespace urcl;
35 
36 TEST(rtde_parser, request_protocol_version)
37 {
38  // Accepted request protocol version
39  unsigned char raw_data[] = { 0x00, 0x04, 0x56, 0x01 };
40  comm::BinParser bp(raw_data, sizeof(raw_data));
41 
42  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
43  rtde_interface::RTDEParser parser({ "" });
44  parser.parse(bp, products);
45 
46  EXPECT_EQ(products.size(), 1);
47 
49  dynamic_cast<rtde_interface::RequestProtocolVersion*>(products[0].get()))
50  {
51  EXPECT_EQ(data->accepted_, true);
52  }
53 }
54 
55 TEST(rtde_parser, get_urcontrol_version)
56 {
57  // URControl version 5.8.0-0
58  unsigned char raw_data[] = { 0x00, 0x13, 0x76, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
59  0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
60  comm::BinParser bp(raw_data, sizeof(raw_data));
61 
62  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
63  rtde_interface::RTDEParser parser({ "" });
64  parser.parse(bp, products);
65 
66  EXPECT_EQ(products.size(), 1);
67 
68  if (rtde_interface::GetUrcontrolVersion* data = dynamic_cast<rtde_interface::GetUrcontrolVersion*>(products[0].get()))
69  {
70  EXPECT_EQ(data->version_information_.major, 5);
71  EXPECT_EQ(data->version_information_.minor, 8);
72  EXPECT_EQ(data->version_information_.bugfix, 0);
73  EXPECT_EQ(data->version_information_.build, 0);
74  }
75 }
76 
77 TEST(rtde_parser, test_to_string)
78 {
79  // Non-existent type
80  unsigned char raw_data[] = { 0x00, 0x05, 0x02, 0x00, 0x00 };
81  comm::BinParser bp(raw_data, sizeof(raw_data));
82 
83  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
84  rtde_interface::RTDEParser parser({ "" });
85  parser.parse(bp, products);
86 
87  EXPECT_EQ(products.size(), 1);
88 
89  std::stringstream expected;
90  expected << "Type: 2" << std::endl;
91  expected << "Raw byte stream: 0 0 " << std::endl;
92 
93  EXPECT_EQ(products[0]->toString(), expected.str());
94 }
95 
96 TEST(rtde_parser, test_illegal_length)
97 {
98  // Non-existent type with false size information
99  unsigned char raw_data[] = { 0x00, 0x06, 0x02, 0x00, 0x00 };
100  comm::BinParser bp(raw_data, sizeof(raw_data));
101 
102  std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
103  rtde_interface::RTDEParser parser({ "" });
104  EXPECT_FALSE(parser.parse(bp, products));
105 }
106 
107 int main(int argc, char* argv[])
108 {
109  ::testing::InitGoogleTest(&argc, argv);
110 
111  return RUN_ALL_TESTS();
112 }
The BinParser class handles a byte buffer and functionality to iteratively parse the content...
Definition: bin_parser.h:44
This class handles the package detailing the UR control version sent by the robot.
bool parse(comm::BinParser &bp, std::vector< std::unique_ptr< RTDEPackage >> &results)
Uses the given BinParser to create package objects from the contained serialization.
Definition: rtde_parser.h:68
The RTDE specific parser. Interprets a given byte stream as serialized RTDE packages and parses it ac...
Definition: rtde_parser.h:45
int main(int argc, char *argv[])
This class handles the robot&#39;s response after trying to set the used RTDE protocol version...
TEST(rtde_parser, request_protocol_version)


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Sun May 9 2021 02:16:26