From 33330f6e2cccb3be51788e919e763139d679cc8b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 1 Sep 2017 23:32:22 +0100 Subject: [PATCH] Fix up remake_with_subtitle_test. --- test/remake_with_subtitle_test.cc | 6 +++-- test/test.cc | 43 +++++++++++++++++++++++++++++++ test/test.h | 2 ++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/test/remake_with_subtitle_test.cc b/test/remake_with_subtitle_test.cc index 0190e9837..bc6d41798 100644 --- a/test/remake_with_subtitle_test.cc +++ b/test/remake_with_subtitle_test.cc @@ -28,6 +28,9 @@ using boost::shared_ptr; using boost::dynamic_pointer_cast; +/** Check that if we remake a DCP having turned off subtitles the code notices + * and doesn't re-use the old video data. + */ BOOST_AUTO_TEST_CASE (remake_with_subtitle_test) { shared_ptr film = new_test_film2 ("remake_with_subtitle_test"); @@ -45,6 +48,5 @@ BOOST_AUTO_TEST_CASE (remake_with_subtitle_test) film->make_dcp (); BOOST_REQUIRE (!wait_for_jobs ()); - /* Nothing is being checked here so this test is not complete */ - DCPOMATIC_ASSERT (false); + check_one_frame (film->dir(film->dcp_name()), 325, private_data / "prophet_frame_325_no_subs.j2c"); } diff --git a/test/test.cc b/test/test.cc index a2593dca4..9027b8b71 100644 --- a/test/test.cc +++ b/test/test.cc @@ -35,6 +35,12 @@ #include "lib/dcp_content_type.h" #include "lib/log_entry.h" #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -45,6 +51,7 @@ extern "C" { #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE dcpomatic_test #include +#include #include #include #include @@ -58,6 +65,7 @@ using std::list; using std::abs; using boost::shared_ptr; using boost::scoped_array; +using boost::dynamic_pointer_cast; boost::filesystem::path private_data = boost::filesystem::path ("..") / boost::filesystem::path ("dcpomatic-test-private"); @@ -459,3 +467,38 @@ check_ffmpeg (boost::filesystem::path ref, boost::filesystem::path check, int sk BOOST_REQUIRE_EQUAL (memcmp (ref_p.buf->data, check_p.buf->data, ref_p.buf->size), 0); } } + +void +check_one_frame (boost::filesystem::path dcp_dir, int64_t index, boost::filesystem::path ref) +{ + dcp::DCP dcp (dcp_dir); + dcp.read (); + shared_ptr asset = dynamic_pointer_cast (dcp.cpls().front()->reels().front()->main_picture()->asset()); + BOOST_REQUIRE (asset); + shared_ptr frame = asset->start_read()->get_frame(index); + + boost::uintmax_t const ref_size = boost::filesystem::file_size(ref); + BOOST_CHECK_EQUAL (frame->j2k_size(), ref_size); + + FILE* ref_file = fopen_boost(ref, "rb"); + BOOST_REQUIRE (ref_file); + + uint8_t* ref_data = new uint8_t[ref_size]; + fread (ref_data, ref_size, 1, ref_file); + fclose (ref_file); + + BOOST_CHECK (memcmp(ref_data, frame->j2k_data(), ref_size) == 0); + delete[] ref_data; +} + +boost::filesystem::path +video_file (shared_ptr film) +{ + boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->dir(film->dcp_name())); + while (i != boost::filesystem::directory_iterator() && !boost::algorithm::starts_with (i->path().leaf().string(), "j2c")) { + ++i; + } + + BOOST_REQUIRE (i != boost::filesystem::directory_iterator()); + return i->path(); +} diff --git a/test/test.h b/test/test.h index 33807bee8..75ab7b7f6 100644 --- a/test/test.h +++ b/test/test.h @@ -38,3 +38,5 @@ extern void check_ffmpeg (boost::filesystem::path, boost::filesystem::path, int extern void check_image (boost::filesystem::path, boost::filesystem::path); extern boost::filesystem::path test_film_dir (std::string); extern void write_image (boost::shared_ptr image, boost::filesystem::path file, std::string format); +boost::filesystem::path video_file (boost::shared_ptr film); +void check_one_frame (boost::filesystem::path dcp, int64_t index, boost::filesystem::path ref); -- 2.30.2