From 2d47cde5d6a2cf0aff885b19e5c2100389313481 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 9 Nov 2016 20:06:49 -0800 Subject: tests: Add a generalized write-roundtrip test This test tests two important invariants: - Every combination of write flags has to result in a valid document - Parsing that document and saving the result has to result in identical output We don't test all flags since parse_no_escapes can intentionally result in malformed documents and other flags aren't relevant for node output. Also note that we test both no-whitespace and whitespace version to make sure we don't have unnecessary whitespace added during formatting. --- tests/test_write.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_write.cpp b/tests/test_write.cpp index 8fbcc27..de77339 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -608,6 +608,31 @@ TEST_XML(write_no_empty_element_tags, "text\n\t\n\ttext\n\t\n\n"), STR("\t"), format_indent | format_no_empty_element_tags); } +TEST_XML_FLAGS(write_roundtrip, "premid<text&escapepostfin", parse_full) +{ + const unsigned int flagset[] = { format_indent, format_raw, format_no_declaration, format_indent_attributes, format_no_empty_element_tags }; + size_t flagcount = sizeof(flagset) / sizeof(flagset[0]); + + for (size_t i = 0; i < size_t(1 << flagcount); ++i) + { + unsigned int flags = 0; + + for (size_t j = 0; j < flagcount; ++j) + if (i & (1 << j)) + flags |= flagset[j]; + + std::string contents = write_narrow(doc, flags, encoding_utf8); + + pugi::xml_document verify; + CHECK(verify.load_buffer(contents.c_str(), contents.size(), parse_full)); + CHECK(test_write_narrow(verify, flags, encoding_utf8, contents.c_str(), contents.size())); + + pugi::xml_document verifyws; + CHECK(verifyws.load_buffer(contents.c_str(), contents.size(), parse_full | parse_ws_pcdata)); + CHECK(test_write_narrow(verifyws, flags, encoding_utf8, contents.c_str(), contents.size())); + } +} + #ifndef PUGIXML_NO_EXCEPTIONS struct throwing_writer: pugi::xml_writer { -- cgit v1.2.3