PhoenixGenerator  2.0.0
Set of tools to generate code
main.cpp File Reference
#include "phoenix_assert.h"
#include "parser_toml.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

bool checkIsParserOk (const PPath &fileName, const PString &fileContent)
 Check if the parsing of a file is OK. More...
 
bool checkKeyMapValue (const DicoValue *mapKey, const PString &expectedValue)
 Check the value of a DicoValue. More...
 
bool checkKeyMapVecValue (const DicoValue *mapKey, const PVecString &vecExpectedValue)
 Check the value of a DicoValue. More...
 
void checkParserToml ()
 Check the YML parser. More...
 
void checkParserTomlFail ()
 Check the YML parser. More...
 
void checkTomlCompactDico ()
 Check the compact dico. More...
 
void checkTomlCompactDico2 ()
 Check the compact dico. More...
 
void checkTomlEmptyList ()
 Check the embeded dico. More...
 
void checkTomlList ()
 Check the embeded dico. More...
 
void checkTomNestedlList ()
 Check the embeded dico. More...
 
void checkTomNestedlMap ()
 Check the embeded dico. More...
 
void checkTomTable ()
 Check the embeded dico. More...
 
int main (int argc, char **argv)
 
void testCheckValue ()
 Call the check value with NULL pointers. More...
 

Function Documentation

◆ checkIsParserOk()

bool checkIsParserOk ( const PPath fileName,
const PString fileContent 
)

Check if the parsing of a file is OK.

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

Definition at line 289 of file main.cpp.

289  {
290  bool b(true);
291  b &= fileName.saveFileContent(fileContent);
292  DicoValue dico;
293  b &= parser_toml(dico, fileName);
294  return b;
295 }
Dictionnary of values.
Definition: DicoValue.h:17
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:395
bool parser_toml(DicoValue &dico, const PPath &fileName)

References parser_toml(), and PPath::saveFileContent().

Referenced by checkParserTomlFail().

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

◆ checkKeyMapValue()

bool checkKeyMapValue ( const DicoValue mapKey,
const PString expectedValue 
)

Check the value of a DicoValue.

Parameters
mapKey: DicoValue to be checked
expectedValue: expected value
Returns
true if the value matches the expectedValue, false otherwise

Definition at line 16 of file main.cpp.

16  {
17  if(mapKey == NULL){
18  std::cout << "checkKeyMapValue : map NULL for expectedValue = '"<<expectedValue<<"'" << std::endl;
19  return expectedValue == "";
20  }
21 // std::cout << "checkKeyMapValue : map '"<<mapKey->getKey()<<"' => '"<<mapKey->getValue()<<"', expectedValue = '"<<expectedValue<<"'" << std::endl;
22  bool b(mapKey->getValue() == expectedValue);
23 // std::cout << "checkKeyMapValue : b = " << b << std::endl;
24  return b;
25 }
T getValue() const
Convert the value of the current DicoValue into a type.

References DicoValue::getValue().

Referenced by checkParserToml(), checkTomlCompactDico(), checkTomlCompactDico2(), checkTomlList(), checkTomNestedlMap(), checkTomTable(), and testCheckValue().

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

◆ checkKeyMapVecValue()

bool checkKeyMapVecValue ( const DicoValue mapKey,
const PVecString vecExpectedValue 
)

Check the value of a DicoValue.

Parameters
mapKey: DicoValue to be checked
expectedValue: expected value
Returns
true if the value matches the expectedValue, false otherwise

Definition at line 32 of file main.cpp.

