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 <iostream> |
||
9 |
#include <vector> |
||
10 |
#include "phoenix_assert.h" |
||
11 |
#include "phoenix_check.h" |
||
12 |
|||
13 |
#include "string_function.h" |
||
14 |
|||
15 |
///Check string lower expression |
||
16 |
/** @param testName : name of the test |
||
17 |
* @param strValue : string to be tested |
||
18 |
* @param strReference : reference string |
||
19 |
* @return true is both strings are equal, false otherwise |
||
20 |
*/ |
||
21 |
14 |
bool checkString(const std::string & testName, const std::string & strValue, const std::string & strReference){ |
|
22 |
14 |
return phoenix_check(testName, strValue, strReference); |
|
23 |
} |
||
24 |
|||
25 |
///Test the find in list string filename function |
||
26 |
1 |
void testFindInListString(){ |
|
27 |
2 |
std::list<std::string> listStrRef; |
|
28 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInListString(listStrRef, "")); |
29 |
✓✓ | 1 |
listStrRef.push_back("one"); |
30 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInListString(listStrRef, "")); |
31 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInListString(listStrRef, "other")); |
32 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInListString(listStrRef, "one")); |
33 |
✓✓ | 1 |
listStrRef.push_back("two"); |
34 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInListString(listStrRef, "other")); |
35 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInListString(listStrRef, "two")); |
36 |
✓✓ | 1 |
listStrRef.push_back("three"); |
37 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInListString(listStrRef, "other")); |
38 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInListString(listStrRef, "two")); |
39 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInListString(listStrRef, "three")); |
40 |
|||
41 |
1 |
std::vector<std::string> vecStrRef; |
|
42 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInVectorString(vecStrRef, "")); |
43 |
✓✓ | 1 |
vecStrRef.push_back("one"); |
44 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInVectorString(vecStrRef, "")); |
45 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInVectorString(vecStrRef, "other")); |
46 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInVectorString(vecStrRef, "one")); |
47 |
✓✓ | 1 |
vecStrRef.push_back("two"); |
48 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInVectorString(vecStrRef, "other")); |
49 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInVectorString(vecStrRef, "two")); |
50 |
✓✓ | 1 |
vecStrRef.push_back("three"); |
51 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInVectorString(vecStrRef, "other")); |
52 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInVectorString(vecStrRef, "two")); |
53 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInVectorString(vecStrRef, "three")); |
54 |
|||
55 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(eraseLastCharsInStr("", "afe") == ""); |
56 |
|||
57 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(replaceStrInStr("", "", "") == ""); |
58 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(replaceStrInStr("", "o", "") == ""); |
59 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(replaceStrInStr("o", "", "") == ""); |
60 |
1 |
} |
|
61 |
|||
62 |
///Test the string filename function |
||
63 |
1 |
void testStringFunction(){ |
|
64 |
✓ | 2 |
std::string testString("some string to be used"); |
65 |
|||
66 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test replaceCharInStr", replaceCharInStr(testString, 'o', "O"), "sOme string tO be used")); |
67 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr(testString, "ot", 'X'), "sXme sXring XX be used")); |
68 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test replaceStrInStr", replaceStrInStr(testString, "string", "text"), "some text to be used")); |
69 |
✓✓✓✓ ✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(checkString("Test replaceStrInStr full", replaceStrInStr("string", "string", "text"), "text")); |
70 |
2 |
std::vector<std::string> vecStringToReplace; |
|
71 |
✓ | 1 |
vecStringToReplace.push_back(testString); |
72 |
✓✓✓ | 3 |
std::vector<std::string> vecReplacedString = replaceStrInStr(vecStringToReplace, "string", "text"); |
73 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(checkString("Test replaceStrInStr vector", vecReplacedString[0], "some text to be used")); |
74 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test copyStr", copyStr("Some string", 2lu, 4lu), "me s")); |
75 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkString("Test eraseCharInStr", eraseCharInStr(testString, 'o'), "sme string t be used")); |
76 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test eraseCharInStr", eraseCharInStr("", 'o'), "")); |
77 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr(testString, "o"), "sme string t be used")); |
78 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr(testString, "oxi"), "sme strng t be used")); |
79 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr("", "o"), "")); |
80 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("", "o", 'd'), "")); |
81 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("", "", 'd'), "")); |
82 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("o", "", 'd'), "o")); |
83 |
|||
84 |
2 |
std::vector<std::string> vecStrRef; |
|
85 |
✓✓ | 1 |
vecStrRef.push_back("one"); |
86 |
✓✓ | 1 |
vecStrRef.push_back("two"); |
87 |
✓✓ | 1 |
vecStrRef.push_back("three"); |
88 |
|||
89 |
✓✓ | 3 |
std::list<std::string> listStr(cutStringList("one two three", ' ')); |
90 |
✓✓ | 3 |
std::vector<std::string> vecStr(cutStringVector("one two three", ' ')); |
91 |
|||
92 |
✓✓ | 3 |
std::list<std::string> listSpaceStr(cutStringOnSpacesList("one two three")); |
93 |
✓✓ | 2 |
std::vector<std::string> vecSpaceStr(cutStringOnSpacesVector("one two three")); |
94 |
|||
95 |
1 |
std::list<std::string>::iterator itList(listStr.begin()); |
|
96 |
1 |
std::list<std::string>::iterator itSpaceList(listSpaceStr.begin()); |
|
97 |
1 |
std::vector<std::string>::iterator itVec(vecStr.begin()); |
|
98 |
1 |
std::vector<std::string>::iterator itSpaceVec(vecSpaceStr.begin()); |
|
99 |
1 |
std::vector<std::string>::iterator itVecRef(vecStrRef.begin()); |
|
100 |
|||
101 |
✓✓✓✗ ✓✗✓✗ ✓✗✓✓ |
4 |
while(itList != listStr.end() && itVec != vecStr.end() && itVecRef != vecStrRef.end() && itSpaceList != listSpaceStr.end() && itSpaceVec != vecSpaceStr.end()){ |
102 |
✓✓✓✓ ✗✓✗✓ |
3 |
phoenix_assert(*itList == *itVec && *itVec ==* itVecRef); |
103 |
✓✓✓✓ ✗✓✗✓ |
3 |
phoenix_assert(*itSpaceList == *itVec && *itSpaceVec == *itVec); |
104 |
|||
105 |
3 |
++itList; |
|
106 |
3 |
++itVec; |
|
107 |
3 |
++itVecRef; |
|
108 |
3 |
++itSpaceList; |
|
109 |
3 |
++itSpaceVec; |
|
110 |
} |
||
111 |
|||
112 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInString("", 'a')); |
113 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInString("abc", 'a')); |
114 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInString("abc", 'b')); |
115 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInString("abc", 'c')); |
116 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInString("abc", 'd')); |
117 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("", "")); |
118 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("", "a")); |
119 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("abc", "")); |
120 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "a")); |
121 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "b")); |
122 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "c")); |
123 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("abc", "d")); |
124 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "xa")); |
125 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "xb")); |
126 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "xc")); |
127 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("abc", "xd")); |
128 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "ax")); |
129 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "bx")); |
130 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "cx")); |
131 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("abc", "dx")); |
132 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(countNbChar("", 'o') == 0lu); |
133 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(countNbChar("some thing to count", 'o') == 3lu); |
134 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(countNbChar("some thing to count", 'w') == 0lu); |
135 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(isSameBegining("", "")); |
136 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!isSameBegining("", "d")); |
137 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(isSameBegining("start", "start")); |
138 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(isSameBegining("start", "st")); |
139 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!isSameBegining("st", "start")); |
140 |
|||
141 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("some string with text", "") == 0lu); |
142 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("", "nothing") == 0lu); |
143 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("", "") == 0lu); |
144 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("some string with text", "with") == 1lu); |
145 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("one char and two chars", "char") == 2lu); |
146 |
1 |
} |
|
147 |
|||
148 |
///Check the replaceVectorStrInStr function |
||
149 |
/** @param inputStr : input string |
||
150 |
* @param vecPattern : vector of patterns |
||
151 |
* @param replace : substitution string |
||
152 |
* @param strReference : expected result |
||
153 |
* @return true on success, false otherwise |
||
154 |
*/ |
||
155 |
5 |
bool checkReplaceVectorStrInStr(const std::string & inputStr, const std::vector<std::string> & vecPattern, const std::string & replace, |
|
156 |
const std::string & strReference) |
||
157 |
{ |
||
158 |
✓ | 5 |
std::string res(replaceVectorStrInStr(inputStr, vecPattern, replace)); |
159 |
✓✓ | 10 |
return phoenix_check("", res, strReference); |
160 |
} |
||
161 |
|||
162 |
///Test the replaceVectorStrInStr function |
||
163 |
1 |
void testReplaceVectorStrInStr(){ |
|
164 |
1 |
std::vector<std::string> vecStrPattern; |
|
165 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("", vecStrPattern, "", "")); |
166 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("something", vecStrPattern, "", "something")); |
167 |
✓✓ | 1 |
vecStrPattern.push_back("key"); |
168 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("", vecStrPattern, "", "")); |
169 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("convert value to key", vecStrPattern, "value", "convert value to value")); |
170 |
✓✓ | 1 |
vecStrPattern.push_back("value"); |
171 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("convert value to key", vecStrPattern, "thing", "convert thing to thing")); |
172 |
1 |
} |
|
173 |
|||
174 |
///Check the replaceVectorStrInStr function |
||
175 |
/** @param inputStr : input string |
||
176 |
* @param vecPattern : list of patterns |
||
177 |
* @param replace : substitution string |
||
178 |
* @param strReference : expected result |
||
179 |
* @return true on success, false otherwise |
||
180 |
*/ |
||
181 |
5 |
bool checkReplaceListStrInStr(const std::string & inputStr, const std::list<std::string> & vecPattern, const std::string & replace, |
|
182 |
const std::string & strReference) |
||
183 |
{ |
||
184 |
✓ | 5 |
std::string res(replaceListStrInStr(inputStr, vecPattern, replace)); |
185 |
✓✓ | 10 |
return phoenix_check("", res, strReference); |
186 |
} |
||
187 |
|||
188 |
///Test the replaceVectorStrInStr function |
||
189 |
1 |
void testReplaceListStrInStr(){ |
|
190 |
1 |
std::list<std::string> vecStrPattern; |
|
191 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("", vecStrPattern, "", "")); |
192 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("something", vecStrPattern, "", "something")); |
193 |
✓✓ | 1 |
vecStrPattern.push_back("key"); |
194 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("", vecStrPattern, "", "")); |
195 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("convert value to key", vecStrPattern, "value", "convert value to value")); |
196 |
✓✓ | 1 |
vecStrPattern.push_back("value"); |
197 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("convert value to key", vecStrPattern, "thing", "convert thing to thing")); |
198 |
1 |
} |
|
199 |
|||
200 |
///Test the replace of str in str with map |
||
201 |
1 |
void testReplaceStrInStrMap(){ |
|
202 |
1 |
std::map<std::string, std::string> mapReplace; |
|
203 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(replaceStrInStr("some string to convert", mapReplace) == "some string to convert"); |
204 |
✓✓✓ | 1 |
mapReplace["string"] = "value"; |
205 |
✓✓✓ | 1 |
mapReplace["convert"] = "replace"; |
206 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(replaceStrInStr("some string to convert", mapReplace) == "some value to replace"); |
207 |
1 |
} |
|
208 |
|||
209 |
///Test the phoenix_charToString function |
||
210 |
1 |
void testCharToString(){ |
|
211 |
✓✓✓✓ ✓ |
1 |
phoenix_assert(phoenix_charToString("some string") == "some string"); |
212 |
✓✓✓✓ ✓ |
1 |
phoenix_assert(phoenix_charToString(NULL) == ""); |
213 |
1 |
} |
|
214 |
|||
215 |
///Test the phoenix_escapeStr function |
||
216 |
1 |
void testEscapeString(){ |
|
217 |
✓✓✓✓ ✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_check("", phoenix_escapeStr("some string with escape's \"char\"", " '\"", "\\"), "some\\ string\\ with\\ escape\\'s\\ \\\"char\\\"")); |
218 |
1 |
} |
|
219 |
|||
220 |
///Test the phoenix_getCommonBegining function |
||
221 |
1 |
void testGetCommonBegning(){ |
|
222 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("", "") == ""); |
223 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("someString", "") == ""); |
224 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("", "someString") == ""); |
225 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("someString", "someOtherString") == "some"); |
226 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("someString", "AndsomeOtherString") == ""); |
227 |
1 |
} |
|
228 |
|||
229 |
1 |
int main(int argc, char** argv){ |
|
230 |
1 |
testStringFunction(); |
|
231 |
1 |
testFindInListString(); |
|
232 |
1 |
testReplaceVectorStrInStr(); |
|
233 |
1 |
testReplaceListStrInStr(); |
|
234 |
1 |
testReplaceStrInStrMap(); |
|
235 |
1 |
testCharToString(); |
|
236 |
1 |
testEscapeString(); |
|
237 |
1 |
testGetCommonBegning(); |
|
238 |
1 |
return 0; |
|
239 |
} |
||
240 |
|||
241 |
Generated by: GCOVR (Version 4.2) |