test_rtde_request_protocol_version.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 
34 using namespace urcl;
35 
36 TEST(rtde_request_protocol_version, generate_serialized_protocol_v2_request)
37 {
38  uint8_t buffer[4096];
39  uint16_t protocol_version = 2;
40  size_t expected_size = 5;
41  size_t actual_size =
43 
44  EXPECT_EQ(expected_size, actual_size);
45 
46  uint8_t expected[] = { 0x00, 0x05, 0x56, 0x00, 0x02 };
47 
48  for (unsigned int i = 0; i < actual_size; ++i)
49  {
50  EXPECT_EQ(expected[i], buffer[i]);
51  }
52 }
53 
54 TEST(rtde_request_protocol_version, generate_serialized_protocol_v1_request)
55 {
56  uint8_t buffer[4096];
57  uint16_t protocol_version = 1;
58  size_t expected_size = 5;
59  size_t actual_size =
61 
62  EXPECT_EQ(expected_size, actual_size);
63 
64  uint8_t expected[] = { 0x00, 0x05, 0x56, 0x00, 0x01 };
65 
66  for (unsigned int i = 0; i < actual_size; ++i)
67  {
68  EXPECT_EQ(expected[i], buffer[i]);
69  }
70 }
71 
72 TEST(rtde_request_protocol_version, parse_accepted_request)
73 {
74  uint8_t request_answer[] = { 0x01 };
75  comm::BinParser bp(request_answer, sizeof(request_answer));
77 
78  EXPECT_TRUE(protocol_version.parseWith(bp));
79 
80  uint8_t expected_anwser = 1;
81 
82  EXPECT_EQ(expected_anwser, protocol_version.accepted_);
83 }
84 
85 TEST(rtde_request_protocol_version, parse_not_accepted_request)
86 {
87  uint8_t request_answer[] = { 0x00 };
88  comm::BinParser bp(request_answer, sizeof(request_answer));
90 
91  EXPECT_TRUE(protocol_version.parseWith(bp));
92 
93  uint8_t expected_anwser = 0;
94 
95  EXPECT_EQ(expected_anwser, protocol_version.accepted_);
96 }
97 
98 int main(int argc, char* argv[])
99 {
100  ::testing::InitGoogleTest(&argc, argv);
101 
102  return RUN_ALL_TESTS();
103 }
int main(int argc, char *argv[])
virtual bool parseWith(comm::BinParser &bp)
Sets the attributes of the package by parsing a serialized representation of the package.
The BinParser class handles a byte buffer and functionality to iteratively parse the content...
Definition: bin_parser.h:44
static size_t generateSerializedRequest(uint8_t *buffer, uint16_t version)
Generates a serialized package.
TEST(rtde_request_protocol_version, generate_serialized_protocol_v2_request)
This class handles the robot&#39;s response after trying to set the used RTDE protocol version...


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