Add test for incorrect ISDCF name with full-frame content, and fix it (#1118).
[dcpomatic.git] / test / isdcf_name_test.cc
1 /*
2     Copyright (C) 2014-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/isdcf_name_test.cc
22  *  @brief Test creation of ISDCF names.
23  *  @ingroup specific
24  */
25
26 #include <boost/test/unit_test.hpp>
27 #include "lib/film.h"
28 #include "lib/ratio.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/image_content.h"
31 #include "lib/video_content.h"
32 #include "lib/audio_mapping.h"
33 #include "lib/ffmpeg_content.h"
34 #include "lib/audio_content.h"
35 #include "test.h"
36 #include <iostream>
37
38 using std::cout;
39 using boost::shared_ptr;
40
41 BOOST_AUTO_TEST_CASE (isdcf_name_test)
42 {
43         shared_ptr<Film> film = new_test_film ("isdcf_name_test");
44
45         /* A basic test */
46
47         film->set_name ("My Nice Film");
48         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
49         film->set_container (Ratio::from_id ("185"));
50         film->_isdcf_date = boost::gregorian::date (2014, boost::gregorian::Jul, 4);
51         ISDCFMetadata m;
52         m.content_version = 1;
53         m.audio_language = "EN";
54         m.subtitle_language = "XX";
55         m.territory = "UK";
56         m.rating = "PG";
57         m.studio = "ST";
58         m.facility = "FA";
59         film->set_isdcf_metadata (m);
60         film->set_interop (true);
61         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilm_FTR-1_F_EN-XX_UK-PG_2K_ST_20140704_FA_IOP_OV");
62
63         /* Test a long name and some different data */
64
65         film->set_name ("My Nice Film With A Very Long Name");
66         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
67         film->set_container (Ratio::from_id ("239"));
68         film->_isdcf_date = boost::gregorian::date (2014, boost::gregorian::Jul, 4);
69         film->set_audio_channels (1);
70         film->set_resolution (RESOLUTION_4K);
71         m.content_version = 2;
72         m.audio_language = "DE";
73         m.subtitle_language = "FR";
74         m.territory = "US";
75         m.rating = "R";
76         m.studio = "DI";
77         m.facility = "PP";
78         film->set_isdcf_metadata (m);
79         film->set_interop (false);
80         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_TLR-2_S_DE-fr_US-R_4K_DI_20140704_PP_SMPTE_OV");
81
82         /* Test interior aspect ratio: shouldn't be shown with trailers */
83
84         shared_ptr<ImageContent> content (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
85         film->examine_and_add_content (content);
86         wait_for_jobs ();
87         content->video->set_scale (VideoContentScale (Ratio::from_id ("133")));
88         film->set_container (Ratio::from_id ("185"));
89         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_TLR-2_F_DE-fr_US-R_4K_DI_20140704_PP_SMPTE_OV");
90
91         /* But should be shown for anything else */
92
93         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("XSN"));
94         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-133_DE-fr_US-R_4K_DI_20140704_PP_SMPTE_OV");
95
96         /* And it should always be numeric */
97
98         content->video->set_scale (VideoContentScale (Ratio::from_id ("239")));
99         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-239_DE-fr_US-R_4K_DI_20140704_PP_SMPTE_OV");
100
101         content->video->set_scale (VideoContentScale (Ratio::from_id ("190")));
102         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-190_DE-fr_US-R_4K_DI_20140704_PP_SMPTE_OV");
103         content->video->set_scale (VideoContentScale (Ratio::from_id ("133")));
104
105         /* Test 3D */
106
107         film->set_three_d (true);
108         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2-3D_F-133_DE-fr_US-R_4K_DI_20140704_PP_SMPTE-3D_OV");
109
110         /* Test content type modifiers */
111
112         film->set_three_d (false);
113         m.temp_version = true;
114         m.pre_release = true;
115         m.red_band = true;
116         m.chain = "MyChain";
117         m.two_d_version_of_three_d = true;
118         m.mastered_luminance = "4fl";
119         film->set_isdcf_metadata (m);
120         film->set_video_frame_rate (48);
121         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2-Temp-Pre-RedBand-MyChain-2D-4fl-48_F-133_DE-fr_US-R_4K_DI_20140704_PP_SMPTE_OV");
122
123         /* Test a name which is already in camelCase */
124
125         film->set_three_d (false);
126         m.temp_version = false;
127         m.pre_release = false;
128         m.red_band = false;
129         m.chain = "";
130         m.two_d_version_of_three_d = false;
131         m.mastered_luminance = "";
132         film->set_isdcf_metadata (m);
133         film->set_video_frame_rate (24);
134         film->set_name ("IKnowCamels");
135         BOOST_CHECK_EQUAL (film->isdcf_name(false), "IKnowCamels_XSN-2_F-133_DE-fr_US-R_4K_DI_20140704_PP_SMPTE_OV");
136
137         /* And one in capitals */
138
139         film->set_name ("LIKE SHOUTING");
140         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_4K_DI_20140704_PP_SMPTE_OV");
141
142         /* Test audio channel markup */
143
144         film->set_audio_channels (6);
145         shared_ptr<FFmpegContent> sound (new FFmpegContent (film, "test/data/sine_440.wav"));
146         film->examine_and_add_content (sound);
147         wait_for_jobs ();
148         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_10_4K_DI_20140704_PP_SMPTE_OV");
149
150         AudioMapping mapping = sound->audio->mapping ();
151
152         mapping.set (0, dcp::LEFT, 1.0);
153         sound->audio->set_mapping (mapping);
154         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_20_4K_DI_20140704_PP_SMPTE_OV");
155         mapping.set (0, dcp::RIGHT, 1.0);
156         sound->audio->set_mapping (mapping);
157         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_30_4K_DI_20140704_PP_SMPTE_OV");
158         mapping.set (0, dcp::LFE, 1.0);
159         sound->audio->set_mapping (mapping);
160         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_31_4K_DI_20140704_PP_SMPTE_OV");
161         mapping.set (0, dcp::LS, 1.0);
162         sound->audio->set_mapping (mapping);
163         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_41_4K_DI_20140704_PP_SMPTE_OV");
164         mapping.set (0, dcp::RS, 1.0);
165         sound->audio->set_mapping (mapping);
166         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51_4K_DI_20140704_PP_SMPTE_OV");
167         mapping.set (0, dcp::HI, 1.0);
168         sound->audio->set_mapping (mapping);
169         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_51_4K_DI_20140704_PP_SMPTE_OV");
170         film->set_audio_channels (8);
171         mapping.set (0, dcp::HI, 1.0);
172         sound->audio->set_mapping (mapping);
173         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_61_4K_DI_20140704_PP_SMPTE_OV");
174         mapping.set (0, dcp::VI, 1.0);
175         sound->audio->set_mapping (mapping);
176         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_71_4K_DI_20140704_PP_SMPTE_OV");
177 }