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;
43 using std::shared_ptr;
52 _format = Config::instance()->dcp_asset_filename_format ();
57 Config::instance()->set_dcp_asset_filename_format (_format);
61 dcp::NameFormat _format;
67 mxf_regex(string part) {
68 #ifdef DCPOMATIC_WINDOWS
69 /* Windows replaces . in filenames with _ */
70 return String::compose(".*flat_%1_png_.*\\.mxf", part);
72 return String::compose(".*flat_%1\\.png_.*\\.mxf", part);
78 BOOST_AUTO_TEST_CASE (file_naming_test)
81 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat("%c"));
83 auto film = new_test_film ("file_naming_test");
84 film->set_name ("file_naming_test");
85 film->set_video_frame_rate (24);
86 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
87 auto r = make_shared<FFmpegContent>("test/data/flat_red.png");
88 film->examine_and_add_content (r);
89 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
90 film->examine_and_add_content (g);
91 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
92 film->examine_and_add_content (b);
93 BOOST_REQUIRE (!wait_for_jobs());
95 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
96 r->set_video_frame_rate(film, 24);
97 r->video->set_length (24);
98 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
99 g->set_video_frame_rate(film, 24);
100 g->video->set_length (24);
101 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
102 b->set_video_frame_rate(film, 24);
103 b->video->set_length (24);
105 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
106 film->write_metadata ();
107 make_and_verify_dcp (
110 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
111 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
114 int got[3] = { 0, 0, 0 };
115 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
116 if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("red")))) {
118 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("green")))) {
120 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("blue")))) {
125 for (int i = 0; i < 3; ++i) {
126 BOOST_CHECK (got[i] == 2);
131 BOOST_AUTO_TEST_CASE (file_naming_test2)
134 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
136 auto film = new_test_film ("file_naming_test2");
137 film->set_name ("file_naming_test2");
138 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
140 #ifdef DCPOMATIC_WINDOWS
141 /* This is necessary so that the UTF8 string constant below gets converted properly */
142 std::locale::global(boost::locale::generator().generate(""));
143 boost::filesystem::path::imbue(std::locale());
146 auto r = make_shared<FFmpegContent>("test/data/flät_red.png");
147 film->examine_and_add_content (r);
148 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
149 film->examine_and_add_content (g);
150 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
151 film->examine_and_add_content (b);
152 BOOST_REQUIRE (!wait_for_jobs());
154 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
155 r->set_video_frame_rate(film, 24);
156 r->video->set_length (24);
157 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
158 g->set_video_frame_rate(film, 24);
159 g->video->set_length (24);
160 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
161 b->set_video_frame_rate(film, 24);
162 b->video->set_length (24);
164 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
165 make_and_verify_dcp (
168 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
169 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
172 int got[3] = { 0, 0, 0 };
173 for (auto i: boost::filesystem::directory_iterator (film->file(film->dcp_name()))) {
174 if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("red")))) {
176 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("green")))) {
178 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("blue")))) {
183 for (int i = 0; i < 3; ++i) {
184 BOOST_CHECK (got[i] == 2);
189 BOOST_AUTO_TEST_CASE (subtitle_file_naming)
193 Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%t ostrabagalous %c"));
195 auto content = content_factory("test/data/15s.srt");
196 auto film = new_test_film2("subtitle_file_naming", content);
197 film->set_interop(false);
199 make_and_verify_dcp (
202 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
203 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
204 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
209 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
210 if (boost::regex_match(i.path().filename().string(), boost::regex("sub_ostrabagalous_15s.*\\.mxf"))) {
215 BOOST_CHECK_EQUAL(got, 1);