PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
main.cpp File Reference
#include "phoenix_assert.h"
#include "phoenix_check.h"
#include "DicoValue.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

bool checkConstDicoValue (const DicoValue &dico)
 Check a const DicoValue. More...
 
int main (int argc, char **argv)
 
bool saveDico (const DicoValue &dv, const PPath &fileName)
 Save the given DicoValue in the given file. More...
 
bool testDicoBadParsing (const PString &fileContent)
 Check all the bad parsing. More...
 
bool testDicoDicoString (const PPath &fileName)
 Test the DicoValue. More...
 
bool testDicoDicoValueKeyPtr (const DicoValue *dv, int expectedValue)
 Test the value of the given DicoValue. More...
 
bool testDicoGoodParsing (const PString &fileContent)
 Check all the good parsing. More...
 
bool testDicoSaveParsing (const PString &fileContent)
 Check all the bad parsing. More...
 
bool testDicoValue (const PPath &fileName)
 Test the DicoValue. More...
 
bool testDicoValue2 (const PPath &fileName)
 Test the DicoValue. More...
 
bool testDicoValue3 (const PPath &fileName)
 Test the DicoValue. More...
 
bool testDicoValueKey (const DicoValue &dv, int expectedValue)
 Test the value of the given DicoValue. More...
 
bool testDicoValueKey (const DicoValue *dv, int expectedValue)
 Test the value of the given DicoValue. More...
 
bool testDicoValueKeyPtr (const DicoValue *dv, int expectedValue)
 Test the value of the given DicoValue. More...
 
bool testDicoVecString (const PPath &fileName)
 Test the DicoValue. More...
 
bool testDicoVecValue (const PPath &fileName)
 Test the DicoValue. More...
 
bool testDicoVecValueKeyPtr (const DicoValue *dv, int expectedValue)
 Test the value of the given DicoValue. More...
 
void testFromJSonToJSon ()
 Test JSON to JSON convertion. More...
 

Function Documentation

◆ checkConstDicoValue()

bool checkConstDicoValue ( const DicoValue dico)

Check a const DicoValue.

Parameters
dico: DicoValue
Returns
true on success, false otherwise

Definition at line 25 of file main.cpp.

25  {
26  bool b(true);
27  b &= dico.getMap("NonExistingmap") == NULL;
28  return b;
29 }
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
Definition: DicoValue.cpp:116

References DicoValue::getMap().

Referenced by testDicoValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 285 of file main.cpp.

285  {
286  PPath fileName0(CMAKE_CURRENT_TEST_DIR "/testInputDico.txt");
287 
288  phoenix_assert(testDicoValue(fileName0));
289  phoenix_assert(!testDicoValue(PString(fileName0 + "whichDoesnotExist")));
290 
291  PPath fileName2(CMAKE_CURRENT_TEST_DIR "/testInputDicoValue.txt");
292  phoenix_assert(testDicoValue2(fileName2));
293  phoenix_assert(!testDicoValue2(PString(fileName2 + "whichDoesnotExist")));
294 
295  PPath fileName3(CMAKE_CURRENT_TEST_DIR "/testInputDicoValue.txt");
296  phoenix_assert(testDicoValue3(fileName3));
297  phoenix_assert(!testDicoValue3(PString(fileName3 + "whichDoesnotExist")));
298 
299  PPath fileNameVec(CMAKE_CURRENT_TEST_DIR "/testInputDicoVecValue.txt");
300  phoenix_assert(testDicoVecValue(fileNameVec));
301  phoenix_assert(!testDicoVecValue(PString(fileNameVec + "whichDoesnotExist")));
302 
303  PPath fileNameVecString(CMAKE_CURRENT_TEST_DIR "/testInputDicoVecString.txt");
304  phoenix_assert(testDicoVecString(fileNameVecString));
305  phoenix_assert(!testDicoVecString(PString(fileNameVecString + "whichDoesnotExist")));
306 
307  PPath fileNameDicoString(CMAKE_CURRENT_TEST_DIR "/testInputDicoMapDico.txt");
308  phoenix_assert(testDicoDicoString(fileNameDicoString));
309  phoenix_assert(!testDicoDicoString(PString(fileNameDicoString + "whichDoesnotExist")));
310 
311  //Test with a JSON
312  phoenix_assert(testDicoDicoString(PPath(CMAKE_CURRENT_TEST_DIR "/testInputDicoMapDico.json")));
313 
316  phoenix_assert(testDicoGoodParsing("key other"));
317  phoenix_assert(testDicoBadParsing("{ key1 {"));
320  phoenix_assert(testDicoBadParsing("{ key1: °"));
321  phoenix_assert(testDicoSaveParsing("Just some text"));
322  phoenix_assert(testDicoSaveParsing("Just some text\nwith new line"));
323  phoenix_assert(testDicoSaveParsing("Just some text with spécial char/"));
325  return 0;
326 }
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16
#define phoenix_assert(isOk)
bool testDicoVecString(const PPath &fileName)
Test the DicoValue.
Definition: main.cpp:162
void testFromJSonToJSon()
Test JSON to JSON convertion.
Definition: main.cpp:273
bool testDicoValue2(const PPath &fileName)
Test the DicoValue.
Definition: main.cpp:71
bool testDicoVecValue(const PPath &fileName)
Test the DicoValue.
Definition: main.cpp:145
bool testDicoValue3(const PPath &fileName)
Test the DicoValue.
Definition: main.cpp:104
bool testDicoDicoString(const PPath &fileName)
Test the DicoValue.
Definition: main.cpp:215
bool testDicoSaveParsing(const PString &fileContent)
Check all the bad parsing.
Definition: main.cpp:263
bool testDicoBadParsing(const PString &fileContent)
Check all the bad parsing.
Definition: main.cpp:250
bool testDicoValue(const PPath &fileName)
Test the DicoValue.
Definition: main.cpp:35
bool testDicoGoodParsing(const PString &fileContent)
Check all the good parsing.
Definition: main.cpp:237

