More <iostream> includes for Arch.
[dcpomatic.git] / test / isdcf_name_test.cc
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <boost/test/unit_test.hpp>
21 #include "lib/film.h"
22 #include "lib/ratio.h"
23 #include "lib/dcp_content_type.h"
24 #include "lib/image_content.h"
25 #include "lib/sndfile_content.h"
26 #include "test.h"
27 #include <iostream>
28
29 using std::cout;
30 using boost::shared_ptr;
31
32 BOOST_AUTO_TEST_CASE (isdcf_name_test)
33 {
34         shared_ptr<Film> film = new_test_film ("isdcf_name_test");
35
36         /* A basic test */
37
38         film->set_name ("My Nice Film");
39         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
40         film->set_container (Ratio::from_id ("185"));
41         film->_isdcf_date = boost::gregorian::date (2014, boost::gregorian::Jul, 4);
42         ISDCFMetadata m;
43         m.content_version = 1;
44         m.audio_language = "EN";
45         m.subtitle_language = "XX";
46         m.territory = "UK";
47         m.rating = "PG";
48         m.studio = "ST";
49         m.facility = "FA";
50         m.package_type = "OV";
51         film->set_isdcf_metadata (m);
52         film->set_interop (true);
53         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilm_FTR-1_F_EN-XX_UK-PG_2K_ST_20140704_FA_IOP_OV");
54
55         /* Test a long name and some different data */
56
57         film->set_name ("My Nice Film With A Very Long Name");
58         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
59         film->set_container (Ratio::from_id ("239"));
60         film->_isdcf_date = boost::gregorian::date (2014, boost::gregorian::Jul, 4);
61         film->set_audio_channels (1);
62         film->set_resolution (RESOLUTION_4K);
63         m.content_version = 2;
64         m.audio_language = "DE";
65         m.subtitle_language = "FR";
66         m.territory = "US";
67         m.rating = "R";
68         m.studio = "DI";
69         m.facility = "PP";
70         m.package_type = "VF";
71         film->set_isdcf_metadata (m);
72         film->set_interop (false);
73         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_TLR-2_S_DE-FR_US-R_4K_DI_20140704_PP_SMPTE_VF");
74
75         /* Test interior aspect ratio: shouldn't be shown with trailers */
76
77         shared_ptr<ImageContent> content (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
78         film->examine_and_add_content (content);
79         wait_for_jobs ();
80         content->set_scale (VideoContentScale (Ratio::from_id ("133")));
81         film->set_container (Ratio::from_id ("185"));
82         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_TLR-2_F_DE-FR_US-R_4K_DI_20140704_PP_SMPTE_VF");
83
84         /* But should be shown for anything else */
85
86         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("XSN"));
87         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-133_DE-FR_US-R_4K_DI_20140704_PP_SMPTE_VF");
88
89         /* Test 3D */
90
91         film->set_three_d (true);
92         BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2-3D_F-133_DE-FR_US-R_4K_DI_20140704_PP_SMPTE-3D_VF");
93
94         /* Test content type modifiers */
95
96         film->set_three_d (false);
97         m.temp_version = true;
98         m.pre_release = true;
99         m.red_band = true;
100         m.chain = "MyChain";
101         m.two_d_version_of_three_d = true;
102         m.mastered_luminance = "4fl";
103         film->set_isdcf_metadata (m);
104         film->set_video_frame_rate (48);
105         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_VF");
106
107         /* Test a name which is already in camelCase */
108
109         film->set_three_d (false);
110         m.temp_version = false;
111         m.pre_release = false;
112         m.red_band = false;
113         m.chain = "";
114         m.two_d_version_of_three_d = false;
115         m.mastered_luminance = "";
116         film->set_isdcf_metadata (m);
117         film->set_video_frame_rate (24);
118         film->set_name ("IKnowCamels");
119         BOOST_CHECK_EQUAL (film->isdcf_name(false), "IKnowCamels_XSN-2_F-133_DE-FR_US-R_4K_DI_20140704_PP_SMPTE_VF");
120
121         /* And one in capitals */
122
123         film->set_name ("LIKE SHOUTING");
124         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_4K_DI_20140704_PP_SMPTE_VF");
125
126         /* Test audio channel markup */
127
128         film->set_audio_channels (6);
129         shared_ptr<SndfileContent> sound (new SndfileContent (film, "test/data/sine_440.wav"));
130         film->examine_and_add_content (sound);
131         wait_for_jobs ();
132         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_10_4K_DI_20140704_PP_SMPTE_VF");
133
134         AudioMapping mapping = sound->audio_mapping ();
135
136         mapping.set (0, dcp::LEFT, 1.0);
137         sound->set_audio_mapping (mapping);
138         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_20_4K_DI_20140704_PP_SMPTE_VF");
139         mapping.set (0, dcp::RIGHT, 1.0);
140         sound->set_audio_mapping (mapping);
141         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_30_4K_DI_20140704_PP_SMPTE_VF");
142         mapping.set (0, dcp::LFE, 1.0);
143         sound->set_audio_mapping (mapping);
144         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_31_4K_DI_20140704_PP_SMPTE_VF");
145         mapping.set (0, dcp::LS, 1.0);
146         sound->set_audio_mapping (mapping);
147         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_41_4K_DI_20140704_PP_SMPTE_VF");
148         mapping.set (0, dcp::RS, 1.0);
149         sound->set_audio_mapping (mapping);
150         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_51_4K_DI_20140704_PP_SMPTE_VF");
151         mapping.set (0, dcp::HI, 1.0);
152         sound->set_audio_mapping (mapping);
153         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_51_4K_DI_20140704_PP_SMPTE_VF");
154         film->set_audio_channels (8);
155         mapping.set (0, dcp::HI, 1.0);
156         sound->set_audio_mapping (mapping);
157         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_61_4K_DI_20140704_PP_SMPTE_VF");
158         mapping.set (0, dcp::VI, 1.0);
159         sound->set_audio_mapping (mapping);
160         BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_71_4K_DI_20140704_PP_SMPTE_VF");
161 }
162
163