From 80d778d0532d83d566d310bc790d9a50646016bb Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Mon, 12 Oct 2009 16:26:18 +0000 Subject: tests: Refactored checking macros, added writing tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@152 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_write.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/test_write.cpp (limited to 'tests/test_write.cpp') diff --git a/tests/test_write.cpp b/tests/test_write.cpp new file mode 100644 index 0000000..78516b2 --- /dev/null +++ b/tests/test_write.cpp @@ -0,0 +1,77 @@ +#include "common.hpp" + +#include + +TEST_XML(write_simple, "text") +{ + CHECK_NODE_EX(doc, "\ntext\n\n", "", 0); +} + +TEST_XML(write_raw, "text") +{ + CHECK_NODE_EX(doc, "text", "", pugi::format_raw); +} + +TEST_XML(write_indent, "text") +{ + CHECK_NODE_EX(doc, "\n\t\n\t\ttext\n\t\n\n", "\t", pugi::format_indent); +} + +TEST_XML(write_pcdata, "text") +{ + CHECK_NODE_EX(doc, "\n\t\n\t\t\n\t\ttext\n\t\n\n", "\t", pugi::format_indent); +} + +TEST_XML(write_cdata, "") +{ + CHECK_NODE(doc, ""); +} + +TEST_XML_FLAGS(write_comment, "", pugi::parse_default | pugi::parse_comments) +{ + CHECK_NODE(doc, ""); +} + +TEST_XML_FLAGS(write_pi, "", pugi::parse_default | pugi::parse_pi) +{ + CHECK_NODE(doc, ""); +} + +TEST_XML_FLAGS(write_declaration, "", pugi::parse_default | pugi::parse_declaration) +{ + CHECK_NODE(doc, ""); +} + +TEST_XML(write_escape, "text") +{ + doc.child("node").attribute("attr") = "<>'\"&\x04\r\n\t"; + doc.child("node").first_child().set_value("<>'\"&\x04\r\n\t"); + + CHECK_NODE(doc, "<>'\"&\r\n\t"); +} + +struct test_writer: xml_writer +{ + std::string contents; + + virtual void write(const void* data, size_t size) + { + contents += std::string(static_cast(data), static_cast(data) + size); + } +}; + +TEST_XML(write_print_writer, "") +{ + test_writer writer; + doc.print(writer); + + CHECK(writer.contents == "\n"); +} + +TEST_XML(write_print_stream, "") +{ + std::ostringstream oss; + doc.print(oss); + + CHECK(oss.str() == "\n"); +} -- cgit v1.2.3