From 05c651d87f95268823f4f0ed5a9206b5cd734507 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Wed, 4 Aug 2010 10:01:16 +0000 Subject: tests: Added more tests for better code coverage git-svn-id: http://pugixml.googlecode.com/svn/trunk@626 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_document.cpp | 32 ++++++++++++++++++++ tests/test_dom_traverse.cpp | 2 +- tests/test_parse.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 102 insertions(+), 6 deletions(-) diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 4a915df..ced06a8 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -126,6 +126,28 @@ TEST(document_load_stream_exceptions) } } #endif + +TEST(document_load_stream_error_previous) +{ + pugi::xml_document doc; + CHECK(doc.load("")); + CHECK(doc.first_child()); + + std::ifstream fs1("filedoesnotexist"); + CHECK(doc.load(fs1).status == status_io_error); + CHECK(!doc.first_child()); +} + +TEST(document_load_stream_wide_error_previous) +{ + pugi::xml_document doc; + CHECK(doc.load("")); + CHECK(doc.first_child()); + + std::basic_ifstream fs1("filedoesnotexist"); + CHECK(doc.load(fs1).status == status_io_error); + CHECK(!doc.first_child()); +} #endif TEST(document_load_string) @@ -182,6 +204,16 @@ TEST(document_load_file_error) CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory); } +TEST(document_load_file_error_previous) +{ + pugi::xml_document doc; + CHECK(doc.load("")); + CHECK(doc.first_child()); + + CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found); + CHECK(!doc.first_child()); +} + TEST_XML(document_save, "") { xml_writer_string writer; diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index fa6c6ef..cbf873b 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -471,7 +471,7 @@ TEST_XML(dom_node_first_last_child, "") CHECK(doc.last_child() == node); } -TEST_XML(dom_node_find_child_by_attribute, "") +TEST_XML(dom_node_find_child_by_attribute, "") { CHECK(xml_node().find_child_by_attribute(STR("name"), STR("attr"), STR("value")) == xml_node()); CHECK(xml_node().find_child_by_attribute(STR("attr"), STR("value")) == xml_node()); diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index c7e3ae3..5b3cf3f 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -144,6 +144,13 @@ TEST(parse_cdata_skip) CHECK(!doc.first_child()); } +TEST(parse_cdata_skip_contents) +{ + xml_document doc; + CHECK(doc.load(STR("hello, world!"), parse_minimal)); + CHECK_NODE(doc, STR("hello, world!")); +} + TEST(parse_cdata_parse) { xml_document doc; @@ -377,6 +384,25 @@ TEST(parse_escapes_code_invalid) CHECK_STRING(doc.child_value(STR("node")), STR("&#;&#x;&;&#x-;&#-;")); } +TEST(parse_escapes_attribute) +{ + xml_document doc; + + for (int wnorm = 0; wnorm < 2; ++wnorm) + for (int eol = 0; eol < 2; ++eol) + for (int wconv = 0; wconv < 2; ++wconv) + { + unsigned int flags = parse_escapes; + + flags |= (wnorm ? parse_wnorm_attribute : 0); + flags |= (eol ? parse_eol : 0); + flags |= (wconv ? parse_wconv_attribute : 0); + + CHECK(doc.load(STR(""), flags)); + CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR("\"")); + } +} + TEST(parse_attribute_spaces) { xml_document doc; @@ -447,11 +473,11 @@ TEST(parse_attribute_variations) for (int escapes = 0; escapes < 2; ++escapes) { unsigned int flags = parse_minimal; - - flags |= (wnorm ? parse_wnorm_attribute : 0); - flags |= (eol ? parse_eol : 0); - flags |= (wconv ? parse_wconv_attribute : 0); - flags |= (escapes ? parse_escapes : 0); + + flags |= (wnorm ? parse_wnorm_attribute : 0); + flags |= (eol ? parse_eol : 0); + flags |= (wconv ? parse_wconv_attribute : 0); + flags |= (escapes ? parse_escapes : 0); CHECK(doc.load(STR(""), flags)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR("1")); @@ -482,6 +508,44 @@ TEST(parse_attribute_error) CHECK(doc.load(STR(""), parse_minimal).status == status_bad_start_element); } +TEST(parse_attribute_termination_error) +{ + xml_document doc; + + for (int wnorm = 0; wnorm < 2; ++wnorm) + for (int eol = 0; eol < 2; ++eol) + for (int wconv = 0; wconv < 2; ++wconv) + { + unsigned int flags = parse_minimal; + + flags |= (wnorm ? parse_wnorm_attribute : 0); + flags |= (eol ? parse_eol : 0); + flags |= (wconv ? parse_wconv_attribute : 0); + + CHECK(doc.load(STR(""), flags)); + CHECK_STRING(doc.child(STR("node")).attribute(STR("id1")).value(), STR("\"")); + CHECK_STRING(doc.child(STR("node")).attribute(STR("id2")).value(), STR("'")); + } +} + TEST(parse_tag_single) { xml_document doc; -- cgit v1.2.3