PhoenixSlider  2.0.0
Tool to create HTML presentation automatically
main.cpp
Go to the documentation of this file.
1 
2 /***************************************
3  Auteur : Pierre Aubert
4  Mail : pierre.aubert@lapp.in2p3.fr
5  Licence : CeCILL-C
6 ****************************************/
7 
8 #include <iostream>
9 #include "phoenix_assert.h"
10 #include "phoenix_check.h"
11 
12 #include "PString.h"
13 
15 
20 bool checkString(const std::string & testName, const std::string & strValue, const std::string & strReference){
21  return phoenix_check(testName, strValue, strReference);
22 }
23 
25 void testPString(){
26  PString baseStr("baseString");
27  phoenix_assert(checkString("Test constructor", baseStr, "baseString"));
28  PString checkEqual;
29  checkEqual = baseStr;
30  phoenix_assert(checkString("Test equal", checkEqual, "baseString"));
31 
32  PString checkEqualStdString;
33  checkEqualStdString = std::string("baseString");
34  phoenix_assert(checkString("Test equal std::string", checkEqualStdString, "baseString"));
35 
36  PString checkConstructorStdString(std::string("baseString"));
37  phoenix_assert(checkString("Test constructor std::string", checkConstructorStdString, "baseString"));
38 
39  PString copyString(baseStr);
40  phoenix_assert(checkString("Test copy constructor", copyString, "baseString"));
41  PString equalOperatorStr;
42  equalOperatorStr = baseStr;
43  phoenix_assert(checkString("Test equal operator str", equalOperatorStr, "baseString"));
44 
45  PString equalOperatorFluxStr;
46  equalOperatorFluxStr = baseStr;
47  phoenix_assert(checkString("Test << operator str", equalOperatorFluxStr, "baseString"));
48 
49  baseStr += " end";
50  phoenix_assert(checkString("Test += string", baseStr, "baseString end"));
51 
52  PString valDouble;
53  valDouble = 42.0;
54  phoenix_assert(checkString("Test equal operator double", valDouble, "42"));
55 
56  PString valFloat;
57  valFloat = 42.0f;
58  phoenix_assert(checkString("Test equal operator float", valFloat, "42"));
59 
60  PString valDoubleFlux;
61  valDoubleFlux << 42.0;
62  phoenix_assert(checkString("Test << operator double", valDoubleFlux, "42"));
63 
64  PString strAndChar("strin");
65  strAndChar += 'g';
66  phoenix_assert(checkString("Test + operator char", strAndChar, "string"));
67 
68  PString valFloatFlux;
69  valFloatFlux << 42.0f;
70  phoenix_assert(checkString("Test << operator float", valFloatFlux, "42"));
71 
72  valDouble += 3.14;
73  phoenix_assert(checkString("Test += operator double", valDouble, "423.14"));
74 
75  valFloat += 3.14f;
76  phoenix_assert(checkString("Test += operator float", valFloat, "423.14"));
77 
78  PString resAdd = valDouble + valFloat;
79  phoenix_assert(checkString("Test + operator PString", resAdd, "423.14423.14"));
80 
81  PString resAddDouble;
82  resAddDouble = PString("double ") + PString::toString(3.14);
83  phoenix_assert(checkString("Test + operator double", resAddDouble, "double 3.14"));
84 
85  PString resAddFloat;
86  resAddFloat = PString("float ") + PString::toString(3.14);
87  phoenix_assert(checkString("Test + operator float", resAddFloat, "float 3.14"));
88 
89  PString strA("str1"), strB("str2"), resResAB, resFluxAB;
90  resResAB = strA + strB;
91  phoenix_assert(checkString("Test + operator PString", resResAB, "str1str2"));
92  resFluxAB << strA << strB;
93  phoenix_assert(checkString("Test << operator PString", resFluxAB, "str1str2"));
94 
95  PString strAddStr("Some string");
96  strAddStr += " other string";
97  phoenix_assert(checkString("Test += operator std::string", strAddStr, "Some string other string"));
98 
99  PString strAddFluxStr("Some string");
100  strAddFluxStr << " other string";
101  phoenix_assert(checkString("Test << operator std::string", strAddFluxStr, "Some string other string"));
102 
103  PString strFlux;
104  strFlux << strAddFluxStr;
105  phoenix_assert(checkString("Test << operator PString", strFlux, "Some string other string"));
106 
107  strFlux += std::string(" and the end");
108  phoenix_assert(checkString("Test += operator std::string", strFlux, "Some string other string and the end"));
109 
110  strFlux << std::string(".");
111  phoenix_assert(checkString("Test += operator std::string", strFlux, "Some string other string and the end."));
112 
113  strA << (strFlux << strAddFluxStr);
114 }
115 
118  PString str;
119  str.fromValue(3.14);
120  phoenix_assert(checkString("Test fromValue", str, "3.14"));
121  phoenix_assert(3.14 == str.toValue<double>());
122 }
123 
126  phoenix_assert(phoenix_check("Check findPatternIndex empty string", PString("").findPatternIndex("key="), 0lu));
127  phoenix_assert(phoenix_check("Check findPatternIndex empty pattern", PString("garbage key=value").findPatternIndex(""), 17lu));
128  phoenix_assert(phoenix_check("Check findPatternIndex", PString("garbage key=value").findPatternIndex("key="), 8lu));
129 
130  phoenix_assert(phoenix_check("Check findPatternIndex offset", PString("key=garbage other key=value").findPatternIndex("key=", 11lu), 18lu));
131 }
132 
135  phoenix_assert(phoenix_check("Check getBetweenDelimiter", PString("garbage key=value; other garbage").getBetweenDelimiter("key=", ";"), "value"));
136  phoenix_assert(phoenix_check("Check getBetweenDelimiter", PString("garbage key=value/othergarbage").getBetweenDelimiter("key=", "/"), "value"));
137 }
138 
141  PString str = "Some string to modify";
142  phoenix_assert(checkString("Check replace", str.replace("string", "sentence"), "Some sentence to modify"));
143  phoenix_assert(checkString("Check replace", PString("some string to modify").replace("string", "sentence"), "some sentence to modify"));
144 
145  PString str2("Some string to modify");
146  phoenix_assert(checkString("Check replace", str2.replace("string", "sentence", 0lu), "Some string to modify"));
147  phoenix_assert(checkString("Check replace", str2.replace("string", "sentence", 1lu), "Some sentence to modify"));
148 
149  PString str3("Some string to modify with other strings");
150  phoenix_assert(checkString("Check replace", str3.replace("string", "sentence", 1lu), "Some sentence to modify with other strings"));
151  phoenix_assert(checkString("Check replace", str3.replace("string", "violin", 1lu), "Some violin to modify with other strings"));
152 
153  phoenix_assert(checkString("Check replaceChar", PString("some string\nwith\tchar to replace").replaceChar(" \t\n", "_"), "some_string_with_char_to_replace"));
154 }
155 
158  phoenix_assert(PString("").isSameBegining(""));
159  phoenix_assert(!PString("").isSameBegining("d"));
160  phoenix_assert(PString("start").isSameBegining("start"));
161  phoenix_assert(PString("start").isSameBegining("st"));
162  phoenix_assert(!PString("st").isSameBegining("start"));
163 }
164 
166 void checkFormat(){
167  PString str3("Some {} to modify with other {}s");
168  phoenix_assert(checkString("Check format", str3.format("sentence"), "Some sentence to modify with other {}s"));
169  phoenix_assert(checkString("Check format", str3.format("violin"), "Some violin to modify with other {}s"));
170 }
171 
173 void checkCount(){
174  phoenix_assert(PString("").count('o') == 0lu);
175  phoenix_assert(PString("some thing to count").count('o') == 3lu);
176  phoenix_assert(PString("some thing to count").count('w') == 0lu);
177 
178  phoenix_assert(PString("some string with text").count("") == 0lu);
179  phoenix_assert(PString("").count("nothing") == 0lu);
180  phoenix_assert(PString("").count("") == 0lu);
181  phoenix_assert(PString("some string with text").count("with") == 1lu);
182  phoenix_assert(PString("one char and two chars").count("char") == 2lu);
183 }
184 
188  phoenix_assert(phoenix_charToString("some text") == "some text");
189 }
190 
193  phoenix_assert(PString("").getCommonBegining("") == "");
194  phoenix_assert(PString("someString").getCommonBegining("") == "");
195  phoenix_assert(PString("").getCommonBegining("someString") == "");
196  phoenix_assert(PString("someString").getCommonBegining("someOtherString") == "some");
197  phoenix_assert(PString("someString").getCommonBegining("AndsomeOtherString") == "");
198 }
199 
201 void checkFind(){
202  phoenix_assert(!PString("").find('0'));
203  phoenix_assert(!PString("123456").find('0'));
204  phoenix_assert(PString("1230456").find('0'));
205 
206  phoenix_assert(!PString("").find("0"));
207  phoenix_assert(!PString("some char").find(""));
208  phoenix_assert(PString("some char").find("co"));
209  phoenix_assert(!PString("some char").find("zwt"));
210 }
211 
214  phoenix_assert(checkString("test keepChar empty", PString("some text").keepChar(""), ""));
215  phoenix_assert(checkString("test keepChar", PString("some text").keepChar("oest"), "soetet"));
216 }
217 
220  phoenix_assert(PString("").split(' ').size() == 0lu);
221  PVecString vecStr(PString("Some String to split").split(' '));
222  phoenix_assert(vecStr.size() == 4lu);
223  phoenix_assert(PString("").merge(vecStr, " ") == "Some String to split");
224 
225  phoenix_assert(PString("").split("").size() == 0lu);
226  phoenix_assert(PString("Some String").split("").size() == 0lu);
227  phoenix_assert(PString("").split(" ").size() == 0lu);
228 
229  PVecString splitStr(PString("Some String to\tsplit").split(" \t"));
230  phoenix_assert(splitStr.size() == 4lu);
231  phoenix_assert(PString("").merge(splitStr, " ") == "Some String to split");
232 }
233 
235 
240 bool checkEraseFirstChars(const std::string & testName, const std::string & strExpr, const std::string & strReference){
241  PString tmp(strExpr);
242  PString strErase(tmp.eraseFirstChar(" \t\n"));
243  return phoenix_check(testName + "("+strExpr+")", strErase, strReference);
244 }
245 
247 
252 bool checkEraseLastChars(const PString & testName, const PString & strExpr, const PString & strReference){
253  PString tmp(strExpr);
254  PString strErase(tmp.eraseLastChar(" \t\n"));
255  return phoenix_check(testName + "("+strExpr+")", strErase, strReference);
256 }
257 
259 
264 bool checkEraseFirstLastChars(const PString & testName, const PString & strExpr, const PString & strReference){
265  PString tmp(strExpr);
266  PString strErase(tmp.eraseFirstLastChar(" \t\n"));
267  return phoenix_check(testName + "("+strExpr+")", strErase, strReference);
268 }
269 
270 
273  phoenix_assert(checkString("Test eraseChar", PString("").eraseChar('o'), ""));
274  phoenix_assert(checkString("Test eraseChar", PString("").eraseChar("o"), ""));
275  phoenix_assert(checkString("Test eraseChar", PString("some string to be used").eraseChar('o'), "sme string t be used"));
276  phoenix_assert(checkString("Test eraseChar", PString("some string to be used").eraseChar("o"), "sme string t be used"));
277  phoenix_assert(checkString("Test eraseChar", PString("some string to be used").eraseChar("oxi"), "sme strng t be used"));
278 
279  phoenix_assert(checkString("Test eraseLastChar", PString("").eraseLastChar("afe"), ""));
280  phoenix_assert(checkString("Test eraseLastChar", PString("").eraseLastChar("afe"), ""));
281 
282  phoenix_assert(checkEraseFirstChars("Erase first chars 1", "one thing", "one thing"));
283  phoenix_assert(checkEraseFirstChars("Erase first chars 2", " one thing", "one thing"));
284  phoenix_assert(checkEraseFirstChars("Erase first chars 3", "one thing ", "one thing "));
285  phoenix_assert(checkEraseFirstChars("Erase first chars 4", " one thing ", "one thing "));
286 
287  phoenix_assert(checkEraseLastChars("Erase last chars 1", "one thing", "one thing"));
288  phoenix_assert(checkEraseLastChars("Erase last chars 2", " one thing", " one thing"));
289  phoenix_assert(checkEraseLastChars("Erase last chars 3", "one thing ", "one thing"));
290  phoenix_assert(checkEraseLastChars("Erase last chars 4", " one thing ", " one thing"));
291 
292  phoenix_assert(checkEraseFirstLastChars("Erase first last chars 1", "one thing", "one thing"));
293  phoenix_assert(checkEraseFirstLastChars("Erase first last chars 2", " one thing", "one thing"));
294  phoenix_assert(checkEraseFirstLastChars("Erase first last chars 3", "one thing ", "one thing"));
295  phoenix_assert(checkEraseFirstLastChars("Erase first last chars 4", " one thing ", "one thing"));
296 
297  PVecString vecIn;
298  vecIn.push_back(" one thing ");
299  PVecString vecOut = eraseFirstLastChar(vecIn, " ");
300  phoenix_assert(vecOut.size() == 1lu);
301  phoenix_assert(vecOut.front() == "one thing");
302 }
303 
306  phoenix_assert(!PString("").isLowerCase());
307  phoenix_assert(!PString("notOnlyLowerCase").isLowerCase());
308  phoenix_assert(PString("fulllowercase").isLowerCase());
309  phoenix_assert(!PString("").isUpperCase());
310  phoenix_assert(!PString("NOToNLYuPPERcASE").isUpperCase());
311  phoenix_assert(PString("FULLYUPPERCASE").isUpperCase());
312  phoenix_assert(!PString("").isNumber());
313  phoenix_assert(!PString("FULLYUPPERCASE").isNumber());
314  phoenix_assert(PString("12345").isNumber());
315 
316  phoenix_assert(checkString("Test", PString("").toLower(), ""));
317  phoenix_assert(checkString("Test", PString("StRiNg").toLower(), "string"));
318  phoenix_assert(checkString("Test", PString("StRiNg1234").toLower(), "string1234"));
319  phoenix_assert(checkString("Test", PString("ABCDEFGHIJKLMNOPQRSTUVWXYZ").toLower(), "abcdefghijklmnopqrstuvwxyz"));
320  phoenix_assert(checkString("Test", PString("").toUpper(), ""));
321  phoenix_assert(checkString("Test", PString("StRiNg").toUpper(), "STRING"));
322  phoenix_assert(checkString("Test", PString("StRiNg1234").toUpper(), "STRING1234"));
323  phoenix_assert(checkString("Test", PString("abcdefghijklmnopqrstuvwxyz").toUpper(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
324  phoenix_assert(checkString("Test", PString("").firstToLower(), ""));
325  phoenix_assert(checkString("Test", PString("ABC").firstToLower(), "aBC"));
326  phoenix_assert(checkString("Test", PString("aBC").firstToLower(), "aBC"));
327  phoenix_assert(checkString("Test", PString("Vec").firstToLower(), "vec"));
328  phoenix_assert(checkString("Test", PString("").firstToUpper(), ""));
329  phoenix_assert(checkString("Test", PString("ABC").firstToUpper(), "ABC"));
330  phoenix_assert(checkString("Test", PString("Vec").firstToUpper(), "Vec"));
331  phoenix_assert(checkString("Test", PString("aBC").firstToUpper(), "ABC"));
332  phoenix_assert(checkString("Test", PString("vec").firstToUpper(), "Vec"));
333  phoenix_assert(checkString("Test", PString("").toLowerUnderscore(), ""));
334  phoenix_assert(checkString("Test", PString("StringType").toLowerUnderscore(), "stringtype"));
335  phoenix_assert(checkString("Test", PString("String Type").toLowerUnderscore(), "string_type"));
336 }
337 
340  phoenix_assert(phoenix_check("PString::escapeStr", PString("some string with escape's \"char\"").escapeStr(" '\"", "\\"), "some\\ string\\ with\\ escape\\'s\\ \\\"char\\\""));
341 }
342 
345  phoenix_assert(PString::toValue<int>("314") == 314);
346  phoenix_assert(PString::toValue<std::string>("314") == "314");
347 
348  phoenix_assert(PString::toString(true) == "true");
349  phoenix_assert(PString::toString(false) == "false");
350  phoenix_assert(PString::toValue<bool>("true") == true);
351  phoenix_assert(PString::toValue<bool>("false") == false);
352 
353 }
354 
355 int main(int argc, char** argv){
356  testPString();
362  checkFormat();
363  checkCount();
366  checkFind();
367  checkKeepChar();
368  checkSplitMerge();
369  checkEraseChar();
372  return 0;
373 }
374 
375 
PString phoenix_charToString(const char *ch)
Convert a char pointer into a string (event if the char pointer is NULL)
Definition: PString.cpp:14
void eraseFirstLastChar(PVecString &vecOut, const PVecString &vecStr, const PString &vecChar)
Erase first and last characters of all PString in given vector.
Definition: PString.cpp:52
std::vector< PString > PVecString
Definition: PString.h:99
Extends the std::string.
Definition: PString.h:16
PString & fromValue(const T &other)
Convert a value to a PString.
Definition: PString_impl.h:36
static PString toString(const T &value)
Convert a value to a PString.
Definition: PString_impl.h:18
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:251
static T toValue(const PString &other)
Convert the given string into a value.
Definition: PString_impl.h:27
PString format(const PString &arg) const
Replace first {} with arg.
Definition: PString.cpp:345
PString eraseFirstLastChar(const PString &vecChar) const
Erase first and last char in a string.
Definition: PString.cpp:607
PString eraseFirstChar(const PString &vecChar) const
Erase first char in a string.
Definition: PString.cpp:564
PString eraseLastChar(const PString &vecChar) const
Erase first and last char in a string.
Definition: PString.cpp:583
#define phoenix_assert(isOk)
bool phoenix_check(const std::string &testName, const std::string &val, const std::string &reference)
Check two string.
int main(int argc, char **argv)
Definition: main.cpp:362
bool checkString(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string lower expression.
Definition: main.cpp:20
void checkFindPatternIndex()
Check the findPatternIndex method.
Definition: main.cpp:125
void checkEraseChar()
Check erase char.
Definition: main.cpp:272
void checkFormat()
Check format.
Definition: main.cpp:166
bool checkEraseLastChars(const PString &testName, const PString &strExpr, const PString &strReference)
Check the erase last chars.
Definition: main.cpp:252
void checkGetBetweenDelimiter()
Check the getBetweenDelimiter method.
Definition: main.cpp:134
void checkSplitMerge()
Check the split and merge.
Definition: main.cpp:219
void checkGetCommonBegining()
Check the getCommonBegining.
Definition: main.cpp:192
void checkIsSameBegining()
Check isSameBegining.
Definition: main.cpp:157
bool checkEraseFirstChars(const std::string &testName, const std::string &strExpr, const std::string &strReference)
Check the erase first chars.
Definition: main.cpp:240
void checkPStringLowerUpper()
Test lower/upper to string.
Definition: main.cpp:305
void checkCount()
Check count.
Definition: main.cpp:173
void checkValueToStringConvertion()
Test value to string and string to value.
Definition: main.cpp:117
bool checkEraseFirstLastChars(const PString &testName, const PString &strExpr, const PString &strReference)
Check the erase first last chars.
Definition: main.cpp:264
void testPString()
Test the PString.
Definition: main.cpp:25
void checkKeepChar()
Check the keepChar method.
Definition: main.cpp:213
void testEscapeString()
Test the phoenix_escapeStr function.
Definition: main.cpp:339
void testPStringConversion()
Test the PString conversion.
Definition: main.cpp:344
void checkFind()
Check the find method.
Definition: main.cpp:201
void checkPStringReplace()
Check PString Replace.
Definition: main.cpp:140
void checkCharToString()
Check phoenix_charToString.
Definition: main.cpp:186