MessageDefinitionTest.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/DataTypeRegistry.h>
00024 #include <variant_topic_tools/MessageDefinition.h>
00025 
00026 using namespace variant_topic_tools;
00027 
00028 TEST(MessageDefinition, Parse) {
00029   DataTypeRegistry registry;
00030   
00031   MessageDefinition d1 = MessageDefinition::create<variant_msgs::Test>();
00032   MessageDataType t1 = d1.getMessageDataType();
00033   MessageType m2("my_msgs/Test", "*",
00034     ros::message_traits::definition<variant_msgs::Test>());
00035   MessageDefinition d2(m2);
00036   MessageDataType t2 = d2.getMessageDataType();
00037   
00038   EXPECT_TRUE(t1.isValid());
00039   EXPECT_TRUE(t1[0].isConstant());
00040   EXPECT_EQ("header", t1[1].getName());
00041   EXPECT_TRUE(t1[2].isVariable());
00042   EXPECT_TRUE(t1[2].getType().isBuiltin());
00043   EXPECT_TRUE(t1[4].getType().isMessage());
00044 
00045   EXPECT_NO_THROW(d1.getField("header"));
00046   EXPECT_NO_THROW(d1.getField("string/data"));
00047   EXPECT_ANY_THROW(d1.getField("string/length"));
00048   EXPECT_TRUE(d1.hasField("byte_constant"));
00049   EXPECT_EQ("std_msgs/Header", d1["header"].getValue().getIdentifier());
00050   
00051   registry.clear();
00052 }
00053 
00054 TEST(MessageDefinition, Load) {
00055   DataTypeRegistry registry;
00056   
00057   MessageDefinition d1;
00058   EXPECT_NO_THROW(d1.load("variant_msgs/Test"));
00059   EXPECT_NO_THROW(d1.getField("header"));
00060   EXPECT_NO_THROW(d1.getField("string/data"));
00061   EXPECT_ANY_THROW(d1.getField("string/length"));
00062   EXPECT_TRUE(d1.hasField("byte_constant"));
00063   EXPECT_EQ("std_msgs/Header", d1["header"].getValue().getIdentifier());
00064   
00065   registry.clear();
00066 }


variant_topic_test
Author(s): Ralf Kaestner
autogenerated on Fri Aug 5 2016 06:06:49