diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_document.cpp | 2 | ||||
| -rw-r--r-- | tests/test_dom_modify.cpp | 98 | ||||
| -rw-r--r-- | tests/test_dom_text.cpp | 14 | ||||
| -rw-r--r-- | tests/test_header_only.cpp | 16 | 
4 files changed, 110 insertions, 20 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp index f57465f..ebcdcd1 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -323,7 +323,7 @@ TEST(document_load_file_wide_ascii)  	CHECK_NODE(doc, STR("<node />"));  } -#if !defined(__DMC__) && !defined(__MWERKS__) && !(defined(__MINGW32__) && defined(__STRICT_ANSI__) && __GNUC__ * 100 + __GNUC_MINOR__ <= 405) +#if !defined(__DMC__) && !defined(__MWERKS__) && !(defined(__MINGW32__) && defined(__STRICT_ANSI__) && !defined(__MINGW64_VERSION_MAJOR))  TEST(document_load_file_wide_unicode)  {  	pugi::xml_document doc; diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 9c9109b..f8a8b2f 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -2,6 +2,7 @@  #include <limits>  #include <string> +#include <cmath>  TEST_XML(dom_attr_assign, "<node/>")  { @@ -21,10 +22,13 @@ TEST_XML(dom_attr_assign, "<node/>")  	node.append_attribute(STR("attr6")) = 0.5;  	xml_attribute() = 0.5; -	node.append_attribute(STR("attr7")) = true; +	node.append_attribute(STR("attr7")) = 0.25f; +	xml_attribute() = 0.25f; + +	node.append_attribute(STR("attr8")) = true;  	xml_attribute() = true; -	CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"true\" />")); +	CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" />"));  }  TEST_XML(dom_attr_set_name, "<node attr='value' />") @@ -55,10 +59,13 @@ TEST_XML(dom_attr_set_value, "<node/>")  	CHECK(node.append_attribute(STR("attr6")).set_value(0.5));  	CHECK(!xml_attribute().set_value(0.5)); -	CHECK(node.append_attribute(STR("attr7")).set_value(true)); +	CHECK(node.append_attribute(STR("attr7")).set_value(0.25f)); +	CHECK(!xml_attribute().set_value(0.25f)); + +	CHECK(node.append_attribute(STR("attr8")).set_value(true));  	CHECK(!xml_attribute().set_value(true)); -	CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"true\" />")); +	CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" />"));  }  #ifdef PUGIXML_HAS_LONG_LONG @@ -93,6 +100,17 @@ TEST_XML(dom_attr_set_value_llong, "<node/>")  }  #endif +TEST_XML(dom_attr_assign_large_number, "<node attr1='' attr2='' />") +{ +	xml_node node = doc.child(STR("node")); + +	node.attribute(STR("attr1")) = std::numeric_limits<float>::max(); +	node.attribute(STR("attr2")) = std::numeric_limits<double>::max(); + +	CHECK(test_node(node, STR("<node attr1=\"3.40282347e+038\" attr2=\"1.7976931348623157e+308\" />"), STR(""), pugi::format_raw) || +		  test_node(node, STR("<node attr1=\"3.40282347e+38\" attr2=\"1.7976931348623157e+308\" />"), STR(""), pugi::format_raw)); +} +  TEST_XML(dom_node_set_name, "<node>text</node>")  {  	CHECK(doc.child(STR("node")).set_name(STR("n"))); @@ -746,17 +764,6 @@ TEST_XML_FLAGS(dom_node_copy_types, "<?xml version='1.0'?><!DOCTYPE id><root><?p  	CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><!DOCTYPE id><?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));  } -TEST_XML(dom_attr_assign_large_number, "<node attr1='' attr2='' />") -{ -	xml_node node = doc.child(STR("node")); - -	node.attribute(STR("attr1")) = std::numeric_limits<float>::max(); -	node.attribute(STR("attr2")) = std::numeric_limits<double>::max(); - -	CHECK(test_node(node, STR("<node attr1=\"3.40282e+038\" attr2=\"1.79769e+308\" />"), STR(""), pugi::format_raw) || -		  test_node(node, STR("<node attr1=\"3.40282e+38\" attr2=\"1.79769e+308\" />"), STR(""), pugi::format_raw)); -} -  TEST(dom_node_declaration_name)  {  	xml_document doc; @@ -1443,3 +1450,64 @@ TEST(dom_node_copy_declaration_empty_name)  	CHECK_STRING(decl2.name(), STR(""));  } + +TEST(dom_fp_roundtrip_min_max) +{ +	xml_document doc; +	xml_node node = doc.append_child(STR("node")); +	xml_attribute attr = node.append_attribute(STR("attr")); + +	node.text().set(std::numeric_limits<float>::min()); +	CHECK(node.text().as_float() == std::numeric_limits<float>::min()); + +	attr.set_value(std::numeric_limits<float>::max()); +	CHECK(attr.as_float() == std::numeric_limits<float>::max()); + +	attr.set_value(std::numeric_limits<double>::min()); +	CHECK(attr.as_double() == std::numeric_limits<double>::min()); + +	node.text().set(std::numeric_limits<double>::max()); +	CHECK(node.text().as_double() == std::numeric_limits<double>::max()); +} + +const double fp_roundtrip_base[] = +{ +	0.31830988618379067154, +	0.43429448190325182765, +	0.57721566490153286061, +	0.69314718055994530942, +	0.70710678118654752440, +	0.78539816339744830962, +}; + +TEST(dom_fp_roundtrip_float) +{ +	xml_document doc; + +	for (int e = -125; e <= 128; ++e) +	{ +		for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i) +		{ +			float value = ldexpf(fp_roundtrip_base[i], e); + +			doc.text().set(value); +			CHECK(doc.text().as_float() == value); +		} +	} +} + +TEST(dom_fp_roundtrip_double) +{ +	xml_document doc; + +	for (int e = -1021; e <= 1024; ++e) +	{ +		for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i) +		{ +			double value = ldexp(fp_roundtrip_base[i], e); + +			doc.text().set(value); +			CHECK(doc.text().as_double() == value); +		} +	} +} diff --git a/tests/test_dom_text.cpp b/tests/test_dom_text.cpp index fb65b03..007334a 100644 --- a/tests/test_dom_text.cpp +++ b/tests/test_dom_text.cpp @@ -263,10 +263,13 @@ TEST_XML(dom_text_assign, "<node/>")  	node.append_child(STR("text6")).text() = 0.5;
  	xml_text() = 0.5;
 -	node.append_child(STR("text7")).text() = true;
 +	node.append_child(STR("text7")).text() = 0.25f;
 +	xml_text() = 0.25f;
 +
 +	node.append_child(STR("text8")).text() = true;
  	xml_text() = true;
 -	CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>true</text7></node>"));
 +	CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>0.25</text7><text8>true</text8></node>"));
  }
  TEST_XML(dom_text_set_value, "<node/>")
 @@ -287,10 +290,13 @@ TEST_XML(dom_text_set_value, "<node/>")  	CHECK(node.append_child(STR("text6")).text().set(0.5));
  	CHECK(!xml_text().set(0.5));
 -	CHECK(node.append_child(STR("text7")).text().set(true));
 +	CHECK(node.append_child(STR("text7")).text().set(0.25f));
 +	CHECK(!xml_text().set(0.25f));
 +
 +	CHECK(node.append_child(STR("text8")).text().set(true));
  	CHECK(!xml_text().set(true));
 -	CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>true</text7></node>"));
 +	CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>0.25</text7><text8>true</text8></node>"));
  }
  #ifdef PUGIXML_HAS_LONG_LONG
 diff --git a/tests/test_header_only.cpp b/tests/test_header_only.cpp new file mode 100644 index 0000000..f1990dd --- /dev/null +++ b/tests/test_header_only.cpp @@ -0,0 +1,16 @@ +#define PUGIXML_HEADER_ONLY +#define pugi pugih + +#include "common.hpp" + +// Check header guards +#include "../src/pugixml.hpp" +#include "../src/pugixml.hpp" + +TEST(header_only) +{ +	xml_document doc; +	CHECK(doc.load_string(STR("<node/>"))); +	CHECK_STRING(doc.first_child().name(), STR("node")); +	CHECK(doc.first_child() == doc.select_node(STR("//*")).node()); +}  | 
