dsdl_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #if __GNUC__
6 # pragma GCC diagnostic ignored "-Wfloat-equal"
7 #endif
8 
9 #include <gtest/gtest.h>
11 #include <limits>
12 #include <root_ns_a/EmptyService.hpp>
13 #include <root_ns_a/EmptyMessage.hpp>
14 #include <root_ns_a/NestedMessage.hpp>
15 #include <root_ns_a/A.hpp>
16 #include <root_ns_a/ReportBackSoldier.hpp>
17 #include <root_ns_b/ServiceWithEmptyRequest.hpp>
18 #include <root_ns_b/ServiceWithEmptyResponse.hpp>
19 #include <root_ns_b/T.hpp>
20 
21 
22 TEST(Dsdl, EmptyServices)
23 {
25  uavcan::BitStream bs_wr(buf);
26  uavcan::ScalarCodec sc_wr(bs_wr);
27 
28  root_ns_b::ServiceWithEmptyRequest::Request req;
29  ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Request::encode(req, sc_wr));
30  ASSERT_EQ("", bs_wr.toString());
31 
32  root_ns_b::ServiceWithEmptyRequest::Response resp;
33  ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Response::encode(resp, sc_wr));
34  ASSERT_EQ("", bs_wr.toString());
35 
36  resp.covariance.push_back(-2);
37  resp.covariance.push_back(65504);
38  root_ns_b::ServiceWithEmptyRequest::Response::encode(resp, sc_wr);
39  ASSERT_EQ("00000000 11000000 11111111 01111011", bs_wr.toString());
40 
41  resp.covariance.push_back(42);
42  resp.covariance[0] = 999;
43 
44  uavcan::BitStream bs_rd(buf);
45  uavcan::ScalarCodec sc_rd(bs_rd);
46  ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Response::decode(resp, sc_rd));
47 
48  ASSERT_EQ(2, resp.covariance.size());
49  ASSERT_EQ(-2, resp.covariance[0]);
50  ASSERT_EQ(65504, resp.covariance[1]);
51 }
52 
53 
54 TEST(Dsdl, Signature)
55 {
56  ASSERT_EQ(0xe74617107a34aa9c, root_ns_a::EmptyService::getDataTypeSignature().get());
57  ASSERT_STREQ("root_ns_a.EmptyService", root_ns_a::EmptyService::getDataTypeFullName());
59 
60  ASSERT_EQ(0x99604d7066e0d713, root_ns_a::NestedMessage::getDataTypeSignature().get()); // Computed manually
61  ASSERT_STREQ("root_ns_a.NestedMessage", root_ns_a::NestedMessage::getDataTypeFullName());
63 }
64 
65 
66 TEST(Dsdl, Operators)
67 {
68  {
69  root_ns_a::EmptyService::Request a, b;
70  ASSERT_TRUE(a == b);
71  ASSERT_FALSE(a != b);
72  }
73  {
74  root_ns_a::NestedMessage c, d;
75  ASSERT_TRUE(c == d);
76  ASSERT_FALSE(c != d);
77 
78  c.field = 1;
79  ASSERT_FALSE(c == d);
80  ASSERT_TRUE(c != d);
81  }
82 }
83 
84 
85 TEST(Dsdl, CloseComparison)
86 {
87  root_ns_a::A first, second;
88 
89  ASSERT_TRUE(first == second);
90 
91  first.vector[1].vector[1] = std::numeric_limits<double>::epsilon();
92  ASSERT_TRUE(first.isClose(second)); // Still close
93  ASSERT_FALSE(first == second); // But not exactly
94 
95  first.vector[1].vector[1] = std::numeric_limits<float>::epsilon();
96  ASSERT_FALSE(first.isClose(second)); // Nope
97  ASSERT_FALSE(first == second); // Ditto
98 }
99 
100 /*
101  * This test assumes that it will be executed before other GDTR tests; otherwise it fails.
102  * TODO: Probably it needs to be called directly from main()
103  */
104 //TEST(Dsdl, Registration)
105 //{
106 // using uavcan::GlobalDataTypeRegistry;
107 // /*
108 // * Descriptors
109 // */
110 // const uavcan::DataTypeDescriptor* desc = UAVCAN_NULLPTR;
111 //
112 // desc = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, "root_ns_a.EmptyMessage");
113 // ASSERT_TRUE(desc);
114 // ASSERT_EQ(root_ns_a::EmptyMessage::DefaultDataTypeID, desc->getID());
115 // ASSERT_EQ(root_ns_a::EmptyMessage::DataTypeKind, desc->getKind());
116 // ASSERT_EQ(root_ns_a::EmptyMessage::getDataTypeSignature(), desc->getSignature());
117 // ASSERT_STREQ(root_ns_a::EmptyMessage::getDataTypeFullName(), desc->getFullName());
118 //
119 // desc = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindService, "root_ns_a.EmptyService");
120 // ASSERT_TRUE(desc);
121 // ASSERT_EQ(root_ns_a::EmptyService::DefaultDataTypeID, desc->getID());
122 // ASSERT_EQ(root_ns_a::EmptyService::DataTypeKind, desc->getKind());
123 // ASSERT_EQ(root_ns_a::EmptyService::getDataTypeSignature(), desc->getSignature());
124 // ASSERT_STREQ(root_ns_a::EmptyService::getDataTypeFullName(), desc->getFullName());
125 //
126 // desc = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindService, "root_ns_a.ReportBackSoldier");
127 // ASSERT_TRUE(desc);
128 // ASSERT_EQ(root_ns_a::ReportBackSoldier::DefaultDataTypeID, desc->getID());
129 // ASSERT_EQ(root_ns_a::ReportBackSoldier::DataTypeKind, desc->getKind());
130 // ASSERT_EQ(root_ns_a::ReportBackSoldier::getDataTypeSignature(), desc->getSignature());
131 // ASSERT_STREQ(root_ns_a::ReportBackSoldier::getDataTypeFullName(), desc->getFullName());
132 //
133 // /*
134 // * Mask
135 // */
136 // uavcan::DataTypeIDMask mask;
137 //
138 // GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, mask);
139 // ASSERT_TRUE(mask[8]);
140 // mask[8] = false;
141 //
142 // GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindService, mask);
143 // ASSERT_TRUE(mask[1]);
144 // ASSERT_TRUE(mask[3]);
145 // mask[1] = mask[3] = false;
146 //
147 // /*
148 // * Reset
149 // */
150 // GlobalDataTypeRegistry::instance().reset();
151 // ASSERT_FALSE(GlobalDataTypeRegistry::instance().isFrozen());
152 //}
uavcan::BitStream
Definition: bit_stream.hpp:31
uavcan::DataTypeKindService
@ DataTypeKindService
Definition: data_type.hpp:21
get
ROSCPP_DECL bool get(const std::string &key, bool &b)
d
d
uavcan::DataTypeKind
DataTypeKind
Definition: data_type.hpp:19
uavcan::StaticTransferBuffer
Definition: transfer_buffer.hpp:50
TEST
TEST(Dsdl, EmptyServices)
Definition: dsdl_test.cpp:22
uavcan::DataTypeKindMessage
@ DataTypeKindMessage
Definition: data_type.hpp:22
transfer_buffer.hpp
uavcan::ScalarCodec
Definition: scalar_codec.hpp:20


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:02