2 Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic 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 DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/content.h"
23 #include "lib/content_factory.h"
25 #include "lib/playlist.h"
27 #include <boost/test/unit_test.hpp>
30 using std::shared_ptr;
36 setup(vector<shared_ptr<Content>>& content, vector<dcpomatic::DCPTime>& positions, vector<dcpomatic::DCPTime>& lengths)
38 for (auto i = 0; i < 3; ++i) {
39 content.push_back(content_factory("test/data/flat_red.png")[0]);
42 auto film = new_test_film2("playlist_move_later_test", content);
44 for (auto i: content) {
45 positions.push_back(i->position());
48 for (auto i: content) {
49 lengths.push_back(i->length_after_trim(film));
56 BOOST_AUTO_TEST_CASE(playlist_move_later_test1)
58 vector<shared_ptr<Content>> content;
59 vector<dcpomatic::DCPTime> positions;
60 vector<dcpomatic::DCPTime> lengths;
61 auto film = setup(content, positions, lengths);
63 film->move_content_later(content[1]);
65 auto moved_content = film->content();
66 BOOST_REQUIRE_EQUAL(moved_content.size(), 3U);
68 BOOST_CHECK_EQUAL(moved_content[0], content[0]);
69 BOOST_CHECK_EQUAL(moved_content[1], content[2]);
70 BOOST_CHECK_EQUAL(moved_content[2], content[1]);
72 BOOST_CHECK(content[0]->position() == positions[0]);
73 BOOST_CHECK(content[1]->position() == positions[1] + lengths[2]);
74 BOOST_CHECK(content[2]->position() == positions[1]);
78 BOOST_AUTO_TEST_CASE(playlist_move_later_test2)
80 vector<shared_ptr<Content>> content;
81 vector<dcpomatic::DCPTime> positions;
82 vector<dcpomatic::DCPTime> lengths;
83 auto film = setup(content, positions, lengths);
85 film->move_content_later(content[0]);
87 auto moved_content = film->content();
88 BOOST_REQUIRE_EQUAL(moved_content.size(), 3U);
90 BOOST_CHECK_EQUAL(moved_content[0], content[1]);
91 BOOST_CHECK_EQUAL(moved_content[1], content[0]);
92 BOOST_CHECK_EQUAL(moved_content[2], content[2]);
94 BOOST_CHECK(content[0]->position() == positions[0] + lengths[1]);
95 BOOST_CHECK(content[1]->position() == positions[0]);
96 BOOST_CHECK(content[2]->position() == positions[2]);