GCC Code Coverage Report


Directory: ./
File: src/directory_replace_placeholder.cpp
Date: 2025-11-27 16:44:16
Exec Total Coverage
Lines: 29 35 82.9%
Functions: 2 2 100.0%
Branches: 24 40 60.0%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7
8 #include "directory_replace_placeholder.h"
9
10 ///Replace placeholder in a directory and its content by respect to the given map of value for all place holder (file only)
11 /** @param outputDir : output directory
12 * @param inputConfigDir : input configuration directory
13 * @param mapReplacePlaceholder : map of placeholders and values to be replaced with
14 * @return true on success, false otherwise
15 */
16 7 bool directory_replace_placeholderFile(const PPath & outputDir, const PPath & inputConfigDir, const PMapString & mapReplacePlaceholder){
17 7 bool b(true);
18
1/1
✓ Branch 0 (2→3) taken 7 times.
7 PVecPath vecFileInputDir = inputConfigDir.getAllFileInDir();
19
2/2
✓ Branch 0 (31→4) taken 8 times.
✓ Branch 1 (31→32) taken 7 times.
30 for(PVecPath::iterator it(vecFileInputDir.begin()); it != vecFileInputDir.end(); ++it){
20
2/2
✓ Branch 0 (6→7) taken 8 times.
✓ Branch 2 (7→8) taken 8 times.
8 PPath relativeFile = it->replace(mapReplacePlaceholder);
21
1/1
✓ Branch 0 (11→12) taken 8 times.
8 PPath fullFile = inputConfigDir / *it;
22
1/1
✓ Branch 0 (12→13) taken 8 times.
8 PString fileContent = fullFile.loadFileContent();
23 //TODO : this could be optimised with the dico_replace_var algorithm, but this is enough for now
24
1/1
✓ Branch 0 (13→14) taken 8 times.
8 PString replacedContent = fileContent.replace(mapReplacePlaceholder);
25
1/1
✓ Branch 0 (14→15) taken 8 times.
8 PPath outputFile = outputDir / relativeFile;
26
1/1
✓ Branch 0 (15→16) taken 8 times.
8 b &= outputFile.saveFileContent(replacedContent);
27 8 }
28 7 return b;
29 7 }
30
31 ///Replace placeholder in a directory and its content by respect to the given map of value for all place holder
32 /** @param outputDir : output directory
33 * @param inputConfigDir : input configuration directory
34 * @param mapReplacePlaceholder : map of placeholders and values to be replaced with
35 * @return true on success, false otherwise
36 */
37 4 bool directory_replace_placeholder(const PPath & outputDir, const PPath & inputConfigDir, const PMapString & mapReplacePlaceholder){
38
2/3
✓ Branch 0 (2→3) taken 4 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→9) taken 4 times.
4 if(!outputDir.createDirectory()){
39 std::cerr << "directory_replace_placeholder : cannot create dir '"<<outputDir<<"'" << std::endl;
40 return false;
41 }
42 //Let's get content of inputConfigDir
43
1/1
✓ Branch 0 (9→10) taken 4 times.
4 PVecPath vecDirInputDir = inputConfigDir.getAllDirectoryInDir();
44 4 bool b(true);
45
2/2
✓ Branch 0 (36→11) taken 3 times.
✓ Branch 1 (36→37) taken 4 times.
14 for(PVecPath::iterator itDir(vecDirInputDir.begin()); itDir != vecDirInputDir.end(); ++itDir){
46
2/2
✓ Branch 0 (13→14) taken 3 times.
✓ Branch 2 (14→15) taken 3 times.
3 PPath relativeDir = itDir->replace(mapReplacePlaceholder);
47
1/1
✓ Branch 0 (18→19) taken 3 times.
3 PPath fullInputDir = inputConfigDir / *itDir;
48
1/1
✓ Branch 0 (19→20) taken 3 times.
3 PPath fullOutputDir = outputDir / relativeDir;
49
1/1
✓ Branch 0 (20→21) taken 3 times.
3 b &= fullOutputDir.createDirectory();
50
51
1/1
✓ Branch 0 (21→22) taken 3 times.
3 b &= directory_replace_placeholderFile(fullOutputDir, fullInputDir, mapReplacePlaceholder);
52
1/1
✓ Branch 0 (22→23) taken 3 times.
3 b &= directory_replace_placeholder(fullOutputDir, fullInputDir, mapReplacePlaceholder);
53 3 }
54
1/1
✓ Branch 0 (37→38) taken 4 times.
4 b &= directory_replace_placeholderFile(outputDir, inputConfigDir, mapReplacePlaceholder);
55
1/2
✗ Branch 0 (38→39) not taken.
✓ Branch 1 (38→50) taken 4 times.
4 if(!b){
56 std::cerr << "directory_replace_placeholder : cannot create output directories architecture" << std::endl;
57 std::cerr << "\tinputConfigDir = '"<<inputConfigDir<<"'" << std::endl;
58 std::cerr << "\toutputDir = '"<<outputDir<<"'" << std::endl;
59 return false;
60 }
61 4 return b;
62 4 }
63