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 "phoenix_assert.h"
9 #include "phoenix_check.h"
10 #include "pxml_utils.h"
11 
13 
19 bool checkParseXmlFile(const PPath & fileName, const PString & inputXml, const PString & referenceOutputXml, bool isSvg){
20  bool b(true);
21  b &= fileName.saveFileContent(inputXml);
22  PXml xml;
23  b &= pxml_parserFile(xml, fileName, isSvg);
24 
25  PString convertedXml(pxml_baliseStr(xml, isSvg));
26  b &= phoenix_check("checkParseXmlFile", convertedXml, referenceOutputXml);
27  return b;
28 }
29 
31 void checkXmlAttr(){
32  PXmlAttr attr, attr2;
33  attr.setName("Name");
34  attr2 = attr;
35 
36  phoenix_assert(attr.getName() == attr2.getName());
37  phoenix_assert(attr.getValue() == attr2.getValue());
38 
39  PXml xml, xmlChild;
40  std::vector<PXmlAttr> vecAttr;
41  vecAttr.push_back(attr);
42  xml.setVecAttr(vecAttr);
43  xmlChild.setVecAttr(vecAttr);
44 
45  std::vector<PXml> vecChild;
46  vecChild.push_back(xmlChild);
47  xml.setVecChild(vecChild);
48 
49  PXml xml2;
50  xml2 = xml;
51 
52  phoenix_assert(!xml2.getIsText());
53 }
54 
56 
61 bool checkXmlString(const PString & inputXml, const PString & referenceOutputXml, bool isSvg){
62  PXml xml;
63  if(!pxml_parserContent(xml, inputXml, isSvg)){
64  std::cerr << "checkXmlString : cannot parse xml string '"<<inputXml<<"'" << std::endl;
65  return false;
66  }
67  bool b(true);
68  PXml child;
69  if(pxml_getChildIfExist(child, xml, "g")){
70  b &= child.getName() == "g";
71  }
72 
73  PString convertedXml(pxml_baliseStr(xml, isSvg));
74  b &= phoenix_check("checkXmlString", convertedXml, referenceOutputXml);
75  return b;
76 }
77 
80  PXml xml;
81  pxml_setAttr(xml, "attr", "value");
82 
83  phoenix_assert(!pxml_saveFile(PPath("nonExistingDir/output.xml"), xml));
84  phoenix_assert(pxml_saveFile(PPath("output.xml"), xml));
85 
86  PXml balise;
87  balise.setName("tmp");
88 
89  PXml baliseG;
90  baliseG.setName("tmp");
91 
92  xml.getVecChild().push_back(balise);
93  xml.getVecChild().push_back(baliseG);
94  xml.getVecChild().push_back(balise);
95  xml.getVecChild().push_back(baliseG);
96  xml.getVecChild().push_back(balise);
97  xml.getVecChild().push_back(baliseG);
98 
99  phoenix_assert(pxml_saveFile(PPath("all.xml"), xml));
100  PXml clearXml(pxml_eraseVecChild(xml, "tmp"));
101  phoenix_assert(pxml_saveFile(PPath("erase.xml"), clearXml));
102 }
103 
104 
105 int main(int argc, char** argv){
106  phoenix_assert(checkParseXmlFile(PPath("file.xml"), "<g><b>truc</b><g>titi</g><g>toto</g></g>", "<root>\n<g>\n<b>\ntruc</b>\n<g>\ntiti</g>\n<g>\ntoto</g>\n</g>\n</root>\n", false));
107  phoenix_assert(checkParseXmlFile(PPath("file.svg"), "some thing to write <b style=\"a very important style\">maybe in bold</b> and some other thing", "<root>some thing to write <b style=\"a very important style\"\n\t>maybe in bold</b> and some other thing</root>", true));
108 
109  phoenix_assert(checkXmlString("<g><b>truc</b><g>titi</g><g>toto</g></g>", "<root>\n<g>\n<b>\ntruc</b>\n<g>\ntiti</g>\n<g>\ntoto</g>\n</g>\n</root>\n", false));
110  phoenix_assert(checkXmlString("<g><b>truc</b><g2>test</g2><g>titi</g><g>toto</g></g>",
111  "<root>\n<g>\n<b>\ntruc</b>\n<g2>\ntest</g2>\n<g>\ntiti</g>\n<g>\ntoto</g>\n</g>\n</root>\n", false));
112  phoenix_assert(checkXmlString("<svg><g><b>truc</b><g2>test</g2><g>titi</g><g>toto</g></g></svg>",
113  "<root>\n<svg>\n<g>\n<b>\ntruc</b>\n<g2>\ntest</g2>\n<g>\ntiti</g>\n<g>\ntoto</g>\n</g>\n</svg>\n</root>\n", false));
114 
115  phoenix_assert(checkXmlString("<svg><g id=\"42\"><b>truc</b><g2>test</g2><g>titi</g><g>toto</g></g></svg>",
116  "<root>\n<svg>\n<g id=\"42\">\n<b>\ntruc</b>\n<g2>\ntest</g2>\n<g>\ntiti</g>\n<g>\ntoto</g>\n</g>\n</svg>\n</root>\n", false));
117 
118  phoenix_assert(checkXmlString("some thing to write <b>maybe in bold</b> and some other thing", "<root>some thing to write <b>maybe in bold</b> and some other thing</root>", true));
119  phoenix_assert(checkXmlString("some thing to write <b >maybe in bold</b> and some other thing", "<root>some thing to write <b>maybe in bold</b> and some other thing</root>", true));
120  phoenix_assert(checkXmlString("some thing to write <b style=\"a very important style\">maybe in bold</b> and some other thing", "<root>some thing to write <b style=\"a very important style\"\n\t>maybe in bold</b> and some other thing</root>", true));
121 
122  phoenix_assert(checkXmlString("<?xml ?><!-- -->some thing to write <b style=\"a very important style\">maybe in bold</b> and some other thing", "<root>some thing to write <b style=\"a very important style\"\n\t>maybe in bold</b> and some other thing</root>", true));
123 
124  phoenix_assert(checkXmlString("<img src=\"image.png\" />", "<root>\n<img src=\"image.png\" />\n</root>\n", false));
125 
126  phoenix_assert(!checkXmlString("empty", "empty not root", true));
127  phoenix_assert(!checkXmlString("", "empty", true));
128  phoenix_assert(!checkXmlString("<b>no end", "empty", true));
129 
130  checkXmlAttr();
131  testCreateXml();
132  return 0;
133 }
134 
135 
Path of a directory or a file.
Definition: PPath.h:17
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:395
Extends the std::string.
Definition: PString.h:16
Attribute from xml.
Definition: PXml.h:30
const PString & getName() const
Get the variable p_name.
Definition: PXml.cpp:68
void setName(const PString &name)
Set the variable p_name, of type 'PString'.
Definition: PXml.cpp:54
const PString & getValue() const
Get the variable p_value.
Definition: PXml.cpp:82
Class used to parse xml.
Definition: PXml.h:54
bool getIsText() const
Get the variable p_isText.
Definition: PXml.cpp:236
void setVecChild(const std ::vector< PXml > &vecChild)
Set the variable p_vecChild, of type 'std ::vector<PXml>'.
Definition: PXml.cpp:187
void setVecAttr(const std ::vector< PXmlAttr > &vecAttr)
Set the variable p_vecAttr, of type 'std ::vector<PXmlAttr>'.
Definition: PXml.cpp:180
const std ::vector< PXml > & getVecChild() const
Get the variable p_vecChild.
Definition: PXml.cpp:264
void setName(const PString &name)
Set the variable p_name, of type 'PString'.
Definition: PXml.cpp:152
const PString & getName() const
Get the variable p_name.
Definition: PXml.cpp:194
#define phoenix_assert(isOk)
bool phoenix_check(const std::string &testName, const std::string &val, const std::string &reference)
Check two string.
PXml pxml_eraseVecChild(const PXml &xml, const PString &childName)
Erase the childs of the current xml if it has childName as name.
Definition: pxml_utils.cpp:288
bool pxml_saveFile(const PPath &fileName, const PXml &xml, bool isSvg)
Save a xml in a file.
Definition: pxml_utils.cpp:308
PString pxml_baliseStr(const PXml &xml, bool isSvg)
Convert xml in string.
Definition: pxml_utils.cpp:318
void pxml_setAttr(PXml &xml, const PString &nameAttr, const PString &valueAttr)
Set a value to an attribute.
Definition: pxml_utils.cpp:270
bool pxml_parserFile(PXml &xml, const PPath &fileName, bool isSvg)
Parse a PXml with a file.
Definition: pxml_utils.cpp:38
bool pxml_getChildIfExist(PXml &match, const PXml &xml, const PString &childName)
Get the child with given name if exist.
Definition: pxml_utils.cpp:215
bool pxml_parserContent(PXml &xml, const PString &fileContent, bool isSvg)
Parse a PXml with a file content.
Definition: pxml_utils.cpp:48
int main(int argc, char **argv)
Definition: main.cpp:290
bool checkParseXmlFile(const PPath &fileName, const PString &inputXml, const PString &referenceOutputXml, bool isSvg)
Check the xml parsing of a file.
Definition: main.cpp:19
void testCreateXml()
Test to create the XML.
Definition: main.cpp:79
void checkXmlAttr()
Check the xml attribute.
Definition: main.cpp:31
bool checkXmlString(const PString &inputXml, const PString &referenceOutputXml, bool isSvg)
Check the xml parsing.
Definition: main.cpp:61