23 #ifndef SystemLoggerTests_cpp 24 #define SystemLoggerTests_cpp 26 #include <cppunit/ui/text/TestRunner.h> 27 #include <cppunit/TextOutputter.h> 28 #include <cppunit/extensions/TestFactoryRegistry.h> 29 #include <cppunit/extensions/HelperMacros.h> 30 #include <cppunit/TestAssert.h> 32 #include <coil/Task.h> 33 #include <coil/DynamicLib.h> 36 #include <coil/TimeMeasure.h> 98 return std::string(
"TestString");
112 :
public CppUnit::TestFixture
116 CPPUNIT_TEST(test_setLevel);
117 CPPUNIT_TEST(test_setDateFormat);
118 CPPUNIT_TEST(test_setName);
119 CPPUNIT_TEST(test_header);
120 CPPUNIT_TEST(test_getDate);
121 CPPUNIT_TEST(test_strToLevel);
122 CPPUNIT_TEST(test_logfile_PARANOID);
123 CPPUNIT_TEST(test_logfile_VERBOSE);
124 CPPUNIT_TEST(test_logfile_TRACE);
125 CPPUNIT_TEST(test_logfile_DEBUG);
126 CPPUNIT_TEST(test_logfile_INFO);
127 CPPUNIT_TEST(test_logfile_WARNING);
128 CPPUNIT_TEST(test_logfile_ERROR);
129 CPPUNIT_TEST(test_logfile_FATAL);
130 CPPUNIT_TEST(test_logfile_SILENT);
131 CPPUNIT_TEST(test_constract_name);
132 CPPUNIT_TEST(test_deadlock);
134 CPPUNIT_TEST_SUITE_END();
179 std::stringstream s0;
185 CPPUNIT_ASSERT(rtclog.
setLevel(
"SILENT"));
186 CPPUNIT_ASSERT(rtclog.
setLevel(
"FATAL"));
187 CPPUNIT_ASSERT(rtclog.
setLevel(
"ERROR"));
188 CPPUNIT_ASSERT(rtclog.
setLevel(
"WARN"));
189 CPPUNIT_ASSERT(rtclog.
setLevel(
"INFO"));
190 CPPUNIT_ASSERT(rtclog.
setLevel(
"DEBUG"));
191 CPPUNIT_ASSERT(rtclog.
setLevel(
"TRACE"));
192 CPPUNIT_ASSERT(rtclog.
setLevel(
"VERBOSE"));
193 CPPUNIT_ASSERT(rtclog.
setLevel(
"PARANOID"));
194 CPPUNIT_ASSERT(rtclog.
setLevel(
"other"));
207 std::stringstream s0;
216 CPPUNIT_ASSERT(rstr.size() == 0);
221 CPPUNIT_ASSERT(rstr.size() > 0);
235 std::stringstream s0;
243 CPPUNIT_ASSERT_EQUAL(std::string(
""), rtclog.
mock_m_name);
244 CPPUNIT_ASSERT_EQUAL(std::string(
" DEBUG: : "), s0.str());
249 CPPUNIT_ASSERT_EQUAL(std::string(
"TestName"), rtclog.
mock_m_name);
250 CPPUNIT_ASSERT_EQUAL(std::string(
" DEBUG: TestName: "), s0.str());
263 std::stringstream s0;
272 CPPUNIT_ASSERT_EQUAL(std::string(
" SILENT: : "), s0.str());
275 CPPUNIT_ASSERT_EQUAL(std::string(
" FATAL: : "), s0.str());
278 CPPUNIT_ASSERT_EQUAL(std::string(
" ERROR: : "), s0.str());
281 CPPUNIT_ASSERT_EQUAL(std::string(
" WARNING: : "), s0.str());
284 CPPUNIT_ASSERT_EQUAL(std::string(
" INFO: : "), s0.str());
287 CPPUNIT_ASSERT_EQUAL(std::string(
" DEBUG: : "), s0.str());
290 CPPUNIT_ASSERT_EQUAL(std::string(
" TRACE: : "), s0.str());
293 CPPUNIT_ASSERT_EQUAL(std::string(
" VERBOSE: : "), s0.str());
296 CPPUNIT_ASSERT_EQUAL(std::string(
" PARANOID: : "), s0.str());
309 std::stringstream s0;
318 CPPUNIT_ASSERT(rstr.size() == 0);
322 CPPUNIT_ASSERT(rstr.size() > 0);
335 std::stringstream s0;
363 std::string logfile(
"rtcPARANOID.log");
366 of.open(logfile.c_str(), std::ios::out);
369 std::cerr <<
"Error: cannot open logfile: " 370 << logfile << std::endl;
387 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
392 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
397 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
402 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
407 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
412 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
417 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
427 std::ifstream
ifs(logfile.c_str());
429 CPPUNIT_ASSERT(rstr.size() > 0);
433 CPPUNIT_ASSERT_EQUAL(std::string(
"PARANOID:"), rstr);
435 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
437 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_PARANOID"), rstr);
439 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
441 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
455 std::string logfile(
"rtcVERBOSE.log");
458 of.open(logfile.c_str(), std::ios::out);
461 std::cerr <<
"Error: cannot open logfile: " 462 << logfile << std::endl;
479 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
484 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
489 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
494 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
499 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
504 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
509 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
519 std::ifstream
ifs(logfile.c_str());
521 CPPUNIT_ASSERT(rstr.size() > 0);
525 CPPUNIT_ASSERT_EQUAL(std::string(
"VERBOSE:"), rstr);
527 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
529 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_VERBOSE"), rstr);
531 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
533 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
547 std::string logfile(
"rtcTRACE.log");
550 of.open(logfile.c_str(), std::ios::out);
553 std::cerr <<
"Error: cannot open logfile: " 554 << logfile << std::endl;
571 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
576 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
581 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
586 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
591 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
596 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
601 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
611 std::ifstream
ifs(logfile.c_str());
613 CPPUNIT_ASSERT(rstr.size() > 0);
617 CPPUNIT_ASSERT_EQUAL(std::string(
"TRACE:"), rstr);
619 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
621 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_TRACE"), rstr);
623 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
625 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
639 std::string logfile(
"rtcDEBUG.log");
642 of.open(logfile.c_str(), std::ios::out);
645 std::cerr <<
"Error: cannot open logfile: " 646 << logfile << std::endl;
663 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
668 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
673 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
678 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
683 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
688 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
693 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
703 std::ifstream
ifs(logfile.c_str());
705 CPPUNIT_ASSERT(rstr.size() > 0);
709 CPPUNIT_ASSERT_EQUAL(std::string(
"DEBUG:"), rstr);
711 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
713 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_DEBUG"), rstr);
715 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
717 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
731 std::string logfile(
"rtcINFO.log");
734 of.open(logfile.c_str(), std::ios::out);
737 std::cerr <<
"Error: cannot open logfile: " 738 << logfile << std::endl;
755 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
760 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
765 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
770 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
775 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
780 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
785 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
795 std::ifstream
ifs(logfile.c_str());
797 CPPUNIT_ASSERT(rstr.size() > 0);
801 CPPUNIT_ASSERT_EQUAL(std::string(
"INFO:"), rstr);
803 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
805 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_INFO"), rstr);
807 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
809 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
823 std::string logfile(
"rtcWARNING.log");
826 of.open(logfile.c_str(), std::ios::out);
829 std::cerr <<
"Error: cannot open logfile: " 830 << logfile << std::endl;
847 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
852 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
857 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
862 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
867 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
872 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
877 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
887 std::ifstream
ifs(logfile.c_str());
889 CPPUNIT_ASSERT(rstr.size() > 0);
893 CPPUNIT_ASSERT_EQUAL(std::string(
"WARNING:"), rstr);
895 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
897 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_WARN"), rstr);
899 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
901 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
915 std::string logfile(
"rtcERROR.log");
918 of.open(logfile.c_str(), std::ios::out);
921 std::cerr <<
"Error: cannot open logfile: " 922 << logfile << std::endl;
939 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
944 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
949 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
954 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
959 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
964 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
969 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
979 std::ifstream
ifs(logfile.c_str());
981 CPPUNIT_ASSERT(rstr.size() > 0);
985 CPPUNIT_ASSERT_EQUAL(std::string(
"ERROR:"), rstr);
987 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
989 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_ERROR"), rstr);
991 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
993 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
1007 std::string logfile(
"rtcFATAL.log");
1010 of.open(logfile.c_str(), std::ios::out);
1013 std::cerr <<
"Error: cannot open logfile: " 1014 << logfile << std::endl;
1031 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
1036 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
1041 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
1046 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
1051 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
1056 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
1061 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
1071 std::ifstream
ifs(logfile.c_str());
1073 CPPUNIT_ASSERT(rstr.size() > 0);
1077 CPPUNIT_ASSERT_EQUAL(std::string(
"FATAL:"), rstr);
1079 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
1081 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_FATAL"), rstr);
1083 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
1085 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
1099 std::string logfile(
"rtcSILENT.log");
1102 of.open(logfile.c_str(), std::ios::out);
1105 std::cerr <<
"Error: cannot open logfile: " 1106 << logfile << std::endl;
1123 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
1128 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
1133 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
1138 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
1143 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
1148 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
1153 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
1163 std::ifstream
ifs(logfile.c_str());
1165 CPPUNIT_ASSERT(rstr.size() > 0);
1169 CPPUNIT_ASSERT_EQUAL(std::string(
"SILENT:"), rstr);
1171 CPPUNIT_ASSERT_EQUAL(std::string(
"Test:"), rstr);
1173 CPPUNIT_ASSERT_EQUAL(std::string(
"RTL_SILENT"), rstr);
1175 CPPUNIT_ASSERT_EQUAL(std::string(
"tests"), rstr);
1177 CPPUNIT_ASSERT_EQUAL(std::string(
"fmt"), rstr);
1192 CPPUNIT_ASSERT(m_mgr != NULL);
1196 CPPUNIT_ASSERT_EQUAL(std::string(
"INFO"), log_level);
1199 std::vector<std::string> logouts =
coil::split(m_config[
"logger.file_name"],
",");
1209 RTC_VERBOSE( (
"Macro RTL_VERBOSE tests %s",
"fmt"));
1214 RTC_TRACE( (
"Macro RTL_TRACE tests %s",
"fmt"));
1219 RTC_DEBUG( (
"Macro RTL_DEBUG tests %s",
"fmt"));
1224 RTC_INFO( (
"Macro RTL_INFO tests %s",
"fmt"));
1229 RTC_WARN( (
"Macro RTL_WARN tests %s",
"fmt"));
1234 RTC_ERROR( (
"Macro RTL_ERROR tests %s",
"fmt"));
1239 RTC_FATAL( (
"Macro RTL_FATAL tests %s",
"fmt"));
1252 std::vector<std::string> vstr;
1254 std::ifstream
ifs(logouts[0].c_str());
1255 while(getline(ifs, rstr))
1257 if(rstr.size() == 0)
break;
1261 if( (vstr[3] ==
"INFO:") || (vstr[3] ==
"WARNING:") || (vstr[3] ==
"ERROR:") ||
1262 (vstr[3] ==
"FATAL:") || (vstr[3] ==
"SILENT:") )
1264 CPPUNIT_ASSERT(bret);
1268 if( (vstr[4] ==
"manager:") || (vstr[4] ==
"TestName:") ||
1269 (vstr[4] ==
"NamingOnCorba:") || (vstr[4] ==
"NamingManager:") ||
1270 (vstr[4] ==
"ManagerServant:") )
1272 CPPUNIT_ASSERT(bret);
1286 std::stringstream s0;
1300 CPPUNIT_ASSERT_EQUAL(std::string(
" TRACE: Test: RTC_TRACE2 test_string()"), rstr);
1302 CPPUNIT_ASSERT_EQUAL(std::string(
" TRACE: Test: RTC_TRACE1 TestString"), rstr);
1318 int main(
int argc,
char* argv[])
1331 std::string arg(argv[i]);
1332 std::string next_arg;
1333 if (i + 1 < argc) next_arg = argv[i + 1];
1336 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
1349 ofs.open(fname.c_str());
1351 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
1352 if ( arg ==
"--cerr" ) { target = 1;
break; }
1353 if ( arg ==
"--xsl" )
1355 if (next_arg ==
"") xsl =
"default.xsl";
1356 else xsl = next_arg;
1358 if ( arg ==
"--namespace" )
1362 std::cerr <<
"no namespace specified" << std::endl;
1372 CppUnit::TextUi::TestRunner runner;
1374 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1376 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1377 CppUnit::Outputter* outputter = 0;
1378 std::ostream* stream = target ? &std::cerr : &std::cout;
1382 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
1385 std::cout <<
"XML_OUT" << std::endl;
1386 outputter =
new CppUnit::XmlOutputter(&runner.result(),
1388 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
1391 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
1394 runner.setOutputter(outputter);
1399 #endif // SystemLoggerTests_cpp void setDateFormat(const char *format)
Set date/time format for adding the header.
std::string test_string(void)
#define RTC_ERROR(fmt)
Error log output macro.
int main(int argc, char **argv)
virtual void header(int level)
Message prefix appender function.
virtual void tearDown()
Test finalization.
void test_logfile_VERBOSE(void)
logfile出力のテスト
log_streambuf template class
#define RTC_ERROR_STR(str)
RT component logger class.
void test_logfile_WARNING(void)
logfile出力のテスト
void test_logfile_PARANOID(void)
logfile出力のテスト
void test_logfile_INFO(void)
logfile出力のテスト
std::string & getLogLevel()
Get the log level of the configuration.
void terminate()
Terminate manager.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
void test_logfile_FATAL(void)
logfile出力のテスト
void setName(const char *name)
Set suffix of date/time string of header.
void setDateFormat(const char *format)
#define RTC_VERBOSE_STR(str)
virtual ~LoggerMock(void)
#define RTC_INFO_STR(str)
int strToLevel(const char *level)
#define RTC_WARN(fmt)
Warning log output macro.
RTComponent manager class.
#define RTC_FATAL(fmt)
Error log output macro.
#define RTC_DEBUG_STR(str)
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
void addStream(streambuf_type *stream, bool cleanup=false)
Destructor.
coil::Properties & getConfig()
Get the manager configuration.
void test_logfile_DEBUG(void)
logfile出力のテスト
#define RTC_DEBUG(fmt)
Debug level log output macro.
void test_setName(void)
setName()メソッドのテスト
static Manager * init(int argc, char **argv)
Initialize manager.
#define RTC_LOG_STR(LV, str)
void test_setDateFormat(void)
setDateFormat()メソッドのテスト
CPPUNIT_TEST_SUITE_REGISTRATION(Tests::SystemLoggerTests)
#define RTC_WARN_STR(str)
void test_strToLevel(void)
strToLevel()メソッドのテスト
void enableLock()
Enable the lock mode.
virtual ~SystemLoggerTests()
Destructor.
std::string getDate(void)
void test_logfile_ERROR(void)
logfile出力のテスト
std::string mock_m_dateFormat
void test_logfile_SILENT(void)
logfile出力のテスト
void test_setLevel(void)
setLevel()メソッドのテスト
void header(int level)
Message prefix appender function.
virtual void setUp()
Test initialization.
bool setLevel(const char *level)
Set log level by string.
ostream_type & level(int level)
Acquire log stream.
Class represents a set of properties.
LoggerMock(RTC::LogStreamBuf *streambuf)
void setName(const char *name)
#define RTC_INFO(fmt)
Information level log output macro.
::OutPortBase::Logger logger
void lock()
Acquire log lock Acquire log lock when the lock mode is set.
void test_getDate(void)
getDate()メソッドのテスト
int strToLevel(const char *level)
Set the log level Set the log level corresponding to the given string.
void test_deadlock(void)
ログ出力のデッドロックテスト
void test_constract_name(void)
コンストラクタログレベルのテスト
void disableLock()
Disable the lock mode.
void unlock()
Release the log lock Release the log lock when the lock mode is set.
std::string getDate(void)
Get the current formatted date/time string Get the current datetime described by specified format...
#define RTC_FATAL_STR(str)
void test_logfile_TRACE(void)
logfile出力のテスト
#define RTC_VERBOSE(fmt)
Verbose level log output macro.
SystemLoggerTests()
Constructor.
#define RTC_TRACE_STR(str)
#define RTC_PARANOID_STR(str)
void test_header(void)
header()メソッドのテスト