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 #include <boost/test/unit_test.hpp>
33 #include <boost/regex.hpp>
36 using boost::shared_ptr;
43 _format = Config::instance()->dcp_asset_filename_format ();
48 Config::instance()->set_dcp_asset_filename_format (_format);
52 dcp::NameFormat _format;
55 BOOST_AUTO_TEST_CASE (file_naming_test)
58 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
60 shared_ptr<Film> film = new_test_film ("file_naming_test");
61 film->set_name ("file_naming_test");
62 film->set_video_frame_rate (24);
63 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
64 shared_ptr<FFmpegContent> r (new FFmpegContent("test/data/flat_red.png"));
65 film->examine_and_add_content (r);
66 shared_ptr<FFmpegContent> g (new FFmpegContent("test/data/flat_green.png"));
67 film->examine_and_add_content (g);
68 shared_ptr<FFmpegContent> b (new FFmpegContent("test/data/flat_blue.png"));
69 film->examine_and_add_content (b);
70 BOOST_REQUIRE (!wait_for_jobs());
72 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
73 r->set_video_frame_rate (24);
74 r->video->set_length (24);
75 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
76 g->set_video_frame_rate (24);
77 g->video->set_length (24);
78 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
79 b->set_video_frame_rate (24);
80 b->video->set_length (24);
82 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
83 film->write_metadata ();
85 BOOST_REQUIRE (!wait_for_jobs());
87 int got[3] = { 0, 0, 0 };
89 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
90 i != boost::filesystem::directory_iterator();
92 if (boost::regex_match(i->path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
94 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
96 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
101 for (int i = 0; i < 3; ++i) {
102 BOOST_CHECK (got[i] == 2);
106 BOOST_AUTO_TEST_CASE (file_naming_test2)
109 Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
111 shared_ptr<Film> film = new_test_film ("file_naming_test2");
112 film->set_name ("file_naming_test2");
113 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
114 shared_ptr<FFmpegContent> r (new FFmpegContent("test/data/flät_red.png"));
115 film->examine_and_add_content (r);
116 shared_ptr<FFmpegContent> g (new FFmpegContent("test/data/flat_green.png"));
117 film->examine_and_add_content (g);
118 shared_ptr<FFmpegContent> b (new FFmpegContent("test/data/flat_blue.png"));
119 film->examine_and_add_content (b);
120 BOOST_REQUIRE (!wait_for_jobs());
122 r->set_position (film, dcpomatic::DCPTime::from_seconds(0));
123 r->set_video_frame_rate (24);
124 r->video->set_length (24);
125 g->set_position (film, dcpomatic::DCPTime::from_seconds(1));
126 g->set_video_frame_rate (24);
127 g->video->set_length (24);
128 b->set_position (film, dcpomatic::DCPTime::from_seconds(2));
129 b->set_video_frame_rate (24);
130 b->video->set_length (24);
132 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
134 BOOST_REQUIRE (!wait_for_jobs());
136 int got[3] = { 0, 0, 0 };
138 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
139 i != boost::filesystem::directory_iterator();
141 if (boost::regex_match(i->path().string(), boost::regex(".*flt_red\\.png_.*\\.mxf"))) {
143 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
145 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
150 for (int i = 0; i < 3; ++i) {
151 BOOST_CHECK (got[i] == 2);