Fix render subtitle references.
[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<SubtitleString>& s, std::string text, bool italic, bool bold, bool underline)
27 {
28         s.push_back (
29                 SubtitleString (
30                         dcp::SubtitleString (
31                                 boost::optional<std::string> (),
32                                 italic,
33                                 bold,
34                                 underline,
35                                 dcp::Colour (255, 255, 255),
36                                 42,
37                                 1,
38                                 dcp::Time (),
39                                 dcp::Time (),
40                                 1,
41                                 dcp::HALIGN_LEFT,
42                                 1,
43                                 dcp::VALIGN_TOP,
44                                 dcp::DIRECTION_LTR,
45                                 text,
46                                 dcp::NONE,
47                                 dcp::Colour (0, 0, 0),
48                                 dcp::Time (),
49                                 dcp::Time ()
50                                 )
51                         )
52                 );
53 }
54
55 /** Test marked_up() in render_subtitles.cc */
56 BOOST_AUTO_TEST_CASE (render_markup_test1)
57 {
58         std::list<SubtitleString> s;
59         add (s, "Hello", false, false, false);
60         BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
61 }
62
63 /** Test marked_up() in render_subtitles.cc */
64 BOOST_AUTO_TEST_CASE (render_markup_test2)
65 {
66         std::list<SubtitleString> s;
67         add (s, "Hello", false, true, false);
68         BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
69 }
70
71
72 /** Test marked_up() in render_subtitles.cc */
73 BOOST_AUTO_TEST_CASE (render_markup_test3)
74 {
75         std::list<SubtitleString> s;
76         add (s, "Hello", true, true, false);
77         BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span style=\"italic\" weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
78 }
79
80 /** Test marked_up() in render_subtitles.cc */
81 BOOST_AUTO_TEST_CASE (render_markup_test4)
82 {
83         std::list<SubtitleString> s;
84         add (s, "Hello", true, true, true);
85         BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span style=\"italic\" weight=\"bold\" underline=\"single\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
86 }
87
88 /** Test marked_up() in render_subtitles.cc */
89 BOOST_AUTO_TEST_CASE (render_markup_test5)
90 {
91         std::list<SubtitleString> s;
92         add (s, "Hello", false, true, false);
93         add (s, " world.", false, false, false);
94         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>");
95 }
96
97 /** Test marked_up() in render_subtitles.cc */
98 BOOST_AUTO_TEST_CASE (render_markup_test6)
99 {
100         std::list<SubtitleString> s;
101         add (s, "Hello", true, false, false);
102         add (s, " world ", false, false, false);
103         add (s, "we are bold.", false, true, false);
104         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>");
105 }