2 Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file test/file_naming_test.cc
23 * @brief Test how files in DCPs are named.
29 #include "lib/config.h"
30 #include "lib/content_factory.h"
31 #include "lib/dcp_content_type.h"
32 #include "lib/ffmpeg_content.h"
34 #include "lib/video_content.h"
35 #ifdef DCPOMATIC_WINDOWS
36 #include <boost/locale.hpp>
38 #include <boost/test/unit_test.hpp>
39 #include <boost/regex.hpp>
42 using std::make_shared;
48 mxf_regex(string part) {
49 #ifdef DCPOMATIC_WINDOWS
50 /* Windows replaces . in filenames with _ */
51 return String::compose(".*flat_%1_png_.*\\.mxf", part);
53 return String::compose(".*flat_%1\\.png_.*\\.mxf", part);
59 BOOST_AUTO_TEST_CASE (file_naming_test)
62 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat("%c"));
64 auto film = new_test_film ("file_naming_test");
65 film->set_name ("file_naming_test");
66 film->set_video_frame_rate (24);
67 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
68 auto r = make_shared<FFmpegContent>("test/data/flat_red.png");
69 film->examine_and_add_content (r);
70 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
71 film->examine_and_add_content (g);
72 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
73 film->examine_and_add_content (b);
74 BOOST_REQUIRE (!wait_for_jobs());
76 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
77 r->set_video_frame_rate(film, 24);
78 r->video->set_length (24);
79 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
80 g->set_video_frame_rate(film, 24);
81 g->video->set_length (24);
82 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
83 b->set_video_frame_rate(film, 24);
84 b->video->set_length (24);
86 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
87 film->write_metadata ();
91 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
92 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
95 int got[3] = { 0, 0, 0 };
96 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
97 if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("red")))) {
99 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("green")))) {
101 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("blue")))) {
106 for (int i = 0; i < 3; ++i) {
107 BOOST_CHECK (got[i] == 2);
112 BOOST_AUTO_TEST_CASE (file_naming_test2)
116 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
118 auto film = new_test_film ("file_naming_test2");
119 film->set_name ("file_naming_test2");
120 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
122 #ifdef DCPOMATIC_WINDOWS
123 /* This is necessary so that the UTF8 string constant below gets converted properly */
124 std::locale::global(boost::locale::generator().generate(""));
125 boost::filesystem::path::imbue(std::locale());
128 auto r = make_shared<FFmpegContent>("test/data/flät_red.png");
129 film->examine_and_add_content (r);
130 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
131 film->examine_and_add_content (g);
132 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
133 film->examine_and_add_content (b);
134 BOOST_REQUIRE (!wait_for_jobs());
136 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
137 r->set_video_frame_rate(film, 24);
138 r->video->set_length (24);
139 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
140 g->set_video_frame_rate(film, 24);
141 g->video->set_length (24);
142 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
143 b->set_video_frame_rate(film, 24);
144 b->video->set_length (24);
146 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
147 make_and_verify_dcp (
150 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
151 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
154 int got[3] = { 0, 0, 0 };
155 for (auto i: boost::filesystem::directory_iterator (film->file(film->dcp_name()))) {
156 if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("red")))) {
158 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("green")))) {
160 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("blue")))) {
165 for (int i = 0; i < 3; ++i) {
166 BOOST_CHECK (got[i] == 2);
171 BOOST_AUTO_TEST_CASE (subtitle_file_naming)
175 Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%t ostrabagalous %c"));
177 auto content = content_factory("test/data/15s.srt");
178 auto film = new_test_film2("subtitle_file_naming", content);
179 film->set_interop(false);
181 make_and_verify_dcp (
184 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
185 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
186 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
191 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
192 if (boost::regex_match(i.path().filename().string(), boost::regex("sub_ostrabagalous_15s.*\\.mxf"))) {
197 BOOST_CHECK_EQUAL(got, 1);
201 BOOST_AUTO_TEST_CASE(remove_bad_characters_from_template)
205 /* %z is not recognised, so the % should be discarded so it won't trip
206 * an invalid URI check in make_and_verify_dcp
208 Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%c%z"));
210 auto content = content_factory("test/data/flat_red.png");
211 auto film = new_test_film2("remove_bad_characters_from_template", content);
215 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
216 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE