2 Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
38 #include "reel_mono_picture_asset.h"
39 #include "reel_sound_asset.h"
41 #include <boost/filesystem.hpp>
42 #include <boost/test/unit_test.hpp>
45 using std::make_shared;
49 /* Read a DCP, change a few things and write it back */
50 BOOST_AUTO_TEST_CASE(read_change_write_test)
52 boost::filesystem::path path = "build/test/read_change_write_test";
53 boost::filesystem::remove_all(path);
54 boost::filesystem::create_directories(path);
55 auto in_picture = simple_picture(path, "1");
56 auto in_sound = simple_sound(path, "1", {}, "de-DE");
57 auto in_reel_picture = make_shared<dcp::ReelMonoPictureAsset>(in_picture, 0);
58 auto in_reel_sound = make_shared<dcp::ReelSoundAsset>(in_sound, 0);
59 auto in_reel = make_shared<dcp::Reel>(in_reel_picture, in_reel_sound);
60 auto in_cpl = make_shared<dcp::CPL>("Input CPL", dcp::ContentKind::FEATURE, dcp::Standard::SMPTE);
62 dcp::DCP in_dcp(path);
64 in_dcp.set_issuer("my great issuer");
65 in_dcp.set_creator("the creator");
68 dcp::DCP work_dcp(path);
70 auto add_picture = simple_picture(path, "2");
71 auto add_sound = simple_sound(path, "2", {}, "de-DE");
72 auto add_reel_picture = make_shared<dcp::ReelMonoPictureAsset>(add_picture, 0);
73 auto add_reel_sound = make_shared<dcp::ReelSoundAsset>(add_sound, 0);
74 auto add_reel = make_shared<dcp::Reel>(add_reel_picture, add_reel_sound);
75 auto add_cpl = make_shared<dcp::CPL>("Added CPL", dcp::ContentKind::FEATURE, dcp::Standard::SMPTE);
76 add_cpl->add(add_reel);
77 work_dcp.add(add_cpl);
80 auto id_in_xml = [](cxml::Document const& doc, string id) {
81 auto assets = doc.node_child("AssetList")->node_children("Asset");
82 return std::find_if(assets.begin(), assets.end(), [id](cxml::ConstNodePtr asset) {
83 return dcp::remove_urn_uuid(asset->string_child("Id")) == id;
87 cxml::Document check_pkl("PackingList");
88 check_pkl.read_file(find_file(path, "pkl_"));
90 BOOST_CHECK_EQUAL(check_pkl.string_child("Issuer"), "my great issuer");
91 BOOST_CHECK_EQUAL(check_pkl.string_child("Creator"), "the creator");
93 BOOST_CHECK(id_in_xml(check_pkl, in_picture->id()));
94 BOOST_CHECK(id_in_xml(check_pkl, in_sound->id()));
95 BOOST_CHECK(id_in_xml(check_pkl, in_cpl->id()));
96 BOOST_CHECK(id_in_xml(check_pkl, add_picture->id()));
97 BOOST_CHECK(id_in_xml(check_pkl, add_sound->id()));
98 BOOST_CHECK(id_in_xml(check_pkl, add_cpl->id()));
100 auto const pkl_id = dcp::remove_urn_uuid(check_pkl.string_child("Id"));
102 cxml::Document check_assetmap("AssetMap");
103 check_assetmap.read_file(path / "ASSETMAP.xml");
105 BOOST_CHECK_EQUAL(check_assetmap.string_child("Issuer"), "my great issuer");
106 BOOST_CHECK_EQUAL(check_assetmap.string_child("Creator"), "the creator");
108 BOOST_CHECK(id_in_xml(check_assetmap, pkl_id));
110 BOOST_CHECK(id_in_xml(check_assetmap, in_picture->id()));
111 BOOST_CHECK(id_in_xml(check_assetmap, in_sound->id()));
112 BOOST_CHECK(id_in_xml(check_assetmap, in_cpl->id()));
113 BOOST_CHECK(id_in_xml(check_assetmap, add_picture->id()));
114 BOOST_CHECK(id_in_xml(check_assetmap, add_sound->id()));
115 BOOST_CHECK(id_in_xml(check_assetmap, add_cpl->id()));