32  {
33  if(mapKey == NULL){
34  std::cout << "checkKeyMapVecValue : map NULL for vecExpectedValue = " << std::endl;
35 // phoenix_print(vecExpectedValue);
36  return vecExpectedValue.size() == 0lu;
37  }
38 // std::cout << "checkKeyMapVecValue : map '"<<mapKey->getKey()<<"' => '"<<mapKey->getValue()<<"', vecExpectedValue = " << std::endl;
39 // phoenix_print(vecExpectedValue);
40  bool b(true);
41  const VecDicoValue & vecValue = mapKey->getVecChild();
42  b &= vecValue.size() == vecExpectedValue.size();
43 // std::cout << "checkKeyMapVecValue : vecValue.size() = " << vecValue.size() << ", vecExpectedValue.size() = "<< vecExpectedValue.size() << ", isOk = " << b << std::endl;
44  VecDicoValue::const_iterator it(vecValue.begin());
45  PVecString::const_iterator itRef(vecExpectedValue.begin());
46  while(b && it != vecValue.end() && itRef != vecExpectedValue.end()){
47  b &= it->getValue() == *itRef;
48  std::cout << "\tvalue = '" << it->getValue() << "', reference = '"<< *itRef << "', isOk = " << b << std::endl;
49  ++it;
50  ++itRef;
51  }
52 // std::cout << "checkKeyMapVecValue : b = " << b << std::endl;
53  return b;
54 }
std::vector< DicoValue > VecDicoValue
Vector of DicoValue.
Definition: DicoValue.h:77
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
Definition: DicoValue.cpp:204

References DicoValue::getVecChild().

Referenced by checkTomlList(), and testCheckValue().

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

◆ checkParserToml()

void checkParserToml ( )

Check the YML parser.

Definition at line 64 of file main.cpp.

64  {
65  PString fileContent("[package]\nname = \"hello_hdf5\"\ndescription = \"some string in double quotes\"\nenable_option = true\ndisable_option = false\n\n");
66  PPath tomlFile("test.toml");
67  phoenix_assert(tomlFile.saveFileContent(fileContent));
68 
69  DicoValue dico;
70  phoenix_assert(parser_toml(dico, tomlFile));
71 // std::cout << "checkParserToml : output DicoValue :" << std::endl;
72 // dico.print();
73 
74  DicoValue * mapPackage = dico.getMap("package");
75 // bool isKeyExist = mapPackage != NULL;
76 // std::cout << "checkParserToml : isKeyExist = " << isKeyExist << std::endl;
77  DicoValue * mapPackageName = mapPackage->getMap("name");
78  phoenix_assert(checkKeyMapValue(mapPackageName, "\"hello_hdf5\""));
79 
80  phoenix_assert(phoenix_get_string(*mapPackage, "name", "SomeVar", "") == "hello_hdf5");
81  phoenix_assert(phoenix_get_string(*mapPackage, "undefined_var", "SomeVar", "") == "SomeVar");
82  phoenix_assert(phoenix_get_string(*mapPackage, "undefined_var", "", "SomeVar") == "SomeVar");
83  phoenix_assert(phoenix_get_string(*mapPackage, "undefined_var", "SomeVar") == "SomeVar");
84 
85  DicoValue * mapPackageEnableOption = mapPackage->getMap("enable_option");
86  phoenix_assert(checkKeyMapValue(mapPackageEnableOption, "true"));
87 
88  DicoValue * mapPackageDisableOption = mapPackage->getMap("disable_option");
89  phoenix_assert(checkKeyMapValue(mapPackageDisableOption, "false"));
90 }
bool checkKeyMapValue(const DicoValue *mapKey, const PString &expectedValue)
Check the value of a DicoValue.
Definition: main.cpp:16
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
Definition: DicoValue.cpp:116
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16
#define phoenix_assert(isOk)
PString phoenix_get_string(const DicoValue &dico, const PString &varName, const PString &defaultValue)
Get the string from a dictionnary.

References checkKeyMapValue(), DicoValue::getMap(), parser_toml(), phoenix_assert, phoenix_get_string(), and PPath::saveFileContent().

Referenced by main().

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

◆ checkParserTomlFail()

void checkParserTomlFail ( )

Check the YML parser.

Definition at line 298 of file main.cpp.

