generated_messages.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
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  * * Neither the name of Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /* Author: Josh Faust */
31 
32 /*
33  * Test generated messages
34  */
35 
36 #include <gtest/gtest.h>
37 #include "helpers.h"
38 #include "test_roscpp/ArrayOfFixedLength.h"
39 #include "test_roscpp/ArrayOfVariableLength.h"
40 #include "test_roscpp/EmbeddedFixedLength.h"
41 #include "test_roscpp/EmbeddedVariableLength.h"
42 #include "test_roscpp/FixedLength.h"
43 #include "test_roscpp/VariableLength.h"
44 #include "test_roscpp/WithHeader.h"
45 #include "test_roscpp/EmbeddedExternal.h"
46 #include "test_roscpp/WithTime.h"
47 #include "test_roscpp/WithDuration.h"
48 #include "test_roscpp/WithMemberNamedHeaderThatIsNotAHeader.h"
49 #include "test_roscpp/FixedLengthArrayOfExternal.h"
50 #include "test_roscpp/VariableLengthArrayOfExternal.h"
51 #include "test_roscpp/Constants.h"
52 #include "test_roscpp/VariableLengthStringArray.h"
53 #include "test_roscpp/FixedLengthStringArray.h"
54 #include "test_roscpp/HeaderNotFirstMember.h"
55 
56 using namespace test_roscpp;
57 
58 namespace test_roscpp
59 {
60  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(ArrayOfFixedLength, MyArrayOfFixedLength, Allocator);
61  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(ArrayOfVariableLength, MyArrayOfVariableLength, Allocator);
62  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(EmbeddedFixedLength, MyEmbeddedFixedLength, Allocator);
63  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(EmbeddedVariableLength, MyEmbeddedVariableLength, Allocator);
64  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(FixedLength, MyFixedLength, Allocator);
65  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(VariableLength, MyVariableLength, Allocator);
67  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(EmbeddedExternal, MyEmbeddedExternal, Allocator);
68  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(WithTime, MyWithTime, Allocator);
69  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(WithDuration, MyWithDuration, Allocator);
70  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(WithMemberNamedHeaderThatIsNotAHeader, MyWithMemberNamedHeaderThatIsNotAHeader, Allocator);
71  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(FixedLengthArrayOfExternal, MyFixedLengthArrayOfExternal, Allocator);
72  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(VariableLengthArrayOfExternal, MyVariableLengthArrayOfExternal, Allocator);
73  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(FixedLengthStringArray, MyFixedLengthStringArray, Allocator);
74  ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(VariableLengthStringArray, MyVariableLengthStringArray, Allocator);
75 }
76 
77 TEST(GeneratedMessages, traitsWithStandardMessages)
78 {
79  EXPECT_TRUE(mt::isFixedSize<ArrayOfFixedLength>());
80  EXPECT_FALSE(mt::isFixedSize<ArrayOfVariableLength>());
81  EXPECT_TRUE(mt::isFixedSize<EmbeddedFixedLength>());
82  EXPECT_FALSE(mt::isFixedSize<EmbeddedVariableLength>());
83  EXPECT_TRUE(mt::isFixedSize<FixedLength>());
84  EXPECT_FALSE(mt::isFixedSize<VariableLength>());
85  EXPECT_FALSE(mt::isFixedSize<WithHeader>());
86  EXPECT_TRUE(mt::isFixedSize<EmbeddedExternal>());
87  EXPECT_TRUE(mt::isFixedSize<WithTime>());
88  EXPECT_TRUE(mt::isFixedSize<WithDuration>());
89  EXPECT_TRUE(mt::isFixedSize<WithMemberNamedHeaderThatIsNotAHeader>());
90  EXPECT_FALSE(mt::isFixedSize<FixedLengthArrayOfExternal>());
91  EXPECT_FALSE(mt::isFixedSize<VariableLengthArrayOfExternal>());
92  EXPECT_FALSE(mt::isFixedSize<FixedLengthStringArray>());
93  EXPECT_FALSE(mt::isFixedSize<VariableLengthStringArray>());
94 
95  EXPECT_FALSE(mt::hasHeader<ArrayOfFixedLength>());
96  EXPECT_FALSE(mt::hasHeader<ArrayOfVariableLength>());
97  EXPECT_FALSE(mt::hasHeader<EmbeddedFixedLength>());
98  EXPECT_FALSE(mt::hasHeader<EmbeddedVariableLength>());
99  EXPECT_FALSE(mt::hasHeader<FixedLength>());
100  EXPECT_FALSE(mt::hasHeader<VariableLength>());
101  EXPECT_TRUE(mt::hasHeader<WithHeader>());
102  EXPECT_FALSE(mt::hasHeader<EmbeddedExternal>());
103  EXPECT_FALSE(mt::hasHeader<WithTime>());
104  EXPECT_FALSE(mt::hasHeader<WithDuration>());
105  EXPECT_FALSE(mt::hasHeader<WithMemberNamedHeaderThatIsNotAHeader>());
106  EXPECT_FALSE(mt::hasHeader<FixedLengthArrayOfExternal>());
107  EXPECT_FALSE(mt::hasHeader<VariableLengthArrayOfExternal>());
108  EXPECT_FALSE(mt::hasHeader<FixedLengthStringArray>());
109  EXPECT_FALSE(mt::hasHeader<VariableLengthStringArray>());
110  EXPECT_FALSE(mt::hasHeader<HeaderNotFirstMember>());
111 
112  EXPECT_FALSE(mt::isSimple<ArrayOfFixedLength>());
113  EXPECT_FALSE(mt::isSimple<ArrayOfVariableLength>());
114  EXPECT_FALSE(mt::isSimple<EmbeddedFixedLength>());
115  EXPECT_FALSE(mt::isSimple<EmbeddedVariableLength>());
116  EXPECT_FALSE(mt::isSimple<FixedLength>());
117  EXPECT_FALSE(mt::isSimple<VariableLength>());
118  EXPECT_FALSE(mt::isSimple<WithHeader>());
119  EXPECT_FALSE(mt::isSimple<EmbeddedExternal>());
120  EXPECT_FALSE(mt::isSimple<WithTime>());
121  EXPECT_FALSE(mt::isSimple<WithDuration>());
122  EXPECT_FALSE(mt::isSimple<WithMemberNamedHeaderThatIsNotAHeader>());
123  EXPECT_FALSE(mt::isSimple<FixedLengthArrayOfExternal>());
124  EXPECT_FALSE(mt::isSimple<VariableLengthArrayOfExternal>());
125  EXPECT_FALSE(mt::isSimple<FixedLengthStringArray>());
126  EXPECT_FALSE(mt::isSimple<VariableLengthStringArray>());
127 }
128 
129 TEST(GeneratedMessages, traitsWithCustomAllocator)
130 {
131  EXPECT_TRUE(mt::isFixedSize<MyArrayOfFixedLength>());
132  EXPECT_FALSE(mt::isFixedSize<MyArrayOfVariableLength>());
133  EXPECT_TRUE(mt::isFixedSize<MyEmbeddedFixedLength>());
134  EXPECT_FALSE(mt::isFixedSize<MyEmbeddedVariableLength>());
135  EXPECT_TRUE(mt::isFixedSize<MyFixedLength>());
136  EXPECT_FALSE(mt::isFixedSize<MyVariableLength>());
137  EXPECT_FALSE(mt::isFixedSize<MyWithHeader>());
138  EXPECT_TRUE(mt::isFixedSize<MyEmbeddedExternal>());
139  EXPECT_TRUE(mt::isFixedSize<MyWithTime>());
140  EXPECT_TRUE(mt::isFixedSize<MyWithDuration>());
141  EXPECT_TRUE(mt::isFixedSize<MyWithMemberNamedHeaderThatIsNotAHeader>());
142  EXPECT_FALSE(mt::isFixedSize<MyFixedLengthArrayOfExternal>());
143  EXPECT_FALSE(mt::isFixedSize<MyVariableLengthArrayOfExternal>());
144  EXPECT_FALSE(mt::isFixedSize<MyFixedLengthStringArray>());
145  EXPECT_FALSE(mt::isFixedSize<MyVariableLengthStringArray>());
146 
147  EXPECT_FALSE(mt::hasHeader<MyArrayOfFixedLength>());
148  EXPECT_FALSE(mt::hasHeader<MyArrayOfVariableLength>());
149  EXPECT_FALSE(mt::hasHeader<MyEmbeddedFixedLength>());
150  EXPECT_FALSE(mt::hasHeader<MyEmbeddedVariableLength>());
151  EXPECT_FALSE(mt::hasHeader<MyFixedLength>());
152  EXPECT_FALSE(mt::hasHeader<MyVariableLength>());
153  EXPECT_TRUE(mt::hasHeader<MyWithHeader>());
154  EXPECT_FALSE(mt::hasHeader<MyEmbeddedExternal>());
155  EXPECT_FALSE(mt::hasHeader<MyWithTime>());
156  EXPECT_FALSE(mt::hasHeader<MyWithDuration>());
157  EXPECT_FALSE(mt::hasHeader<MyWithMemberNamedHeaderThatIsNotAHeader>());
158  EXPECT_FALSE(mt::hasHeader<MyFixedLengthArrayOfExternal>());
159  EXPECT_FALSE(mt::hasHeader<MyVariableLengthArrayOfExternal>());
160  EXPECT_FALSE(mt::hasHeader<MyFixedLengthStringArray>());
161  EXPECT_FALSE(mt::hasHeader<MyVariableLengthStringArray>());
162 
163  EXPECT_FALSE(mt::isSimple<MyArrayOfFixedLength>());
164  EXPECT_FALSE(mt::isSimple<MyArrayOfVariableLength>());
165  EXPECT_FALSE(mt::isSimple<MyEmbeddedFixedLength>());
166  EXPECT_FALSE(mt::isSimple<MyEmbeddedVariableLength>());
167  EXPECT_FALSE(mt::isSimple<MyFixedLength>());
168  EXPECT_FALSE(mt::isSimple<MyVariableLength>());
169  EXPECT_FALSE(mt::isSimple<MyWithHeader>());
170  EXPECT_FALSE(mt::isSimple<MyEmbeddedExternal>());
171  EXPECT_FALSE(mt::isSimple<MyWithTime>());
172  EXPECT_FALSE(mt::isSimple<MyWithDuration>());
173  EXPECT_FALSE(mt::isSimple<MyWithMemberNamedHeaderThatIsNotAHeader>());
174  EXPECT_FALSE(mt::isSimple<MyFixedLengthArrayOfExternal>());
175  EXPECT_FALSE(mt::isSimple<MyVariableLengthArrayOfExternal>());
176  EXPECT_FALSE(mt::isSimple<MyFixedLengthStringArray>());
177  EXPECT_FALSE(mt::isSimple<MyVariableLengthStringArray>());
178 }
179 
180 #define SERIALIZATION_COMPILATION_TEST(Type) \
181  TEST(GeneratedMessages, serialization_##Type) \
182  { \
183  Type ser_val, deser_val; \
184  serializeAndDeserialize(ser_val, deser_val); \
185  }
186 
187 SERIALIZATION_COMPILATION_TEST(ArrayOfFixedLength);
188 SERIALIZATION_COMPILATION_TEST(ArrayOfVariableLength);
189 SERIALIZATION_COMPILATION_TEST(EmbeddedFixedLength);
190 SERIALIZATION_COMPILATION_TEST(EmbeddedVariableLength);
191 SERIALIZATION_COMPILATION_TEST(FixedLength);
192 SERIALIZATION_COMPILATION_TEST(VariableLength);
194 SERIALIZATION_COMPILATION_TEST(EmbeddedExternal);
196 SERIALIZATION_COMPILATION_TEST(WithDuration);
197 SERIALIZATION_COMPILATION_TEST(WithMemberNamedHeaderThatIsNotAHeader);
198 SERIALIZATION_COMPILATION_TEST(FixedLengthArrayOfExternal);
199 SERIALIZATION_COMPILATION_TEST(VariableLengthArrayOfExternal);
200 SERIALIZATION_COMPILATION_TEST(FixedLengthStringArray);
201 SERIALIZATION_COMPILATION_TEST(VariableLengthStringArray);
202 
203 SERIALIZATION_COMPILATION_TEST(MyArrayOfFixedLength);
204 SERIALIZATION_COMPILATION_TEST(MyArrayOfVariableLength);
205 SERIALIZATION_COMPILATION_TEST(MyEmbeddedFixedLength);
206 SERIALIZATION_COMPILATION_TEST(MyEmbeddedVariableLength);
207 SERIALIZATION_COMPILATION_TEST(MyFixedLength);
208 SERIALIZATION_COMPILATION_TEST(MyVariableLength);
209 SERIALIZATION_COMPILATION_TEST(MyWithHeader);
210 SERIALIZATION_COMPILATION_TEST(MyEmbeddedExternal);
212 SERIALIZATION_COMPILATION_TEST(MyWithDuration);
213 SERIALIZATION_COMPILATION_TEST(MyWithMemberNamedHeaderThatIsNotAHeader);
214 SERIALIZATION_COMPILATION_TEST(MyFixedLengthArrayOfExternal);
215 SERIALIZATION_COMPILATION_TEST(MyVariableLengthArrayOfExternal);
216 SERIALIZATION_COMPILATION_TEST(MyFixedLengthStringArray);
217 SERIALIZATION_COMPILATION_TEST(MyVariableLengthStringArray);
218 
219 #define ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(Type, Allocator) \
220  TEST(GeneratedMessages, allocationConstructor_##Type) \
221  { \
222  Allocator a; \
223  Type val(a); \
224  }
225 
236 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(WithMemberNamedHeaderThatIsNotAHeader, std::allocator<void>);
238 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(VariableLengthArrayOfExternal, std::allocator<void>);
241 
252 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyWithMemberNamedHeaderThatIsNotAHeader, Allocator<void>);
253 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyFixedLengthArrayOfExternal, Allocator<void>);
254 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyVariableLengthArrayOfExternal, Allocator<void>);
256 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyVariableLengthStringArray, Allocator<void>);
257 
258 TEST(Generated, serializationOStreamOperator)
259 {
260  using namespace ros::serialization;
261  Array b(new uint8_t[8]);
262  OStream ostream(b.get(), 8);
263  FixedLength m;
264  ostream << m;
265  ASSERT_EQ(ostream.getLength(), 0UL);
266 }
267 
268 TEST(Generated, constants)
269 {
270  EXPECT_EQ(Constants::a, 1U);
271  EXPECT_EQ(Constants::b, 2);
272  EXPECT_EQ(Constants::c, 3U);
273  EXPECT_EQ(Constants::d, 4);
274  EXPECT_EQ(Constants::e, 5U);
275  EXPECT_EQ(Constants::f, 6);
276  EXPECT_EQ(Constants::g, 7U);
277  EXPECT_EQ(Constants::h, 8);
278  EXPECT_FLOAT_EQ(Constants::fa, 1.5);
279  EXPECT_FLOAT_EQ(Constants::fb, 40.9);
280  EXPECT_STREQ(Constants::str.c_str(), "hello there");
281  EXPECT_STREQ(Constants::str2.c_str(), "this string has \"quotes\" and \\slashes\\ in it");
282 }
283 
284 int main(int argc, char** argv)
285 {
286  testing::InitGoogleTest(&argc, argv);
287  return RUN_ALL_TESTS();
288 }
289 
290 
291 
#define SERIALIZATION_COMPILATION_TEST(Type)
ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(ArrayOfFixedLength, MyArrayOfFixedLength, Allocator)
int main(int argc, char **argv)
#define ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(Type, Allocator)
TEST(GeneratedMessages, traitsWithStandardMessages)


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:46