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 |
13 |
bool checkString(const std::string & testName, const std::string & strValue, const std::string & strReference){ |
|
22 |
13 |
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 |
2 |
std::vector<std::string> vecStringToReplace; |
|
70 |
✓ | 1 |
vecStringToReplace.push_back(testString); |
71 |
✓✓✓ | 3 |
std::vector<std::string> vecReplacedString = replaceStrInStr(vecStringToReplace, "string", "text"); |
72 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(checkString("Test replaceStrInStr vector", vecReplacedString[0], "some text to be used")); |
73 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test copyStr", copyStr("Some string", 2lu, 4lu), "me s")); |
74 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkString("Test eraseCharInStr", eraseCharInStr(testString, 'o'), "sme string t be used")); |
75 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test eraseCharInStr", eraseCharInStr("", 'o'), "")); |
76 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr(testString, "o"), "sme string t be used")); |
77 |
✓✓✓✓ ✓✓✓✓ ✓ |
1 |
phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr(testString, "oxi"), "sme strng t be used")); |
78 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test eraseCharsInStr", eraseCharsInStr("", "o"), "")); |
79 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("", "o", 'd'), "")); |
80 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("", "", 'd'), "")); |
81 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
1 |
phoenix_assert(checkString("Test replaceCharsInStr", replaceCharsInStr("o", "", 'd'), "o")); |
82 |
|||
83 |
2 |
std::vector<std::string> vecStrRef; |
|
84 |
✓✓ | 1 |
vecStrRef.push_back("one"); |
85 |
✓✓ | 1 |
vecStrRef.push_back("two"); |
86 |
✓✓ | 1 |
vecStrRef.push_back("three"); |
87 |
|||
88 |
✓✓ | 3 |
std::list<std::string> listStr(cutStringList("one two three", ' ')); |
89 |
✓✓ | 3 |
std::vector<std::string> vecStr(cutStringVector("one two three", ' ')); |
90 |
|||
91 |
✓✓ | 3 |
std::list<std::string> listSpaceStr(cutStringOnSpacesList("one two three")); |
92 |
✓✓ | 2 |
std::vector<std::string> vecSpaceStr(cutStringOnSpacesVector("one two three")); |
93 |
|||
94 |
1 |
std::list<std::string>::iterator itList(listStr.begin()); |
|
95 |
1 |
std::list<std::string>::iterator itSpaceList(listSpaceStr.begin()); |
|
96 |
1 |
std::vector<std::string>::iterator itVec(vecStr.begin()); |
|
97 |
1 |
std::vector<std::string>::iterator itSpaceVec(vecSpaceStr.begin()); |
|
98 |
1 |
std::vector<std::string>::iterator itVecRef(vecStrRef.begin()); |
|
99 |
|||
100 |
✓✓✓✗ ✓✗✓✗ ✓✗✓✓ |
4 |
while(itList != listStr.end() && itVec != vecStr.end() && itVecRef != vecStrRef.end() && itSpaceList != listSpaceStr.end() && itSpaceVec != vecSpaceStr.end()){ |
101 |
✓✓✓✓ ✗✓✗✓ |
3 |
phoenix_assert(*itList == *itVec && *itVec ==* itVecRef); |
102 |
✓✓✓✓ ✗✓✗✓ |
3 |
phoenix_assert(*itSpaceList == *itVec && *itSpaceVec == *itVec); |
103 |
|||
104 |
3 |
++itList; |
|
105 |
3 |
++itVec; |
|
106 |
3 |
++itVecRef; |
|
107 |
3 |
++itSpaceList; |
|
108 |
3 |
++itSpaceVec; |
|
109 |
} |
||
110 |
|||
111 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInString("", 'a')); |
112 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInString("abc", 'a')); |
113 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInString("abc", 'b')); |
114 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(findInString("abc", 'c')); |
115 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(!findInString("abc", 'd')); |
116 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("", "")); |
117 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("", "a")); |
118 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("abc", "")); |
119 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "a")); |
120 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "b")); |
121 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "c")); |
122 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("abc", "d")); |
123 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "xa")); |
124 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "xb")); |
125 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "xc")); |
126 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("abc", "xd")); |
127 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "ax")); |
128 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "bx")); |
129 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(findCharsInString("abc", "cx")); |
130 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!findCharsInString("abc", "dx")); |
131 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(countNbChar("", 'o') == 0lu); |
132 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(countNbChar("some thing to count", 'o') == 3lu); |
133 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(countNbChar("some thing to count", 'w') == 0lu); |
134 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(isSameBegining("", "")); |
135 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!isSameBegining("", "d")); |
136 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(isSameBegining("start", "start")); |
137 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(isSameBegining("start", "st")); |
138 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(!isSameBegining("st", "start")); |
139 |
|||
140 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("some string with text", "") == 0lu); |
141 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("", "nothing") == 0lu); |
142 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("", "") == 0lu); |
143 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("some string with text", "with") == 1lu); |
144 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(countStrInStr("one char and two chars", "char") == 2lu); |
145 |
1 |
} |
|
146 |
|||
147 |
///Check the replaceVectorStrInStr function |
||
148 |
/** @param inputStr : input string |
||
149 |
* @param vecPattern : vector of patterns |
||
150 |
* @param replace : substitution string |
||
151 |
* @param strReference : expected result |
||
152 |
* @return true on success, false otherwise |
||
153 |
*/ |
||
154 |
5 |
bool checkReplaceVectorStrInStr(const std::string & inputStr, const std::vector<std::string> & vecPattern, const std::string & replace, |
|
155 |
const std::string & strReference) |
||
156 |
{ |
||
157 |
✓ | 5 |
std::string res(replaceVectorStrInStr(inputStr, vecPattern, replace)); |
158 |
✓✓ | 10 |
return phoenix_check("", res, strReference); |
159 |
} |
||
160 |
|||
161 |
///Test the replaceVectorStrInStr function |
||
162 |
1 |
void testReplaceVectorStrInStr(){ |
|
163 |
1 |
std::vector<std::string> vecStrPattern; |
|
164 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("", vecStrPattern, "", "")); |
165 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("something", vecStrPattern, "", "something")); |
166 |
✓✓ | 1 |
vecStrPattern.push_back("key"); |
167 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("", vecStrPattern, "", "")); |
168 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("convert value to key", vecStrPattern, "value", "convert value to value")); |
169 |
✓✓ | 1 |
vecStrPattern.push_back("value"); |
170 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceVectorStrInStr("convert value to key", vecStrPattern, "thing", "convert thing to thing")); |
171 |
1 |
} |
|
172 |
|||
173 |
///Check the replaceVectorStrInStr function |
||
174 |
/** @param inputStr : input string |
||
175 |
* @param vecPattern : list of patterns |
||
176 |
* @param replace : substitution string |
||
177 |
* @param strReference : expected result |
||
178 |
* @return true on success, false otherwise |
||
179 |
*/ |
||
180 |
5 |
bool checkReplaceListStrInStr(const std::string & inputStr, const std::list<std::string> & vecPattern, const std::string & replace, |
|
181 |
const std::string & strReference) |
||
182 |
{ |
||
183 |
✓ | 5 |
std::string res(replaceListStrInStr(inputStr, vecPattern, replace)); |
184 |
✓✓ | 10 |
return phoenix_check("", res, strReference); |
185 |
} |
||
186 |
|||
187 |
///Test the replaceVectorStrInStr function |
||
188 |
1 |
void testReplaceListStrInStr(){ |
|
189 |
1 |
std::list<std::string> vecStrPattern; |
|
190 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("", vecStrPattern, "", "")); |
191 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("something", vecStrPattern, "", "something")); |
192 |
✓✓ | 1 |
vecStrPattern.push_back("key"); |
193 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("", vecStrPattern, "", "")); |
194 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("convert value to key", vecStrPattern, "value", "convert value to value")); |
195 |
✓✓ | 1 |
vecStrPattern.push_back("value"); |
196 |
✓✓✓✓ ✓✓✓✓ |
1 |
phoenix_assert(checkReplaceListStrInStr("convert value to key", vecStrPattern, "thing", "convert thing to thing")); |
197 |
1 |
} |
|
198 |
|||
199 |
///Test the replace of str in str with map |
||
200 |
1 |
void testReplaceStrInStrMap(){ |
|
201 |
1 |
std::map<std::string, std::string> mapReplace; |
|
202 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(replaceStrInStr("some string to convert", mapReplace) == "some string to convert"); |
203 |
✓✓✓ | 1 |
mapReplace["string"] = "value"; |
204 |
✓✓✓ | 1 |
mapReplace["convert"] = "replace"; |
205 |
✓✓✓✓ ✓✓ |
1 |
phoenix_assert(replaceStrInStr("some string to convert", mapReplace) == "some value to replace"); |
206 |
1 |
} |
|
207 |
|||
208 |
///Test the phoenix_charToString function |
||
209 |
1 |
void testCharToString(){ |
|
210 |
✓✓✓✓ ✓ |
1 |
phoenix_assert(phoenix_charToString("some string") == "some string"); |
211 |
✓✓✓✓ ✓ |
1 |
phoenix_assert(phoenix_charToString(NULL) == ""); |
212 |
1 |
} |
|
213 |
|||
214 |
///Test the phoenix_escapeStr function |
||
215 |
1 |
void testEscapeString(){ |
|
216 |
✓✓✓✓ ✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_check("", phoenix_escapeStr("some string with escape's \"char\"", " '\"", "\\"), "some\\ string\\ with\\ escape\\'s\\ \\\"char\\\"")); |
217 |
1 |
} |
|
218 |
|||
219 |
///Test the phoenix_getCommonBegining function |
||
220 |
1 |
void testGetCommonBegning(){ |
|
221 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("", "") == ""); |
222 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("someString", "") == ""); |
223 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("", "someString") == ""); |
224 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("someString", "someOtherString") == "some"); |
225 |
✓✓✓✓ ✓✓✓ |
1 |
phoenix_assert(phoenix_getCommonBegining("someString", "AndsomeOtherString") == ""); |
226 |
1 |
} |
|
227 |
|||
228 |
1 |
int main(int argc, char** argv){ |
|
229 |
1 |
testStringFunction(); |
|
230 |
1 |
testFindInListString(); |
|
231 |
1 |
testReplaceVectorStrInStr(); |
|
232 |
1 |
testReplaceListStrInStr(); |
|
233 |
1 |
testReplaceStrInStrMap(); |
|
234 |
1 |
testCharToString(); |
|
235 |
1 |
testEscapeString(); |
|
236 |
1 |
testGetCommonBegning(); |
|
237 |
1 |
return 0; |
|
238 |
} |
||
239 |
|||
240 |
Generated by: GCOVR (Version 4.2) |