298  {
299  DicoValue dico;
300  phoenix_assert(!parser_toml(dico, PString("UnexsitingFileName.toml")));
301  phoenix_assert(!checkIsParserOk(PString("unextected_token.toml"), "=\n"));
302  phoenix_assert(!checkIsParserOk(PString("missing_equal_of_variable.toml"), "[package]\nvariable value\n"));
303  phoenix_assert(!checkIsParserOk(PString("missing_value_of_variable.toml"), "[package]\nvariable =\n"));
304  phoenix_assert(!checkIsParserOk(PString("unclosed_list.toml"), "[package]\nlist = [42\n"));
305  phoenix_assert(!checkIsParserOk(PString("unclosed_empty_list.toml"), "[package]\nlist = [\n"));
306  phoenix_assert(!checkIsParserOk(PString("unclosed_dico.toml"), "[package]\ndico = {name\n"));
307  phoenix_assert(!checkIsParserOk(PString("unclosed_empty_dico.toml"), "[package]\ndico = {\n"));
308  phoenix_assert(checkIsParserOk(PString("some_comment.toml"), "# Some value\n[package]\nvalue = 42\n"));
309  phoenix_assert(checkIsParserOk(PString("some_triple_double_quote_string.toml"), "# Some value\n[package]\nstrvalue = \"\"\"\nsome string\n\"\"\"\n"));
310 }
bool checkIsParserOk(const PPath &fileName, const PString &fileContent)
Check if the parsing of a file is OK.
Definition: main.cpp:289

References checkIsParserOk(), parser_toml(), and phoenix_assert.

Referenced by main().

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

◆ checkTomlCompactDico()

void checkTomlCompactDico ( )

Check the compact dico.

Definition at line 243 of file main.cpp.

243  {
244  PString fileContent("[program]\nname = {url = \"someUrl\"}\nage = 42\n\n");
245 
246  PPath tomlFile("test_toml_compact_dico.toml");
247  phoenix_assert(tomlFile.saveFileContent(fileContent));
248 
249  DicoValue dico;
250  phoenix_assert(parser_toml(dico, tomlFile));
251 // std::cout << "checkTomlCompactDico : output DicoValue :" << std::endl;
252 // dico.print();
253  DicoValue * mapProgram = dico.getMap("program");
254 // bool isKeyExist = mapProgram != NULL;
255 // std::cout << "checkTomlCompactDico : isKeyExist = " << isKeyExist << std::endl;
256  const DicoValue * mapName = mapProgram->getMap("name");
257  const DicoValue * mapNameUrl = mapName->getMap("url");
258  phoenix_assert(checkKeyMapValue(mapNameUrl, "\"someUrl\""));
259  const DicoValue * mapAge = mapProgram->getMap("age");
260  phoenix_assert(checkKeyMapValue(mapAge, "42"));
261 }

References checkKeyMapValue(), DicoValue::getMap(), parser_toml(), phoenix_assert, and PPath::saveFileContent().

Referenced by main().

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

◆ checkTomlCompactDico2()

void checkTomlCompactDico2 ( )

Check the compact dico.

Definition at line 264 of file main.cpp.

264  {
265  PString fileContent("[program]\nname = {url = \"someUrl\",\n#Some comment\n version = \"1.0.0\"}\n# Some Comment\nage = 42\nemptyDico = {}\n\n");
266  PPath tomlFile("test_toml_compact_dico.toml");
267  phoenix_assert(tomlFile.saveFileContent(fileContent));
268  DicoValue dico;
269  phoenix_assert(parser_toml(dico, tomlFile));
270 // std::cout << "checkTomlCompactDico : output DicoValue :" << std::endl;
271 // dico.print();
272  DicoValue * mapProgram = dico.getMap("program");
273 // bool isKeyExist = mapProgram != NULL;
274 // std::cout << "checkTomlCompactDico : isKeyExist = " << isKeyExist << std::endl;
275  const DicoValue * mapName = mapProgram->getMap("name");
276  const DicoValue * mapNameUrl = mapName->getMap("url");
277  phoenix_assert(checkKeyMapValue(mapNameUrl, "\"someUrl\""));
278  const DicoValue * mapNameVersion = mapName->getMap("version");
279  phoenix_assert(checkKeyMapValue(mapNameVersion, "\"1.0.0\""));
280  const DicoValue * mapAge = mapProgram->getMap("age");
281  phoenix_assert(checkKeyMapValue(mapAge, "42"));
282 }

