32 #include "log4cxx/appenderskeleton.h" 33 #include "log4cxx/spi/loggingevent.h" 38 #include <gtest/gtest.h> 40 #include <boost/shared_array.hpp> 57 virtual void append(
const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool&)
60 info.level_ =
event->getLevel();
61 info.message_ =
event->getMessage();
62 info.logger_name_ =
event->getLoggerName();
64 info_.push_back( info );
79 virtual void append(
const log4cxx::spi::LoggingEventPtr&, log4cxx::helpers::Pool&)
81 throw std::runtime_error(
"This should be caught");
99 inline virtual bool isEnabled() {
return enabled_; };
106 #define DEFINE_COND_TESTS(name, macro_base, level, log4cxx_level) \ 107 TEST(RosConsole, name##Cond) \ 109 TestAppender* appender = new TestAppender; \ 110 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 111 macro_base##_COND(true, "Testing %d %d %d", 1, 2, 3); \ 112 macro_base##_COND(false, "Testing %d %d %d", 1, 2, 3); \ 113 ASSERT_EQ((int)appender->info_.size(), 1); \ 114 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 115 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 116 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 118 TEST(RosConsole, name##NamedCond) \ 120 TestAppender* appender = new TestAppender; \ 121 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 122 macro_base##_COND_NAMED(true, "test", "Testing %d %d %d", 1, 2, 3); \ 123 macro_base##_COND_NAMED(false, "test", "Testing %d %d %d", 1, 2, 3); \ 124 ASSERT_EQ((int)appender->info_.size(), 1); \ 125 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 126 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 127 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 128 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 130 TEST(RosConsole, name##StreamCond) \ 132 TestAppender* appender = new TestAppender; \ 133 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 134 macro_base##_STREAM_COND(true, "Testing " << 1 << " " << 2 << " " << 3); \ 135 macro_base##_STREAM_COND(false, "Testing " << 1 << " " << 2 << " " << 3); \ 136 ASSERT_EQ((int)appender->info_.size(), 1); \ 137 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 138 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 139 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 141 TEST(RosConsole, name##StreamCondNamed) \ 143 TestAppender* appender = new TestAppender; \ 144 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 145 macro_base##_STREAM_COND_NAMED(true, "test", "Testing " << 1 << " " << 2 << " " << 3); \ 146 macro_base##_STREAM_COND_NAMED(false, "test", "Testing " << 1 << " " << 2 << " " << 3); \ 147 ASSERT_EQ((int)appender->info_.size(), 1); \ 148 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 149 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 150 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 151 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 154 #define DEFINE_ONCE_TESTS(name, macro_base, level, log4cxx_level) \ 155 TEST(RosConsole, name##Once) \ 157 TestAppender* appender = new TestAppender; \ 158 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 159 macro_base##_ONCE("Testing %d %d %d", 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 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 165 TEST(RosConsole, name##NamedOnce) \ 167 TestAppender* appender = new TestAppender; \ 168 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 169 macro_base##_ONCE_NAMED("test", "Testing %d %d %d", 1, 2, 3); \ 170 ASSERT_EQ((int)appender->info_.size(), 1); \ 171 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 172 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 173 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 174 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 176 TEST(RosConsole, name##StreamOnce) \ 178 TestAppender* appender = new TestAppender; \ 179 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 180 macro_base##_STREAM_ONCE("Testing " << 1 << " " << 2 << " " << 3); \ 181 ASSERT_EQ((int)appender->info_.size(), 1); \ 182 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 183 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 184 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 186 TEST(RosConsole, name##StreamOnceNamed) \ 188 TestAppender* appender = new TestAppender; \ 189 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 190 macro_base##_STREAM_ONCE_NAMED("test", "Testing " << 1 << " " << 2 << " " << 3); \ 191 ASSERT_EQ((int)appender->info_.size(), 1); \ 192 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 193 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 194 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 195 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 198 #define DEFINE_THROTTLE_TESTS(name, macro_base, level, log4cxx_level) \ 199 TEST(RosConsole, name##Throttle) \ 201 TestAppender* appender = new TestAppender; \ 202 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 203 macro_base##_THROTTLE(0.5, "Testing %d %d %d", 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 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 209 TEST(RosConsole, name##NamedThrottle) \ 211 TestAppender* appender = new TestAppender; \ 212 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 213 macro_base##_THROTTLE_NAMED(0.5, "test", "Testing %d %d %d", 1, 2, 3); \ 214 ASSERT_EQ((int)appender->info_.size(), 1); \ 215 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 216 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 217 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 218 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 220 TEST(RosConsole, name##StreamThrottle) \ 222 TestAppender* appender = new TestAppender; \ 223 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 224 macro_base##_STREAM_THROTTLE(0.5, "Testing " << 1 << " " << 2 << " " << 3); \ 225 ASSERT_EQ((int)appender->info_.size(), 1); \ 226 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 227 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 228 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 230 TEST(RosConsole, name##StreamThrottleNamed) \ 232 TestAppender* appender = new TestAppender; \ 233 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 234 macro_base##_STREAM_THROTTLE_NAMED(0.5, "test", "Testing " << 1 << " " << 2 << " " << 3); \ 235 ASSERT_EQ((int)appender->info_.size(), 1); \ 236 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 237 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 238 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 239 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 242 #define DEFINE_FILTER_TESTS(name, macro_base, level, log4cxx_level) \ 243 TEST(RosConsole, name##Filter) \ 245 TestAppender* appender = new TestAppender; \ 246 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 247 macro_base##_FILTER(&g_filter, "Testing %d %d %d", 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 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 253 TEST(RosConsole, name##NamedFilter) \ 255 TestAppender* appender = new TestAppender; \ 256 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 257 macro_base##_FILTER_NAMED(&g_filter, "test", "Testing %d %d %d", 1, 2, 3); \ 258 ASSERT_EQ((int)appender->info_.size(), 1); \ 259 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 260 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 261 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 262 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 264 TEST(RosConsole, name##StreamFilter) \ 266 TestAppender* appender = new TestAppender; \ 267 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 268 macro_base##_STREAM_FILTER(&g_filter, "Testing " << 1 << " " << 2 << " " << 3); \ 269 ASSERT_EQ((int)appender->info_.size(), 1); \ 270 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 271 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 272 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 274 TEST(RosConsole, name##StreamFilterNamed) \ 276 TestAppender* appender = new TestAppender; \ 277 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 278 macro_base##_STREAM_FILTER_NAMED(&g_filter, "test", "Testing " << 1 << " " << 2 << " " << 3); \ 279 ASSERT_EQ((int)appender->info_.size(), 1); \ 280 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 281 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 282 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 283 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 286 #define DEFINE_LEVEL_TESTS(name, macro_base, level, log4cxx_level) \ 287 TEST(RosConsole, name) \ 289 TestAppender* appender = new TestAppender; \ 290 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 291 macro_base("Testing %d %d %d", 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 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 297 TEST(RosConsole, name##Named) \ 299 TestAppender* appender = new TestAppender; \ 300 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 301 macro_base##_NAMED("test", "Testing %d %d %d", 1, 2, 3); \ 302 ASSERT_EQ((int)appender->info_.size(), 1); \ 303 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 304 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 305 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 306 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 308 TEST(RosConsole, name##Stream) \ 310 TestAppender* appender = new TestAppender; \ 311 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 312 macro_base##_STREAM("Testing " << 1 << " " << 2 << " " << 3); \ 313 ASSERT_EQ((int)appender->info_.size(), 1); \ 314 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 315 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 316 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 318 TEST(RosConsole, name##StreamNamed) \ 320 TestAppender* appender = new TestAppender; \ 321 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 322 macro_base##_STREAM_NAMED("test", "Testing " << 1 << " " << 2 << " " << 3); \ 323 ASSERT_EQ((int)appender->info_.size(), 1); \ 324 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 325 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 326 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 327 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 329 DEFINE_COND_TESTS(name, macro_base, level, log4cxx_level) \ 330 DEFINE_ONCE_TESTS(name, macro_base, level, log4cxx_level) \ 331 DEFINE_THROTTLE_TESTS(name, macro_base, level, log4cxx_level) \ 332 DEFINE_FILTER_TESTS(name, macro_base, level, log4cxx_level) 340 TEST(RosConsole, loggingLevels)
345 logger->addAppender( appender );
351 logger->setLevel( log4cxx::Level::getInfo() );
352 pre_count = appender->
info_.size();
358 post_count = appender->
info_.size();
359 EXPECT_EQ(post_count, pre_count + 4);
361 logger->setLevel( log4cxx::Level::getWarn() );
362 pre_count = appender->
info_.size();
368 post_count = appender->
info_.size();
369 EXPECT_EQ(post_count, pre_count + 3);
371 logger->setLevel( log4cxx::Level::getError() );
372 pre_count = appender->
info_.size();
378 post_count = appender->
info_.size();
379 EXPECT_EQ(post_count, pre_count + 2);
381 logger->setLevel( log4cxx::Level::getFatal() );
382 pre_count = appender->
info_.size();
388 post_count = appender->
info_.size();
389 EXPECT_EQ(post_count, pre_count + 1);
391 logger->setLevel( log4cxx::Level::getOff() );
392 pre_count = appender->
info_.size();
398 post_count = appender->
info_.size();
399 EXPECT_EQ(post_count, pre_count);
403 logger->setLevel( log4cxx::Level::getInfo() );
404 pre_count = appender->
info_.size();
410 post_count = appender->
info_.size();
411 EXPECT_EQ(post_count, pre_count + 4);
413 logger->setLevel( log4cxx::Level::getWarn() );
414 pre_count = appender->
info_.size();
420 post_count = appender->
info_.size();
421 EXPECT_EQ(post_count, pre_count + 3);
423 logger->setLevel( log4cxx::Level::getError() );
424 pre_count = appender->
info_.size();
430 post_count = appender->
info_.size();
431 EXPECT_EQ(post_count, pre_count + 2);
433 logger->setLevel( log4cxx::Level::getFatal() );
434 pre_count = appender->
info_.size();
440 post_count = appender->
info_.size();
441 EXPECT_EQ(post_count, pre_count + 1);
443 logger->setLevel( log4cxx::Level::getOff() );
444 pre_count = appender->
info_.size();
450 post_count = appender->
info_.size();
451 EXPECT_EQ(post_count, pre_count);
455 logger->setLevel( log4cxx::Level::getInfo() );
456 pre_count = appender->
info_.size();
462 post_count = appender->
info_.size();
463 EXPECT_EQ(post_count, pre_count + 4);
465 logger->setLevel( log4cxx::Level::getWarn() );
466 pre_count = appender->
info_.size();
472 post_count = appender->
info_.size();
473 EXPECT_EQ(post_count, pre_count + 3);
475 logger->setLevel( log4cxx::Level::getError() );
476 pre_count = appender->
info_.size();
482 post_count = appender->
info_.size();
483 EXPECT_EQ(post_count, pre_count + 2);
485 logger->setLevel( log4cxx::Level::getFatal() );
486 pre_count = appender->
info_.size();
492 post_count = appender->
info_.size();
493 EXPECT_EQ(post_count, pre_count + 1);
495 logger->setLevel( log4cxx::Level::getOff() );
496 pre_count = appender->
info_.size();
502 post_count = appender->
info_.size();
503 EXPECT_EQ(post_count, pre_count);
507 logger->setLevel( log4cxx::Level::getInfo() );
508 pre_count = appender->
info_.size();
514 post_count = appender->
info_.size();
515 EXPECT_EQ(post_count, pre_count + 4);
517 logger->setLevel( log4cxx::Level::getWarn() );
518 pre_count = appender->
info_.size();
524 post_count = appender->
info_.size();
525 EXPECT_EQ(post_count, pre_count + 3);
527 logger->setLevel( log4cxx::Level::getError() );
528 pre_count = appender->
info_.size();
534 post_count = appender->
info_.size();
535 EXPECT_EQ(post_count, pre_count + 2);
537 logger->setLevel( log4cxx::Level::getFatal() );
538 pre_count = appender->
info_.size();
544 post_count = appender->
info_.size();
545 EXPECT_EQ(post_count, pre_count + 1);
547 logger->setLevel( log4cxx::Level::getOff() );
548 pre_count = appender->
info_.size();
554 post_count = appender->
info_.size();
555 EXPECT_EQ(post_count, pre_count);
558 logger->removeAppender( appender );
561 TEST(RosConsole, changingLevel)
566 logger->addAppender( appender );
568 logger->setLevel( log4cxx::Level::getError() );
574 EXPECT_EQ((
int)appender->
info_.size(), 2);
576 logger->removeAppender( appender );
578 logger->setLevel( log4cxx::Level::getDebug() );
581 TEST(RosConsole, changingLoggerLevel)
586 logger->addAppender( appender );
588 logger->setLevel(log4cxx::Level::getDebug());
592 logger->setLevel(log4cxx::Level::getInfo());
596 logger->setLevel(log4cxx::Level::getWarn());
600 logger->setLevel(log4cxx::Level::getError());
604 logger->setLevel(log4cxx::Level::getFatal());
608 EXPECT_EQ((
int)appender->
info_.size(), 5);
610 logger->removeAppender( appender );
612 logger->setLevel( log4cxx::Level::getDebug() );
615 TEST(RosConsole, longPrintfStyleOutput)
620 logger->addAppender( appender );
622 std::stringstream ss;
623 for (
int i = 0; i < 100000; ++i )
630 ASSERT_EQ((
int)appender->
info_.size(), 1);
631 EXPECT_STREQ(appender->
info_[0].message_.c_str(), ss.str().c_str());
633 logger->removeAppender( appender );
635 logger->setLevel( log4cxx::Level::getDebug() );
638 TEST(RosConsole, throwingAppender)
643 logger->addAppender( appender );
649 catch (std::exception& e)
654 logger->removeAppender( appender );
655 logger->setLevel( log4cxx::Level::getDebug() );
668 logger->addAppender(appender);
673 EXPECT_EQ(appender->
info_.size(), 1ULL);
675 logger->removeAppender(appender);
688 logger->addAppender(appender);
699 EXPECT_EQ(appender->
info_.size(), 2ULL);
701 logger->removeAppender(appender);
714 TEST(RosConsole, delayedThrottle)
719 logger->addAppender(appender);
728 EXPECT_EQ(appender->
info_.size(), 0ULL);
730 const int pre_count = appender->
info_.size();
738 const int post_count = appender->
info_.size();
740 EXPECT_EQ(post_count, pre_count + 1);
742 logger->removeAppender(appender);
756 logger->addAppender(appender);
761 EXPECT_EQ(appender->
info_.size(), 1ULL);
763 logger->removeAppender(appender);
771 TEST(RosConsole, throttleStream)
776 logger->addAppender(appender);
787 EXPECT_EQ(appender->
info_.size(), 2ULL);
789 logger->removeAppender(appender);
802 TEST(RosConsole, delayedStreamThrottle)
807 logger->addAppender(appender);
816 EXPECT_EQ(appender->
info_.size(), 0ULL);
818 const int pre_count = appender->
info_.size();
826 const int post_count = appender->
info_.size();
828 EXPECT_EQ(post_count, pre_count + 1);
830 logger->removeAppender(appender);
838 logger->addAppender(appender);
844 ASSERT_EQ(appender->
info_.size(), 1ULL);
845 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
847 logger->removeAppender(appender);
850 TEST(RosConsole, basicFilterStream)
855 logger->addAppender(appender);
861 ASSERT_EQ(appender->
info_.size(), 1ULL);
862 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
864 logger->removeAppender(appender);
886 TEST(RosConsole, advancedFilter)
891 logger->addAppender(appender);
897 ASSERT_EQ(appender->
info_.size(), 1ULL);
898 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
899 EXPECT_EQ(trueFilter.count_, 1);
900 EXPECT_EQ(falseFilter.
count_, 1);
902 logger->removeAppender(appender);
905 TEST(RosConsole, advancedFilterStream)
910 logger->addAppender(appender);
916 ASSERT_EQ(appender->
info_.size(), 1ULL);
917 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
918 EXPECT_EQ(trueFilter.count_, 1);
919 EXPECT_EQ(falseFilter.
count_, 1);
921 logger->removeAppender(appender);
940 logger->addAppender(appender);
945 ASSERT_EQ(appender->
info_.size(), 1ULL);
946 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"haha");
947 EXPECT_EQ(appender->
info_[0].level_, log4cxx::Level::getError());
949 logger->removeAppender(appender);
952 TEST(RosConsole, changeFilterStream)
957 logger->addAppender(appender);
962 ASSERT_EQ(appender->
info_.size(), 1ULL);
963 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"haha");
964 EXPECT_EQ(appender->
info_[0].level_, log4cxx::Level::getError());
966 logger->removeAppender(appender);
969 TEST(RosConsole, formatToBufferInitialZero)
974 EXPECT_EQ(size, 14U);
975 EXPECT_STREQ(buffer.get(),
"Hello World 5");
978 TEST(RosConsole, formatToBufferInitialLargerThanFormat)
983 EXPECT_EQ(size, 30U);
984 EXPECT_STREQ(buffer.get(),
"Hello World 5");
990 EXPECT_STREQ(str.c_str(),
"Hello World 5");
993 int main(
int argc,
char **argv)
995 testing::InitGoogleTest(&argc, argv);
1000 log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
1003 return RUN_ALL_TESTS();
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
#define ROS_INFO_NAMED(name,...)
AdvancedFilter(bool enabled)
#define ROS_DEBUG_STREAM_NAMED(name, args)
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
Base-class for filters. Filters allow full user-defined control over whether or not a message should ...
#define DEFINE_LEVEL_TESTS(name, macro_base, level, log4cxx_level)
#define ROS_ERROR_STREAM_NAMED(name, args)
Parameter structure passed to FilterBase::isEnabled(...);. Includes both input and output parameters...
#define ROS_WARN_NAMED(name,...)
const char * message
[input] The formatted message that will be output
#define ROS_INFO_STREAM_NAMED(name, args)
#define ROSCONSOLE_AUTOINIT
Initializes the rosconsole library. Usually unnecessary to call directly.
virtual void append(const log4cxx::spi::LoggingEventPtr &, log4cxx::helpers::Pool &)
#define ROS_LOG_DELAYED_THROTTLE(rate, level, name,...)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing...
ROSCONSOLE_DECL std::string formatToString(const char *fmt,...)
#define ROSCONSOLE_ROOT_LOGGER_NAME
std::string out_message
[output] If set, writes this message instead of the original
Level level
[input/output] Severity level. If changed, uses the new level
BasicFilter(bool enabled)
#define ROS_LOG_STREAM_ONCE(level, name, args)
Log to a given named logger at a given verbosity level, only the first time it is hit when enabled...
#define ROS_DEBUG_NAMED(name,...)
#define ROS_LOG_STREAM_THROTTLE(rate, level, name, args)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing...
#define ROS_FATAL_STREAM(args)
#define ROS_FATAL_STREAM_NAMED(name, args)
void delayedThrottleStreamFunc2()
const char * file
[input] File the message came from
std::vector< Info > V_Info
#define ROS_LOG_THROTTLE(rate, level, name,...)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing...
int main(int argc, char **argv)
const char * function
[input] Function the message came from
virtual bool requiresLayout() const
void delayedThrottleFunc2()
virtual bool requiresLayout() const
void throttleStreamFunc()
#define ROS_WARN_STREAM(args)
BasicFilter g_filter(true)
#define ROS_DEBUG_STREAM(args)
void delayedThrottleFunc()
virtual void append(const log4cxx::spi::LoggingEventPtr &event, log4cxx::helpers::Pool &)
virtual bool isEnabled(ros::console::FilterParams ¶ms)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
#define ROS_LOG(level, name,...)
Log to a given named logger at a given verbosity level, with printf-style formatting.
#define ROS_INFO_STREAM(args)
void delayedThrottleStreamFunc()
#define ROS_LOG_FILTER(filter, level, name,...)
Log to a given named logger at a given verbosity level, with user-defined filtering, with printf-style formatting.
#define ROS_FATAL_NAMED(name,...)
int line
[input] Line the message came from
#define ROS_LOG_STREAM_DELAYED_THROTTLE(rate, level, name, args)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing and po...
#define ROS_ERROR_NAMED(name,...)
#define ROS_LOG_STREAM_FILTER(filter, level, name, args)
Log to a given named logger at a given verbosity level, with user-defined filtering, with stream-style formatting.
#define ROS_LOG_ONCE(level, name,...)
Log to a given named logger at a given verbosity level, only the first time it is hit when enabled...
#define ROS_ERROR_STREAM(args)
TEST(RosConsole, loggingLevels)
virtual bool isEnabled(ros::console::FilterParams ¶ms)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
#define ROSCONSOLE_DEFAULT_NAME
ROSCONSOLE_DECL void formatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt,...)
#define ROS_WARN_STREAM_NAMED(name, args)