summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-09 20:35:39 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-09 20:35:39 +0100
commit89115db77729a2c99f1a09ff6a461720e16f889e (patch)
treee528ec014b820d4e0efa28893dcee91cd76ee618 /test
parentf8ad440cf187c517b7800f3efdfc0954025c4422 (diff)
parentd2ff6a6b0256e256b6df416f280c846072f7682f (diff)
Merge master.
Diffstat (limited to 'test')
-rw-r--r--test/test.cc5
-rw-r--r--test/trimmer_test.cc110
-rw-r--r--test/wscript2
3 files changed, 114 insertions, 3 deletions
diff --git a/test/test.cc b/test/test.cc
index 4494540a2..d6c7842d7 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -42,6 +42,7 @@
#include "sndfile_decoder.h"
#include "dcp_content_type.h"
#include "ui_signaller.h"
+#include "ratio.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE dcpomatic_test
#include <boost/test/unit_test.hpp>
@@ -66,8 +67,8 @@ struct TestConfig
Config::instance()->set_servers (vector<ServerDescription*> ());
Config::instance()->set_server_port (61920);
Config::instance()->set_default_dci_metadata (DCIMetadata ());
- Config::instance()->set_default_container (0);
- Config::instance()->set_default_dcp_content_type (0);
+ Config::instance()->set_default_container (static_cast<Ratio*> (0));
+ Config::instance()->set_default_dcp_content_type (static_cast<DCPContentType*> (0));
ui_signaller = new UISignaller ();
}
diff --git a/test/trimmer_test.cc b/test/trimmer_test.cc
new file mode 100644
index 000000000..ad2f2f6f5
--- /dev/null
+++ b/test/trimmer_test.cc
@@ -0,0 +1,110 @@
+/*
+ Copyright (C) 2012 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.
+
+*/
+
+using boost::shared_ptr;
+
+shared_ptr<const Image> trimmer_test_last_video;
+int trimmer_test_video_frames = 0;
+shared_ptr<const AudioBuffers> trimmer_test_last_audio;
+
+void
+trimmer_test_video_helper (shared_ptr<const Image> image, bool, shared_ptr<Subtitle>)
+{
+ trimmer_test_last_video = image;
+ ++trimmer_test_video_frames;
+}
+
+void
+trimmer_test_audio_helper (shared_ptr<const AudioBuffers> audio)
+{
+ trimmer_test_last_audio = audio;
+}
+
+BOOST_AUTO_TEST_CASE (trimmer_passthrough_test)
+{
+ Trimmer trimmer (shared_ptr<Log> (), 0, 0, 200, 48000, 25, 25);
+ trimmer.Video.connect (bind (&trimmer_test_video_helper, _1, _2, _3));
+ trimmer.Audio.connect (bind (&trimmer_test_audio_helper, _1));
+
+ shared_ptr<SimpleImage> video (new SimpleImage (PIX_FMT_RGB24, libdcp::Size (1998, 1080), true));
+ shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 42 * 1920));
+
+ trimmer.process_video (video, false, shared_ptr<Subtitle> ());
+ trimmer.process_audio (audio);
+
+ BOOST_CHECK_EQUAL (video.get(), trimmer_test_last_video.get());
+ BOOST_CHECK_EQUAL (audio.get(), trimmer_test_last_audio.get());
+ BOOST_CHECK_EQUAL (audio->frames(), trimmer_test_last_audio->frames());
+}
+
+
+/** Test the audio handling of the Trimmer */
+BOOST_AUTO_TEST_CASE (trimmer_audio_test)
+{
+ Trimmer trimmer (shared_ptr<Log> (), 25, 75, 200, 48000, 25, 25);
+
+ trimmer.Audio.connect (bind (&trimmer_test_audio_helper, _1));
+
+ /* 21 video frames-worth of audio frames; should be completely stripped */
+ trimmer_test_last_audio.reset ();
+ shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 21 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last_audio == 0);
+
+ /* 42 more video frames-worth, 4 should be stripped from the start */
+ audio.reset (new AudioBuffers (6, 42 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last_audio);
+ BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 38 * 1920);
+
+ /* 42 more video frames-worth, should be kept as-is */
+ trimmer_test_last_audio.reset ();
+ audio.reset (new AudioBuffers (6, 42 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last_audio);
+ BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 42 * 1920);
+
+ /* 25 more video frames-worth, 5 should be trimmed from the end */
+ trimmer_test_last_audio.reset ();
+ audio.reset (new AudioBuffers (6, 25 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last_audio);
+ BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 20 * 1920);
+
+ /* Now some more; all should be trimmed */
+ trimmer_test_last_audio.reset ();
+ audio.reset (new AudioBuffers (6, 100 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last_audio == 0);
+}
+
+BOOST_AUTO_TEST_CASE (trim_end_test)
+{
+ Trimmer trimmer (shared_ptr<Log> (), 0, 75, 200, 48000, 25, 25);
+
+ shared_ptr<SimpleImage> image (new SimpleImage (PIX_FMT_RGB24, libdcp::Size (256, 256), true));
+
+ trimmer.Video.connect (bind (&trimmer_test_video_helper, _1, _2, _3));
+ trimmer_test_video_frames = 0;
+ for (int i = 0; i < 200; ++i) {
+ trimmer.process_video (image, false, shared_ptr<Subtitle> ());
+ }
+
+ BOOST_CHECK_EQUAL (trimmer_test_video_frames, 125);
+}
diff --git a/test/wscript b/test/wscript
index 2fbbdacbf..60d846aea 100644
--- a/test/wscript
+++ b/test/wscript
@@ -12,7 +12,7 @@ def configure(conf):
def build(bld):
obj = bld(features = 'cxx cxxprogram')
obj.name = 'unit-tests'
- obj.uselib = 'BOOST_TEST CXML DCP OPENJPEG AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC'
+ obj.uselib = 'BOOST_TEST DCP OPENJPEG AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML'
obj.use = 'libdcpomatic'
obj.source = 'test.cc'
obj.target = 'unit-tests'