Fix test refs right this time (using v2.16.x branch).
[dcpomatic.git] / test / hints_test.cc
index 0e47125d0a8edef8d59cb19eca6a679d05f96239..c228cd07af4c6b38089c259dd9242a0b0785b20f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 */
 
 
+#include "lib/audio_content.h"
 #include "lib/content.h"
 #include "lib/content_factory.h"
+#include "lib/cross.h"
 #include "lib/film.h"
+#include "lib/font.h"
 #include "lib/hints.h"
 #include "lib/text_content.h"
 #include "lib/util.h"
 #include "test.h"
-#include <boost/shared_ptr.hpp>
 #include <boost/test/unit_test.hpp>
 
 
+using std::make_shared;
+using std::shared_ptr;
 using std::string;
 using std::vector;
-using boost::shared_ptr;
+using boost::optional;
 
 
 vector<string> current_hints;
@@ -52,6 +56,8 @@ get_hints (shared_ptr<Film> film)
 {
        current_hints.clear ();
        Hints hints (film);
+       /* None of our tests need the audio analysis, and it is quite time-consuming */
+       hints.disable_audio_analysis ();
        hints.Hint.connect (collect_hint);
        hints.start ();
        hints.join ();
@@ -62,24 +68,29 @@ get_hints (shared_ptr<Film> film)
 
 static
 void
-check (TextType type, string name, string expected_hint)
+check (TextType type, string name, optional<string> expected_hint = optional<string>())
 {
-       shared_ptr<Film> film = new_test_film2 (name);
-       shared_ptr<Content> content = content_factory("test/data/" + name + ".srt").front();
+       auto film = new_test_film2 (name);
+       auto content = content_factory("test/data/" + name + ".srt").front();
        content->text.front()->set_type (type);
+       content->text.front()->set_language (dcp::LanguageTag("en-US"));
        film->examine_and_add_content (content);
        BOOST_REQUIRE (!wait_for_jobs());
-       vector<string> hints = get_hints (film);
-
-       BOOST_REQUIRE_EQUAL (hints.size(), 1);
-       BOOST_CHECK_EQUAL (hints[0], expected_hint);
+       auto hints = get_hints (film);
+
+       if (expected_hint) {
+               BOOST_REQUIRE_EQUAL (hints.size(), 1U);
+               BOOST_CHECK_EQUAL (hints[0], *expected_hint);
+       } else {
+               BOOST_CHECK (hints.empty());
+       }
 }
 
 
 BOOST_AUTO_TEST_CASE (hint_closed_caption_too_long)
 {
        check (
-               TEXT_CLOSED_CAPTION,
+               TextType::CLOSED_CAPTION,
                "hint_closed_caption_too_long",
                String::compose("At least one of your closed caption lines has more than %1 characters.  It is advisable to make each line %1 characters at most in length.", MAX_CLOSED_CAPTION_LENGTH, MAX_CLOSED_CAPTION_LENGTH)
              );
@@ -89,7 +100,7 @@ BOOST_AUTO_TEST_CASE (hint_closed_caption_too_long)
 BOOST_AUTO_TEST_CASE (hint_many_closed_caption_lines)
 {
        check (
-               TEXT_CLOSED_CAPTION,
+               TextType::CLOSED_CAPTION,
                "hint_many_closed_caption_lines",
                String::compose("Some of your closed captions span more than %1 lines, so they will be truncated.", MAX_CLOSED_CAPTION_LINES)
              );
@@ -99,9 +110,9 @@ BOOST_AUTO_TEST_CASE (hint_many_closed_caption_lines)
 BOOST_AUTO_TEST_CASE (hint_subtitle_too_early)
 {
        check (
-               TEXT_OPEN_SUBTITLE,
+               TextType::OPEN_SUBTITLE,
                "hint_subtitle_too_early",
-               "It is advisable to put your first subtitle at least 4 seconds after the start of the DCP to make sure it is seen."
+               string("It is advisable to put your first subtitle at least 4 seconds after the start of the DCP to make sure it is seen.")
                );
 }
 
@@ -109,9 +120,9 @@ BOOST_AUTO_TEST_CASE (hint_subtitle_too_early)
 BOOST_AUTO_TEST_CASE (hint_short_subtitles)
 {
        check (
-               TEXT_OPEN_SUBTITLE,
+               TextType::OPEN_SUBTITLE,
                "hint_short_subtitles",
-               "At least one of your subtitles lasts less than 15 frames.  It is advisable to make each subtitle at least 15 frames long."
+               string("At least one of your subtitles lasts less than 15 frames.  It is advisable to make each subtitle at least 15 frames long.")
                );
 }
 
@@ -119,9 +130,9 @@ BOOST_AUTO_TEST_CASE (hint_short_subtitles)
 BOOST_AUTO_TEST_CASE (hint_subtitles_too_close)
 {
        check (
-               TEXT_OPEN_SUBTITLE,
+               TextType::OPEN_SUBTITLE,
                "hint_subtitles_too_close",
-               "At least one of your subtitles starts less than 2 frames after the previous one.  It is advisable to make the gap between subtitles at least 2 frames."
+               string("At least one of your subtitles starts less than 2 frames after the previous one.  It is advisable to make the gap between subtitles at least 2 frames.")
              );
 }
 
@@ -129,9 +140,9 @@ BOOST_AUTO_TEST_CASE (hint_subtitles_too_close)
 BOOST_AUTO_TEST_CASE (hint_many_subtitle_lines)
 {
        check (
-               TEXT_OPEN_SUBTITLE,
+               TextType::OPEN_SUBTITLE,
                "hint_many_subtitle_lines",
-               "At least one of your subtitles has more than 3 lines.  It is advisable to use no more than 3 lines."
+               string("At least one of your subtitles has more than 3 lines.  It is advisable to use no more than 3 lines.")
              );
 }
 
@@ -139,9 +150,110 @@ BOOST_AUTO_TEST_CASE (hint_many_subtitle_lines)
 BOOST_AUTO_TEST_CASE (hint_subtitle_too_long)
 {
        check (
-               TEXT_OPEN_SUBTITLE,
+               TextType::OPEN_SUBTITLE,
                "hint_subtitle_too_long",
-               "At least one of your subtitle lines has more than 52 characters.  It is advisable to make each line 52 characters at most in length."
+               string("At least one of your subtitle lines has more than 52 characters.  It is recommended to make each line 52 characters at most in length.")
              );
 }
 
+
+BOOST_AUTO_TEST_CASE (hint_subtitle_much_too_long)
+{
+       check (
+               TextType::OPEN_SUBTITLE,
+               "hint_subtitle_much_too_long",
+               string("At least one of your subtitle lines has more than 79 characters.  You should make each line 79 characters at most in length.")
+             );
+}
+
+
+BOOST_AUTO_TEST_CASE (hint_subtitle_mxf_too_big)
+{
+       string const name = "hint_subtitle_mxf_too_big";
+
+       auto film = new_test_film2 (name);
+       auto content = content_factory("test/data/" + name + ".srt").front();
+       content->text.front()->set_type (TextType::OPEN_SUBTITLE);
+       content->text.front()->set_language (dcp::LanguageTag("en-US"));
+       for (int i = 1; i < 512; ++i) {
+               auto font = make_shared<dcpomatic::Font>(String::compose("font_%1", i));
+               font->set_file ("test/data/LiberationSans-Regular.ttf");
+               content->text.front()->add_font(font);
+       }
+       film->examine_and_add_content (content);
+       BOOST_REQUIRE (!wait_for_jobs());
+       auto hints = get_hints (film);
+
+       BOOST_REQUIRE_EQUAL (hints.size(), 1U);
+       BOOST_CHECK_EQUAL (
+               hints[0],
+               "At least one of your subtitle files is larger than " MAX_TEXT_MXF_SIZE_TEXT " in total.  "
+               "You should divide the DCP into shorter reels."
+               );
+}
+
+
+BOOST_AUTO_TEST_CASE (hint_closed_caption_xml_too_big)
+{
+       string const name = "hint_closed_caption_xml_too_big";
+
+       auto film = new_test_film2 (name);
+
+       auto ccap = fopen_boost (String::compose("build/test/%1.srt", name), "w");
+       BOOST_REQUIRE (ccap);
+       for (int i = 0; i < 2048; ++i) {
+               fprintf(ccap, "%d\n", i + 1);
+               int second = i * 2;
+               int minute = second % 60;
+               fprintf(ccap, "00:%02d:%02d,000 --> 00:%02d:%02d,000\n", minute, second, minute, second + 1);
+               fprintf(ccap, "Here are some closed captions.\n\n");
+       }
+       fclose (ccap);
+
+       auto content = content_factory("build/test/" + name + ".srt").front();
+       content->text.front()->set_type (TextType::CLOSED_CAPTION);
+       content->text.front()->set_language (dcp::LanguageTag("en-US"));
+       film->examine_and_add_content (content);
+       BOOST_REQUIRE (!wait_for_jobs());
+       auto hints = get_hints (film);
+
+       BOOST_REQUIRE_EQUAL (hints.size(), 1U);
+       BOOST_CHECK_EQUAL (
+               hints[0],
+               "At least one of your closed caption files' XML part is larger than " MAX_CLOSED_CAPTION_XML_SIZE_TEXT ".  "
+               "You should divide the DCP into shorter reels."
+               );
+}
+
+
+BOOST_AUTO_TEST_CASE (hints_destroyed_while_running)
+{
+       auto film = new_test_film2 ("hints_destroyed_while_running");
+       auto content = content_factory(TestPaths::private_data() / "boon_telly.mkv").front();
+       film->examine_and_add_content (content);
+       BOOST_REQUIRE (!wait_for_jobs());
+
+       auto hints = make_shared<Hints>(film);
+       hints->start ();
+       dcpomatic_sleep_seconds (1);
+       hints.reset ();
+       dcpomatic_sleep_seconds (1);
+}
+
+
+BOOST_AUTO_TEST_CASE (hints_audio_with_no_language)
+{
+       auto content = content_factory("test/data/sine_440.wav").front();
+       auto film = new_test_film2 ("hints_audio_with_no_language", { content });
+       content->audio->set_gain (-6);
+
+       auto hints = get_hints (film);
+       BOOST_REQUIRE_EQUAL (hints.size(), 1U);
+       BOOST_CHECK_EQUAL (
+               hints[0],
+               "Some of your content has audio but you have not set the audio language.  It is advisable to set the audio language "
+               "in the \"DCP\" tab unless your audio has no spoken parts."
+               );
+
+}
+