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