Skip to content

Commit 91ea781

Browse files
committed
Fix configuration change logger
Write out test results of unit tests
1 parent 33b8cc0 commit 91ea781

File tree

10 files changed

+141
-11
lines changed

10 files changed

+141
-11
lines changed

examples/configuration/main.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ constexpr auto logMessage = "This is a log message";
5050
/**
5151
* @brief Function for log some messages.
5252
*/
53-
static void logSomeMessages() {
53+
static void logSomeMessages( vx::Logger *_logger ) {
5454

55-
LogFatal( logMessage );
56-
LogError( logMessage );
57-
LogWarning( logMessage );
58-
LogInfo( logMessage );
59-
LogDebug( logMessage );
60-
LogVerbose( logMessage );
55+
_logger->log( logMessage, vx::Severity::Fatal );
56+
_logger->log( logMessage, vx::Severity::Error );
57+
_logger->log( logMessage, vx::Severity::Warning );
58+
_logger->log( logMessage, vx::Severity::Info );
59+
_logger->log( logMessage, vx::Severity::Debug );
60+
_logger->log( logMessage, vx::Severity::Verbose );
6161
}
6262

6363
int main() {
6464

6565
/* configure logging, if you dont it defaults to standard out logging with colors */
6666
std::cout << "Log to std::cout" << std::endl;
67-
ConfigureLogger( { { "type", "std" }, { "color", "true" } } );
67+
std::unique_ptr<vx::Logger> stdLogger( vx::LoggerFactory::instance().produce( { { "type", "std" }, { "color", "true" } } ) );
6868

6969
/* Log some messages */
70-
logSomeMessages();
70+
logSomeMessages( stdLogger.get() );
7171

7272
/* create tmp file */
7373
std::filesystem::path tmpPath = std::filesystem::temp_directory_path();
@@ -77,10 +77,10 @@ int main() {
7777

7878
/* configure logging, if you dont it defaults to standard out logging with colors */
7979
std::cout << "Log to file" << std::endl;
80-
ConfigureLogger( { { "type", "file" }, { "filename", tmpFile }, { "reopen_interval", "1" } } );
80+
std::unique_ptr<vx::Logger> fileLogger( vx::LoggerFactory::instance().produce( { { "type", "file" }, { "filename", tmpFile }, { "reopen_interval", "1" } } ) );
8181

8282
/* Log some messages */
83-
logSomeMessages();
83+
logSomeMessages( fileLogger.get() );
8484

8585
/* remove tmp file */
8686
if ( !std::filesystem::remove( tmpFile ) ) {

tests/simple/SimpleFileLogger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/XmlOutputter.h>
4142
#include <cppunit/extensions/HelperMacros.h>
4243
#include <cppunit/ui/text/TestRunner.h>
4344
#ifdef __GNUC__
@@ -141,5 +142,18 @@ int main() {
141142
CppUnit::TextUi::TestRunner runner;
142143
runner.addTest( vx::SimpleFileLogger::suite() );
143144
bool wasSuccessful = runner.run();
145+
146+
std::ofstream xmlFileOut( "../SimpleFileLogger.xml" );
147+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
148+
xmlOut.write();
149+
try {
150+
151+
xmlFileOut.close();
152+
}
153+
catch ( [[maybe_unused]] const std::exception &_exception ) {
154+
155+
/* Do not throw exception here */
156+
}
157+
144158
return wasSuccessful ? 0 : 1;
145159
}

tests/simple/SimpleNullLogger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/XmlOutputter.h>
4142
#include <cppunit/extensions/HelperMacros.h>
4243
#include <cppunit/ui/text/TestRunner.h>
4344
#ifdef __GNUC__
@@ -113,5 +114,18 @@ int main() {
113114
CppUnit::TextUi::TestRunner runner;
114115
runner.addTest( vx::SimpleNullLogger::suite() );
115116
bool wasSuccessful = runner.run();
117+
118+
std::ofstream xmlFileOut( "../SimpleNullLogger.xml" );
119+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
120+
xmlOut.write();
121+
try {
122+
123+
xmlFileOut.close();
124+
}
125+
catch ( [[maybe_unused]] const std::exception &_exception ) {
126+
127+
/* Do not throw exception here */
128+
}
129+
116130
return wasSuccessful ? 0 : 1;
117131
}

tests/simple/SimpleStdLogger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/XmlOutputter.h>
4142
#include <cppunit/extensions/HelperMacros.h>
4243
#include <cppunit/ui/text/TestRunner.h>
4344
#ifdef __GNUC__
@@ -113,5 +114,18 @@ int main() {
113114
CppUnit::TextUi::TestRunner runner;
114115
runner.addTest( vx::SimpleStdLogger::suite() );
115116
bool wasSuccessful = runner.run();
117+
118+
std::ofstream xmlFileOut( "../SimpleStdLogger.xml" );
119+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
120+
xmlOut.write();
121+
try {
122+
123+
xmlFileOut.close();
124+
}
125+
catch ( [[maybe_unused]] const std::exception &_exception ) {
126+
127+
/* Do not throw exception here */
128+
}
129+
116130
return wasSuccessful ? 0 : 1;
117131
}

tests/simple/SimpleXmlLogger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/XmlOutputter.h>
4142
#include <cppunit/extensions/HelperMacros.h>
4243
#include <cppunit/ui/text/TestRunner.h>
4344
#ifdef __GNUC__
@@ -140,5 +141,18 @@ int main() {
140141
CppUnit::TextUi::TestRunner runner;
141142
runner.addTest( vx::SimpleXmlLogger::suite() );
142143
bool wasSuccessful = runner.run();
144+
145+
std::ofstream xmlFileOut( "../SimpleXmlLogger.xml" );
146+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
147+
xmlOut.write();
148+
try {
149+
150+
xmlFileOut.close();
151+
}
152+
catch ( [[maybe_unused]] const std::exception &_exception ) {
153+
154+
/* Do not throw exception here */
155+
}
156+
143157
return wasSuccessful ? 0 : 1;
144158
}

tests/template/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/TestResult.h>
42+
#include <cppunit/TestResultCollector.h>
43+
#include <cppunit/XmlOutputter.h>
4144
#include <cppunit/extensions/HelperMacros.h>
4245
#include <cppunit/ui/text/TestRunner.h>
4346
#ifdef __GNUC__
@@ -80,5 +83,18 @@ int main() {
8083
CppUnit::TextUi::TestRunner runner;
8184
runner.addTest( Test::suite() );
8285
bool wasSuccessful = runner.run();
86+
87+
std::ofstream xmlFileOut( "Test.xml" );
88+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
89+
xmlOut.write();
90+
try {
91+
92+
xmlFileOut.close();
93+
}
94+
catch ( [[maybe_unused]] const std::exception &_exception ) {
95+
96+
/* Do not throw exception here */
97+
}
98+
8399
return wasSuccessful ? 0 : 1;
84100
}

tests/threads/ThreadsFileLogger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/XmlOutputter.h>
4142
#include <cppunit/extensions/HelperMacros.h>
4243
#include <cppunit/ui/text/TestRunner.h>
4344
#ifdef __GNUC__
@@ -157,5 +158,18 @@ int main() {
157158
CppUnit::TextUi::TestRunner runner;
158159
runner.addTest( vx::ThreadsFileLogger::suite() );
159160
bool wasSuccessful = runner.run();
161+
162+
std::ofstream xmlFileOut( "../ThreadsFileLogger.xml" );
163+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
164+
xmlOut.write();
165+
try {
166+
167+
xmlFileOut.close();
168+
}
169+
catch ( [[maybe_unused]] const std::exception &_exception ) {
170+
171+
/* Do not throw exception here */
172+
}
173+
160174
return wasSuccessful ? 0 : 1;
161175
}

tests/threads/ThreadsNullLogger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/XmlOutputter.h>
4142
#include <cppunit/extensions/HelperMacros.h>
4243
#include <cppunit/ui/text/TestRunner.h>
4344
#ifdef __GNUC__
@@ -131,5 +132,18 @@ int main() {
131132
CppUnit::TextUi::TestRunner runner;
132133
runner.addTest( vx::ThreadsNullLogger::suite() );
133134
bool wasSuccessful = runner.run();
135+
136+
std::ofstream xmlFileOut( "../ThreadsNullLogger.xml" );
137+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
138+
xmlOut.write();
139+
try {
140+
141+
xmlFileOut.close();
142+
}
143+
catch ( [[maybe_unused]] const std::exception &_exception ) {
144+
145+
/* Do not throw exception here */
146+
}
147+
134148
return wasSuccessful ? 0 : 1;
135149
}

tests/threads/ThreadsStdLogger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/XmlOutputter.h>
4142
#include <cppunit/extensions/HelperMacros.h>
4243
#include <cppunit/ui/text/TestRunner.h>
4344
#ifdef __GNUC__
@@ -131,5 +132,18 @@ int main() {
131132
CppUnit::TextUi::TestRunner runner;
132133
runner.addTest( vx::ThreadsStdLogger::suite() );
133134
bool wasSuccessful = runner.run();
135+
136+
std::ofstream xmlFileOut( "../ThreadsStdLogger.xml" );
137+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
138+
xmlOut.write();
139+
try {
140+
141+
xmlFileOut.close();
142+
}
143+
catch ( [[maybe_unused]] const std::exception &_exception ) {
144+
145+
/* Do not throw exception here */
146+
}
147+
134148
return wasSuccessful ? 0 : 1;
135149
}

tests/threads/ThreadsXmlLogger.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#pragma GCC diagnostic ignored "-Weffc++"
3939
#endif
4040
#include <cppunit/TestCase.h>
41+
#include <cppunit/TestResult.h>
42+
#include <cppunit/TestResultCollector.h>
43+
#include <cppunit/XmlOutputter.h>
4144
#include <cppunit/extensions/HelperMacros.h>
4245
#include <cppunit/ui/text/TestRunner.h>
4346
#ifdef __GNUC__
@@ -156,5 +159,18 @@ int main() {
156159
CppUnit::TextUi::TestRunner runner;
157160
runner.addTest( vx::ThreadsXmlLogger::suite() );
158161
bool wasSuccessful = runner.run();
162+
163+
std::ofstream xmlFileOut( "../ThreadsXmlLogger.xml" );
164+
CppUnit::XmlOutputter xmlOut( &runner.result(), xmlFileOut );
165+
xmlOut.write();
166+
try {
167+
168+
xmlFileOut.close();
169+
}
170+
catch ( [[maybe_unused]] const std::exception &_exception ) {
171+
172+
/* Do not throw exception here */
173+
}
174+
159175
return wasSuccessful ? 0 : 1;
160176
}

0 commit comments

Comments
 (0)