References checkKeyMapValue(), DicoValue::getMap(), parser_toml(), phoenix_assert, and PPath::saveFileContent().

Referenced by main().

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

◆ checkTomlEmptyList()

void checkTomlEmptyList ( )

Check the embeded dico.

Definition at line 141 of file main.cpp.

141  {
142  PString fileContent("[package]\nsome_list = []\n\n");
143 
144  PPath tomlFile("test_toml_empty_list.toml");
145  phoenix_assert(tomlFile.saveFileContent(fileContent));
146 
147  DicoValue dico;
148  phoenix_assert(parser_toml(dico, tomlFile));
149 // std::cout << "checkTomlEmptyList : output DicoValue :" << std::endl;
150 // dico.print();
151 
152  DicoValue * mapPackage = dico.getMap("package");
153 // bool isKeyExist = mapPackage != NULL;
154 // std::cout << "checkTomlEmptyList : isKeyExist = " << isKeyExist << std::endl;
155 
156  DicoValue * mapSomeListKey = mapPackage->getMap("some_list");
157 // bool isSomeListExist = mapSomeListKey != NULL;
158 // std::cout << "checkTomlEmptyList : isSomeListExist = " << isSomeListExist << std::endl;
159  phoenix_assert(mapSomeListKey->getVecChild().size() == 0lu);
160 }

References DicoValue::getMap(), DicoValue::getVecChild(), parser_toml(), phoenix_assert, and PPath::saveFileContent().

Referenced by main().

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

◆ checkTomlList()

void checkTomlList ( )

Check the embeded dico.

Definition at line 93 of file main.cpp.

93  {
94  PString fileContent("[package]\nname = \"hello_hdf5\"\ndescription = 'some string in simple quotes'\nsome_list = [\"one\", \"two\", \"three\"]\nlist_value = [1, 2, 3, 4]\n\n[dependencies]\nhdf5 = \"0.8.1\"\nndarray = '0.15.6'\n\n");
95 
96  PPath tomlFile("test_toml_list.toml");
97  phoenix_assert(tomlFile.saveFileContent(fileContent));
98 
99  DicoValue dico;
100  phoenix_assert(parser_toml(dico, tomlFile));
101 // std::cout << "checkTomlList : output DicoValue :" << std::endl;
102 // dico.print();
103 
104  DicoValue * mapPackage = dico.getMap("package");
105 // bool isKeyExist = mapPackage != NULL;
106 // std::cout << "checkTomlList : isKeyExist = " << isKeyExist << std::endl;
107  DicoValue * mapPackageName = mapPackage->getMap("name");
108  phoenix_assert(checkKeyMapValue(mapPackageName, "\"hello_hdf5\""));
109  DicoValue * mapPackageDescription = mapPackage->getMap("description");
110  phoenix_assert(checkKeyMapValue(mapPackageDescription, "'some string in simple quotes'"));
111 
112  DicoValue * mapSomeListKey = mapPackage->getMap("some_list");
113 // bool isSomeListExist = mapSomeListKey != NULL;
114 // std::cout << "checkTomlList : isSomeListExist = " << isSomeListExist << std::endl;
115 
116  PVecString vecExpectedValue;
117  vecExpectedValue.push_back("\"one\"");
118  vecExpectedValue.push_back("\"two\"");
119  vecExpectedValue.push_back("\"three\"");
120  phoenix_assert(checkKeyMapVecValue(mapSomeListKey, vecExpectedValue));
121 
122  DicoValue * mapOtherListKey = mapPackage->getMap("list_value");
123 // bool isOtherListExist = mapOtherListKey != NULL;
124 // std::cout << "checkTomlList : isOtherListExist = " << isOtherListExist << std::endl;
125 
126  PVecString vecOtherExpectedValue;
127  vecOtherExpectedValue.push_back("1");
128  vecOtherExpectedValue.push_back("2");
129  vecOtherExpectedValue.push_back("3");
130  vecOtherExpectedValue.push_back("4");
131  phoenix_assert(checkKeyMapVecValue(mapOtherListKey, vecOtherExpectedValue));
132 
133  DicoValue * mapDependencies = dico.getMap("dependencies");
134  DicoValue * mapDependenciesHdf5 = mapDependencies->getMap("hdf5");
135  phoenix_assert(checkKeyMapValue(mapDependenciesHdf5, "\"0.8.1\""));
136  DicoValue * mapDependenciesNdarray = mapDependencies->getMap("ndarray");
137  phoenix_assert(checkKeyMapValue(mapDependenciesNdarray, "'0.15.6'"));
138 }
std::vector< PString > PVecString
Definition: PString.h:96
bool checkKeyMapVecValue(const DicoValue *mapKey, const PVecString &vecExpectedValue)
Check the value of a DicoValue.
Definition: main.cpp:32

