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"
29 #define BOOST_TEST_DYN_LINK
30 #define BOOST_TEST_MODULE libdcp_test
31 #include <boost/test/unit_test.hpp>
34 using namespace boost;
39 return "test/data/32x32_red_square.j2c";
45 return "test/data/1s_24-bit_48k_silence.wav";
49 BOOST_AUTO_TEST_CASE (dcp_test)
51 Kumu::libdcp_test = true;
53 libdcp::Metadata* t = libdcp::Metadata::instance ();
54 t->issuer = "OpenDCP 0.0.25";
55 t->creator = "OpenDCP 0.0.25";
56 t->company_name = "OpenDCP";
57 t->product_name = "OpenDCP";
58 t->product_version = "0.0.25";
59 t->issue_date = "2012-07-17T04:45:18+00:00";
60 filesystem::remove_all ("build/test/foo");
61 filesystem::create_directories ("build/test/foo");
62 libdcp::DCP d ("build/test/foo", "A Test DCP", libdcp::FEATURE, 24, 24);
64 d.add_picture_asset (sigc::ptr_fun (&j2c), 32, 32);
65 d.add_sound_asset (sigc::ptr_fun (&wav), 2);
70 BOOST_AUTO_TEST_CASE (error_test)
72 libdcp::DCP d ("build/test/bar", "A Test DCP", libdcp::TEST, 24, 24);
74 p.push_back ("frobozz");
75 BOOST_CHECK_THROW (d.add_picture_asset (p, 32, 32), libdcp::FileError);
76 BOOST_CHECK_THROW (d.add_sound_asset (p), libdcp::FileError);
79 BOOST_AUTO_TEST_CASE (read_dcp)
81 libdcp::DCP d ("test/ref/DCP");
83 BOOST_CHECK_EQUAL (d.name(), "A Test DCP");
84 BOOST_CHECK_EQUAL (d.content_kind(), libdcp::FEATURE);
85 BOOST_CHECK_EQUAL (d.frames_per_second(), 24);
86 BOOST_CHECK_EQUAL (d.length(), 24);
89 BOOST_AUTO_TEST_CASE (subtitles)
91 libdcp::SubtitleAsset subs ("test/ref", "subs.xml");
93 BOOST_CHECK_EQUAL (subs.language(), "French");
94 BOOST_CHECK_EQUAL (subs.fonts().size(), 1);
95 BOOST_CHECK_EQUAL (subs.fonts().front()->subtitles().size(), 4);
97 list<shared_ptr<libdcp::Subtitle> >::const_iterator i = subs.fonts().front()->subtitles().begin ();
99 BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 5, 198));
100 BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 7, 115));
101 BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
102 BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
103 BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "My jacket was Idi Amin's");
106 BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 7, 177));
107 BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 11, 31));
108 BOOST_CHECK_EQUAL ((*i)->texts().size(), 2);
109 BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 21);
110 BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "My corset was H.M. The Queen's");
111 BOOST_CHECK_EQUAL ((*i)->texts().back()->v_position(), 15);
112 BOOST_CHECK_EQUAL ((*i)->texts().back()->text(), "My large wonderbra");
115 BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 11, 94));
116 BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 13, 63));
117 BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
118 BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
119 BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "Once belonged to the Shah");
122 BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 13, 104));
123 BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 15, 177));
124 BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
125 BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
126 BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "And these are Roy Hattersley's jeans");
128 BOOST_CHECK_EQUAL (subs.subtitles_at (libdcp::Time (0, 0, 14, 042)).size(), 1);
129 BOOST_CHECK_EQUAL (subs.subtitles_at (libdcp::Time (0, 0, 14, 042)).front()->text(), "And these are Roy Hattersley's jeans");