diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-06-09 11:13:02 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-06-09 11:13:02 +0100 |
| commit | 5c1b079a28941781c9cfa46d57e0c20b55681b32 (patch) | |
| tree | 35c0d2aac409ca1b52699e974f299a64aa5ffc1f /test | |
| parent | 6425742f95a4c2e539061b29016a4a5bd10ac9ae (diff) | |
Basically-working interop subtitle font handling.
Diffstat (limited to 'test')
| -rw-r--r-- | test/data/dummy.ttf | 1 | ||||
| -rw-r--r-- | test/dcp_font_test.cc | 72 | ||||
| -rw-r--r-- | test/test.cc | 42 | ||||
| -rw-r--r-- | test/test.h | 1 | ||||
| -rw-r--r-- | test/wscript | 1 |
5 files changed, 117 insertions, 0 deletions
diff --git a/test/data/dummy.ttf b/test/data/dummy.ttf new file mode 100644 index 00000000..1353512a --- /dev/null +++ b/test/data/dummy.ttf @@ -0,0 +1 @@ +Uap[~"ײB&ccOFJXPx{(TI{8tO'ـr"@7pNͷ-4'4BVlhy<yg
\ No newline at end of file diff --git a/test/dcp_font_test.cc b/test/dcp_font_test.cc new file mode 100644 index 00000000..e50219a0 --- /dev/null +++ b/test/dcp_font_test.cc @@ -0,0 +1,72 @@ +/* + Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "interop_subtitle_asset.h" +#include "dcp.h" +#include "cpl.h" +#include "test.h" +#include "reel.h" +#include "util.h" +#include "reel_subtitle_asset.h" +#include <boost/test/unit_test.hpp> +#include <cstdio> + +using std::list; +using std::string; +using boost::shared_ptr; +using boost::dynamic_pointer_cast; +using boost::shared_array; + +/** Create a DCP with interop subtitles and check that the font is written and read back correctly */ +BOOST_AUTO_TEST_CASE (interop_dcp_font_test) +{ + boost::filesystem::path directory = "build/test/interop_dcp_font_test"; + dcp::DCP dcp (directory); + + shared_ptr<dcp::InteropSubtitleAsset> subs (new dcp::InteropSubtitleAsset ()); + subs->add_font ("theFontId", "test/data/dummy.ttf"); + subs->write (directory / "frobozz.xml"); + check_file ("test/data/dummy.ttf", "build/test/interop_dcp_font_test/dummy.ttf"); + + shared_ptr<dcp::Reel> reel (new dcp::Reel ()); + reel->add (shared_ptr<dcp::ReelAsset> (new dcp::ReelSubtitleAsset (subs, dcp::Fraction (24, 1), 24, 0))); + + shared_ptr<dcp::CPL> cpl (new dcp::CPL ("", dcp::TRAILER)); + cpl->add (reel); + + dcp.add (cpl); + dcp.write_xml (dcp::INTEROP); + + dcp::DCP dcp2 (directory); + dcp2.read (); + shared_ptr<dcp::SubtitleAsset> subs2 = dynamic_pointer_cast<dcp::SubtitleAsset> ( + dcp2.cpls().front()->reels().front()->main_subtitle()->asset_ref().object() + ); + BOOST_REQUIRE (subs2); + BOOST_REQUIRE_EQUAL (subs2->_fonts.size(), 1); + + boost::uintmax_t const size = boost::filesystem::file_size ("test/data/dummy.ttf"); + FILE* f = dcp::fopen_boost ("test/data/dummy.ttf", "r"); + BOOST_REQUIRE (f); + shared_array<uint8_t> ref (new uint8_t[size]); + fread (ref.get(), 1, size, f); + fclose (f); + + BOOST_CHECK_EQUAL (memcmp (subs2->_fonts["theFontId"].data.get(), ref.get(), size), 0); +} diff --git a/test/test.cc b/test/test.cc index 0c3d2c5d..c83c1048 100644 --- a/test/test.cc +++ b/test/test.cc @@ -23,8 +23,11 @@ #include "test.h" #include <libxml++/libxml++.h> #include <boost/test/unit_test.hpp> +#include <cstdio> using std::string; +using std::min; +using std::stringstream; using std::list; boost::filesystem::path private_test; @@ -106,4 +109,43 @@ check_xml (string ref, string test, list<string> ignore) check_xml (ref_root, test_root, ignore); } +void +check_file (boost::filesystem::path ref, boost::filesystem::path check) +{ + uintmax_t N = boost::filesystem::file_size (ref); + BOOST_CHECK_EQUAL (N, boost::filesystem::file_size (check)); + FILE* ref_file = dcp::fopen_boost (ref, "rb"); + BOOST_CHECK (ref_file); + FILE* check_file = dcp::fopen_boost (check, "rb"); + BOOST_CHECK (check_file); + + int const buffer_size = 65536; + uint8_t* ref_buffer = new uint8_t[buffer_size]; + uint8_t* check_buffer = new uint8_t[buffer_size]; + + stringstream error; + error << "File " << check.string() << " differs from reference " << ref.string(); + + while (N) { + uintmax_t this_time = min (uintmax_t (buffer_size), N); + size_t r = fread (ref_buffer, 1, this_time, ref_file); + BOOST_CHECK_EQUAL (r, this_time); + r = fread (check_buffer, 1, this_time, check_file); + BOOST_CHECK_EQUAL (r, this_time); + + BOOST_CHECK_MESSAGE (memcmp (ref_buffer, check_buffer, this_time) == 0, error.str ()); + if (memcmp (ref_buffer, check_buffer, this_time)) { + break; + } + + N -= this_time; + } + + delete[] ref_buffer; + delete[] check_buffer; + + fclose (ref_file); + fclose (check_file); +} + BOOST_GLOBAL_FIXTURE (TestConfig); diff --git a/test/test.h b/test/test.h index 4c941023..62a4c942 100644 --- a/test/test.h +++ b/test/test.h @@ -24,3 +24,4 @@ namespace xmlpp { extern boost::filesystem::path private_test; extern void check_xml (xmlpp::Element* ref, xmlpp::Element* test, std::list<std::string> ignore); extern void check_xml (std::string ref, std::string test, std::list<std::string> ignore); +extern void check_file (boost::filesystem::path ref, boost::filesystem::path check); diff --git a/test/wscript b/test/wscript index f640f6fc..6cf0d958 100644 --- a/test/wscript +++ b/test/wscript @@ -29,6 +29,7 @@ def build(bld): colour_test.cc colour_conversion_test.cc cpl_sar_test.cc + dcp_font_test.cc dcp_test.cc dcp_time_test.cc decryption_test.cc |