References phoenix_assert, testDicoBadParsing(), testDicoDicoString(), testDicoGoodParsing(), testDicoSaveParsing(), testDicoValue(), testDicoValue2(), testDicoValue3(), testDicoVecString(), testDicoVecValue(), and testFromJSonToJSon().

+ Here is the call graph for this function:

◆ saveDico()

bool saveDico ( const DicoValue dv,
const PPath fileName 
)

Save the given DicoValue in the given file.

Parameters
dv: DicoValue to be saved
fileName: name of the file to be saved
Returns
true on success, false otherwise

Definition at line 17 of file main.cpp.

17  {
18  return dv.save(fileName.replace(".txt", ".dico").replace(CMAKE_CURRENT_TEST_DIR, CMAKE_CURRENT_BUILD_DIR));
19 }
bool save(const PPath &fileName, const PString &valueDecorator="", PString baseIndentation="\t", PString baseNewLine="\n") const
Save the DicoValue with a text file.
Definition: DicoValue.cpp:53
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:204

References PString::replace(), and DicoValue::save().

Referenced by testDicoDicoString(), testDicoValue(), testDicoValue2(), testDicoValue3(), testDicoVecString(), and testDicoVecValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoBadParsing()

bool testDicoBadParsing ( const PString fileContent)

Check all the bad parsing.

Parameters
fileContent: wrong file content
Returns
true on success, false otherwise

Definition at line 250 of file main.cpp.

250  {
251  PPath fileName("config.txt");
252  bool b(true);
253  b &= fileName.saveFileContent(fileContent);
254  DicoValue dico;
255  b &= !dico.load(fileName);
256  return b;
257 }
Dictionnary of values.
Definition: DicoValue.h:17
bool load(const PPath &fileName)
Load the DicoValue with a text file.
Definition: DicoValue.cpp:40

References DicoValue::load(), and PPath::saveFileContent().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoDicoString()

bool testDicoDicoString ( const PPath fileName)

Test the DicoValue.

Parameters
fileName: name of the file to be used
Returns
true on success, false otherwise

Definition at line 215 of file main.cpp.

215  {
216  DicoValue dv;
217  if(!dv.load(fileName)){
218  std::cerr << "testDicoDicoString : cannot load file '"<<fileName<<"'" << std::endl;
219  return false;
220  }
221  bool b(testDicoDicoValueKeyPtr(dv.getMap("key1"), 1));
222  b &= testDicoDicoValueKeyPtr(dv.getMap("key2"), 2);
223  b &= testDicoDicoValueKeyPtr(dv.getMap("key3"), 3);
224 
225  b &= !testDicoDicoValueKeyPtr(NULL, 0);
226  DicoValue val;
227  b &= !testDicoDicoValueKeyPtr(&val, 0);
228 
229  b &= saveDico(dv, fileName);
230  return b;
231 }
bool testDicoDicoValueKeyPtr(const DicoValue *dv, int expectedValue)
Test the value of the given DicoValue.
Definition: main.cpp:194
bool saveDico(const DicoValue &dv, const PPath &fileName)
Save the given DicoValue in the given file.
Definition: main.cpp:17

