summaryrefslogtreecommitdiff
path: root/tests/test_write.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-10-12 16:26:18 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-10-12 16:26:18 +0000
commit80d778d0532d83d566d310bc790d9a50646016bb (patch)
treebe9e9a4c313d12b7e72077bb74067260c086126f /tests/test_write.cpp
parent9c7d93817e768e59a666ad57defb1ca7c605fbe9 (diff)
tests: Refactored checking macros, added writing tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@152 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_write.cpp')
-rw-r--r--tests/test_write.cpp77
1 files changed, 77 insertions, 0 deletions
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 <string>
+
+TEST_XML(write_simple, "<node attr='1'><child>text</child></node>")
+{
+ CHECK_NODE_EX(doc, "<node attr=\"1\">\n<child>text</child>\n</node>\n", "", 0);
+}
+
+TEST_XML(write_raw, "<node attr='1'><child>text</child></node>")
+{
+ CHECK_NODE_EX(doc, "<node attr=\"1\"><child>text</child></node>", "", pugi::format_raw);
+}
+
+TEST_XML(write_indent, "<node attr='1'><child><sub>text</sub></child></node>")
+{
+ CHECK_NODE_EX(doc, "<node attr=\"1\">\n\t<child>\n\t\t<sub>text</sub>\n\t</child>\n</node>\n", "\t", pugi::format_indent);
+}
+
+TEST_XML(write_pcdata, "<node attr='1'><child><sub/>text</child></node>")
+{
+ CHECK_NODE_EX(doc, "<node attr=\"1\">\n\t<child>\n\t\t<sub />\n\t\ttext\n\t</child>\n</node>\n", "\t", pugi::format_indent);
+}
+
+TEST_XML(write_cdata, "<![CDATA[value]]>")
+{
+ CHECK_NODE(doc, "<![CDATA[value]]>");
+}
+
+TEST_XML_FLAGS(write_comment, "<!--text-->", pugi::parse_default | pugi::parse_comments)
+{
+ CHECK_NODE(doc, "<!--text-->");
+}
+
+TEST_XML_FLAGS(write_pi, "<?name value?>", pugi::parse_default | pugi::parse_pi)
+{
+ CHECK_NODE(doc, "<?name value?>");
+}
+
+TEST_XML_FLAGS(write_declaration, "<?xml version='2.0'?>", pugi::parse_default | pugi::parse_declaration)
+{
+ CHECK_NODE(doc, "<?xml version=\"2.0\"?>");
+}
+
+TEST_XML(write_escape, "<node attr=''>text</node>")
+{
+ doc.child("node").attribute("attr") = "<>'\"&\x04\r\n\t";
+ doc.child("node").first_child().set_value("<>'\"&\x04\r\n\t");
+
+ CHECK_NODE(doc, "<node attr=\"&lt;&gt;'&quot;&amp;&#4;&#13;&#10;\t\">&lt;&gt;'\"&amp;&#4;\r\n\t</node>");
+}
+
+struct test_writer: xml_writer
+{
+ std::string contents;
+
+ virtual void write(const void* data, size_t size)
+ {
+ contents += std::string(static_cast<const char*>(data), static_cast<const char*>(data) + size);
+ }
+};
+
+TEST_XML(write_print_writer, "<node/>")
+{
+ test_writer writer;
+ doc.print(writer);
+
+ CHECK(writer.contents == "<node />\n");
+}
+
+TEST_XML(write_print_stream, "<node/>")
+{
+ std::ostringstream oss;
+ doc.print(oss);
+
+ CHECK(oss.str() == "<node />\n");
+}