Rudimentary SSA parser.
[libsub.git] / test / ssa_reader_test.cc
1 /*
2     Copyright (C) 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 "test.h"
21 #include "ssa_reader.h"
22 #include "collect.h"
23 #include "subtitle.h"
24 #include <boost/test/unit_test.hpp>
25 #include <boost/filesystem.hpp>
26 #include <cstdio>
27
28 using std::list;
29
30 BOOST_AUTO_TEST_CASE (ssa_reader_test)
31 {
32         boost::filesystem::path p = private_test / "example.ssa";
33         FILE* f = fopen (p.string().c_str(), "r");
34         sub::SSAReader reader (f);
35         fclose (f);
36         list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
37
38         list<sub::Subtitle>::iterator i = subs.begin ();
39
40         BOOST_REQUIRE (i != subs.end ());
41         BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 2, 40, 650));
42         BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 2, 41, 790));
43         list<sub::Line>::iterator j = i->lines.begin();
44         BOOST_REQUIRE (j != i->lines.end ());
45         BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
46         sub::Block b = j->blocks.front ();
47         BOOST_CHECK_EQUAL (b.text, "Et les enregistrements de ses ondes delta ?");
48         BOOST_CHECK_EQUAL (b.font.get(), "Wolf_Rain");
49         BOOST_CHECK_EQUAL (b.font_size.points().get(), 56);
50         BOOST_CHECK_EQUAL (b.bold, false);
51         BOOST_CHECK_EQUAL (b.italic, false);
52         BOOST_CHECK_EQUAL (b.underline, false);
53         ++i;
54
55         BOOST_REQUIRE (i != subs.end ());
56         BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 2, 42, 420));
57         BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 2, 44, 150));
58         j = i->lines.begin();
59         BOOST_REQUIRE (j != i->lines.end ());
60         BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
61         b = j->blocks.front ();
62         BOOST_CHECK_EQUAL (b.text, "Toujours rien.");
63         BOOST_CHECK_EQUAL (b.font.get(), "Wolf_Rain");
64         BOOST_CHECK_EQUAL (b.font_size.points().get(), 56);
65         BOOST_CHECK_EQUAL (b.bold, false);
66         BOOST_CHECK_EQUAL (b.italic, false);
67         BOOST_CHECK_EQUAL (b.underline, false);
68         ++i;
69
70         BOOST_CHECK (i == subs.end());
71 }