GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/FileParser/TESTS/TEST_OPEN_FILE_STREAM/main.cpp Lines: 42 42 100.0 %
Date: 2023-10-11 10:52:07 Branches: 49 49 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 <iostream>
9
#include "phoenix_check.h"
10
#include "openFileStream.h"
11
12
///Check the openFileStream
13
/**	@return true on success, false otherwise
14
*/
15
1
bool checkOpenFileStream(){
16
1
	bool b(true);
17
18
2
	std::ofstream fs;
19
1
	b &= openFileStream(fs, "fileNameOut.txt");
20
1
	fs << "some content" << std::endl;
21
1
	fs.close();
22
23
2
	std::ifstream ifs;
24
1
	b &= openFileStream(ifs, "fileNameOut.txt");
25
1
	std::string fileContent("");
26
1
	ifs >> fileContent;
27
1
	ifs.close();
28
29
1
	b &= fileContent == "some";	//The input stream cut on blank characters
30

1
	std::cout << "checkOpenFileStream : fileContent = '" << fileContent << "'" << std::endl;
31
32
1
	b &= !openFileStream(fs, "outputDirWhichNotExist/test.txt");
33
1
	b &= !openFileStream(ifs, "unexistingFileNameOut.txt");
34
35
1
	b &= !openFileStream(fs, "");
36
1
	b &= !openFileStream(ifs, "");
37
1
	phoenix_functionOk("checkOpenFileStream", b);
38
2
	return b;
39
}
40
41
///Check the openFileStream
42
/**	@param fileName : name of the file to be used as a model
43
 * 	@param nbFile : number of files to be opened
44
 * 	@return true on success, false otherwise
45
*/
46
20
bool checkOpenVecFileStream(const std::string & fileName, size_t nbFile){
47
20
	bool b(true);
48
40
	PVecOFStream vecOut;
49
20
	b &= openFileStream(vecOut, fileName, nbFile);
50
110
	for(size_t i(0lu); i < nbFile; ++i){
51
90
		vecOut[i] << i << std::endl;
52
	}
53
20
	closeFileStream(vecOut);
54
20
	PVecIFStream vecIn;
55
20
	b &= openFileStream(vecIn, fileName, nbFile);
56
110
	for(size_t i(0lu); i < nbFile; ++i){
57
90
		size_t val(0lu);
58
90
		vecIn[i] >> val;
59
90
		b &= phoenix_check("checkOpenVecFileStream : read element", val, i);
60
	}
61
20
	closeFileStream(vecIn);
62
20
	phoenix_functionOk("checkOpenVecFileStream", b);
63
40
	return b;
64
}
65
66
67
1
int main(int argc, char** argv){
68
1
	bool b(checkOpenFileStream());
69
11
	for(size_t i(0lu); i < 10lu; ++i){
70
10
		b &= checkOpenVecFileStream("some_file_name.txt", i);
71
10
		b &= checkOpenVecFileStream("some_file_without_extention", i);
72
	}
73
1
	phoenix_functionOk("final", b);
74
1
	return b - 1;
75
}
76
77