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_topic_tools/MessageFieldCollection.h> 00022 00023 using namespace variant_topic_tools; 00024 00025 TEST(MessageFieldCollection, Namespaces) { 00026 variant_topic_tools::MessageFieldCollection<bool> c1; 00027 00028 c1.appendField("field1"); 00029 c1.appendField("field2", true); 00030 c1["field2"].appendField("field2_1"); 00031 00032 EXPECT_FALSE(c1.isEmpty()); 00033 EXPECT_EQ(2, c1.getNumFields()); 00034 00035 EXPECT_TRUE(c1.hasField("field1")); 00036 EXPECT_TRUE(c1.hasField("/field2")); 00037 EXPECT_TRUE(c1.hasField("field2/field2_1")); 00038 EXPECT_TRUE(c1.hasField("/field2/field2_1")); 00039 EXPECT_FALSE(c1.hasField("field3")); 00040 EXPECT_FALSE(c1.hasField("field2/field2_2")); 00041 00042 EXPECT_NO_THROW(c1.getField("field1")); 00043 EXPECT_NO_THROW(c1.getField("/field2")); 00044 EXPECT_NO_THROW(c1.getField("field2/field2_1")); 00045 EXPECT_NO_THROW(c1.getField("/field2/field2_1")); 00046 EXPECT_ANY_THROW(c1.getField("field3")); 00047 EXPECT_ANY_THROW(c1.getField("field2/field2_2")); 00048 00049 EXPECT_FALSE(c1["field1"].getValue()); 00050 EXPECT_TRUE(c1["field2"].getValue()); 00051 00052 c1.clear(); 00053 00054 EXPECT_TRUE(c1.isEmpty()); 00055 }