References DicoValue::getMap(), DicoValue::load(), saveDico(), and testDicoDicoValueKeyPtr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoDicoValueKeyPtr()

bool testDicoDicoValueKeyPtr ( const DicoValue dv,
int  expectedValue 
)

Test the value of the given DicoValue.

Parameters
dv: DicoValue to be checked
expectedValue: expected value
Returns
true on success, false otherwise

Definition at line 194 of file main.cpp.

194  {
195  if(dv == NULL){
196  std::cerr << "testDicoDicoValueKeyPtr : DicoValue for value "<<expectedValue<<" not found!!!" << std::endl;
197  return false;
198  }
199  const MapDicoValue & mapVal = dv->getMapChild();
200  if(mapVal.size() != 3lu){
201  std::cerr << "testDicoDicoValueKeyPtr : expect 3 value for first value " << expectedValue << std::endl;
202  return false;
203  }
204  bool b(true);
205  b &= testDicoValueKey(dv->getMap("val1"), expectedValue);
206  b &= testDicoValueKey(dv->getMap("val2"), 1 + expectedValue);
207  b &= testDicoValueKey(dv->getMap("val3"), 2 + expectedValue);
208  return b;
209 }
std::map< PString, DicoValue > MapDicoValue
Vector of DicoValue.
Definition: DicoValue.h:79
const std::map< PString, DicoValue > & getMapChild() const
Gets the mapChild of the DicoValue.
Definition: DicoValue.cpp:218
bool testDicoValueKey(const DicoValue &dv, int expectedValue)
Test the value of the given DicoValue.
Definition: main.cpp:62

References DicoValue::getMap(), DicoValue::getMapChild(), and testDicoValueKey().

Referenced by testDicoDicoString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoGoodParsing()

bool testDicoGoodParsing ( const PString fileContent)

Check all the good parsing.

Parameters
fileContent: wrong file content
Returns
true on success, false otherwise

Definition at line 237 of file main.cpp.

237  {
238  PPath fileName("config.txt");
239  bool b(true);
240  b &= fileName.saveFileContent(fileContent);
241  DicoValue dico;
242  b &= dico.load(fileName);
243  return b;
244 }

References DicoValue::load(), and PPath::saveFileContent().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoSaveParsing()

bool testDicoSaveParsing ( const PString fileContent)

Check all the bad parsing.

Parameters
fileContent: wrong file content
Returns
true on success, false otherwise

Definition at line 263 of file main.cpp.

263  {
264  PPath fileName("config_out.txt");
265  bool b(true);
266  DicoValue dico;
267  dico.setValue(fileContent);
268  b &= dico.save(fileName);
269  return b;
270 }
void setValue(const PString &value)
Sets the value of the DicoValue.
Definition: DicoValue.cpp:141

References DicoValue::save(), and DicoValue::setValue().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoValue()

bool testDicoValue ( const PPath fileName)

Test the DicoValue.

Parameters
fileName: name of the file to be used
Returns
true on success, false otherwise

Definition at line 35 of file main.cpp.

35  {
36  DicoValue dv;
37  if(!dv.load(fileName)){
38  std::cerr << "testDicoValue : cannot load file '"<<fileName<<"'" << std::endl;
39  return false;
40  }
41  std::vector<DicoValue> & vecChild = dv.getVecChild();
42 
43  DicoValue & value = dv.getMapChild()["key"];
44  bool b(true);
45  b &= dv.getMap("NonExistingmap") == NULL;
46  b &= checkConstDicoValue(dv);
47  DicoValue dico;
48  dico.setVecChild(dv.getVecChild());
49  dico.setMapChild(dv.getMapChild());
50 
51  std::cout << "testDicoValue : value of key : '" << value.getValue() << "' with key '" << value.getKey() << "', vecChild.size = " << vecChild.size() << std::endl;
52  b &= value.getValue() == "value";
53  b &= saveDico(dv, fileName);
54  return b;
55 }
void setVecChild(const std::vector< DicoValue > &vecChild)
Sets the vecChild of the DicoValue.
Definition: DicoValue.cpp:155
const PString & getKey() const
Gets the key of the DicoValue.
Definition: DicoValue.cpp:190
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
Definition: DicoValue.cpp:204
T getValue() const
Convert the value of the current DicoValue into a type.
void setMapChild(const std::map< PString, DicoValue > &mapChild)
Sets the mapChild of the DicoValue.
Definition: DicoValue.cpp:162
bool checkConstDicoValue(const DicoValue &dico)
Check a const DicoValue.
Definition: main.cpp:25

