Supporters update.
[dcpomatic.git] / test / playlist_test.cc
1 /*
2     Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "lib/content.h"
23 #include "lib/content_factory.h"
24 #include "lib/film.h"
25 #include "lib/playlist.h"
26 #include "test.h"
27 #include <boost/test/unit_test.hpp>
28
29
30 using std::shared_ptr;
31 using std::vector;
32
33
34 static
35 shared_ptr<Film>
36 setup(vector<shared_ptr<Content>>& content, vector<dcpomatic::DCPTime>& positions, vector<dcpomatic::DCPTime>& lengths)
37 {
38         for (auto i = 0; i < 3; ++i) {
39                 content.push_back(content_factory("test/data/flat_red.png")[0]);
40         }
41
42         auto film = new_test_film2("playlist_move_later_test", content);
43
44         for (auto i: content) {
45                 positions.push_back(i->position());
46         }
47
48         for (auto i: content) {
49                 lengths.push_back(i->length_after_trim(film));
50         }
51
52         return film;
53 }
54
55
56 BOOST_AUTO_TEST_CASE(playlist_move_later_test1)
57 {
58         vector<shared_ptr<Content>> content;
59         vector<dcpomatic::DCPTime> positions;
60         vector<dcpomatic::DCPTime> lengths;
61         auto film = setup(content, positions, lengths);
62
63         film->move_content_later(content[1]);
64
65         auto moved_content = film->content();
66         BOOST_REQUIRE_EQUAL(moved_content.size(), 3U);
67
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]);
71
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]);
75 }
76
77
78 BOOST_AUTO_TEST_CASE(playlist_move_later_test2)
79 {
80         vector<shared_ptr<Content>> content;
81         vector<dcpomatic::DCPTime> positions;
82         vector<dcpomatic::DCPTime> lengths;
83         auto film = setup(content, positions, lengths);
84
85         film->move_content_later(content[0]);
86
87         auto moved_content = film->content();
88         BOOST_REQUIRE_EQUAL(moved_content.size(), 3U);
89
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]);
93
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]);
97 }
98