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;
51 _format = Config::instance()->dcp_asset_filename_format ();
56 Config::instance()->set_dcp_asset_filename_format (_format);
60 dcp::NameFormat _format;
66 mxf_regex(string part) {
67 #ifdef DCPOMATIC_WINDOWS
68 /* Windows replaces . in filenames with _ */
69 return String::compose(".*flat_%1_png_.*\\.mxf", part);
71 return String::compose(".*flat_%1\\.png_.*\\.mxf", part);
77 BOOST_AUTO_TEST_CASE (file_naming_test)
80 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat("%c"));
82 auto film = new_test_film ("file_naming_test");
83 film->set_name ("file_naming_test");
84 film->set_video_frame_rate (24);
85 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
86 auto r = make_shared<FFmpegContent>("test/data/flat_red.png");
87 film->examine_and_add_content (r);
88 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
89 film->examine_and_add_content (g);
90 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
91 film->examine_and_add_content (b);
92 BOOST_REQUIRE (!wait_for_jobs());
94 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
95 r->set_video_frame_rate(film, 24);
96 r->video->set_length (24);
97 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
98 g->set_video_frame_rate(film, 24);
99 g->video->set_length (24);
100 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
101 b->set_video_frame_rate(film, 24);
102 b->video->set_length (24);
104 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
105 film->write_metadata ();
106 make_and_verify_dcp (
109 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
110 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
113 int got[3] = { 0, 0, 0 };
114 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
115 if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("red")))) {
117 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("green")))) {
119 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("blue")))) {
124 for (int i = 0; i < 3; ++i) {
125 BOOST_CHECK (got[i] == 2);
130 BOOST_AUTO_TEST_CASE (file_naming_test2)
133 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
135 auto film = new_test_film ("file_naming_test2");
136 film->set_name ("file_naming_test2");
137 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
139 #ifdef DCPOMATIC_WINDOWS
140 /* This is necessary so that the UTF8 string constant below gets converted properly */
141 std::locale::global(boost::locale::generator().generate(""));
142 boost::filesystem::path::imbue(std::locale());
145 auto r = make_shared<FFmpegContent>("test/data/flät_red.png");
146 film->examine_and_add_content (r);
147 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
148 film->examine_and_add_content (g);
149 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
150 film->examine_and_add_content (b);
151 BOOST_REQUIRE (!wait_for_jobs());
153 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
154 r->set_video_frame_rate(film, 24);
155 r->video->set_length (24);
156 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
157 g->set_video_frame_rate(film, 24);
158 g->video->set_length (24);
159 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
160 b->set_video_frame_rate(film, 24);
161 b->video->set_length (24);
163 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
164 make_and_verify_dcp (
167 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
168 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
171 int got[3] = { 0, 0, 0 };
172 for (auto i: boost::filesystem::directory_iterator (film->file(film->dcp_name()))) {
173 if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("red")))) {
175 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("green")))) {
177 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("blue")))) {
182 for (int i = 0; i < 3; ++i) {
183 BOOST_CHECK (got[i] == 2);
188 BOOST_AUTO_TEST_CASE (subtitle_file_naming)
192 Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%t ostrabagalous %c"));
194 auto content = content_factory("test/data/15s.srt");
195 auto film = new_test_film2("subtitle_file_naming", content);
196 film->set_interop(false);
198 make_and_verify_dcp (
201 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
202 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
203 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
208 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
209 if (boost::regex_match(i.path().filename().string(), boost::regex("sub_ostrabagalous_15s.*\\.mxf"))) {
214 BOOST_CHECK_EQUAL(got, 1);