Basics of allowing custom filenames for DCP components.
[libdcp.git] / test / write_subtitle_test.cc
1 /*
2     Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp 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     libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "interop_subtitle_asset.h"
21 #include "smpte_subtitle_asset.h"
22 #include "subtitle_string.h"
23 #include "test.h"
24 #include <boost/test/unit_test.hpp>
25
26 using std::list;
27 using std::string;
28 using boost::shared_ptr;
29
30 /* Write some subtitle content as Interop XML and check that it is right */
31 BOOST_AUTO_TEST_CASE (write_interop_subtitle_test)
32 {
33         dcp::InteropSubtitleAsset c;
34         c.set_reel_number ("1");
35         c.set_language ("EN");
36         c.set_movie_title ("Test");
37
38         c.add (
39                 dcp::SubtitleString (
40                         string ("Frutiger"),
41                         false,
42                         false,
43                         false,
44                         dcp::Colour (255, 255, 255),
45                         48,
46                         1.0,
47                         dcp::Time (0, 4,  9, 22, 24),
48                         dcp::Time (0, 4, 11, 22, 24),
49                         0,
50                         dcp::HALIGN_CENTER,
51                         0.8,
52                         dcp::VALIGN_TOP,
53                         dcp::DIRECTION_LTR,
54                         "Hello world",
55                         dcp::NONE,
56                         dcp::Colour (0, 0, 0),
57                         dcp::Time (0, 0, 0, 0, 24),
58                         dcp::Time (0, 0, 0, 0, 24)
59                         )
60                 );
61
62         c.add (
63                 dcp::SubtitleString (
64                         boost::optional<string> (),
65                         true,
66                         true,
67                         true,
68                         dcp::Colour (128, 0, 64),
69                         91,
70                         1.0,
71                         dcp::Time (5, 41,  0, 21, 24),
72                         dcp::Time (6, 12, 15, 21, 24),
73                         0,
74                         dcp::HALIGN_CENTER,
75                         0.4,
76                         dcp::VALIGN_BOTTOM,
77                         dcp::DIRECTION_LTR,
78                         "What's going on",
79                         dcp::BORDER,
80                         dcp::Colour (1, 2, 3),
81                         dcp::Time (1, 2, 3, 4, 24),
82                         dcp::Time (5, 6, 7, 8, 24)
83                         )
84                 );
85
86         c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
87
88         check_xml (
89                 c.xml_as_string (),
90                 "<DCSubtitle Version=\"1.0\">\n"
91                 "  <SubtitleID>a6c58cff-3e1e-4b38-acec-a42224475ef6</SubtitleID>\n"
92                 "  <MovieTitle>Test</MovieTitle>\n"
93                 "  <ReelNumber>1</ReelNumber>\n"
94                 "  <Language>EN</Language>\n"
95                 "  <Font Id=\"Frutiger\" Italic=\"no\" Color=\"FFFFFFFF\" Size=\"48\" Effect=\"none\" EffectColor=\"FF000000\" Script=\"normal\" Underlined=\"no\" Weight=\"normal\">\n"
96                 "    <Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:229\" TimeOut=\"00:04:11:229\" FadeUpTime=\"0\" FadeDownTime=\"0\">\n"
97                 "      <Text VAlign=\"top\" VPosition=\"80\">Hello world</Text>\n"
98                 "    </Subtitle>\n"
99                 "  </Font>\n"
100                 "  <Font Italic=\"yes\" Color=\"FF800040\" Size=\"91\" Effect=\"border\" EffectColor=\"FF010203\" Script=\"normal\" Underlined=\"yes\" Weight=\"bold\">\n"
101                 "    <Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:218\" TimeOut=\"06:12:15:218\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">\n"
102                 "      <Text VAlign=\"bottom\" VPosition=\"40\">What's going on</Text>\n"
103                 "    </Subtitle>\n"
104                 "  </Font>\n"
105                 "</DCSubtitle>",
106                 list<string> ()
107                 );
108 }
109
110 /* Write some subtitle content as SMPTE XML and check that it is right */
111 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test)
112 {
113         dcp::SMPTESubtitleAsset c;
114         c.set_reel_number (1);
115         c.set_language ("EN");
116         c.set_content_title_text ("Test");
117         c.set_issue_date (dcp::LocalTime ("2016-04-01T03:52:00+00:00"));
118
119         c.add (
120                 dcp::SubtitleString (
121                         string ("Frutiger"),
122                         false,
123                         false,
124                         false,
125                         dcp::Colour (255, 255, 255),
126                         48,
127                         1.0,
128                         dcp::Time (0, 4,  9, 22, 24),
129                         dcp::Time (0, 4, 11, 22, 24),
130                         0,
131                         dcp::HALIGN_CENTER,
132                         0.8,
133                         dcp::VALIGN_TOP,
134                         dcp::DIRECTION_LTR,
135                         "Hello world",
136                         dcp::NONE,
137                         dcp::Colour (0, 0, 0),
138                         dcp::Time (0, 0, 0, 0, 24),
139                         dcp::Time (0, 0, 0, 0, 24)
140                         )
141                 );
142
143         c.add (
144                 dcp::SubtitleString (
145                         boost::optional<string> (),
146                         true,
147                         true,
148                         true,
149                         dcp::Colour (128, 0, 64),
150                         91,
151                         1.0,
152                         dcp::Time (5, 41,  0, 21, 24),
153                         dcp::Time (6, 12, 15, 21, 24),
154                         0,
155                         dcp::HALIGN_CENTER,
156                         0.4,
157                         dcp::VALIGN_BOTTOM,
158                         dcp::DIRECTION_RTL,
159                         "What's going on",
160                         dcp::BORDER,
161                         dcp::Colour (1, 2, 3),
162                         dcp::Time (1, 2, 3, 4, 24),
163                         dcp::Time (5, 6, 7, 8, 24)
164                         )
165                 );
166
167         c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
168
169         check_xml (
170                 c.xml_as_string (),
171                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
172                 "<dcst:SubtitleReel xmlns:dcst=\"http://www.smpte-ra.org/schemas/428-7/2010/DCST\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
173                 "  <dcst:Id>urn:uuid:a6c58cff-3e1e-4b38-acec-a42224475ef6</dcst:Id>\n"
174                 "  <dcst:ContentTitleText>Test</dcst:ContentTitleText>\n"
175                 "  <dcst:IssueDate>2016-04-01T03:52:00.000+00:00</dcst:IssueDate>\n"
176                 "  <dcst:ReelNumber>1</dcst:ReelNumber>\n"
177                 "  <dcst:Language>EN</dcst:Language>\n"
178                 "  <dcst:EditRate>24 1</dcst:EditRate>\n"
179                 "  <dcst:TimeCodeRate>24</dcst:TimeCodeRate>\n"
180                 "  <dcst:SubtitleList>\n"
181                 "    <dcst:Font ID=\"Frutiger\" Italic=\"no\" Color=\"FFFFFFFF\" Size=\"48\" Effect=\"none\" EffectColor=\"FF000000\" Script=\"normal\" Underline=\"no\" Weight=\"normal\">\n"
182                 "      <dcst:Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:22\" TimeOut=\"00:04:11:22\" FadeUpTime=\"00:00:00:00\" FadeDownTime=\"00:00:00:00\">\n"
183                 "        <dcst:Text Valign=\"top\" Vposition=\"80\">Hello world</dcst:Text>\n"
184                 "      </dcst:Subtitle>\n"
185                 "    </dcst:Font>\n"
186                 "    <dcst:Font Italic=\"yes\" Color=\"FF800040\" Size=\"91\" Effect=\"border\" EffectColor=\"FF010203\" Script=\"normal\" Underline=\"yes\" Weight=\"bold\">\n"
187                 "      <dcst:Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:21\" TimeOut=\"06:12:15:21\" FadeUpTime=\"01:02:03:04\" FadeDownTime=\"05:06:07:08\">\n"
188                 "        <dcst:Text Valign=\"bottom\" Vposition=\"40\" Direction=\"rtl\">What's going on</dcst:Text>\n"
189                 "      </dcst:Subtitle>\n"
190                 "    </dcst:Font>\n"
191                 "  </dcst:SubtitleList>\n"
192                 "</dcst:SubtitleReel>\n",
193                 list<string> ()
194                 );
195 }