MessageDefinitionTest.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 
25 
26 using namespace variant_topic_tools;
27 
29  DataTypeRegistry registry;
30 
31  MessageDefinition d1 = MessageDefinition::create<variant_msgs::Test>();
33  MessageType m2("my_msgs/Test", "*",
34  ros::message_traits::definition<variant_msgs::Test>());
35  MessageDefinition d2(m2);
37 
38  EXPECT_TRUE(t1.isValid());
39  EXPECT_TRUE(t1[0].isConstant());
40  EXPECT_EQ("header", t1[1].getName());
41  EXPECT_TRUE(t1[2].isVariable());
42  EXPECT_TRUE(t1[2].getType().isBuiltin());
43  EXPECT_TRUE(t1[4].getType().isMessage());
44 
45  EXPECT_NO_THROW(d1.getField("header"));
46  EXPECT_NO_THROW(d1.getField("string/data"));
47  EXPECT_ANY_THROW(d1.getField("string/length"));
48  EXPECT_TRUE(d1.hasField("byte_constant"));
49  EXPECT_EQ("std_msgs/Header", d1["header"].getValue().getIdentifier());
50 
51  registry.clear();
52 }
53 
55  DataTypeRegistry registry;
56 
58  EXPECT_NO_THROW(d1.load("variant_msgs/Test"));
59  EXPECT_NO_THROW(d1.getField("header"));
60  EXPECT_NO_THROW(d1.getField("string/data"));
61  EXPECT_ANY_THROW(d1.getField("string/length"));
62  EXPECT_TRUE(d1.hasField("byte_constant"));
63  EXPECT_EQ("std_msgs/Header", d1["header"].getValue().getIdentifier());
64 
65  registry.clear();
66 }
Header file providing the MessageDefinition class interface.
MessageField< T > & getField(int index)
Retrieve a field of the message field collection by index (non-const version)
Variant message type information.
Definition: MessageType.h:33
void clear()
Clear the data type registry.
bool hasField(const std::string &name) const
True, if the message field collection contains the field with the specified name. ...
std::string getName(void *handle)
void load(const std::string &messageDataType)
Attempt to load the message definition for the specified message data type.
MessageDataType getMessageDataType() const
Retrieve the message data type represented by this message definition.
Header file providing the DataTypeRegistry class interface.
TEST(MessageDefinition, Parse)


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