2 Copyright (C) 2016-2020 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/>.
21 /** @file test/file_naming_test.cc
22 * @brief Test how files in DCPs are named.
27 #include "lib/config.h"
29 #include "lib/ffmpeg_content.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/video_content.h"
32 #ifdef DCPOMATIC_WINDOWS
33 #include <boost/locale.hpp>
35 #include <boost/test/unit_test.hpp>
36 #include <boost/regex.hpp>
39 using std::shared_ptr;
46 _format = Config::instance()->dcp_asset_filename_format ();
51 Config::instance()->set_dcp_asset_filename_format (_format);
55 dcp::NameFormat _format;
58 BOOST_AUTO_TEST_CASE (file_naming_test)
61 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
63 shared_ptr<Film> film = new_test_film ("file_naming_test");
64 film->set_name ("file_naming_test");
65 film->set_video_frame_rate (24);
66 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
67 shared_ptr<FFmpegContent> r (new FFmpegContent("test/data/flat_red.png"));
68 film->examine_and_add_content (r);
69 shared_ptr<FFmpegContent> g (new FFmpegContent("test/data/flat_green.png"));
70 film->examine_and_add_content (g);
71 shared_ptr<FFmpegContent> b (new FFmpegContent("test/data/flat_blue.png"));
72 film->examine_and_add_content (b);
73 BOOST_REQUIRE (!wait_for_jobs());
75 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
76 r->set_video_frame_rate (24);
77 r->video->set_length (24);
78 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
79 g->set_video_frame_rate (24);
80 g->video->set_length (24);
81 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
82 b->set_video_frame_rate (24);
83 b->video->set_length (24);
85 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
86 film->write_metadata ();
88 BOOST_REQUIRE (!wait_for_jobs());
90 int got[3] = { 0, 0, 0 };
92 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
93 i != boost::filesystem::directory_iterator();
95 if (boost::regex_match(i->path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
97 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
99 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
104 for (int i = 0; i < 3; ++i) {
105 BOOST_CHECK (got[i] == 2);
109 BOOST_AUTO_TEST_CASE (file_naming_test2)
112 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
114 shared_ptr<Film> film = new_test_film ("file_naming_test2");
115 film->set_name ("file_naming_test2");
116 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
118 #ifdef DCPOMATIC_WINDOWS
119 /* This is necessary so that the UTF8 string constant below gets converted properly */
120 std::locale::global(boost::locale::generator().generate(""));
121 boost::filesystem::path::imbue(std::locale());
124 shared_ptr<FFmpegContent> r (new FFmpegContent("test/data/flät_red.png"));
125 film->examine_and_add_content (r);
126 shared_ptr<FFmpegContent> g (new FFmpegContent("test/data/flat_green.png"));
127 film->examine_and_add_content (g);
128 shared_ptr<FFmpegContent> b (new FFmpegContent("test/data/flat_blue.png"));
129 film->examine_and_add_content (b);
130 BOOST_REQUIRE (!wait_for_jobs());
132 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
133 r->set_video_frame_rate (24);
134 r->video->set_length (24);
135 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
136 g->set_video_frame_rate (24);
137 g->video->set_length (24);
138 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
139 b->set_video_frame_rate (24);
140 b->video->set_length (24);
142 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
144 BOOST_REQUIRE (!wait_for_jobs());
146 int got[3] = { 0, 0, 0 };
148 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
149 i != boost::filesystem::directory_iterator();
151 if (boost::regex_match(i->path().string(), boost::regex(".*flt_red\\.png_.*\\.mxf"))) {
153 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
155 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
160 for (int i = 0; i < 3; ++i) {
161 BOOST_CHECK (got[i] == 2);