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"
30 #define BOOST_TEST_DYN_LINK
31 #define BOOST_TEST_MODULE dvdomatic_test
32 #include <boost/test/unit_test.hpp>
35 using namespace boost;
38 compare (string ref, string test, list<string> exclude)
40 ifstream r (ref.c_str ());
41 ifstream t (test.c_str ());
50 for (list<string>::iterator i = exclude.begin(); i != exclude.end(); ++i) {
51 if (rl.find (*i) != string::npos && tl.find (*i) != string::npos) {
56 if (!ex && rl != tl) {
57 cerr << "Fail:\n" << rl << "\n" << tl << "\n";
66 BOOST_AUTO_TEST_CASE (make_dcp_test)
70 string const dcp_name = "FOO-BAR-BAZ";
72 string const ref_film = "test/film";
73 string const ref_dcp = ref_film + "/" + dcp_name;
74 string const ref_pkl = ref_dcp + "/bdb4ae0a-0d09-4554-8557-0b4260f4c359_pkl.xml";
75 string const ref_cpl = ref_dcp + "/08dd6e45-83b5-41dc-9179-d7c59f597a12_cpl.xml";
76 string const test_film = "build/test/film";
77 string const test_dcp = test_film + "/" + dcp_name;
79 if (boost::filesystem::exists (test_film)) {
80 boost::filesystem::remove_all (test_film);
83 Film f (test_film, false);
85 boost::filesystem::copy_file ("test/zombie.mpeg", "build/test/film/zombie.mpeg");
86 f.set_content ("zombie.mpeg");
87 f.set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
89 BOOST_CHECK_EQUAL (f.audio_channels(), 2);
90 BOOST_CHECK_EQUAL (f.audio_sample_rate(), 48000);
91 BOOST_CHECK_EQUAL (audio_sample_format_to_string (f.audio_sample_format()), "S16");
93 f.set_format (Format::from_nickname ("Flat"));
97 while (JobManager::instance()->work_to_do ()) {
103 s << "diff -ur test/film/j2c " << test_film << "/j2c";
104 int const r = ::system (s.str().c_str ());
105 BOOST_CHECK_EQUAL (r, 0);
110 s << "diff -ur test/film/wavs " << test_film << "/wavs";
111 int const r = ::system (s.str().c_str ());
112 BOOST_CHECK_EQUAL (r, 0);
117 s << "diff -u test/film/metadata " << test_film << "/metadata";
118 int const r = ::system (s.str().c_str ());
119 BOOST_CHECK_EQUAL (r, 0);
122 /* Find the test pkl and cpl */
126 for (filesystem::directory_iterator i = filesystem::directory_iterator (test_dcp); i != filesystem::directory_iterator(); ++i) {
127 #if BOOST_FILESYSTEM_VERSION == 3
128 string const t = filesystem::path(*i).generic_string ();
130 string const t = i->string ();
132 if (algorithm::ends_with (t, "cpl.xml")) {
134 } else if (algorithm::ends_with (t, "pkl.xml")) {
140 list<string> exclude;
141 exclude.push_back ("urn:uuid");
142 exclude.push_back ("urn:uri");
143 exclude.push_back ("<IssueDate>");
144 exclude.push_back ("<LabelText>");
145 exclude.push_back ("<Hash>");
146 BOOST_CHECK_EQUAL (compare (ref_cpl, test_cpl, exclude), false);
150 list<string> exclude;
151 exclude.push_back ("urn:uuid");
152 exclude.push_back ("<IssueDate>");
153 exclude.push_back ("<Hash>");
154 BOOST_CHECK_EQUAL (compare (ref_pkl, test_pkl, exclude), false);