2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include "interop_subtitle_asset.h"
26 #include "reel_subtitle_asset.h"
27 #include <boost/test/unit_test.hpp>
32 using boost::shared_ptr;
33 using boost::dynamic_pointer_cast;
34 using boost::shared_array;
36 /** Create a DCP with interop subtitles and check that the font is written and read back correctly */
37 BOOST_AUTO_TEST_CASE (interop_dcp_font_test)
39 boost::filesystem::path directory = "build/test/interop_dcp_font_test";
40 dcp::DCP dcp (directory);
42 shared_ptr<dcp::InteropSubtitleAsset> subs (new dcp::InteropSubtitleAsset ());
43 subs->add_font ("theFontId", "test/data/dummy.ttf");
44 subs->write (directory / "frobozz.xml");
45 check_file ("test/data/dummy.ttf", "build/test/interop_dcp_font_test/dummy.ttf");
47 shared_ptr<dcp::Reel> reel (new dcp::Reel ());
48 reel->add (shared_ptr<dcp::ReelAsset> (new dcp::ReelSubtitleAsset (subs, dcp::Fraction (24, 1), 24, 0)));
50 shared_ptr<dcp::CPL> cpl (new dcp::CPL ("", dcp::TRAILER));
54 dcp.write_xml (dcp::INTEROP);
56 dcp::DCP dcp2 (directory);
58 shared_ptr<dcp::SubtitleAsset> subs2 = dynamic_pointer_cast<dcp::SubtitleAsset> (
59 dcp2.cpls().front()->reels().front()->main_subtitle()->asset_ref().object()
61 BOOST_REQUIRE (subs2);
62 BOOST_REQUIRE_EQUAL (subs2->_fonts.size(), 1);
64 boost::uintmax_t const size = boost::filesystem::file_size ("test/data/dummy.ttf");
65 FILE* f = dcp::fopen_boost ("test/data/dummy.ttf", "r");
67 shared_array<uint8_t> ref (new uint8_t[size]);
68 fread (ref.get(), 1, size, f);
71 BOOST_CHECK_EQUAL (memcmp (subs2->_fonts["theFontId"].data.get(), ref.get(), size), 0);