PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
main.cpp File Reference
#include <time.h>
#include <iostream>
#include "phoenix_assert.h"
#include "PLog.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 
void testLogCoutDedirectInFile ()
 Test if the std::cout redirection is working. More...
 
void testLogDisable ()
 Test if the std::cout redirection is working. More...
 
void testLogLevelToString ()
 Test the conversion of log level into string. More...
 
void testLogStdoutOnly ()
 Test if the std::cout redirection is working. More...
 
void testStringLogAppend ()
 Test if the STRING_ONLY log mode works. More...
 
void testStringMultiPLog ()
 Test the PLog. More...
 
void testStringPLog ()
 Test the PLog. More...
 
void testStringPLogLevel ()
 Test the PLog. More...
 
void testStringToLogLevel ()
 Test the conversion of string into log level. More...
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

◆ testLogCoutDedirectInFile()

void testLogCoutDedirectInFile ( )

Test if the std::cout redirection is working.

Definition at line 82 of file main.cpp.

82  {
83  PLog log;
84  log.setFileName("logFileRedirectCoutCerr.log");
86  phoenix_assert(log.open());
87 
88  std::cout << "Some redirected std::cout stuff" << std::endl;
89  std::cerr << "Some redirected std::cerr stuff" << std::endl;
90  log.getLog() << "Some classic log" << std::endl;
91 
92  log.close(); //Stops the redirection
93 }

References PLog::close(), PLog::FILE_CAPTURE_STDOUT_STDERR, PLog::getLog(), PLog::open(), phoenix_assert, PLog::setFileName(), and PLog::setMode().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testLogDisable()

void testLogDisable ( )

Test if the std::cout redirection is working.

Definition at line 109 of file main.cpp.

109  {
110  PLog log;
111  log.setFileName("logFileDisable.log");
112  log.setMode(PLog::DISABLE);
113  phoenix_assert(log.open());
114  log.getLog() << "Some log message" << std::endl;
115  log.getLog() << "Some classic log" << std::endl;
116  log.close(); //Stops the redirection
117 }

References PLog::close(), PLog::DISABLE, PLog::getLog(), PLog::open(), phoenix_assert, PLog::setFileName(), and PLog::setMode().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testLogLevelToString()

void testLogLevelToString ( )

Test the conversion of log level into string.

Definition at line 14 of file main.cpp.

References PLog::ALWAYS, PLog::CRITICAL, PLog::DEBUG, PLog::ERROR, PLog::INFO, phoenix_assert, phoenix_logLevelToStr(), and PLog::WARNING.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testLogStdoutOnly()

void testLogStdoutOnly ( )

Test if the std::cout redirection is working.

Definition at line 96 of file main.cpp.

96  {
97  PLog log;
98  log.setFileName("logFileStdOutOnly.log");
100  phoenix_assert(log.open());
101 
102  log.getLog() << "Some log message" << std::endl;
103  log.getLog() << "Some classic log" << std::endl;
104 
105  log.close(); //Stops the redirection
106 }

References PLog::close(), PLog::getLog(), PLog::open(), phoenix_assert, PLog::setFileName(), PLog::setMode(), and PLog::STDOUT_ONLY.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testStringLogAppend()

void testStringLogAppend ( )

Test if the STRING_ONLY log mode works.

Definition at line 120 of file main.cpp.

120  {
121  PLog log;
122  log.setFileName("logFileStringAppend.log");
124  phoenix_assert(log.open());
125  log.getLogInfo() << "Let's test log append" << std::endl;
126 
127  PLog logStr;
128  logStr.setThreadIndex(1lu);
129  logStr.setLogLevel(PLog::DEBUG);
130  logStr.setMode(PLog::STRING_ONLY);
131  phoenix_assert(logStr.open());
132 
133  logStr.getLog(PLog::DEBUG) << "Some debug log entry" << std::endl;
134  logStr.getLogDebug() << "Some other debug log entry" << std::endl;
135  logStr.getLog(PLog::INFO) << "Some info log entry" << std::endl;
136  logStr.getLog() << "Some other info log entry" << std::endl;
137  logStr.getLogInfo() << "Some other info log entry (again)" << std::endl;
138 
139  log.getLogInfo() << "Some log info at the same time (should be before log append)" << std::endl;
140 
141  logStr.getLog(PLog::WARNING) << "Some warning log entry" << std::endl;
142  logStr.getLogWarning() << "Some other warning log entry" << std::endl;
143  logStr.getLog(PLog::ERROR) << "Some error log entry" << std::endl;
144  logStr.getLogError() << "Some other error log entry" << std::endl;
145  logStr.getLog(PLog::CRITICAL) << "Some critical log entry" << std::endl;
146  logStr.getLogCritical() << "Some other critical log entry" << std::endl;
147 
148  log.getLogInfo() << "Just before log append" << std::endl;
149 // logStr.close();
150  log.appendLog(logStr.getLogString());
151  logStr.close();
152  log.getLogInfo() << "Just after log append" << std::endl;
153 
154  log.close();
155 }

