2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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.
11 libdcp 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.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
20 #include "interop_subtitle_asset.h"
21 #include "smpte_subtitle_asset.h"
27 #include "reel_subtitle_asset.h"
28 #include <boost/test/unit_test.hpp>
33 using boost::shared_ptr;
34 using boost::dynamic_pointer_cast;
35 using boost::shared_array;
37 /** Create a DCP with interop subtitles and check that the font is written and read back correctly */
38 BOOST_AUTO_TEST_CASE (interop_dcp_font_test)
40 boost::filesystem::path directory = "build/test/interop_dcp_font_test";
41 dcp::DCP dcp (directory);
43 shared_ptr<dcp::InteropSubtitleAsset> subs (new dcp::InteropSubtitleAsset ());
44 subs->add_font ("theFontId", "test/data/dummy.ttf");
45 subs->write (directory / "frobozz.xml");
46 check_file ("test/data/dummy.ttf", "build/test/interop_dcp_font_test/dummy.ttf");
48 shared_ptr<dcp::Reel> reel (new dcp::Reel ());
49 reel->add (shared_ptr<dcp::ReelAsset> (new dcp::ReelSubtitleAsset (subs, dcp::Fraction (24, 1), 24, 0)));
51 shared_ptr<dcp::CPL> cpl (new dcp::CPL ("", dcp::TRAILER));
55 dcp.write_xml (dcp::INTEROP);
57 dcp::DCP dcp2 (directory);
59 shared_ptr<dcp::SubtitleAsset> subs2 = dynamic_pointer_cast<dcp::SubtitleAsset> (
60 dcp2.cpls().front()->reels().front()->main_subtitle()->asset_ref().asset()
62 BOOST_REQUIRE (subs2);
63 BOOST_REQUIRE_EQUAL (subs2->_fonts.size(), 1);
65 boost::uintmax_t const size = boost::filesystem::file_size ("test/data/dummy.ttf");
66 FILE* f = dcp::fopen_boost ("test/data/dummy.ttf", "rb");
68 shared_array<uint8_t> ref (new uint8_t[size]);
69 fread (ref.get(), 1, size, f);
72 BOOST_CHECK_EQUAL (memcmp (subs2->_fonts.front().data.data().get(), ref.get(), size), 0);
75 /** Create a DCP with SMPTE subtitles and check that the font is written and read back correctly */
76 BOOST_AUTO_TEST_CASE (smpte_dcp_font_test)
78 boost::filesystem::path directory = "build/test/smpte_dcp_font_test";
79 dcp::DCP dcp (directory);
81 shared_ptr<dcp::SMPTESubtitleAsset> subs (new dcp::SMPTESubtitleAsset ());
82 subs->add_font ("theFontId", "test/data/dummy.ttf");
83 subs->write (directory / "frobozz.mxf");
85 shared_ptr<dcp::Reel> reel (new dcp::Reel ());
86 reel->add (shared_ptr<dcp::ReelAsset> (new dcp::ReelSubtitleAsset (subs, dcp::Fraction (24, 1), 24, 0)));
88 shared_ptr<dcp::CPL> cpl (new dcp::CPL ("", dcp::TRAILER));
92 dcp.write_xml (dcp::SMPTE);
94 dcp::DCP dcp2 (directory);
96 shared_ptr<dcp::SubtitleAsset> subs2 = dynamic_pointer_cast<dcp::SubtitleAsset> (
97 dcp2.cpls().front()->reels().front()->main_subtitle()->asset_ref().asset()
99 BOOST_REQUIRE (subs2);
100 BOOST_REQUIRE_EQUAL (subs2->_fonts.size(), 1);
102 boost::uintmax_t const size = boost::filesystem::file_size ("test/data/dummy.ttf");
103 FILE* f = dcp::fopen_boost ("test/data/dummy.ttf", "rb");
105 shared_array<uint8_t> ref (new uint8_t[size]);
106 fread (ref.get(), 1, size, f);
109 BOOST_REQUIRE (subs2->_fonts.front().data.data());
110 BOOST_CHECK_EQUAL (memcmp (subs2->_fonts.front().data.data().get(), ref.get(), size), 0);