From 37467c13bfdfbdbee7cc5176a8755e04353a9deb Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 11 Apr 2015 22:44:42 -0700 Subject: 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. --- tests/test_write.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests/test_write.cpp') 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, "premid\npostfin\n\n\n"), STR("\t"), 0); CHECK_NODE_EX(doc, STR("\n\t\n\tpremid\n\t\tpostfin\n\t\n\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, "") +{ + try + { + throwing_writer w; + doc.print(w); + + CHECK_FORCE_FAIL("Expected exception"); + } + catch (std::runtime_error&) + { + } +} + +TEST_XML(write_throw_encoding, "") +{ + try + { + throwing_writer w; + doc.print(w, STR("\t"), format_default, encoding_utf32_be); + + CHECK_FORCE_FAIL("Expected exception"); + } + catch (std::runtime_error&) + { + } +} +#endif -- cgit v1.2.3 From 3da7d68617d196d76b56cff27ad565f64f87d476 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 11 Apr 2015 22:52:41 -0700 Subject: Fix Travis CI build. --- tests/test_write.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/test_write.cpp') diff --git a/tests/test_write.cpp b/tests/test_write.cpp index 230d652..af4acf4 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -4,6 +4,7 @@ #include #include +#include TEST_XML(write_simple, "text") { -- cgit v1.2.3