diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-08-04 10:01:16 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-08-04 10:01:16 +0000 |
commit | 05c651d87f95268823f4f0ed5a9206b5cd734507 (patch) | |
tree | 4439f7fdb0665693ed724fa914c37aac7469ebe3 /tests | |
parent | f8c18461e6e6459a4e13c05fb964dddfa810dae0 (diff) |
tests: Added more tests for better code coverage
git-svn-id: http://pugixml.googlecode.com/svn/trunk@626 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_document.cpp | 32 | ||||
-rw-r--r-- | tests/test_dom_traverse.cpp | 2 | ||||
-rw-r--r-- | 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("<node/>")); + 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("<node/>")); + CHECK(doc.first_child()); + + std::basic_ifstream<wchar_t> 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("<node/>")); + CHECK(doc.first_child()); + + CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found); + CHECK(!doc.first_child()); +} + TEST_XML(document_save, "<node/>") { 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, "<node><child1/><child2/></node>") CHECK(doc.last_child() == node); } -TEST_XML(dom_node_find_child_by_attribute, "<node><child1 attr='value1'/><child2 attr='value2'/><child2 attr='value3'/></node>") +TEST_XML(dom_node_find_child_by_attribute, "<node><stub attr='value3' /><child1 attr='value1'/><child2 attr='value2'/><child2 attr='value3'/></node>") { 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("<node><![CDATA[]]>hello<![CDATA[value]]>, world!</node>"), parse_minimal)); + CHECK_NODE(doc, STR("<node>hello, world!</node>")); +} + 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("<node id='"'/>"), 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("<node id='1'/>"), 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("<node &='1'/>"), 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("<node id='value"), flags).status == status_bad_attribute); + } +} + +TEST(parse_attribute_quot_inside) +{ + 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("<node id1='\"' id2=\"'\"/>"), 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; |