summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-01-15 16:21:41 +0000
committerCarl Hetherington <cth@carlh.net>2014-01-15 16:21:41 +0000
commit86214f4619476b1a4951e15f002a93743b5f7a1e (patch)
treea827550b72a7409d280d21fc6e0a820c9f940fc2 /test
parenta890bedf688f0066d70dd5e9b07cbd86736cc0b1 (diff)
Basics of subtitle rendering.
Diffstat (limited to 'test')
-rw-r--r--test/subrip_test.cc36
-rw-r--r--test/test.cc13
-rw-r--r--test/test.h3
3 files changed, 50 insertions, 2 deletions
diff --git a/test/subrip_test.cc b/test/subrip_test.cc
index a66ee1afd..0dbf6d310 100644
--- a/test/subrip_test.cc
+++ b/test/subrip_test.cc
@@ -18,10 +18,15 @@
*/
#include <boost/test/unit_test.hpp>
+#include <libdcp/subtitle_asset.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;
@@ -121,7 +126,7 @@ BOOST_AUTO_TEST_CASE (subrip_parse_test)
SubRip s (content);
- list<SubRipSubtitle>::const_iterator i = s._subtitles.begin();
+ vector<SubRipSubtitle>::const_iterator i = s._subtitles.begin();
BOOST_CHECK (i != s._subtitles.end ());
BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 49.200) * TIME_HZ);
@@ -169,3 +174,32 @@ BOOST_AUTO_TEST_CASE (subrip_parse_test)
++i;
BOOST_CHECK (i == s._subtitles.end ());
}
+
+static list<libdcp::Subtitle> subtitles;
+
+static void
+process_subtitle (list<libdcp::Subtitle> s)
+{
+ subtitles = s;
+}
+
+
+/** Test rendering of a SubRip subtitle */
+BOOST_AUTO_TEST_CASE (subrip_render_test)
+{
+ shared_ptr<SubRipContent> content (new SubRipContent (shared_ptr<Film> (), "test/data/subrip.srt"));
+ content->examine (shared_ptr<Job> ());
+ BOOST_CHECK_EQUAL (content->full_length(), ((3 * 60) + 56.471) * TIME_HZ);
+
+ shared_ptr<Film> film = new_test_film ("subrip_render_test");
+
+ shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (film, content));
+ decoder->TextSubtitle.connect (boost::bind (&process_subtitle, _1));
+ decoder->pass ();
+
+ shared_ptr<Image> image;
+ Position<int> position;
+ render_subtitles (subtitles, libdcp::Size (1998, 1080), image, position);
+ write_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 22dea1fc4..e76c98d8b 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -19,6 +19,7 @@
#include <vector>
#include <list>
+#include <Magick++.h>
#include <libxml++/libxml++.h>
#include <libdcp/dcp.h>
#include "lib/config.h"
@@ -29,6 +30,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>
@@ -94,7 +96,7 @@ new_test_film (string name)
return f;
}
-static void
+void
check_file (string ref, string check)
{
uintmax_t N = boost::filesystem::file_size (ref);
@@ -230,3 +232,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 e49dfc276..8b302b119 100644
--- a/test/test.h
+++ b/test/test.h
@@ -20,9 +20,12 @@
#include <boost/filesystem.hpp>
class Film;
+class Image;
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_file (std::string ref, std::string check);
extern void check_xml (boost::filesystem::path, boost::filesystem::path, std::list<std::string>);
extern boost::filesystem::path test_film_dir (std::string);
+extern void write_image (boost::shared_ptr<const Image> image, boost::filesystem::path file);