Fix tests.
authorCarl Hetherington <cth@carlh.net>
Sun, 22 Jan 2023 19:53:07 +0000 (20:53 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 27 Feb 2023 13:56:44 +0000 (14:56 +0100)
run/tests
test/data
test/subtitle_position_test.cc

index 0fafa3c5e9a7d18e7dee0dd02c1f1cc727923843..282d923bbe21dc069cf205229a1fca166f5840c4 100755 (executable)
--- a/run/tests
+++ b/run/tests
@@ -3,7 +3,7 @@
 # e.g. --run_tests=foo
 set -e
 
-PRIVATE_GIT="6ae250072192de2e56243da1883a6fa13e56aaf4"
+PRIVATE_GIT="0af96c8d8f28e71b8b1a19e3ea5637fcba5e913e"
 
 if [ "$1" == "--check" ]; then
        shift 1
index 3e257c17fa5aa43b907af78d23c3fb810eaabdb2..aede894d8bf60f18915bf6f7046af05d9bfe585e 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 3e257c17fa5aa43b907af78d23c3fb810eaabdb2
+Subproject commit aede894d8bf60f18915bf6f7046af05d9bfe585e
index 3b35c02c6d2fd4c065fccfb862e3196356015418..94a06b7f82ea2c1dbc6ab924c771f374ed2fd833 100644 (file)
 #include "lib/text_content.h"
 #include "test.h"
 #include <dcp/interop_subtitle_asset.h>
-#include <dcp/smpte_subtitle_asset.h>
 #include <dcp/language_tag.h>
+#include <dcp/smpte_subtitle_asset.h>
 #include <boost/test/unit_test.hpp>
 #include <vector>
 
 
+using std::shared_ptr;
 using std::string;
 using std::vector;
-using std::shared_ptr;
 
 
-BOOST_AUTO_TEST_CASE(interop_correctly_placed_in_interop)
+BOOST_AUTO_TEST_CASE(srt_correctly_placed_in_interop)
 {
-       string const name = "interop_in_interop_position_test";
-       auto fr = content_factory("test/data/dcp_sub.xml");
+       string const name = "srt_in_interop_position_test";
+       auto fr = content_factory("test/data/short.srt");
        auto film = new_test_film2(name, fr);
 
        film->set_interop(true);
@@ -50,78 +50,67 @@ BOOST_AUTO_TEST_CASE(interop_correctly_placed_in_interop)
                {
                        dcp::VerificationNote::Code::INVALID_STANDARD,
                        dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
-                       dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION
+                       dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
                });
 
        auto output = subtitle_file(film);
+
        dcp::InteropSubtitleAsset asset(output);
        auto output_subs = asset.subtitles();
        BOOST_REQUIRE_EQUAL(output_subs.size(), 1U);
 
-       /* The input subtitle should have been left alone */
        BOOST_CHECK(output_subs[0]->v_align() == dcp::VAlign::BOTTOM);
-       BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.08, 1e-3);
+       BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.172726989, 1e-3);
 }
 
 
-BOOST_AUTO_TEST_CASE(interop_correctly_placed_in_smpte)
+BOOST_AUTO_TEST_CASE(srt_correctly_placed_in_smpte)
 {
-       string const name = "interop_in_smpte_position_test";
-       auto fr = content_factory("test/data/dcp_sub.xml");
+       string const name = "srt_in_smpte_position_test";
+       auto fr = content_factory("test/data/short.srt");
        auto film = new_test_film2(name, fr);
 
+       fr[0]->text[0]->set_language(dcp::LanguageTag("en-GB"));
        film->set_interop(false);
 
        make_and_verify_dcp (
                film,
                {
-                       dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
-                       dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
                        dcp::VerificationNote::Code::MISSING_CPL_METADATA,
+                       dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
                        dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
                });
 
        auto output = subtitle_file(film);
+
        dcp::SMPTESubtitleAsset asset(output);
        auto output_subs = asset.subtitles();
        BOOST_REQUIRE_EQUAL(output_subs.size(), 1U);
 
        BOOST_CHECK(output_subs[0]->v_align() == dcp::VAlign::BOTTOM);
-       BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.07074, 2);
-}
-
-
-BOOST_AUTO_TEST_CASE(smpte_correctly_placed_in_interop)
-{
-       string const name = "smpte_in_interop_position_test";
-       auto fr = content_factory("test/data/short.srt");
-       auto film = new_test_film2(name, fr);
-
-       film->set_interop(true);
-
-       make_and_verify_dcp (
-               film,
-               {
-                       dcp::VerificationNote::Code::INVALID_STANDARD,
-                       dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
-                       dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
-               });
-
-       auto output = subtitle_file(film);
-       dcp::InteropSubtitleAsset asset(output);
-       auto output_subs = asset.subtitles();
-       BOOST_REQUIRE_EQUAL(output_subs.size(), 1U);
-
-       BOOST_CHECK(output_subs[0]->v_align() == dcp::VAlign::TOP);
-       BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.87079, 1e-3);
+       BOOST_CHECK_CLOSE(output_subs[0]->v_position(), 0.172726989, 1e-3);
 }
 
 
