summaryrefslogtreecommitdiff
path: root/src/utils/xml_unittest.cc
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-11-30 13:59:45 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-20 21:58:39 +0300
commitbc3a7cf853510ffe1e42dc683f854d360f6528c7 (patch)
tree9898f13eafc3e1a20388d8d592bfcc05c8f50ba7 /src/utils/xml_unittest.cc
parenta058af57bddd4a4394401cc75d33461e17aab8c1 (diff)
downloadmv-bc3a7cf853510ffe1e42dc683f854d360f6528c7.tar.gz
mv-bc3a7cf853510ffe1e42dc683f854d360f6528c7.tar.bz2
mv-bc3a7cf853510ffe1e42dc683f854d360f6528c7.tar.xz
mv-bc3a7cf853510ffe1e42dc683f854d360f6528c7.zip
Add pugixml backend incomplete.
Add some defines for xml nodes manipulation. With pugixml backend no xml writing.
Diffstat (limited to 'src/utils/xml_unittest.cc')
-rw-r--r--src/utils/xml_unittest.cc43
1 files changed, 37 insertions, 6 deletions
diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc
index ba89a3b70..24a025e4a 100644
--- a/src/utils/xml_unittest.cc
+++ b/src/utils/xml_unittest.cc
@@ -51,13 +51,15 @@ TEST_CASE("xml doc")
REQUIRE(xmlNameEqual(doc.rootNode(), "skinset") == true);
REQUIRE(xmlNameEqual(doc.rootNode(), "skinset123") == false);
REQUIRE(xmlTypeEqual(doc.rootNode(), XML_ELEMENT_NODE) == true);
+// REQUIRE(XmlHaveChildContent(doc.rootNode()) == true);
}
SECTION("load2")
{
- const std::string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
- "<root><data option1=\"false\" option2=\"true\"/></root>";
- XML::Document doc(xml.c_str(), xml.size());
+ const char *xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<root><data option1=\"false\" option2=\"true\"/>"
+ "<cont>this is test</cont></root>";
+ XML::Document doc(xml, strlen(xml));
REQUIRE(doc.isLoaded() == true);
REQUIRE(doc.isValid() == true);
REQUIRE(doc.rootNode() != nullptr);
@@ -66,6 +68,8 @@ TEST_CASE("xml doc")
REQUIRE(xmlTypeEqual(doc.rootNode(), XML_ELEMENT_NODE) == true);
REQUIRE(XmlHasProp(doc.rootNode(), "option1") == false);
REQUIRE(XmlHasProp(doc.rootNode(), "option123") == false);
+ logger->log("content: '%s'", doc.rootNode().first_child().child_value());
+ REQUIRE(XmlHaveChildContent(doc.rootNode()) == false);
}
SECTION("load3")
@@ -82,6 +86,24 @@ TEST_CASE("xml doc")
REQUIRE(xmlTypeEqual(doc.rootNode(), XML_ELEMENT_NODE) == true);
REQUIRE(XmlHasProp(doc.rootNode(), "option1") == false);
REQUIRE(XmlHasProp(doc.rootNode(), "option123") == false);
+ REQUIRE(XmlHaveChildContent(doc.rootNode()) == false);
+ }
+
+ SECTION("load4")
+ {
+ const char *xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<root>this is test</root>";
+ XML::Document doc(xml, strlen(xml));
+ REQUIRE(doc.isLoaded() == true);
+ REQUIRE(doc.isValid() == true);
+ REQUIRE(doc.rootNode() != nullptr);
+ REQUIRE(xmlNameEqual(doc.rootNode(), "root") == true);
+ REQUIRE(xmlNameEqual(doc.rootNode(), "root123") == false);
+ REQUIRE(xmlTypeEqual(doc.rootNode(), XML_ELEMENT_NODE) == true);
+ REQUIRE(XmlHasProp(doc.rootNode(), "option1") == false);
+ REQUIRE(XmlHasProp(doc.rootNode(), "option123") == false);
+ REQUIRE(XmlHaveChildContent(doc.rootNode()) == true);
+ REQUIRE(!strcmp(XmlChildContent(doc.rootNode()), "this is test"));
}
SECTION("properties")
@@ -101,7 +123,8 @@ TEST_CASE("xml doc")
SkipError_false);
const XmlNodePtr rootNode = doc.rootNode();
- XmlNodePtr node = nullptr;
+// REQUIRE(XmlHaveChildContent(rootNode) == true);
+ XmlNodePtr node = XmlNodeDefault;
for_each_xml_child_node(widgetNode, rootNode)
{
node = widgetNode;
@@ -111,6 +134,7 @@ TEST_CASE("xml doc")
REQUIRE(node != nullptr);
REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true);
REQUIRE(xmlNameEqual(node, "widget") == true);
+// REQUIRE(XmlHaveChildContent(node) == true);
for_each_xml_child_node(optionNode, node)
{
node = optionNode;
@@ -120,6 +144,7 @@ TEST_CASE("xml doc")
REQUIRE(node != nullptr);
REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true);
REQUIRE(xmlNameEqual(node, "option") == true);
+ REQUIRE(XmlHaveChildContent(node) == false);
REQUIRE(XmlHasProp(node, "name") == true);
REQUIRE(XmlHasProp(node, "value") == true);
REQUIRE(XmlHasProp(node, "option123") == false);
@@ -142,10 +167,12 @@ TEST_CASE("xml doc")
REQUIRE(node != nullptr);
REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true);
REQUIRE(xmlNameEqual(node, "widget") == true);
+// REQUIRE(XmlHaveChildContent(node) == true);
node = XML::findFirstChildByName(node, "option");
REQUIRE(node != nullptr);
REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true);
REQUIRE(xmlNameEqual(node, "option") == true);
+ REQUIRE(XmlHaveChildContent(node) == false);
REQUIRE(XmlHasProp(node, "name") == true);
REQUIRE(XmlHasProp(node, "value") == true);
REQUIRE(XmlHasProp(node, "option123") == false);
@@ -163,15 +190,17 @@ TEST_CASE("xml doc")
SECTION("child2")
{
- const std::string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ const char *xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<root><data option1=\"false\" option2=\"true\" "
"option3=\"10.5\"/></root>";
- XML::Document doc(xml.c_str(), xml.size());
+ XML::Document doc(xml, strlen(xml));
const XmlNodePtr rootNode = doc.rootNode();
+ REQUIRE(XmlHaveChildContent(rootNode) == false);
XmlNodePtr node = XML::findFirstChildByName(rootNode, "data");
REQUIRE(node != nullptr);
REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true);
REQUIRE(xmlNameEqual(node, "data") == true);
+ REQUIRE(XmlHaveChildContent(node) == false);
REQUIRE(XmlHasProp(node, "option1") == true);
REQUIRE(XmlHasProp(node, "option123") == false);
REQUIRE(XML::getBoolProperty(node, "option1", true) == false);
@@ -189,10 +218,12 @@ TEST_CASE("xml doc")
"option3=\"10.5\"/><!-- comment --></root>";
XML::Document doc(xml.c_str(), xml.size());
const XmlNodePtr rootNode = doc.rootNode();
+// REQUIRE(XmlHaveChildContent(rootNode) == true);
XmlNodePtr node = XML::findFirstChildByName(rootNode, "data");
REQUIRE(node != nullptr);
REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true);
REQUIRE(xmlNameEqual(node, "data") == true);
+ REQUIRE(XmlHaveChildContent(node) == false);
REQUIRE(XmlHasProp(node, "option1") == true);
REQUIRE(XmlHasProp(node, "option123") == false);
REQUIRE(XML::getBoolProperty(node, "option1", true) == false);