Basic and slightly inaccurate support for <Space> in subtitles (#2103).
[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 /** @file  test/render_text_test.cc
22  *  @brief Check markup of subtitles for rendering.
23  *  @ingroup feature
24  */
25
26 #include "lib/render_text.h"
27 #include <dcp/subtitle_string.h>
28 #include <boost/test/unit_test.hpp>
29
30 static void
31 add (std::list<StringText>& s, std::string text, bool italic, bool bold, bool underline)
32 {
33         s.push_back (
34                 StringText (
35                         dcp::SubtitleString (
36                                 boost::optional<std::string> (),
37                                 italic,
38                                 bold,
39                                 underline,
40                                 dcp::Colour (255, 255, 255),
41                                 42,
42                                 1,
43                                 dcp::Time (),
44                                 dcp::Time (),
45                                 1,
46                                 dcp::HAlign::LEFT,
47                                 1,
48                                 dcp::VAlign::TOP,
49                                 dcp::Direction::LTR,
50                                 text,
51                                 dcp::Effect::NONE,
52                                 dcp::Colour (0, 0, 0),
53                                 dcp::Time (),
54                                 dcp::Time (),
55                                 0
56                                 ),
57                         2
58                         )
59                 );
60 }
61
62 /** Test marked_up() in render_text.cc */
63 BOOST_AUTO_TEST_CASE (render_markup_test1)
64 {
65         std::list<StringText> s;
66         add (s, "Hello", false, false, false);
67         BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
68 }
69
70 /** Test marked_up() in render_text.cc */
71 BOOST_AUTO_TEST_CASE (render_markup_test2)
72 {
73         std::list<StringText> s;
74         add (s, "Hello", false, true, false);
75         BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
76 }
77
78
79 /** Test marked_up() in render_text.cc */
80 BOOST_AUTO_TEST_CASE (render_markup_test3)
81 {
82         std::list<StringText> s;
83         add (s, "Hello", true, true, false);
84         BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span style=\"italic\" weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
85 }
86
87 /** Test marked_up() in render_text.cc */
88 BOOST_AUTO_TEST_CASE (render_markup_test4)
89 {
90         std::list<StringText> s;
91         add (s, "Hello", true, true, true);
92         BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span style=\"italic\" weight=\"bold\" underline=\"single\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
93 }
94
95 /** Test marked_up() in render_text.cc */
96 BOOST_AUTO_TEST_CASE (render_markup_test5)
97 {
98         std::list<StringText> s;
99         add (s, "Hello", false, true, false);
100         add (s, " world.", false, false, false);
101         BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span><span size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\"> world.</span>");
102 }
103
104 /** Test marked_up() in render_text.cc */
105 BOOST_AUTO_TEST_CASE (render_markup_test6)
106 {
107         std::list<StringText> s;
108         add (s, "Hello", true, false, false);
109         add (s, " world ", false, false, false);
110         add (s, "we are bold.", false, true, false);
111         BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span style=\"italic\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span><span size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\"> world </span><span weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">we are bold.</span>");
112 }