MessageDefinitionParserTest.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *.
17  ******************************************************************************/
18 
19 #include <gtest/gtest.h>
20 
21 #include <variant_msgs/Test.h>
22 
24 
25 using namespace variant_topic_tools;
26 
28  std::vector<MessageType> messageTypes;
29 
31  ros::message_traits::datatype<variant_msgs::Test>(),
32  ros::message_traits::definition<variant_msgs::Test>(),
33  messageTypes);
34 
35  EXPECT_FALSE(messageTypes.empty());
36  EXPECT_EQ(ros::message_traits::datatype<variant_msgs::Test>(),
37  messageTypes[0].getDataType());
38  EXPECT_EQ(ros::message_traits::datatype<std_msgs::Header>(),
39  messageTypes[1].getDataType());
40  EXPECT_EQ(ros::message_traits::definition<std_msgs::Header>(),
41  messageTypes[1].getDefinition());
42 }
43 
45  std::string name, type, value;
46  size_t size;
47 
48  EXPECT_TRUE(MessageDefinitionParser::matchType("int32"));
49  EXPECT_TRUE(MessageDefinitionParser::matchArrayType("int32[3]",
50  type, size));
51  EXPECT_EQ("int32", type);
52  EXPECT_EQ(3, size);
53  EXPECT_TRUE(MessageDefinitionParser::matchArrayType("int32[]",
54  type, size));
55  EXPECT_EQ("int32", type);
56  EXPECT_EQ(0, size);
57  EXPECT_TRUE(MessageDefinitionParser::match("int32 x # Comment", name, type));
58  EXPECT_EQ("x", name);
59  EXPECT_EQ("int32", type);
60  EXPECT_FALSE(MessageDefinitionParser::match("# Comment", name, type));
61  EXPECT_FALSE(MessageDefinitionParser::match("int32 # Comment", name, type));
62  EXPECT_TRUE(MessageDefinitionParser::match("int32 x=1 # Comment",
63  name, type));
64  EXPECT_EQ("x", name);
65  EXPECT_EQ("int32", type);
66  EXPECT_TRUE(MessageDefinitionParser::matchConstant("int32 x=1 # Comment",
67  name, type, value));
68  EXPECT_EQ("x", name);
69  EXPECT_EQ("int32", type);
70  EXPECT_EQ("1", value);
72  "string x= value # Comment ", name, type, value));
73  EXPECT_EQ("x", name);
74  EXPECT_EQ("string", type);
75  EXPECT_EQ("value # Comment", value);
76  EXPECT_TRUE(MessageDefinitionParser::matchVariable("int32 x # Comment",
77  name, type));
78  EXPECT_EQ("x", name);
79  EXPECT_EQ("int32", type);
80  EXPECT_TRUE(MessageDefinitionParser::matchVariable("int32[3] x # Comment",
81  name, type));
82  EXPECT_EQ("x", name);
83  EXPECT_EQ("int32[3]", type);
84  EXPECT_TRUE(MessageDefinitionParser::matchArray("int32[3] x # Comment",
85  name, type, size));
86  EXPECT_EQ("x", name);
87  EXPECT_EQ("int32", type);
88  EXPECT_EQ(3, size);
89  EXPECT_TRUE(MessageDefinitionParser::matchArray("int32[] x # Comment",
90  name, type, size));
91  EXPECT_EQ("x", name);
92  EXPECT_EQ("int32", type);
93  EXPECT_EQ(0, size);
94 }
static bool matchConstant(const std::string &expression, std::string &name, std::string &type, std::string &value)
Match a constant message member expression.
static bool match(const std::string &expression, std::string &name, std::string &type)
Match any message member expression.
Header file providing the MessageDefinitionParser class interface.
static bool matchArray(const std::string &expression, std::string &name, std::string &memberType, size_t &size)
Match an array message member expression.
static bool matchArrayType(const std::string &expression, std::string &memberType, size_t &size)
Match an array type expression.
static bool matchType(const std::string &expression)
Match any message type expression.
static size_t parse(const std::string &messageDataType, const std::string &messageDefinition, std::vector< MessageType > &messageTypes)
Parse a message definition and generate the message types.
static bool matchVariable(const std::string &expression, std::string &name, std::string &type)
Match a variable message member expression.
TEST(MessageDefinitionParser, Parse)


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49