Reword again: Text -> Caption and Plain -> Text.
[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 specific
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<TextCaption>& s, std::string text, bool italic, bool bold, bool underline)
32 {
33         s.push_back (
34                 TextCaption (
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::NONE,
52                                 dcp::Colour (0, 0, 0),
53                                 dcp::Time (),
54                                 dcp::Time ()
55                                 )
56                         )
57                 );
58 }
59
60 /** Test marked_up() in render_text.cc */
61 BOOST_AUTO_TEST_CASE (render_markup_test1)
62 {
63         std::list<TextCaption> s;
64         add (s, "Hello", false, false, false);
65         BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
66 }
67
68 /** Test marked_up() in render_text.cc */
69 BOOST_AUTO_TEST_CASE (render_markup_test2)
70 {
71         std::list<TextCaption> s;
72         add (s, "Hello", false, true, false);
73         BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
74 }
75
76
77 /** Test marked_up() in render_text.cc */
78 BOOST_AUTO_TEST_CASE (render_markup_test3)
79 {
80         std::list<TextCaption> s;
81         add (s, "Hello", true, true, false);
82         BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span style=\"italic\" weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
83 }
84
85 /** Test marked_up() in render_text.cc */
86 BOOST_AUTO_TEST_CASE (render_markup_test4)
87 {
88         std::list<TextCaption> s;
89         add (s, "Hello", true, true, true);
90         BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span style=\"italic\" weight=\"bold\" underline=\"single\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
91 }
92
93 /** Test marked_up() in render_text.cc */
94 BOOST_AUTO_TEST_CASE (render_markup_test5)
95 {
96         std::list<TextCaption> s;
97         add (s, "Hello", false, true, false);
98         add (s, " world.", false, false, false);
99         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>");
100 }
101
102 /** Test marked_up() in render_text.cc */
103 BOOST_AUTO_TEST_CASE (render_markup_test6)
104 {
105         std::list<TextCaption> s;
106         add (s, "Hello", true, false, false);
107         add (s, " world ", false, false, false);
108         add (s, "we are bold.", false, true, false);
109         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>");
110 }