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();
static TimeStampStatusParam DefaultTimeStampStatusParam
Default TimeStampStatusParam. This is like calling the constructor with no arguments.
void unwrapped(diagnostic_msgs::DiagnosticStatus &s)
virtual void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
Fills out this Task's DiagnosticStatusWrapper.
void summary(unsigned char lvl, const std::string s)
Fills out the level and message fields of the DiagnosticStatus.
A structure that holds the constructor parameters for the FrequencyStatus class.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void add(const std::string &name, TaskFunction f)
Add a DiagnosticTask embodied by a name and function to the DiagnosticTaskVector. ...
int main(int argc, char **argv)
A structure that holds the constructor parameters for the TimeStampStatus class.
virtual void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
Fills out this Task's DiagnosticStatusWrapper.
static void setNow(const Time &new_now)
void addf(const std::string &key, const char *format,...)
Add a key-value pair using a format string.
Manages a list of diagnostic tasks, and calls them in a rate-limited manner.
A diagnostic task that monitors the frequency of an event.
void wrapped(DiagnosticStatusWrapper &s)
void tick()
Signals that an event has occurred.
Diagnostic task to monitor the interval between events.
void clear()
Resets the statistics.
void mergeSummary(unsigned char lvl, const std::string s)
Merges a level and message with the existing ones.
const std::string & getName()
Returns the name of the DiagnosticTask.
TEST(DiagnosticUpdater, testDiagnosticUpdater)
DiagnosticTask is an abstract base class for collecting diagnostic data.
void add(const std::string &key, const T &val)
Add a key-value pair.
void tick(double stamp)
Signals an event. Timestamp stored as a double.
Wrapper for the diagnostic_msgs::DiagnosticStatus message that makes it easier to update...