test_dd_enum.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <gtest/gtest.h>
4 
5 namespace ddynamic_reconfigure {
6 
10  TEST(DDEnumTest, constructorTest) { // NOLINT(cert-err58-cpp,modernize-use-equals-delete)
11  map<string,int> dict;
12  dict["ONE"] = 1;
13  dict["NEG-ONE"] = -1;
14  dict["TEN"] = 10;
15  DDEnum param1("param1",0,"param1",0,dict);
16  DDEnum param2("",0,"","ONE",dict);
17  DDEnum param3("\000",0,"\000", 0, dict); // NOLINT(bugprone-string-literal-with-embedded-nul)
18  }
19 
23  TEST(DDEnumTest, valueTest) { // NOLINT(cert-err58-cpp,modernize-use-equals-delete)
24  map<string,int> dict;
25  dict["ONE"] = 1;
26  dict["NEG-ONE"] = -1;
27  dict["TEN"] = 10;
28  DDEnum param("dd_param",0,"dd_param",1,dict);
29  // we won't do any tests on getLevel or getName, as those are implicit.
30  Value v(1);
31  ASSERT_TRUE(param.sameType(v));
32  ASSERT_TRUE(param.sameValue(v));
33 
34  v = Value("ONE");
35  ASSERT_TRUE(param.sameType(v));
36  ASSERT_TRUE(param.sameValue(v));
37 
38  v = Value(1.0);
39  ASSERT_FALSE(param.sameType(v));
40  ASSERT_TRUE(param.sameValue(v));
41 
42  v = Value(10);
43  ASSERT_TRUE(param.sameType(v));
44  ASSERT_FALSE(param.sameValue(v));
45 
46  v = Value("TEN");
47  ASSERT_TRUE(param.sameType(v));
48  ASSERT_FALSE(param.sameValue(v));
49 
50  v = Value(10.0);
51  ASSERT_FALSE(param.sameType(v));
52  ASSERT_FALSE(param.sameValue(v));
53 
54  param.setValue(v);
55  v = Value(-1);
56  ASSERT_FALSE(param.sameValue(v)); // makes sure anti-aliasing happens regarding int setValue
57 
58  ASSERT_TRUE(param.getValue().getType() == "int");
59  ASSERT_TRUE(param.sameValue(Value(10)));
60 
61  param.setValue(v);
62  param.setValue(Value("TEN"));
63  ASSERT_FALSE(param.sameValue(v)); // makes sure anti-aliasing happens regarding string setValue
64 
65  ASSERT_TRUE(param.getValue().getType() == "int");
66  ASSERT_TRUE(param.sameValue(Value(10)));
67 
68  // make sure setValue and sameValue can handle int-string values
69  v = Value("10");
70  ASSERT_TRUE(param.sameValue(v));
71  param.setValue(v);
72 
73  ASSERT_TRUE(param.getValue().getType() == "int");
74  ASSERT_TRUE(param.sameValue(Value(10)));
75 
76  // make sure setValue and sameValue can handle non-number non-dictionary strings
77  v = Value("TWO");
78  // 'two' is not in our dictionary, so we will attempt to place it in there using a hash conversion
79  ASSERT_FALSE(param.sameValue(v));
80  param.setValue(v);
81 
82  ASSERT_TRUE(param.getValue().getType() == "int");
83  int hash = (int)boost::hash<string>()("TWO");
84  ASSERT_TRUE(param.sameValue(Value(hash)));
85  }
86 
87  TEST(DDEnumTest, streamTest) { // NOLINT(cert-err58-cpp,modernize-use-equals-delete)
88  map<string,int> dict;
89  dict["ONE"] = 1;
90  dict["NEG-ONE"] = -1;
91  dict["TEN"] = 10;
92  DDEnum param1("param1",0,"param1",1,dict);
93  stringstream stream;
94  stream << param1;
95  ASSERT_EQ(param1.getName() + ":" + param1.getValue().toString(),stream.str());
96  }
97 }
98 
99 
100 int main(int argc, char** argv) {
101  testing::InitGoogleTest(&argc, argv);
102 
103  srand((unsigned int)random());
104 
105  return RUN_ALL_TESTS();
106 }
bool sameType(Value val)
checks whether or not the raw value stored in the value is compatible with the given parameter...
bool param(const std::string &param_name, T &param_val, const T &default_val)
void setValue(Value val)
sets the value of this parameter as this one.
int main(int argc, char **argv)
bool sameValue(Value val)
checks whether or not the value stored in the value object, when converted to the type of the interna...
an integer enum implementation of the parameter. This is an extension to the int parameter, which allows creating string aliases for certain (if not all) numbers available.
Definition: dd_enum_param.h:19
Value getValue() const
gets the value of this parameter.
The Value class is used to wrap all basic data-types (bool,int,double,string) in something generic...
Definition: dd_value.h:29
TEST(DDFullScaleTest, doTest)
A ROS client making sure the server sends the new information.
Definition: dd_client.cpp:16
string getType() const
gets the type this value wrapper stores
Definition: dd_value.h:84


ddynamic_reconfigure
Author(s): Noam Dori
autogenerated on Thu May 16 2019 02:46:37