Fill test disk partitions with random noise to expose more bugs.
[dcpomatic.git] / test / isdcf_name_test.cc
1 /*
2     Copyright (C) 2014-2021 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
22 /** @file  test/isdcf_name_test.cc
23  *  @brief Test creation of ISDCF names.
24  *  @ingroup feature
25  */
26
27
28 #include <boost/test/unit_test.hpp>
29 #include "lib/film.h"
30 #include "lib/ratio.h"
31 #include "lib/dcp_content_type.h"
32 #include "lib/image_content.h"
33 #include "lib/video_content.h"
34 #include "lib/audio_mapping.h"
35 #include "lib/ffmpeg_content.h"
36 #include "lib/audio_content.h"
37 #include "lib/content_factory.h"
38 #include "lib/text_content.h"
39 #include "test.h"
40 #include <iostream>
41
42
43 using std::cout;
44 using std::make_shared;
45 using std::shared_ptr;
46 using std::string;
47
48
49 BOOST_AUTO_TEST_CASE (isdcf_name_test)
50 {
51         auto film = new_test_film ("isdcf_name_test");
52
53         /* A basic test */
54
55         film->set_name ("My Nice Film");
56         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
57         film->set_container (Ratio::from_id ("185"));
58         film->_isdcf_date = boost::gregorian::date (2014, boost::gregorian::Jul, 4);
59         auto audio = content_factory("test/data/sine_440.wav").front();
60         film->examine_and_add_content (audio);
61         BOOST_REQUIRE (!wait_for_jobs());
62         film->set_audio_language(dcp::LanguageTag("en-US"));
63         film->set_content_versions({"1"});
64         film->set_release_territory(dcp::LanguageTag::RegionSubtag("GB"));
65         film->set_ratings({dcp::Rating("BBFC", "PG")});
66         film->set_studio (string("ST"));
67         film->set_facility (string("FAC"));
68         film->set_interop (true);
69         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilm_FTR-1_F_EN-XX_GB-PG_10_2K_ST_20140704_FAC_IOP_OV");
70
71         /* Check that specifying no audio language writes XX */
72         film->set_audio_language (boost::none);
73         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilm_FTR-1_F_XX-XX_GB-PG_10_2K_ST_20140704_FAC_IOP_OV");
74
75         /* Test a long name and some different data */
76
77         film->set_name ("My Nice Film With A Very Long Name");
78         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
79         film->set_container (Ratio::from_id ("239"));
80         film->_isdcf_date = boost::gregorian::date (2014, boost::gregorian::Jul, 4);
81         film->set_audio_channels (1);
82         film->set_resolution (Resolution::FOUR_K);
83         auto text = content_factory("test/data/subrip.srt").front();
84         BOOST_REQUIRE_EQUAL (text->text.size(), 1U);
85         text->text.front()->set_burn (true);
86         text->text.front()->set_language (dcp::LanguageTag("fr-FR"));
87         film->examine_and_add_content (text);
88         film->set_version_number(2);
89         film->set_release_territory(dcp::LanguageTag::RegionSubtag("US"));
90         film->set_ratings({dcp::Rating("MPA", "R")});
91         film->set_studio (string("di"));
92         film->set_facility (string("ppfacility"));
93         BOOST_REQUIRE (!wait_for_jobs());
94         audio = content_factory("test/data/sine_440.wav").front();
95         film->examine_and_add_content (audio);
96         BOOST_REQUIRE (!wait_for_jobs());
97         film->set_audio_language (dcp::LanguageTag("de-DE"));
98         film->set_interop (false);
99         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_TLR-2_S_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
100
101         /* Test to see that RU ratings like 6+ survive */
102         film->set_ratings({dcp::Rating("RARS", "6+")});
103         BOOST_CHECK_EQUAL (film->dcp_name(false), "MyNiceFilmWith_TLR-2_S_DE-fr_US-6+_MOS_4K_DI_20140704_PPF_SMPTE_OV");
104         film->set_ratings({dcp::Rating("MPA", "R")});
105
106         /* Test interior aspect ratio: shouldn't be shown with trailers */
107
108         shared_ptr<ImageContent> content (new ImageContent ("test/data/simple_testcard_640x480.png"));
109         film->examine_and_add_content (content);
110         BOOST_REQUIRE (!wait_for_jobs());
111         content->video->set_custom_ratio (1.33);
112         film->set_container (Ratio::from_id ("185"));
113         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_TLR-2_F_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
114
115         /* But should be shown for anything else */
116
117         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("XSN"));
118         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-133_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
119
120         /* And it should always be numeric */
121
122         content->video->set_custom_ratio (2.39);
123         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-239_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
124
125         content->video->set_custom_ratio (1.9);
126         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-190_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
127
128         /* And it should be possible to set any 'strange' ratio, not just the ones we know about */
129         content->video->set_custom_ratio (2.2);
130         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-220_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
131         content->video->set_custom_ratio (1.95);
132         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-195_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
133
134         content->video->set_custom_ratio (1.33);
135
136         /* Test 3D */
137
138         film->set_three_d (true);
139         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2-3D_F-133_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE-3D_OV");
140
141         /* Test content type modifiers */
142
143         film->set_three_d (false);
144         film->set_temp_version (true);
145         film->set_pre_release (true);
146         film->set_red_band (true);
147         film->set_two_d_version_of_three_d (true);
148         film->set_chain (string("MyChain"));
149         film->set_luminance (dcp::Luminance(4.5, dcp::Luminance::Unit::FOOT_LAMBERT));
150         film->set_video_frame_rate (48);
151         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2-Temp-Pre-RedBand-MyChain-2D-4.5fl-48_F-133_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
152
153         /* Test a name which is already in camelCase */
154
155         film->set_three_d (false);
156         film->set_temp_version (false);
157         film->set_pre_release (false);
158         film->set_red_band (false);
159         film->set_two_d_version_of_three_d (false);
160         film->set_chain (string(""));
161         film->set_luminance (boost::none);
162         film->set_video_frame_rate (24);
163         film->set_name ("IKnowCamels");
164         BOOST_CHECK_EQUAL (film->isdcf_name(false), "IKnowCamels_XSN-2_F-133_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
165
166         /* And one in capitals */
167
168         film->set_name ("LIKE SHOUTING");
169         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
170
171         /* Test audio channel markup */
172
173         film->set_audio_channels (6);
174         auto sound = make_shared<FFmpegContent>("test/data/sine_440.wav");
175         film->examine_and_add_content (sound);
176         BOOST_REQUIRE (!wait_for_jobs());
177         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_10_4K_DI_20140704_PPF_SMPTE_OV");
178
179         AudioMapping mapping = sound->audio->mapping ();
180
181         mapping.set (0, dcp::Channel::LEFT, 1.0);
182         sound->audio->set_mapping (mapping);
183         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_20_4K_DI_20140704_PPF_SMPTE_OV");
184         mapping.set (0, dcp::Channel::RIGHT, 1.0);
185         sound->audio->set_mapping (mapping);
186         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_30_4K_DI_20140704_PPF_SMPTE_OV");
187         mapping.set (0, dcp::Channel::LFE, 1.0);
188         sound->audio->set_mapping (mapping);
189         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_31_4K_DI_20140704_PPF_SMPTE_OV");
190         mapping.set (0, dcp::Channel::LS, 1.0);
191         sound->audio->set_mapping (mapping);
192         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_41_4K_DI_20140704_PPF_SMPTE_OV");
193         mapping.set (0, dcp::Channel::RS, 1.0);
194         sound->audio->set_mapping (mapping);
195         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51_4K_DI_20140704_PPF_SMPTE_OV");
196         mapping.set (0, dcp::Channel::HI, 1.0);
197         sound->audio->set_mapping (mapping);
198         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51_4K_DI_20140704_PPF_SMPTE_OV");
199
200         film->set_audio_channels (8);
201         mapping.set (0, dcp::Channel::HI, 1.0);
202         sound->audio->set_mapping (mapping);
203         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51-HI_4K_DI_20140704_PPF_SMPTE_OV");
204         mapping.set (0, dcp::Channel::VI, 1.0);
205         sound->audio->set_mapping (mapping);
206         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51-HI-VI_4K_DI_20140704_PPF_SMPTE_OV");
207
208         film->set_audio_channels(10);
209         mapping.set (0, dcp::Channel::HI, 0.0);
210         mapping.set (0, dcp::Channel::VI, 0.0);
211         sound->audio->set_mapping (mapping);
212         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51_4K_DI_20140704_PPF_SMPTE_OV");
213         mapping.set (0, dcp::Channel::HI, 1.0);
214         sound->audio->set_mapping (mapping);
215         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51-HI_4K_DI_20140704_PPF_SMPTE_OV");
216         mapping.set (0, dcp::Channel::VI, 1.0);
217         sound->audio->set_mapping (mapping);
218         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51-HI-VI_4K_DI_20140704_PPF_SMPTE_OV");
219
220         film->set_audio_channels(12);
221         mapping.set (0, dcp::Channel::BSL, 1.0);
222         mapping.set (0, dcp::Channel::BSR, 1.0);
223         mapping.set (0, dcp::Channel::HI, 0.0);
224         mapping.set (0, dcp::Channel::VI, 0.0);
225         sound->audio->set_mapping (mapping);
226         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_71_4K_DI_20140704_PPF_SMPTE_OV");
227         mapping.set (0, dcp::Channel::HI, 1.0);
228         sound->audio->set_mapping (mapping);
229         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_71-HI_4K_DI_20140704_PPF_SMPTE_OV");
230         mapping.set (0, dcp::Channel::VI, 1.0);
231         sound->audio->set_mapping (mapping);
232         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_71-HI-VI_4K_DI_20140704_PPF_SMPTE_OV");
233
234         /* Check that the proper codes are used, not just part of the language code; in this case, QBP instead of PT (#2235) */
235         film->set_audio_language(dcp::LanguageTag("pt-BR"));
236         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_QBP-fr_US-R_71-HI-VI_4K_DI_20140704_PPF_SMPTE_OV");
237 }
238