References checkKeyMapValue(), checkKeyMapVecValue(), DicoValue::getMap(), parser_toml(), phoenix_assert, and PPath::saveFileContent().

Referenced by main().

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

◆ checkTomNestedlList()

void checkTomNestedlList ( )

Check the embeded dico.

Definition at line 164 of file main.cpp.

164  {
165  PString fileContent("[package]\nsome_nested_list = [1, 2, [3, 4]]\n\n");
166 
167  PPath tomlFile("test_toml_nested_list.toml");
168  phoenix_assert(tomlFile.saveFileContent(fileContent));
169 
170  DicoValue dico;
171  phoenix_assert(parser_toml(dico, tomlFile));
172 // std::cout << "checkTomlNestedList : output DicoValue :" << std::endl;
173 // dico.print();
174 
175  DicoValue * mapPackage = dico.getMap("package");
176 // bool isKeyExist = mapPackage != NULL;
177 // std::cout << "checkTomlNestedList : isKeyExist = " << isKeyExist << std::endl;
178  DicoValue * mapOtherListKey = mapPackage->getMap("some_nested_list");
179 // bool isOtherListExist = mapOtherListKey != NULL;
180 // std::cout << "checkTomlNestedList : isOtherListExist = " << isOtherListExist << std::endl;
181 
182  const VecDicoValue & vecValue = mapOtherListKey->getVecChild();
183  phoenix_assert(vecValue.size() == 3lu);
184  phoenix_assert(vecValue[0].getValue() == "1");
185  phoenix_assert(vecValue[1].getValue() == "2");
186 
187  const DicoValue & subList = vecValue[2];
188  const VecDicoValue & vecSubValue = subList.getVecChild();
189  phoenix_assert(vecSubValue.size() == 2lu);
190  phoenix_assert(vecSubValue[0].getValue() == "3");
191  phoenix_assert(vecSubValue[1].getValue() == "4");
192 }

References DicoValue::getMap(), DicoValue::getVecChild(), parser_toml(), phoenix_assert, and PPath::saveFileContent().

Referenced by main().

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

◆ checkTomNestedlMap()

void checkTomNestedlMap ( )

Check the embeded dico.

Definition at line 196 of file main.cpp.

196  {
197  PString fileContent("[first.second]\nsome_value = 42\n\n");
198 
199  PPath tomlFile("test_toml_nested_map.toml");
200  phoenix_assert(tomlFile.saveFileContent(fileContent));
201 
202  DicoValue dico;
203  phoenix_assert(parser_toml(dico, tomlFile));
204 // std::cout << "checkTomNestedlMap : output DicoValue :" << std::endl;
205 // dico.print();
206 
207  DicoValue * mapFirst = dico.getMap("first");
208 // bool isKeyExist = mapFirst != NULL;
209 // std::cout << "checkTomNestedlMap : isKeyExist = " << isKeyExist << std::endl;
210  DicoValue * mapSecond = mapFirst->getMap("second");
211  DicoValue * mapOtherListKey = mapSecond->getMap("some_value");
212  phoenix_assert(checkKeyMapValue(mapOtherListKey, "42"));
213 }

