00001
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SystemLoggerTests_cpp
00024 #define SystemLoggerTests_cpp
00025
00026 #include <cppunit/ui/text/TestRunner.h>
00027 #include <cppunit/TextOutputter.h>
00028 #include <cppunit/extensions/TestFactoryRegistry.h>
00029 #include <cppunit/extensions/HelperMacros.h>
00030 #include <cppunit/TestAssert.h>
00031
00032 #include <coil/Task.h>
00033 #include <coil/DynamicLib.h>
00034
00035 #include <rtm/SystemLogger.h>
00036 #include <coil/TimeMeasure.h>
00037 #include <rtm/Manager.h>
00038
00043 namespace Tests
00044 {
00045
00046 class LoggerMock : public RTC::Logger
00047 {
00048 public:
00049
00050 LoggerMock(RTC::LogStreamBuf* streambuf)
00051 : RTC::Logger(streambuf) {}
00052 virtual ~LoggerMock(void) {}
00053
00054
00055 void setDateFormat(const char* format)
00056 {
00057
00058 RTC::Logger::setDateFormat(format);
00059 mock_m_dateFormat = std::string(format);
00060
00061 }
00062
00063 void setName(const char* name)
00064 {
00065
00066 RTC::Logger::setName(name);
00067 mock_m_name = name;
00068
00069 }
00070
00071 void header(int level)
00072 {
00073
00074 RTC::Logger::header(level);
00075
00076 }
00077
00078 std::string getDate(void)
00079 {
00080
00081 return RTC::Logger::getDate();
00082 }
00083
00084 int strToLevel(const char* level)
00085 {
00086
00087 return RTC::Logger::strToLevel(level);
00088 }
00089
00090
00091 std::string test_string(void)
00092 {
00093
00094 this->lock();
00095 this->level(RTC::Logger::RTL_TRACE) << "RTC_TRACE2 test_string()" << std::endl;
00096 this->unlock();
00097
00098 return std::string("TestString");
00099 }
00100
00101 std::string mock_m_name;
00102 std::string mock_m_dateFormat;
00103 };
00104
00105
00111 class SystemLoggerTests
00112 : public CppUnit::TestFixture
00113 {
00114 CPPUNIT_TEST_SUITE(SystemLoggerTests);
00115
00116 CPPUNIT_TEST(test_setLevel);
00117 CPPUNIT_TEST(test_setDateFormat);
00118 CPPUNIT_TEST(test_setName);
00119 CPPUNIT_TEST(test_header);
00120 CPPUNIT_TEST(test_getDate);
00121 CPPUNIT_TEST(test_strToLevel);
00122 CPPUNIT_TEST(test_logfile_PARANOID);
00123 CPPUNIT_TEST(test_logfile_VERBOSE);
00124 CPPUNIT_TEST(test_logfile_TRACE);
00125 CPPUNIT_TEST(test_logfile_DEBUG);
00126 CPPUNIT_TEST(test_logfile_INFO);
00127 CPPUNIT_TEST(test_logfile_WARNING);
00128 CPPUNIT_TEST(test_logfile_ERROR);
00129 CPPUNIT_TEST(test_logfile_FATAL);
00130 CPPUNIT_TEST(test_logfile_SILENT);
00131 CPPUNIT_TEST(test_constract_name);
00132 CPPUNIT_TEST(test_deadlock);
00133
00134 CPPUNIT_TEST_SUITE_END();
00135
00136 private:
00137
00138 protected:
00139
00140 public:
00144 SystemLoggerTests()
00145 {
00146 }
00147
00151 virtual ~SystemLoggerTests()
00152 {
00153 }
00154
00158 virtual void setUp()
00159 {
00160 }
00161
00162
00166 virtual void tearDown()
00167 {
00168 }
00169
00175 void test_setLevel(void)
00176 {
00177
00178 coil::LogStreamBuffer logger;
00179 std::stringstream s0;
00180
00181 logger.addStream(s0.rdbuf());
00182 LoggerMock rtclog(&logger);
00183
00184
00185 CPPUNIT_ASSERT(rtclog.setLevel("SILENT"));
00186 CPPUNIT_ASSERT(rtclog.setLevel("FATAL"));
00187 CPPUNIT_ASSERT(rtclog.setLevel("ERROR"));
00188 CPPUNIT_ASSERT(rtclog.setLevel("WARN"));
00189 CPPUNIT_ASSERT(rtclog.setLevel("INFO"));
00190 CPPUNIT_ASSERT(rtclog.setLevel("DEBUG"));
00191 CPPUNIT_ASSERT(rtclog.setLevel("TRACE"));
00192 CPPUNIT_ASSERT(rtclog.setLevel("VERBOSE"));
00193 CPPUNIT_ASSERT(rtclog.setLevel("PARANOID"));
00194 CPPUNIT_ASSERT(rtclog.setLevel("other"));
00195
00196 }
00197
00203 void test_setDateFormat(void)
00204 {
00205
00206 coil::LogStreamBuffer logger;
00207 std::stringstream s0;
00208 std::string rstr;
00209
00210 logger.addStream(s0.rdbuf());
00211 LoggerMock rtclog(&logger);
00212
00213
00214 rtclog.setDateFormat("");
00215 rstr = rtclog.getDate();
00216 CPPUNIT_ASSERT(rstr.size() == 0);
00217 CPPUNIT_ASSERT_EQUAL(std::string(""), rtclog.mock_m_dateFormat);
00218
00219 rtclog.setDateFormat("%b %d %H:%M:%S");
00220 rstr = rtclog.getDate();
00221 CPPUNIT_ASSERT(rstr.size() > 0);
00222 CPPUNIT_ASSERT_EQUAL(std::string("%b %d %H:%M:%S"), rtclog.mock_m_dateFormat);
00223
00224 }
00225
00231 void test_setName(void)
00232 {
00233
00234 coil::LogStreamBuffer logger;
00235 std::stringstream s0;
00236
00237 logger.addStream(s0.rdbuf());
00238 LoggerMock rtclog(&logger);
00239 rtclog.setDateFormat("");
00240
00241 rtclog.setName("");
00242 rtclog.header(rtclog.RTL_DEBUG);
00243 CPPUNIT_ASSERT_EQUAL(std::string(""), rtclog.mock_m_name);
00244 CPPUNIT_ASSERT_EQUAL(std::string(" DEBUG: : "), s0.str());
00245
00246 s0.str("");
00247 rtclog.setName("TestName");
00248 rtclog.header(rtclog.RTL_DEBUG);
00249 CPPUNIT_ASSERT_EQUAL(std::string("TestName"), rtclog.mock_m_name);
00250 CPPUNIT_ASSERT_EQUAL(std::string(" DEBUG: TestName: "), s0.str());
00251
00252 }
00253
00259 void test_header(void)
00260 {
00261
00262 coil::LogStreamBuffer logger;
00263 std::stringstream s0;
00264
00265 logger.addStream(s0.rdbuf());
00266 LoggerMock rtclog(&logger);
00267
00268
00269 rtclog.setDateFormat("");
00270 rtclog.setName("");
00271 rtclog.header(rtclog.RTL_SILENT);
00272 CPPUNIT_ASSERT_EQUAL(std::string(" SILENT: : "), s0.str());
00273 s0.str("");
00274 rtclog.header(rtclog.RTL_FATAL);
00275 CPPUNIT_ASSERT_EQUAL(std::string(" FATAL: : "), s0.str());
00276 s0.str("");
00277 rtclog.header(rtclog.RTL_ERROR);
00278 CPPUNIT_ASSERT_EQUAL(std::string(" ERROR: : "), s0.str());
00279 s0.str("");
00280 rtclog.header(rtclog.RTL_WARN);
00281 CPPUNIT_ASSERT_EQUAL(std::string(" WARNING: : "), s0.str());
00282 s0.str("");
00283 rtclog.header(rtclog.RTL_INFO);
00284 CPPUNIT_ASSERT_EQUAL(std::string(" INFO: : "), s0.str());
00285 s0.str("");
00286 rtclog.header(rtclog.RTL_DEBUG);
00287 CPPUNIT_ASSERT_EQUAL(std::string(" DEBUG: : "), s0.str());
00288 s0.str("");
00289 rtclog.header(rtclog.RTL_TRACE);
00290 CPPUNIT_ASSERT_EQUAL(std::string(" TRACE: : "), s0.str());
00291 s0.str("");
00292 rtclog.header(rtclog.RTL_VERBOSE);
00293 CPPUNIT_ASSERT_EQUAL(std::string(" VERBOSE: : "), s0.str());
00294 s0.str("");
00295 rtclog.header(rtclog.RTL_PARANOID);
00296 CPPUNIT_ASSERT_EQUAL(std::string(" PARANOID: : "), s0.str());
00297
00298 }
00299
00305 void test_getDate(void)
00306 {
00307
00308 coil::LogStreamBuffer logger;
00309 std::stringstream s0;
00310 std::string rstr;
00311
00312 logger.addStream(s0.rdbuf());
00313 LoggerMock rtclog(&logger);
00314
00315
00316 rtclog.setDateFormat("");
00317 rstr = rtclog.getDate();
00318 CPPUNIT_ASSERT(rstr.size() == 0);
00319
00320 rtclog.setDateFormat("%b %d %H:%M:%S");
00321 rstr = rtclog.getDate();
00322 CPPUNIT_ASSERT(rstr.size() > 0);
00323
00324 }
00325
00331 void test_strToLevel(void)
00332 {
00333
00334 coil::LogStreamBuffer logger;
00335 std::stringstream s0;
00336
00337 logger.addStream(s0.rdbuf());
00338 LoggerMock rtclog(&logger);
00339
00340
00341 CPPUNIT_ASSERT(rtclog.strToLevel("SILENT") == rtclog.RTL_SILENT);
00342 CPPUNIT_ASSERT(rtclog.strToLevel("FATAL") == rtclog.RTL_FATAL);
00343 CPPUNIT_ASSERT(rtclog.strToLevel("ERROR") == rtclog.RTL_ERROR);
00344 CPPUNIT_ASSERT(rtclog.strToLevel("WARN") == rtclog.RTL_WARN);
00345 CPPUNIT_ASSERT(rtclog.strToLevel("INFO") == rtclog.RTL_INFO);
00346 CPPUNIT_ASSERT(rtclog.strToLevel("DEBUG") == rtclog.RTL_DEBUG);
00347 CPPUNIT_ASSERT(rtclog.strToLevel("TRACE") == rtclog.RTL_TRACE);
00348 CPPUNIT_ASSERT(rtclog.strToLevel("VERBOSE") == rtclog.RTL_VERBOSE);
00349 CPPUNIT_ASSERT(rtclog.strToLevel("PARANOID") == rtclog.RTL_PARANOID);
00350 CPPUNIT_ASSERT(rtclog.strToLevel("other") == rtclog.RTL_SILENT);
00351
00352 }
00353
00359 void test_logfile_PARANOID(void)
00360 {
00361
00362 coil::LogStreamBuffer logger;
00363 std::string logfile("rtcPARANOID.log");
00364
00365 std::filebuf of;
00366 of.open(logfile.c_str(), std::ios::out);
00367 if (!of.is_open())
00368 {
00369 std::cerr << "Error: cannot open logfile: "
00370 << logfile << std::endl;
00371 }
00372 logger.addStream(&of, true);
00373
00374 RTC::Logger rtclog(&logger);
00375 rtclog.setName("Test");
00376 rtclog.setDateFormat("%b %d %H:%M:%S");
00377 rtclog.setLevel("PARANOID");
00378
00379
00380 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
00381 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
00382 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
00383 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
00384
00385 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
00386 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
00387 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
00388 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
00389
00390 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
00391 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
00392 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
00393 RTC_TRACE_STR("Macro RTL_TRACE tests str");
00394
00395 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
00396 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
00397 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
00398 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
00399
00400 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
00401 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
00402 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
00403 RTC_INFO_STR("Macro RTL_INFO tests str");
00404
00405 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
00406 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
00407 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
00408 RTC_WARN_STR("Macro RTL_WARN tests str");
00409
00410 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
00411 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
00412 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
00413 RTC_ERROR_STR("Macro RTL_ERROR tests str");
00414
00415 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
00416 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
00417 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
00418 RTC_FATAL_STR("Macro RTL_FATAL tests str");
00419
00420 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
00421 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
00422
00423 of.close();
00424
00425
00426 std::string rstr;
00427 std::ifstream ifs(logfile.c_str());
00428 ifs >> rstr;
00429 CPPUNIT_ASSERT(rstr.size() > 0);
00430 ifs >> rstr;
00431 ifs >> rstr;
00432 ifs >> rstr;
00433 CPPUNIT_ASSERT_EQUAL(std::string("PARANOID:"), rstr);
00434 ifs >> rstr;
00435 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
00436 ifs >> rstr;
00437 CPPUNIT_ASSERT_EQUAL(std::string("RTL_PARANOID"), rstr);
00438 ifs >> rstr;
00439 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
00440 ifs >> rstr;
00441 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
00442
00443
00444 }
00445
00451 void test_logfile_VERBOSE(void)
00452 {
00453
00454 coil::LogStreamBuffer logger;
00455 std::string logfile("rtcVERBOSE.log");
00456
00457 std::filebuf of;
00458 of.open(logfile.c_str(), std::ios::out);
00459 if (!of.is_open())
00460 {
00461 std::cerr << "Error: cannot open logfile: "
00462 << logfile << std::endl;
00463 }
00464 logger.addStream(&of, true);
00465
00466 RTC::Logger rtclog(&logger);
00467 rtclog.setName("Test");
00468 rtclog.setDateFormat("%b %d %H:%M:%S");
00469 rtclog.setLevel("VERBOSE");
00470
00471
00472 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
00473 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
00474 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
00475 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
00476
00477 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
00478 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
00479 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
00480 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
00481
00482 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
00483 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
00484 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
00485 RTC_TRACE_STR("Macro RTL_TRACE tests str");
00486
00487 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
00488 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
00489 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
00490 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
00491
00492 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
00493 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
00494 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
00495 RTC_INFO_STR("Macro RTL_INFO tests str");
00496
00497 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
00498 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
00499 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
00500 RTC_WARN_STR("Macro RTL_WARN tests str");
00501
00502 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
00503 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
00504 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
00505 RTC_ERROR_STR("Macro RTL_ERROR tests str");
00506
00507 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
00508 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
00509 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
00510 RTC_FATAL_STR("Macro RTL_FATAL tests str");
00511
00512 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
00513 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
00514
00515 of.close();
00516
00517
00518 std::string rstr;
00519 std::ifstream ifs(logfile.c_str());
00520 ifs >> rstr;
00521 CPPUNIT_ASSERT(rstr.size() > 0);
00522 ifs >> rstr;
00523 ifs >> rstr;
00524 ifs >> rstr;
00525 CPPUNIT_ASSERT_EQUAL(std::string("VERBOSE:"), rstr);
00526 ifs >> rstr;
00527 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
00528 ifs >> rstr;
00529 CPPUNIT_ASSERT_EQUAL(std::string("RTL_VERBOSE"), rstr);
00530 ifs >> rstr;
00531 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
00532 ifs >> rstr;
00533 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
00534
00535
00536 }
00537
00543 void test_logfile_TRACE(void)
00544 {
00545
00546 coil::LogStreamBuffer logger;
00547 std::string logfile("rtcTRACE.log");
00548
00549 std::filebuf of;
00550 of.open(logfile.c_str(), std::ios::out);
00551 if (!of.is_open())
00552 {
00553 std::cerr << "Error: cannot open logfile: "
00554 << logfile << std::endl;
00555 }
00556 logger.addStream(&of, true);
00557
00558 RTC::Logger rtclog(&logger);
00559 rtclog.setName("Test");
00560 rtclog.setDateFormat("%b %d %H:%M:%S");
00561 rtclog.setLevel("TRACE");
00562
00563
00564 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
00565 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
00566 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
00567 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
00568
00569 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
00570 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
00571 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
00572 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
00573
00574 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
00575 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
00576 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
00577 RTC_TRACE_STR("Macro RTL_TRACE tests str");
00578
00579 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
00580 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
00581 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
00582 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
00583
00584 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
00585 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
00586 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
00587 RTC_INFO_STR("Macro RTL_INFO tests str");
00588
00589 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
00590 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
00591 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
00592 RTC_WARN_STR("Macro RTL_WARN tests str");
00593
00594 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
00595 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
00596 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
00597 RTC_ERROR_STR("Macro RTL_ERROR tests str");
00598
00599 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
00600 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
00601 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
00602 RTC_FATAL_STR("Macro RTL_FATAL tests str");
00603
00604 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
00605 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
00606
00607 of.close();
00608
00609
00610 std::string rstr;
00611 std::ifstream ifs(logfile.c_str());
00612 ifs >> rstr;
00613 CPPUNIT_ASSERT(rstr.size() > 0);
00614 ifs >> rstr;
00615 ifs >> rstr;
00616 ifs >> rstr;
00617 CPPUNIT_ASSERT_EQUAL(std::string("TRACE:"), rstr);
00618 ifs >> rstr;
00619 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
00620 ifs >> rstr;
00621 CPPUNIT_ASSERT_EQUAL(std::string("RTL_TRACE"), rstr);
00622 ifs >> rstr;
00623 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
00624 ifs >> rstr;
00625 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
00626
00627
00628 }
00629
00635 void test_logfile_DEBUG(void)
00636 {
00637
00638 coil::LogStreamBuffer logger;
00639 std::string logfile("rtcDEBUG.log");
00640
00641 std::filebuf of;
00642 of.open(logfile.c_str(), std::ios::out);
00643 if (!of.is_open())
00644 {
00645 std::cerr << "Error: cannot open logfile: "
00646 << logfile << std::endl;
00647 }
00648 logger.addStream(&of, true);
00649
00650 RTC::Logger rtclog(&logger);
00651 rtclog.setName("Test");
00652 rtclog.setDateFormat("%b %d %H:%M:%S");
00653 rtclog.setLevel("DEBUG");
00654
00655
00656 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
00657 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
00658 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
00659 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
00660
00661 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
00662 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
00663 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
00664 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
00665
00666 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
00667 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
00668 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
00669 RTC_TRACE_STR("Macro RTL_TRACE tests str");
00670
00671 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
00672 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
00673 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
00674 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
00675
00676 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
00677 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
00678 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
00679 RTC_INFO_STR("Macro RTL_INFO tests str");
00680
00681 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
00682 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
00683 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
00684 RTC_WARN_STR("Macro RTL_WARN tests str");
00685
00686 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
00687 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
00688 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
00689 RTC_ERROR_STR("Macro RTL_ERROR tests str");
00690
00691 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
00692 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
00693 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
00694 RTC_FATAL_STR("Macro RTL_FATAL tests str");
00695
00696 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
00697 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
00698
00699 of.close();
00700
00701
00702 std::string rstr;
00703 std::ifstream ifs(logfile.c_str());
00704 ifs >> rstr;
00705 CPPUNIT_ASSERT(rstr.size() > 0);
00706 ifs >> rstr;
00707 ifs >> rstr;
00708 ifs >> rstr;
00709 CPPUNIT_ASSERT_EQUAL(std::string("DEBUG:"), rstr);
00710 ifs >> rstr;
00711 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
00712 ifs >> rstr;
00713 CPPUNIT_ASSERT_EQUAL(std::string("RTL_DEBUG"), rstr);
00714 ifs >> rstr;
00715 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
00716 ifs >> rstr;
00717 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
00718
00719
00720 }
00721
00727 void test_logfile_INFO(void)
00728 {
00729
00730 coil::LogStreamBuffer logger;
00731 std::string logfile("rtcINFO.log");
00732
00733 std::filebuf of;
00734 of.open(logfile.c_str(), std::ios::out);
00735 if (!of.is_open())
00736 {
00737 std::cerr << "Error: cannot open logfile: "
00738 << logfile << std::endl;
00739 }
00740 logger.addStream(&of, true);
00741
00742 RTC::Logger rtclog(&logger);
00743 rtclog.setName("Test");
00744 rtclog.setDateFormat("%b %d %H:%M:%S");
00745 rtclog.setLevel("INFO");
00746
00747
00748 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
00749 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
00750 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
00751 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
00752
00753 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
00754 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
00755 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
00756 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
00757
00758 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
00759 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
00760 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
00761 RTC_TRACE_STR("Macro RTL_TRACE tests str");
00762
00763 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
00764 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
00765 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
00766 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
00767
00768 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
00769 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
00770 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
00771 RTC_INFO_STR("Macro RTL_INFO tests str");
00772
00773 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
00774 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
00775 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
00776 RTC_WARN_STR("Macro RTL_WARN tests str");
00777
00778 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
00779 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
00780 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
00781 RTC_ERROR_STR("Macro RTL_ERROR tests str");
00782
00783 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
00784 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
00785 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
00786 RTC_FATAL_STR("Macro RTL_FATAL tests str");
00787
00788 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
00789 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
00790
00791 of.close();
00792
00793
00794 std::string rstr;
00795 std::ifstream ifs(logfile.c_str());
00796 ifs >> rstr;
00797 CPPUNIT_ASSERT(rstr.size() > 0);
00798 ifs >> rstr;
00799 ifs >> rstr;
00800 ifs >> rstr;
00801 CPPUNIT_ASSERT_EQUAL(std::string("INFO:"), rstr);
00802 ifs >> rstr;
00803 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
00804 ifs >> rstr;
00805 CPPUNIT_ASSERT_EQUAL(std::string("RTL_INFO"), rstr);
00806 ifs >> rstr;
00807 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
00808 ifs >> rstr;
00809 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
00810
00811
00812 }
00813
00819 void test_logfile_WARNING(void)
00820 {
00821
00822 coil::LogStreamBuffer logger;
00823 std::string logfile("rtcWARNING.log");
00824
00825 std::filebuf of;
00826 of.open(logfile.c_str(), std::ios::out);
00827 if (!of.is_open())
00828 {
00829 std::cerr << "Error: cannot open logfile: "
00830 << logfile << std::endl;
00831 }
00832 logger.addStream(&of, true);
00833
00834 RTC::Logger rtclog(&logger);
00835 rtclog.setName("Test");
00836 rtclog.setDateFormat("%b %d %H:%M:%S");
00837 rtclog.setLevel("WARN");
00838
00839
00840 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
00841 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
00842 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
00843 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
00844
00845 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
00846 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
00847 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
00848 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
00849
00850 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
00851 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
00852 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
00853 RTC_TRACE_STR("Macro RTL_TRACE tests str");
00854
00855 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
00856 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
00857 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
00858 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
00859
00860 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
00861 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
00862 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
00863 RTC_INFO_STR("Macro RTL_INFO tests str");
00864
00865 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
00866 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
00867 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
00868 RTC_WARN_STR("Macro RTL_WARN tests str");
00869
00870 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
00871 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
00872 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
00873 RTC_ERROR_STR("Macro RTL_ERROR tests str");
00874
00875 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
00876 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
00877 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
00878 RTC_FATAL_STR("Macro RTL_FATAL tests str");
00879
00880 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
00881 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
00882
00883 of.close();
00884
00885
00886 std::string rstr;
00887 std::ifstream ifs(logfile.c_str());
00888 ifs >> rstr;
00889 CPPUNIT_ASSERT(rstr.size() > 0);
00890 ifs >> rstr;
00891 ifs >> rstr;
00892 ifs >> rstr;
00893 CPPUNIT_ASSERT_EQUAL(std::string("WARNING:"), rstr);
00894 ifs >> rstr;
00895 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
00896 ifs >> rstr;
00897 CPPUNIT_ASSERT_EQUAL(std::string("RTL_WARN"), rstr);
00898 ifs >> rstr;
00899 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
00900 ifs >> rstr;
00901 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
00902
00903
00904 }
00905
00911 void test_logfile_ERROR(void)
00912 {
00913
00914 coil::LogStreamBuffer logger;
00915 std::string logfile("rtcERROR.log");
00916
00917 std::filebuf of;
00918 of.open(logfile.c_str(), std::ios::out);
00919 if (!of.is_open())
00920 {
00921 std::cerr << "Error: cannot open logfile: "
00922 << logfile << std::endl;
00923 }
00924 logger.addStream(&of, true);
00925
00926 RTC::Logger rtclog(&logger);
00927 rtclog.setName("Test");
00928 rtclog.setDateFormat("%b %d %H:%M:%S");
00929 rtclog.setLevel("ERROR");
00930
00931
00932 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
00933 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
00934 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
00935 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
00936
00937 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
00938 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
00939 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
00940 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
00941
00942 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
00943 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
00944 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
00945 RTC_TRACE_STR("Macro RTL_TRACE tests str");
00946
00947 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
00948 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
00949 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
00950 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
00951
00952 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
00953 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
00954 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
00955 RTC_INFO_STR("Macro RTL_INFO tests str");
00956
00957 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
00958 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
00959 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
00960 RTC_WARN_STR("Macro RTL_WARN tests str");
00961
00962 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
00963 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
00964 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
00965 RTC_ERROR_STR("Macro RTL_ERROR tests str");
00966
00967 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
00968 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
00969 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
00970 RTC_FATAL_STR("Macro RTL_FATAL tests str");
00971
00972 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
00973 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
00974
00975 of.close();
00976
00977
00978 std::string rstr;
00979 std::ifstream ifs(logfile.c_str());
00980 ifs >> rstr;
00981 CPPUNIT_ASSERT(rstr.size() > 0);
00982 ifs >> rstr;
00983 ifs >> rstr;
00984 ifs >> rstr;
00985 CPPUNIT_ASSERT_EQUAL(std::string("ERROR:"), rstr);
00986 ifs >> rstr;
00987 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
00988 ifs >> rstr;
00989 CPPUNIT_ASSERT_EQUAL(std::string("RTL_ERROR"), rstr);
00990 ifs >> rstr;
00991 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
00992 ifs >> rstr;
00993 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
00994
00995
00996 }
00997
01003 void test_logfile_FATAL(void)
01004 {
01005
01006 coil::LogStreamBuffer logger;
01007 std::string logfile("rtcFATAL.log");
01008
01009 std::filebuf of;
01010 of.open(logfile.c_str(), std::ios::out);
01011 if (!of.is_open())
01012 {
01013 std::cerr << "Error: cannot open logfile: "
01014 << logfile << std::endl;
01015 }
01016 logger.addStream(&of, true);
01017
01018 RTC::Logger rtclog(&logger);
01019 rtclog.setName("Test");
01020 rtclog.setDateFormat("%b %d %H:%M:%S");
01021 rtclog.setLevel("FATAL");
01022
01023
01024 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
01025 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
01026 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
01027 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
01028
01029 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
01030 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
01031 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
01032 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
01033
01034 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
01035 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
01036 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
01037 RTC_TRACE_STR("Macro RTL_TRACE tests str");
01038
01039 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
01040 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
01041 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
01042 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
01043
01044 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
01045 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
01046 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
01047 RTC_INFO_STR("Macro RTL_INFO tests str");
01048
01049 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
01050 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
01051 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
01052 RTC_WARN_STR("Macro RTL_WARN tests str");
01053
01054 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
01055 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
01056 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
01057 RTC_ERROR_STR("Macro RTL_ERROR tests str");
01058
01059 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
01060 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
01061 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
01062 RTC_FATAL_STR("Macro RTL_FATAL tests str");
01063
01064 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
01065 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
01066
01067 of.close();
01068
01069
01070 std::string rstr;
01071 std::ifstream ifs(logfile.c_str());
01072 ifs >> rstr;
01073 CPPUNIT_ASSERT(rstr.size() > 0);
01074 ifs >> rstr;
01075 ifs >> rstr;
01076 ifs >> rstr;
01077 CPPUNIT_ASSERT_EQUAL(std::string("FATAL:"), rstr);
01078 ifs >> rstr;
01079 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
01080 ifs >> rstr;
01081 CPPUNIT_ASSERT_EQUAL(std::string("RTL_FATAL"), rstr);
01082 ifs >> rstr;
01083 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
01084 ifs >> rstr;
01085 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
01086
01087
01088 }
01089
01095 void test_logfile_SILENT(void)
01096 {
01097
01098 coil::LogStreamBuffer logger;
01099 std::string logfile("rtcSILENT.log");
01100
01101 std::filebuf of;
01102 of.open(logfile.c_str(), std::ios::out);
01103 if (!of.is_open())
01104 {
01105 std::cerr << "Error: cannot open logfile: "
01106 << logfile << std::endl;
01107 }
01108 logger.addStream(&of, true);
01109
01110 RTC::Logger rtclog(&logger);
01111 rtclog.setName("Test");
01112 rtclog.setDateFormat("%b %d %H:%M:%S");
01113 rtclog.setLevel("SILENT");
01114
01115
01116 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
01117 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
01118 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
01119 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
01120
01121 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
01122 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
01123 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
01124 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
01125
01126 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
01127 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
01128 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
01129 RTC_TRACE_STR("Macro RTL_TRACE tests str");
01130
01131 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
01132 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
01133 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
01134 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
01135
01136 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
01137 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
01138 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
01139 RTC_INFO_STR("Macro RTL_INFO tests str");
01140
01141 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
01142 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
01143 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
01144 RTC_WARN_STR("Macro RTL_WARN tests str");
01145
01146 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
01147 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
01148 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
01149 RTC_ERROR_STR("Macro RTL_ERROR tests str");
01150
01151 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
01152 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
01153 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
01154 RTC_FATAL_STR("Macro RTL_FATAL tests str");
01155
01156 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
01157 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
01158
01159 of.close();
01160
01161
01162 std::string rstr;
01163 std::ifstream ifs(logfile.c_str());
01164 ifs >> rstr;
01165 CPPUNIT_ASSERT(rstr.size() > 0);
01166 ifs >> rstr;
01167 ifs >> rstr;
01168 ifs >> rstr;
01169 CPPUNIT_ASSERT_EQUAL(std::string("SILENT:"), rstr);
01170 ifs >> rstr;
01171 CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
01172 ifs >> rstr;
01173 CPPUNIT_ASSERT_EQUAL(std::string("RTL_SILENT"), rstr);
01174 ifs >> rstr;
01175 CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
01176 ifs >> rstr;
01177 CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);
01178
01179
01180 }
01181
01187 void test_constract_name(void)
01188 {
01189
01190 RTC::Manager* m_mgr;
01191 m_mgr = RTC::Manager::init(0, NULL);
01192 CPPUNIT_ASSERT(m_mgr != NULL);
01193
01194 RTC::Logger rtclog("TestName");
01195 std::string log_level = m_mgr->getLogLevel();
01196 CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level);
01197
01198 coil::Properties m_config = m_mgr->getConfig();
01199 std::vector<std::string> logouts = coil::split(m_config["logger.file_name"], ",");
01200
01201
01202 RTC_LOG( ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
01203 RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
01204 RTC_PARANOID( ("Macro RTL_PARANOID tests %s","fmt"));
01205 RTC_PARANOID_STR("Macro RTL_PARANOID tests str");
01206
01207 RTC_LOG( ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
01208 RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
01209 RTC_VERBOSE( ("Macro RTL_VERBOSE tests %s","fmt"));
01210 RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");
01211
01212 RTC_LOG( ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
01213 RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
01214 RTC_TRACE( ("Macro RTL_TRACE tests %s","fmt"));
01215 RTC_TRACE_STR("Macro RTL_TRACE tests str");
01216
01217 RTC_LOG( ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
01218 RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
01219 RTC_DEBUG( ("Macro RTL_DEBUG tests %s","fmt"));
01220 RTC_DEBUG_STR("Macro RTL_DEBUG tests str");
01221
01222 RTC_LOG( ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
01223 RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
01224 RTC_INFO( ("Macro RTL_INFO tests %s","fmt"));
01225 RTC_INFO_STR("Macro RTL_INFO tests str");
01226
01227 RTC_LOG( ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
01228 RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
01229 RTC_WARN( ("Macro RTL_WARN tests %s","fmt"));
01230 RTC_WARN_STR("Macro RTL_WARN tests str");
01231
01232 RTC_LOG( ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
01233 RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
01234 RTC_ERROR( ("Macro RTL_ERROR tests %s","fmt"));
01235 RTC_ERROR_STR("Macro RTL_ERROR tests str");
01236
01237 RTC_LOG( ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
01238 RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
01239 RTC_FATAL( ("Macro RTL_FATAL tests %s","fmt"));
01240 RTC_FATAL_STR("Macro RTL_FATAL tests str");
01241
01242 RTC_LOG( ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
01243 RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");
01244
01245 m_mgr->terminate();
01246
01247
01248
01249
01250
01251 std::string rstr;
01252 std::vector<std::string> vstr;
01253 bool bret;
01254 std::ifstream ifs(logouts[0].c_str());
01255 while(getline(ifs, rstr))
01256 {
01257 if(rstr.size() == 0) break;
01258 vstr = coil::split(rstr, " ");
01259
01260 bret = false;
01261 if( (vstr[3] == "INFO:") || (vstr[3] == "WARNING:") || (vstr[3] == "ERROR:") ||
01262 (vstr[3] == "FATAL:") || (vstr[3] == "SILENT:") )
01263 bret = true;
01264 CPPUNIT_ASSERT(bret);
01265
01266
01267 bret = false;
01268 if( (vstr[4] == "manager:") || (vstr[4] == "TestName:") ||
01269 (vstr[4] == "NamingOnCorba:") || (vstr[4] == "NamingManager:") ||
01270 (vstr[4] == "ManagerServant:") )
01271 bret = true;
01272 CPPUNIT_ASSERT(bret);
01273 }
01274
01275 }
01276
01282 void test_deadlock(void)
01283 {
01284
01285 coil::LogStreamBuffer logger;
01286 std::stringstream s0;
01287
01288 logger.addStream(s0.rdbuf());
01289 LoggerMock rtclog(&logger);
01290 rtclog.setName("Test");
01291 rtclog.setDateFormat("");
01292 rtclog.setLevel("TRACE");
01293 s0.str("");
01294
01295 rtclog.enableLock();
01296 RTC_TRACE(("RTC_TRACE1 %s", rtclog.test_string().c_str()));
01297
01298 std::string rstr;
01299 getline(s0, rstr);
01300 CPPUNIT_ASSERT_EQUAL(std::string(" TRACE: Test: RTC_TRACE2 test_string()"), rstr);
01301 getline(s0, rstr);
01302 CPPUNIT_ASSERT_EQUAL(std::string(" TRACE: Test: RTC_TRACE1 TestString"), rstr);
01303
01304
01305 rtclog.disableLock();
01306
01307 }
01308
01309 };
01310 };
01311
01312
01313
01314
01315 CPPUNIT_TEST_SUITE_REGISTRATION(Tests::SystemLoggerTests);
01316
01317 #ifdef LOCAL_MAIN
01318 int main(int argc, char* argv[])
01319 {
01320
01321 FORMAT format = TEXT_OUT;
01322 int target = 0;
01323 std::string xsl;
01324 std::string ns;
01325 std::string fname;
01326 std::ofstream ofs;
01327
01328 int i(1);
01329 while (i < argc)
01330 {
01331 std::string arg(argv[i]);
01332 std::string next_arg;
01333 if (i + 1 < argc) next_arg = argv[i + 1];
01334 else next_arg = "";
01335
01336 if (arg == "--text") { format = TEXT_OUT; break; }
01337 if (arg == "--xml")
01338 {
01339 if (next_arg == "")
01340 {
01341 fname = argv[0];
01342 fname += ".xml";
01343 }
01344 else
01345 {
01346 fname = next_arg;
01347 }
01348 format = XML_OUT;
01349 ofs.open(fname.c_str());
01350 }
01351 if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
01352 if ( arg == "--cerr" ) { target = 1; break; }
01353 if ( arg == "--xsl" )
01354 {
01355 if (next_arg == "") xsl = "default.xsl";
01356 else xsl = next_arg;
01357 }
01358 if ( arg == "--namespace" )
01359 {
01360 if (next_arg == "")
01361 {
01362 std::cerr << "no namespace specified" << std::endl;
01363 exit(1);
01364 }
01365 else
01366 {
01367 xsl = next_arg;
01368 }
01369 }
01370 ++i;
01371 }
01372 CppUnit::TextUi::TestRunner runner;
01373 if ( ns.empty() )
01374 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
01375 else
01376 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
01377 CppUnit::Outputter* outputter = 0;
01378 std::ostream* stream = target ? &std::cerr : &std::cout;
01379 switch ( format )
01380 {
01381 case TEXT_OUT :
01382 outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
01383 break;
01384 case XML_OUT :
01385 std::cout << "XML_OUT" << std::endl;
01386 outputter = new CppUnit::XmlOutputter(&runner.result(),
01387 ofs, "shift_jis");
01388 static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
01389 break;
01390 case COMPILER_OUT :
01391 outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
01392 break;
01393 }
01394 runner.setOutputter(outputter);
01395 runner.run();
01396 return 0;
01397 }
01398 #endif // MAIN
01399 #endif // SystemLoggerTests_cpp