X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Fwriter_test.cc;h=d5cafe1fbfd33aa25f517910e02d50327a2d194f;hb=HEAD;hp=cb97cf78afb2209b4cccbf1dc342249e44bb5636;hpb=3b137ece1ab4bffe4c959047972c5d1317f8a79c;p=dcpomatic.git diff --git a/test/writer_test.cc b/test/writer_test.cc index cb97cf78a..86b60818f 100644 --- a/test/writer_test.cc +++ b/test/writer_test.cc @@ -23,6 +23,7 @@ #include "lib/content.h" #include "lib/content_factory.h" #include "lib/cross.h" +#include "lib/dcp_encoder.h" #include "lib/film.h" #include "lib/job.h" #include "lib/video_content.h" @@ -36,13 +37,15 @@ using std::make_shared; using std::shared_ptr; +using std::string; +using std::vector; BOOST_AUTO_TEST_CASE (test_write_odd_amount_of_silence) { - auto content = content_factory("test/data/flat_red.png").front(); - auto film = new_test_film2 ("test_write_odd_amount_of_silence", {content}); - content->video->set_length(24); + auto content = content_factory("test/data/flat_red.png"); + auto film = new_test_film2 ("test_write_odd_amount_of_silence", content); + content[0]->video->set_length(24); auto writer = make_shared(film, shared_ptr()); auto audio = make_shared(6, 48000); @@ -53,14 +56,16 @@ BOOST_AUTO_TEST_CASE (test_write_odd_amount_of_silence) BOOST_AUTO_TEST_CASE (interrupt_writer) { - auto film = new_test_film2 ("test_interrupt_writer"); + Cleanup cl; - auto content = content_factory("test/data/check_image0.png").front(); + auto film = new_test_film2 ("test_interrupt_writer", {}, &cl); + + auto content = content_factory("test/data/check_image0.png")[0]; 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 * 60; + auto constexpr frames = 24 * 60; content->video->set_length (frames); /* Make a random J2K image */ @@ -68,7 +73,7 @@ BOOST_AUTO_TEST_CASE (interrupt_writer) 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(); + image->data(i)[j] = rand() % 4095; } } @@ -93,7 +98,58 @@ BOOST_AUTO_TEST_CASE (interrupt_writer) dcpomatic_sleep_seconds (1); thread.interrupt (); + thread.join (); dcpomatic_sleep_seconds (1); + cl.run (); +} + + +BOOST_AUTO_TEST_CASE(writer_progress_test) +{ + class TestJob : public Job + { + public: + explicit TestJob(shared_ptr film) + : Job(film) + {} + + ~TestJob() + { + stop_thread(); + } + + std::string name() const override { + return "test"; + } + std::string json_name() const override { + return "test"; + } + void run() override {}; + }; + + auto picture1 = content_factory("test/data/flat_red.png")[0]; + auto picture2 = content_factory("test/data/flat_red.png")[0]; + + auto film = new_test_film2("writer_progress_test", { picture1, picture2 }); + film->set_reel_type(ReelType::BY_VIDEO_CONTENT); + picture1->video->set_length(240); + picture2->video->set_length(240); + picture2->set_position(film, dcpomatic::DCPTime::from_seconds(10)); + + auto job = std::make_shared(film); + job->set_rate_limit_progress(false); + + float last_progress = 0; + string last_sub_name; + boost::signals2::scoped_connection connection = job->Progress.connect([job, &last_progress, &last_sub_name]() { + auto const progress = job->progress().get_value_or(0); + BOOST_REQUIRE(job->sub_name() != last_sub_name || progress >= last_progress); + last_progress = progress; + last_sub_name = job->sub_name(); + }); + + DCPEncoder encoder(film, job); + encoder.go(); }