c29ff7c98dbda1565ec6421a3124bbb3e8a37872
[libsub.git] / test / ssa_reader_test.cc
1 /*
2     Copyright (C) 2016-2021 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 "test.h"
21 #include "ssa_reader.h"
22 #include "collect.h"
23 #include "subtitle.h"
24 #include "exceptions.h"
25 #include <boost/test/unit_test.hpp>
26 #include <boost/filesystem.hpp>
27 #include <boost/foreach.hpp>
28 #include <cstdio>
29 #include <cmath>
30 #include <iostream>
31
32 using std::fabs;
33 using std::vector;
34
35 BOOST_AUTO_TEST_CASE (ssa_reader_test)
36 {
37         boost::filesystem::path p = private_test / "example.ssa";
38         FILE* f = fopen (p.string().c_str(), "r");
39         sub::SSAReader reader (f);
40         fclose (f);
41         auto subs = sub::collect<vector<sub::Subtitle>> (reader.subtitles());
42
43         auto i = subs.begin ();
44
45         BOOST_REQUIRE (i != subs.end ());
46         BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 2, 40, 650));
47         BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 2, 41, 790));
48         auto j = i->lines.begin();
49         BOOST_REQUIRE (j != i->lines.end ());
50         BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
51         sub::Block b = j->blocks.front ();
52         BOOST_CHECK_EQUAL (b.text, "Et les enregistrements de ses ondes delta ?");
53         BOOST_CHECK_EQUAL (b.font.get(), "Wolf_Rain");
54         BOOST_CHECK_EQUAL (b.font_size.points().get(), 56);
55         BOOST_CHECK_EQUAL (b.bold, false);
56         BOOST_CHECK_EQUAL (b.italic, false);
57         BOOST_CHECK_EQUAL (b.underline, false);
58         ++i;
59
60         BOOST_REQUIRE (i != subs.end ());
61         BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 2, 42, 420));
62         BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 2, 44, 150));
63         j = i->lines.begin();
64         BOOST_REQUIRE (j != i->lines.end ());
65         BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
66         b = j->blocks.front ();
67         BOOST_CHECK_EQUAL (b.text, "Toujours rien.");
68         BOOST_CHECK_EQUAL (b.font.get(), "Wolf_Rain");
69         BOOST_CHECK_EQUAL (b.font_size.points().get(), 56);
70         BOOST_CHECK_EQUAL (b.bold, false);
71         BOOST_CHECK_EQUAL (b.italic, false);
72         BOOST_CHECK_EQUAL (b.underline, false);
73         ++i;
74
75         BOOST_CHECK (i == subs.end());
76 }
77
78 BOOST_AUTO_TEST_CASE (ssa_reader_line_test1)
79 {
80         sub::RawSubtitle base;
81         auto r = sub::SSAReader::parse_line (
82                 base,
83                 "This is a line with some {\\i1}italics{\\i0} and then\\nthere is a new line.",
84                 1920, 1080
85                 );
86
87         auto i = r.begin();
88         BOOST_CHECK_EQUAL (i->text, "This is a line with some ");
89         BOOST_CHECK_EQUAL (i->italic, false);
90         ++i;
91         BOOST_REQUIRE (i != r.end ());
92
93         BOOST_CHECK_EQUAL (i->text, "italics");
94         BOOST_CHECK_EQUAL (i->italic, true);
95         ++i;
96         BOOST_REQUIRE (i != r.end ());
97
98         BOOST_CHECK_EQUAL (i->text, " and then");
99         BOOST_CHECK_EQUAL (i->italic, false);
100         ++i;
101         BOOST_REQUIRE (i != r.end ());
102
103         BOOST_CHECK_EQUAL (i->text, "there is a new line.");
104         ++i;
105         BOOST_REQUIRE (i == r.end ());
106 }
107
108 BOOST_AUTO_TEST_CASE (ssa_reader_line_test2)
109 {
110         sub::RawSubtitle base;
111         auto r = sub::SSAReader::parse_line (
112                 base,
113                 "{\\i1}It's all just italics{\\i0}",
114                 1920, 1080
115                 );
116
117         auto i = r.begin ();
118         BOOST_CHECK_EQUAL (i->text, "It's all just italics");
119         BOOST_CHECK_EQUAL (i->italic, true);
120         ++i;
121         BOOST_REQUIRE (i == r.end ());
122
123         r = sub::SSAReader::parse_line (
124                 base,
125                 "{\\i1}Italic{\\i0}\\Nand new line",
126                 1920, 1080
127                 );
128
129         i = r.begin ();
130         BOOST_CHECK_EQUAL (i->text, "Italic");
131         BOOST_CHECK_EQUAL (i->italic, true);
132         BOOST_CHECK (fabs ((72.0 * 1.2 / 792) - i->vertical_position.proportional.get()) < 1e-5);
133         ++i;
134         BOOST_CHECK_EQUAL (i->text, "and new line");
135         BOOST_CHECK_EQUAL (i->italic, false);
136         BOOST_CHECK (i->vertical_position.proportional.get() < 1e-5);
137 }
138
139 static void
140 test (boost::filesystem::path p)
141 {
142         p = private_test / p;
143         FILE* f = fopen (p.string().c_str(), "r");
144         BOOST_REQUIRE (f);
145         sub::SSAReader r (f);
146         fclose (f);
147 }
148
149 /** Test of reading some typical .ssa files */
150 BOOST_AUTO_TEST_CASE (ssa_reader_test2)
151 {
152         test ("DKH_UT_EN20160601def.ssa");
153         test ("dcpsubtest-en.ssa");
154         test ("dcpsubtest-en.ssa");
155         test ("W_GERMAN_SUBS_grey.ass");
156 }
157
158 #define SUB_START(f, t) \
159         BOOST_REQUIRE (i != subs.end ()); \
160         BOOST_CHECK_EQUAL (i->from, f); \
161         BOOST_CHECK_EQUAL (i->to, t); \
162         j = i->lines.begin ();
163
164 #define LINE(vp, vr, hp, hr)                  \
165         BOOST_REQUIRE (j != i->lines.end ()); \
166         BOOST_CHECK (j->vertical_position.proportional); \
167         BOOST_CHECK (fabs (j->vertical_position.proportional.get() - vp) < 1e-5); \
168         BOOST_CHECK (j->vertical_position.reference); \
169         BOOST_CHECK_EQUAL (j->vertical_position.reference.get(), vr); \
170         BOOST_CHECK (fabs (j->horizontal_position.proportional - hp) < 1e-5); \
171         BOOST_CHECK_EQUAL (j->horizontal_position.reference, hr); \
172         k = j->blocks.begin (); \
173         ++j;
174
175 #define BLOCK(t, f, s, b, i, u) \
176         BOOST_REQUIRE (k != j->blocks.end ()); \
177         BOOST_CHECK_EQUAL (k->text, t); \
178         BOOST_CHECK_EQUAL (k->font.get(), f); \
179         BOOST_CHECK_EQUAL (k->font_size.points().get(), s); \
180         BOOST_CHECK_EQUAL (k->bold, b); \
181         BOOST_CHECK_EQUAL (k->italic, i); \
182         BOOST_CHECK_EQUAL (k->underline, u); \
183         ++k;
184
185 #define SUB_END() \
186         ++i;
187
188 /** Test reading of a file within the libsub tree which exercises the parser */
189 BOOST_AUTO_TEST_CASE (ssa_reader_test3)
190 {
191         boost::filesystem::path p = "test/data/test.ssa";
192         FILE* f = fopen (p.string().c_str(), "r");
193         sub::SSAReader reader (f);
194         fclose (f);
195         auto subs = sub::collect<vector<sub::Subtitle>> (reader.subtitles());
196
197         auto i = subs.begin();
198         vector<sub::Line>::iterator j;
199         vector<sub::Block>::iterator k;
200
201         /* Hello world */
202         SUB_START (sub::Time::from_hms (0, 0, 1, 230), sub::Time::from_hms (0, 0, 4, 550));
203         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
204         BLOCK ("Hello world", "Arial", 20, false, false, false);
205         SUB_END();
206
207         /* This is vertically moved\nand has two lines. */
208         SUB_START (sub::Time::from_hms (0, 0, 5, 740), sub::Time::from_hms (0, 0, 11, 0));
209         /* The first line should be 900 pixels and one line (20
210            points, 1.2 times spaced, as a proportion of the total
211            screen height 729 points) up.
212         */
213         LINE((900.0 / 1080) - (20.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
214         BLOCK("This is vertically moved", "Arial", 20, false, false, false);
215         LINE((900.0 / 1080), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
216         BLOCK("and has two lines.", "Arial", 20, false, false, false);
217         SUB_END();
218
219         /* Some {\i1}italics{\i} are here. */
220         SUB_START (sub::Time::from_hms (0, 0, 7, 740), sub::Time::from_hms (0, 0, 9, 0));
221         LINE(0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
222         BLOCK("Some ", "Arial", 20, false, false, false);
223         BLOCK("italics", "Arial", 20, false, true, false);
224         BLOCK(" are here.", "Arial", 20, false, false, false);
225         SUB_END();
226
227         /* Alignments */
228
229         SUB_START (sub::Time::from_hms (0, 0, 9, 230), sub::Time::from_hms (0, 0, 11, 560));
230         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::LEFT_OF_SCREEN);
231         BLOCK("bottom left", "Arial", 20, false, false, false);
232         SUB_END ();
233
234         SUB_START (sub::Time::from_hms (0, 0, 9, 240), sub::Time::from_hms (0, 0, 11, 560));
235         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
236         BLOCK("bottom centre", "Arial", 20, false, false, false);
237         SUB_END ();
238
239         SUB_START (sub::Time::from_hms (0, 0, 9, 250), sub::Time::from_hms (0, 0, 11, 560));
240         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::RIGHT_OF_SCREEN);
241         BLOCK("bottom right", "Arial", 20, false, false, false);
242         SUB_END ();
243
244         SUB_START (sub::Time::from_hms (0, 0, 9, 260), sub::Time::from_hms (0, 0, 11, 560));
245         LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::LEFT_OF_SCREEN);
246         BLOCK("middle left", "Arial", 20, false, false, false);
247         SUB_END ();
248
249         SUB_START (sub::Time::from_hms (0, 0, 9, 270), sub::Time::from_hms (0, 0, 11, 560));
250         LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
251         BLOCK("middle centre", "Arial", 20, false, false, false);
252         SUB_END ();
253
254         SUB_START (sub::Time::from_hms (0, 0, 9, 280), sub::Time::from_hms (0, 0, 11, 560));
255         LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::RIGHT_OF_SCREEN);
256         BLOCK("middle right", "Arial", 20, false, false, false);
257         SUB_END ();
258
259         SUB_START (sub::Time::from_hms (0, 0, 9, 290), sub::Time::from_hms (0, 0, 11, 560));
260         LINE (0, sub::TOP_OF_SCREEN, 0, sub::LEFT_OF_SCREEN);
261         BLOCK("top left", "Arial", 20, false, false, false);
262         SUB_END ();
263
264         SUB_START (sub::Time::from_hms (0, 0, 9, 300), sub::Time::from_hms (0, 0, 11, 560));
265         LINE (0, sub::TOP_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
266         BLOCK("top centre", "Arial", 20, false, false, false);
267         SUB_END ();
268
269         SUB_START (sub::Time::from_hms (0, 0, 9, 310), sub::Time::from_hms (0, 0, 11, 560));
270         LINE (0, sub::TOP_OF_SCREEN, 0, sub::RIGHT_OF_SCREEN);
271         BLOCK("top right", "Arial", 20, false, false, false);
272         SUB_END ();
273
274         BOOST_REQUIRE (i == subs.end ());
275 }
276
277 /** Test reading of a file within the libsub-test-private tree which exercises the parser */
278 BOOST_AUTO_TEST_CASE (ssa_reader_test4)
279 {
280         boost::filesystem::path p = private_test / "dcpsubtest2-en.ssa";
281         FILE* f = fopen (p.string().c_str(), "r");
282         sub::SSAReader reader (f);
283         fclose (f);
284         auto subs = sub::collect<vector<sub::Subtitle>> (reader.subtitles());
285
286         auto i = subs.begin();
287         vector<sub::Line>::iterator j;
288         vector<sub::Block>::iterator k;
289
290         BOOST_REQUIRE (i != subs.end ());
291
292         SUB_START (sub::Time::from_hms (0, 0, 1, 0), sub::Time::from_hms (0, 0, 3, 0));
293         /* The first line should be one line (50 points, 1.2 times
294            spaced, as a proportion of the total screen height 729
295            points) up.
296         */
297         LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
298         BLOCK ("1st line: This is normal", "Verdana", 50, false, false, false);
299         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
300         BLOCK ("2d line: this is bold", "Verdana", 50, true, false, false);
301         SUB_END ();
302
303         SUB_START (sub::Time::from_hms (0, 0, 3, 100), sub::Time::from_hms (0, 0, 5, 100));
304         LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
305         BLOCK ("1st line: this is bold", "Verdana", 50, true, false, false);
306         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
307         BLOCK ("2nd line: This is normal", "Verdana", 50, false, false, false);
308         SUB_END ();
309
310         SUB_START (sub::Time::from_hms (0, 0, 5, 200), sub::Time::from_hms (0, 0, 7, 200));
311         LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
312         BLOCK ("1st line: this is bold", "Verdana", 50, true, false, false);
313         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
314         BLOCK ("2nd line: this is italics", "Verdana", 50, false, true, false);
315         SUB_END ();
316
317         SUB_START (sub::Time::from_hms (0, 0, 7, 300), sub::Time::from_hms (0, 0, 9, 300));
318         LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
319         BLOCK ("1st line: this is italics", "Verdana", 50, false, true, false);
320         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
321         BLOCK ("2nd line: this is bold", "Verdana", 50, true, false, false);
322         SUB_END ();
323 }
324
325 /** Test reading of a .ass file */
326 BOOST_AUTO_TEST_CASE (ssa_reader_test5)
327 {
328         boost::filesystem::path p = private_test / "dcpsubtest-en.ass";
329         FILE* f = fopen (p.string().c_str(), "r");
330         sub::SSAReader reader (f);
331         fclose (f);
332         auto subs = sub::collect<vector<sub::Subtitle>> (reader.subtitles());
333
334         auto i = subs.begin ();
335         vector<sub::Line>::iterator j;
336         vector<sub::Block>::iterator k;
337
338         BOOST_REQUIRE (i != subs.end ());
339
340         SUB_START (sub::Time::from_hms (0, 0, 1, 0), sub::Time::from_hms (0, 0, 3, 0));
341         /* The first line should be one line (26 points, 1.2 times
342            spaced, as a proportion of the total screen height 729
343            points) up.
344         */
345         LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
346         BLOCK ("1st subtitle, 1st line", "arial", 26, true, false, false);
347         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
348         BLOCK ("2nd subtitle, 2nd line", "arial", 26, true, false, false);
349         SUB_END ();
350
351         SUB_START (sub::Time::from_hms (0, 0, 3, 100), sub::Time::from_hms (0, 0, 5, 100));
352         LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
353         BLOCK ("2nd subtitle, 1st line", "arial", 26, true, false, false);
354         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
355         BLOCK ("2nd subtitle, 2nd line", "arial", 26, true, false, false);
356         SUB_END ();
357
358         SUB_START (sub::Time::from_hms (0, 0, 5, 200), sub::Time::from_hms (0, 0, 7, 200));
359         LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
360         BLOCK ("3rd subtitle, 1st line", "arial", 26, true, false, false);
361         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
362         BLOCK ("3rd subtitle, 2nd line", "arial", 26, true, false, false);
363         SUB_END ();
364
365         SUB_START (sub::Time::from_hms (0, 0, 7, 300), sub::Time::from_hms (0, 0, 9, 300));
366         LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
367         BLOCK ("4th subtitle, 1st line", "arial", 26, true, false, false);
368         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
369         BLOCK ("4th subtitle, 2nd line", "arial", 26, true, false, false);
370         SUB_END ();
371 }
372
373 /** Test reading of another .ass file */
374 BOOST_AUTO_TEST_CASE (ssa_reader_test6)
375 {
376         boost::filesystem::path p = private_test / "DCP-o-matic_test_subs_1.ass";
377         FILE* f = fopen (p.string().c_str(), "r");
378         BOOST_REQUIRE (f);
379         sub::SSAReader reader (f);
380         fclose (f);
381         auto subs = sub::collect<vector<sub::Subtitle>> (reader.subtitles());
382
383         auto i = subs.begin ();
384         vector<sub::Line>::iterator j;
385         vector<sub::Block>::iterator k;
386
387         BOOST_REQUIRE (i != subs.end ());
388
389         SUB_START (sub::Time::from_hms (0, 0, 0, 70), sub::Time::from_hms (0, 0, 1, 110));
390         /* The first line should be one line (30 points, 1.2 times
391            spaced, as a proportion of the total screen height 729
392            points) up.
393         */
394         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
395         BLOCK ("This line is normal", "Arial", 30, false, false, false);
396         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
397         BLOCK ("This line is bold", "Arial", 30, true, false, false);
398         SUB_END ();
399
400         SUB_START (sub::Time::from_hms (0, 0, 1, 200), sub::Time::from_hms (0, 0, 2, 240));
401         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
402         BLOCK ("This line is bold", "Arial", 30, true, false, false);
403         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
404         BLOCK ("This line is normal", "Arial", 30, false, false, false);
405         SUB_END ();
406
407         SUB_START (sub::Time::from_hms (0, 0, 2, 300), sub::Time::from_hms (0, 0, 3, 380));
408         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
409         BLOCK ("This line is bold", "Arial", 30, true, false, false);
410         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
411         BLOCK ("This line is italic", "Arial", 30, false, true, false);
412         SUB_END ();
413
414         SUB_START (sub::Time::from_hms (0, 0, 3, 400), sub::Time::from_hms (0, 0, 4, 480));
415         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
416         BLOCK ("This line is italic", "Arial", 30, false, true, false);
417         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
418         BLOCK ("This line is bold", "Arial", 30, true, false, false);
419         SUB_END ();
420
421         SUB_START (sub::Time::from_hms (0, 0, 4, 510), sub::Time::from_hms (0, 0, 5, 600));
422         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
423         BLOCK ("Last three words are ", "Arial", 30, false, false, false);
424         BLOCK ("bold AND italic", "Arial", 30, true, true, false);
425         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
426         BLOCK ("Last three words are ", "Arial", 30, false, false, false);
427         BLOCK ("italic AND bold", "Arial", 30, true, true, false);
428         SUB_END ();
429
430         SUB_START (sub::Time::from_hms (0, 0, 5, 620), sub::Time::from_hms (0, 0, 6, 710));
431         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
432         BLOCK ("Last three words are ", "Arial", 30, false, false, false);
433         BLOCK ("bold AND italic", "Arial", 30, true, true, false);
434         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
435         BLOCK ("First three words", "Arial", 30, true, true, false);
436         BLOCK (" are italic AND bold", "Arial", 30, false, false, false);
437         SUB_END ();
438
439         SUB_START (sub::Time::from_hms (0, 0, 6, 730), sub::Time::from_hms (0, 0, 8, 30));
440         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
441         BLOCK ("Last three words are ", "Arial", 30, false, false, false);
442         BLOCK ("bold AND italic", "Arial", 30, true, true, false);
443         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
444         BLOCK ("This line is normal", "Arial", 30, false, false, false);
445         SUB_END ();
446
447         SUB_START (sub::Time::from_hms (0, 0, 8, 90), sub::Time::from_hms (0, 0, 9, 210));
448         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
449         BLOCK ("Both lines are bold AND italic", "Arial", 30, true, true, false);
450         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
451         BLOCK ("Both lines are bold AND italic", "Arial", 30, true, true, false);
452         SUB_END ();
453 }
454
455 /** Test \pos */
456 BOOST_AUTO_TEST_CASE (ssa_reader_pos)
457 {
458         boost::filesystem::path p = "test/data/test2.ssa";
459         FILE* f = fopen (p.string().c_str(), "r");
460         sub::SSAReader reader (f);
461         fclose (f);
462         auto subs = sub::collect<vector<sub::Subtitle>> (reader.subtitles());
463
464         auto i = subs.begin ();
465         vector<sub::Line>::iterator j;
466         vector<sub::Block>::iterator k;
467
468         /* Hello world */
469         SUB_START (sub::Time::from_hms (0, 0, 1, 230), sub::Time::from_hms (0, 0, 4, 550));
470         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
471         BLOCK ("Hello world this is ", "Arial", 20, false, false, false);
472         LINE (300.0 / 1080, sub::TOP_OF_SCREEN, 400.0 / 1920, sub::LEFT_OF_SCREEN);
473         BLOCK ("positioning.", "Arial", 20, false, false, false);
474         SUB_END();
475 }
476
477 /** Test \fs */
478 BOOST_AUTO_TEST_CASE (ssa_reader_fs)
479 {
480         sub::RawSubtitle base;
481         auto r = sub::SSAReader::parse_line (
482                 base,
483                 "This is a line with some {\\fs64}font sizing.",
484                 1920, 1080
485                 );
486
487         auto i = r.begin ();
488         BOOST_CHECK_EQUAL (i->text, "This is a line with some ");
489         ++i;
490         BOOST_REQUIRE (i != r.end ());
491
492         BOOST_CHECK_EQUAL (i->text, "font sizing.");
493         BOOST_CHECK (i->font_size.points());
494         BOOST_CHECK_EQUAL (i->font_size.points().get(), 64);
495         ++i;
496         BOOST_REQUIRE (i == r.end ());
497 }
498
499 /** Test a valid \c */
500 BOOST_AUTO_TEST_CASE (ssa_reader_c)
501 {
502         sub::RawSubtitle base;
503         auto r = sub::SSAReader::parse_line (
504                 base,
505                 "{\\c&H00FFFF&}Dieser Untertitel ist gelb",
506                 1920, 1080
507                 );
508
509         auto i = r.begin ();
510         BOOST_CHECK_EQUAL (i->text, "Dieser Untertitel ist gelb");
511         BOOST_CHECK (i->colour == sub::Colour::from_rgb_hex("ffff00"));
512         ++i;
513         BOOST_REQUIRE (i == r.end ());
514 }
515
516 /** Test invalid \c */
517 BOOST_AUTO_TEST_CASE (ssa_reader_c_bad)
518 {
519         sub::RawSubtitle base;
520         BOOST_CHECK_THROW(
521                 sub::SSAReader::parse_line(
522                         base,
523                         "{\\c&H0}Dieser Untertitel ist gelb",
524                         1920, 1080
525                         ),
526                 sub::SSAError
527                 );
528 }