From cf72c20ca173bbad227e8f70bd68a2dbfb5b2890 Mon Sep 17 00:00:00 2001 From: Steve Doiel Date: Fri, 16 Jan 2015 16:14:59 -0800 Subject: Increase precision on large number test --- tests/test_dom_modify.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_dom_modify.cpp') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 7863718..85c381e 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -753,8 +753,8 @@ TEST_XML(dom_attr_assign_large_number, "") node.attribute(STR("attr1")) = std::numeric_limits::max(); node.attribute(STR("attr2")) = std::numeric_limits::max(); - CHECK(test_node(node, STR(""), STR(""), pugi::format_raw) || - test_node(node, STR(""), STR(""), pugi::format_raw)); + CHECK(test_node(node, STR(""), STR(""), pugi::format_raw) || + test_node(node, STR(""), STR(""), pugi::format_raw)); } TEST(dom_node_declaration_name) -- cgit v1.2.3 From f9ee391233ed8526597abb3ffa96c4eb8b1c92ad Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 16 Jan 2015 21:42:35 -0800 Subject: tests: Add coverage tests for new float setters These only do basic testing to make sure the paths are covered and trivial values work. --- tests/test_dom_modify.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'tests/test_dom_modify.cpp') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 85c381e..70cba53 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -21,10 +21,13 @@ TEST_XML(dom_attr_assign, "") 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("")); + CHECK_NODE(node, STR("")); } TEST_XML(dom_attr_set_name, "") @@ -55,10 +58,13 @@ TEST_XML(dom_attr_set_value, "") 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("")); + CHECK_NODE(node, STR("")); } #ifdef PUGIXML_HAS_LONG_LONG @@ -753,7 +759,7 @@ TEST_XML(dom_attr_assign_large_number, "") node.attribute(STR("attr1")) = std::numeric_limits::max(); node.attribute(STR("attr2")) = std::numeric_limits::max(); - CHECK(test_node(node, STR(""), STR(""), pugi::format_raw) || + CHECK(test_node(node, STR(""), STR(""), pugi::format_raw) || test_node(node, STR(""), STR(""), pugi::format_raw)); } -- cgit v1.2.3 From d454013cffe1be5819bfb6329b1aa218b8de618f Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 16 Jan 2015 21:43:28 -0800 Subject: tests: Add tests for fp roundtrip We test min/max and several different mantissas for the entire exponent range for both float and double. It's not clear whether all supported compilers provide an implementation of sprintf/strtod that supports roundtripping so we may need to disable some of these tests in the future. --- tests/test_dom_modify.cpp | 84 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 11 deletions(-) (limited to 'tests/test_dom_modify.cpp') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 70cba53..1fb9dd3 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -2,6 +2,7 @@ #include #include +#include TEST_XML(dom_attr_assign, "") { @@ -99,6 +100,17 @@ TEST_XML(dom_attr_set_value_llong, "") } #endif +TEST_XML(dom_attr_assign_large_number, "") +{ + xml_node node = doc.child(STR("node")); + + node.attribute(STR("attr1")) = std::numeric_limits::max(); + node.attribute(STR("attr2")) = std::numeric_limits::max(); + + CHECK(test_node(node, STR(""), STR(""), pugi::format_raw) || + test_node(node, STR(""), STR(""), pugi::format_raw)); +} + TEST_XML(dom_node_set_name, "text") { CHECK(doc.child(STR("node")).set_name(STR("n"))); @@ -752,17 +764,6 @@ TEST_XML_FLAGS(dom_node_copy_types, "pcdatapcdata")); } -TEST_XML(dom_attr_assign_large_number, "") -{ - xml_node node = doc.child(STR("node")); - - node.attribute(STR("attr1")) = std::numeric_limits::max(); - node.attribute(STR("attr2")) = std::numeric_limits::max(); - - CHECK(test_node(node, STR(""), STR(""), pugi::format_raw) || - test_node(node, STR(""), STR(""), pugi::format_raw)); -} - TEST(dom_node_declaration_name) { xml_document doc; @@ -1444,3 +1445,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::min()); + CHECK(node.text().as_float() == std::numeric_limits::min()); + + attr.set_value(std::numeric_limits::max()); + CHECK(attr.as_float() == std::numeric_limits::max()); + + attr.set_value(std::numeric_limits::min()); + CHECK(attr.as_double() == std::numeric_limits::min()); + + node.text().set(std::numeric_limits::max()); + CHECK(node.text().as_double() == std::numeric_limits::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); + } + } +} -- cgit v1.2.3