References PLog::appendLog(), PLog::close(), PLog::CRITICAL, PLog::DEBUG, PLog::ERROR, PLog::FILE_ONLY, PLog::getLog(), PLog::getLogCritical(), PLog::getLogDebug(), PLog::getLogError(), PLog::getLogInfo(), PLog::getLogString(), PLog::getLogWarning(), PLog::INFO, PLog::open(), phoenix_assert, PLog::setFileName(), PLog::setLogLevel(), PLog::setMode(), PLog::setThreadIndex(), PLog::STRING_ONLY, and PLog::WARNING.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testStringMultiPLog()

void testStringMultiPLog ( )

Test the PLog.

Definition at line 67 of file main.cpp.

67  {
68  PLog log;
69  log.setFileName("logMultiFile.log"); //Always set the file name first
70  size_t nbThread(4lu);
71  log.resize(nbThread); //Then, set the number of threads
72  phoenix_assert(log.open()); //Then, open all log file
73  log.getLog() << "Log of all threads" << std::endl;
74  for(size_t i(0lu); i < nbThread; ++i){
75  PLog & subLog = log.getLog(i);
76  subLog.getLog() << " i = "<<i<<", Some log entry" << std::endl;
77  subLog.getLog() << " i = "<<i<<", Some other log entry" << std::endl;
78  }
79 }

References PLog::getLog(), PLog::open(), phoenix_assert, PLog::resize(), and PLog::setFileName().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testStringPLog()

void testStringPLog ( )

Test the PLog.

Definition at line 34 of file main.cpp.

34  {
35  PLog log;
36  log.setFileName("logFile.log");
37  log.setThreadIndex(2lu);
38  phoenix_assert(log.open());
39  phoenix_assert(log.getThreadIndex() == 2lu);
40  phoenix_assert(log.getFileName() == "logFile.log");
41 
42  log.getLog() << "Some log entry" << std::endl;
43  log.getLog() << "Some other log entry" << std::endl;
44 }

References PLog::getFileName(), PLog::getLog(), PLog::getThreadIndex(), PLog::open(), phoenix_assert, PLog::setFileName(), and PLog::setThreadIndex().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testStringPLogLevel()

void testStringPLogLevel ( )

Test the PLog.

Definition at line 47 of file main.cpp.

47  {
48  PLog log;
49  log.setFileName("logLevelFile.log");
51  phoenix_assert(log.open());
52  phoenix_assert(log.getFileName() == "logLevelFile.log");
53  log.getLog(PLog::DEBUG) << "Some debug log entry" << std::endl;
54  log.getLogDebug() << "Some other debug log entry" << std::endl;
55  log.getLog(PLog::INFO) << "Some info log entry" << std::endl;
56  log.getLog() << "Some other info log entry" << std::endl;
57  log.getLogInfo() << "Some other info log entry (again)" << std::endl;
58  log.getLog(PLog::WARNING) << "Some warning log entry" << std::endl;
59  log.getLogWarning() << "Some other warning log entry" << std::endl;
60  log.getLog(PLog::ERROR) << "Some error log entry" << std::endl;
61  log.getLogError() << "Some other error log entry" << std::endl;
62  log.getLog(PLog::CRITICAL) << "Some critical log entry" << std::endl;
63  log.getLogCritical() << "Some other critical log entry" << std::endl;
64 }

References PLog::CRITICAL, PLog::DEBUG, PLog::ERROR, PLog::getFileName(), PLog::getLog(), PLog::getLogCritical(), PLog::getLogDebug(), PLog::getLogError(), PLog::getLogInfo(), PLog::getLogWarning(), PLog::INFO, PLog::open(), phoenix_assert, PLog::setFileName(), PLog::setLogLevel(), and PLog::WARNING.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testStringToLogLevel()

void testStringToLogLevel ( )

Test the conversion of string into log level.

Definition at line 24 of file main.cpp.

