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