mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-26 21:04:25 +08:00
tests: Added more tests for better code coverage
git-svn-id: http://pugixml.googlecode.com/svn/trunk@626 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
f8c18461e6
commit
05c651d87f
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user