summaryrefslogtreecommitdiff
path: root/tests/test_write.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-11 22:44:42 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-11 22:44:42 -0700
commit37467c13bfdfbdbee7cc5176a8755e04353a9deb (patch)
tree23f406bb4a77d8443600c506d4cf29e44a5f8b67 /tests/test_write.cpp
parente2e5bc906a06f7937319896d55254e4881888ce4 (diff)
tests: Add a test for throwing from xml_writer::write
We currently don't allocate/modify any state so there are no issues with this.
Diffstat (limited to 'tests/test_write.cpp')
-rw-r--r--tests/test_write.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_write.cpp b/tests/test_write.cpp
index ad6c409..230d652 100644
--- a/tests/test_write.cpp
+++ b/tests/test_write.cpp
@@ -574,3 +574,41 @@ TEST_XML_FLAGS(write_mixed, "<node><child1/><child2>pre<![CDATA[data]]>mid<!--co
CHECK_NODE_EX(doc, STR("<node>\n<child1 />\n<child2>pre<![CDATA[data]]>mid<!--comment-->\n<test />post<?pi value?>fin</child2>\n<child3 />\n</node>\n"), STR("\t"), 0);
CHECK_NODE_EX(doc, STR("<node>\n\t<child1 />\n\t<child2>pre<![CDATA[data]]>mid<!--comment-->\n\t\t<test />post<?pi value?>fin</child2>\n\t<child3 />\n</node>\n"), STR("\t"), format_indent);
}
+
+#ifndef PUGIXML_NO_EXCEPTIONS
+struct throwing_writer: pugi::xml_writer
+{
+ virtual void write(const void*, size_t)
+ {
+ throw std::runtime_error("write failed");
+ }
+};
+
+TEST_XML(write_throw_simple, "<node><child/></node>")
+{
+ try
+ {
+ throwing_writer w;
+ doc.print(w);
+
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (std::runtime_error&)
+ {
+ }
+}
+
+TEST_XML(write_throw_encoding, "<node><child/></node>")
+{
+ try
+ {
+ throwing_writer w;
+ doc.print(w, STR("\t"), format_default, encoding_utf32_be);
+
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (std::runtime_error&)
+ {
+ }
+}
+#endif