Fix crashes when using templates in some cases (#2491).
[dcpomatic.git] / test / kdm_util_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/kdm_util.h"
23 #include <dcp/certificate.h>
24 #include <dcp/util.h>
25 #include <boost/test/unit_test.hpp>
26
27
28 BOOST_AUTO_TEST_CASE(check_kdm_and_certificate_validity_periods_good)
29 {
30         auto const result = check_kdm_and_certificate_validity_periods(
31                 dcp::Certificate(dcp::file_to_string("test/data/cert.pem")),
32                 dcp::LocalTime("2023-01-03T10:30:00"),
33                 dcp::LocalTime("2050-10-20T14:00:00")
34                 );
35
36         BOOST_CHECK(result == KDMCertificatePeriod::KDM_WITHIN_CERTIFICATE);
37 }
38
39
40 BOOST_AUTO_TEST_CASE(check_kdm_and_certificate_validity_periods_overlap_start)
41 {
42         auto const result = check_kdm_and_certificate_validity_periods(
43                 dcp::Certificate(dcp::file_to_string("test/data/cert.pem")),
44                 dcp::LocalTime("2011-01-03T10:30:00"),
45                 dcp::LocalTime("2050-10-20T14:00:00")
46                 );
47
48         BOOST_CHECK(result == KDMCertificatePeriod::KDM_OVERLAPS_CERTIFICATE);
49 }
50
51
52 BOOST_AUTO_TEST_CASE(check_kdm_and_certificate_validity_periods_overlap_end)
53 {
54         auto const result = check_kdm_and_certificate_validity_periods(
55                 dcp::Certificate(dcp::file_to_string("test/data/cert.pem")),
56                 dcp::LocalTime("2033-01-03T10:30:00"),
57                 dcp::LocalTime("2095-10-20T14:00:00")
58                 );
59
60         BOOST_CHECK(result == KDMCertificatePeriod::KDM_OVERLAPS_CERTIFICATE);
61 }
62
63
64 BOOST_AUTO_TEST_CASE(check_kdm_and_certificate_validity_periods_overlap_start_and_end)
65 {
66         auto const result = check_kdm_and_certificate_validity_periods(
67                 dcp::Certificate(dcp::file_to_string("test/data/cert.pem")),
68                 dcp::LocalTime("2011-01-03T10:30:00"),
69                 dcp::LocalTime("2095-10-20T14:00:00")
70                 );
71
72         BOOST_CHECK(result == KDMCertificatePeriod::KDM_OVERLAPS_CERTIFICATE);
73 }
74
75
76 BOOST_AUTO_TEST_CASE(check_kdm_and_certificate_validity_periods_outside)
77 {
78         auto const result = check_kdm_and_certificate_validity_periods(
79                 dcp::Certificate(dcp::file_to_string("test/data/cert.pem")),
80                 dcp::LocalTime("2011-01-03T10:30:00"),
81                 dcp::LocalTime("2012-10-20T14:00:00")
82                 );
83
84         BOOST_CHECK(result == KDMCertificatePeriod::KDM_OUTSIDE_CERTIFICATE);
85 }