X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Fwriter_test.cc;h=1dfc75bfc024c588c7eef1b2db86cde3db64c4d2;hb=ace084a4b7595deea9d2bd019e9123a76a0fa1a9;hp=dade4d6b4388ab36e0ce42ac9469d0dfb163305b;hpb=786d0317a86f81d391efd4fab1bb331b4959f666;p=dcpomatic.git diff --git a/test/writer_test.cc b/test/writer_test.cc index dade4d6b4..1dfc75bfc 100644 --- a/test/writer_test.cc +++ b/test/writer_test.cc @@ -22,11 +22,14 @@ #include "lib/audio_buffers.h" #include "lib/content.h" #include "lib/content_factory.h" +#include "lib/cross.h" #include "lib/film.h" #include "lib/job.h" #include "lib/video_content.h" #include "lib/writer.h" #include "test.h" +#include +#include #include #include @@ -47,3 +50,54 @@ BOOST_AUTO_TEST_CASE (test_write_odd_amount_of_silence) writer->write (audio, dcpomatic::DCPTime(1)); } + +BOOST_AUTO_TEST_CASE (interrupt_writer) +{ + Cleanup cl; + + auto film = new_test_film2 ("test_interrupt_writer", {}, &cl); + + auto content = content_factory("test/data/check_image0.png").front(); + film->examine_and_add_content (content); + BOOST_REQUIRE (!wait_for_jobs()); + + /* Add some dummy content to the film so that it has a reel of the right length */ + auto constexpr frames = 24 * 60; + content->video->set_length (frames); + + /* Make a random J2K image */ + auto size = dcp::Size(1998, 1080); + auto image = make_shared(size); + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < (size.width * size.height); ++j) { + image->data(i)[j] = rand(); + } + } + + /* Write some data */ + auto video = dcp::compress_j2k(image, 100000000, 24, false, false); + auto video_ptr = make_shared(video.data(), video.size()); + auto audio = make_shared(6, 48000 / 24); + + auto writer = make_shared(film, shared_ptr()); + writer->start (); + + for (int i = 0; i < frames; ++i) { + writer->write (video_ptr, i, Eyes::BOTH); + writer->write (audio, dcpomatic::DCPTime::from_frames(i, 24)); + } + + /* Start digest calculations then abort them; there should be no crash or error */ + boost::thread thread([film, writer]() { + writer->finish(film->dir(film->dcp_name())); + }); + + dcpomatic_sleep_seconds (1); + + thread.interrupt (); + thread.join (); + + dcpomatic_sleep_seconds (1); + cl.run (); +} +