GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/StringUtils/TESTS/TEST_FILENAME/main.cpp Lines: 85 85 100.0 %
Date: 2023-10-11 10:52:07 Branches: 255 255 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 "phoenix_check.h"
11
12
#include "string_filename.h"
13
14
///Check string lower expression
15
/**	@param testName : name of the test
16
 * 	@param strValue : string to be tested
17
 * 	@param strReference : reference string
18
 * 	@return true is both strings are equal, false otherwise
19
*/
20
7
bool checkString(const std::string & testName, const std::string & strValue, const std::string & strReference){
21
7
	return phoenix_check(testName, strValue, strReference);
22
}
23
24
///Test the string filename function
25
/**	@return true on success, false otherwise
26
*/
27
1
bool testStringFilename(){
28
1
	bool b(true);
29
2
	std::string fileName("someDir/someOtherDir/fileName.extention");
30

1
	b &= checkString("Test getFileName", getFileName(fileName), "fileName.extention");
31

1
	b &= checkString("Test getDirectory", getDirectory(fileName), "someDir/someOtherDir");
32

1
	b &= checkString("Test eraseExtension", eraseExtension(fileName), "someDir/someOtherDir/fileName");
33

1
	b &= checkString("Test getExtention", getExtention(fileName), "extention");
34

1
	b &= checkString("Test getExtention", getExtention("fileWithoutExtention"), "");
35

1
	b &= checkString("Test eraseExtension", eraseExtension(""), "");
36

1
	b &= checkString("Test eraseExtension", eraseExtension("file.tar.gz"), "file.tar");
37
38
39
1
	b &= isFileOrDirExist("Makefile");
40
1
	std::cout << "testStringFilename : isFileOrDirExist(Makefile), b = " << b << std::endl;
41
1
	b &= isFileOrDirExist("CMakeFiles");
42
1
	std::cout << "testStringFilename : isFileOrDirExist(CMakeFiles), b = " << b << std::endl;
43
44
1
	b &= !isFileExist("");
45
1
	b &= !isFileOrDirExist("");
46
47
1
	std::cout << "testStringFilename : b = " << b << std::endl;
48
1
	b &= isFileExist("./Makefile");
49
1
	std::cout << "testStringFilename : isFileExist(Makefile), b = " << b << std::endl;
50
1
	b &= !isFileExist("CMakeFiles");
51
1
	std::cout << "testStringFilename : !isFileExist(CMakeFiles), b = " << b << std::endl;
52
1
	b &= !isFileExist("SomeInexistingFile");
53
1
	std::cout << "testStringFilename : !isFileExist(SomeInexistingFile), b = " << b << std::endl;
54
1
	b &= getFileContent("Makefile") != "";
55

1
	b &= phoenix_check("Test getFileContent missing file", getFileContent("SomeInexistingFile"), "");
56

1
	b &= phoenix_check("Test getFileContent NULL", getFileContent(NULL), "");
57
1
	b &= !saveFileContent(NULL, "");
58
1
	b &= !saveFileContent(NULL, "some string");
59
60
1
	b &= saveFileContent("testFile.txt", "some file content");
61
1
	b &= !saveFileContent("", "some file content");
62
1
	b &= !isDirectoryExist("");
63
1
	b &= isDirectoryExist("CMakeFiles");
64

1
	b &= phoenix_check("Test isDirectoryExist not dir", isDirectoryExist("SomeInexistingDir"), false);
65
66
1
	std::cout << "testStringFilename : isDirectoryExist, b = " << b << std::endl;
67
1
	b &= getCurrentDirectory() != "";
68
1
	std::cout << "testStringFilename : getCurrentDirectory, b = " << b << std::endl;
69
1
	std::vector<std::string> vecDir;
70

1
	b &= phoenix_check("Test getExistingFileName empty", getExistingFileName("", vecDir), "");
71

1
	b &= phoenix_check("Test getExistingFileName", getExistingFileName("Makefile", vecDir), "");
72
1
	std::cout << "testStringFilename : Makefile, b = " << b << std::endl;
73
1
	vecDir.push_back("SomeInexistingDir");
74
1
	b &= getExistingFileName("", vecDir) == "";
75
1
	b &= getExistingFileName("Makefile", vecDir) == "";
76
1
	std::cout << "testStringFilename : Makefile, testStringFilename, b = " << b << std::endl;
77
1
	vecDir.push_back("./");
78
1
	b &= getExistingFileName("Makefile", vecDir) != "";
79
1
	std::cout << "testStringFilename : Makefile, testStringFilename,./, b = " << b << std::endl;
80
81
1
	b &= createDirectoriesIfNotExist("someDir");
82
1
	std::cout << "testStringFilename : createDirectoriesIfNotExist(someDir), b = " << b << std::endl;
83
1
	b &= createDirectoriesIfNotExist("someDir/someOtherDir");
84
1
	std::cout << "testStringFilename : createDirectoriesIfNotExist(someDir/someOtherDir), b = " << b << std::endl;
85
86
1
	b &= createDirectoriesIfNotExist("///");
87
88
1
	b &= makeAbsolutePath("") != "";
89
1
	b &= makeAbsolutePath("./dir") != "";
90
1
	b &= makeAbsolutePath("/usr/lib") == "/usr/lib";
91
1
	b &= !isAbsolutePath("");
92
1
	b &= isAbsolutePath("/someting/absolute");
93
1
	b &= !isAbsolutePath("../someting/not/absolute");
94
95

1
	b &= phoenix_check("getUnderPath : empty", getUnderPath("", ""), "");
96

1
	b &= phoenix_check("getUnderPath : base", getUnderPath("/some/dir/path", "dir"), "path");
97

1
	b &= phoenix_check("getUnderPath : not found", getUnderPath("/some/dir/path", "nothere"), "");
98
99

1
	b &= phoenix_check("removePathDots : empty", removePathDots(""), "");
100

1
	b &= phoenix_check("removePathDots : relative path", removePathDots("some/relative/path"), "some/relative/path");
101

1
	b &= phoenix_check("removePathDots : absolute path", removePathDots("/some/absolute/path"), "/some/absolute/path");
102

1
	b &= phoenix_check("removePathDots : dot relative path", removePathDots("some/./relative/path"), "some/relative/path");
103

1
	b &= phoenix_check("removePathDots : dot absolute path", removePathDots("/some/./absolute/path"), "/some/absolute/path");
104

1
	b &= phoenix_check("removePathDots : dots relative path", removePathDots("some/relative/../path"), "some/path");
105

1
	b &= phoenix_check("removePathDots : dots absolute path", removePathDots("/some/absolute/../path"), "/some/path");
106
107

1
	b &= phoenix_check("removePathDots : dots 2 relative path", removePathDots("some/../relative/../path"), "path");
108

1
	b &= phoenix_check("removePathDots : dots 2 absolute path", removePathDots("/some/../absolute/../path"), "/path");
109
110

1
	b &= phoenix_check("removePathDots : dots 1.5 relative path", removePathDots("some/./relative/../path"), "some/path");
111

1
	b &= phoenix_check("removePathDots : dots 1.5 absolute path", removePathDots("/some/./absolute/../path"), "/some/path");
112

1
	b &= phoenix_check("removePathDots : dots 1.8 relative path", removePathDots("some//relative/../path"), "some/path");
113

1
	b &= phoenix_check("removePathDots : dots 1.8 absolute path", removePathDots("/some//absolute/../path"), "/some/path");
114
115

1
	b &= phoenix_check("getDirName : /some/dir", getDirName("/some/dir"), "dir");
116

1
	b &= phoenix_check("getDirName : /some/dir/again/", getDirName("/some/dir/again/"), "again");
117
118
1
	phoenix_functionOk("testStringFilename", b);
119
2
	return b;
120
}
121
122
1
int main(int argc, char** argv){
123
1
	bool b(true);
124
1
	b &= testStringFilename();
125
126
1
	phoenix_functionOk("final", b);
127
1
	return b - 1;
128
}
129
130