19 #include <gtest/gtest.h> 21 #include <std_msgs/Bool.h> 22 #include <std_msgs/String.h> 24 #include <variant_msgs/Test.h> 43 EXPECT_EQ(0.0, v1.
getValue<
double>());
45 EXPECT_ANY_THROW(v1.
getValue<
int>());
50 EXPECT_EQ(M_PI, v1.getValue<
double>());
51 EXPECT_TRUE(v1 == M_PI);
52 EXPECT_FALSE(v1 != M_PI);
53 EXPECT_TRUE(v1 != 1.0);
54 EXPECT_FALSE(v1 == 1.0);
59 EXPECT_FALSE(v1 == 1);
60 EXPECT_EQ(1.0, v1.getNumericValue());
64 EXPECT_FALSE(v1.hasType());
65 EXPECT_TRUE(v1.isEmpty());
84 EXPECT_NO_THROW(v1[0] = 0);
85 EXPECT_NO_THROW(v1[1] = 0);
86 EXPECT_NO_THROW(v1[2] = 0);
87 EXPECT_NO_THROW(v1.
resize(3));
88 EXPECT_ANY_THROW(v1.
resize(4));
89 EXPECT_TRUE(v1[0].hasType());
90 EXPECT_FALSE(v1[0].isEmpty());
91 EXPECT_NO_THROW(v1[0] = 0);
92 EXPECT_NO_THROW(v1[1] = 1);
93 EXPECT_NO_THROW(v1[2] = 2);
94 EXPECT_ANY_THROW(v1[3] = 3);
95 EXPECT_EQ(0, v1[0].getValue<int>());
96 EXPECT_EQ(1, v1[1].getValue<int>());
97 EXPECT_EQ(2, v1[2].getValue<int>());
98 EXPECT_ANY_THROW(v1.
clear());
103 EXPECT_NO_THROW(v2.
resize(3));
106 EXPECT_TRUE(v2[0].hasType());
107 EXPECT_FALSE(v2[0].isEmpty());
108 EXPECT_NO_THROW(v2[0] = 0.0);
109 EXPECT_NO_THROW(v2[1] = 1.0);
110 EXPECT_NO_THROW(v2[2] = 2.0);
111 EXPECT_ANY_THROW(v2[3] = 3);
112 EXPECT_EQ(0.0, v2[0].getValue<double>());
113 EXPECT_EQ(1.0, v2[1].getValue<double>());
114 EXPECT_EQ(2.0, v2[2].getValue<double>());
115 EXPECT_NO_THROW(v2.
clear());
125 getMessageDataType().createVariant());
127 getMessageDataType().createVariant());
128 MessageVariant v3(MessageDefinition::create<variant_msgs::Test>().
129 getMessageDataType().createVariant());
137 EXPECT_TRUE(v1[
"data"].hasType());
138 EXPECT_FALSE(v1[
"data"].isEmpty());
139 EXPECT_NO_THROW(v1[
"data"] =
true);
140 EXPECT_EQ(
true, v1[
"data"].getValue<bool>());
146 EXPECT_TRUE(v2[
"data"].hasType());
147 EXPECT_FALSE(v2[
"data"].isEmpty());
148 EXPECT_NO_THROW(v2[
"data"] =
"Test");
149 EXPECT_EQ(
"Test", v2[
"data"].getValue<std::string>());
154 EXPECT_TRUE(v3[
"header"].hasType());
155 EXPECT_FALSE(v3[
"header"].isEmpty());
156 EXPECT_EQ(
typeid(
void), v3[
"header"].getValueTypeInfo());
157 EXPECT_NO_THROW(v3[
"builtin_string"] =
"Test");
158 EXPECT_EQ(
"Test", v3[
"builtin_string"].getValue<std::string>());
163 EXPECT_TRUE(v4[
"header"].hasType());
164 EXPECT_FALSE(v4[
"header"].isEmpty());
165 EXPECT_EQ(
typeid(std_msgs::Header), v4[
"header"].getValueTypeInfo());
166 EXPECT_NO_THROW(v4[
"builtin_string"] =
"Test");
167 EXPECT_EQ(
"Test", v4[
"builtin_string"].getValue<std::string>());
168 EXPECT_EQ(
typeid(
bool[3]),
169 v4[
"builtin_boolean_array"].getType().getTypeInfo());
170 EXPECT_EQ(
typeid(boost::array<uint8_t, 3>),
171 v4[
"builtin_boolean_array"].getValueTypeInfo());
Header file providing the MessageDefinition class interface.
Header file providing the MessageVariant class interface.
Header file providing the DataTypeRegistry class interface.
Header file providing the ArrayVariant class interface.
Header file providing the BuiltinVariant class interface.