Fix crash with sub-sample push parts in AudioMerger.
[dcpomatic.git] / test / file_naming_test.cc
1 /*
2     Copyright (C) 2016 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 <boost/test/unit_test.hpp>
32 #include <boost/regex.hpp>
33
34 using std::string;
35 using boost::shared_ptr;
36
37 class Keep
38 {
39 public:
40         Keep ()
41         {
42                 _format = Config::instance()->dcp_asset_filename_format ();
43         }
44
45         ~Keep ()
46         {
47                 Config::instance()->set_dcp_asset_filename_format (_format);
48         }
49
50 private:
51         dcp::NameFormat _format;
52 };
53
54 BOOST_AUTO_TEST_CASE (file_naming_test)
55 {
56         Keep k;
57         Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
58
59         shared_ptr<Film> film = new_test_film ("file_naming_test");
60         film->set_name ("file_naming_test");
61         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
62         shared_ptr<FFmpegContent> r (new FFmpegContent("test/data/flat_red.png"));
63         film->examine_and_add_content (r);
64         shared_ptr<FFmpegContent> g (new FFmpegContent("test/data/flat_green.png"));
65         film->examine_and_add_content (g);
66         shared_ptr<FFmpegContent> b (new FFmpegContent("test/data/flat_blue.png"));
67         film->examine_and_add_content (b);
68         BOOST_REQUIRE (!wait_for_jobs());
69
70         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
71         film->make_dcp ();
72         BOOST_REQUIRE (!wait_for_jobs());
73
74         int got[3] = { 0, 0, 0 };
75         for (
76                 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
77                 i != boost::filesystem::directory_iterator();
78                 ++i) {
79                 if (boost::regex_match(i->path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
80                         ++got[0];
81                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
82                         ++got[1];
83                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
84                         ++got[2];
85                 }
86         }
87
88         for (int i = 0; i < 3; ++i) {
89                 BOOST_CHECK (got[i] == 2);
90         }
91 }
92
93 BOOST_AUTO_TEST_CASE (file_naming_test2)
94 {
95         Keep k;
96         Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
97
98         shared_ptr<Film> film = new_test_film ("file_naming_test2");
99         film->set_name ("file_naming_test2");
100         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
101         shared_ptr<FFmpegContent> r (new FFmpegContent("test/data/flät_red.png"));
102         film->examine_and_add_content (r);
103         shared_ptr<FFmpegContent> g (new FFmpegContent("test/data/flat_green.png"));
104         film->examine_and_add_content (g);
105         shared_ptr<FFmpegContent> b (new FFmpegContent("test/data/flat_blue.png"));
106         film->examine_and_add_content (b);
107         BOOST_REQUIRE (!wait_for_jobs());
108
109         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
110         film->make_dcp ();
111         BOOST_REQUIRE (!wait_for_jobs());
112
113         int got[3] = { 0, 0, 0 };
114         for (
115                 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
116                 i != boost::filesystem::directory_iterator();
117                 ++i) {
118                 if (boost::regex_match(i->path().string(), boost::regex(".*flt_red\\.png_.*\\.mxf"))) {
119                         ++got[0];
120                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
121                         ++got[1];
122                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
123                         ++got[2];
124                 }
125         }
126
127         for (int i = 0; i < 3; ++i) {
128                 BOOST_CHECK (got[i] == 2);
129         }
130 }