35 #include <gtest/gtest.h>
48 void unwrapped(diagnostic_msgs::DiagnosticStatus &s)
57 TEST(DiagnosticUpdater, testDiagnosticUpdater)
67 s.summary(0,
"Test is running");
68 s.addf(
"Value",
"%f", 5);
69 s.add(
"String",
"Toto");
70 s.add(
"Floating", 5.55);
72 s.addf(
"Formatted %s %i",
"Hello", 5);
88 TEST(DiagnosticUpdater, testDiagnosticStatusWrapperKeyValuePairs)
92 const char *message =
"dummy";
95 EXPECT_STREQ(message, stat.message.c_str()) <<
"DiagnosticStatusWrapper::summary failed to set message";
96 EXPECT_EQ(level, stat.level) <<
"DiagnosticStatusWrapper::summary failed to set level";
98 stat.
addf(
"toto",
"%.1f", 5.0);
100 stat.
addf(
"foo",
"%05i", 27);
102 stat.
add(
"bool",
true);
103 stat.
add(
"bool2",
false);
105 EXPECT_STREQ(
"5.0", stat.values[0].value.c_str()) <<
"Bad value, adding a value with addf";
106 EXPECT_STREQ(
"5", stat.values[1].value.c_str()) <<
"Bad value, adding a string with add";
107 EXPECT_STREQ(
"00027", stat.values[2].value.c_str()) <<
"Bad value, adding a string with addf";
108 EXPECT_STREQ(
"toto", stat.values[0].key.c_str()) <<
"Bad label, adding a value with add";
109 EXPECT_STREQ(
"baba", stat.values[1].key.c_str()) <<
"Bad label, adding a string with add";
110 EXPECT_STREQ(
"foo", stat.values[2].key.c_str()) <<
"Bad label, adding a string with addf";
112 EXPECT_STREQ(
"bool", stat.values[3].key.c_str()) <<
"Bad label, adding a true bool key with add";
113 EXPECT_STREQ(
"True", stat.values[3].value.c_str()) <<
"Bad label, adding a true bool with add";
115 EXPECT_STREQ(
"bool2", stat.values[4].key.c_str()) <<
"Bad label, adding a false bool key with add";
116 EXPECT_STREQ(
"False", stat.values[4].value.c_str()) <<
"Bad label, adding a false bool with add";
119 TEST(DiagnosticUpdater, testDiagnosticStatusWrapperMergeSummary)
126 EXPECT_STREQ(
"Old", stat.message.c_str()) <<
"Bad summary, merging levels (OK,OK)";
131 EXPECT_STREQ(
"New", stat.message.c_str()) <<
"Bad summary, merging levels (OK,WARN)";
136 EXPECT_STREQ(
"Old; New", stat.message.c_str()) <<
"Bad summary, merging levels (WARN,WARN)";
141 EXPECT_STREQ(
"Old; New", stat.message.c_str()) <<
"Bad summary, merging levels (WARN,ERROR)";
144 TEST(DiagnosticUpdater, testFrequencyStatus)
155 const int MS_TO_NS = 1000000;
173 using diagnostic_msgs::DiagnosticStatus;
180 EXPECT_STREQ(
"", stat[0].name.c_str()) <<
"Name should not be set by FrequencyStatus";
181 EXPECT_STREQ(
"Frequency Status", fs.
getName().c_str()) <<
"Name should be \"Frequency Status\"";
184 TEST(DiagnosticUpdater, testSlowFrequencyStatus)
190 double minFreq = 0.25;
191 double maxFreq = 0.75;
220 using diagnostic_msgs::DiagnosticStatus;
232 TEST(DiagnosticUpdater, testTimeStampStatus)
251 using diagnostic_msgs::DiagnosticStatus;
258 EXPECT_STREQ(
"", stat[0].name.c_str()) <<
"Name should not be set by TimeStapmStatus";
259 EXPECT_STREQ(
"Timestamp Status", ts.
getName().c_str()) <<
"Name should be \"Timestamp Status\"";
262 TEST(DiagnosticUpdater, testSlowTimeStampStatus)
289 using diagnostic_msgs::DiagnosticStatus;
304 int main(
int argc,
char **argv){
306 testing::InitGoogleTest(&argc, argv);
307 return RUN_ALL_TESTS();