diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-03-15 15:32:49 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-03-19 23:04:35 +0100 |
| commit | ec87fa55c5909ae85429fc5344469cf284e5f6b3 (patch) | |
| tree | 2ea1d5fb73c254dd43844a00796c41bbf7cbd22e /test/shared_subtitle_test.cc | |
| parent | 2516e657c80da672d1ea1ef5b5a189ef8799c070 (diff) | |
Nearly pretty-print subtitle XML (though not in <Text> nodes).
This is an attempt to fix DoM bug #2205.
Diffstat (limited to 'test/shared_subtitle_test.cc')
| -rw-r--r-- | test/shared_subtitle_test.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/shared_subtitle_test.cc b/test/shared_subtitle_test.cc index f18b03db..2231d631 100644 --- a/test/shared_subtitle_test.cc +++ b/test/shared_subtitle_test.cc @@ -167,3 +167,41 @@ BOOST_AUTO_TEST_CASE (pull_fonts_test3) BOOST_CHECK_EQUAL (sub1->font._values["size"], "42"); } + +/* Check that subtitle XML is prettily formatted without inserting any white space into + * <Text> node, which I think has the potential to alter appearance. + */ +BOOST_AUTO_TEST_CASE (format_xml_test1) +{ + xmlpp::Document doc; + auto root = doc.create_root_node("Foo"); + root->add_child("Empty"); + root->add_child("Text")->add_child_text("Hello world"); + root->add_child("Font")->add_child("Text")->add_child_text("Say what"); + auto fred = root->add_child("Text")->add_child("Font"); + fred->set_attribute("bob", "job"); + fred->add_child_text("Fred"); + fred->add_child("Text")->add_child_text("Jim"); + fred->add_child_text("Sheila"); + BOOST_REQUIRE_EQUAL (dcp::SubtitleAsset::format_xml(doc, { {"", "fred"}, {"jim", "sheila"} }), +"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +"<Foo xmlns=\"fred\" xmlns:jim=\"sheila\">\n" +" <Empty/>\n" +" <Text>Hello world</Text>\n" +" <Font>\n" +" <Text>Say what</Text>\n" +" </Font>\n" +" <Text><Font bob=\"job\">Fred<Text>Jim</Text>Sheila</Font></Text>\n" +"</Foo>\n"); +} + + +BOOST_AUTO_TEST_CASE (format_xml_test2) +{ + xmlpp::DomParser parser; + auto path = private_test / "DKH_UT_EN20160601def.xml"; + parser.parse_file(path.string().c_str()); + auto document = parser.get_document(); + check_xml (dcp::file_to_string(private_test / "DKH_UT_EN20160601def.reformatted.xml"), dcp::SubtitleAsset::format_xml(*document, {}), {}); +} + |
