Use ffmpeg calls for pixel parameters; add (and alter, hmm) tests to suit.
[dcpomatic.git] / test / film_metadata_test.cc
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 BOOST_AUTO_TEST_CASE (film_metadata_test)
21 {
22         string const test_film = "build/test/film_metadata_test";
23         
24         if (boost::filesystem::exists (test_film)) {
25                 boost::filesystem::remove_all (test_film);
26         }
27
28         BOOST_CHECK_THROW (new Film (test_film, true), OpenFileError);
29         
30         shared_ptr<Film> f (new Film (test_film, false));
31         f->_dci_date = boost::gregorian::from_undelimited_string ("20130211");
32         BOOST_CHECK (f->format() == 0);
33         BOOST_CHECK (f->dcp_content_type() == 0);
34         BOOST_CHECK (f->filters ().empty());
35
36         f->set_name ("fred");
37         BOOST_CHECK_THROW (f->set_content ("jim"), OpenFileError);
38         f->set_dcp_content_type (DCPContentType::from_pretty_name ("Short"));
39         f->set_format (Format::from_nickname ("Flat"));
40         f->set_left_crop (1);
41         f->set_right_crop (2);
42         f->set_top_crop (3);
43         f->set_bottom_crop (4);
44         vector<Filter const *> f_filters;
45         f_filters.push_back (Filter::from_id ("pphb"));
46         f_filters.push_back (Filter::from_id ("unsharp"));
47         f->set_filters (f_filters);
48         f->set_trim_start (42);
49         f->set_trim_end (99);
50         f->set_dcp_ab (true);
51         f->write_metadata ();
52
53         stringstream s;
54         s << "diff -u test/metadata.ref " << test_film << "/metadata";
55         BOOST_CHECK_EQUAL (::system (s.str().c_str ()), 0);
56
57         shared_ptr<Film> g (new Film (test_film, true));
58
59         BOOST_CHECK_EQUAL (g->name(), "fred");
60         BOOST_CHECK_EQUAL (g->dcp_content_type(), DCPContentType::from_pretty_name ("Short"));
61         BOOST_CHECK_EQUAL (g->format(), Format::from_nickname ("Flat"));
62         BOOST_CHECK_EQUAL (g->crop().left, 1);
63         BOOST_CHECK_EQUAL (g->crop().right, 2);
64         BOOST_CHECK_EQUAL (g->crop().top, 3);
65         BOOST_CHECK_EQUAL (g->crop().bottom, 4);
66         vector<Filter const *> g_filters = g->filters ();
67         BOOST_CHECK_EQUAL (g_filters.size(), 2);
68         BOOST_CHECK_EQUAL (g_filters.front(), Filter::from_id ("pphb"));
69         BOOST_CHECK_EQUAL (g_filters.back(), Filter::from_id ("unsharp"));
70         BOOST_CHECK_EQUAL (g->trim_start(), 42);
71         BOOST_CHECK_EQUAL (g->trim_end(), 99);
72         BOOST_CHECK_EQUAL (g->dcp_ab(), true);
73         
74         g->write_metadata ();
75         BOOST_CHECK_EQUAL (::system (s.str().c_str ()), 0);
76 }