GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/StringUtils/TESTS/TEST_PLOG/main.cpp Lines: 67 67 100.0 %
Date: 2023-10-11 10:52:07 Branches: 84 84 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 "PLog.h"
11
12
///Test the PLog
13
/**	@return true on success, false otherwise
14
*/
15
1
bool testStringPLog(){
16
1
	bool b(true);
17
1
	PLog log;
18
1
	log.setFileName("logFile.log");
19
1
	b &= log.open();
20
1
	b &= log.getFileName() == "logFile.log";
21
22
1
	log.getLog() << "Some log entry" << std::endl;
23
1
	log.getLog() << "Some other log entry" << std::endl;
24
25
1
	std::cout << "testStringPLog : b = " << b << std::endl;
26
2
	return b;
27
}
28
29
///Test the PLog
30
/**	@return true on success, false otherwise
31
*/
32
1
bool testStringMultiPLog(){
33
1
	bool b(true);
34
1
	PLog log;
35
1
	log.setFileName("logMultiFile.log");	//Always set the file name first
36
1
	size_t nbThread(4lu);
37
1
	log.resize(nbThread);			//Then, set the number of threads
38
1
	b &= log.open();			//Then, open all log file
39
1
	log.getLog() << "Log of all threads" << std::endl;
40
5
	for(size_t i(0lu); i < nbThread; ++i){
41
4
		PLog & subLog = log.getLog(i);
42

4
		subLog.getLog() << " i = "<<i<<", Some log entry" << std::endl;
43

4
		subLog.getLog() << " i = "<<i<<", Some other log entry" << std::endl;
44
	}
45
1
	std::cout << "testStringMultiPLog : b = " << b << std::endl;
46
2
	return b;
47
}
48
49
///Test if the std::cout redirection is working
50
/**	@return true on success, false otherwise
51
*/
52
1
bool testLogCoutDedirectInFile(){
53
1
	bool b(true);
54
1
	PLog log;
55
1
	log.setFileName("logFileRedirectCoutCerr.log");
56
1
	log.setMode(PLog::FILE_CAPTURE_STDOUT_STDERR);
57
1
	b &= log.open();
58
59
1
	std::cout << "Some redirected std::cout stuff" << std::endl;
60
1
	std::cerr << "Some redirected std::cerr stuff" << std::endl;
61
1
	log.getLog() << "Some classic log" << std::endl;
62
63
1
	log.close();	//Stops the redirection
64
1
	std::cout << "testLogCoutDedirectInFile : b = " << b << std::endl;
65
2
	return b;
66
}
67
68
///Test if the std::cout redirection is working
69
/**	@return true on success, false otherwise
70
*/
71
1
bool testLogStdoutOnly(){
72
1
	bool b(true);
73
1
	PLog log;
74
1
	log.setFileName("logFileStdOutOnly.log");
75
1
	log.setMode(PLog::STDOUT_ONLY);
76
1
	b &= log.open();
77
78
1
	log.getLog() << "Some log message" << std::endl;
79
1
	log.getLog() << "Some classic log" << std::endl;
80
81
1
	log.close();	//Stops the redirection
82
1
	std::cout << "testLogStdoutOnly : b = " << b << std::endl;
83
2
	return b;
84
}
85
86
///Test if the std::cout redirection is working
87
/**	@return true on success, false otherwise
88
*/
89
1
bool testLogDisable(){
90
1
	bool b(true);
91
1
	PLog log;
92
1
	log.setFileName("logFileDisable.log");
93
1
	log.setMode(PLog::DISABLE);
94
1
	b &= log.open();
95
96
1
	log.getLog() << "Some log message" << std::endl;
97
1
	log.getLog() << "Some classic log" << std::endl;
98
99
1
	log.close();	//Stops the redirection
100
1
	std::cout << "testLogDisable : b = " << b << std::endl;
101
2
	return b;
102
}
103
104
1
int main(int argc, char** argv){
105
1
	bool b(true);
106
1
	b &= testStringPLog();
107
1
	b &= testStringMultiPLog();
108
1
	b &= testLogCoutDedirectInFile();
109
1
	b &= testLogStdoutOnly();
110
1
	b &= testLogDisable();
111
1
	std::cout << "Final : b = " << b << std::endl;
112
1
	return b - 1;
113
}
114
115