Fix up remake_with_subtitle_test.
authorCarl Hetherington <cth@carlh.net>
Fri, 1 Sep 2017 22:32:22 +0000 (23:32 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 1 Sep 2017 22:32:22 +0000 (23:32 +0100)
test/remake_with_subtitle_test.cc
test/test.cc
test/test.h

index 0190e9837c0f4150c12500d288aead3bbee7eb7b..bc6d4179866af71799a77de035912232e9a34bab 100644 (file)
@@ -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> 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");
 }
index a2593dca48c70879cb9b56576799d154acbc6410..9027b8b71bf139576f8805d9b2c882b8aeb1aeaa 100644 (file)
 #include "lib/dcp_content_type.h"
 #include "lib/log_entry.h"
 #include <dcp/dcp.h>
+#include <dcp/cpl.h>
+#include <dcp/reel.h>
+#include <dcp/reel_picture_asset.h>
+#include <dcp/mono_picture_frame.h>
+#include <dcp/mono_picture_asset.h>
+#include <dcp/openjpeg_image.h>
 #include <asdcp/AS_DCP.h>
 #include <sndfile.h>
 #include <libxml++/libxml++.h>
@@ -45,6 +51,7 @@ extern "C" {
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_MODULE dcpomatic_test
 #include <boost/test/unit_test.hpp>
+#include <boost/algorithm/string.hpp>
 #include <list>
 #include <vector>
 #include <iostream>
@@ -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<dcp::MonoPictureAsset> asset = dynamic_pointer_cast<dcp::MonoPictureAsset> (dcp.cpls().front()->reels().front()->main_picture()->asset());
+       BOOST_REQUIRE (asset);
+       shared_ptr<const dcp::MonoPictureFrame> 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<const Film> 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();
+}
index 33807bee8e56d62d8087a69dabaf6eecaff79e75..75ab7b7f6b23b23aa5106ada6aaa5d68592b1602 100644 (file)
@@ -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<const Image> image, boost::filesystem::path file, std::string format);
+boost::filesystem::path video_file (boost::shared_ptr<const Film> film);
+void check_one_frame (boost::filesystem::path dcp, int64_t index, boost::filesystem::path ref);