2 Copyright (C) 2013-2019 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.
35 #include "local_time.h"
36 #include <boost/test/unit_test.hpp>
43 /** Test dcp::base64_decode */
44 BOOST_AUTO_TEST_CASE (base64_decode_test)
48 ifstream f ("test/data/base64_test");
49 BOOST_CHECK (f.good ());
57 ifstream g ("test/ref/base64_test_decoded", std::ios::binary);
58 BOOST_CHECK (g.good ());
59 unsigned char ref_decoded[N];
60 for (int i = 0; i < N; ++i) {
63 ref_decoded[i] = static_cast<unsigned char> (c);
66 unsigned char decoded[N];
67 int const r = dcp::base64_decode (s, decoded, N);
68 BOOST_CHECK_EQUAL (r, N);
70 for (int i = 0; i < N; ++i) {
71 BOOST_CHECK_EQUAL (decoded[i], ref_decoded[i]);
75 /** Test dcp::content_kind_from_string */
76 BOOST_AUTO_TEST_CASE (content_kind_test)
78 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("feature"), dcp::ContentKind::FEATURE);
79 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("Feature"), dcp::ContentKind::FEATURE);
80 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("FeaturE"), dcp::ContentKind::FEATURE);
81 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("Short"), dcp::ContentKind::SHORT);
82 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("trailer"), dcp::ContentKind::TRAILER);
83 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("test"), dcp::ContentKind::TEST);
84 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("transitional"), dcp::ContentKind::TRANSITIONAL);
85 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("rating"), dcp::ContentKind::RATING);
86 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("teaser"), dcp::ContentKind::TEASER);
87 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("policy"), dcp::ContentKind::POLICY);
88 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("psa"), dcp::ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT);
89 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("advertisement"), dcp::ContentKind::ADVERTISEMENT);
92 /** Test dcp::relative_to_root */
93 BOOST_AUTO_TEST_CASE (relative_to_root_test)
96 boost::filesystem::path root = "a";
99 boost::filesystem::path file = "a";
103 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
105 BOOST_CHECK_EQUAL (rel.get(), boost::filesystem::path ("c"));
109 boost::filesystem::path root = "a";
113 boost::filesystem::path file = "a";
116 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
121 boost::filesystem::path root = "a";
123 boost::filesystem::path file = "a";
127 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
130 boost::filesystem::path check = "b";
132 BOOST_CHECK_EQUAL (rel.get(), check);
136 /** Test private_key_fingerprint() */
137 BOOST_AUTO_TEST_CASE (private_key_fingerprint_test)
139 BOOST_CHECK_EQUAL (dcp::private_key_fingerprint (dcp::file_to_string ("test/data/private.key")), "Jdz1bFpCcKI7R16Ccx9JHYytag0=");
142 BOOST_AUTO_TEST_CASE (day_less_than_or_equal_test)
146 dcp::LocalTime a ("1978-04-05T00:00:00");
147 dcp::LocalTime b ("1978-04-05T00:00:00");
148 BOOST_CHECK (day_less_than_or_equal(a, b));
152 /* every part of a less than b */
153 dcp::LocalTime a ("1981-02-04T00:00:00");
154 dcp::LocalTime b ("1985-05-23T00:00:00");
155 BOOST_CHECK (day_less_than_or_equal(a, b));
159 /* years equal, other parts less */
160 dcp::LocalTime a ("1981-03-02T00:00:00");
161 dcp::LocalTime b ("1981-05-10T00:00:00");
162 BOOST_CHECK (day_less_than_or_equal(a, b));
166 /* year and month equal, day less */
167 dcp::LocalTime a ("1981-03-09T00:00:00");
168 dcp::LocalTime b ("1981-03-12T00:00:00");
169 BOOST_CHECK (day_less_than_or_equal(a, b));
173 /* a one day later than b */
174 dcp::LocalTime a ("1981-03-05T00:00:00");
175 dcp::LocalTime b ("1981-03-04T00:00:00");
176 BOOST_CHECK (!day_less_than_or_equal(a, b));
180 /* year and month same, day much later */
181 dcp::LocalTime a ("1981-03-22T00:00:00");
182 dcp::LocalTime b ("1981-03-04T00:00:00");
183 BOOST_CHECK (!day_less_than_or_equal(a, b));
187 /* year same, month and day later */
188 dcp::LocalTime a ("1981-06-22T00:00:00");
189 dcp::LocalTime b ("1981-02-04T00:00:00");
190 BOOST_CHECK (!day_less_than_or_equal(a, b));
195 dcp::LocalTime a ("1999-06-22T00:00:00");
196 dcp::LocalTime b ("1981-02-04T00:00:00");
197 BOOST_CHECK (!day_less_than_or_equal(a, b));
201 BOOST_AUTO_TEST_CASE (day_greater_than_or_equal_test)
205 dcp::LocalTime a ("1978-04-05T00:00:00");
206 dcp::LocalTime b ("1978-04-05T00:00:00");
207 BOOST_CHECK (day_greater_than_or_equal(a, b));
211 /* every part of a less than b */
212 dcp::LocalTime a ("1981-03-04T00:00:00");
213 dcp::LocalTime b ("1985-05-23T00:00:00");
214 BOOST_CHECK (!day_greater_than_or_equal(a, b));
218 /* years equal, other parts less */
219 dcp::LocalTime a ("1981-02-05T00:00:00");
220 dcp::LocalTime b ("1981-05-10T00:00:00");
221 BOOST_CHECK (!day_greater_than_or_equal(a, b));
225 /* year and month equal, day less */
226 dcp::LocalTime a ("1981-03-04T00:00:00");
227 dcp::LocalTime b ("1981-03-12T00:00:00");
228 BOOST_CHECK (!day_greater_than_or_equal(a, b));
232 /* year and month equal, day less */
233 dcp::LocalTime a ("1981-03-01T00:00:00");
234 dcp::LocalTime b ("1981-03-04T00:00:00");
235 BOOST_CHECK (!day_greater_than_or_equal(a, b));
239 /* a one day later than b */
240 dcp::LocalTime a ("1981-03-05T00:00:00");
241 dcp::LocalTime b ("1981-03-04T00:00:00");
242 BOOST_CHECK (day_greater_than_or_equal(a, b));
246 /* year and month same, day much later */
247 dcp::LocalTime a ("1981-03-22T00:00:00");
248 dcp::LocalTime b ("1981-03-04T00:00:00");
249 BOOST_CHECK (day_greater_than_or_equal(a, b));
253 /* year same, month and day later */
254 dcp::LocalTime a ("1981-05-22T00:00:00");
255 dcp::LocalTime b ("1981-02-04T00:00:00");
256 BOOST_CHECK (day_greater_than_or_equal(a, b));
261 dcp::LocalTime a ("1999-06-22T00:00:00");
262 dcp::LocalTime b ("1981-02-04T00:00:00");
263 BOOST_CHECK (day_greater_than_or_equal(a, b));
267 BOOST_AUTO_TEST_CASE (unique_string_test)
269 vector<string> existing;
270 for (int i = 0; i < 16; i++) {
272 BOOST_CHECK_NO_THROW (s = dcp::unique_string(existing, "foo"));
273 BOOST_CHECK (find(existing.begin(), existing.end(), s) == existing.end());
274 existing.push_back (s);