Fix pango markup when rendering subtitles.
[dcpomatic.git] / test / render_subtitles_test.cc
1 /*
2     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "lib/render_subtitles.h"
22 #include <dcp/subtitle_string.h>
23 #include <boost/test/unit_test.hpp>
24
25 static void
26 add (std::list<dcp::SubtitleString>& s, std::string text, bool italic, bool bold, bool underline)
27 {
28         s.push_back (
29                 dcp::SubtitleString (
30                         boost::optional<std::string> (),
31                         italic,
32                         bold,
33                         underline,
34                         dcp::Colour (255, 255, 255),
35                         42,
36                         1,
37                         dcp::Time (),
38                         dcp::Time (),
39                         1,
40                         dcp::HALIGN_LEFT,
41                         1,
42                         dcp::VALIGN_TOP,
43                         dcp::DIRECTION_LTR,
44                         text,
45                         dcp::NONE,
46                         dcp::Colour (0, 0, 0),
47                         dcp::Time (),
48                         dcp::Time ()
49                         )
50                 );
51 }
52
53 /** Test marked_up() in render_subtitles.cc */
54 BOOST_AUTO_TEST_CASE (render_markup_test1)
55 {
56         std::list<dcp::SubtitleString> s;
57         add (s, "Hello", false, false, false);
58         BOOST_CHECK_EQUAL (marked_up (s), "Hello");
59 }
60
61 /** Test marked_up() in render_subtitles.cc */
62 BOOST_AUTO_TEST_CASE (render_markup_test2)
63 {
64         std::list<dcp::SubtitleString> s;
65         add (s, "Hello", false, true, false);
66         BOOST_CHECK_EQUAL (marked_up (s), "<b>Hello</b>");
67 }
68
69
70 /** Test marked_up() in render_subtitles.cc */
71 BOOST_AUTO_TEST_CASE (render_markup_test3)
72 {
73         std::list<dcp::SubtitleString> s;
74         add (s, "Hello", true, true, false);
75         BOOST_CHECK_EQUAL (marked_up (s), "<i><b>Hello</b></i>");
76 }
77
78 /** Test marked_up() in render_subtitles.cc */
79 BOOST_AUTO_TEST_CASE (render_markup_test4)
80 {
81         std::list<dcp::SubtitleString> s;
82         add (s, "Hello", true, true, true);
83         BOOST_CHECK_EQUAL (marked_up (s), "<i><b><u>Hello</u></b></i>");
84 }