PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
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  PString str = "Some string to modify";
127  phoenix_assert(checkString("Check replace", str.replace("string", "sentence"), "Some sentence to modify"));
128  phoenix_assert(checkString("Check replace", PString("some string to modify").replace("string", "sentence"), "some sentence to modify"));
129 
130  PString str2("Some string to modify");
131  phoenix_assert(checkString("Check replace", str2.replace("string", "sentence", 0lu), "Some string to modify"));
132  phoenix_assert(checkString("Check replace", str2.replace("string", "sentence", 1lu), "Some sentence to modify"));
133 
134  PString str3("Some string to modify with other strings");
135  phoenix_assert(checkString("Check replace", str3.replace("string", "sentence", 1lu), "Some sentence to modify with other strings"));
136  phoenix_assert(checkString("Check replace", str3.replace("string", "violin", 1lu), "Some violin to modify with other strings"));
137 
138  phoenix_assert(checkString("Check replaceChar", PString("some string\nwith\tchar to replace").replaceChar(" \t\n", "_"), "some_string_with_char_to_replace"));
139 }
140 
143  phoenix_assert(PString("").isSameBegining(""));
144  phoenix_assert(!PString("").isSameBegining("d"));
145  phoenix_assert(PString("start").isSameBegining("start"));
146  phoenix_assert(PString("start").isSameBegining("st"));
147  phoenix_assert(!PString("st").isSameBegining("start"));
148 }
149 
151 void checkFormat(){
152  PString str3("Some {} to modify with other {}s");
153  phoenix_assert(checkString("Check format", str3.format("sentence"), "Some sentence to modify with other {}s"));
154  phoenix_assert(checkString("Check format", str3.format("violin"), "Some violin to modify with other {}s"));
155 }
156 
158 void checkCount(){
159  phoenix_assert(PString("").count('o') == 0lu);
160  phoenix_assert(PString("some thing to count").count('o') == 3lu);
161  phoenix_assert(PString("some thing to count").count('w') == 0lu);
162 
163  phoenix_assert(PString("some string with text").count("") == 0lu);
164  phoenix_assert(PString("").count("nothing") == 0lu);
165  phoenix_assert(PString("").count("") == 0lu);
166  phoenix_assert(PString("some string with text").count("with") == 1lu);
167  phoenix_assert(PString("one char and two chars").count("char") == 2lu);
168 }
169 
173  phoenix_assert(phoenix_charToString("some text") == "some text");
174 }
175 
178  phoenix_assert(PString("").getCommonBegining("") == "");
179  phoenix_assert(PString("someString").getCommonBegining("") == "");
180  phoenix_assert(PString("").getCommonBegining("someString") == "");
181  phoenix_assert(PString("someString").getCommonBegining("someOtherString") == "some");
182  phoenix_assert(PString("someString").getCommonBegining("AndsomeOtherString") == "");
183 }
184 
186 void checkFind(){
187  phoenix_assert(!PString("").find('0'));
188  phoenix_assert(!PString("123456").find('0'));
189  phoenix_assert(PString("1230456").find('0'));
190 
191  phoenix_assert(!PString("").find("0"));
192  phoenix_assert(!PString("some char").find(""));
193  phoenix_assert(PString("some char").find("co"));
194  phoenix_assert(!PString("some char").find("zwt"));
195 }
196 
199  phoenix_assert(PString("").split(' ').size() == 0lu);
200  PVecString vecStr(PString("Some String to split").split(' '));
201  phoenix_assert(vecStr.size() == 4lu);
202  phoenix_assert(PString("").merge(vecStr, " ") == "Some String to split");
203 
204  phoenix_assert(PString("").split("").size() == 0lu);
205  phoenix_assert(PString("Some String").split("").size() == 0lu);
206  phoenix_assert(PString("").split(" ").size() == 0lu);
207 
208  PVecString splitStr(PString("Some String to\tsplit").split(" \t"));
209  phoenix_assert(splitStr.size() == 4lu);
210  phoenix_assert(PString("").merge(splitStr, " ") == "Some String to split");
211 }
212 
214 
219 bool checkEraseFirstChars(const std::string & testName, const std::string & strExpr, const std::string & strReference){
220  PString tmp(strExpr);
221  PString strErase(tmp.eraseFirstChar(" \t\n"));
222  return phoenix_check(testName + "("+strExpr+")", strErase, strReference);
223 }
224 
226 
231 bool checkEraseLastChars(const PString & testName, const PString & strExpr, const PString & strReference){
232  PString tmp(strExpr);
233  PString strErase(tmp.eraseLastChar(" \t\n"));
234  return phoenix_check(testName + "("+strExpr+")", strErase, strReference);
235 }
236 
238 
243 bool checkEraseFirstLastChars(const PString & testName, const PString & strExpr, const PString & strReference){
244  PString tmp(strExpr);
245  PString strErase(tmp.eraseFirstLastChar(" \t\n"));
246  return phoenix_check(testName + "("+strExpr+")", strErase, strReference);
247 }
248 
249 
252  phoenix_assert(checkString("Test eraseChar", PString("").eraseChar('o'), ""));
253  phoenix_assert(checkString("Test eraseChar", PString("").eraseChar("o"), ""));
254  phoenix_assert(checkString("Test eraseChar", PString("some string to be used").eraseChar('o'), "sme string t be used"));
255  phoenix_assert(checkString("Test eraseChar", PString("some string to be used").eraseChar("o"), "sme string t be used"));
256  phoenix_assert(checkString("Test eraseChar", PString("some string to be used").eraseChar("oxi"), "sme strng t be used"));
257 
258  phoenix_assert(checkString("Test eraseLastChar", PString("").eraseLastChar("afe"), ""));
259  phoenix_assert(checkString("Test eraseLastChar", PString("").eraseLastChar("afe"), ""));
260 
261  phoenix_assert(checkEraseFirstChars("Erase first chars 1", "one thing", "one thing"));
262  phoenix_assert(checkEraseFirstChars("Erase first chars 2", " one thing", "one thing"));
263  phoenix_assert(checkEraseFirstChars("Erase first chars 3", "one thing ", "one thing "));
264  phoenix_assert(checkEraseFirstChars("Erase first chars 4", " one thing ", "one thing "));
265 
266  phoenix_assert(checkEraseLastChars("Erase last chars 1", "one thing", "one thing"));
267  phoenix_assert(checkEraseLastChars("Erase last chars 2", " one thing", " one thing"));
268  phoenix_assert(checkEraseLastChars("Erase last chars 3", "one thing ", "one thing"));
269  phoenix_assert(checkEraseLastChars("Erase last chars 4", " one thing ", " one thing"));
270 
271  phoenix_assert(checkEraseFirstLastChars("Erase first last chars 1", "one thing", "one thing"));
272  phoenix_assert(checkEraseFirstLastChars("Erase first last chars 2", " one thing", "one thing"));
273  phoenix_assert(checkEraseFirstLastChars("Erase first last chars 3", "one thing ", "one thing"));
274  phoenix_assert(checkEraseFirstLastChars("Erase first last chars 4", " one thing ", "one thing"));
275 
276  PVecString vecIn;
277  vecIn.push_back(" one thing ");
278  PVecString vecOut = eraseFirstLastChar(vecIn, " ");
279  phoenix_assert(vecOut.size() == 1lu);
280  phoenix_assert(vecOut.front() == "one thing");
281 }
282 
285  phoenix_assert(!PString("").isLowerCase());
286  phoenix_assert(!PString("notOnlyLowerCase").isLowerCase());
287  phoenix_assert(PString("fulllowercase").isLowerCase());
288  phoenix_assert(!PString("").isUpperCase());
289  phoenix_assert(!PString("NOToNLYuPPERcASE").isUpperCase());
290  phoenix_assert(PString("FULLYUPPERCASE").isUpperCase());
291  phoenix_assert(!PString("").isNumber());
292  phoenix_assert(!PString("FULLYUPPERCASE").isNumber());
293  phoenix_assert(PString("12345").isNumber());
294 
295  phoenix_assert(checkString("Test", PString("").toLower(), ""));
296  phoenix_assert(checkString("Test", PString("StRiNg").toLower(), "string"));
297  phoenix_assert(checkString("Test", PString("StRiNg1234").toLower(), "string1234"));
298  phoenix_assert(checkString("Test", PString("ABCDEFGHIJKLMNOPQRSTUVWXYZ").toLower(), "abcdefghijklmnopqrstuvwxyz"));
299  phoenix_assert(checkString("Test", PString("").toUpper(), ""));
300  phoenix_assert(checkString("Test", PString("StRiNg").toUpper(), "STRING"));
301  phoenix_assert(checkString("Test", PString("StRiNg1234").toUpper(), "STRING1234"));
302  phoenix_assert(checkString("Test", PString("abcdefghijklmnopqrstuvwxyz").toUpper(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
303  phoenix_assert(checkString("Test", PString("").firstToLower(), ""));
304  phoenix_assert(checkString("Test", PString("ABC").firstToLower(), "aBC"));
305  phoenix_assert(checkString("Test", PString("aBC").firstToLower(), "aBC"));
306  phoenix_assert(checkString("Test", PString("Vec").firstToLower(), "vec"));
307  phoenix_assert(checkString("Test", PString("").firstToUpper(), ""));
308  phoenix_assert(checkString("Test", PString("ABC").firstToUpper(), "ABC"));
309  phoenix_assert(checkString("Test", PString("Vec").firstToUpper(), "Vec"));
310  phoenix_assert(checkString("Test", PString("aBC").firstToUpper(), "ABC"));
311  phoenix_assert(checkString("Test", PString("vec").firstToUpper(), "Vec"));
312  phoenix_assert(checkString("Test", PString("").toLowerUnderscore(), ""));
313  phoenix_assert(checkString("Test", PString("StringType").toLowerUnderscore(), "stringtype"));
314  phoenix_assert(checkString("Test", PString("String Type").toLowerUnderscore(), "string_type"));
315 }
316 
319  phoenix_assert(phoenix_check("PString::escapeStr", PString("some string with escape's \"char\"").escapeStr(" '\"", "\\"), "some\\ string\\ with\\ escape\\'s\\ \\\"char\\\""));
320 }
321 
324  phoenix_assert(PString::toValue<int>("314") == 314);
325  phoenix_assert(PString::toValue<std::string>("314") == "314");
326 
327  phoenix_assert(PString::toString(true) == "true");
328  phoenix_assert(PString::toString(false) == "false");
329  phoenix_assert(PString::toValue<bool>("true") == true);
330  phoenix_assert(PString::toValue<bool>("false") == false);
331 
332 }
333 
334 int main(int argc, char** argv){
335  testPString();
339  checkFormat();
340  checkCount();
343  checkFind();
344  checkSplitMerge();
345  checkEraseChar();
348  return 0;
349 }
350 
351 
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:96
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:204
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:298
PString eraseFirstLastChar(const PString &vecChar) const
Erase first and last char in a string.
Definition: PString.cpp:545
PString eraseFirstChar(const PString &vecChar) const
Erase first char in a string.
Definition: PString.cpp:502
PString eraseLastChar(const PString &vecChar) const
Erase first and last char in a string.
Definition: PString.cpp:521
#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:290
bool checkString(const std::string &testName, const std::string &strValue, const std::string &strReference)
Check string lower expression.
Definition: main.cpp:20
void checkEraseChar()
Check erase char.
Definition: main.cpp:251
void checkFormat()
Check format.
Definition: main.cpp:151
bool checkEraseLastChars(const PString &testName, const PString &strExpr, const PString &strReference)
Check the erase last chars.
Definition: main.cpp:231
void checkSplitMerge()
Check the split and merge.
Definition: main.cpp:198
void checkGetCommonBegining()
Check the getCommonBegining.
Definition: main.cpp:177
void checkIsSameBegining()
Check isSameBegining.
Definition: main.cpp:142
bool checkEraseFirstChars(const std::string &testName, const std::string &strExpr, const std::string &strReference)
Check the erase first chars.
Definition: main.cpp:219
void checkPStringLowerUpper()
Test lower/upper to string.
Definition: main.cpp:284
void checkCount()
Check count.
Definition: main.cpp:158
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:243
void testPString()
Test the PString.
Definition: main.cpp:25
void testEscapeString()
Test the phoenix_escapeStr function.
Definition: main.cpp:318
void testPStringConversion()
Test the PString conversion.
Definition: main.cpp:323
void checkFind()
Check the find method.
Definition: main.cpp:186
void checkPStringReplace()
Check PString Replace.
Definition: main.cpp:125
void checkCharToString()
Check phoenix_charToString.
Definition: main.cpp:171