summaryrefslogtreecommitdiff
path: root/tests/test_document.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-10-12 16:42:13 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-10-12 16:42:13 +0000
commit557a690529ab1342c5902b8db28622f4bf263b80 (patch)
tree22fd05fe21ecd9e0178a8f53e17cf797679b3cc5 /tests/test_document.cpp
parente1013bfcd83174cfe2076c76cb03e960f7998106 (diff)
tests: Added document tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@154 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_document.cpp')
-rw-r--r--tests/test_document.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
new file mode 100644
index 0000000..a2e76b0
--- /dev/null
+++ b/tests/test_document.cpp
@@ -0,0 +1,110 @@
+#include "common.hpp"
+
+TEST(document_create)
+{
+ pugi::xml_document doc;
+ doc.append_child().set_name("node");
+ CHECK_NODE(doc, "<node />");
+}
+
+TEST(document_load_stream)
+{
+ pugi::xml_document doc;
+
+ std::istringstream iss("<node/>");
+ CHECK(doc.load(iss));
+ CHECK_NODE(doc, "<node />");
+}
+
+TEST(document_load_string)
+{
+ pugi::xml_document doc;
+
+ CHECK(doc.load("<node/>"));
+ CHECK_NODE(doc, "<node />");
+}
+
+TEST(document_load_file)
+{
+ pugi::xml_document doc;
+
+ CHECK(doc.load_file("tests/data/small.xml"));
+ CHECK_NODE(doc, "<node />");
+}
+
+TEST(document_load_file_large)
+{
+ pugi::xml_document doc;
+
+ CHECK(doc.load_file("tests/data/large.xml"));
+
+ std::ostringstream oss;
+ oss << "<node>";
+ for (int i = 0; i < 10000; ++i) oss << "<node />";
+ oss << "</node>";
+
+ CHECK_NODE(doc, oss.str().c_str());
+}
+
+TEST_XML(document_save, "<node/>")
+{
+ std::ostringstream oss;
+ xml_writer_stream writer(oss);
+
+ doc.save(writer, "", pugi::format_no_declaration | pugi::format_raw);
+
+ CHECK(oss.str() == "<node />");
+}
+
+TEST_XML(document_save_bom, "<node/>")
+{
+ std::ostringstream oss;
+ xml_writer_stream writer(oss);
+
+ doc.save(writer, "", pugi::format_no_declaration | pugi::format_raw | pugi::format_write_bom_utf8);
+
+ CHECK(oss.str() == "\xef\xbb\xbf<node />");
+}
+
+TEST_XML(document_save_declaration, "<node/>")
+{
+ std::ostringstream oss;
+ xml_writer_stream writer(oss);
+
+ doc.save(writer);
+
+ CHECK(oss.str() == "<?xml version=\"1.0\"?>\n<node />\n");
+}
+
+TEST_XML(document_save_file, "<node/>")
+{
+ CHECK(doc.save_file("tests/data/output.xml"));
+
+ CHECK(doc.load_file("tests/data/output.xml", pugi::parse_default | pugi::parse_declaration));
+ CHECK_NODE(doc, "<?xml version=\"1.0\"?><node />");
+
+ unlink("tests/data/output.xml");
+}
+
+TEST(document_parse)
+{
+ char text[] = "<node/>";
+
+ pugi::xml_document doc;
+
+ CHECK(doc.parse(text));
+ CHECK_NODE(doc, "<node />");
+}
+
+TEST(document_parse_transfer_ownership)
+{
+ char* text = static_cast<char*>(malloc(strlen("<node/>") + 1));
+ CHECK(text);
+
+ strcpy(text, "<node/>");
+
+ pugi::xml_document doc;
+
+ CHECK(doc.parse(transfer_ownership_tag(), text));
+ CHECK_NODE(doc, "<node />");
+}