GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/StringUtils/TESTS/TEST_SYSTEM/main.cpp Lines: 51 51 100.0 %
Date: 2023-10-11 10:52:07 Branches: 87 87 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 <vector>
10
#include "string_filename.h"
11
#include "string_system.h"
12
13
///Test the string system function
14
/**	@return true on success, false otherwise
15
*/
16
1
bool testStringSystem(){
17
1
	bool b(true);
18
19
1
	b &= getProgramDirectory() != "";
20
1
	b &= getProgramLocation() != "";
21
1
	b &= getProgramPrefix() != "";
22
1
	b &= getFileModificationTime("Makefile") != 0l;
23
1
	b &= getFileModificationTime("") == -1l;
24
1
	b &= getFileModificationTime("SomeInexistingFile") == -1l;
25
1
	b &= getHomeDir() != "";
26
27
2
	std::list<std::string> listFile;
28
1
	b &= getListAllFileInDir(listFile, "./");
29
1
	b &= getListFileInDir(listFile, "./", "\\.cmake");
30
1
	getListFileInCurrentDir(listFile, "\\.cmake");
31
1
	b &= listFile.size() != 0lu;
32
33
1
	b &= !isStringMatchRegex("", "");
34
1
	b &= !isStringMatchRegex("es", "");
35
1
	b &= !isStringMatchRegex("", "egzg");
36
1
	b &= !isStringMatchRegex("thing.txt", "*.*");
37
1
	b &= isStringMatchRegex("file.txt", "\\.txt");
38
1
	b &= createDirIfNotExist("NewDirectory");
39
1
	b &= createDirIfNotExist("NewDirectory");
40
41
1
	b &= saveFileContent("NewDirectory/newFile.txt", "some content of the new file");
42
1
	std::cerr << "testStringSystem : saveFileContent : b = " << b << std::endl;
43
2
	std::vector<std::string> vecFile1;
44
1
	time_t lastTime = getFileInDirPerTime(vecFile1, "NewDirectory/");
45
1
	b &= vecFile1.size() == 1lu;
46
1
	std::cerr << "testStringSystem : vecFile1.size : b = " << b << std::endl;
47
48
2
	std::vector<std::string> vecFile2;
49
1
	time_t lastTime2 = getFileInDirPerTime(vecFile2, "NewDirectory/", lastTime);
50
1
	b &= lastTime2 == lastTime;
51

1
	std::cerr << "testStringSystem : lastTime("<<lastTime<<") == lastTime2("<<lastTime2<<") : b = " << b << std::endl;
52
1
	b &= vecFile2.size() == 0lu;
53
1
	std::cerr << "testStringSystem : vecFile2.size : b = " << b << std::endl;
54
55
1
	std::string currentNode(getCurrentNodeName());
56

1
	std::cout << "testStringSystem : currentNode = '" << currentNode << "'" << std::endl;
57
1
	b &= currentNode != "";
58
59
1
	b &= phoenix_getenv("UNEXISTING_VARIABLE") == "";
60
1
	b &= phoenix_setenv("SomeExistingVariable", "42");
61
1
	b &= phoenix_getenv("SomeExistingVariable") == "42";
62
1
	b &= phoenix_unsetenv("SomeExistingVariable");
63
64
1
	b &= phoenix_chmod("Makefile");
65
1
	b &= !phoenix_chmod("UnexistingFile");
66
67
1
	std::cout << "testStringSystem : b = " << b << std::endl;
68
2
	return b;
69
}
70
71
1
int main(int argc, char** argv){
72
1
	bool b(true);
73
1
	std::list<std::string> listArg;
74
1
	makeListArgument(listArg, argc, argv);
75
1
	b &= listArg.size() != 0lu;
76
1
	b &= testStringSystem();
77
1
	return b - 1;
78
}
79
80