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"
31 #include "lib/ffmpeg_content.h"
32 #include "lib/dcp_content_type.h"
33 #include "lib/video_content.h"
34 #ifdef DCPOMATIC_WINDOWS
35 #include <boost/locale.hpp>
37 #include <boost/test/unit_test.hpp>
38 #include <boost/regex.hpp>
42 using std::shared_ptr;
43 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;
64 BOOST_AUTO_TEST_CASE (file_naming_test)
67 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat("%c"));
69 auto film = new_test_film ("file_naming_test");
70 film->set_name ("file_naming_test");
71 film->set_video_frame_rate (24);
72 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
73 auto r = make_shared<FFmpegContent>("test/data/flat_red.png");
74 film->examine_and_add_content (r);
75 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
76 film->examine_and_add_content (g);
77 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
78 film->examine_and_add_content (b);
79 BOOST_REQUIRE (!wait_for_jobs());
81 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
82 r->set_video_frame_rate (24);
83 r->video->set_length (24);
84 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
85 g->set_video_frame_rate (24);
86 g->video->set_length (24);
87 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
88 b->set_video_frame_rate (24);
89 b->video->set_length (24);
91 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
92 film->write_metadata ();
96 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
97 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
100 int got[3] = { 0, 0, 0 };
101 for (auto i: boost::filesystem::directory_iterator(film->file(film->dcp_name()))) {
102 if (boost::regex_match(i.path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
104 } else if (boost::regex_match(i.path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
106 } else if (boost::regex_match(i.path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
111 for (int i = 0; i < 3; ++i) {
112 BOOST_CHECK (got[i] == 2);
117 BOOST_AUTO_TEST_CASE (file_naming_test2)
120 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
122 auto film = new_test_film ("file_naming_test2");
123 film->set_name ("file_naming_test2");
124 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
126 #ifdef DCPOMATIC_WINDOWS
127 /* This is necessary so that the UTF8 string constant below gets converted properly */
128 std::locale::global(boost::locale::generator().generate(""));
129 boost::filesystem::path::imbue(std::locale());
132 auto r = make_shared<FFmpegContent>("test/data/flät_red.png");
133 film->examine_and_add_content (r);
134 auto g = make_shared<FFmpegContent>("test/data/flat_green.png");
135 film->examine_and_add_content (g);
136 auto b = make_shared<FFmpegContent>("test/data/flat_blue.png");
137 film->examine_and_add_content (b);
138 BOOST_REQUIRE (!wait_for_jobs());
140 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
141 r->set_video_frame_rate (24);
142 r->video->set_length (24);
143 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
144 g->set_video_frame_rate (24);
145 g->video->set_length (24);
146 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
147 b->set_video_frame_rate (24);
148 b->video->set_length (24);
150 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
151 make_and_verify_dcp (
154 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
155 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
158 int got[3] = { 0, 0, 0 };
159 for (auto i: boost::filesystem::directory_iterator (film->file(film->dcp_name()))) {
160 if (boost::regex_match(i.path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
162 } else if (boost::regex_match(i.path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
164 } else if (boost::regex_match(i.path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
169 for (int i = 0; i < 3; ++i) {
170 BOOST_CHECK (got[i] == 2);