Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <gtest/gtest.h>
00037 #include "ros/header.h"
00038
00039 static char g_header_data1[] = "A=B";
00040 static char g_header_data2[] = "AAAAAAAAAAAAA=BBBBBBB\nBBBBBBB";
00041
00042 using namespace ros;
00043
00044 TEST(Header, parse)
00045 {
00046 Header header;
00047
00048 uint32_t total_len = 4 + sizeof(g_header_data1) + 4 + sizeof(g_header_data2);
00049 boost::shared_array<uint8_t> buffer(new uint8_t[total_len]);
00050
00051 char* ptr = (char*)buffer.get();
00052 *(uint32_t*)ptr = sizeof(g_header_data1);
00053 ptr += 4;
00054 memcpy(ptr, g_header_data1, sizeof(g_header_data1));
00055 ptr += sizeof(g_header_data1);
00056
00057 *(uint32_t*)ptr = sizeof(g_header_data2);
00058 ptr += 4;
00059 memcpy(ptr, g_header_data2, sizeof(g_header_data2));
00060 ptr += sizeof(g_header_data2);
00061
00062 std::string error_msg;
00063 ASSERT_TRUE(header.parse(buffer, total_len, error_msg));
00064
00065 std::string val;
00066 ASSERT_TRUE(header.getValue("A", val));
00067 ASSERT_STREQ(val.c_str(), "B");
00068
00069 ASSERT_TRUE(header.getValue("AAAAAAAAAAAAA", val));
00070 ASSERT_STREQ(val.c_str(), "BBBBBBB\nBBBBBBB");
00071 }
00072
00073 TEST(Header, write)
00074 {
00075 M_string map;
00076 map["haha"] = "hoho";
00077 map["fasdf"] = "aaaaaaaaaaaaaaa";
00078 map["02490\n254"] = "idsjowiejf\nioajfoiwje";
00079
00080 boost::shared_array<uint8_t> buffer;
00081 uint32_t len;
00082 Header::write(map, buffer, len);
00083
00084 ASSERT_EQ(len, 4*3 + 3 + strlen("haha") + strlen("hoho") + strlen("fasdf") + strlen("aaaaaaaaaaaaaaa") + strlen("02490\n254") + strlen("idsjowiejf\nioajfoiwje"));
00085
00086 Header header;
00087 std::string error_msg;
00088 ASSERT_TRUE(header.parse(buffer, len, error_msg));
00089
00090 std::string val;
00091 ASSERT_TRUE(header.getValue("haha", val));
00092 ASSERT_STREQ(val.c_str(), "hoho");
00093
00094 ASSERT_TRUE(header.getValue("fasdf", val));
00095 ASSERT_STREQ(val.c_str(), "aaaaaaaaaaaaaaa");
00096
00097 ASSERT_TRUE(header.getValue("02490\n254", val));
00098 ASSERT_STREQ(val.c_str(), "idsjowiejf\nioajfoiwje");
00099 }
00100
00101 int
00102 main(int argc, char** argv)
00103 {
00104 testing::InitGoogleTest(&argc, argv);
00105 return RUN_ALL_TESTS();
00106 }
00107
00108
roscpp
Author(s): Morgan Quigley mquigley@cs.stanford.edu, Josh Faust jfaust@willowgarage.com, Brian Gerkey gerkey@willowgarage.com, Troy Straszheim straszheim@willowgarage.com
autogenerated on Sat Dec 28 2013 17:35:52