References checkKeyMapValue(), DicoValue::getMap(), parser_toml(), phoenix_assert, and PPath::saveFileContent().

Referenced by main().

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

◆ checkTomTable()

void checkTomTable ( )

Check the embeded dico.

Definition at line 216 of file main.cpp.

216  {
217  PString fileContent("[[program]]\nname = \"shadok\"\nage = 42\n\n[[program]]\nname = \"gibi\"\nage = 23\n\n");
218 
219  PPath tomlFile("test_toml_table.toml");
220  phoenix_assert(tomlFile.saveFileContent(fileContent));
221 
222  DicoValue dico;
223  phoenix_assert(parser_toml(dico, tomlFile));
224 // std::cout << "checkTomTable : output DicoValue :" << std::endl;
225 // dico.print();
226  DicoValue * mapProgram = dico.getMap("program");
227 // bool isKeyExist = mapProgram != NULL;
228 // std::cout << "checkTomTable : isKeyExist = " << isKeyExist << std::endl;
229  const VecDicoValue & vecProgramValue = mapProgram->getVecChild();
230  phoenix_assert(vecProgramValue.size() == 2lu);
231  const DicoValue * mapProgram0Name = vecProgramValue[0].getMap("name");
232  phoenix_assert(checkKeyMapValue(mapProgram0Name, "\"shadok\""));
233  const DicoValue * mapProgram0Age = vecProgramValue[0].getMap("age");
234  phoenix_assert(checkKeyMapValue(mapProgram0Age, "42"));
235 
236  const DicoValue * mapProgram1Name = vecProgramValue[1].getMap("name");
237  phoenix_assert(checkKeyMapValue(mapProgram1Name, "\"gibi\""));
238  const DicoValue * mapProgram1Age = vecProgramValue[1].getMap("age");
239  phoenix_assert(checkKeyMapValue(mapProgram1Age, "23"));
240 }

References checkKeyMapValue(), DicoValue::getMap(), DicoValue::getVecChild(), parser_toml(), phoenix_assert, and PPath::saveFileContent().

Referenced by main().

+ 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 312 of file main.cpp.

312  {
313  testCheckValue();
315  checkParserToml();
316  checkTomlList();
320  checkTomTable();
323  return 0;
324 }
void checkTomlList()
Check the embeded dico.
Definition: main.cpp:93
void testCheckValue()
Call the check value with NULL pointers.
Definition: main.cpp:57
void checkTomlCompactDico2()
Check the compact dico.
Definition: main.cpp:264
void checkTomTable()
Check the embeded dico.
Definition: main.cpp:216
void checkTomlCompactDico()
Check the compact dico.
Definition: main.cpp:243
void checkTomNestedlMap()
Check the embeded dico.
Definition: main.cpp:196
void checkTomNestedlList()
Check the embeded dico.
Definition: main.cpp:164
void checkParserToml()
Check the YML parser.
Definition: main.cpp:64
void checkParserTomlFail()
Check the YML parser.
Definition: main.cpp:298
void checkTomlEmptyList()
Check the embeded dico.
Definition: main.cpp:141

References checkParserToml(), checkParserTomlFail(), checkTomlCompactDico(), checkTomlCompactDico2(), checkTomlEmptyList(), checkTomlList(), checkTomNestedlList(), checkTomNestedlMap(), checkTomTable(), and testCheckValue().

+ Here is the call graph for this function:

◆ testCheckValue()

void testCheckValue ( )

Call the check value with NULL pointers.

Definition at line 57 of file main.cpp.

57  {
58  checkKeyMapValue(NULL, "");
59  PVecString vecNoValue;
60  checkKeyMapVecValue(NULL, vecNoValue);
61 }

References checkKeyMapValue(), and checkKeyMapVecValue().

Referenced by main().

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