32 #include "log4cxx/appenderskeleton.h"
33 #include "log4cxx/spi/loggingevent.h"
36 #include "log4cxx/helpers/transcoder.h"
42 #include <gtest/gtest.h>
44 #include <boost/shared_array.hpp>
45 #include <boost/regex.hpp>
62 virtual void append(
const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool&)
65 info.level_ =
event->getLevel();
67 LOG4CXX_ENCODE_CHAR(msgstr, event->getMessage());
68 info.message_ = msgstr;
70 LOG4CXX_ENCODE_CHAR(loggerstr, event->getLoggerName());
71 info.logger_name_ = loggerstr;
73 info.message_ =
event->getMessage();
74 info.logger_name_ =
event->getLoggerName();
77 info_.push_back( info );
92 virtual void append(
const log4cxx::spi::LoggingEventPtr&, log4cxx::helpers::Pool&)
94 throw std::runtime_error(
"This should be caught");
119 #define DEFINE_COND_TESTS(name, macro_base, level, log4cxx_level) \
120 TEST(RosConsole, name##Cond) \
122 TestAppender* appender = new TestAppender; \
123 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
124 macro_base##_COND(true, "Testing %d %d %d", 1, 2, 3); \
125 macro_base##_COND(false, "Testing %d %d %d", 1, 2, 3); \
126 ASSERT_EQ((int)appender->info_.size(), 1); \
127 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
128 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
129 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
131 TEST(RosConsole, name##NamedCond) \
133 TestAppender* appender = new TestAppender; \
134 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
135 macro_base##_COND_NAMED(true, "test", "Testing %d %d %d", 1, 2, 3); \
136 macro_base##_COND_NAMED(false, "test", "Testing %d %d %d", 1, 2, 3); \
137 ASSERT_EQ((int)appender->info_.size(), 1); \
138 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
139 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
140 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
141 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
143 TEST(RosConsole, name##StreamCond) \
145 TestAppender* appender = new TestAppender; \
146 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
147 macro_base##_STREAM_COND(true, "Testing " << 1 << " " << 2 << " " << 3); \
148 macro_base##_STREAM_COND(false, "Testing " << 1 << " " << 2 << " " << 3); \
149 ASSERT_EQ((int)appender->info_.size(), 1); \
150 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
151 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
152 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
154 TEST(RosConsole, name##StreamCondNamed) \
156 TestAppender* appender = new TestAppender; \
157 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
158 macro_base##_STREAM_COND_NAMED(true, "test", "Testing " << 1 << " " << 2 << " " << 3); \
159 macro_base##_STREAM_COND_NAMED(false, "test", "Testing " << 1 << " " << 2 << " " << 3); \
160 ASSERT_EQ((int)appender->info_.size(), 1); \
161 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
162 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
163 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
164 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
167 #define DEFINE_ONCE_TESTS(name, macro_base, level, log4cxx_level) \
168 TEST(RosConsole, name##Once) \
170 TestAppender* appender = new TestAppender; \
171 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
172 macro_base##_ONCE("Testing %d %d %d", 1, 2, 3); \
173 ASSERT_EQ((int)appender->info_.size(), 1); \
174 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
175 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
176 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
178 TEST(RosConsole, name##NamedOnce) \
180 TestAppender* appender = new TestAppender; \
181 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
182 macro_base##_ONCE_NAMED("test", "Testing %d %d %d", 1, 2, 3); \
183 ASSERT_EQ((int)appender->info_.size(), 1); \
184 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
185 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
186 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
187 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
189 TEST(RosConsole, name##StreamOnce) \
191 TestAppender* appender = new TestAppender; \
192 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
193 macro_base##_STREAM_ONCE("Testing " << 1 << " " << 2 << " " << 3); \
194 ASSERT_EQ((int)appender->info_.size(), 1); \
195 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
196 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
197 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
199 TEST(RosConsole, name##StreamOnceNamed) \
201 TestAppender* appender = new TestAppender; \
202 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
203 macro_base##_STREAM_ONCE_NAMED("test", "Testing " << 1 << " " << 2 << " " << 3); \
204 ASSERT_EQ((int)appender->info_.size(), 1); \
205 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
206 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
207 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
208 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
211 #define DEFINE_THROTTLE_TESTS(name, macro_base, level, log4cxx_level) \
212 TEST(RosConsole, name##Throttle) \
214 TestAppender* appender = new TestAppender; \
215 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
216 macro_base##_THROTTLE(0.5, "Testing %d %d %d", 1, 2, 3); \
217 ASSERT_EQ((int)appender->info_.size(), 1); \
218 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
219 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
220 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
222 TEST(RosConsole, name##NamedThrottle) \
224 TestAppender* appender = new TestAppender; \
225 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
226 macro_base##_THROTTLE_NAMED(0.5, "test", "Testing %d %d %d", 1, 2, 3); \
227 ASSERT_EQ((int)appender->info_.size(), 1); \
228 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
229 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
230 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
231 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
233 TEST(RosConsole, name##StreamThrottle) \
235 TestAppender* appender = new TestAppender; \
236 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
237 macro_base##_STREAM_THROTTLE(0.5, "Testing " << 1 << " " << 2 << " " << 3); \
238 ASSERT_EQ((int)appender->info_.size(), 1); \
239 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
240 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
241 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
243 TEST(RosConsole, name##StreamThrottleNamed) \
245 TestAppender* appender = new TestAppender; \
246 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
247 macro_base##_STREAM_THROTTLE_NAMED(0.5, "test", "Testing " << 1 << " " << 2 << " " << 3); \
248 ASSERT_EQ((int)appender->info_.size(), 1); \
249 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
250 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
251 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
252 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
255 #define DEFINE_FILTER_TESTS(name, macro_base, level, log4cxx_level) \
256 TEST(RosConsole, name##Filter) \
258 TestAppender* appender = new TestAppender; \
259 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
260 macro_base##_FILTER(&g_filter, "Testing %d %d %d", 1, 2, 3); \
261 ASSERT_EQ((int)appender->info_.size(), 1); \
262 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
263 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
264 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
266 TEST(RosConsole, name##NamedFilter) \
268 TestAppender* appender = new TestAppender; \
269 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
270 macro_base##_FILTER_NAMED(&g_filter, "test", "Testing %d %d %d", 1, 2, 3); \
271 ASSERT_EQ((int)appender->info_.size(), 1); \
272 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
273 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
274 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
275 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
277 TEST(RosConsole, name##StreamFilter) \
279 TestAppender* appender = new TestAppender; \
280 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
281 macro_base##_STREAM_FILTER(&g_filter, "Testing " << 1 << " " << 2 << " " << 3); \
282 ASSERT_EQ((int)appender->info_.size(), 1); \
283 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
284 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
285 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
287 TEST(RosConsole, name##StreamFilterNamed) \
289 TestAppender* appender = new TestAppender; \
290 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
291 macro_base##_STREAM_FILTER_NAMED(&g_filter, "test", "Testing " << 1 << " " << 2 << " " << 3); \
292 ASSERT_EQ((int)appender->info_.size(), 1); \
293 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
294 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
295 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
296 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
299 #define DEFINE_LEVEL_TESTS(name, macro_base, level, log4cxx_level) \
300 TEST(RosConsole, name) \
302 TestAppender* appender = new TestAppender; \
303 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
304 macro_base("Testing %d %d %d", 1, 2, 3); \
305 ASSERT_EQ((int)appender->info_.size(), 1); \
306 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
307 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
308 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
310 TEST(RosConsole, name##Named) \
312 TestAppender* appender = new TestAppender; \
313 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
314 macro_base##_NAMED("test", "Testing %d %d %d", 1, 2, 3); \
315 ASSERT_EQ((int)appender->info_.size(), 1); \
316 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
317 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
318 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
319 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
321 TEST(RosConsole, name##Stream) \
323 TestAppender* appender = new TestAppender; \
324 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
325 macro_base##_STREAM("Testing " << 1 << " " << 2 << " " << 3); \
326 ASSERT_EQ((int)appender->info_.size(), 1); \
327 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
328 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
329 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
331 TEST(RosConsole, name##StreamNamed) \
333 TestAppender* appender = new TestAppender; \
334 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \
335 macro_base##_STREAM_NAMED("test", "Testing " << 1 << " " << 2 << " " << 3); \
336 ASSERT_EQ((int)appender->info_.size(), 1); \
337 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \
338 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \
339 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \
340 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \
342 DEFINE_COND_TESTS(name, macro_base, level, log4cxx_level) \
343 DEFINE_ONCE_TESTS(name, macro_base, level, log4cxx_level) \
344 DEFINE_THROTTLE_TESTS(name, macro_base, level, log4cxx_level) \
345 DEFINE_FILTER_TESTS(name, macro_base, level, log4cxx_level)
353 TEST(RosConsole, loggingLevels)
358 logger->addAppender( appender );
364 logger->setLevel( log4cxx::Level::getInfo() );
365 pre_count = appender->
info_.size();
371 post_count = appender->
info_.size();
372 EXPECT_EQ(post_count, pre_count + 4);
374 logger->setLevel( log4cxx::Level::getWarn() );
375 pre_count = appender->
info_.size();
381 post_count = appender->
info_.size();
382 EXPECT_EQ(post_count, pre_count + 3);
384 logger->setLevel( log4cxx::Level::getError() );
385 pre_count = appender->
info_.size();
391 post_count = appender->
info_.size();
392 EXPECT_EQ(post_count, pre_count + 2);
394 logger->setLevel( log4cxx::Level::getFatal() );
395 pre_count = appender->
info_.size();
401 post_count = appender->
info_.size();
402 EXPECT_EQ(post_count, pre_count + 1);
404 logger->setLevel( log4cxx::Level::getOff() );
405 pre_count = appender->
info_.size();
411 post_count = appender->
info_.size();
412 EXPECT_EQ(post_count, pre_count);
416 logger->setLevel( log4cxx::Level::getInfo() );
417 pre_count = appender->
info_.size();
423 post_count = appender->
info_.size();
424 EXPECT_EQ(post_count, pre_count + 4);
426 logger->setLevel( log4cxx::Level::getWarn() );
427 pre_count = appender->
info_.size();
433 post_count = appender->
info_.size();
434 EXPECT_EQ(post_count, pre_count + 3);
436 logger->setLevel( log4cxx::Level::getError() );
437 pre_count = appender->
info_.size();
443 post_count = appender->
info_.size();
444 EXPECT_EQ(post_count, pre_count + 2);
446 logger->setLevel( log4cxx::Level::getFatal() );
447 pre_count = appender->
info_.size();
453 post_count = appender->
info_.size();
454 EXPECT_EQ(post_count, pre_count + 1);
456 logger->setLevel( log4cxx::Level::getOff() );
457 pre_count = appender->
info_.size();
463 post_count = appender->
info_.size();
464 EXPECT_EQ(post_count, pre_count);
468 logger->setLevel( log4cxx::Level::getInfo() );
469 pre_count = appender->
info_.size();
475 post_count = appender->
info_.size();
476 EXPECT_EQ(post_count, pre_count + 4);
478 logger->setLevel( log4cxx::Level::getWarn() );
479 pre_count = appender->
info_.size();
485 post_count = appender->
info_.size();
486 EXPECT_EQ(post_count, pre_count + 3);
488 logger->setLevel( log4cxx::Level::getError() );
489 pre_count = appender->
info_.size();
495 post_count = appender->
info_.size();
496 EXPECT_EQ(post_count, pre_count + 2);
498 logger->setLevel( log4cxx::Level::getFatal() );
499 pre_count = appender->
info_.size();
505 post_count = appender->
info_.size();
506 EXPECT_EQ(post_count, pre_count + 1);
508 logger->setLevel( log4cxx::Level::getOff() );
509 pre_count = appender->
info_.size();
515 post_count = appender->
info_.size();
516 EXPECT_EQ(post_count, pre_count);
520 logger->setLevel( log4cxx::Level::getInfo() );
521 pre_count = appender->
info_.size();
527 post_count = appender->
info_.size();
528 EXPECT_EQ(post_count, pre_count + 4);
530 logger->setLevel( log4cxx::Level::getWarn() );
531 pre_count = appender->
info_.size();
537 post_count = appender->
info_.size();
538 EXPECT_EQ(post_count, pre_count + 3);
540 logger->setLevel( log4cxx::Level::getError() );
541 pre_count = appender->
info_.size();
547 post_count = appender->
info_.size();
548 EXPECT_EQ(post_count, pre_count + 2);
550 logger->setLevel( log4cxx::Level::getFatal() );
551 pre_count = appender->
info_.size();
557 post_count = appender->
info_.size();
558 EXPECT_EQ(post_count, pre_count + 1);
560 logger->setLevel( log4cxx::Level::getOff() );
561 pre_count = appender->
info_.size();
567 post_count = appender->
info_.size();
568 EXPECT_EQ(post_count, pre_count);
571 logger->removeAppender( appender );
574 TEST(RosConsole, changingLevel)
579 logger->addAppender( appender );
581 logger->setLevel( log4cxx::Level::getError() );
587 EXPECT_EQ((
int)appender->
info_.size(), 2);
589 logger->removeAppender( appender );
591 logger->setLevel( log4cxx::Level::getDebug() );
594 TEST(RosConsole, changingLoggerLevel)
599 logger->addAppender( appender );
601 logger->setLevel(log4cxx::Level::getDebug());
605 logger->setLevel(log4cxx::Level::getInfo());
609 logger->setLevel(log4cxx::Level::getWarn());
613 logger->setLevel(log4cxx::Level::getError());
617 logger->setLevel(log4cxx::Level::getFatal());
621 EXPECT_EQ((
int)appender->
info_.size(), 5);
623 logger->removeAppender( appender );
625 logger->setLevel( log4cxx::Level::getDebug() );
628 TEST(RosConsole, longPrintfStyleOutput)
633 logger->addAppender( appender );
635 std::stringstream ss;
636 for (
int i = 0; i < 100000; ++i )
643 ASSERT_EQ((
int)appender->
info_.size(), 1);
644 EXPECT_STREQ(appender->
info_[0].message_.c_str(), ss.str().c_str());
646 logger->removeAppender( appender );
648 logger->setLevel( log4cxx::Level::getDebug() );
651 TEST(RosConsole, throwingAppender)
656 logger->addAppender( appender );
662 catch (std::exception& e)
667 logger->removeAppender( appender );
668 logger->setLevel( log4cxx::Level::getDebug() );
681 logger->addAppender(appender);
686 EXPECT_EQ(appender->
info_.size(), 1ULL);
688 logger->removeAppender(appender);
701 logger->addAppender(appender);
712 EXPECT_EQ(appender->
info_.size(), 2ULL);
714 logger->removeAppender(appender);
727 TEST(RosConsole, delayedThrottle)
732 logger->addAppender(appender);
741 EXPECT_EQ(appender->
info_.size(), 0ULL);
743 const int pre_count = appender->
info_.size();
751 const int post_count = appender->
info_.size();
753 EXPECT_EQ(post_count, pre_count + 1);
755 logger->removeAppender(appender);
769 logger->addAppender(appender);
774 EXPECT_EQ(appender->
info_.size(), 1ULL);
776 logger->removeAppender(appender);
784 TEST(RosConsole, throttleStream)
789 logger->addAppender(appender);
800 EXPECT_EQ(appender->
info_.size(), 2ULL);
802 logger->removeAppender(appender);
815 TEST(RosConsole, delayedStreamThrottle)
820 logger->addAppender(appender);
829 EXPECT_EQ(appender->
info_.size(), 0ULL);
831 const int pre_count = appender->
info_.size();
839 const int post_count = appender->
info_.size();
841 EXPECT_EQ(post_count, pre_count + 1);
843 logger->removeAppender(appender);
851 logger->addAppender(appender);
857 ASSERT_EQ(appender->
info_.size(), 1ULL);
858 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
860 logger->removeAppender(appender);
863 TEST(RosConsole, basicFilterStream)
868 logger->addAppender(appender);
874 ASSERT_EQ(appender->
info_.size(), 1ULL);
875 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
877 logger->removeAppender(appender);
899 TEST(RosConsole, advancedFilter)
904 logger->addAppender(appender);
910 ASSERT_EQ(appender->
info_.size(), 1ULL);
911 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
912 EXPECT_EQ(trueFilter.count_, 1);
913 EXPECT_EQ(falseFilter.
count_, 1);
915 logger->removeAppender(appender);
918 TEST(RosConsole, advancedFilterStream)
923 logger->addAppender(appender);
929 ASSERT_EQ(appender->
info_.size(), 1ULL);
930 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
931 EXPECT_EQ(trueFilter.count_, 1);
932 EXPECT_EQ(falseFilter.
count_, 1);
934 logger->removeAppender(appender);
953 logger->addAppender(appender);
958 ASSERT_EQ(appender->
info_.size(), 1ULL);
959 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"haha");
960 EXPECT_EQ(appender->
info_[0].level_, log4cxx::Level::getError());
962 logger->removeAppender(appender);
965 TEST(RosConsole, changeFilterStream)
970 logger->addAppender(appender);
975 ASSERT_EQ(appender->
info_.size(), 1ULL);
976 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"haha");
977 EXPECT_EQ(appender->
info_[0].level_, log4cxx::Level::getError());
979 logger->removeAppender(appender);
982 TEST(RosConsole, formatToBufferInitialZero)
987 EXPECT_EQ(size, 14U);
988 EXPECT_STREQ(buffer.get(),
"Hello World 5");
991 TEST(RosConsole, formatToBufferInitialLargerThanFormat)
996 EXPECT_EQ(size, 30U);
997 EXPECT_STREQ(buffer.get(),
"Hello World 5");
1003 EXPECT_STREQ(str.c_str(),
"Hello World 5");
1008 std::string format_string;
1019 std::string format_string =
"${time}";
1028 boost::regex expr(
"([0-9]+)\\.([0-9]+)");
1029 EXPECT_TRUE(boost::regex_match(result, expr));
1034 std::string format_string =
"${time:%Y %H:%M:%S}";
1043 boost::regex expr(
"([0-9]{4}) ([0-9]{2}:[0-9]{2}:[0-9]{2})");
1044 EXPECT_TRUE(boost::regex_match(result, expr));
1049 std::string format_string =
"${walltime}";
1058 boost::regex expr(
"([0-9]+)\\.([0-9]+)");
1059 EXPECT_TRUE(boost::regex_match(result, expr));
1064 std::string format_string =
"${walltime:%Y %H:%M:%S}";
1073 boost::regex expr(
"([0-9]{4}) ([0-9]{2}:[0-9]{2}:[0-9]{2})");
1074 EXPECT_TRUE(boost::regex_match(result, expr));
1080 testing::InitGoogleTest(&argc, argv);
1085 log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
1088 return RUN_ALL_TESTS();