Test updates now that there can't be <1s long DCPs any more.
[dcpomatic.git] / test / file_naming_test.cc
1 /*
2     Copyright (C) 2016-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 /** @file  test/file_naming_test.cc
22  *  @brief Test how files in DCPs are named.
23  *  @ingroup specific
24  */
25
26 #include "test.h"
27 #include "lib/config.h"
28 #include "lib/film.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>
34
35 using std::string;
36 using boost::shared_ptr;
37
38 class Keep
39 {
40 public:
41         Keep ()
42         {
43                 _format = Config::instance()->dcp_asset_filename_format ();
44         }
45
46         ~Keep ()
47         {
48                 Config::instance()->set_dcp_asset_filename_format (_format);
49         }
50
51 private:
52         dcp::NameFormat _format;
53 };
54
55 BOOST_AUTO_TEST_CASE (file_naming_test)
56 {
57         Keep k;
58         Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
59
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());
71
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);
81
82         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
83         film->write_metadata ();
84         film->make_dcp ();
85         BOOST_REQUIRE (!wait_for_jobs());
86
87         int got[3] = { 0, 0, 0 };
88         for (
89                 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
90                 i != boost::filesystem::directory_iterator();
91                 ++i) {
92                 if (boost::regex_match(i->path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
93                         ++got[0];
94                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
95                         ++got[1];
96                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
97                         ++got[2];
98                 }
99         }
100
101         for (int i = 0; i < 3; ++i) {
102                 BOOST_CHECK (got[i] == 2);
103         }
104 }
105
106 BOOST_AUTO_TEST_CASE (file_naming_test2)
107 {
108         Keep k;
109         Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
110
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());
121
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);
131
132         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
133         film->make_dcp ();
134         BOOST_REQUIRE (!wait_for_jobs());
135
136         int got[3] = { 0, 0, 0 };
137         for (
138                 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
139                 i != boost::filesystem::directory_iterator();
140                 ++i) {
141                 if (boost::regex_match(i->path().string(), boost::regex(".*flt_red\\.png_.*\\.mxf"))) {
142                         ++got[0];
143                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
144                         ++got[1];
145                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
146                         ++got[2];
147                 }
148         }
149
150         for (int i = 0; i < 3; ++i) {
151                 BOOST_CHECK (got[i] == 2);
152         }
153 }