From 1a3e92a7cc80a719efd988f14860a1aa9692d584 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 31 Jan 2017 20:36:59 -0800 Subject: tests: Add more tests to increase coverage This change adds more thorough tests for attribute conversion as well as some assorted tests that fix gaps in coverage. --- tests/test_compact.cpp | 10 +++++++--- tests/test_dom_traverse.cpp | 4 ++++ tests/test_parse.cpp | 30 ++++++++++++++++++++++++++++++ tests/test_write.cpp | 6 ++++++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/tests/test_compact.cpp b/tests/test_compact.cpp index 7c90d07..f9560c9 100644 --- a/tests/test_compact.cpp +++ b/tests/test_compact.cpp @@ -11,15 +11,19 @@ static void overflow_hash_table(xml_document& doc) CHECK(n.prepend_child(node_element)); } -TEST_XML(compact_out_of_memory_string, "") +TEST_XML_FLAGS(compact_out_of_memory_string, "", parse_pi) { test_runner::_memory_fail_threshold = 1; overflow_hash_table(doc); - xml_node n = doc.child(STR("n")); + xml_attribute a = doc.child(STR("n")).attribute(STR("a")); + xml_node pi = doc.last_child(); - CHECK_ALLOC_FAIL(CHECK(!n.set_name(STR("name")))); + CHECK_ALLOC_FAIL(CHECK(!pi.set_name(STR("name")))); + CHECK_ALLOC_FAIL(CHECK(!pi.set_value(STR("value")))); + CHECK_ALLOC_FAIL(CHECK(!a.set_name(STR("name")))); + CHECK_ALLOC_FAIL(CHECK(!a.set_value(STR("value")))); } TEST_XML(compact_out_of_memory_attribute, "") diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index 773f0f0..3d30a82 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -137,6 +137,10 @@ TEST_XML(dom_attr_as_integer_space, "") diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index fa9555d..882ba3a 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -746,6 +746,36 @@ TEST(parse_attribute_quot_inside) } } +TEST(parse_attribute_wnorm_coverage) +{ + xml_document doc; + CHECK(doc.load_string(STR(""), parse_wnorm_attribute)); + CHECK_NODE(doc, STR("")); + + CHECK(doc.load_string(STR(""), parse_wnorm_attribute | parse_escapes)); + CHECK_NODE(doc, STR("")); +} + +TEST(parse_attribute_wconv_coverage) +{ + xml_document doc; + CHECK(doc.load_string(STR(""), parse_wconv_attribute)); + CHECK_NODE(doc, STR("")); + + CHECK(doc.load_string(STR(""), parse_wconv_attribute | parse_escapes)); + CHECK_NODE(doc, STR("")); +} + +TEST(parse_attribute_eol_coverage) +{ + xml_document doc; + CHECK(doc.load_string(STR(""), parse_eol)); + CHECK_NODE(doc, STR("")); + + CHECK(doc.load_string(STR(""), parse_eol | parse_escapes)); + CHECK_NODE(doc, STR("")); +} + TEST(parse_tag_single) { xml_document doc; diff --git a/tests/test_write.cpp b/tests/test_write.cpp index d5f3dad..5cd92a5 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -69,6 +69,12 @@ TEST_XML_FLAGS(write_cdata_escape, "", parse_cdata | parse_frag doc.first_child().set_value(STR("1]]>2]]>3")); CHECK_NODE(doc, STR("2]]]]>3]]>")); + + doc.first_child().set_value(STR("1]")); + CHECK_NODE(doc, STR("")); + + doc.first_child().set_value(STR("1]]")); + CHECK_NODE(doc, STR("")); } TEST_XML(write_cdata_inner, "") -- cgit v1.2.3