References checkConstDicoValue(), DicoValue::getKey(), DicoValue::getMap(), DicoValue::getMapChild(), DicoValue::getValue(), DicoValue::getVecChild(), DicoValue::load(), saveDico(), DicoValue::setMapChild(), and DicoValue::setVecChild().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoValue2()

bool testDicoValue2 ( const PPath fileName)

Test the DicoValue.

Parameters
fileName: name of the file to be used
Returns
true on success, false otherwise

Definition at line 71 of file main.cpp.

71  {
72  DicoValue dv;
73  if(!dv.load(fileName)){
74  std::cerr << "testDicoValue2 : cannot load file '"<<fileName<<"'" << std::endl;
75  return false;
76  }
77  bool b(testDicoValueKey(dv.getMapChild()["key1"], 1));
78  b &= testDicoValueKey(dv.getMapChild()["key2"], 2);
79  b &= testDicoValueKey(dv.getMapChild()["key3"], 3);
80  b &= dv.isKeyExist("key3");
81 
82  b &= saveDico(dv, fileName);
83  return b;
84 }
bool isKeyExist(const PString &key) const
Say if the given key exists in the map of children.
Definition: DicoValue.cpp:107

References DicoValue::getMapChild(), DicoValue::isKeyExist(), DicoValue::load(), saveDico(), and testDicoValueKey().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoValue3()

bool testDicoValue3 ( const PPath fileName)

Test the DicoValue.

Parameters
fileName: name of the file to be used
Returns
true on success, false otherwise

Definition at line 104 of file main.cpp.

104  {
105  DicoValue dv;
106  if(!dv.load(fileName)){
107  std::cerr << "testDicoValue3 : cannot load file '"<<fileName<<"'" << std::endl;
108  return false;
109  }
110  bool b(testDicoValueKeyPtr(dv.getMap("key1"), 1));
111  b &= testDicoValueKeyPtr(dv.getMap("key2"), 2);
112  b &= testDicoValueKeyPtr(dv.getMap("key3"), 3);
113  b &= !testDicoValueKeyPtr(NULL, 0);
114  b &= saveDico(dv, fileName);
115  return b;
116 }
bool testDicoValueKeyPtr(const DicoValue *dv, int expectedValue)
Test the value of the given DicoValue.
Definition: main.cpp:91

References DicoValue::getMap(), DicoValue::load(), saveDico(), and testDicoValueKeyPtr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoValueKey() [1/2]

bool testDicoValueKey ( const DicoValue dv,
int  expectedValue 
)

Test the value of the given DicoValue.

Parameters
dv: DicoValue to be checked
expectedValue: expected value
Returns
true on success, false otherwise

Definition at line 62 of file main.cpp.

62  {
63 // std::cout << "testDicoValueKey : key '" << dv.getKey() << "' with value '" << dv.getValue() << "', hasKey = " << dv.hasKey() << "', hasMap = " << dv.hasMap() << "', hasVec = " << dv.hasVec() << std::endl;
64  return phoenix_check("testDicoValueKey", dv.getValue<int>(), expectedValue);
65 }
bool phoenix_check(const std::string &testName, const std::string &val, const std::string &reference)
Check two string.

References DicoValue::getValue(), and phoenix_check().

Referenced by testDicoDicoValueKeyPtr(), and testDicoValue2().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoValueKey() [2/2]

bool testDicoValueKey ( const DicoValue dv,
int  expectedValue 
)

Test the value of the given DicoValue.

Parameters
dv: DicoValue to be checked
expectedValue: expected value
Returns
true on success, false otherwise

Definition at line 185 of file main.cpp.

185  {
186  return phoenix_check("testDicoValueKey", dv->getValue<int>(), expectedValue);
187 }

References DicoValue::getValue(), and phoenix_check().

+ Here is the call graph for this function:

◆ testDicoValueKeyPtr()

bool testDicoValueKeyPtr ( const DicoValue dv,
int  expectedValue 
)

Test the value of the given DicoValue.

Parameters
dv: DicoValue to be checked
expectedValue: expected value
Returns
true on success, false otherwise

Definition at line 91 of file main.cpp.

91  {
92  if(dv == NULL){
93  std::cerr << "testDicoValueKeyPtr : DicoValue for value "<<expectedValue<<" not found!!!" << std::endl;
94  return false;
95  }
96 // std::cout << "testDicoValueKeyPtr : key '" << dv->getKey() << "' with value '" << dv->getValue() << "'" << std::endl;
97  return dv->getValue<int>() == expectedValue;
98 }

References DicoValue::getValue().

Referenced by testDicoValue3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoVecString()

bool testDicoVecString ( const PPath fileName)

Test the DicoValue.