References PLog::ALWAYS, PLog::CRITICAL, PLog::DEBUG, PLog::ERROR, PLog::INFO, phoenix_assert, phoenix_strToLogLevel(), and PLog::WARNING.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:
PLog::setThreadIndex
void setThreadIndex(size_t threadIndex)
Set the thread index of the current PLog.
Definition: PLog.cpp:83
PLog::getLog
PLog & getLog(size_t threadIndex)
Get the PLog at given index.
Definition: PLog.cpp:177
PLog::getFileName
const std::string & getFileName() const
Get the filename of the current log.
Definition: PLog.cpp:254
PLog::WARNING
@ WARNING
Definition: PLog.h:33
PLog::STDOUT_ONLY
@ STDOUT_ONLY
Definition: PLog.h:25
PLog::CRITICAL
@ CRITICAL
Definition: PLog.h:35
testLogCoutDedirectInFile
void testLogCoutDedirectInFile()
Test if the std::cout redirection is working.
Definition: main.cpp:82
PLog::ERROR
@ ERROR
Definition: PLog.h:34
PLog::DEBUG
@ DEBUG
Definition: PLog.h:31
PLog::getLogError
std::ostream & getLogError()
Write error message into the PLog.
Definition: PLog.cpp:232
PLog::close
void close()
Close the current PLog and its children.
Definition: PLog.cpp:125
PLog::appendLog
void appendLog(std::stringstream &str)
Append the log (STRING_ONLY mode) into an other log.
Definition: PLog.cpp:170
PLog::getLogWarning
std::ostream & getLogWarning()
Write warning message into the PLog.
Definition: PLog.cpp:225
testStringToLogLevel
void testStringToLogLevel()
Test the conversion of string into log level.
Definition: main.cpp:24
PLog::setFileName
void setFileName(const std::string &fileName)
Set the output filename of the current PLog.
Definition: PLog.cpp:62
phoenix_logLevelToStr
std::string phoenix_logLevelToStr(PLog::Level logLevel)
Convert the log level into a string.
Definition: PLog.cpp:17
PLog::FILE_CAPTURE_STDOUT_STDERR
@ FILE_CAPTURE_STDOUT_STDERR
Definition: PLog.h:26
testLogLevelToString
void testLogLevelToString()
Test the conversion of log level into string.
Definition: main.cpp:14
PLog::setLogLevel
void setLogLevel(PLog::Level logLevel)
Set the log level of the current PLog.
Definition: PLog.cpp:76
PLog::getLogDebug
std::ostream & getLogDebug()
Write debug message into the PLog.
Definition: PLog.cpp:211
PLog::getLogInfo
std::ostream & getLogInfo()
Write info message into the PLog.
Definition: PLog.cpp:218
PLog::resize
void resize(size_t nbThread)
Resize the number of cihldren log file.
Definition: PLog.cpp:90
PLog::setMode
void setMode(PLog::Mode mode)
Set the mode of the current PLog.
Definition: PLog.cpp:69
PLog::open
bool open()
Open the current PLog and its children.
Definition: PLog.cpp:106
testStringPLogLevel
void testStringPLogLevel()
Test the PLog.
Definition: main.cpp:47
testStringMultiPLog
void testStringMultiPLog()
Test the PLog.
Definition: main.cpp:67
PLog::STRING_ONLY
@ STRING_ONLY
Definition: PLog.h:24
PLog::ALWAYS
@ ALWAYS
Definition: PLog.h:36
PLog::FILE_ONLY
@ FILE_ONLY
Definition: PLog.h:23
PLog::DISABLE
@ DISABLE
Definition: PLog.h:27
testStringLogAppend
void testStringLogAppend()
Test if the STRING_ONLY log mode works.
Definition: main.cpp:120
testLogDisable
void testLogDisable()
Test if the std::cout redirection is working.
Definition: main.cpp:109
phoenix_assert
#define phoenix_assert(isOk)
Definition: phoenix_assert.h:19
PLog::getLogString
std::stringstream & getLogString()
Get the log string.
Definition: PLog.cpp:191
PLog
Phoenix Logger.
Definition: PLog.h:19
testLogStdoutOnly
void testLogStdoutOnly()
Test if the std::cout redirection is working.
Definition: main.cpp:96
PLog::getLogCritical
std::ostream & getLogCritical()
Write critical message into the PLog.
Definition: PLog.cpp:239
testStringPLog
void testStringPLog()
Test the PLog.
Definition: main.cpp:34
PLog::getThreadIndex
size_t getThreadIndex() const
Get the thread index of the current PLog.
Definition: PLog.cpp:275
PLog::INFO
@ INFO
Definition: PLog.h:32
phoenix_strToLogLevel
PLog::Level phoenix_strToLogLevel(const std::string &str)
Convert a string into a log level.
Definition: PLog.cpp:38