2 Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net>
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.
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.
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.
21 #include "ssa_reader.h"
24 #include "exceptions.h"
25 #include <boost/test/unit_test.hpp>
26 #include <boost/filesystem.hpp>
27 #include <boost/foreach.hpp>
35 BOOST_AUTO_TEST_CASE (ssa_reader_test)
37 boost::filesystem::path p = private_test / "example.ssa";
38 FILE* f = fopen (p.string().c_str(), "r");
39 sub::SSAReader reader (f);
41 list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
43 list<sub::Subtitle>::iterator i = subs.begin ();
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 list<sub::Line>::iterator 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);
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));
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);
75 BOOST_CHECK (i == subs.end());
78 BOOST_AUTO_TEST_CASE (ssa_reader_line_test1)
80 sub::RawSubtitle base;
81 list<sub::RawSubtitle> r = sub::SSAReader::parse_line (
83 "This is a line with some {\\i1}italics{\\i0} and then\\nthere is a new line.",
87 list<sub::RawSubtitle>::const_iterator i = r.begin ();
88 BOOST_CHECK_EQUAL (i->text, "This is a line with some ");
89 BOOST_CHECK_EQUAL (i->italic, false);
91 BOOST_REQUIRE (i != r.end ());
93 BOOST_CHECK_EQUAL (i->text, "italics");
94 BOOST_CHECK_EQUAL (i->italic, true);
96 BOOST_REQUIRE (i != r.end ());
98 BOOST_CHECK_EQUAL (i->text, " and then");
99 BOOST_CHECK_EQUAL (i->italic, false);
101 BOOST_REQUIRE (i != r.end ());
103 BOOST_CHECK_EQUAL (i->text, "there is a new line.");
105 BOOST_REQUIRE (i == r.end ());
108 BOOST_AUTO_TEST_CASE (ssa_reader_line_test2)
110 sub::RawSubtitle base;
111 list<sub::RawSubtitle> r = sub::SSAReader::parse_line (
113 "{\\i1}It's all just italics{\\i0}",
117 list<sub::RawSubtitle>::const_iterator i = r.begin ();
118 BOOST_CHECK_EQUAL (i->text, "It's all just italics");
119 BOOST_CHECK_EQUAL (i->italic, true);
121 BOOST_REQUIRE (i == r.end ());
123 r = sub::SSAReader::parse_line (
125 "{\\i1}Italic{\\i0}\\Nand new line",
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);
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);
140 test (boost::filesystem::path p)
142 p = private_test / p;
143 FILE* f = fopen (p.string().c_str(), "r");
145 sub::SSAReader r (f);
149 /** Test of reading some typical .ssa files */
150 BOOST_AUTO_TEST_CASE (ssa_reader_test2)
152 test ("DKH_UT_EN20160601def.ssa");
153 test ("dcpsubtest-en.ssa");
154 test ("dcpsubtest-en.ssa");
155 test ("W_GERMAN_SUBS_grey.ass");
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 ();
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 (); \
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); \
188 /** Test reading of a file within the libsub tree which exercises the parser */
189 BOOST_AUTO_TEST_CASE (ssa_reader_test3)
191 boost::filesystem::path p = "test/data/test.ssa";
192 FILE* f = fopen (p.string().c_str(), "r");
193 sub::SSAReader reader (f);
195 list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
197 list<sub::Subtitle>::iterator i = subs.begin ();
198 list<sub::Line>::iterator j;
199 list<sub::Block>::iterator k;
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);
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.
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
274 BOOST_REQUIRE (i == subs.end ());
277 /** Test reading of a file within the libsub-test-private tree which exercises the parser */
278 BOOST_AUTO_TEST_CASE (ssa_reader_test4)
280 boost::filesystem::path p = private_test / "dcpsubtest2-en.ssa";
281 FILE* f = fopen (p.string().c_str(), "r");
282 sub::SSAReader reader (f);
284 list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
286 list<sub::Subtitle>::iterator i = subs.begin ();
287 list<sub::Line>::iterator j;
288 list<sub::Block>::iterator k;
290 BOOST_REQUIRE (i != subs.end ());
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
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);
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);
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);
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);
325 /** Test reading of a .ass file */
326 BOOST_AUTO_TEST_CASE (ssa_reader_test5)
328 boost::filesystem::path p = private_test / "dcpsubtest-en.ass";
329 FILE* f = fopen (p.string().c_str(), "r");
330 sub::SSAReader reader (f);
332 list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
334 list<sub::Subtitle>::iterator i = subs.begin ();
335 list<sub::Line>::iterator j;
336 list<sub::Block>::iterator k;
338 BOOST_REQUIRE (i != subs.end ());
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
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);
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);
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);
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);
373 /** Test reading of another .ass file */
374 BOOST_AUTO_TEST_CASE (ssa_reader_test6)
376 boost::filesystem::path p = private_test / "DCP-o-matic_test_subs_1.ass";
377 FILE* f = fopen (p.string().c_str(), "r");
379 sub::SSAReader reader (f);
381 list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
383 list<sub::Subtitle>::iterator i = subs.begin ();
384 list<sub::Line>::iterator j;
385 list<sub::Block>::iterator k;
387 BOOST_REQUIRE (i != subs.end ());
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
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);
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);
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);
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);
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);
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);
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);
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);
456 BOOST_AUTO_TEST_CASE (ssa_reader_pos)
458 boost::filesystem::path p = "test/data/test2.ssa";
459 FILE* f = fopen (p.string().c_str(), "r");
460 sub::SSAReader reader (f);
462 list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
464 list<sub::Subtitle>::iterator i = subs.begin ();
465 list<sub::Line>::iterator j;
466 list<sub::Block>::iterator k;
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);
478 BOOST_AUTO_TEST_CASE (ssa_reader_fs)
480 sub::RawSubtitle base;
481 list<sub::RawSubtitle> r = sub::SSAReader::parse_line (
483 "This is a line with some {\\fs64}font sizing.",
487 list<sub::RawSubtitle>::const_iterator i = r.begin ();
488 BOOST_CHECK_EQUAL (i->text, "This is a line with some ");
490 BOOST_REQUIRE (i != r.end ());
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);
496 BOOST_REQUIRE (i == r.end ());
499 /** Test a valid \c */
500 BOOST_AUTO_TEST_CASE (ssa_reader_c)
502 sub::RawSubtitle base;
503 list<sub::RawSubtitle> r = sub::SSAReader::parse_line (
505 "{\\c&H00FFFF&}Dieser Untertitel ist gelb",
509 list<sub::RawSubtitle>::const_iterator i = r.begin ();
510 BOOST_CHECK_EQUAL (i->text, "Dieser Untertitel ist gelb");
511 BOOST_CHECK (i->colour == sub::Colour::from_rgb_hex("ffff00"));
513 BOOST_REQUIRE (i == r.end ());
516 /** Test invalid \c */
517 BOOST_AUTO_TEST_CASE (ssa_reader_c_bad)
519 sub::RawSubtitle base;
521 sub::SSAReader::parse_line(
523 "{\\c&H0}Dieser Untertitel ist gelb",