2 Copyright (C) 2015-2017 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/>.
21 /** @file test/dcpomatic_time_test.cc
22 * @brief Test Time and TimePeriod classes.
23 * @ingroup selfcontained
26 #include "lib/dcpomatic_time.h"
27 #include <boost/test/unit_test.hpp>
32 BOOST_AUTO_TEST_CASE (dcpomatic_time_test)
34 FrameRateChange frc (24, 48);
37 for (int64_t i = 0; i < 62000; i += 2000) {
39 ContentTime c (d, frc);
40 BOOST_CHECK_EQUAL (c.frames_floor (24.0), j);
49 BOOST_AUTO_TEST_CASE (dcpomatic_time_period_overlaps_test)
51 /* Taking times as the start of a sampling interval
53 |--|--|--|--|--|--|--|--|--|--|
55 |--|--|--|--|--|--|--|--|--|--|
57 <------a----><----b----->
59 and saying `from' is the start of the first sampling
60 interval and `to' is the start of the interval after
61 the period... a and b do not overlap.
64 TimePeriod<DCPTime> a (DCPTime (0), DCPTime (4));
65 TimePeriod<DCPTime> b (DCPTime (4), DCPTime (8));
66 BOOST_CHECK (!a.overlap (b));
68 /* Some more obvious non-overlaps */
69 a = TimePeriod<DCPTime> (DCPTime (0), DCPTime (4));
70 b = TimePeriod<DCPTime> (DCPTime (5), DCPTime (8));
71 BOOST_CHECK (!a.overlap (b));
74 a = TimePeriod<DCPTime> (DCPTime (0), DCPTime (4));
75 b = TimePeriod<DCPTime> (DCPTime (3), DCPTime (8));
76 BOOST_CHECK (a.overlap(b));
77 BOOST_CHECK (a.overlap(b).get() == DCPTimePeriod(DCPTime(3), DCPTime(4)));
78 a = TimePeriod<DCPTime> (DCPTime (1), DCPTime (9));
79 b = TimePeriod<DCPTime> (DCPTime (0), DCPTime (10));
80 BOOST_CHECK (a.overlap(b));
81 BOOST_CHECK (a.overlap(b).get() == DCPTimePeriod(DCPTime(1), DCPTime(9)));
84 BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test1)
86 DCPTimePeriod A (DCPTime (0), DCPTime (106));
87 list<DCPTimePeriod> B;
88 B.push_back (DCPTimePeriod (DCPTime (0), DCPTime (42)));
89 B.push_back (DCPTimePeriod (DCPTime (52), DCPTime (91)));
90 B.push_back (DCPTimePeriod (DCPTime (94), DCPTime (106)));
91 list<DCPTimePeriod> r = subtract (A, B);
92 list<DCPTimePeriod>::const_iterator i = r.begin ();
93 BOOST_REQUIRE (i != r.end ());
94 BOOST_CHECK (i->from == DCPTime (42));
95 BOOST_CHECK (i->to == DCPTime (52));
97 BOOST_REQUIRE (i != r.end ());
98 BOOST_CHECK (i->from == DCPTime (91));
99 BOOST_CHECK (i->to == DCPTime (94));
101 BOOST_REQUIRE (i == r.end ());
104 BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test2)
106 DCPTimePeriod A (DCPTime (0), DCPTime (106));
107 list<DCPTimePeriod> B;
108 B.push_back (DCPTimePeriod (DCPTime (14), DCPTime (42)));
109 B.push_back (DCPTimePeriod (DCPTime (52), DCPTime (91)));
110 B.push_back (DCPTimePeriod (DCPTime (94), DCPTime (106)));
111 list<DCPTimePeriod> r = subtract (A, B);
112 list<DCPTimePeriod>::const_iterator i = r.begin ();
113 BOOST_REQUIRE (i != r.end ());
114 BOOST_CHECK (i->from == DCPTime (0));
115 BOOST_CHECK (i->to == DCPTime (14));
117 BOOST_REQUIRE (i != r.end ());
118 BOOST_CHECK (i->from == DCPTime (42));
119 BOOST_CHECK (i->to == DCPTime (52));
121 BOOST_REQUIRE (i != r.end ());
122 BOOST_CHECK (i->from == DCPTime (91));
123 BOOST_CHECK (i->to == DCPTime (94));
125 BOOST_REQUIRE (i == r.end ());
128 BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test3)
130 DCPTimePeriod A (DCPTime (0), DCPTime (106));
131 list<DCPTimePeriod> B;
132 B.push_back (DCPTimePeriod (DCPTime (14), DCPTime (42)));
133 B.push_back (DCPTimePeriod (DCPTime (52), DCPTime (91)));
134 B.push_back (DCPTimePeriod (DCPTime (94), DCPTime (99)));
135 list<DCPTimePeriod> r = subtract (A, B);
136 list<DCPTimePeriod>::const_iterator i = r.begin ();
137 BOOST_REQUIRE (i != r.end ());
138 BOOST_CHECK (i->from == DCPTime (0));
139 BOOST_CHECK (i->to == DCPTime (14));
141 BOOST_REQUIRE (i != r.end ());
142 BOOST_CHECK (i->from == DCPTime (42));
143 BOOST_CHECK (i->to == DCPTime (52));
145 BOOST_REQUIRE (i != r.end ());
146 BOOST_CHECK (i->from == DCPTime (91));
147 BOOST_CHECK (i->to == DCPTime (94));
149 BOOST_REQUIRE (i != r.end ());
150 BOOST_CHECK (i->from == DCPTime (99));
151 BOOST_CHECK (i->to == DCPTime (106));
153 BOOST_REQUIRE (i == r.end ());
156 BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test4)
158 DCPTimePeriod A (DCPTime (0), DCPTime (106));
159 list<DCPTimePeriod> B;
160 list<DCPTimePeriod> r = subtract (A, B);
161 list<DCPTimePeriod>::const_iterator i = r.begin ();
162 BOOST_REQUIRE (i != r.end ());
163 BOOST_CHECK (i->from == DCPTime (0));
164 BOOST_CHECK (i->to == DCPTime (106));
166 BOOST_REQUIRE (i == r.end ());
169 BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test5)
171 DCPTimePeriod A (DCPTime (0), DCPTime (106));
172 list<DCPTimePeriod> B;
173 B.push_back (DCPTimePeriod (DCPTime (14), DCPTime (42)));
174 B.push_back (DCPTimePeriod (DCPTime (42), DCPTime (91)));
175 B.push_back (DCPTimePeriod (DCPTime (94), DCPTime (99)));
176 list<DCPTimePeriod> r = subtract (A, B);
177 list<DCPTimePeriod>::const_iterator i = r.begin ();
178 BOOST_REQUIRE (i != r.end ());
179 BOOST_CHECK (i->from == DCPTime (0));
180 BOOST_CHECK (i->to == DCPTime (14));
182 BOOST_REQUIRE (i != r.end ());
183 BOOST_CHECK (i->from ==DCPTime (91));
184 BOOST_CHECK (i->to == DCPTime (94));
186 BOOST_REQUIRE (i != r.end ());
187 BOOST_CHECK (i->from == DCPTime (99));
188 BOOST_CHECK (i->to == DCPTime (106));
190 BOOST_REQUIRE (i == r.end ());
193 BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test6)
195 DCPTimePeriod A (DCPTime (0), DCPTime (106));
196 list<DCPTimePeriod> B;
197 B.push_back (DCPTimePeriod (DCPTime (0), DCPTime (42)));
198 B.push_back (DCPTimePeriod (DCPTime (42), DCPTime (91)));
199 B.push_back (DCPTimePeriod (DCPTime (91), DCPTime (106)));
200 list<DCPTimePeriod> r = subtract (A, B);
201 BOOST_CHECK (r.empty());
204 BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test7)
206 DCPTimePeriod A (DCPTime (228), DCPTime (356));
207 list<DCPTimePeriod> B;
208 B.push_back (DCPTimePeriod (DCPTime (34), DCPTime (162)));
209 list<DCPTimePeriod> r = subtract (A, B);
210 list<DCPTimePeriod>::const_iterator i = r.begin ();
211 BOOST_REQUIRE (i != r.end ());
212 BOOST_CHECK (i->from == DCPTime (228));
213 BOOST_CHECK (i->to == DCPTime (356));
215 BOOST_REQUIRE (i == r.end ());