tests: Added declaration and document load/load_file error tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@157 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
a0990f0975
commit
3d986d2b0d
@ -1,5 +1,7 @@
|
|||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
TEST(document_create)
|
TEST(document_create)
|
||||||
{
|
{
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc;
|
||||||
@ -16,6 +18,17 @@ TEST(document_load_stream)
|
|||||||
CHECK_NODE(doc, "<node />");
|
CHECK_NODE(doc, "<node />");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(document_load_stream_error)
|
||||||
|
{
|
||||||
|
pugi::xml_document doc;
|
||||||
|
|
||||||
|
std::ifstream fs1("");
|
||||||
|
CHECK(doc.load(fs1).status == status_io_error);
|
||||||
|
|
||||||
|
std::ifstream fs2("con");
|
||||||
|
CHECK(doc.load(fs2).status == status_io_error);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(document_load_string)
|
TEST(document_load_string)
|
||||||
{
|
{
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc;
|
||||||
@ -46,6 +59,14 @@ TEST(document_load_file_large)
|
|||||||
CHECK_NODE(doc, oss.str().c_str());
|
CHECK_NODE(doc, oss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(document_load_file_error)
|
||||||
|
{
|
||||||
|
pugi::xml_document doc;
|
||||||
|
|
||||||
|
CHECK(doc.load_file("").status == status_file_not_found);
|
||||||
|
CHECK(doc.load_file("con").status == status_io_error);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_XML(document_save, "<node/>")
|
TEST_XML(document_save, "<node/>")
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|||||||
@ -355,3 +355,45 @@ TEST(parse_tag_error)
|
|||||||
CHECK(doc.load("<node></node ", parse_minimal).status == status_bad_end_element);
|
CHECK(doc.load("<node></node ", parse_minimal).status == status_bad_end_element);
|
||||||
CHECK(doc.load("<node></nodes>", parse_minimal).status == status_end_element_mismatch);
|
CHECK(doc.load("<node></nodes>", parse_minimal).status == status_end_element_mismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(parse_declaration_skip)
|
||||||
|
{
|
||||||
|
xml_document doc;
|
||||||
|
CHECK(doc.load("<?xml?><?xml version='1.0'?>", parse_minimal));
|
||||||
|
CHECK(!doc.first_child());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(parse_declaration_parse)
|
||||||
|
{
|
||||||
|
xml_document doc;
|
||||||
|
CHECK(doc.load("<?xml?><?xml version='1.0'?>", parse_minimal | parse_declaration));
|
||||||
|
|
||||||
|
xml_node d1 = doc.first_child();
|
||||||
|
xml_node d2 = doc.last_child();
|
||||||
|
|
||||||
|
CHECK(d1 != d2);
|
||||||
|
CHECK(d1.type() == node_declaration);
|
||||||
|
CHECK_STRING(d1.name(), "xml");
|
||||||
|
CHECK(d2.type() == node_declaration);
|
||||||
|
CHECK_STRING(d2.name(), "xml");
|
||||||
|
CHECK_STRING(d2.attribute("version").value(), "1.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(parse_declaration_error)
|
||||||
|
{
|
||||||
|
xml_document doc;
|
||||||
|
|
||||||
|
unsigned int flag_sets[] = {parse_minimal, parse_minimal | parse_declaration};
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < sizeof(flag_sets) / sizeof(flag_sets[0]); ++i)
|
||||||
|
{
|
||||||
|
unsigned int flags = flag_sets[i];
|
||||||
|
|
||||||
|
CHECK(doc.load("<?xml", flags).status == status_bad_pi);
|
||||||
|
CHECK(doc.load("<?xml?", flags).status == status_bad_pi);
|
||||||
|
CHECK(doc.load("<?xml>", flags).status == status_bad_pi);
|
||||||
|
CHECK(doc.load("<?xml version='1>", flags).status == status_bad_pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(doc.load("<?xml version='1?>", parse_minimal | parse_declaration).status == status_bad_attribute);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user