36 #include <gtest/gtest.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"
77 TEST(GeneratedMessages, traitsWithStandardMessages)
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>());
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>());
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>());
129 TEST(GeneratedMessages, traitsWithCustomAllocator)
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>());
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>());
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>());
180 #define SERIALIZATION_COMPILATION_TEST(Type) \
181 TEST(GeneratedMessages, serialization_##Type) \
183 Type ser_val, deser_val; \
184 serializeAndDeserialize(ser_val, deser_val); \
219 #define ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(Type, Allocator) \
220 TEST(GeneratedMessages, allocationConstructor_##Type) \
258 TEST(Generated, serializationOStreamOperator)
261 Array b(
new uint8_t[8]);
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");
284 int main(
int argc,
char** argv)
286 testing::InitGoogleTest(&argc, argv);
287 return RUN_ALL_TESTS();