From f68a320a0203279db2e8692cc9e21f71551454e4 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 1 Nov 2014 11:45:13 +0100 Subject: tests: Improve test coverage --- tests/test_document.cpp | 4 ++++ tests/test_xpath_paths.cpp | 2 ++ 2 files changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 2cc39a6..2774a07 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -301,6 +301,10 @@ TEST(document_load_file_error) CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found); +#ifndef _WIN32 + CHECK(doc.load_file("/dev/tty").status == status_io_error); +#endif + test_runner::_memory_fail_threshold = 1; CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory); } diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp index df0dfa4..e51a395 100644 --- a/tests/test_xpath_paths.cpp +++ b/tests/test_xpath_paths.cpp @@ -664,6 +664,8 @@ TEST_XML(xpath_paths_optimize_step_once, "

") -- cgit v1.2.3 From e9948b4b05ca23cb95a6ca75ce4ee840e1fbda9b Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 2 Nov 2014 09:30:56 +0100 Subject: Fix undefined behavior while calling memcpy Calling memcpy(x, 0, 0) is technically undefined (although it should usually be a no-op). --- tests/test_dom_modify.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 07fe6dc..45cf3ea 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1091,6 +1091,19 @@ TEST_XML(dom_node_append_buffer_fragment, "") CHECK_NODE(doc, STR("1234")); } +TEST_XML(dom_node_append_buffer_empty, "") +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.append_buffer("", 0).status == status_no_document_element); + CHECK(node.append_buffer("", 0, parse_fragment).status == status_ok); + + CHECK(node.append_buffer(0, 0).status == status_no_document_element); + CHECK(node.append_buffer(0, 0, parse_fragment).status == status_ok); + + CHECK_NODE(doc, STR("")); +} + TEST_XML(dom_node_prepend_move, "foo") { xml_node child = doc.child(STR("node")).child(STR("child")); -- cgit v1.2.3 From 97a515f8733d9555278b6eb3f3dc244a9580c308 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 3 Nov 2014 07:50:00 +0100 Subject: tests: Add more XPath mod tests --- tests/test_xpath_operators.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests') diff --git a/tests/test_xpath_operators.cpp b/tests/test_xpath_operators.cpp index c028224..57e3755 100644 --- a/tests/test_xpath_operators.cpp +++ b/tests/test_xpath_operators.cpp @@ -481,4 +481,52 @@ TEST(xpath_operators_associativity_arithmetic) CHECK_XPATH_NUMBER(c, STR("1-1+1"), 1); } +TEST(xpath_operators_mod) +{ + // Check that mod operator conforms to Java spec (since this is the only concrete source of information about XPath mod) + xml_node c; + + // Basic tests from spec + CHECK_XPATH_NUMBER(c, STR("5 mod 3"), 2); + CHECK_XPATH_NUMBER(c, STR("5 mod -3"), 2); + CHECK_XPATH_NUMBER(c, STR("-5 mod 3"), -2); + CHECK_XPATH_NUMBER(c, STR("-5 mod -3"), -2); + + // If either operand is NaN, the result is NaN + CHECK_XPATH_NUMBER_NAN(c, STR("(0 div 0) mod 3")); + CHECK_XPATH_NUMBER_NAN(c, STR("3 mod (0 div 0)")); + CHECK_XPATH_NUMBER_NAN(c, STR("(0 div 0) mod (0 div 0)")); + + // If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN + CHECK_XPATH_NUMBER_NAN(c, STR("(1 div 0) mod 3")); + CHECK_XPATH_NUMBER_NAN(c, STR("(1 div 0) mod -3")); + CHECK_XPATH_NUMBER_NAN(c, STR("(-1 div 0) mod 3")); + CHECK_XPATH_NUMBER_NAN(c, STR("1 mod 0")); + CHECK_XPATH_NUMBER_NAN(c, STR("-1 mod 0")); + CHECK_XPATH_NUMBER_NAN(c, STR("(1 div 0) mod 0")); + CHECK_XPATH_NUMBER_NAN(c, STR("(-1 div 0) mod 0")); + + // If the dividend is finite and the divisor is an infinity, the result equals the dividend + CHECK_XPATH_NUMBER(c, STR("1 mod (1 div 0)"), 1); + CHECK_XPATH_NUMBER(c, STR("1 mod (-1 div 0)"), 1); + CHECK_XPATH_NUMBER(c, STR("-1 mod (1 div 0)"), -1); + CHECK_XPATH_NUMBER(c, STR("0 mod (1 div 0)"), 0); + CHECK_XPATH_NUMBER(c, STR("0 mod (-1 div 0)"), 0); + CHECK_XPATH_NUMBER(c, STR("100000 mod (1 div 0)"), 100000); + + // If the dividend is a zero and the divisor is finite, the result equals the dividend. + CHECK_XPATH_NUMBER(c, STR("0 mod 1000000"), 0); + CHECK_XPATH_NUMBER(c, STR("0 mod -1000000"), 0); + + // In the remaining cases ... the floating-point remainder r from the division of a dividend n by a divisor d + // is defined by the mathematical relation r = n - (d * q) where q is an integer that is negative only if n/d is + // negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true + // mathematical quotient of n and d. + CHECK_XPATH_NUMBER(c, STR("9007199254740991 mod 2"), 1); + CHECK_XPATH_NUMBER(c, STR("9007199254740991 mod 3"), 1); + CHECK_XPATH_NUMBER(c, STR("18446744073709551615 mod 2"), 0); + CHECK_XPATH_NUMBER(c, STR("18446744073709551615 mod 3"), 1); + CHECK_XPATH_NUMBER(c, STR("115792089237316195423570985008687907853269984665640564039457584007913129639935 mod 2"), 0); + CHECK_XPATH_NUMBER(c, STR("115792089237316195423570985008687907853269984665640564039457584007913129639935 mod 3"), 1); +} #endif -- cgit v1.2.3