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.
22 #include <boost/filesystem.hpp>
23 #include <boost/algorithm/string/predicate.hpp>
27 #include "job_manager.h"
29 #include "exceptions.h"
31 #include "delay_line.h"
32 #define BOOST_TEST_DYN_LINK
33 #define BOOST_TEST_MODULE dvdomatic_test
34 #include <boost/test/unit_test.hpp>
37 using namespace boost;
39 BOOST_AUTO_TEST_CASE (film_metadata_test)
43 string const test_film = "build/test/film";
45 if (boost::filesystem::exists (test_film)) {
46 boost::filesystem::remove_all (test_film);
49 BOOST_CHECK_THROW (new Film ("build/test/film", true), OpenFileError);
51 Film f (test_film, false);
52 BOOST_CHECK (f.format() == 0);
53 BOOST_CHECK (f.dcp_content_type() == 0);
54 BOOST_CHECK (f.filters ().empty());
57 BOOST_CHECK_THROW (f.set_content ("jim"), OpenFileError);
58 f.set_dcp_content_type (DCPContentType::from_pretty_name ("Short"));
59 f.set_format (Format::from_nickname ("Flat"));
63 f.set_bottom_crop (4);
64 vector<Filter const *> f_filters;
65 f_filters.push_back (Filter::from_id ("pphb"));
66 f_filters.push_back (Filter::from_id ("unsharp"));
67 f.set_filters (f_filters);
68 f.set_dcp_frames (42);
73 s << "diff -u test/metadata.ref " << test_film << "/metadata";
74 BOOST_CHECK_EQUAL (::system (s.str().c_str ()), 0);
76 Film g (test_film, true);
78 BOOST_CHECK_EQUAL (g.name(), "fred");
79 BOOST_CHECK_EQUAL (g.dcp_content_type(), DCPContentType::from_pretty_name ("Short"));
80 BOOST_CHECK_EQUAL (g.format(), Format::from_nickname ("Flat"));
81 BOOST_CHECK_EQUAL (g.left_crop(), 1);
82 BOOST_CHECK_EQUAL (g.right_crop(), 2);
83 BOOST_CHECK_EQUAL (g.top_crop(), 3);
84 BOOST_CHECK_EQUAL (g.bottom_crop(), 4);
85 vector<Filter const *> g_filters = g.filters ();
86 BOOST_CHECK_EQUAL (g_filters.size(), 2);
87 BOOST_CHECK_EQUAL (g_filters.front(), Filter::from_id ("pphb"));
88 BOOST_CHECK_EQUAL (g_filters.back(), Filter::from_id ("unsharp"));
89 BOOST_CHECK_EQUAL (g.dcp_frames(), 42);
90 BOOST_CHECK_EQUAL (g.dcp_ab(), true);
93 BOOST_CHECK_EQUAL (::system (s.str().c_str ()), 0);
96 BOOST_AUTO_TEST_CASE (format_test)
98 Format::setup_formats ();
100 Format const * f = Format::from_nickname ("Flat");
102 BOOST_CHECK_EQUAL (f->ratio_as_integer(), 185);
104 f = Format::from_nickname ("Scope");
106 BOOST_CHECK_EQUAL (f->ratio_as_integer(), 239);
109 BOOST_AUTO_TEST_CASE (util_test)
111 string t = "Hello this is a string \"with quotes\" and indeed without them";
112 vector<string> b = split_at_spaces_considering_quotes (t);
113 vector<string>::iterator i = b.begin ();
114 BOOST_CHECK_EQUAL (*i++, "Hello");
115 BOOST_CHECK_EQUAL (*i++, "this");
116 BOOST_CHECK_EQUAL (*i++, "is");
117 BOOST_CHECK_EQUAL (*i++, "a");
118 BOOST_CHECK_EQUAL (*i++, "string");
119 BOOST_CHECK_EQUAL (*i++, "with quotes");
120 BOOST_CHECK_EQUAL (*i++, "and");
121 BOOST_CHECK_EQUAL (*i++, "indeed");
122 BOOST_CHECK_EQUAL (*i++, "without");
123 BOOST_CHECK_EQUAL (*i++, "them");
126 BOOST_AUTO_TEST_CASE (dvd_test)
128 list<DVDTitle> const t = dvd_titles ("test/dvd");
129 BOOST_CHECK_EQUAL (t.size(), 3);
130 list<DVDTitle>::const_iterator i = t.begin ();
132 BOOST_CHECK_EQUAL (i->number, 1);
133 BOOST_CHECK_EQUAL (i->size, 0);
136 BOOST_CHECK_EQUAL (i->number, 2);
137 BOOST_CHECK_EQUAL (i->size, 14);
140 BOOST_CHECK_EQUAL (i->number, 3);
141 BOOST_CHECK_EQUAL (i->size, 7);
145 do_positive_delay_line_test (int delay_length, int block_length)
147 DelayLine d (delay_length);
148 uint8_t data[block_length];
155 for (int i = 0; i < 64; ++i) {
156 for (int j = 0; j < block_length; ++j) {
161 int const a = d.feed (data, block_length);
164 for (int j = 0; j < a; ++j) {
165 if (zeros < delay_length) {
166 BOOST_CHECK_EQUAL (data[j], 0);
169 BOOST_CHECK_EQUAL (data[j], out & 0xff);
175 BOOST_CHECK_EQUAL (returned, 64 * block_length);
179 do_negative_delay_line_test (int delay_length, int block_length)
181 DelayLine d (delay_length);
182 uint8_t data[block_length];
185 int out = -delay_length;
188 for (int i = 0; i < 256; ++i) {
189 for (int j = 0; j < block_length; ++j) {
194 int const a = d.feed (data, block_length);
197 for (int j = 0; j < a; ++j) {
198 BOOST_CHECK_EQUAL (data[j], out & 0xff);
203 uint8_t remainder[-delay_length];
204 d.get_remaining (remainder);
205 returned += -delay_length;
207 for (int i = 0; i < -delay_length; ++i) {
208 BOOST_CHECK_EQUAL (remainder[i], 0);
212 BOOST_CHECK_EQUAL (returned, 256 * block_length);
216 BOOST_AUTO_TEST_CASE (delay_line_test)
218 do_positive_delay_line_test (64, 128);
219 do_positive_delay_line_test (128, 64);
220 do_positive_delay_line_test (3, 512);
221 do_positive_delay_line_test (512, 3);
223 do_positive_delay_line_test (0, 64);
225 do_negative_delay_line_test (-64, 128);
226 do_negative_delay_line_test (-128, 64);
227 do_negative_delay_line_test (-3, 512);
228 do_negative_delay_line_test (-512, 3);