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 r = make_shared<FFmpegContent>("test/data/flat_red.png");
65 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
66 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
67 auto film = new_test_film("file_naming_test", { r, g, b });
68 film->set_video_frame_rate (24);
70 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
71 r->set_video_frame_rate(film, 24);
72 r->video->set_length (24);
73 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
74 g->set_video_frame_rate(film, 24);
75 g->video->set_length (24);
76 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
77 b->set_video_frame_rate(film, 24);
78 b->video->set_length (24);
80 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
81 film->write_metadata ();
85 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
86 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
89 int got[3] = { 0, 0, 0 };
90 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
91 if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("red")))) {
93 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("green")))) {
95 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("blue")))) {
100 for (int i = 0; i < 3; ++i) {
101 BOOST_CHECK (got[i] == 2);
106 BOOST_AUTO_TEST_CASE (file_naming_test2)
110 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
112 #ifdef DCPOMATIC_WINDOWS
113 /* This is necessary so that the UTF8 string constant below gets converted properly */
114 std::locale::global(boost::locale::generator().generate(""));
115 boost::filesystem::path::imbue(std::locale());
118 auto r = make_shared<FFmpegContent>("test/data/flät_red.png");
119 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
120 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
121 auto film = new_test_film("file_naming_test2", { r, g, b });
123 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
124 r->set_video_frame_rate(film, 24);
125 r->video->set_length (24);
126 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
127 g->set_video_frame_rate(film, 24);
128 g->video->set_length (24);
129 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
130 b->set_video_frame_rate(film, 24);
131 b->video->set_length (24);
133 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
134 make_and_verify_dcp (
137 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
138 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
141 int got[3] = { 0, 0, 0 };
142 for (auto i: boost::filesystem::directory_iterator (film->file(film->dcp_name()))) {
143 if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("red")))) {
145 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("green")))) {
147 } else if (boost::regex_match(i.path().string(), boost::regex(mxf_regex("blue")))) {
152 for (int i = 0; i < 3; ++i) {
153 BOOST_CHECK (got[i] == 2);
158 BOOST_AUTO_TEST_CASE (subtitle_file_naming)
162 Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%t ostrabagalous %c"));
164 auto content = content_factory("test/data/15s.srt");
165 auto film = new_test_film("subtitle_file_naming", content);
166 film->set_interop(false);
168 make_and_verify_dcp (
171 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
172 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
173 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
178 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
179 if (boost::regex_match(i.path().filename().string(), boost::regex("sub_ostrabagalous_15s.*\\.mxf"))) {
184 BOOST_CHECK_EQUAL(got, 1);
188 BOOST_AUTO_TEST_CASE(remove_bad_characters_from_template)
192 /* %z is not recognised, so the % should be discarded so it won't trip
193 * an invalid URI check in make_and_verify_dcp
195 Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%c%z"));
197 auto content = content_factory("test/data/flat_red.png");
198 auto film = new_test_film("remove_bad_characters_from_template", content);
202 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
203 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE