GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
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 <map> |
||
9 |
#include <iostream> |
||
10 |
#include "phoenix_assert.h" |
||
11 |
#include "phoenix_check.h" |
||
12 |
|||
13 |
#include "string_utils.h" |
||
14 |
#include "string_system.h" |
||
15 |
|||
16 |
///Create a map with a string |
||
17 |
/** @param mapStr : map of string to be created |
||
18 |
* @param listStr : list of string to be used |
||
19 |
*/ |
||
20 |
16 |
void fillMapString(std::map<std::string, bool> & mapStr, const std::list<std::string> & listStr){ |
|
21 |
✓✓ | 82 |
for(std::list<std::string>::const_iterator it(listStr.begin()); it != listStr.end(); ++it){ |
22 |
✓ | 66 |
mapStr[*it] = true; |
23 |
} |
||
24 |
16 |
} |
|
25 |
|||
26 |
///Check the restut |
||
27 |
/** @param resultCmd : result |
||
28 |
* @param expectedResult : expected result |
||
29 |
* @param separator : separator to be used to split the results |
||
30 |
* @return true if the results matches the expected result, false otherwise |
||
31 |
*/ |
||
32 |
16 |
bool checkResultSeparator(const std::string & resultCmd, const std::string & expectedResult, char separator){ |
|
33 |
✓ | 32 |
std::list<std::string> listRes = cutStringList(resultCmd, separator); |
34 |
✓ | 32 |
std::list<std::string> listExpectedRes = cutStringList(expectedResult, separator); |
35 |
|||
36 |
16 |
std::map<std::string, bool> mapExpectedRes; |
|
37 |
✓ | 16 |
fillMapString(mapExpectedRes, listExpectedRes); |
38 |
|||
39 |
16 |
bool b(true); |
|
40 |
✓✓ | 82 |
for(std::list<std::string>::const_iterator it(listRes.begin()); it != listRes.end(); ++it){ |
41 |
✓ | 66 |
b &= mapExpectedRes.find(*it) != mapExpectedRes.end(); |
42 |
} |
||
43 |
|||
44 |
32 |
return b; |
|
45 |
} |
||
46 |
|||
47 |
///Check the restut |
||
48 |
/** @param resultCmd : result |
||
49 |
* @param expectedResult : expected result |
||
50 |
* @return true if the results matches the expected result, false otherwise |
||
51 |
*/ |
||
52 |
16 |
bool checkResult(const std::string & resultCmd, const std::string & expectedResult){ |
|
53 |
✗✓ | 16 |
if(!checkResultSeparator(resultCmd, expectedResult, ' ')){ |
54 |
if(!checkResultSeparator(resultCmd, expectedResult, '\n')){ |
||
55 |
return false; |
||
56 |
} |
||
57 |
} |
||
58 |
16 |
return true; |
|
59 |
} |
||
60 |
|||
61 |
///Check the option completion of a program |
||
62 |
/** @param program : program to be tested |
||
63 |
* @param partialOption : partial typed option |
||
64 |
* @param prevCursorOption : previous cursor option |
||
65 |
* @param cursorOption : option of the cursor |
||
66 |
* @param expectedResult : expected completion result |
||
67 |
* @return true on success, false otherwise |
||
68 |
*/ |
||
69 |
16 |
bool checkOptionCompletion(const std::string & program, const std::string & partialOption, |
|
70 |
const std::string & prevCursorOption, const std::string & cursorOption, const std::string & expectedResult) |
||
71 |
{ |
||
72 |
✓✓✓✓ ✓✓ |
48 |
std::string command(program + " __bashcompletionmode=\""+cursorOption+"\" __bashcompletionmodeprev=\""+prevCursorOption+"\" prgName " + partialOption); |
73 |
✓ | 16 |
std::string resultCmd(phoenix_popen(command)); |
74 |
// std::cout << "checkOptionCompletion : command '"<<command<<"':\n\tresult = '"<<resultCmd<<"', expectedResult = '"<<expectedResult<<"'" << std::endl; |
||
75 |
|||
76 |
✓ | 16 |
bool b(checkResult(resultCmd, expectedResult)); |
77 |
32 |
return b; |
|
78 |
} |
||
79 |
|||
80 |
///Test the completion of the option |
||
81 |
1 |
void testCompletion(){ |
|
82 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "", "", "", "class source --help -h --version -v \n")); |
83 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "", "--name -n --template -t --config -c --help -h --version -v \n")); |
84 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "-", "--name -n --template -t --config -c --help -h --version -v \n")); |
85 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "--", "--name --template --config --help --version \n")); |
86 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "--n", "--name \n")); |
87 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --name=test --", "--name=test", "--", "--template --config --help --version \n")); |
88 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --name=\"test\" --", "--name=\"test\"", "--", "--template --config --help --version \n")); |
89 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class -n \"test\" --", "\"test\"", "--", "--template --config --help --version \n")); |
90 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "source", "source", "", "--name -n --help -h --version -v \n")); |
91 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config ", "--config", "", "./\n")); |
92 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION, "--config", DIR_COMPLETION, DIR_COMPLETION "/0-someDir\n" DIR_COMPLETION "/1-someFile.txt\n\n")); |
93 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir", "--config", DIR_COMPLETION "/0-someDir", DIR_COMPLETION "/0-someDir/someFile.txt\n\n")); |
94 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir/someFile.txt", "--config", DIR_COMPLETION "/0-someDir/someFile.txt", "\n")); |
95 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir/some", "--config", DIR_COMPLETION "/0-someDir/some", DIR_COMPLETION "/0-someDir/someFile.txt\n\n")); |
96 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE_DIR, "class --dir " DIR_COMPLETION "/0-some", "--dir", DIR_COMPLETION "/0-some", DIR_COMPLETION "/0-someDir\n\n")); |
97 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE_DIR, "class --dir " DIR_COMPLETION, "--dir", DIR_COMPLETION, DIR_COMPLETION "/0-someDir\n\n")); |
98 |
1 |
} |
|
99 |
|||
100 |
1 |
int main(int argc, char** argv){ |
|
101 |
1 |
testCompletion(); |
|
102 |
1 |
return 0; |
|
103 |
} |
||
104 |
|||
105 |
Generated by: GCOVR (Version 4.2) |