Fix ISDCF name reference in test.
[dcpomatic.git] / test / isdcf_name_test.cc
1 /*
2     Copyright (C) 2014-2019 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         BOOST_REQUIRE (audio->audio);
63         audio->audio->set_language(dcp::LanguageTag("en-US"));
64         film->set_content_versions({"1"});
65         film->set_release_territory(dcp::LanguageTag::RegionSubtag("GB"));
66         film->set_ratings({dcp::Rating("BBFC", "PG")});
67         film->set_studio (string("ST"));
68         film->set_facility (string("FAC"));
69         film->set_interop (true);
70         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilm_FTR-1_F_EN-XX_GB-PG_10_2K_ST_20140704_FAC_IOP_OV");
71
72         /* Check that specifying no audio language writes XX */
73         audio->audio->set_language (boost::none);
74         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilm_FTR-1_F_XX-XX_GB-PG_10_2K_ST_20140704_FAC_IOP_OV");
75
76         /* Test a long name and some different data */
77
78         film->set_name ("My Nice Film With A Very Long Name");
79         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
80         film->set_container (Ratio::from_id ("239"));
81         film->_isdcf_date = boost::gregorian::date (2014, boost::gregorian::Jul, 4);
82         film->set_audio_channels (1);
83         film->set_resolution (Resolution::FOUR_K);
84         auto text = content_factory("test/data/subrip.srt").front();
85         BOOST_REQUIRE_EQUAL (text->text.size(), 1U);
86         text->text.front()->set_burn (true);
87         text->text.front()->set_language (dcp::LanguageTag("fr-FR"));
88         film->examine_and_add_content (text);
89         film->set_version_number(2);
90         film->set_release_territory(dcp::LanguageTag::RegionSubtag("US"));
91         film->set_ratings({dcp::Rating("MPA", "R")});
92         film->set_studio (string("di"));
93         film->set_facility (string("ppfacility"));
94         BOOST_REQUIRE (!wait_for_jobs());
95         audio = content_factory("test/data/sine_440.wav").front();
96         film->examine_and_add_content (audio);
97         BOOST_REQUIRE (!wait_for_jobs());
98         BOOST_REQUIRE (audio->audio);
99         audio->audio->set_language (dcp::LanguageTag("de-DE"));
100         film->set_interop (false);
101         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_TLR-2_S_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
102
103         /* Test to see that RU ratings like 6+ survive */
104         film->set_ratings({dcp::Rating("RARS", "6+")});
105         BOOST_CHECK_EQUAL (film->dcp_name(false), "MyNiceFilmWith_TLR-2_S_DE-fr_US-6+_MOS_4K_DI_20140704_PPF_SMPTE_OV");
106         film->set_ratings({dcp::Rating("MPA", "R")});
107
108         /* Test interior aspect ratio: shouldn't be shown with trailers */
109
110         shared_ptr<ImageContent> content (new ImageContent ("test/data/simple_testcard_640x480.png"));
111         film->examine_and_add_content (content);
112         BOOST_REQUIRE (!wait_for_jobs());
113         content->video->set_custom_ratio (1.33);
114         film->set_container (Ratio::from_id ("185"));
115         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_TLR-2_F_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
116
117         /* But should be shown for anything else */
118
119         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("XSN"));
120         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-133_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
121
122         /* And it should always be numeric */
123
124         content->video->set_custom_ratio (2.39);
125         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-239_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
126
127         content->video->set_custom_ratio (1.9);
128         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-190_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
129         content->video->set_custom_ratio (1.33);
130
131         /* Test 3D */
132
133         film->set_three_d (true);
134         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");
135
136         /* Test content type modifiers */
137
138         film->set_three_d (false);
139         film->set_temp_version (true);
140         film->set_pre_release (true);
141         film->set_red_band (true);
142         film->set_two_d_version_of_three_d (true);
143         film->set_chain (string("MyChain"));
144         film->set_luminance (dcp::Luminance(4.5, dcp::Luminance::Unit::FOOT_LAMBERT));
145         film->set_video_frame_rate (48);
146         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");
147
148         /* Test a name which is already in camelCase */
149
150         film->set_three_d (false);
151         film->set_temp_version (false);
152         film->set_pre_release (false);
153         film->set_red_band (false);
154         film->set_two_d_version_of_three_d (false);
155         film->set_chain (string(""));
156         film->set_luminance (boost::none);
157         film->set_video_frame_rate (24);
158         film->set_name ("IKnowCamels");
159         BOOST_CHECK_EQUAL (film->isdcf_name(false), "IKnowCamels_XSN-2_F-133_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
160
161         /* And one in capitals */
162
163         film->set_name ("LIKE SHOUTING");
164         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
165
166         /* Test audio channel markup */
167
168         film->set_audio_channels (6);
169         auto sound = make_shared<FFmpegContent>("test/data/sine_440.wav");
170         film->examine_and_add_content (sound);
171         BOOST_REQUIRE (!wait_for_jobs());
172         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_10_4K_DI_20140704_PPF_SMPTE_OV");
173
174         AudioMapping mapping = sound->audio->mapping ();
175
176         mapping.set (0, dcp::Channel::LEFT, 1.0);
177         sound->audio->set_mapping (mapping);
178         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_20_4K_DI_20140704_PPF_SMPTE_OV");
179         mapping.set (0, dcp::Channel::RIGHT, 1.0);
180         sound->audio->set_mapping (mapping);
181         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_30_4K_DI_20140704_PPF_SMPTE_OV");
182         mapping.set (0, dcp::Channel::LFE, 1.0);
183         sound->audio->set_mapping (mapping);
184         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_31_4K_DI_20140704_PPF_SMPTE_OV");
185         mapping.set (0, dcp::Channel::LS, 1.0);
186         sound->audio->set_mapping (mapping);
187         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_41_4K_DI_20140704_PPF_SMPTE_OV");
188         mapping.set (0, dcp::Channel::RS, 1.0);
189         sound->audio->set_mapping (mapping);
190         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51_4K_DI_20140704_PPF_SMPTE_OV");
191         mapping.set (0, dcp::Channel::HI, 1.0);
192         sound->audio->set_mapping (mapping);
193         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51_4K_DI_20140704_PPF_SMPTE_OV");
194
195         film->set_audio_channels (8);
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-HI_4K_DI_20140704_PPF_SMPTE_OV");
199         mapping.set (0, dcp::Channel::VI, 1.0);
200         sound->audio->set_mapping (mapping);
201         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");
202
203         film->set_audio_channels(10);
204         mapping.set (0, dcp::Channel::HI, 0.0);
205         mapping.set (0, dcp::Channel::VI, 0.0);
206         sound->audio->set_mapping (mapping);
207         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51_4K_DI_20140704_PPF_SMPTE_OV");
208         mapping.set (0, dcp::Channel::HI, 1.0);
209         sound->audio->set_mapping (mapping);
210         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51-HI_4K_DI_20140704_PPF_SMPTE_OV");
211         mapping.set (0, dcp::Channel::VI, 1.0);
212         sound->audio->set_mapping (mapping);
213         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");
214
215         film->set_audio_channels(12);
216         mapping.set (0, dcp::Channel::BSL, 1.0);
217         mapping.set (0, dcp::Channel::BSR, 1.0);
218         mapping.set (0, dcp::Channel::HI, 0.0);
219         mapping.set (0, dcp::Channel::VI, 0.0);
220         sound->audio->set_mapping (mapping);
221         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_71_4K_DI_20140704_PPF_SMPTE_OV");
222         mapping.set (0, dcp::Channel::HI, 1.0);
223         sound->audio->set_mapping (mapping);
224         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_71-HI_4K_DI_20140704_PPF_SMPTE_OV");
225         mapping.set (0, dcp::Channel::VI, 1.0);
226         sound->audio->set_mapping (mapping);
227         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");
228 }
229