diff --git a/tests/data/large.xml b/tests/data/large.xml new file mode 100644 index 0000000..dfee797 --- /dev/null +++ b/tests/data/large.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/data/small.xml b/tests/data/small.xml new file mode 100644 index 0000000..6187c16 --- /dev/null +++ b/tests/data/small.xml @@ -0,0 +1 @@ + \ No newline at end of file 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, ""); +} + +TEST(document_load_stream) +{ + pugi::xml_document doc; + + std::istringstream iss(""); + CHECK(doc.load(iss)); + CHECK_NODE(doc, ""); +} + +TEST(document_load_string) +{ + pugi::xml_document doc; + + CHECK(doc.load("")); + CHECK_NODE(doc, ""); +} + +TEST(document_load_file) +{ + pugi::xml_document doc; + + CHECK(doc.load_file("tests/data/small.xml")); + CHECK_NODE(doc, ""); +} + +TEST(document_load_file_large) +{ + pugi::xml_document doc; + + CHECK(doc.load_file("tests/data/large.xml")); + + std::ostringstream oss; + oss << ""; + for (int i = 0; i < 10000; ++i) oss << ""; + oss << ""; + + CHECK_NODE(doc, oss.str().c_str()); +} + +TEST_XML(document_save, "") +{ + std::ostringstream oss; + xml_writer_stream writer(oss); + + doc.save(writer, "", pugi::format_no_declaration | pugi::format_raw); + + CHECK(oss.str() == ""); +} + +TEST_XML(document_save_bom, "") +{ + 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"); +} + +TEST_XML(document_save_declaration, "") +{ + std::ostringstream oss; + xml_writer_stream writer(oss); + + doc.save(writer); + + CHECK(oss.str() == "\n\n"); +} + +TEST_XML(document_save_file, "") +{ + 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, ""); + + unlink("tests/data/output.xml"); +} + +TEST(document_parse) +{ + char text[] = ""; + + pugi::xml_document doc; + + CHECK(doc.parse(text)); + CHECK_NODE(doc, ""); +} + +TEST(document_parse_transfer_ownership) +{ + char* text = static_cast(malloc(strlen("") + 1)); + CHECK(text); + + strcpy(text, ""); + + pugi::xml_document doc; + + CHECK(doc.parse(transfer_ownership_tag(), text)); + CHECK_NODE(doc, ""); +}