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