Parameters
fileName: name of the file to be used
Returns
true on success, false otherwise

Definition at line 162 of file main.cpp.

162  {
163  DicoValue dv;
164  if(!dv.load(fileName)){
165  std::cerr << "testDicoVecString : cannot load file '"<<fileName<<"'" << std::endl;
166  return false;
167  }
168  bool b(testDicoVecValueKeyPtr(dv.getMap("key1"), 1));
169  b &= testDicoVecValueKeyPtr(dv.getMap("key2"), 2);
170  b &= testDicoVecValueKeyPtr(dv.getMap("key3"), 3);
171 
172  b &= !testDicoVecValueKeyPtr(NULL, 0);
173  DicoValue val;
174  b &= !testDicoVecValueKeyPtr(&val, 0);
175 
176  b &= saveDico(dv, fileName);
177  return b;
178 }
bool testDicoVecValueKeyPtr(const DicoValue *dv, int expectedValue)
Test the value of the given DicoValue.
Definition: main.cpp:123

References DicoValue::getMap(), DicoValue::load(), saveDico(), and testDicoVecValueKeyPtr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoVecValue()

bool testDicoVecValue ( const PPath fileName)

Test the DicoValue.

Parameters
fileName: name of the file to be used
Returns
true on success, false otherwise

Definition at line 145 of file main.cpp.

145  {
146  DicoValue dv;
147  if(!dv.load(fileName)){
148  std::cerr << "testDicoVecValue : cannot load file '"<<fileName<<"'" << std::endl;
149  return false;
150  }
151  bool b(testDicoVecValueKeyPtr(dv.getMap("key1"), 1));
152  b &= testDicoVecValueKeyPtr(dv.getMap("key2"), 2);
153  b &= testDicoVecValueKeyPtr(dv.getMap("key3"), 3);
154  b &= saveDico(dv, fileName);
155  return b;
156 }

References DicoValue::getMap(), DicoValue::load(), saveDico(), and testDicoVecValueKeyPtr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDicoVecValueKeyPtr()

bool testDicoVecValueKeyPtr ( const DicoValue dv,
int  expectedValue 
)

Test the value of the given DicoValue.

Parameters
dv: DicoValue to be checked
expectedValue: expected value
Returns
true on success, false otherwise

Definition at line 123 of file main.cpp.

123  {
124  if(dv == NULL){
125  std::cerr << "testDicoVecValueKeyPtr : DicoValue for value "<<expectedValue<<" not found!!!" << std::endl;
126  return false;
127  }
128  const VecDicoValue & vecVal = dv->getVecChild();
129  if(vecVal.size() != 3lu){
130  std::cerr << "testDicoVecValueKeyPtr : expect 3 value for first value " << expectedValue << std::endl;
131  return false;
132  }
133  bool b(true);
134  for(int i(0); i < 3; ++i){
135  std::cout << "testDicoVecValueKeyPtr : value["<<i<<"] = " << vecVal[i].getValue<int>() << ", expect = " << (i + expectedValue) << std::endl;
136  b &= vecVal[i].getValue<int>() == expectedValue + i;
137  }
138  return b;
139 }
std::vector< DicoValue > VecDicoValue
Vector of DicoValue.
Definition: DicoValue.h:77

References DicoValue::getVecChild().

Referenced by testDicoVecString(), and testDicoVecValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testFromJSonToJSon()

void testFromJSonToJSon ( )

Test JSON to JSON convertion.

Definition at line 273 of file main.cpp.

273  {
274  PPath fileName(CMAKE_CURRENT_TEST_DIR "/testInputDicoMapDico.json");
275 
276  DicoValue dv;
277  phoenix_assert(dv.load(fileName));
278  phoenix_assert(dv.save(fileName.getFileName(), "\""));
279 
280  DicoValue compact;
281  phoenix_assert(compact.fromString("{\"key1\": \"1\", \"key2\": \"2\", \"key3\": \"3\" }"));
282  phoenix_assert(phoenix_check("Test compact JSON", compact.toString("\"", "", ""), "{\"key1\": \"1\",\"key2\": \"2\",\"key3\": \"3\"}"));
283 }
PString toString(const PString &valueDecorator="", PString baseIndentation="\t", PString baseNewLine="\n") const
Convert the DicoValue into a string.
Definition: DicoValue.cpp:74
bool fromString(const PString &content)
Create a DicoValue from a PString.
Definition: DicoValue.cpp:62

References DicoValue::fromString(), PPath::getFileName(), DicoValue::load(), phoenix_assert, phoenix_check(), DicoValue::save(), and DicoValue::toString().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: