MessageDefinitionParserTest.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2014 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *.
00017  ******************************************************************************/
00018 
00019 #include <gtest/gtest.h>
00020 
00021 #include <variant_msgs/Test.h>
00022 
00023 #include <variant_topic_tools/MessageDefinitionParser.h>
00024 
00025 using namespace variant_topic_tools;
00026 
00027 TEST(MessageDefinitionParser, Parse) {
00028   std::vector<MessageType> messageTypes;
00029   
00030   MessageDefinitionParser::parse(
00031     ros::message_traits::datatype<variant_msgs::Test>(),
00032     ros::message_traits::definition<variant_msgs::Test>(),
00033     messageTypes);
00034   
00035   EXPECT_FALSE(messageTypes.empty());
00036   EXPECT_EQ(ros::message_traits::datatype<variant_msgs::Test>(),
00037     messageTypes[0].getDataType());
00038   EXPECT_EQ(ros::message_traits::datatype<std_msgs::Header>(),
00039     messageTypes[1].getDataType());
00040   EXPECT_EQ(ros::message_traits::definition<std_msgs::Header>(),
00041     messageTypes[1].getDefinition());
00042 }
00043 
00044 TEST(MessageDefinitionParser, Match) {
00045   std::string name, type, value;
00046   size_t size;
00047   
00048   EXPECT_TRUE(MessageDefinitionParser::matchType("int32"));
00049   EXPECT_TRUE(MessageDefinitionParser::matchArrayType("int32[3]",
00050     type, size));
00051   EXPECT_EQ("int32", type);
00052   EXPECT_EQ(3, size);
00053   EXPECT_TRUE(MessageDefinitionParser::matchArrayType("int32[]",
00054     type, size));
00055   EXPECT_EQ("int32", type);
00056   EXPECT_EQ(0, size);
00057   EXPECT_TRUE(MessageDefinitionParser::match("int32 x # Comment", name, type));
00058   EXPECT_EQ("x", name);
00059   EXPECT_EQ("int32", type);
00060   EXPECT_FALSE(MessageDefinitionParser::match("# Comment", name, type));
00061   EXPECT_FALSE(MessageDefinitionParser::match("int32 # Comment", name, type));
00062   EXPECT_TRUE(MessageDefinitionParser::match("int32 x=1 # Comment",
00063     name, type));
00064   EXPECT_EQ("x", name);
00065   EXPECT_EQ("int32", type);
00066   EXPECT_TRUE(MessageDefinitionParser::matchConstant("int32 x=1 # Comment",
00067     name, type, value));
00068   EXPECT_EQ("x", name);
00069   EXPECT_EQ("int32", type);
00070   EXPECT_EQ("1", value);
00071   EXPECT_TRUE(MessageDefinitionParser::matchConstant(
00072     "string x= value # Comment ", name, type, value));
00073   EXPECT_EQ("x", name);
00074   EXPECT_EQ("string", type);
00075   EXPECT_EQ("value # Comment", value);
00076   EXPECT_TRUE(MessageDefinitionParser::matchVariable("int32 x # Comment",
00077     name, type));
00078   EXPECT_EQ("x", name);
00079   EXPECT_EQ("int32", type);
00080   EXPECT_TRUE(MessageDefinitionParser::matchVariable("int32[3] x # Comment",
00081     name, type));
00082   EXPECT_EQ("x", name);
00083   EXPECT_EQ("int32[3]", type);
00084   EXPECT_TRUE(MessageDefinitionParser::matchArray("int32[3] x # Comment",
00085     name, type, size));
00086   EXPECT_EQ("x", name);
00087   EXPECT_EQ("int32", type);
00088   EXPECT_EQ(3, size);
00089   EXPECT_TRUE(MessageDefinitionParser::matchArray("int32[] x # Comment",
00090     name, type, size));
00091   EXPECT_EQ("x", name);
00092   EXPECT_EQ("int32", type);
00093   EXPECT_EQ(0, size);
00094 }


variant_topic_test
Author(s): Ralf Kaestner
autogenerated on Tue Jul 9 2019 03:18:49