diff options
Diffstat (limited to 'test')
41 files changed, 1777 insertions, 350 deletions
diff --git a/test/4k_test.cc b/test/4k_test.cc index e65804aa5..fa5b33bb9 100644 --- a/test/4k_test.cc +++ b/test/4k_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,6 +17,12 @@ */ +/** @file test/4k_test.cc + * @brief Run a 4K encode from a simple input. + * + * The output is checked against test/data/4k_test. + */ + #include <boost/test/unit_test.hpp> #include "lib/film.h" #include "lib/ffmpeg_content.h" diff --git a/test/README b/test/README new file mode 100644 index 000000000..a129b6617 --- /dev/null +++ b/test/README @@ -0,0 +1,50 @@ +DCP-o-matic unit tests +---------------------- + +They can be grouped roughly into the following: + +* Self-contained tests of single classes / method sets + +AudioAnalysis: audio_analysis_test +AudioBuffers: audio_buffers_test +AudioDecoder: audio_decoder_test +AudioMapping: audio_mapping_test +ColourConversion: colour_conversion_test +FileGroup: file_group_test +Image: image_test, pixel_formats_test, make_black_test +Player: player_test +Job/JobManager: job_test +SubRip: subrip_test +Ratio: ratio_test +Resampler: resampler_test +util.cc: util_test + +* "Complete" builds of DCPs with various characteristics, aiming +to test broad areas of code + +4k_test +threed_test + +* Tests of fairly specific areas + +audio_delay_test +black_fill_test +client_server_test +film_metadata_test +frame_rate_test +recover_test +repeat_frame_test +scaling_test +silence_padding_test +skip_frame_test + + - FFmpeg decoding + + ffmpeg_audio_test + ffmpeg_dcp_test + ffmpeg_decoder_seek_test + ffmpeg_decoder_sequential_test + ffmpeg_examiner_test + ffmpeg_pts_offset_test + seek_zero_test.cc + stream_test diff --git a/test/audio_analysis_test.cc b/test/audio_analysis_test.cc index 77b2aeaf6..13a8dac84 100644 --- a/test/audio_analysis_test.cc +++ b/test/audio_analysis_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 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 @@ -17,6 +17,10 @@ */ +/** @file test/audio_analysis_test.cc + * @brief Check serialisation of audio analyses. + */ + #include <boost/test/unit_test.hpp> #include "lib/audio_analysis.h" @@ -26,7 +30,6 @@ random_float () return (float (rand ()) / RAND_MAX) * 2 - 1; } -/* Check serialisation of audio analyses */ BOOST_AUTO_TEST_CASE (audio_analysis_test) { int const channels = 3; @@ -50,7 +53,7 @@ BOOST_AUTO_TEST_CASE (audio_analysis_test) AudioAnalysis b ("build/test/audio_analysis_test"); for (int i = 0; i < channels; ++i) { - BOOST_CHECK (b.points(i) == points); + BOOST_CHECK_EQUAL (b.points(i), points); for (int j = 0; j < points; ++j) { AudioPoint p = b.get_point (i, j); BOOST_CHECK_CLOSE (p[AudioPoint::PEAK], random_float (), 1); diff --git a/test/audio_buffers_test.cc b/test/audio_buffers_test.cc new file mode 100644 index 000000000..15f918470 --- /dev/null +++ b/test/audio_buffers_test.cc @@ -0,0 +1,303 @@ +/* + Copyright (C) 2014 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. + +*/ + +/** @file test/audio_buffers_test.cc + * @brief Test AudioBuffers in various ways. + */ + +#include <cmath> +#include <boost/test/unit_test.hpp> +#include "lib/audio_buffers.h" + +using std::pow; + +static float tolerance = 1e-3; + +static float +random_float () +{ + return float (rand ()) / RAND_MAX; +} + +static void +random_fill (AudioBuffers& buffers) +{ + for (int i = 0; i < buffers.frames(); ++i) { + for (int j = 0; j < buffers.channels(); ++j) { + buffers.data(j)[i] = random_float (); + } + } +} + +static void +random_check (AudioBuffers& buffers, int from, int frames) +{ + for (int i = from; i < (from + frames); ++i) { + for (int j = 0; j < buffers.channels(); ++j) { + BOOST_CHECK_CLOSE (buffers.data(j)[i], random_float (), tolerance); + } + } +} + +/** Basic setup */ +BOOST_AUTO_TEST_CASE (audio_buffers_setup_test) +{ + AudioBuffers buffers (4, 9155); + + BOOST_CHECK (buffers.data ()); + for (int i = 0; i < 4; ++i) { + BOOST_CHECK (buffers.data (i)); + } + + BOOST_CHECK_EQUAL (buffers.channels(), 4); + BOOST_CHECK_EQUAL (buffers.frames(), 9155); +} + +/** Extending some buffers */ +BOOST_AUTO_TEST_CASE (audio_buffers_extend_test) +{ + AudioBuffers buffers (3, 150); + srand (1); + random_fill (buffers); + + /* Extend */ + buffers.ensure_size (299); + + srand (1); + random_check (buffers, 0, 150); + + /* New space should be silent */ + for (int i = 150; i < 299; ++i) { + for (int c = 0; c < 3; ++c) { + BOOST_CHECK_EQUAL (buffers.data(c)[i], 0); + } + } +} + +/** make_silent() */ +BOOST_AUTO_TEST_CASE (audio_buffers_make_silent_test) +{ + AudioBuffers buffers (9, 9933); + srand (2); + random_fill (buffers); + + buffers.make_silent (); + + for (int i = 0; i < 9933; ++i) { + for (int c = 0; c < 9; ++c) { + BOOST_CHECK_EQUAL (buffers.data(c)[i], 0); + } + } +} + +/** make_silent (int c) */ +BOOST_AUTO_TEST_CASE (audio_buffers_make_silent_channel_test) +{ + AudioBuffers buffers (9, 9933); + srand (3); + random_fill (buffers); + + buffers.make_silent (4); + + srand (3); + for (int i = 0; i < 9933; ++i) { + for (int c = 0; c < 9; ++c) { + if (c == 4) { + random_float (); + BOOST_CHECK_EQUAL (buffers.data(c)[i], 0); + } else { + BOOST_CHECK_CLOSE (buffers.data(c)[i], random_float (), tolerance); + } + } + } +} + +/** make_silent (int from, int frames) */ +BOOST_AUTO_TEST_CASE (audio_buffers_make_silent_part_test) +{ + AudioBuffers buffers (9, 9933); + srand (4); + random_fill (buffers); + + buffers.make_silent (145, 833); + + srand (4); + for (int i = 0; i < 145; ++i) { + for (int c = 0; c < 9; ++c) { + BOOST_CHECK_EQUAL (buffers.data(c)[i], random_float ()); + } + } + + for (int i = 145; i < (145 + 833); ++i) { + for (int c = 0; c < 9; ++c) { + random_float (); + BOOST_CHECK_EQUAL (buffers.data(c)[i], 0); + } + } + + for (int i = (145 + 833); i < 9933; ++i) { + for (int c = 0; c < 9; ++c) { + BOOST_CHECK_EQUAL (buffers.data(c)[i], random_float ()); + } + } +} + +/* apply_gain */ +BOOST_AUTO_TEST_CASE (audio_buffers_apply_gain) +{ + AudioBuffers buffers (2, 417315); + srand (9); + random_fill (buffers); + + buffers.apply_gain (5.4); + + srand (9); + for (int i = 0; i < 417315; ++i) { + for (int c = 0; c < 2; ++c) { + BOOST_CHECK_CLOSE (buffers.data(c)[i], random_float() * pow (10, 5.4 / 20), tolerance); + } + } +} + +/* copy_from */ +BOOST_AUTO_TEST_CASE (audio_buffers_copy_from) +{ + AudioBuffers a (5, 63711); + AudioBuffers b (5, 12345); + + srand (42); + random_fill (a); + + srand (99); + random_fill (b); + + a.copy_from (&b, 517, 233, 194); + + /* Re-seed a's generator and check the numbers that came from it */ + + /* First part; not copied-over */ + srand (42); + random_check (a, 0, 194); + + /* Second part; copied-over (just burn generator a's numbers) */ + for (int i = 0; i < (517 * 5); ++i) { + random_float (); + } + + /* Third part; not copied-over */ + random_check (a, 194 + 517, a.frames() - 194 - 517); + + /* Re-seed b's generator and check the numbers that came from it */ + srand (99); + + /* First part; burn */ + for (int i = 0; i < 194 * 5; ++i) { + random_float (); + } + + /* Second part; copied */ + random_check (b, 194, 517); +} + +/* move */ +BOOST_AUTO_TEST_CASE (audio_buffers_move) +{ + AudioBuffers buffers (7, 65536); + + srand (84); + random_fill (buffers); + + int const from = 888; + int const to = 666; + int const frames = 444; + + buffers.move (from, to, frames); + + /* Re-seed and check the un-moved parts */ + srand (84); + + random_check (buffers, 0, to); + + /* Burn a few */ + for (int i = 0; i < (from - to + frames) * 7; ++i) { + random_float (); + } + + random_check (buffers, from + frames, 65536 - frames - from); + + /* Re-seed and check the moved part */ + srand (84); + + /* Burn a few */ + for (int i = 0; i < from * 7; ++i) { + random_float (); + } + + random_check (buffers, to, frames); +} + +/** accumulate_channel */ +BOOST_AUTO_TEST_CASE (audio_buffers_accumulate_channel) +{ + AudioBuffers a (3, 256); + srand (38); + random_fill (a); + + AudioBuffers b (3, 256); + random_fill (b); + + a.accumulate_channel (&b, 2, 1, 1.2); + + srand (38); + for (int i = 0; i < 256; ++i) { + for (int c = 0; c < 3; ++c) { + float const A = random_float (); + if (c == 1) { + BOOST_CHECK_CLOSE (a.data(c)[i], A + b.data(2)[i] * 1.2, tolerance); + } else { + BOOST_CHECK_CLOSE (a.data(c)[i], A, tolerance); + } + } + } +} + +/** accumulate_frames */ +BOOST_AUTO_TEST_CASE (audio_buffers_accumulate_frames) +{ + AudioBuffers a (3, 256); + srand (38); + random_fill (a); + + AudioBuffers b (3, 256); + random_fill (b); + + a.accumulate_frames (&b, 91, 44, 129); + + srand (38); + for (int i = 0; i < 256; ++i) { + for (int c = 0; c < 3; ++c) { + float const A = random_float (); + if (i < 44 || i >= (44 + 129)) { + BOOST_CHECK_CLOSE (a.data(c)[i], A, tolerance); + } else { + BOOST_CHECK_CLOSE (a.data(c)[i], A + b.data(c)[i + 91 - 44], tolerance); + } + } + } +} diff --git a/test/audio_decoder_test.cc b/test/audio_decoder_test.cc new file mode 100644 index 000000000..a14e2f9be --- /dev/null +++ b/test/audio_decoder_test.cc @@ -0,0 +1,161 @@ +/* + Copyright (C) 2014 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. + +*/ + +/** @file test/audio_decoder_test.cc + * @brief Tests of the AudioDecoder class. + */ + +#include <cassert> +#include <boost/test/unit_test.hpp> +#include "test.h" +#include "lib/audio_decoder.h" +#include "lib/audio_content.h" + +using std::string; +using std::cout; +using std::min; +using boost::shared_ptr; + +class TestAudioDecoder : public AudioDecoder +{ +public: + TestAudioDecoder (shared_ptr<AudioContent> content) + : AudioDecoder (content) + , _position (0) + {} + + bool pass () + { + AudioFrame const N = min ( + AudioFrame (2000), + _audio_content->audio_length().frames (_audio_content->resampled_audio_frame_rate ()) - _position + ); + + shared_ptr<AudioBuffers> buffers (new AudioBuffers (_audio_content->audio_channels(), N)); + for (int i = 0; i < _audio_content->audio_channels(); ++i) { + for (int j = 0; j < N; ++j) { + buffers->data(i)[j] = j + _position; + } + } + + audio (buffers, ContentTime::from_frames (_position, _audio_content->resampled_audio_frame_rate ())); + _position += N; + + return N < 2000; + } + + void seek (ContentTime t, bool accurate) + { + AudioDecoder::seek (t, accurate); + _position = t.frames (_audio_content->resampled_audio_frame_rate ()); + } + +private: + AudioFrame _position; +}; + +class TestAudioContent : public AudioContent +{ +public: + TestAudioContent (shared_ptr<Film> film) + : Content (film) + , AudioContent (film, DCPTime ()) + {} + + string summary () const { + return ""; + } + + string information () const { + return ""; + } + + DCPTime full_length () const { + return DCPTime (audio_length().get ()); + } + + int audio_channels () const { + return 2; + } + + ContentTime audio_length () const { + return ContentTime::from_seconds (61.2942); + } + + int audio_frame_rate () const { + return 48000; + } + + AudioMapping audio_mapping () const { + return AudioMapping (audio_channels ()); + } + + void set_audio_mapping (AudioMapping) {} +}; + +shared_ptr<TestAudioContent> content; +shared_ptr<TestAudioDecoder> decoder; + +static shared_ptr<ContentAudio> +get (AudioFrame from, AudioFrame length) +{ + decoder->seek (ContentTime::from_frames (from, content->resampled_audio_frame_rate ()), true); + shared_ptr<ContentAudio> ca = decoder->get_audio (from, length, true); + BOOST_CHECK_EQUAL (ca->frame, from); + return ca; +} + +static void +check (AudioFrame from, AudioFrame length) +{ + shared_ptr<ContentAudio> ca = get (from, length); + for (int i = 0; i < content->audio_channels(); ++i) { + for (int j = 0; j < length; ++j) { + BOOST_CHECK_EQUAL (ca->audio->data(i)[j], j + from); + assert (ca->audio->data(i)[j] == j + from); + } + } +} + +/** Check the logic in AudioDecoder::get_audio */ +BOOST_AUTO_TEST_CASE (audio_decoder_get_audio_test) +{ + shared_ptr<Film> film = new_test_film ("audio_decoder_test"); + + content.reset (new TestAudioContent (film)); + decoder.reset (new TestAudioDecoder (content)); + + /* Simple reads */ + check (0, 48000); + check (44, 9123); + check (9991, 22); + + /* Read off the end */ + + AudioFrame const from = content->resampled_audio_frame_rate() * 61; + AudioFrame const length = content->resampled_audio_frame_rate() * 4; + shared_ptr<ContentAudio> ca = get (from, length); + + for (int i = 0; i < content->audio_channels(); ++i) { + for (int j = 0; j < ca->audio->frames(); ++j) { + BOOST_CHECK_EQUAL (ca->audio->data(i)[j], j + from); + assert (ca->audio->data(i)[j] == j + from); + } + } +} diff --git a/test/audio_delay_test.cc b/test/audio_delay_test.cc index 8ac5f746c..68e14ff3c 100644 --- a/test/audio_delay_test.cc +++ b/test/audio_delay_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,11 +17,18 @@ */ +/** @file test/audio_delay_test.cc + * @brief Test encode using some SndfileContents which have audio delays. + * + * The output is checked algorithmically using knowledge of the input. + */ + #include <boost/test/unit_test.hpp> -#include <libdcp/sound_frame.h> -#include <libdcp/cpl.h> -#include <libdcp/reel.h> -#include <libdcp/sound_asset.h> +#include <dcp/sound_frame.h> +#include <dcp/cpl.h> +#include <dcp/reel.h> +#include <dcp/sound_mxf.h> +#include <dcp/reel_sound_asset.h> #include "lib/sndfile_content.h" #include "lib/dcp_content_type.h" #include "lib/ratio.h" @@ -53,10 +60,10 @@ void test_audio_delay (int delay_in_ms) boost::filesystem::path path = "build/test"; path /= film_name; path /= film->dcp_name (); - libdcp::DCP check (path.string ()); + dcp::DCP check (path.string ()); check.read (); - shared_ptr<const libdcp::SoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); + shared_ptr<const dcp::ReelSoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); BOOST_CHECK (sound_asset); /* Sample index in the DCP */ @@ -66,11 +73,11 @@ void test_audio_delay (int delay_in_ms) /* Delay in frames */ int const delay_in_frames = delay_in_ms * 48000 / 1000; - while (n < sound_asset->intrinsic_duration()) { - shared_ptr<const libdcp::SoundFrame> sound_frame = sound_asset->get_frame (frame++); + while (n < sound_asset->mxf()->intrinsic_duration()) { + shared_ptr<const dcp::SoundFrame> sound_frame = sound_asset->mxf()->get_frame (frame++); uint8_t const * d = sound_frame->data (); - for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->channels())) { + for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->mxf()->channels())) { /* Mono input so it will appear on centre */ int const sample = d[i + 7] | (d[i + 8] << 8); @@ -86,7 +93,6 @@ void test_audio_delay (int delay_in_ms) } } - /* Test audio delay when specified in a piece of audio content */ BOOST_AUTO_TEST_CASE (audio_delay_test) { diff --git a/test/audio_mapping_test.cc b/test/audio_mapping_test.cc index bfb53b087..fc597b91d 100644 --- a/test/audio_mapping_test.cc +++ b/test/audio_mapping_test.cc @@ -17,13 +17,14 @@ */ +/** @file test/audio_mapping_test.cc + * @brief Basic tests of the AudioMapping class, which itself doesn't really do much. + */ + #include <boost/test/unit_test.hpp> #include "lib/audio_mapping.h" #include "lib/util.h" -/* Basic tests of the AudioMapping class, which itself - doesn't really do much. -*/ BOOST_AUTO_TEST_CASE (audio_mapping_test) { AudioMapping none; @@ -35,10 +36,10 @@ BOOST_AUTO_TEST_CASE (audio_mapping_test) for (int i = 0; i < 4; ++i) { for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) { - BOOST_CHECK_EQUAL (four.get (i, static_cast<libdcp::Channel> (j)), i == j ? 1 : 0); + BOOST_CHECK_EQUAL (four.get (i, static_cast<dcp::Channel> (j)), i == j ? 1 : 0); } } - four.set (0, libdcp::RIGHT, 1); - BOOST_CHECK_EQUAL (four.get (0, libdcp::RIGHT), 1); + four.set (0, dcp::RIGHT, 1); + BOOST_CHECK_EQUAL (four.get (0, dcp::RIGHT), 1); } diff --git a/test/audio_merger_test.cc b/test/audio_merger_test.cc deleted file mode 100644 index 31d055ab7..000000000 --- a/test/audio_merger_test.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* - Copyright (C) 2013 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 <boost/test/unit_test.hpp> -#include <boost/bind.hpp> -#include <boost/function.hpp> -#include <boost/signals2.hpp> -#include "lib/audio_merger.h" -#include "lib/audio_buffers.h" - -using boost::shared_ptr; -using boost::bind; - -static shared_ptr<const AudioBuffers> last_audio; - -static int -pass_through (int x) -{ - return x; -} - -BOOST_AUTO_TEST_CASE (audio_merger_test1) -{ - AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1)); - - /* Push 64 samples, 0 -> 63 at time 0 */ - shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64)); - for (int i = 0; i < 64; ++i) { - buffers->data()[0][i] = i; - } - merger.push (buffers, 0); - - /* Push 64 samples, 0 -> 63 at time 22 */ - merger.push (buffers, 22); - - TimedAudioBuffers<int> tb = merger.pull (22); - BOOST_CHECK (tb.audio != shared_ptr<const AudioBuffers> ()); - BOOST_CHECK_EQUAL (tb.audio->frames(), 22); - BOOST_CHECK_EQUAL (tb.time, 0); - - /* And they should be a staircase */ - for (int i = 0; i < 22; ++i) { - BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i); - } - - tb = merger.flush (); - - /* That flush should give us 64 samples at 22 */ - BOOST_CHECK_EQUAL (tb.audio->frames(), 64); - BOOST_CHECK_EQUAL (tb.time, 22); - - /* Check the sample values */ - for (int i = 0; i < 64; ++i) { - int correct = i; - if (i < (64 - 22)) { - correct += i + 22; - } - BOOST_CHECK_EQUAL (tb.audio->data()[0][i], correct); - } -} - -BOOST_AUTO_TEST_CASE (audio_merger_test2) -{ - AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1)); - - /* Push 64 samples, 0 -> 63 at time 9 */ - shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64)); - for (int i = 0; i < 64; ++i) { - buffers->data()[0][i] = i; - } - merger.push (buffers, 9); - - TimedAudioBuffers<int> tb = merger.pull (9); - BOOST_CHECK_EQUAL (tb.audio->frames(), 9); - BOOST_CHECK_EQUAL (tb.time, 0); - - for (int i = 0; i < 9; ++i) { - BOOST_CHECK_EQUAL (tb.audio->data()[0][i], 0); - } - - tb = merger.flush (); - - /* That flush should give us 64 samples at 9 */ - BOOST_CHECK_EQUAL (tb.audio->frames(), 64); - BOOST_CHECK_EQUAL (tb.time, 9); - - /* Check the sample values */ - for (int i = 0; i < 64; ++i) { - BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i); - } -} diff --git a/test/black_fill_test.cc b/test/black_fill_test.cc index 5c594f68c..148ec9738 100644 --- a/test/black_fill_test.cc +++ b/test/black_fill_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -25,7 +25,7 @@ #include "test.h" /** @file test/black_fill_test.cc - * @brief Test insertion of black frames between video content. + * @brief Test insertion of black frames between separate bits of video content. */ using boost::shared_ptr; @@ -46,10 +46,10 @@ BOOST_AUTO_TEST_CASE (black_fill_test) film->examine_and_add_content (contentB); wait_for_jobs (); - contentA->set_video_length (3); - contentA->set_position (film->video_frames_to_time (2)); - contentB->set_video_length (1); - contentB->set_position (film->video_frames_to_time (7)); + contentA->set_video_length (ContentTime::from_frames (3, 24)); + contentA->set_position (DCPTime::from_frames (2, film->video_frame_rate ())); + contentB->set_video_length (ContentTime::from_frames (1, 24)); + contentB->set_position (DCPTime::from_frames (7, film->video_frame_rate ())); film->make_dcp (); diff --git a/test/burnt_subtitle_test.cc b/test/burnt_subtitle_test.cc new file mode 100644 index 000000000..c5d6c4c14 --- /dev/null +++ b/test/burnt_subtitle_test.cc @@ -0,0 +1,49 @@ +/* + Copyright (C) 2014 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. + +*/ + +/** @file test/burnt_subtitle_test.cc + * @brief Test the burning of subtitles into the DCP. + */ + +#include <boost/test/unit_test.hpp> +#include "lib/subrip_content.h" +#include "lib/film.h" +#include "lib/ratio.h" +#include "lib/dcp_content_type.h" +#include "test.h" + +using std::cout; +using boost::shared_ptr; + +/** Build a small DCP with no picture and a single subtitle overlaid onto it */ +BOOST_AUTO_TEST_CASE (burnt_subtitle_test) +{ + shared_ptr<Film> film = new_test_film ("burnt_subtitle_test"); + film->set_container (Ratio::from_id ("185")); + film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR")); + film->set_name ("frobozz"); + film->set_with_subtitles (true); + shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip2.srt")); + film->examine_and_add_content (content); + wait_for_jobs (); + film->make_dcp (); + wait_for_jobs (); + + check_dcp ("test/data/burnt_subtitle_test", film->dir (film->dcp_name ())); +} diff --git a/test/client_server_test.cc b/test/client_server_test.cc index 07af1255c..51594a47a 100644 --- a/test/client_server_test.cc +++ b/test/client_server_test.cc @@ -17,6 +17,14 @@ */ +/** @file test/client_server_test.cc + * @brief Test the server class. + * + * Create a test image and then encode it using the standard mechanism + * and also using a Server object running on localhost. Compare the resulting + * encoded data to check that they are the same. + */ + #include <boost/test/unit_test.hpp> #include <boost/thread.hpp> #include "lib/server.h" @@ -39,12 +47,12 @@ do_remote_encode (shared_ptr<DCPVideoFrame> frame, ServerDescription description BOOST_CHECK (remotely_encoded); BOOST_CHECK_EQUAL (locally_encoded->size(), remotely_encoded->size()); - BOOST_CHECK (memcmp (locally_encoded->data(), remotely_encoded->data(), locally_encoded->size()) == 0); + BOOST_CHECK_EQUAL (memcmp (locally_encoded->data(), remotely_encoded->data(), locally_encoded->size()), 0); } BOOST_AUTO_TEST_CASE (client_server_test_rgb) { - shared_ptr<Image> image (new Image (PIX_FMT_RGB24, libdcp::Size (1998, 1080), true)); + shared_ptr<Image> image (new Image (PIX_FMT_RGB24, dcp::Size (1998, 1080), true)); uint8_t* p = image->data()[0]; for (int y = 0; y < 1080; ++y) { @@ -57,7 +65,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb) p += image->stride()[0]; } - shared_ptr<Image> sub_image (new Image (PIX_FMT_RGBA, libdcp::Size (100, 200), true)); + shared_ptr<Image> sub_image (new Image (PIX_FMT_RGBA, dcp::Size (100, 200), true)); p = sub_image->data()[0]; for (int y = 0; y < 200; ++y) { uint8_t* q = p; @@ -76,8 +84,8 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb) new PlayerVideoFrame ( shared_ptr<ImageProxy> (new RawImageProxy (image, log)), Crop (), - libdcp::Size (1998, 1080), - libdcp::Size (1998, 1080), + dcp::Size (1998, 1080), + dcp::Size (1998, 1080), Scaler::from_id ("bicubic"), EYES_BOTH, PART_WHOLE, @@ -85,7 +93,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb) ) ); - pvf->set_subtitle (sub_image, Position<int> (50, 60)); + pvf->set_subtitle (PositionImage (sub_image, Position<int> (50, 60))); shared_ptr<DCPVideoFrame> frame ( new DCPVideoFrame ( @@ -122,11 +130,13 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb) for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) { delete *i; } + + delete server; } BOOST_AUTO_TEST_CASE (client_server_test_yuv) { - shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, libdcp::Size (1998, 1080), true)); + shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, dcp::Size (1998, 1080), true)); uint8_t* p = image->data()[0]; for (int i = 0; i < image->components(); ++i) { @@ -136,7 +146,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv) } } - shared_ptr<Image> sub_image (new Image (PIX_FMT_RGBA, libdcp::Size (100, 200), true)); + shared_ptr<Image> sub_image (new Image (PIX_FMT_RGBA, dcp::Size (100, 200), true)); p = sub_image->data()[0]; for (int y = 0; y < 200; ++y) { uint8_t* q = p; @@ -155,8 +165,8 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv) new PlayerVideoFrame ( shared_ptr<ImageProxy> (new RawImageProxy (image, log)), Crop (), - libdcp::Size (1998, 1080), - libdcp::Size (1998, 1080), + dcp::Size (1998, 1080), + dcp::Size (1998, 1080), Scaler::from_id ("bicubic"), EYES_BOTH, PART_WHOLE, @@ -164,7 +174,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv) ) ); - pvf->set_subtitle (sub_image, Position<int> (50, 60)); + pvf->set_subtitle (PositionImage (sub_image, Position<int> (50, 60))); shared_ptr<DCPVideoFrame> frame ( new DCPVideoFrame ( @@ -201,5 +211,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv) for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) { delete *i; } + + delete server; } diff --git a/test/colour_conversion_test.cc b/test/colour_conversion_test.cc index f850847b8..7de169dd3 100644 --- a/test/colour_conversion_test.cc +++ b/test/colour_conversion_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,17 +17,20 @@ */ +/** @file test/colour_conversion_test.cc + * @brief Basic test of identifier() for ColourConversion (i.e. a hash of the numbers) + */ + #include <boost/test/unit_test.hpp> -#include <libdcp/colour_matrix.h> +#include <dcp/colour_matrix.h> #include "lib/colour_conversion.h" using std::cout; -/* Basic test of identifier() for ColourConversion (i.e. a hash of the numbers) */ BOOST_AUTO_TEST_CASE (colour_conversion_test) { - ColourConversion A (2.4, true, libdcp::colour_matrix::srgb_to_xyz, 2.6); - ColourConversion B (2.4, false, libdcp::colour_matrix::srgb_to_xyz, 2.6); + ColourConversion A (2.4, true, dcp::colour_matrix::srgb_to_xyz, 2.6); + ColourConversion B (2.4, false, dcp::colour_matrix::srgb_to_xyz, 2.6); BOOST_CHECK_EQUAL (A.identifier(), "1e720d2d99add654d7816f3b72da815e"); BOOST_CHECK_EQUAL (B.identifier(), "18751a247b22682b725bf9c4caf71522"); diff --git a/test/ffmpeg_audio_test.cc b/test/ffmpeg_audio_test.cc index 2e83d45c9..98efe4dd0 100644 --- a/test/ffmpeg_audio_test.cc +++ b/test/ffmpeg_audio_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,12 +17,17 @@ */ +/** @file test/ffmpeg_audio_test.cc + * @brief A simple test of reading audio from an FFmpeg file. + */ + #include <boost/test/unit_test.hpp> -#include <libdcp/cpl.h> -#include <libdcp/dcp.h> -#include <libdcp/sound_asset.h> -#include <libdcp/sound_frame.h> -#include <libdcp/reel.h> +#include <dcp/cpl.h> +#include <dcp/dcp.h> +#include <dcp/sound_mxf.h> +#include <dcp/sound_frame.h> +#include <dcp/reel_sound_asset.h> +#include <dcp/reel.h> #include "lib/sndfile_content.h" #include "lib/film.h" #include "lib/dcp_content_type.h" @@ -55,56 +60,56 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_test) boost::filesystem::path path = "build/test"; path /= "ffmpeg_audio_test"; path /= film->dcp_name (); - libdcp::DCP check (path.string ()); + dcp::DCP check (path.string ()); check.read (); - shared_ptr<const libdcp::SoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); + shared_ptr<const dcp::ReelSoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); BOOST_CHECK (sound_asset); - BOOST_CHECK (sound_asset->channels () == 6); + BOOST_CHECK_EQUAL (sound_asset->mxf()->channels (), 6); /* Sample index in the DCP */ int n = 0; /* DCP sound asset frame */ int frame = 0; - while (n < sound_asset->intrinsic_duration()) { - shared_ptr<const libdcp::SoundFrame> sound_frame = sound_asset->get_frame (frame++); + while (n < sound_asset->mxf()->intrinsic_duration()) { + shared_ptr<const dcp::SoundFrame> sound_frame = sound_asset->mxf()->get_frame (frame++); uint8_t const * d = sound_frame->data (); - for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->channels())) { + for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->mxf()->channels())) { - if (sound_asset->channels() > 0) { + if (sound_asset->mxf()->channels() > 0) { /* L should be silent */ int const sample = d[i + 0] | (d[i + 1] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 1) { + if (sound_asset->mxf()->channels() > 1) { /* R should be silent */ int const sample = d[i + 2] | (d[i + 3] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 2) { + if (sound_asset->mxf()->channels() > 2) { /* Mono input so it will appear on centre */ int const sample = d[i + 7] | (d[i + 8] << 8); BOOST_CHECK_EQUAL (sample, n); } - if (sound_asset->channels() > 3) { + if (sound_asset->mxf()->channels() > 3) { /* Lfe should be silent */ int const sample = d[i + 9] | (d[i + 10] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 4) { + if (sound_asset->mxf()->channels() > 4) { /* Ls should be silent */ int const sample = d[i + 11] | (d[i + 12] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 5) { + if (sound_asset->mxf()->channels() > 5) { /* Rs should be silent */ int const sample = d[i + 13] | (d[i + 14] << 8); BOOST_CHECK_EQUAL (sample, 0); diff --git a/test/ffmpeg_dcp_test.cc b/test/ffmpeg_dcp_test.cc index 4922ec4d4..234bf2c79 100644 --- a/test/ffmpeg_dcp_test.cc +++ b/test/ffmpeg_dcp_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 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 @@ -17,6 +17,12 @@ */ +/** @file test/ffmpeg_dcp_test.cc + * @brief Test creation of a very simple DCP from some FFmpegContent (data/test.mp4). + * + * Also a quick test of Film::have_dcp (). + */ + #include <boost/test/unit_test.hpp> #include <boost/filesystem.hpp> #include "lib/film.h" @@ -27,10 +33,6 @@ using boost::shared_ptr; -/** @file test/ffmpeg_dcp_test.cc - * @brief Test scaling and black-padding of images from a still-image source. - */ - BOOST_AUTO_TEST_CASE (ffmpeg_dcp_test) { shared_ptr<Film> film = new_test_film ("ffmpeg_dcp_test"); diff --git a/test/ffmpeg_decoder_seek_test.cc b/test/ffmpeg_decoder_seek_test.cc new file mode 100644 index 000000000..968c3bdf9 --- /dev/null +++ b/test/ffmpeg_decoder_seek_test.cc @@ -0,0 +1,94 @@ +/* + Copyright (C) 2014 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. + +*/ + +/** @file test/ffmpeg_decoder_seek_test.cc + * @brief Check that get_video() returns the frame indexes that we ask for + * for FFmpegDecoder. + * + * This doesn't check that the contents of those frames are right, which + * it probably should. + */ + +#include <vector> +#include <boost/test/unit_test.hpp> +#include <boost/filesystem.hpp> +#include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_decoder.h" +#include "lib/log.h" +#include "lib/film.h" +#include "test.h" + +using std::cerr; +using std::vector; +using std::list; +using boost::shared_ptr; +using boost::optional; + +static void +check (FFmpegDecoder& decoder, int frame) +{ + list<ContentVideo> v; + v = decoder.get_video (frame, true); + BOOST_CHECK (v.size() == 1); + BOOST_CHECK_EQUAL (v.front().frame, frame); +} + +static void +test (boost::filesystem::path file, vector<int> frames) +{ + boost::filesystem::path path = private_data / file; + if (!boost::filesystem::exists (path)) { + cerr << "Skipping test: " << path.string() << " not found.\n"; + return; + } + + shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string()); + shared_ptr<FFmpegContent> content (new FFmpegContent (film, path)); + film->examine_and_add_content (content); + wait_for_jobs (); + shared_ptr<Log> log (new NullLog); + FFmpegDecoder decoder (content, log); + + for (vector<int>::const_iterator i = frames.begin(); i != frames.end(); ++i) { + check (decoder, *i); + } +} + +BOOST_AUTO_TEST_CASE (ffmpeg_decoder_seek_test) +{ + vector<int> frames; + + frames.clear (); + frames.push_back (0); + frames.push_back (42); + frames.push_back (999); + frames.push_back (0); + + test ("boon_telly.mkv", frames); + test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", frames); + + frames.clear (); + frames.push_back (15); + frames.push_back (42); + frames.push_back (999); + frames.push_back (15); + + test ("prophet_clip.mkv", frames); +} + diff --git a/test/ffmpeg_decoder_sequential_test.cc b/test/ffmpeg_decoder_sequential_test.cc new file mode 100644 index 000000000..9a14c5adb --- /dev/null +++ b/test/ffmpeg_decoder_sequential_test.cc @@ -0,0 +1,83 @@ +/* + Copyright (C) 2014 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. + +*/ + +/** @file test/ffmpeg_decoder_sequential_test.cc + * @brief Check that the FFmpeg decoder produces sequential frames without gaps or dropped frames; + * (dropped frames being checked by assert() in VideoDecoder). Also that the decoder picks up frame rates correctly. + */ + +#include <boost/test/unit_test.hpp> +#include <boost/filesystem.hpp> +#include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_decoder.h" +#include "lib/log.h" +#include "lib/film.h" +#include "test.h" + +using std::cout; +using std::cerr; +using std::list; +using boost::shared_ptr; +using boost::optional; + +/** @param black Frame index of first frame in the video */ +static void +test (boost::filesystem::path file, float fps, int first) +{ + boost::filesystem::path path = private_data / file; + if (!boost::filesystem::exists (path)) { + cerr << "Skipping test: " << path.string() << " not found.\n"; + return; + } + + shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string()); + shared_ptr<FFmpegContent> content (new FFmpegContent (film, path)); + film->examine_and_add_content (content); + wait_for_jobs (); + shared_ptr<Log> log (new NullLog); + FFmpegDecoder decoder (content, log); + + BOOST_CHECK_CLOSE (decoder.video_content()->video_frame_rate(), fps, 0.01); + + VideoFrame const N = decoder.video_content()->video_length().frames (decoder.video_content()->video_frame_rate ()); +#ifdef DCPOMATIC_DEBUG + decoder.test_gaps = 0; +#endif + for (VideoFrame i = 0; i < N; ++i) { + list<ContentVideo> v; + v = decoder.get_video (i, true); + if (i < first) { + BOOST_CHECK (v.empty ()); + } else { + BOOST_CHECK (v.size() == 1); + BOOST_CHECK_EQUAL (v.front().frame, i); + } + } +#ifdef DCPOMATIC_DEBUG + BOOST_CHECK_EQUAL (decoder.test_gaps, 0); +#endif +} + +BOOST_AUTO_TEST_CASE (ffmpeg_decoder_sequential_test) +{ + test ("boon_telly.mkv", 29.97, 0); + test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", 24, 0); + test ("prophet_clip.mkv", 23.976, 12); +} + diff --git a/test/ffmpeg_examiner_test.cc b/test/ffmpeg_examiner_test.cc index a3b9bb4f6..26834aafc 100644 --- a/test/ffmpeg_examiner_test.cc +++ b/test/ffmpeg_examiner_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,9 +17,15 @@ */ +/** @file test/ffmpeg_examiner_test.cc + * @brief Check that the FFmpegExaminer can extract the first video and audio time + * correctly from data/count300bd24.m2ts. + */ + #include <boost/test/unit_test.hpp> #include "lib/ffmpeg_examiner.h" #include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_audio_stream.h" #include "test.h" using boost::shared_ptr; @@ -30,7 +36,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_examiner_test) shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd24.m2ts")); shared_ptr<FFmpegExaminer> examiner (new FFmpegExaminer (content)); - BOOST_CHECK_EQUAL (examiner->first_video().get(), 600); + BOOST_CHECK_EQUAL (examiner->first_video().get(), ContentTime::from_seconds (600)); BOOST_CHECK_EQUAL (examiner->audio_streams().size(), 1); - BOOST_CHECK_EQUAL (examiner->audio_streams()[0]->first_audio.get(), 600); + BOOST_CHECK_EQUAL (examiner->audio_streams()[0]->first_audio.get(), ContentTime::from_seconds (600)); } diff --git a/test/ffmpeg_pts_offset.cc b/test/ffmpeg_pts_offset_test.cc index 6caf0d07a..94e7223ab 100644 --- a/test/ffmpeg_pts_offset.cc +++ b/test/ffmpeg_pts_offset_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,10 +17,15 @@ */ +/** @file test/ffmpeg_pts_offset_test.cc + * @brief Check the computation of _pts_offset in FFmpegDecoder. + */ + #include <boost/test/unit_test.hpp> #include "lib/film.h" #include "lib/ffmpeg_decoder.h" #include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_audio_stream.h" #include "test.h" using boost::shared_ptr; @@ -34,48 +39,43 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test) { /* Sound == video so no offset required */ - content->_first_video = 0; - content->_audio_stream->first_audio = 0; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._pts_offset, 0); - BOOST_CHECK_EQUAL (decoder._pts_offset, 0); + content->_first_video = ContentTime (); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime ()); } { /* Common offset should be removed */ - content->_first_video = 600; - content->_audio_stream->first_audio = 600; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._pts_offset, -600); - BOOST_CHECK_EQUAL (decoder._pts_offset, -600); + content->_first_video = ContentTime::from_seconds (600); + content->_audio_stream->first_audio = ContentTime::from_seconds (600); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime::from_seconds (-600)); } { /* Video is on a frame boundary */ - content->_first_video = 1.0 / 24.0; - content->_audio_stream->first_audio = 0; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._pts_offset, 0); - BOOST_CHECK_EQUAL (decoder._pts_offset, 0); + content->_first_video = ContentTime::from_frames (1, 24); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime ()); } { /* Video is off a frame boundary */ double const frame = 1.0 / 24.0; - content->_first_video = frame + 0.0215; - content->_audio_stream->first_audio = 0; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_CLOSE (decoder._pts_offset, (frame - 0.0215), 0.00001); - BOOST_CHECK_CLOSE (decoder._pts_offset, (frame - 0.0215), 0.00001); + content->_first_video = ContentTime::from_seconds (frame + 0.0215); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215), 0.00001); } { /* Video is off a frame boundary and both have a common offset */ double const frame = 1.0 / 24.0; - content->_first_video = frame + 0.0215 + 4.1; - content->_audio_stream->first_audio = 4.1; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._pts_offset, (frame - 0.0215) - 4.1); - BOOST_CHECK_EQUAL (decoder._pts_offset, (frame - 0.0215) - 4.1); + content->_first_video = ContentTime::from_seconds (frame + 0.0215 + 4.1); + content->_audio_stream->first_audio = ContentTime::from_seconds (4.1); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215) - 4.1, 0.1); } } diff --git a/test/file_group_test.cc b/test/file_group_test.cc index 14c01a976..888834511 100644 --- a/test/file_group_test.cc +++ b/test/file_group_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,6 +17,10 @@ */ +/** @file test/file_group_test.cc + * @brief Check that FileGroup works. + */ + #include <stdint.h> #include <cstdio> #include <boost/test/unit_test.hpp> diff --git a/test/film_metadata_test.cc b/test/film_metadata_test.cc index 7440e4338..70f29b998 100644 --- a/test/film_metadata_test.cc +++ b/test/film_metadata_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,6 +17,10 @@ */ +/** @file test/film_metadata_test.cc + * @brief Test some basic reading/writing of film metadata. + */ + #include <sstream> #include <boost/test/unit_test.hpp> #include <boost/filesystem.hpp> @@ -33,13 +37,9 @@ using boost::shared_ptr; BOOST_AUTO_TEST_CASE (film_metadata_test) { - string const test_film = "build/test/film_metadata_test"; - - if (boost::filesystem::exists (test_film)) { - boost::filesystem::remove_all (test_film); - } + shared_ptr<Film> f = new_test_film ("film_metadata_test"); + boost::filesystem::path dir = test_film_dir ("film_metadata_test"); - shared_ptr<Film> f (new Film (test_film)); f->_isdcf_date = boost::gregorian::from_undelimited_string ("20130211"); BOOST_CHECK (f->container() == 0); BOOST_CHECK (f->dcp_content_type() == 0); @@ -52,9 +52,9 @@ BOOST_AUTO_TEST_CASE (film_metadata_test) list<string> ignore; ignore.push_back ("Key"); - check_xml ("test/data/metadata.xml.ref", test_film + "/metadata.xml", ignore); + check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore); - shared_ptr<Film> g (new Film (test_film)); + shared_ptr<Film> g (new Film (dir)); g->read_metadata (); BOOST_CHECK_EQUAL (g->name(), "fred"); @@ -62,5 +62,5 @@ BOOST_AUTO_TEST_CASE (film_metadata_test) BOOST_CHECK_EQUAL (g->container(), Ratio::from_id ("185")); g->write_metadata (); - check_xml ("test/data/metadata.xml.ref", test_film + "/metadata.xml", ignore); + check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore); } diff --git a/test/frame_rate_test.cc b/test/frame_rate_test.cc index 7e197dc03..e8ebcea3b 100644 --- a/test/frame_rate_test.cc +++ b/test/frame_rate_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 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 @@ -17,11 +17,17 @@ */ +/** @file test/frame_rate_test.cc + * @brief Tests for FrameRateChange and the computation of the best + * frame rate for the DCP. + */ + #include <boost/test/unit_test.hpp> #include "lib/film.h" #include "lib/config.h" #include "lib/ffmpeg_content.h" #include "lib/playlist.h" +#include "lib/ffmpeg_audio_stream.h" #include "lib/frame_rate_change.h" #include "test.h" @@ -53,6 +59,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, true); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 50; best = film->playlist()->best_dcp_frame_rate (); @@ -61,6 +68,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, true); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 48; best = film->playlist()->best_dcp_frame_rate (); @@ -69,6 +77,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, true); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 30; best = film->playlist()->best_dcp_frame_rate (); @@ -77,6 +86,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 29.97; best = film->playlist()->best_dcp_frame_rate (); @@ -85,6 +95,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 30 / 29.97, 0.1); content->_video_frame_rate = 25; best = film->playlist()->best_dcp_frame_rate (); @@ -93,6 +104,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 24; best = film->playlist()->best_dcp_frame_rate (); @@ -101,6 +113,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 14.5; best = film->playlist()->best_dcp_frame_rate (); @@ -109,6 +122,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 15 / 14.5, 0.1); content->_video_frame_rate = 12.6; best = film->playlist()->best_dcp_frame_rate (); @@ -117,6 +131,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 25 / 25.2, 0.1); content->_video_frame_rate = 12.4; best = film->playlist()->best_dcp_frame_rate (); @@ -125,6 +140,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 25 / 24.8, 0.1); content->_video_frame_rate = 12; best = film->playlist()->best_dcp_frame_rate (); @@ -133,6 +149,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); /* Now add some more rates and see if it will use them in preference to skip/repeat. @@ -150,6 +167,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 50; best = film->playlist()->best_dcp_frame_rate (); @@ -158,6 +176,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 48; best = film->playlist()->best_dcp_frame_rate (); @@ -166,6 +185,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); /* Check some out-there conversions (not the best) */ @@ -173,6 +193,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 24 / (2 * 14.99), 0.1); /* Check some conversions with limited DCP targets */ @@ -187,6 +208,7 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 24.0 / 25, 0.1); } /* Test Playlist::best_dcp_frame_rate and FrameRateChange @@ -233,43 +255,43 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test) content->_video_frame_rate = 24; film->set_video_frame_rate (24); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0))); - BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 48000); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 48000); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0))); - BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 48000); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 48000); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 80000, 0))); - BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 96000); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 96000); content->_video_frame_rate = 23.976; film->set_video_frame_rate (24); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0))); - BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 47952); content->_video_frame_rate = 29.97; film->set_video_frame_rate (30); BOOST_CHECK_EQUAL (film->video_frame_rate (), 30); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0))); - BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 47952); content->_video_frame_rate = 25; film->set_video_frame_rate (24); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0))); - BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 50000); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 50000); content->_video_frame_rate = 25; film->set_video_frame_rate (24); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0))); - BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 50000); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 50000); /* Check some out-there conversions (not the best) */ content->_video_frame_rate = 14.99; film->set_video_frame_rate (25); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 16000, 0))); - /* The FrameRateChange within output_audio_frame_rate should choose to double-up + /* The FrameRateChange within resampled_audio_frame_rate should choose to double-up the 14.99 fps video to 30 and then run it slow at 25. */ - BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25)); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25)); } diff --git a/test/image_test.cc b/test/image_test.cc index 51ad49ebf..ee4819d6b 100644 --- a/test/image_test.cc +++ b/test/image_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 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 @@ -17,18 +17,25 @@ */ +/** @file test/image_test.cc + * @brief Tests of the Image class. + * + * @see test/make_black_test.cc, test/pixel_formats_test.cc + */ + #include <boost/test/unit_test.hpp> #include <Magick++.h> #include "lib/image.h" #include "lib/scaler.h" using std::string; +using std::list; using std::cout; using boost::shared_ptr; BOOST_AUTO_TEST_CASE (aligned_image_test) { - Image* s = new Image (PIX_FMT_RGB24, libdcp::Size (50, 50), true); + Image* s = new Image (PIX_FMT_RGB24, dcp::Size (50, 50), true); BOOST_CHECK_EQUAL (s->components(), 1); /* 160 is 150 aligned to the nearest 32 bytes */ BOOST_CHECK_EQUAL (s->stride()[0], 160); @@ -50,12 +57,12 @@ BOOST_AUTO_TEST_CASE (aligned_image_test) BOOST_CHECK (t->data() != s->data()); BOOST_CHECK (t->data()[0] != s->data()[0]); BOOST_CHECK (t->line_size() != s->line_size()); - BOOST_CHECK (t->line_size()[0] == s->line_size()[0]); + BOOST_CHECK_EQUAL (t->line_size()[0], s->line_size()[0]); BOOST_CHECK (t->stride() != s->stride()); - BOOST_CHECK (t->stride()[0] == s->stride()[0]); + BOOST_CHECK_EQUAL (t->stride()[0], s->stride()[0]); /* assignment operator */ - Image* u = new Image (PIX_FMT_YUV422P, libdcp::Size (150, 150), false); + Image* u = new Image (PIX_FMT_YUV422P, dcp::Size (150, 150), false); *u = *s; BOOST_CHECK_EQUAL (u->components(), 1); BOOST_CHECK_EQUAL (u->stride()[0], 160); @@ -67,9 +74,9 @@ BOOST_AUTO_TEST_CASE (aligned_image_test) BOOST_CHECK (u->data() != s->data()); BOOST_CHECK (u->data()[0] != s->data()[0]); BOOST_CHECK (u->line_size() != s->line_size()); - BOOST_CHECK (u->line_size()[0] == s->line_size()[0]); + BOOST_CHECK_EQUAL (u->line_size()[0], s->line_size()[0]); BOOST_CHECK (u->stride() != s->stride()); - BOOST_CHECK (u->stride()[0] == s->stride()[0]); + BOOST_CHECK_EQUAL (u->stride()[0], s->stride()[0]); delete s; delete t; @@ -78,7 +85,7 @@ BOOST_AUTO_TEST_CASE (aligned_image_test) BOOST_AUTO_TEST_CASE (compact_image_test) { - Image* s = new Image (PIX_FMT_RGB24, libdcp::Size (50, 50), false); + Image* s = new Image (PIX_FMT_RGB24, dcp::Size (50, 50), false); BOOST_CHECK_EQUAL (s->components(), 1); BOOST_CHECK_EQUAL (s->stride()[0], 50 * 3); BOOST_CHECK_EQUAL (s->line_size()[0], 50 * 3); @@ -99,12 +106,12 @@ BOOST_AUTO_TEST_CASE (compact_image_test) BOOST_CHECK (t->data() != s->data()); BOOST_CHECK (t->data()[0] != s->data()[0]); BOOST_CHECK (t->line_size() != s->line_size()); - BOOST_CHECK (t->line_size()[0] == s->line_size()[0]); + BOOST_CHECK_EQUAL (t->line_size()[0], s->line_size()[0]); BOOST_CHECK (t->stride() != s->stride()); - BOOST_CHECK (t->stride()[0] == s->stride()[0]); + BOOST_CHECK_EQUAL (t->stride()[0], s->stride()[0]); /* assignment operator */ - Image* u = new Image (PIX_FMT_YUV422P, libdcp::Size (150, 150), true); + Image* u = new Image (PIX_FMT_YUV422P, dcp::Size (150, 150), true); *u = *s; BOOST_CHECK_EQUAL (u->components(), 1); BOOST_CHECK_EQUAL (u->stride()[0], 50 * 3); @@ -116,9 +123,9 @@ BOOST_AUTO_TEST_CASE (compact_image_test) BOOST_CHECK (u->data() != s->data()); BOOST_CHECK (u->data()[0] != s->data()[0]); BOOST_CHECK (u->line_size() != s->line_size()); - BOOST_CHECK (u->line_size()[0] == s->line_size()[0]); + BOOST_CHECK_EQUAL (u->line_size()[0], s->line_size()[0]); BOOST_CHECK (u->stride() != s->stride()); - BOOST_CHECK (u->stride()[0] == s->stride()[0]); + BOOST_CHECK_EQUAL (u->stride()[0], s->stride()[0]); delete s; delete t; @@ -128,7 +135,7 @@ BOOST_AUTO_TEST_CASE (compact_image_test) BOOST_AUTO_TEST_CASE (crop_image_test) { /* This was to check out a bug with valgrind, and is probably not very useful */ - shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, libdcp::Size (16, 16), true)); + shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, dcp::Size (16, 16), true)); image->make_black (); Crop crop; crop.top = 3; @@ -141,7 +148,7 @@ BOOST_AUTO_TEST_CASE (crop_image_test) BOOST_AUTO_TEST_CASE (crop_image_test2) { /* Here's a 1998 x 1080 image which is black */ - shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, libdcp::Size (1998, 1080), true)); + shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, dcp::Size (1998, 1080), true)); image->make_black (); /* Crop it by 1 pixel */ @@ -170,7 +177,7 @@ boost::shared_ptr<Image> read_file (string file) { Magick::Image magick_image (file.c_str ()); - libdcp::Size size (magick_image.columns(), magick_image.rows()); + dcp::Size size (magick_image.columns(), magick_image.rows()); boost::shared_ptr<Image> image (new Image (PIX_FMT_RGB24, size, true)); @@ -214,7 +221,7 @@ write_file (shared_ptr<Image> image, string file) static void -crop_scale_window_single (AVPixelFormat in_format, libdcp::Size in_size, Crop crop, libdcp::Size inter_size, libdcp::Size out_size) +crop_scale_window_single (AVPixelFormat in_format, dcp::Size in_size, Crop crop, dcp::Size inter_size, dcp::Size out_size) { /* Set up our test image */ shared_ptr<Image> test (new Image (in_format, in_size, true)); @@ -262,12 +269,134 @@ crop_scale_window_single (AVPixelFormat in_format, libdcp::Size in_size, Crop cr /** Test Image::crop_scale_window against separate calls to crop/scale/copy */ BOOST_AUTO_TEST_CASE (crop_scale_window_test) { - crop_scale_window_single (AV_PIX_FMT_YUV422P, libdcp::Size (640, 480), Crop (), libdcp::Size (640, 480), libdcp::Size (640, 480)); - crop_scale_window_single (AV_PIX_FMT_YUV422P, libdcp::Size (640, 480), Crop (2, 4, 6, 8), libdcp::Size (640, 480), libdcp::Size (640, 480)); - crop_scale_window_single (AV_PIX_FMT_YUV422P, libdcp::Size (640, 480), Crop (2, 4, 6, 8), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_YUV422P, libdcp::Size (640, 480), Crop (1, 4, 6, 8), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_YUV420P, libdcp::Size (640, 480), Crop (16, 16, 0, 0), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_YUV420P, libdcp::Size (640, 480), Crop (16, 3, 3, 0), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_RGB24, libdcp::Size (1000, 800), Crop (0, 0, 0, 0), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_RGB24, libdcp::Size (1000, 800), Crop (55, 0, 1, 9), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_YUV422P, dcp::Size (640, 480), Crop (), dcp::Size (640, 480), dcp::Size (640, 480)); + crop_scale_window_single (AV_PIX_FMT_YUV422P, dcp::Size (640, 480), Crop (2, 4, 6, 8), dcp::Size (640, 480), dcp::Size (640, 480)); + crop_scale_window_single (AV_PIX_FMT_YUV422P, dcp::Size (640, 480), Crop (2, 4, 6, 8), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_YUV422P, dcp::Size (640, 480), Crop (1, 4, 6, 8), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_YUV420P, dcp::Size (640, 480), Crop (16, 16, 0, 0), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_YUV420P, dcp::Size (640, 480), Crop (16, 3, 3, 0), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_RGB24, dcp::Size (1000, 800), Crop (0, 0, 0, 0), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_RGB24, dcp::Size (1000, 800), Crop (55, 0, 1, 9), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); +} + +/** Test Image::alpha_blend */ +BOOST_AUTO_TEST_CASE (alpha_blend_test) +{ + int const stride = 48 * 4; + + shared_ptr<Image> A (new Image (AV_PIX_FMT_RGBA, dcp::Size (48, 48), false)); + A->make_black (); + uint8_t* a = A->data()[0]; + + for (int y = 0; y < 48; ++y) { + uint8_t* p = a + y * stride; + for (int x = 0; x < 16; ++x) { + p[x * 4] = 255; + p[(x + 16) * 4 + 1] = 255; + p[(x + 32) * 4 + 2] = 255; + } + } + + shared_ptr<Image> B (new Image (AV_PIX_FMT_RGBA, dcp::Size (48, 48), true)); + B->make_transparent (); + uint8_t* b = B->data()[0]; + + for (int y = 32; y < 48; ++y) { + uint8_t* p = b + y * stride; + for (int x = 0; x < 48; ++x) { + p[x * 4] = 255; + p[x * 4 + 1] = 255; + p[x * 4 + 2] = 255; + p[x * 4 + 3] = 255; + } + } + + A->alpha_blend (B, Position<int> (0, 0)); + + for (int y = 0; y < 32; ++y) { + uint8_t* p = a + y * stride; + for (int x = 0; x < 16; ++x) { + BOOST_CHECK_EQUAL (p[x * 4], 255); + BOOST_CHECK_EQUAL (p[(x + 16) * 4 + 1], 255); + BOOST_CHECK_EQUAL (p[(x + 32) * 4 + 2], 255); + } + } + + for (int y = 32; y < 48; ++y) { + uint8_t* p = a + y * stride; + for (int x = 0; x < 48; ++x) { + BOOST_CHECK_EQUAL (p[x * 4], 255); + BOOST_CHECK_EQUAL (p[x * 4 + 1], 255); + BOOST_CHECK_EQUAL (p[x * 4 + 2], 255); + BOOST_CHECK_EQUAL (p[x * 4 + 3], 255); + } + } +} + +/** Test merge (list<PositionImage>) with a single image */ +BOOST_AUTO_TEST_CASE (merge_test1) +{ + int const stride = 48 * 4; + + shared_ptr<Image> A (new Image (AV_PIX_FMT_RGBA, dcp::Size (48, 48), false)); + A->make_transparent (); + uint8_t* a = A->data()[0]; + + for (int y = 0; y < 48; ++y) { + uint8_t* p = a + y * stride; + for (int x = 0; x < 16; ++x) { + /* red */ + p[x * 4] = 255; + /* opaque */ + p[x * 4 + 3] = 255; + } + } + + list<PositionImage> all; + all.push_back (PositionImage (A, Position<int> (0, 0))); + PositionImage merged = merge (all); + + BOOST_CHECK (merged.position == Position<int> (0, 0)); + BOOST_CHECK_EQUAL (memcmp (merged.image->data()[0], A->data()[0], stride * 48), 0); +} + +/** Test merge (list<PositionImage>) with two images */ +BOOST_AUTO_TEST_CASE (merge_test2) +{ + shared_ptr<Image> A (new Image (AV_PIX_FMT_RGBA, dcp::Size (48, 1), false)); + A->make_transparent (); + uint8_t* a = A->data()[0]; + for (int x = 0; x < 16; ++x) { + /* red */ + a[x * 4] = 255; + /* opaque */ + a[x * 4 + 3] = 255; + } + + shared_ptr<Image> B (new Image (AV_PIX_FMT_RGBA, dcp::Size (48, 1), false)); + B->make_transparent (); + uint8_t* b = B->data()[0]; + for (int x = 0; x < 16; ++x) { + /* blue */ + b[(x + 32) * 4 + 2] = 255; + /* opaque */ + b[(x + 32) * 4 + 3] = 255; + } + + list<PositionImage> all; + all.push_back (PositionImage (A, Position<int> (0, 0))); + all.push_back (PositionImage (B, Position<int> (0, 0))); + PositionImage merged = merge (all); + + BOOST_CHECK (merged.position == Position<int> (0, 0)); + + uint8_t* m = merged.image->data()[0]; + + for (int x = 0; x < 16; ++x) { + BOOST_CHECK_EQUAL (m[x * 4], 255); + BOOST_CHECK_EQUAL (m[x * 4 + 3], 255); + BOOST_CHECK_EQUAL (m[(x + 16) * 4 + 3], 0); + BOOST_CHECK_EQUAL (m[(x + 32) * 4 + 2], 255); + BOOST_CHECK_EQUAL (m[(x + 32) * 4 + 3], 255); + } } diff --git a/test/job_test.cc b/test/job_test.cc index 4d32b1e0c..2022a8dda 100644 --- a/test/job_test.cc +++ b/test/job_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 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 @@ -17,6 +17,10 @@ */ +/** @file test/job_test.cc + * @brief Basic tests of Job and JobManager. + */ + #include <boost/test/unit_test.hpp> #include "lib/job.h" #include "lib/job_manager.h" diff --git a/test/make_black_test.cc b/test/make_black_test.cc index 7c0f92142..0ae2fd137 100644 --- a/test/make_black_test.cc +++ b/test/make_black_test.cc @@ -17,8 +17,15 @@ */ +/** @file test/make_black_test.cc + * @brief Check that Image::make_black works, and doesn't use values which crash + * sws_scale(). + * + * @see test/image_test.cc + */ + #include <boost/test/unit_test.hpp> -#include <libdcp/util.h> +#include <dcp/util.h> extern "C" { #include <libavutil/pixfmt.h> } @@ -27,13 +34,10 @@ extern "C" { using std::list; -/* Check that Image::make_black works, and doesn't use values which crash - sws_scale(). -*/ BOOST_AUTO_TEST_CASE (make_black_test) { - libdcp::Size in_size (512, 512); - libdcp::Size out_size (1024, 1024); + dcp::Size in_size (512, 512); + dcp::Size out_size (1024, 1024); list<AVPixelFormat> pix_fmts; pix_fmts.push_back (AV_PIX_FMT_RGB24); diff --git a/test/pixel_formats_test.cc b/test/pixel_formats_test.cc index 1b720d9bf..68d225e6e 100644 --- a/test/pixel_formats_test.cc +++ b/test/pixel_formats_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,6 +17,13 @@ */ +/** @file src/pixel_formats_test.cc + * @brief Make sure that Image::lines() and Image::bytes_per_pixel() return the right + * things for various pixel formats. + * + * @see test/image_test.cc + */ + #include <boost/test/unit_test.hpp> #include <list> extern "C" { @@ -28,6 +35,9 @@ extern "C" { using std::list; using std::cout; +/** @struct Case + * @brief A test case for pixel_formats_test. + */ struct Case { Case (AVPixelFormat f, int c, int l0, int l1, int l2, float b0, float b1, float b2) diff --git a/test/player_test.cc b/test/player_test.cc new file mode 100644 index 000000000..d48060242 --- /dev/null +++ b/test/player_test.cc @@ -0,0 +1,104 @@ +/* + Copyright (C) 2014 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. + +*/ + +/** @file test/player_test.cc + * @brief Various tests of Player. + */ + +#include <iostream> +#include <boost/test/unit_test.hpp> +#include "lib/film.h" +#include "lib/ffmpeg_content.h" +#include "lib/dcp_content_type.h" +#include "lib/ratio.h" +#include "lib/audio_buffers.h" +#include "lib/player.h" +#include "test.h" + +using std::cout; +using std::list; +using boost::shared_ptr; + +/** Player::overlaps */ +BOOST_AUTO_TEST_CASE (player_overlaps_test) +{ + shared_ptr<Film> film = new_test_film ("player_overlaps_test"); + film->set_container (Ratio::from_id ("185")); + shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4")); + shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4")); + shared_ptr<FFmpegContent> C (new FFmpegContent (film, "test/data/test.mp4")); + + film->examine_and_add_content (A); + film->examine_and_add_content (B); + film->examine_and_add_content (C); + wait_for_jobs (); + + BOOST_CHECK_EQUAL (A->full_length(), DCPTime (280000)); + + A->set_position (DCPTime::from_seconds (0)); + B->set_position (DCPTime::from_seconds (10)); + C->set_position (DCPTime::from_seconds (20)); + + shared_ptr<Player> player = film->make_player (); + + list<shared_ptr<Piece> > o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (0), DCPTime::from_seconds (5)); + BOOST_CHECK_EQUAL (o.size(), 1); + BOOST_CHECK_EQUAL (o.front()->content, A); + + o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (5), DCPTime::from_seconds (8)); + BOOST_CHECK_EQUAL (o.size(), 0); + + o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (8), DCPTime::from_seconds (12)); + BOOST_CHECK_EQUAL (o.size(), 1); + BOOST_CHECK_EQUAL (o.front()->content, B); + + o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (2), DCPTime::from_seconds (12)); + BOOST_CHECK_EQUAL (o.size(), 2); + BOOST_CHECK_EQUAL (o.front()->content, A); + BOOST_CHECK_EQUAL (o.back()->content, B); + + o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (8), DCPTime::from_seconds (11)); + BOOST_CHECK_EQUAL (o.size(), 1); + BOOST_CHECK_EQUAL (o.front()->content, B); +} + +/** Check that the Player correctly generates silence when used with a silent FFmpegContent */ +BOOST_AUTO_TEST_CASE (player_silence_padding_test) +{ + shared_ptr<Film> film = new_test_film ("player_silence_padding_test"); + film->set_name ("player_silence_padding_test"); + shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4")); + film->set_container (Ratio::from_id ("185")); + film->set_audio_channels (6); + + film->examine_and_add_content (c); + wait_for_jobs (); + + shared_ptr<Player> player = film->make_player (); + shared_ptr<AudioBuffers> test = player->get_audio (DCPTime (0), DCPTime::from_seconds (1), true); + BOOST_CHECK_EQUAL (test->frames(), 48000); + BOOST_CHECK_EQUAL (test->channels(), film->audio_channels ()); + + for (int i = 0; i < test->frames(); ++i) { + for (int c = 0; c < test->channels(); ++c) { + BOOST_CHECK_EQUAL (test->data()[c][i], 0); + } + } +} + diff --git a/test/ratio_test.cc b/test/ratio_test.cc index f3cbb504f..84e80861b 100644 --- a/test/ratio_test.cc +++ b/test/ratio_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 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 @@ -17,63 +17,56 @@ */ +/** @file test/ratio_test.cc + * @brief Test Ratio and fit_ratio_within(). + */ + #include <iostream> #include <boost/test/unit_test.hpp> -#include <libdcp/util.h> +#include <dcp/util.h> #include "lib/ratio.h" #include "lib/util.h" using std::ostream; -namespace libdcp { - -ostream& -operator<< (ostream& s, libdcp::Size const & t) -{ - s << t.width << "x" << t.height; - return s; -} - -} - BOOST_AUTO_TEST_CASE (ratio_test) { Ratio::setup_ratios (); Ratio const * r = Ratio::from_id ("119"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1290, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1290, 1080)); r = Ratio::from_id ("133"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1440, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1440, 1080)); r = Ratio::from_id ("137"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1480, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1480, 1080)); r = Ratio::from_id ("138"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1485, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1485, 1080)); r = Ratio::from_id ("166"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1800, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1800, 1080)); r = Ratio::from_id ("178"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1920, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1920, 1080)); r = Ratio::from_id ("185"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1998, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1998, 1080)); r = Ratio::from_id ("239"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (2048, 858)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (2048, 858)); r = Ratio::from_id ("full-frame"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (2048, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (2048, 1080)); } diff --git a/test/recover_test.cc b/test/recover_test.cc index 284895e0a..c9a593241 100644 --- a/test/recover_test.cc +++ b/test/recover_test.cc @@ -17,8 +17,12 @@ */ +/** @file test/recover_test.cc + * @brief Test recovery of a DCP transcode after a crash. + */ + #include <boost/test/unit_test.hpp> -#include <libdcp/stereo_picture_asset.h> +#include <dcp/stereo_picture_mxf.h> #include "lib/film.h" #include "lib/dcp_content_type.h" #include "lib/image_content.h" @@ -30,12 +34,13 @@ using std::string; using boost::shared_ptr; static void -note (libdcp::NoteType, string n) +note (dcp::NoteType t, string n) { - cout << n << "\n"; + if (t == dcp::DCP_ERROR) { + cout << n << "\n"; + } } -/** Test recovery of a DCP transcode after a crash */ BOOST_AUTO_TEST_CASE (recover_test) { shared_ptr<Film> film = new_test_film ("recover_test"); @@ -52,20 +57,22 @@ BOOST_AUTO_TEST_CASE (recover_test) film->make_dcp (); wait_for_jobs (); + boost::filesystem::path const video = "build/test/recover_test/video/185_2K_e8efb95857b62aa6ff94e3d669e75776_24_bicubic_100000000_P_S_3D.mxf"; + boost::filesystem::copy_file ( - "build/test/recover_test/video/185_2K_58a090f8d70a2b410c534120d35e5256_24_bicubic_200000000_P_S_3D.mxf", + video, "build/test/recover_test/original.mxf" ); - boost::filesystem::resize_file ("build/test/recover_test/video/185_2K_58a090f8d70a2b410c534120d35e5256_24_bicubic_200000000_P_S_3D.mxf", 2 * 1024 * 1024); + boost::filesystem::resize_file (video, 2 * 1024 * 1024); film->make_dcp (); wait_for_jobs (); - shared_ptr<libdcp::StereoPictureAsset> A (new libdcp::StereoPictureAsset ("build/test/recover_test", "original.mxf")); - shared_ptr<libdcp::StereoPictureAsset> B (new libdcp::StereoPictureAsset ("build/test/recover_test/video", "185_2K_58a090f8d70a2b410c534120d35e5256_24_bicubic_200000000_P_S_3D.mxf")); + shared_ptr<dcp::StereoPictureMXF> A (new dcp::StereoPictureMXF ("build/test/recover_test/original.mxf")); + shared_ptr<dcp::StereoPictureMXF> B (new dcp::StereoPictureMXF (video)); - libdcp::EqualityOptions eq; + dcp::EqualityOptions eq; eq.mxf_names_can_differ = true; BOOST_CHECK (A->equals (B, eq, boost::bind (¬e, _1, _2))); } diff --git a/test/repeat_frame_test.cc b/test/repeat_frame_test.cc new file mode 100644 index 000000000..4f66420ea --- /dev/null +++ b/test/repeat_frame_test.cc @@ -0,0 +1,54 @@ +/* + Copyright (C) 2013-2014 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. + +*/ + +/** @file test/repeat_frame_test.cc + * @brief Test the repeat of frames by the player when putting a 24fps + * source into a 48fps DCP. + * + * @see test/skip_frame_test.cc + */ + +#include <boost/test/unit_test.hpp> +#include "test.h" +#include "lib/film.h" +#include "lib/ratio.h" +#include "lib/ffmpeg_content.h" +#include "lib/dcp_content_type.h" + +using boost::shared_ptr; + +BOOST_AUTO_TEST_CASE (repeat_frame_test) +{ + shared_ptr<Film> film = new_test_film ("repeat_frame_test"); + film->set_name ("repeat_frame_test"); + film->set_container (Ratio::from_id ("185")); + film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/red_24.mp4")); + c->set_scale (VideoContentScale (Ratio::from_id ("185"))); + film->examine_and_add_content (c); + + wait_for_jobs (); + + film->set_video_frame_rate (48); + film->make_dcp (); + wait_for_jobs (); + + check_dcp ("test/data/repeat_frame_test", film->dir (film->dcp_name ())); +} + diff --git a/test/resampler_test.cc b/test/resampler_test.cc index 9247159a7..ffd636ac8 100644 --- a/test/resampler_test.cc +++ b/test/resampler_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,6 +17,11 @@ */ +/** @file test/resampler_test.cc + * @brief Check that the timings that come back from the resampler correspond + * to the number of samples it generates. + */ + #include <boost/test/unit_test.hpp> #include "lib/audio_buffers.h" #include "lib/resampler.h" @@ -34,19 +39,16 @@ resampler_test_one (int from, int to) /* 3 hours */ int64_t const N = int64_t (from) * 60 * 60 * 3; - + + /* XXX: no longer checks anything */ for (int64_t i = 0; i < N; i += 1000) { shared_ptr<AudioBuffers> a (new AudioBuffers (1, 1000)); a->make_silent (); - pair<shared_ptr<const AudioBuffers>, AudioContent::Frame> r = resamp.run (a, i); - BOOST_CHECK_EQUAL (r.second, total_out); - total_out += r.first->frames (); + shared_ptr<const AudioBuffers> r = resamp.run (a); + total_out += r->frames (); } } -/** Check that the timings that come back from the resampler correspond - to the number of samples it generates. -*/ BOOST_AUTO_TEST_CASE (resampler_test) { resampler_test_one (44100, 48000); diff --git a/test/scaling_test.cc b/test/scaling_test.cc index cdf1653cd..441af6bf3 100644 --- a/test/scaling_test.cc +++ b/test/scaling_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,6 +17,10 @@ */ +/** @file test/scaling_test.cc + * @brief Test scaling and black-padding of images from a still-image source. + */ + #include <boost/test/unit_test.hpp> #include "lib/image_content.h" #include "lib/ratio.h" @@ -24,10 +28,6 @@ #include "lib/dcp_content_type.h" #include "test.h" -/** @file test/scaling_test.cc - * @brief Test scaling and black-padding of images from a still-image source. - */ - using std::string; using boost::shared_ptr; @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (scaling_test) wait_for_jobs (); - imc->set_video_length (1); + imc->set_video_length (ContentTime::from_frames (1, 24)); scaling_test_for (film, imc, "133", "185"); scaling_test_for (film, imc, "185", "185"); diff --git a/test/seek_zero_test.cc b/test/seek_zero_test.cc new file mode 100644 index 000000000..682fa9355 --- /dev/null +++ b/test/seek_zero_test.cc @@ -0,0 +1,66 @@ +/* + Copyright (C) 2013-2014 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. + +*/ + +/** @file test/seek_zero_test.cc + * @brief Test seek to zero with a raw FFmpegDecoder (without the player + * confusing things as it might in ffmpeg_seek_test). + */ + +#include <boost/test/unit_test.hpp> +#include "lib/film.h" +#include "lib/ffmpeg_content.h" +#include "lib/ratio.h" +#include "lib/dcp_content_type.h" +#include "lib/ffmpeg_decoder.h" +#include "lib/ffmpeg_audio_stream.h" +#include "lib/content_video.h" +#include "test.h" + +using std::cout; +using std::list; +using boost::shared_ptr; +using boost::dynamic_pointer_cast; +using boost::optional; + +BOOST_AUTO_TEST_CASE (seek_zero_test) +{ + shared_ptr<Film> film = new_test_film ("seek_zero_test"); + film->set_name ("seek_zero_test"); + film->set_container (Ratio::from_id ("185")); + film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd48.m2ts")); + content->set_scale (VideoContentScale (Ratio::from_id ("185"))); + film->examine_and_add_content (content); + wait_for_jobs (); + + /* Work out the first video frame index that we will be given, taking into account + * the difference between first video and first audio. + */ + ContentTime video_delay = content->first_video().get() - content->audio_stream()->first_audio.get(); + if (video_delay < ContentTime ()) { + video_delay = ContentTime (); + } + + VideoFrame const first_frame = video_delay.round_up (content->video_frame_rate ()).frames (content->video_frame_rate ()); + + FFmpegDecoder decoder (content, film->log()); + list<ContentVideo> a = decoder.get_video (first_frame, true); + BOOST_CHECK (a.size() == 1); + BOOST_CHECK_EQUAL (a.front().frame, first_frame); +} diff --git a/test/silence_padding_test.cc b/test/silence_padding_test.cc index f1136a3f1..d876a0228 100644 --- a/test/silence_padding_test.cc +++ b/test/silence_padding_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,12 +17,17 @@ */ +/** @file test/silence_padding_test.cc + * @brief Test the padding (with silence) of a mono source to a 6-channel DCP. + */ + #include <boost/test/unit_test.hpp> -#include <libdcp/cpl.h> -#include <libdcp/dcp.h> -#include <libdcp/sound_asset.h> -#include <libdcp/sound_frame.h> -#include <libdcp/reel.h> +#include <dcp/cpl.h> +#include <dcp/dcp.h> +#include <dcp/sound_mxf.h> +#include <dcp/sound_frame.h> +#include <dcp/reel.h> +#include <dcp/reel_sound_asset.h> #include "lib/sndfile_content.h" #include "lib/film.h" #include "lib/dcp_content_type.h" @@ -33,7 +38,8 @@ using std::string; using boost::lexical_cast; using boost::shared_ptr; -static void test_silence_padding (int channels) +static void +test_silence_padding (int channels) { string const film_name = "silence_padding_test_" + lexical_cast<string> (channels); shared_ptr<Film> film = new_test_film (film_name); @@ -52,56 +58,56 @@ static void test_silence_padding (int channels) boost::filesystem::path path = "build/test"; path /= film_name; path /= film->dcp_name (); - libdcp::DCP check (path.string ()); + dcp::DCP check (path.string ()); check.read (); - shared_ptr<const libdcp::SoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); + shared_ptr<const dcp::ReelSoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); BOOST_CHECK (sound_asset); - BOOST_CHECK (sound_asset->channels () == channels); + BOOST_CHECK_EQUAL (sound_asset->mxf()->channels (), channels); /* Sample index in the DCP */ int n = 0; /* DCP sound asset frame */ int frame = 0; - while (n < sound_asset->intrinsic_duration()) { - shared_ptr<const libdcp::SoundFrame> sound_frame = sound_asset->get_frame (frame++); + while (n < sound_asset->mxf()->intrinsic_duration()) { + shared_ptr<const dcp::SoundFrame> sound_frame = sound_asset->mxf()->get_frame (frame++); uint8_t const * d = sound_frame->data (); - for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->channels())) { + for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->mxf()->channels())) { - if (sound_asset->channels() > 0) { + if (sound_asset->mxf()->channels() > 0) { /* L should be silent */ int const sample = d[i + 0] | (d[i + 1] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 1) { + if (sound_asset->mxf()->channels() > 1) { /* R should be silent */ int const sample = d[i + 2] | (d[i + 3] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 2) { + if (sound_asset->mxf()->channels() > 2) { /* Mono input so it will appear on centre */ int const sample = d[i + 7] | (d[i + 8] << 8); BOOST_CHECK_EQUAL (sample, n); } - if (sound_asset->channels() > 3) { + if (sound_asset->mxf()->channels() > 3) { /* Lfe should be silent */ int const sample = d[i + 9] | (d[i + 10] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 4) { + if (sound_asset->mxf()->channels() > 4) { /* Ls should be silent */ int const sample = d[i + 11] | (d[i + 12] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 5) { + if (sound_asset->mxf()->channels() > 5) { /* Rs should be silent */ int const sample = d[i + 13] | (d[i + 14] << 8); BOOST_CHECK_EQUAL (sample, 0); diff --git a/test/skip_frame_test.cc b/test/skip_frame_test.cc new file mode 100644 index 000000000..a77d8459b --- /dev/null +++ b/test/skip_frame_test.cc @@ -0,0 +1,55 @@ +/* + Copyright (C) 2013-2014 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. + +*/ + +/** @file test/skip_frame_test.cc + * @brief Test the skip of frames by the player when putting a 48fps + * source into a 24fps DCP. + * + * @see test/repeat_frame_test.cc + */ + +#include <boost/test/unit_test.hpp> +#include "test.h" +#include "lib/film.h" +#include "lib/ratio.h" +#include "lib/ffmpeg_content.h" +#include "lib/dcp_content_type.h" + +using boost::shared_ptr; + +BOOST_AUTO_TEST_CASE (skip_frame_test) +{ + shared_ptr<Film> film = new_test_film ("skip_frame_test"); + film->set_name ("skip_frame_test"); + film->set_container (Ratio::from_id ("185")); + film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/count300bd48.m2ts")); + c->set_scale (VideoContentScale (Ratio::from_id ("185"))); + film->examine_and_add_content (c); + + wait_for_jobs (); + film->write_metadata (); + + film->set_video_frame_rate (24); + film->make_dcp (); + wait_for_jobs (); + + check_dcp ("test/data/skip_frame_test", film->dir (film->dcp_name ())); +} + diff --git a/test/stream_test.cc b/test/stream_test.cc index fed3ecabe..16ab83baf 100644 --- a/test/stream_test.cc +++ b/test/stream_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,10 +17,15 @@ */ +/** @test test/stream_test.cc + * @brief Some simple tests of FFmpegAudioStream. + */ + #include <boost/test/unit_test.hpp> #include <libxml++/libxml++.h> #include <libcxml/cxml.h> #include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_audio_stream.h" #include "lib/film.h" using std::pair; @@ -65,7 +70,7 @@ BOOST_AUTO_TEST_CASE (stream_test) map->add_child("DCP")->add_child_text ("2"); } - FFmpegAudioStream a (shared_ptr<cxml::Node> (new cxml::Node (root)), 5); + FFmpegAudioStream a (cxml::NodePtr (new cxml::Node (root)), 5); BOOST_CHECK_EQUAL (a.identifier(), "4"); BOOST_CHECK_EQUAL (a.frame_rate, 44100); @@ -73,11 +78,11 @@ BOOST_AUTO_TEST_CASE (stream_test) BOOST_CHECK_EQUAL (a.name, "hello there world"); BOOST_CHECK_EQUAL (a.mapping.content_channels(), 2); - BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::LEFT), 1); - BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::RIGHT), 0); - BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::CENTRE), 1); - BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::LEFT), 0); - BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::RIGHT), 1); - BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::CENTRE), 1); + BOOST_CHECK_EQUAL (a.mapping.get (0, dcp::LEFT), 1); + BOOST_CHECK_EQUAL (a.mapping.get (0, dcp::RIGHT), 0); + BOOST_CHECK_EQUAL (a.mapping.get (0, dcp::CENTRE), 1); + BOOST_CHECK_EQUAL (a.mapping.get (1, dcp::LEFT), 0); + BOOST_CHECK_EQUAL (a.mapping.get (1, dcp::RIGHT), 1); + BOOST_CHECK_EQUAL (a.mapping.get (1, dcp::CENTRE), 1); } diff --git a/test/subrip_test.cc b/test/subrip_test.cc new file mode 100644 index 000000000..adb548f0c --- /dev/null +++ b/test/subrip_test.cc @@ -0,0 +1,203 @@ +/* + Copyright (C) 2014 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. + +*/ + +/** @file test/subrip_test.cc + * @brief Various tests of the subrip code. + */ + +#include <boost/test/unit_test.hpp> +#include <dcp/subtitle_content.h> +#include "lib/subrip.h" +#include "lib/subrip_content.h" +#include "lib/subrip_decoder.h" +#include "lib/render_subtitles.h" +#include "test.h" + +using std::list; +using std::vector; +using std::string; +using boost::shared_ptr; +using boost::dynamic_pointer_cast; + +/** Test SubRip::convert_time */ +BOOST_AUTO_TEST_CASE (subrip_time_test) +{ + BOOST_CHECK_EQUAL (SubRip::convert_time ("00:03:10,500"), ContentTime::from_seconds ((3 * 60) + 10 + 0.5)); + BOOST_CHECK_EQUAL (SubRip::convert_time ("04:19:51,782"), ContentTime::from_seconds ((4 * 3600) + (19 * 60) + 51 + 0.782)); +} + +/** Test SubRip::convert_coordinate */ +BOOST_AUTO_TEST_CASE (subrip_coordinate_test) +{ + BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("foo:42"), 42); + BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("X1:999"), 999); +} + +/** Test SubRip::convert_content */ +BOOST_AUTO_TEST_CASE (subrip_content_test) +{ + list<string> c; + list<SubRipSubtitlePiece> p; + + c.push_back ("Hello world"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + c.clear (); + + c.push_back ("<b>Hello world</b>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().bold, true); + c.clear (); + + c.push_back ("<i>Hello world</i>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().italic, true); + c.clear (); + + c.push_back ("<u>Hello world</u>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().underline, true); + c.clear (); + + c.push_back ("{b}Hello world{/b}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().bold, true); + c.clear (); + + c.push_back ("{i}Hello world{/i}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().italic, true); + c.clear (); + + c.push_back ("{u}Hello world{/u}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().underline, true); + c.clear (); + + c.push_back ("<b>This is <i>nesting</i> of subtitles</b>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 3); + list<SubRipSubtitlePiece>::iterator i = p.begin (); + BOOST_CHECK_EQUAL (i->text, "This is "); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, false); + ++i; + BOOST_CHECK_EQUAL (i->text, "nesting"); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, true); + ++i; + BOOST_CHECK_EQUAL (i->text, " of subtitles"); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, false); + ++i; + c.clear (); +} + +/** Test parsing of full SubRip file content */ +BOOST_AUTO_TEST_CASE (subrip_parse_test) +{ + shared_ptr<Film> film = new_test_film ("subrip_parse_test"); + shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip.srt")); + content->examine (shared_ptr<Job> ()); + BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471)); + + SubRip s (content); + + vector<SubRipSubtitle>::const_iterator i = s._subtitles.begin(); + + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->period.from, ContentTime::from_seconds ((1 * 60) + 49.200)); + BOOST_CHECK_EQUAL (i->period.to, ContentTime::from_seconds ((1 * 60) + 52.351)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "This is a subtitle, and it goes over two lines."); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->period.from, ContentTime::from_seconds ((1 * 60) + 52.440)); + BOOST_CHECK_EQUAL (i->period.to, ContentTime::from_seconds ((1 * 60) + 54.351)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "We have emboldened this"); + BOOST_CHECK_EQUAL (i->pieces.front().bold, true); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->period.from, ContentTime::from_seconds ((1 * 60) + 54.440)); + BOOST_CHECK_EQUAL (i->period.to, ContentTime::from_seconds ((1 * 60) + 56.590)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "And italicised this."); + BOOST_CHECK_EQUAL (i->pieces.front().italic, true); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->period.from, ContentTime::from_seconds ((1 * 60) + 56.680)); + BOOST_CHECK_EQUAL (i->period.to, ContentTime::from_seconds ((1 * 60) + 58.955)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "Shall I compare thee to a summers' day?"); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->period.from, ContentTime::from_seconds ((2 * 60) + 0.840)); + BOOST_CHECK_EQUAL (i->period.to, ContentTime::from_seconds ((2 * 60) + 3.400)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "Is this a dagger I see before me?"); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->period.from, ContentTime::from_seconds ((3 * 60) + 54.560)); + BOOST_CHECK_EQUAL (i->period.to, ContentTime::from_seconds ((3 * 60) + 56.471)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "Hello world."); + + ++i; + BOOST_CHECK (i == s._subtitles.end ()); +} + +/** Test rendering of a SubRip subtitle */ +BOOST_AUTO_TEST_CASE (subrip_render_test) +{ + shared_ptr<Film> film = new_test_film ("subrip_render_test"); + shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip.srt")); + content->examine (shared_ptr<Job> ()); + BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471)); + + shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (content)); + list<shared_ptr<ContentTextSubtitle> > cts = decoder->get_text_subtitles ( + ContentTimePeriod ( + ContentTime::from_seconds (109), ContentTime::from_seconds (110) + ) + ); + BOOST_CHECK_EQUAL (cts.size(), 1); + + PositionImage image = render_subtitles (cts.front()->subs, dcp::Size (1998, 1080)); + write_image (image.image, "build/test/subrip_render_test.png"); + check_file ("build/test/subrip_render_test.png", "test/data/subrip_render_test.png"); +} diff --git a/test/test.cc b/test/test.cc index 0b87b8062..32f74a7d2 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 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 @@ -17,10 +17,15 @@ */ +/** @file test/test.cc + * @brief Overall test stuff and useful methods for tests. + */ + #include <vector> #include <list> +#include <Magick++.h> #include <libxml++/libxml++.h> -#include <libdcp/dcp.h> +#include <dcp/dcp.h> #include "lib/config.h" #include "lib/util.h" #include "lib/ui_signaller.h" @@ -29,6 +34,7 @@ #include "lib/job.h" #include "lib/cross.h" #include "lib/server_finder.h" +#include "lib/image.h" #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE dcpomatic_test #include <boost/test/unit_test.hpp> @@ -41,6 +47,8 @@ using std::cerr; using std::list; using boost::shared_ptr; +boost::filesystem::path private_data = boost::filesystem::path ("test") / boost::filesystem::path ("private"); + class TestUISignaller : public UISignaller { public: @@ -53,20 +61,26 @@ public: struct TestConfig { - TestConfig() + TestConfig () { - dcpomatic_setup(); + dcpomatic_setup (); Config::instance()->set_num_local_encoding_threads (1); Config::instance()->set_server_port_base (61920); Config::instance()->set_default_isdcf_metadata (ISDCFMetadata ()); Config::instance()->set_default_container (static_cast<Ratio*> (0)); Config::instance()->set_default_dcp_content_type (static_cast<DCPContentType*> (0)); + Config::instance()->set_default_audio_delay (0); ServerFinder::instance()->disable (); ui_signaller = new TestUISignaller (); } + + ~TestConfig () + { + JobManager::drop (); + } }; BOOST_GLOBAL_FIXTURE (TestConfig); @@ -98,8 +112,8 @@ 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 = fopen_boost (ref, "rb"); + BOOST_CHECK_EQUAL (N, boost::filesystem::file_size (check)); + FILE* ref_file = fopen (ref.c_str(), "rb"); BOOST_CHECK (ref_file); FILE* check_file = fopen_boost (check, "rb"); BOOST_CHECK (check_file); @@ -127,26 +141,26 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check) } static void -note (libdcp::NoteType t, string n) +note (dcp::NoteType t, string n) { - if (t == libdcp::ERROR) { + if (t == dcp::DCP_ERROR) { cerr << n << "\n"; } } void -check_dcp (string ref, string check) +check_dcp (boost::filesystem::path ref, boost::filesystem::path check) { - libdcp::DCP ref_dcp (ref); + dcp::DCP ref_dcp (ref); ref_dcp.read (); - libdcp::DCP check_dcp (check); + dcp::DCP check_dcp (check); check_dcp.read (); - libdcp::EqualityOptions options; + dcp::EqualityOptions options; options.max_mean_pixel_error = 5; options.max_std_dev_pixel_error = 5; options.max_audio_sample_error = 255; - options.cpl_names_can_differ = true; + options.cpl_annotation_texts_can_differ = true; options.mxf_names_can_differ = true; BOOST_CHECK (ref_dcp.equals (check_dcp, options, boost::bind (note, _1, _2))); @@ -218,10 +232,19 @@ wait_for_jobs () ui_signaller->ui_idle (); } if (jm->errors ()) { + int N = 0; for (list<shared_ptr<Job> >::iterator i = jm->_jobs.begin(); i != jm->_jobs.end(); ++i) { if ((*i)->finished_in_error ()) { - cerr << (*i)->error_summary () << "\n" - << (*i)->error_details () << "\n"; + ++N; + } + } + cerr << N << " errors.\n"; + + for (list<shared_ptr<Job> >::iterator i = jm->_jobs.begin(); i != jm->_jobs.end(); ++i) { + if ((*i)->finished_in_error ()) { + cerr << (*i)->name() << ":\n" + << "\tsummary: " << (*i)->error_summary () << "\n" + << "\tdetails: " << (*i)->error_details () << "\n"; } } } @@ -230,3 +253,12 @@ wait_for_jobs () ui_signaller->ui_idle (); } + +void +write_image (shared_ptr<const Image> image, boost::filesystem::path file) +{ + using namespace MagickCore; + + Magick::Image m (image->size().width, image->size().height, "ARGB", CharPixel, (void *) image->data()[0]); + m.write (file.string ()); +} diff --git a/test/test.h b/test/test.h index dd007e8c9..57ea32c57 100644 --- a/test/test.h +++ b/test/test.h @@ -20,10 +20,15 @@ #include <boost/filesystem.hpp> class Film; +class Image; + +extern boost::filesystem::path private_data; extern void wait_for_jobs (); extern boost::shared_ptr<Film> new_test_film (std::string); -extern void check_dcp (std::string, std::string); +extern void check_dcp (boost::filesystem::path, boost::filesystem::path); +extern void check_file (boost::filesystem::path ref, boost::filesystem::path check); extern void check_xml (boost::filesystem::path, boost::filesystem::path, std::list<std::string>); extern void check_file (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); diff --git a/test/threed_test.cc b/test/threed_test.cc index 8da9b46a8..5ad78103f 100644 --- a/test/threed_test.cc +++ b/test/threed_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 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 @@ -17,6 +17,10 @@ */ +/** @file test/threed_test.cc + * @brief Create a 3D DCP (without comparing the result to anything). + */ + #include <boost/test/unit_test.hpp> #include "test.h" #include "lib/film.h" diff --git a/test/util_test.cc b/test/util_test.cc index 750023d9f..5eb3e27f1 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 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 @@ -17,6 +17,10 @@ */ +/** @file test/util_test.cc + * @brief Test various utility methods. + */ + #include <boost/test/unit_test.hpp> #include "lib/util.h" #include "lib/exceptions.h" @@ -54,6 +58,24 @@ BOOST_AUTO_TEST_CASE (md5_digest_test) BOOST_CHECK_THROW (md5_digest (p, shared_ptr<Job> ()), std::runtime_error); } +/* Straightforward test of DCPTime::round_up */ +BOOST_AUTO_TEST_CASE (dcptime_round_up_test) +{ + BOOST_CHECK_EQUAL (DCPTime (0).round_up (DCPTime::HZ / 2), DCPTime (0)); + BOOST_CHECK_EQUAL (DCPTime (1).round_up (DCPTime::HZ / 2), DCPTime (2)); + BOOST_CHECK_EQUAL (DCPTime (2).round_up (DCPTime::HZ / 2), DCPTime (2)); + BOOST_CHECK_EQUAL (DCPTime (3).round_up (DCPTime::HZ / 2), DCPTime (4)); + + BOOST_CHECK_EQUAL (DCPTime (0).round_up (DCPTime::HZ / 42), DCPTime (0)); + BOOST_CHECK_EQUAL (DCPTime (1).round_up (DCPTime::HZ / 42), DCPTime (42)); + BOOST_CHECK_EQUAL (DCPTime (42).round_up (DCPTime::HZ / 42), DCPTime (42)); + BOOST_CHECK_EQUAL (DCPTime (43).round_up (DCPTime::HZ / 42), DCPTime (84)); + + /* Check that rounding up to non-integer frame rates works */ + BOOST_CHECK_EQUAL (DCPTime (45312).round_up (29.976), DCPTime (48045)); +} + + BOOST_AUTO_TEST_CASE (divide_with_round_test) { BOOST_CHECK_EQUAL (divide_with_round (0, 4), 0); diff --git a/test/wscript b/test/wscript index 09df14673..0ece839e6 100644 --- a/test/wscript +++ b/test/wscript @@ -10,23 +10,27 @@ def configure(conf): """, msg = 'Checking for boost unit testing library', lib = 'boost_unit_test_framework%s' % boost_test_suffix, uselib_store = 'BOOST_TEST') def build(bld): - obj = bld(features = 'cxx cxxprogram') + obj = bld(features='cxx cxxprogram') obj.name = 'unit-tests' obj.uselib = 'BOOST_TEST BOOST_THREAD DCP OPENJPEG AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML' obj.use = 'libdcpomatic' obj.source = """ 4k_test.cc audio_analysis_test.cc + audio_buffers_test.cc audio_delay_test.cc + audio_decoder_test.cc audio_mapping_test.cc - audio_merger_test.cc black_fill_test.cc + burnt_subtitle_test.cc client_server_test.cc colour_conversion_test.cc ffmpeg_audio_test.cc ffmpeg_dcp_test.cc + ffmpeg_decoder_seek_test.cc + ffmpeg_decoder_sequential_test.cc ffmpeg_examiner_test.cc - ffmpeg_pts_offset.cc + ffmpeg_pts_offset_test.cc file_group_test.cc film_metadata_test.cc frame_rate_test.cc @@ -34,14 +38,18 @@ def build(bld): isdcf_name_test.cc job_test.cc make_black_test.cc + player_test.cc pixel_formats_test.cc - play_test.cc ratio_test.cc + repeat_frame_test.cc recover_test.cc resampler_test.cc scaling_test.cc + seek_zero_test.cc silence_padding_test.cc + skip_frame_test.cc stream_test.cc + subrip_test.cc test.cc threed_test.cc util_test.cc @@ -49,3 +57,14 @@ def build(bld): obj.target = 'unit-tests' obj.install_path = '' + + obj = bld(features='cxx cxxprogram') + obj.name = 'long-unit-tests' + obj.uselib = 'BOOST_TEST DCP OPENJPEG AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML' + obj.use = 'libdcpomatic' + obj.source = """ + test.cc + """ + + obj.target = 'long-unit-tests' + obj.install_path = '' |
