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;
65 BOOST_AUTO_TEST_CASE (file_naming_test)
68 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat("%c"));
70 auto film = new_test_film ("file_naming_test");
71 film->set_name ("file_naming_test");
72 film->set_video_frame_rate (24);
73 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
74 auto r = make_shared<FFmpegContent>("test/data/flat_red.png");
75 film->examine_and_add_content (r);
76 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
77 film->examine_and_add_content (g);
78 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
79 film->examine_and_add_content (b);
80 BOOST_REQUIRE (!wait_for_jobs());
82 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
83 r->set_video_frame_rate (24);
84 r->video->set_length (24);
85 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
86 g->set_video_frame_rate (24);
87 g->video->set_length (24);
88 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
89 b->set_video_frame_rate (24);
90 b->video->set_length (24);
92 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
93 film->write_metadata ();
97 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
98 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
101 int got[3] = { 0, 0, 0 };
102 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
103 if (boost::regex_match(i.path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
105 } else if (boost::regex_match(i.path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
107 } else if (boost::regex_match(i.path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
112 for (int i = 0; i < 3; ++i) {
113 BOOST_CHECK (got[i] == 2);
118 BOOST_AUTO_TEST_CASE (file_naming_test2)
121 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
123 auto film = new_test_film ("file_naming_test2");
124 film->set_name ("file_naming_test2");
125 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
127 #ifdef DCPOMATIC_WINDOWS
128 /* This is necessary so that the UTF8 string constant below gets converted properly */
129 std::locale::global(boost::locale::generator().generate(""));
130 boost::filesystem::path::imbue(std::locale());
133 auto r = make_shared<FFmpegContent>("test/data/flät_red.png");
134 film->examine_and_add_content (r);
135 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
136 film->examine_and_add_content (g);
137 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
138 film->examine_and_add_content (b);
139 BOOST_REQUIRE (!wait_for_jobs());
141 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
142 r->set_video_frame_rate (24);
143 r->video->set_length (24);
144 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
145 g->set_video_frame_rate (24);
146 g->video->set_length (24);
147 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
148 b->set_video_frame_rate (24);
149 b->video->set_length (24);
151 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
152 make_and_verify_dcp (
155 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
156 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
159 int got[3] = { 0, 0, 0 };
160 for (auto i: boost::filesystem::directory_iterator (film->file(film->dcp_name()))) {
161 if (boost::regex_match(i.path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
163 } else if (boost::regex_match(i.path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
165 } else if (boost::regex_match(i.path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
170 for (int i = 0; i < 3; ++i) {
171 BOOST_CHECK (got[i] == 2);
176 BOOST_AUTO_TEST_CASE (subtitle_file_naming)
180 Config::instance()->set_dcp_asset_filename_format(dcp::NameFormat("%t ostrabagalous %c"));
182 auto content = content_factory("test/data/15s.srt");
183 auto film = new_test_film2("subtitle_file_naming", { content.front() });
184 film->set_interop(false);
186 make_and_verify_dcp (
189 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
190 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
191 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
196 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
197 if (boost::regex_match(i.path().filename().string(), boost::regex("sub_ostrabagalous_15s.*\\.mxf"))) {
202 BOOST_CHECK_EQUAL(got, 1);