test/data updates.
[dcpomatic.git] / test / subrip_test.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  test/subrip_test.cc
21  *  @brief Various tests of the subrip code.
22  */
23
24 #include <boost/test/unit_test.hpp>
25 #include <dcp/subtitle_content.h>
26 #include "lib/subrip.h"
27 #include "lib/subrip_content.h"
28 #include "lib/subrip_decoder.h"
29 #include "lib/render_subtitles.h"
30 #include "test.h"
31
32 using std::list;
33 using std::vector;
34 using std::string;
35 using boost::shared_ptr;
36 using boost::dynamic_pointer_cast;
37
38 /** Test rendering of a SubRip subtitle */
39 BOOST_AUTO_TEST_CASE (subrip_render_test)
40 {
41         shared_ptr<Film> film = new_test_film ("subrip_render_test");
42         shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip.srt"));
43         content->examine (shared_ptr<Job> (), true);
44         BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471));
45
46         shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (content));
47         list<ContentTextSubtitle> cts = decoder->get_text_subtitles (
48                 ContentTimePeriod (
49                         ContentTime::from_seconds (109), ContentTime::from_seconds (110)
50                         ), false
51                 );
52         BOOST_CHECK_EQUAL (cts.size(), 1);
53
54         PositionImage image = render_subtitles (cts.front().subs, dcp::Size (1998, 1080));
55         write_image (image.image, "build/test/subrip_render_test.png");
56         check_file ("build/test/subrip_render_test.png", "test/data/subrip_render_test.png");
57 }