+/** Make a DCP from some DCP subtitles and check the vertical alignment */
 static
 void
-vpos_test(dcp::VAlign reference, float position, dcp::Standard from, dcp::Standard to)
+vpos_test(dcp::VAlign reference, float position, dcp::SubtitleStandard from, dcp::Standard to)
 {
-       string standard = from == dcp::Standard::INTEROP ? "interop" : "smpte";
+       string standard;
+       switch (from) {
+               case dcp::SubtitleStandard::SMPTE_2007:
+               case dcp::SubtitleStandard::SMPTE_2010:
+                       standard = "smpte_2010";
+                       break;
+               case dcp::SubtitleStandard::INTEROP:
+                       standard = "interop";
+                       break;
+               case dcp::SubtitleStandard::SMPTE_2014:
+                       standard = "smpte_2014";
+                       break;
+       }
+
        auto name = String::compose("vpos_test_%1_%2", standard, valign_to_string(reference));
        auto in = content_factory(String::compose("test/data/%1.xml", name));
        auto film = new_test_film2(name, in);
@@ -154,11 +143,43 @@ BOOST_AUTO_TEST_CASE(subtitles_correctly_placed_with_all_references)
        constexpr auto baseline_to_bottom = 0.00925926;
        constexpr auto height = 0.0462963;
 
-       vpos_test(dcp::VAlign::TOP, 0.2 - height + baseline_to_bottom, dcp::Standard::INTEROP, dcp::Standard::SMPTE);
-       vpos_test(dcp::VAlign::CENTER, 0.11 - (height / 2) + baseline_to_bottom, dcp::Standard::INTEROP, dcp::Standard::SMPTE);
-       vpos_test(dcp::VAlign::BOTTOM, 0.08 - baseline_to_bottom, dcp::Standard::INTEROP, dcp::Standard::SMPTE);
-       vpos_test(dcp::VAlign::TOP, 0.1 + height - baseline_to_bottom, dcp::Standard::SMPTE, dcp::Standard::INTEROP);
-       vpos_test(dcp::VAlign::CENTER, 0.15 + (height / 2) - baseline_to_bottom, dcp::Standard::SMPTE, dcp::Standard::INTEROP);
-       vpos_test(dcp::VAlign::BOTTOM, 0.10 + baseline_to_bottom, dcp::Standard::SMPTE, dcp::Standard::INTEROP);
+       /* Interop source */
+       auto from = dcp::SubtitleStandard::INTEROP;
+
+       // -> Interop
+       vpos_test(dcp::VAlign::TOP, 0.2, from, dcp::Standard::INTEROP);
+       vpos_test(dcp::VAlign::CENTER, 0.11, from, dcp::Standard::INTEROP);
+       vpos_test(dcp::VAlign::BOTTOM, 0.08, from, dcp::Standard::INTEROP);
+
+       // -> SMPTE (2014)
+       vpos_test(dcp::VAlign::TOP, 0.2, from, dcp::Standard::SMPTE);
+       vpos_test(dcp::VAlign::CENTER, 0.11, from, dcp::Standard::SMPTE);
+       vpos_test(dcp::VAlign::BOTTOM, 0.08, from, dcp::Standard::SMPTE);
+
+       /* SMPTE 2010 source */
+       from = dcp::SubtitleStandard::SMPTE_2010;
+
+       // -> Interop
+       vpos_test(dcp::VAlign::TOP, 0.1 + height - baseline_to_bottom, from, dcp::Standard::INTEROP);
+       vpos_test(dcp::VAlign::CENTER, 0.15 + (height / 2) - baseline_to_bottom, from, dcp::Standard::INTEROP);
+       vpos_test(dcp::VAlign::BOTTOM, 0.10 + baseline_to_bottom, from, dcp::Standard::INTEROP);
+
+       // -> SMPTE (2014)
+       vpos_test(dcp::VAlign::TOP, 0.1 + height - baseline_to_bottom, from, dcp::Standard::SMPTE);
+       vpos_test(dcp::VAlign::CENTER, 0.15 + (height / 2) - baseline_to_bottom, from, dcp::Standard::SMPTE);
+       vpos_test(dcp::VAlign::BOTTOM, 0.10 + baseline_to_bottom, from, dcp::Standard::SMPTE);
+
+       /* SMPTE 2014 source */
+       from = dcp::SubtitleStandard::SMPTE_2014;
+
+       // -> Interop
+       vpos_test(dcp::VAlign::TOP, 0.2, from, dcp::Standard::INTEROP);
+       vpos_test(dcp::VAlign::CENTER, 0.11, from, dcp::Standard::INTEROP);
+       vpos_test(dcp::VAlign::BOTTOM, 0.08, from, dcp::Standard::INTEROP);
+
+       // -> SMPTE (2014)
+       vpos_test(dcp::VAlign::TOP, 0.2, from, dcp::Standard::SMPTE);
+       vpos_test(dcp::VAlign::CENTER, 0.11, from, dcp::Standard::SMPTE);
+       vpos_test(dcp::VAlign::BOTTOM, 0.08, from, dcp::Standard::SMPTE);
 }