Change video content scaling so that it either:
[dcpomatic.git] / test / ecinema_kdm_test.cc
1 /*
2     Copyright (C) 2019 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 #include "lib/decrypted_ecinema_kdm.h"
22 #include "lib/encrypted_ecinema_kdm.h"
23 #include "lib/config.h"
24 #include <boost/test/unit_test.hpp>
25 extern "C" {
26 #include <libavutil/aes_ctr.h>
27 }
28 #include <fstream>
29
30 using std::string;
31 using boost::optional;
32
33 #ifdef DCPOMATIC_VARIANT_SWAROOP
34
35 BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test1)
36 {
37         dcp::Key key (AES_CTR_KEY_SIZE);
38         DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, optional<dcp::LocalTime>(), optional<dcp::LocalTime>());
39         EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf());
40         DecryptedECinemaKDM dec2 (enc, *Config::instance()->decryption_chain()->key());
41         BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0");
42         BOOST_CHECK_EQUAL (dec2.name(), "Hello world");
43         BOOST_CHECK (dec2.key() == key);
44         BOOST_CHECK (!static_cast<bool>(dec2.not_valid_before()));
45         BOOST_CHECK (!static_cast<bool>(dec2.not_valid_after()));
46 }
47
48 BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test2)
49 {
50         dcp::Key key (AES_CTR_KEY_SIZE);
51         DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, dcp::LocalTime("2019-06-01T15:05:23+01:00"), dcp::LocalTime("2019-07-02T19:10:12+02:00"));
52         EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf());
53         DecryptedECinemaKDM dec2 (enc, *Config::instance()->decryption_chain()->key());
54         BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0");
55         BOOST_CHECK_EQUAL (dec2.name(), "Hello world");
56         BOOST_CHECK (dec2.key() == key);
57         BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_before()));
58         BOOST_CHECK_EQUAL (dec2.not_valid_before()->as_string(), "2019-06-01T15:05:23+01:00");
59         BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_after()));
60         BOOST_CHECK_EQUAL (dec2.not_valid_after()->as_string(), "2019-07-02T19:10:12+02:00");
61 }
62
63 BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test3)
64 {
65         dcp::Key key (AES_CTR_KEY_SIZE);
66         DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, optional<dcp::LocalTime>(), optional<dcp::LocalTime>());
67         EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf());
68         string const enc_xml = enc.as_xml ();
69         EncryptedECinemaKDM enc2 (enc_xml);
70         DecryptedECinemaKDM dec2 (enc2, *Config::instance()->decryption_chain()->key());
71         BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0");
72         BOOST_CHECK_EQUAL (dec2.name(), "Hello world");
73         BOOST_CHECK (dec2.key() == key);
74         BOOST_CHECK (!static_cast<bool>(dec2.not_valid_before()));
75         BOOST_CHECK (!static_cast<bool>(dec2.not_valid_after()));
76 }
77
78 BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test4)
79 {
80         dcp::Key key (AES_CTR_KEY_SIZE);
81         DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, dcp::LocalTime("2019-06-01T15:05:23+01:00"), dcp::LocalTime("2019-07-02T19:10:12+02:00"));
82         EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf());
83         string const enc_xml = enc.as_xml();
84         EncryptedECinemaKDM enc2 (dcp::file_to_string("build/test/shit_the_bed.xml"));
85         DecryptedECinemaKDM dec2 (enc2, *Config::instance()->decryption_chain()->key());
86         BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0");
87         BOOST_CHECK_EQUAL (dec2.name(), "Hello world");
88         BOOST_CHECK (dec2.key() == key);
89         BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_before()));
90         BOOST_CHECK_EQUAL (dec2.not_valid_before()->as_string(), "2019-06-01T15:05:23+01:00");
91         BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_after()));
92         BOOST_CHECK_EQUAL (dec2.not_valid_after()->as_string(), "2019-07-02T19:10:12+02:00");
93 }
94
95 #endif