diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-19 22:26:08 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-19 22:26:08 +0300 |
commit | 858d471f921c75d3963acff3dd3022b47c96f5dd (patch) | |
tree | a8dcb57ff8a0c963beedf8e0b4a5649c68f8880b /src/utils | |
parent | 3d6211f4d5e744622c8e55ef31b42cf066a32da0 (diff) | |
download | manaplus-858d471f921c75d3963acff3dd3022b47c96f5dd.tar.gz manaplus-858d471f921c75d3963acff3dd3022b47c96f5dd.tar.bz2 manaplus-858d471f921c75d3963acff3dd3022b47c96f5dd.tar.xz manaplus-858d471f921c75d3963acff3dd3022b47c96f5dd.zip |
Add tests for xml macroses.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/xml.cpp | 4 | ||||
-rw-r--r-- | src/utils/xml.h | 4 | ||||
-rw-r--r-- | src/utils/xml_unittest.cc | 26 |
3 files changed, 30 insertions, 4 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 4dc331c4f..4d7688b1b 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -167,7 +167,7 @@ namespace XML xmlChar *const prop = XmlGetProp(node, name); if (prop) { - ret = atoi(reinterpret_cast<char*>(prop)); + ret = atoi(reinterpret_cast<const char*>(prop)); xmlFree(prop); } @@ -241,7 +241,7 @@ namespace XML const char *const name, const bool def) { - const xmlChar *const prop = XmlGetProp(node, name); + xmlChar *const prop = XmlGetProp(node, name); if (XmlStrEqual(prop, "true")) return true; diff --git a/src/utils/xml.h b/src/utils/xml.h index 60c1c94c4..fe56917eb 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -41,8 +41,8 @@ reinterpret_cast<const xmlChar*>(str)) #define XmlTextWriterPtr xmlTextWriterPtr #define xmlTypeEqual(node, typ) ((node)->type == (typ)) -#define XmlHasProp(node, name) xmlHasProp(node, \ - reinterpret_cast<const xmlChar*>(name)) +#define XmlHasProp(node, name) (xmlHasProp(node, \ + reinterpret_cast<const xmlChar*>(name)) != nullptr) #define XmlGetProp(node, name) xmlGetProp(node, \ reinterpret_cast<const xmlChar*>(name)) #define XmlTextWriterStartElement(writer, name) \ diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc index 07edfe7c6..ba89a3b70 100644 --- a/src/utils/xml_unittest.cc +++ b/src/utils/xml_unittest.cc @@ -49,6 +49,8 @@ TEST_CASE("xml doc") REQUIRE(doc.isValid() == true); REQUIRE(doc.rootNode() != nullptr); REQUIRE(xmlNameEqual(doc.rootNode(), "skinset") == true); + REQUIRE(xmlNameEqual(doc.rootNode(), "skinset123") == false); + REQUIRE(xmlTypeEqual(doc.rootNode(), XML_ELEMENT_NODE) == true); } SECTION("load2") @@ -60,6 +62,10 @@ TEST_CASE("xml doc") 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); } SECTION("load3") @@ -72,6 +78,10 @@ TEST_CASE("xml doc") 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); } SECTION("properties") @@ -99,6 +109,7 @@ TEST_CASE("xml doc") break; } REQUIRE(node != nullptr); + REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true); REQUIRE(xmlNameEqual(node, "widget") == true); for_each_xml_child_node(optionNode, node) { @@ -107,7 +118,11 @@ TEST_CASE("xml doc") break; } REQUIRE(node != nullptr); + REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true); REQUIRE(xmlNameEqual(node, "option") == true); + REQUIRE(XmlHasProp(node, "name") == true); + REQUIRE(XmlHasProp(node, "value") == true); + REQUIRE(XmlHasProp(node, "option123") == false); REQUIRE(XML::getProperty(node, "name", "") == "padding"); REQUIRE(XML::langProperty(node, "name", "") == "padding"); REQUIRE(XML::getProperty(node, "value", 0) == 1); @@ -125,10 +140,15 @@ TEST_CASE("xml doc") const XmlNodePtr rootNode = doc.rootNode(); XmlNodePtr node = XML::findFirstChildByName(rootNode, "widget"); REQUIRE(node != nullptr); + REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true); REQUIRE(xmlNameEqual(node, "widget") == true); node = XML::findFirstChildByName(node, "option"); REQUIRE(node != nullptr); + REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true); REQUIRE(xmlNameEqual(node, "option") == true); + REQUIRE(XmlHasProp(node, "name") == true); + REQUIRE(XmlHasProp(node, "value") == true); + REQUIRE(XmlHasProp(node, "option123") == false); REQUIRE(XML::getProperty(node, "name", "") == "padding"); REQUIRE(XML::langProperty(node, "name", "") == "padding"); REQUIRE(XML::langProperty(node, "name123", "") == ""); @@ -150,7 +170,10 @@ TEST_CASE("xml doc") const XmlNodePtr rootNode = doc.rootNode(); XmlNodePtr node = XML::findFirstChildByName(rootNode, "data"); REQUIRE(node != nullptr); + REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true); REQUIRE(xmlNameEqual(node, "data") == true); + REQUIRE(XmlHasProp(node, "option1") == true); + REQUIRE(XmlHasProp(node, "option123") == false); REQUIRE(XML::getBoolProperty(node, "option1", true) == false); REQUIRE(XML::getBoolProperty(node, "option2", false) == true); const float opt3 = XML::getFloatProperty(node, "option3", 0.0); @@ -168,7 +191,10 @@ TEST_CASE("xml doc") const XmlNodePtr rootNode = doc.rootNode(); XmlNodePtr node = XML::findFirstChildByName(rootNode, "data"); REQUIRE(node != nullptr); + REQUIRE(xmlTypeEqual(node, XML_ELEMENT_NODE) == true); REQUIRE(xmlNameEqual(node, "data") == true); + REQUIRE(XmlHasProp(node, "option1") == true); + REQUIRE(XmlHasProp(node, "option123") == false); REQUIRE(XML::getBoolProperty(node, "option1", true) == false); REQUIRE(XML::getBoolProperty(node, "option2", false) == true); const float opt3 = XML::getFloatProperty(node, "option3", 0.0); |