Directory: | ./ |
---|---|
File: | tmp_project/PhoenixString/TESTS/TEST_PLOG/main.cpp |
Date: | 2024-07-27 10:53:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 124 | 124 | 100.0% |
Branches: | 279 | 279 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | /*************************************** | ||
3 | Auteur : Pierre Aubert | ||
4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
5 | Licence : CeCILL-C | ||
6 | ****************************************/ | ||
7 | |||
8 | #include <time.h> | ||
9 | #include <iostream> | ||
10 | #include "phoenix_assert.h" | ||
11 | #include "PLog.h" | ||
12 | |||
13 | ///Test the conversion of log level into string | ||
14 | 1 | void testLogLevelToString(){ | |
15 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 17 taken 1 times.
|
1 | phoenix_assert(phoenix_logLevelToStr(PLog::DEBUG) == "DEBUG"); |
16 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 17 taken 1 times.
|
1 | phoenix_assert(phoenix_logLevelToStr(PLog::INFO) == "INFO"); |
17 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 17 taken 1 times.
|
1 | phoenix_assert(phoenix_logLevelToStr(PLog::WARNING) == "WARNING"); |
18 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 17 taken 1 times.
|
1 | phoenix_assert(phoenix_logLevelToStr(PLog::ERROR) == "ERROR"); |
19 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 17 taken 1 times.
|
1 | phoenix_assert(phoenix_logLevelToStr(PLog::CRITICAL) == "CRITICAL"); |
20 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 17 taken 1 times.
|
1 | phoenix_assert(phoenix_logLevelToStr(PLog::ALWAYS) == "ALWAYS"); |
21 | 1 | } | |
22 | |||
23 | ///Test the conversion of string into log level | ||
24 | 1 | void testStringToLogLevel(){ | |
25 |
6/6✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
|
1 | phoenix_assert(phoenix_strToLogLevel("DEBUG") == PLog::DEBUG); |
26 |
6/6✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
|
1 | phoenix_assert(phoenix_strToLogLevel("INFO") == PLog::INFO); |
27 |
6/6✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
|
1 | phoenix_assert(phoenix_strToLogLevel("WARNING") == PLog::WARNING); |
28 |
6/6✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
|
1 | phoenix_assert(phoenix_strToLogLevel("ERROR") == PLog::ERROR); |
29 |
6/6✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
|
1 | phoenix_assert(phoenix_strToLogLevel("CRITICAL") == PLog::CRITICAL); |
30 |
6/6✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
|
1 | phoenix_assert(phoenix_strToLogLevel("ALWAYS") == PLog::ALWAYS); |
31 | 1 | } | |
32 | |||
33 | ///Test the PLog | ||
34 | 1 | void testStringPLog(){ | |
35 |
1/1✓ Branch 1 taken 1 times.
|
1 | PLog log; |
36 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | log.setFileName("logFile.log"); |
37 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.setThreadIndex(2lu); |
38 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(log.open()); |
39 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(log.getThreadIndex() == 2lu); |
40 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 17 taken 1 times.
|
1 | phoenix_assert(log.getFileName() == "logFile.log"); |
41 | |||
42 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Some log entry" << std::endl; |
43 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Some other log entry" << std::endl; |
44 | 1 | } | |
45 | |||
46 | ///Test the PLog | ||
47 | 1 | void testStringPLogLevel(){ | |
48 |
1/1✓ Branch 1 taken 1 times.
|
1 | PLog log; |
49 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | log.setFileName("logLevelFile.log"); |
50 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.setLogLevel(PLog::INFO); |
51 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(log.open()); |
52 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 17 taken 1 times.
|
1 | phoenix_assert(log.getFileName() == "logLevelFile.log"); |
53 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog(PLog::DEBUG) << "Some debug log entry" << std::endl; |
54 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogDebug() << "Some other debug log entry" << std::endl; |
55 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog(PLog::INFO) << "Some info log entry" << std::endl; |
56 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Some other info log entry" << std::endl; |
57 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogInfo() << "Some other info log entry (again)" << std::endl; |
58 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog(PLog::WARNING) << "Some warning log entry" << std::endl; |
59 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogWarning() << "Some other warning log entry" << std::endl; |
60 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog(PLog::ERROR) << "Some error log entry" << std::endl; |
61 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogError() << "Some other error log entry" << std::endl; |
62 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog(PLog::CRITICAL) << "Some critical log entry" << std::endl; |
63 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogCritical() << "Some other critical log entry" << std::endl; |
64 | 1 | } | |
65 | |||
66 | ///Test the PLog | ||
67 | 1 | void testStringMultiPLog(){ | |
68 |
1/1✓ Branch 1 taken 1 times.
|
1 | PLog log; |
69 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | log.setFileName("logMultiFile.log"); //Always set the file name first |
70 | 1 | size_t nbThread(4lu); | |
71 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.resize(nbThread); //Then, set the number of threads |
72 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(log.open()); //Then, open all log file |
73 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Log of all threads" << std::endl; |
74 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for(size_t i(0lu); i < nbThread; ++i){ |
75 |
1/1✓ Branch 1 taken 4 times.
|
4 | PLog & subLog = log.getLog(i); |
76 |
5/5✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
|
4 | subLog.getLog() << " i = "<<i<<", Some log entry" << std::endl; |
77 |
5/5✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
|
4 | subLog.getLog() << " i = "<<i<<", Some other log entry" << std::endl; |
78 | } | ||
79 | 1 | } | |
80 | |||
81 | ///Test if the std::cout redirection is working | ||
82 | 1 | void testLogCoutDedirectInFile(){ | |
83 |
1/1✓ Branch 1 taken 1 times.
|
1 | PLog log; |
84 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | log.setFileName("logFileRedirectCoutCerr.log"); |
85 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.setMode(PLog::FILE_CAPTURE_STDOUT_STDERR); |
86 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(log.open()); |
87 | |||
88 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | std::cout << "Some redirected std::cout stuff" << std::endl; |
89 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | std::cerr << "Some redirected std::cerr stuff" << std::endl; |
90 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Some classic log" << std::endl; |
91 | |||
92 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.close(); //Stops the redirection |
93 | 1 | } | |
94 | |||
95 | ///Test if the std::cout redirection is working | ||
96 | 1 | void testLogStdoutOnly(){ | |
97 |
1/1✓ Branch 1 taken 1 times.
|
1 | PLog log; |
98 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | log.setFileName("logFileStdOutOnly.log"); |
99 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.setMode(PLog::STDOUT_ONLY); |
100 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(log.open()); |
101 | |||
102 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Some log message" << std::endl; |
103 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Some classic log" << std::endl; |
104 | |||
105 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.close(); //Stops the redirection |
106 | 1 | } | |
107 | |||
108 | ///Test if the std::cout redirection is working | ||
109 | 1 | void testLogDisable(){ | |
110 |
1/1✓ Branch 1 taken 1 times.
|
1 | PLog log; |
111 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | log.setFileName("logFileDisable.log"); |
112 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.setMode(PLog::DISABLE); |
113 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(log.open()); |
114 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Some log message" << std::endl; |
115 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLog() << "Some classic log" << std::endl; |
116 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.close(); //Stops the redirection |
117 | 1 | } | |
118 | |||
119 | ///Test if the STRING_ONLY log mode works | ||
120 | 1 | void testStringLogAppend(){ | |
121 |
1/1✓ Branch 1 taken 1 times.
|
1 | PLog log; |
122 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | log.setFileName("logFileStringAppend.log"); |
123 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.setMode(PLog::FILE_ONLY); |
124 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(log.open()); |
125 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogInfo() << "Let's test log append" << std::endl; |
126 | |||
127 |
1/1✓ Branch 1 taken 1 times.
|
1 | PLog logStr; |
128 |
1/1✓ Branch 1 taken 1 times.
|
1 | logStr.setThreadIndex(1lu); |
129 |
1/1✓ Branch 1 taken 1 times.
|
1 | logStr.setLogLevel(PLog::DEBUG); |
130 |
1/1✓ Branch 1 taken 1 times.
|
1 | logStr.setMode(PLog::STRING_ONLY); |
131 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(logStr.open()); |
132 | |||
133 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLog(PLog::DEBUG) << "Some debug log entry" << std::endl; |
134 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLogDebug() << "Some other debug log entry" << std::endl; |
135 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLog(PLog::INFO) << "Some info log entry" << std::endl; |
136 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLog() << "Some other info log entry" << std::endl; |
137 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLogInfo() << "Some other info log entry (again)" << std::endl; |
138 | |||
139 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogInfo() << "Some log info at the same time (should be before log append)" << std::endl; |
140 | |||
141 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLog(PLog::WARNING) << "Some warning log entry" << std::endl; |
142 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLogWarning() << "Some other warning log entry" << std::endl; |
143 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLog(PLog::ERROR) << "Some error log entry" << std::endl; |
144 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLogError() << "Some other error log entry" << std::endl; |
145 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLog(PLog::CRITICAL) << "Some critical log entry" << std::endl; |
146 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | logStr.getLogCritical() << "Some other critical log entry" << std::endl; |
147 | |||
148 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogInfo() << "Just before log append" << std::endl; |
149 | // logStr.close(); | ||
150 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | log.appendLog(logStr.getLogString()); |
151 |
1/1✓ Branch 1 taken 1 times.
|
1 | logStr.close(); |
152 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | log.getLogInfo() << "Just after log append" << std::endl; |
153 | |||
154 |
1/1✓ Branch 1 taken 1 times.
|
1 | log.close(); |
155 | 1 | } | |
156 | |||
157 | 1 | int main(int argc, char** argv){ | |
158 | 1 | testLogLevelToString(); | |
159 | 1 | testStringToLogLevel(); | |
160 | 1 | testStringPLog(); | |
161 | 1 | testStringPLogLevel(); | |
162 | 1 | testStringMultiPLog(); | |
163 | 1 | testLogCoutDedirectInFile(); | |
164 | 1 | testLogStdoutOnly(); | |
165 | 1 | testLogDisable(); | |
166 | 1 | testStringLogAppend(); | |
167 | 1 | return 0; | |
168 | } | ||
169 | |||
170 | |||
171 |