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