2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/filesystem.hpp>
26 #include "exceptions.h"
27 #include "subtitle_asset.h"
28 #include "picture_asset.h"
29 #include "sound_asset.h"
32 #define BOOST_TEST_DYN_LINK
33 #define BOOST_TEST_MODULE libdcp_test
34 #include <boost/test/unit_test.hpp>
37 using namespace boost;
42 return "test/data/32x32_red_square.j2c";
48 return "test/data/1s_24-bit_48k_silence.wav";
52 BOOST_AUTO_TEST_CASE (dcp_test)
54 Kumu::libdcp_test = true;
56 libdcp::Metadata* t = libdcp::Metadata::instance ();
57 t->issuer = "OpenDCP 0.0.25";
58 t->creator = "OpenDCP 0.0.25";
59 t->company_name = "OpenDCP";
60 t->product_name = "OpenDCP";
61 t->product_version = "0.0.25";
62 t->issue_date = "2012-07-17T04:45:18+00:00";
63 filesystem::remove_all ("build/test/foo");
64 filesystem::create_directories ("build/test/foo");
65 libdcp::DCP d ("build/test/foo", "A Test DCP", libdcp::FEATURE, 24, 24);
67 shared_ptr<libdcp::PictureAsset> mp (new libdcp::PictureAsset (
78 shared_ptr<libdcp::SoundAsset> ms (new libdcp::SoundAsset (
88 d.add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (mp, ms, shared_ptr<libdcp::SubtitleAsset> ())));
93 BOOST_AUTO_TEST_CASE (error_test)
95 libdcp::DCP d ("build/test/bar", "A Test DCP", libdcp::TEST, 24, 24);
97 p.push_back ("frobozz");
99 BOOST_CHECK_THROW (new libdcp::PictureAsset (p, "build/test/bar", "video.mxf", &d.Progress, 24, 24, 32, 32), libdcp::FileError);
100 BOOST_CHECK_THROW (new libdcp::SoundAsset (p, "build/test/bar", "audio.mxf", &d.Progress, 24, 24), libdcp::FileError);
103 BOOST_AUTO_TEST_CASE (read_dcp)
105 libdcp::DCP d ("test/ref/DCP");
107 BOOST_CHECK_EQUAL (d.name(), "A Test DCP");
108 BOOST_CHECK_EQUAL (d.content_kind(), libdcp::FEATURE);
109 BOOST_CHECK_EQUAL (d.frames_per_second(), 24);
110 BOOST_CHECK_EQUAL (d.length(), 24);
113 BOOST_AUTO_TEST_CASE (subtitles)
115 libdcp::SubtitleAsset subs ("test/ref", "subs.xml");
117 BOOST_CHECK_EQUAL (subs.language(), "French");
118 BOOST_CHECK_EQUAL (subs.fonts().size(), 1);
119 BOOST_CHECK_EQUAL (subs.fonts().front()->subtitles().size(), 4);
121 list<shared_ptr<libdcp::Subtitle> >::const_iterator i = subs.fonts().front()->subtitles().begin ();
123 BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 5, 198));
124 BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 7, 115));
125 BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
126 BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
127 BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "My jacket was Idi Amin's");
130 BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 7, 177));
131 BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 11, 31));
132 BOOST_CHECK_EQUAL ((*i)->texts().size(), 2);
133 BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 21);
134 BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "My corset was H.M. The Queen's");
135 BOOST_CHECK_EQUAL ((*i)->texts().back()->v_position(), 15);
136 BOOST_CHECK_EQUAL ((*i)->texts().back()->text(), "My large wonderbra");
139 BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 11, 94));
140 BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 13, 63));
141 BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
142 BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
143 BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "Once belonged to the Shah");
146 BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 13, 104));
147 BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 15, 177));
148 BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
149 BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
150 BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "And these are Roy Hattersley's jeans");
152 BOOST_CHECK_EQUAL (subs.subtitles_at (libdcp::Time (0, 0, 14, 042)).size(), 1);
153 BOOST_CHECK_EQUAL (subs.subtitles_at (libdcp::Time (0, 0, 14, 042)).front()->text(), "And these are Roy Hattersley's jeans");
156 BOOST_AUTO_TEST_CASE (dcp_time)
158 libdcp::Time t (977143, 24);
160 BOOST_CHECK_EQUAL (t.t, 73);
161 BOOST_CHECK_EQUAL (t.s, 34);
162 BOOST_CHECK_EQUAL (t.m, 18);
163 BOOST_CHECK_EQUAL (t.h, 11);