1 |
|
|
|
2 |
|
|
/*************************************** |
3 |
|
|
Auteur : Pierre Aubert |
4 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
5 |
|
|
Licence : CeCILL-C |
6 |
|
|
****************************************/ |
7 |
|
|
|
8 |
|
|
#include "phoenix_check.h" |
9 |
|
|
#include "file_utils.h" |
10 |
|
|
#include "pxml_utils.h" |
11 |
|
|
|
12 |
|
|
///Check the xml parsing of a file |
13 |
|
|
/** @param fileName : file to be used |
14 |
|
|
* @param inputXml : input xml string |
15 |
|
|
* @param referenceOutputXml : reference output |
16 |
|
|
* @param isSvg : true if the given xml is supposed to be svg |
17 |
|
|
* @return true on success, false otherwise |
18 |
|
|
*/ |
19 |
|
2 |
bool checkParseXmlFile(const std::string & fileName, const std::string & inputXml, const std::string & referenceOutputXml, bool isSvg){ |
20 |
|
2 |
bool b(true); |
21 |
✓ |
2 |
b &= saveFileContent(fileName, inputXml); |
22 |
✓ |
4 |
PXml xml; |
23 |
✓ |
2 |
b &= pxml_parserFile(xml, fileName, isSvg); |
24 |
|
|
|
25 |
✓ |
2 |
std::string convertedXml(pxml_baliseStr(xml, isSvg)); |
26 |
✓✓ |
2 |
b &= phoenix_check("checkParseXmlFile", convertedXml, referenceOutputXml); |
27 |
✓✓ |
2 |
phoenix_functionOk("checkParseXmlFile", b); |
28 |
|
4 |
return b; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
///Check the xml attribute |
32 |
|
|
/** @return true on success, false otherwise |
33 |
|
|
*/ |
34 |
|
1 |
bool checkXmlAttr(){ |
35 |
✓✓ |
2 |
PXmlAttr attr, attr2; |
36 |
✓✓ |
1 |
attr.setName("Name"); |
37 |
✓ |
1 |
attr2 = attr; |
38 |
|
|
|
39 |
|
1 |
bool b(true); |
40 |
✓✓ |
1 |
b &= attr.getName() == attr2.getName(); |
41 |
✓✓ |
1 |
b &= attr.getValue() == attr2.getValue(); |
42 |
|
|
|
43 |
✓✓ |
2 |
PXml xml, xmlChild; |
44 |
|
2 |
std::vector<PXmlAttr> vecAttr; |
45 |
✓ |
1 |
vecAttr.push_back(attr); |
46 |
✓ |
1 |
xml.setVecAttr(vecAttr); |
47 |
✓ |
1 |
xmlChild.setVecAttr(vecAttr); |
48 |
|
|
|
49 |
|
2 |
std::vector<PXml> vecChild; |
50 |
✓ |
1 |
vecChild.push_back(xmlChild); |
51 |
✓ |
1 |
xml.setVecChild(vecChild); |
52 |
|
|
|
53 |
✓ |
1 |
PXml xml2; |
54 |
✓ |
1 |
xml2 = xml; |
55 |
|
|
|
56 |
✓✓✓✓
|
1 |
std::cout << "checkXmlAttr : xml2.getIsText() = " << xml2.getIsText() << std::endl; |
57 |
✓✓ |
1 |
phoenix_functionOk("checkXmlAttr", b); |
58 |
|
2 |
return b; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
///Check the xml parsing |
62 |
|
|
/** @param inputXml : input xml string |
63 |
|
|
* @param referenceOutputXml : reference output |
64 |
|
|
* @param isSvg : true if the given xml is supposed to be svg |
65 |
|
|
* @return true on success, false otherwise |
66 |
|
|
*/ |
67 |
|
12 |
bool checkXmlString(const std::string & inputXml, const std::string & referenceOutputXml, bool isSvg){ |
68 |
✓ |
24 |
PXml xml; |
69 |
✓✓✓ |
12 |
if(!pxml_parserContent(xml, inputXml, isSvg)){ |
70 |
✓✓✓✓
|
1 |
std::cerr << "checkXmlString : cannot parse xml string '"<<inputXml<<"'" << std::endl; |
71 |
|
1 |
return false; |
72 |
|
|
} |
73 |
|
11 |
bool b(true); |
74 |
✓ |
22 |
PXml child; |
75 |
✓✓✓✓
|
11 |
if(pxml_getChildIfExist(child, xml, "g")){ |
76 |
✓ |
2 |
b &= child.getName() == "g"; |
77 |
|
|
} |
78 |
|
|
|
79 |
✓ |
11 |
std::string convertedXml(pxml_baliseStr(xml, isSvg)); |
80 |
✓✓ |
11 |
b &= phoenix_check("checkXmlString", convertedXml, referenceOutputXml); |
81 |
✓✓ |
11 |
phoenix_functionOk("checkXmlString", b); |
82 |
|
11 |
return b; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
///Test to create the XML |
86 |
|
|
/** @return true on success, false otherwise |
87 |
|
|
*/ |
88 |
|
1 |
bool testCreateXml(){ |
89 |
|
1 |
bool b(true); |
90 |
|
|
|
91 |
✓ |
2 |
PXml xml; |
92 |
✓✓✓ |
1 |
pxml_setAttr(xml, "attr", "value"); |
93 |
|
|
|
94 |
✓✓ |
1 |
b &= !pxml_saveFile("nonExistingDir/output.xml", xml); |
95 |
✓✓ |
1 |
b &= pxml_saveFile("output.xml", xml); |
96 |
|
|
|
97 |
✓ |
2 |
PXml balise; |
98 |
✓✓ |
1 |
balise.setName("tmp"); |
99 |
|
|
|
100 |
✓ |
2 |
PXml baliseG; |
101 |
✓✓ |
1 |
baliseG.setName("tmp"); |
102 |
|
|
|
103 |
✓✓ |
1 |
xml.getVecChild().push_back(balise); |
104 |
✓✓ |
1 |
xml.getVecChild().push_back(baliseG); |
105 |
✓✓ |
1 |
xml.getVecChild().push_back(balise); |
106 |
✓✓ |
1 |
xml.getVecChild().push_back(baliseG); |
107 |
✓✓ |
1 |
xml.getVecChild().push_back(balise); |
108 |
✓✓ |
1 |
xml.getVecChild().push_back(baliseG); |
109 |
|
|
|
110 |
✓✓ |
1 |
b &= pxml_saveFile("all.xml", xml); |
111 |
✓✓ |
2 |
PXml clearXml(pxml_eraseVecChild(xml, "tmp")); |
112 |
✓✓ |
1 |
b &= pxml_saveFile("erase.xml", clearXml); |
113 |
✓✓ |
1 |
phoenix_functionOk("testCreateXml", b); |
114 |
|
2 |
return b; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
|
118 |
|
1 |
int main(int argc, char** argv){ |
119 |
✓✓✓✓
|
1 |
bool b(checkParseXmlFile("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)); |
120 |
✓✓✓✓
|
1 |
b &= checkParseXmlFile("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); |
121 |
|
|
|
122 |
✓✓✓ |
1 |
b &= 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); |
123 |
✓✓✓ |
2 |
b &= checkXmlString("<g><b>truc</b><g2>test</g2><g>titi</g><g>toto</g></g>", |
124 |
|
1 |
"<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); |
125 |
✓✓✓ |
2 |
b &= checkXmlString("<svg><g><b>truc</b><g2>test</g2><g>titi</g><g>toto</g></g></svg>", |
126 |
|
1 |
"<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); |
127 |
|
|
|
128 |
✓✓✓ |
2 |
b &= checkXmlString("<svg><g id=\"42\"><b>truc</b><g2>test</g2><g>titi</g><g>toto</g></g></svg>", |
129 |
|
1 |
"<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); |
130 |
|
|
|
131 |
✓✓✓ |
1 |
b &= 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); |
132 |
✓✓✓ |
1 |
b &= 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); |
133 |
✓✓✓ |
1 |
b &= 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); |
134 |
|
|
|
135 |
✓✓✓ |
1 |
b &= 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); |
136 |
|
|
|
137 |
✓✓✓ |
1 |
b &= checkXmlString("<img src=\"image.png\" />", "<root>\n<img src=\"image.png\" />\n</root>\n", false); |
138 |
|
|
|
139 |
✓✓✓ |
1 |
b &= !checkXmlString("empty", "empty not root", true); |
140 |
✓✓✓ |
1 |
b &= !checkXmlString("", "empty", true); |
141 |
|
|
|
142 |
✓✓✓ |
1 |
b &= !checkXmlString("<b>no end", "empty", true); |
143 |
|
|
|
144 |
|
1 |
b &= checkXmlAttr(); |
145 |
|
1 |
b &= testCreateXml(); |
146 |
✓✓ |
1 |
phoenix_functionOk("final", b); |
147 |
|
1 |
return b - 1; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
|