Various developments.
[libsub.git] / test / stl_reader_test.cc
1 /*
2     Copyright (C) 2014 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 <boost/test/unit_test.hpp>
21 #include <fstream>
22 #include "stl_reader.h"
23 #include "subtitle.h"
24
25 using std::list;
26 using std::ifstream;
27
28 /* Test reading of an STL file */
29 BOOST_AUTO_TEST_CASE (stl_reader_test)
30 {
31         ifstream file ("test/data/test.stl");
32         sub::STLReader reader (file);
33         list<sub::Subtitle> subs = reader.subtitles ();
34
35         list<sub::Subtitle>::iterator i = subs.begin ();
36
37         BOOST_CHECK (i != subs.end ());
38         BOOST_CHECK_EQUAL (i->text, " This is a subtitle ");
39         BOOST_CHECK_EQUAL (i->font, "Arial");
40         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
41         BOOST_CHECK_EQUAL (i->bold, false);
42         BOOST_CHECK_EQUAL (i->italic, false);
43         BOOST_CHECK_EQUAL (i->underline, false);
44         BOOST_CHECK_EQUAL (i->line, 0);
45         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 0, 41, 9));
46         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 0, 42, 21));
47         ++i;
48
49         BOOST_CHECK (i != subs.end ());
50         BOOST_CHECK_EQUAL (i->text, " and that's a line break");
51         BOOST_CHECK_EQUAL (i->font, "Arial");
52         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
53         BOOST_CHECK_EQUAL (i->bold, false);
54         BOOST_CHECK_EQUAL (i->italic, false);
55         BOOST_CHECK_EQUAL (i->underline, false);
56         BOOST_CHECK_EQUAL (i->line, 1);
57         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 0, 41, 9));
58         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 0, 42, 21));
59         ++i;
60
61         BOOST_CHECK (i != subs.end ());
62         BOOST_CHECK_EQUAL (i->text, " This is some ");
63         BOOST_CHECK_EQUAL (i->font, "Arial");
64         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
65         BOOST_CHECK_EQUAL (i->bold, false);
66         BOOST_CHECK_EQUAL (i->italic, false);
67         BOOST_CHECK_EQUAL (i->underline, false);
68         BOOST_CHECK_EQUAL (i->line, 0);
69         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1));
70         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10));
71         ++i;
72
73         BOOST_CHECK (i != subs.end ());
74         BOOST_CHECK_EQUAL (i->text, "bold");
75         BOOST_CHECK_EQUAL (i->font, "Arial");
76         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
77         BOOST_CHECK_EQUAL (i->bold, true);
78         BOOST_CHECK_EQUAL (i->italic, false);
79         BOOST_CHECK_EQUAL (i->underline, false);
80         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1));
81         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10));
82         ++i;
83
84         BOOST_CHECK (i != subs.end ());
85         BOOST_CHECK_EQUAL (i->text, " and some ");
86         BOOST_CHECK_EQUAL (i->font, "Arial");
87         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
88         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1));
89         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10));
90         BOOST_CHECK_EQUAL (i->bold, false);
91         BOOST_CHECK_EQUAL (i->italic, false);
92         BOOST_CHECK_EQUAL (i->underline, false);
93         BOOST_CHECK_EQUAL (i->line, 0);
94         ++i;
95
96         BOOST_CHECK (i != subs.end ());
97         BOOST_CHECK_EQUAL (i->text, "bold italic");
98         BOOST_CHECK_EQUAL (i->font, "Arial");
99         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
100         BOOST_CHECK_EQUAL (i->bold, true);
101         BOOST_CHECK_EQUAL (i->italic, true);
102         BOOST_CHECK_EQUAL (i->underline, false);
103         BOOST_CHECK_EQUAL (i->line, 0);
104         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1));
105         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10));
106         ++i;
107
108         BOOST_CHECK (i != subs.end ());
109         BOOST_CHECK_EQUAL (i->text, " and some ");
110         BOOST_CHECK_EQUAL (i->font, "Arial");
111         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
112         BOOST_CHECK_EQUAL (i->bold, false);
113         BOOST_CHECK_EQUAL (i->italic, false);
114         BOOST_CHECK_EQUAL (i->underline, false);
115         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1));
116         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10));
117         ++i;
118
119         BOOST_CHECK (i != subs.end ());
120         BOOST_CHECK_EQUAL (i->text, "underlined");
121         BOOST_CHECK_EQUAL (i->font, "Arial");
122         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
123         BOOST_CHECK_EQUAL (i->bold, false);
124         BOOST_CHECK_EQUAL (i->italic, false);
125         BOOST_CHECK_EQUAL (i->underline, true);
126         BOOST_CHECK_EQUAL (i->line, 0);
127         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1));
128         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10));
129         ++i;
130
131         BOOST_CHECK_EQUAL (i->text, ".");
132         BOOST_CHECK_EQUAL (i->font, "Arial");
133         BOOST_CHECK_EQUAL (i->font_size.points.get(), 42);
134         BOOST_CHECK_EQUAL (i->bold, false);
135         BOOST_CHECK_EQUAL (i->italic, false);
136         BOOST_CHECK_EQUAL (i->underline, false);
137         BOOST_CHECK_EQUAL (i->line, 0);
138         BOOST_CHECK_EQUAL (i->from.frame.get(), sub::FrameTime (0, 1, 1, 1));
139         BOOST_CHECK_EQUAL (i->to.frame.get(), sub::FrameTime (0, 1, 2, 10));
140         ++i;
141         
142         BOOST_CHECK (i == subs.end ());
143 }
144
145