36 #include <gtest/gtest.h> 38 #include <std_msgs/Header.h> 52 #define PRIMITIVE_SERIALIZATION_TEST(Type, SerInit, DeserInit) \ 53 TEST(Serialization, Type) \ 55 Type ser_val SerInit; \ 56 Type deser_val DeserInit; \ 57 Array b = serializeAndDeserialize(ser_val, deser_val); \ 58 EXPECT_EQ(*(Type*)b.get(), ser_val); \ 59 EXPECT_EQ(ser_val, deser_val); \ 75 #define PRIMITIVE_VARIABLE_LENGTH_ARRAY_TEST(Type, Start, Increment) \ 76 TEST(Serialization, variableLengthArray_##Type) \ 78 std::vector<Type> ser_val, deser_val; \ 80 for (uint32_t i = 0; i < 8; ++i) \ 82 ser_val.push_back(val); \ 83 val = val + Increment; \ 86 Array b = serializeAndDeserialize(ser_val, deser_val); \ 87 EXPECT_TRUE(ser_val == deser_val); \ 89 EXPECT_EQ(*(uint32_t*)b.get(), (uint32_t)ser_val.size()); \ 90 for(size_t i = 0; i < ser_val.size(); ++i) \ 92 Type* ptr = ((Type*)(b.get() + 4)) + i; \ 93 EXPECT_EQ(*ptr, ser_val[i]); \ 110 #define PRIMITIVE_FIXED_LENGTH_ARRAY_TEST(Type, Start, Increment) \ 111 TEST(Serialization, fixedLengthArray_##Type) \ 113 boost::array<Type, 8> ser_val, deser_val; \ 115 for (uint32_t i = 0; i < 8; ++i) \ 118 val = val + Increment; \ 121 Array b = serializeAndDeserialize(ser_val, deser_val); \ 122 EXPECT_TRUE(ser_val == deser_val); \ 124 for(size_t i = 0; i < ser_val.size(); ++i) \ 126 Type* ptr = ((Type*)b.get()) + i; \ 127 EXPECT_EQ(*ptr, ser_val[i]); \ 146 std::string ser_val =
"hello world";
147 std::string deser_val;
149 EXPECT_STREQ(ser_val.c_str(), deser_val.c_str());
151 EXPECT_EQ(*(uint32_t*)b.get(), (uint32_t)ser_val.size());
152 EXPECT_EQ(memcmp(b.get() + 4, ser_val.data(), ser_val.size()), 0);
155 TEST(Serialization, variableLengthArray_string)
157 std::vector<std::string> ser_val, deser_val;
158 ser_val.push_back(
"hello world");
159 ser_val.push_back(
"hello world22");
160 ser_val.push_back(
"hello world333");
161 ser_val.push_back(
"hello world4444");
162 ser_val.push_back(
"hello world55555");
164 EXPECT_TRUE(ser_val == deser_val);
167 TEST(Serialization, fixedLengthArray_string)
169 boost::array<std::string, 5> ser_val, deser_val;
170 ser_val[0] =
"hello world";
171 ser_val[1] =
"hello world22";
172 ser_val[2] =
"hello world333";
173 ser_val[3] =
"hello world4444";
174 ser_val[4] =
"hello world55555";
176 EXPECT_TRUE(ser_val == deser_val);
198 namespace message_traits
204 namespace serialization
209 template<
typename Stream>
215 template<
typename Stream>
229 TEST(Serialization, fixedSizeSimple_vector)
242 std::vector<FixedSizeSimple> in, out;
248 ASSERT_EQ(out[0].a, 1);
249 ASSERT_EQ(out[0].b, 1);
253 TEST(Serialization, fixedSizeSimple_array)
255 boost::array<FixedSizeSimple, 2> in, out;
260 ASSERT_EQ(out[0].a, 1);
261 ASSERT_EQ(out[0].b, 1);
269 : length_to_report(4)
277 namespace message_traits
282 namespace serialization
295 TEST(Serialization, fixedSizeNonSimple_vector)
297 std::vector<FixedSizeNonSimple> in;
299 in[1].length_to_report = 100;
305 TEST(Serialization, fixedSizeNonSimple_array)
307 boost::array<FixedSizeNonSimple, 2> in;
308 in[1].length_to_report = 100;
319 : length_to_report(4)
327 namespace serialization
340 TEST(Serialization, variableSize_vector)
342 std::vector<VariableSize> in;
344 in[1].length_to_report = 100;
350 TEST(Serialization, variableSize_array)
352 boost::array<VariableSize, 2> in;
353 in[1].length_to_report = 100;
366 namespace serialization
371 template<
typename Stream,
typename T>
387 ASSERT_EQ(out.
a, in.
a);
408 namespace message_traits
441 TEST(Serialization, bufferOverrun)
443 Array b(
new uint8_t[4]);
458 TEST(Serialization, streamOperators)
460 Array b(
new uint8_t[4]);
470 int main(
int argc,
char** argv)
472 testing::InitGoogleTest(&argc, argv);
473 return RUN_ALL_TESTS();
#define PRIMITIVE_SERIALIZATION_TEST(Type, SerInit, DeserInit)
#define PRIMITIVE_FIXED_LENGTH_ARRAY_TEST(Type, Start, Increment)
ros::Time * timeStamp(M &m)
#define ROS_DECLARE_ALLINONE_SERIALIZER
ROS_STATIC_ASSERT(sizeof(ros::Time)==8)
int main(int argc, char **argv)
std::string * frameId(M &m)
std_msgs::Header * header(M &m)
static void read(Stream &stream, FixedSizeSimple &v)
static void allInOne(Stream &stream, T t)
void serialize(Stream &stream, const T &t)
static uint32_t serializedLength(const FixedSizeNonSimple &v)
#define PRIMITIVE_VARIABLE_LENGTH_ARRAY_TEST(Type, Start, Increment)
Array serializeAndDeserialize(const T &ser_val, T &deser_val)
static void write(Stream &stream, const FixedSizeSimple &v)
uint32_t serializationLength(const T &t)
TEST(Serialization, string)
void deserialize(Stream &stream, T &t)
static uint32_t serializedLength(const FixedSizeSimple &)
static uint32_t serializedLength(const VariableSize &v)