GCC Code Coverage Report


Directory: ./
File: src/get_argument_list.cpp
Date: 2024-07-27 10:53:27
Exec Total Coverage
Lines: 38 38 100.0%
Branches: 32 34 94.1%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "string_function.h"
8 #include "get_argument_list.h"
9
10
11 ///Convert the list of given arguments to the program into a list of string
12 /** @param argc : number of arguments passed to the program
13 * @param argv : table of arguments passed to the program
14 * @return corresponding list of string
15 */
16 3 std::list<std::string> phoenix_getArgumentList(int argc, char** argv){
17 3 std::list<std::string> argList;
18
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
8 for(int i(0); i < argc; ++i){
19
2/2
✓ Branch 2 taken 5 times.
✓ Branch 5 taken 5 times.
5 argList.push_back(std::string(argv[i]));
20 }
21 3 return argList;
22 }
23
24 ///Check if one of the two passed arguments are in the list of arguments
25 /** @param listArg : list of arguments given to the program
26 * @param argCheckList : list of argument to be searched
27 * @return true if one element of argCheckList has been found in listArg, false otherwise
28 */
29 6 bool phoenix_isOptionExist(const std::list<std::string> & listArg, const std::list<std::string> & argCheckList){
30 6 bool isSearch(true);
31 6 std::list<std::string>::const_iterator itArg(listArg.begin());
32
5/6
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 6 times.
16 while(itArg != listArg.end() && isSearch){
33 10 std::list<std::string>::const_iterator itCheck(argCheckList.begin());
34
6/6
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 10 times.
24 while(itCheck != argCheckList.end() && isSearch){
35 14 isSearch = *itArg != *itCheck;
36 14 ++itCheck;
37 }
38 10 ++itArg;
39 }
40 6 return !isSearch;
41 }
42
43 ///Check if one of the two passed arguments are in the list of arguments
44 /** @param listArg : list of arguments given to the program
45 * @param arg1 : argument to be searched
46 * @return true if arg1 or arg2 is in listArg, false otherwise
47 */
48 3 bool phoenix_isOptionExist(const std::list<std::string> & listArg, const std::string & arg1){
49 3 std::list<std::string> argCheckList;
50
1/1
✓ Branch 1 taken 3 times.
3 argCheckList.push_back(arg1);
51
1/1
✓ Branch 1 taken 3 times.
6 return phoenix_isOptionExist(listArg, argCheckList);
52 3 }
53
54 ///Check if one of the two passed arguments are in the list of arguments
55 /** @param listArg : list of arguments given to the program
56 * @param arg1 : argument to be searched
57 * @param arg2 : argument to be searched
58 * @return true if arg1 or arg2 is in listArg, false otherwise
59 */
60 3 bool phoenix_isOptionExist(const std::list<std::string> & listArg, const std::string & arg1, const std::string & arg2){
61 3 std::list<std::string> argCheckList;
62
1/1
✓ Branch 1 taken 3 times.
3 argCheckList.push_back(arg1);
63
1/1
✓ Branch 1 taken 3 times.
3 argCheckList.push_back(arg2);
64
1/1
✓ Branch 1 taken 3 times.
6 return phoenix_isOptionExist(listArg, argCheckList);
65 3 }
66
67 ///Convert the given list of arguement into a string
68 /** @param listArg : list of argument to be converted into a string
69 * @return corresponding string
70 */
71 6 std::string phoenix_listArgToString(const std::list<std::string> & listArg){
72
1/1
✓ Branch 2 taken 6 times.
6 std::string body("");
73
2/2
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 6 times.
13 for(std::list<std::string>::const_iterator itArg(listArg.begin()); itArg != listArg.end(); ++itArg){
74
5/5
✓ Branch 2 taken 7 times.
✓ Branch 6 taken 7 times.
✓ Branch 10 taken 7 times.
✓ Branch 13 taken 7 times.
✓ Branch 16 taken 7 times.
7 body += phoenix_escapeStr(*itArg, " '\"", "\\") + " ";
75 }
76 6 return body;
77 }
78
79 ///Get the program call
80 /** @param listArg : list of argument passed to the program
81 * @return program call, or empty string if list of argument is empty
82 */
83 6 std::string phoenix_getProgramCall(const std::list<std::string> & listArg){
84
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
6 if(listArg.size() != 0lu){return listArg.front();}
85
1/1
✓ Branch 2 taken 1 times.
1 else{return "";}
86 }
87
88 ///Remove the program call from the list of argument
89 /** @param[out] listArg : list or argument to be modified
90 */
91 3 void phoenix_rmProgramCall(std::list<std::string> & listArg){
92
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if(listArg.size() != 0lu){
93 3 listArg.pop_front();
94 }
95 3 }
96
97
98
99