Update wscript.
[libsub.git] / test / stl_text_writer_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_text_writer.h"
23 #include "subtitle.h"
24 #include "test.h"
25
26 using std::list;
27 using std::string;
28 using std::ifstream;
29 using std::ofstream;
30
31 static sub::Subtitle
32 make (string text, bool bold, bool italic, bool underline, int line, sub::FrameTime from, sub::FrameTime to)
33 {
34         sub::Subtitle s;
35         s.text = text;
36         s.font = "Arial";
37         s.font_size.points = 42;
38         s.bold = bold;
39         s.italic = italic;
40         s.underline = underline;
41         s.line = line;
42         s.from.frame = from;
43         s.to.frame = to;
44         return s;
45 }
46
47 /* Test writing of an textual STL file */
48 BOOST_AUTO_TEST_CASE (stl_text_writer_test)
49 {
50         list<sub::Subtitle> subs;
51         subs.push_back (make (" This is a subtitle ",     false, false, false, 0, sub::FrameTime (0, 0, 41, 9), sub::FrameTime (0, 0, 42, 21)));
52         subs.push_back (make (" and that's a line break", false, false, false, 1, sub::FrameTime (0, 0, 41, 9), sub::FrameTime (0, 0, 42, 21)));
53         subs.push_back (make (" This is some ",           false, false, false, 0, sub::FrameTime (0, 1,  1, 1), sub::FrameTime (0, 1,  2, 10)));
54         subs.push_back (make ("bold",                     true,  false, false, 0, sub::FrameTime (0, 1,  1, 1), sub::FrameTime (0, 1,  2, 10)));
55         subs.push_back (make (" and some ",               false, false, false, 0, sub::FrameTime (0, 1,  1, 1), sub::FrameTime (0, 1,  2, 10)));
56         subs.push_back (make ("bold italic",              true,  true,  false, 0, sub::FrameTime (0, 1,  1, 1), sub::FrameTime (0, 1,  2, 10)));
57         subs.push_back (make (" and some ",               false, false, false, 0, sub::FrameTime (0, 1,  1, 1), sub::FrameTime (0, 1,  2, 10)));
58         subs.push_back (make ("underlined",               false, false, true,  0, sub::FrameTime (0, 1,  1, 1), sub::FrameTime (0, 1,  2, 10)));
59         subs.push_back (make (".",                        false, false, false, 0, sub::FrameTime (0, 1,  1, 1), sub::FrameTime (0, 1,  2, 10)));
60
61         ofstream f ("build/test/test.stl");
62         write_stl_text (subs, 24, 72 * 11, f);
63         f.close ();
64
65         check_text ("test/ref/test.stl", "build/test/test.stl");
66 }
67
68