2 Copyright (C) 2023 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/>.
22 #include "lib/cinema.h"
23 #include "lib/cinema_list.h"
24 #include "lib/config.h"
25 #include "lib/screen.h"
26 #include <dcp/certificate.h>
27 #include <dcp/filesystem.h>
29 #include <boost/filesystem.hpp>
30 #include <boost/test/unit_test.hpp>
41 boost::filesystem::path
44 boost::filesystem::path db = boost::filesystem::path("build") / "test" / (name + ".db");
45 boost::system::error_code ec;
46 boost::filesystem::remove(db, ec);
51 BOOST_AUTO_TEST_CASE(add_cinema_test)
53 auto const db = setup("add_cinema_test");
55 auto const name = "Bob's Zero-G Cinema";
56 auto const emails = vector<string>{"zerogbob@hotmail.com"};
57 auto const notes = "Nice enough place but the popcorn keeps floating away";
58 auto const utc_offset = dcp::UTCOffset{5, 0};
60 CinemaList cinemas(db);
61 cinemas.add_cinema({name, emails, notes, utc_offset});
63 CinemaList cinemas2(db);
64 auto const check = cinemas2.cinemas();
65 BOOST_REQUIRE_EQUAL(check.size(), 1U);
66 BOOST_CHECK(check[0].second.name == name);
67 BOOST_CHECK(check[0].second.emails == emails);
68 BOOST_CHECK_EQUAL(check[0].second.notes, notes);
69 BOOST_CHECK(check[0].second.utc_offset == utc_offset);
73 BOOST_AUTO_TEST_CASE(remove_cinema_test)
75 auto const db = setup("remove_cinema_test");
77 auto const name1 = "Bob's Zero-G Cinema";
78 auto const emails1 = vector<string>{"zerogbob@hotmail.com"};
79 auto const notes1 = "Nice enough place but the popcorn keeps floating away";
80 auto const utc_offset1 = dcp::UTCOffset{-4, -30};
82 auto const name2 = "Angie's Infinite-Screen Cinema";
83 auto const emails2 = vector<string>{"angie@infinitium.com", "projection-screen912341235@infinitium.com"};
84 auto const notes2 = "Nice enough place but it's very hard to find the right screen";
85 auto const utc_offset2 = dcp::UTCOffset{9, 0};
87 CinemaList cinemas(db);
88 auto const id1 = cinemas.add_cinema({name1, emails1, notes1, utc_offset1});
89 cinemas.add_cinema({name2, emails2, notes2, utc_offset2});
91 auto const check = cinemas.cinemas();
92 BOOST_REQUIRE_EQUAL(check.size(), 2U);
93 BOOST_CHECK(check[0].second.name == name2);
94 BOOST_CHECK(check[0].second.emails == emails2);
95 BOOST_CHECK_EQUAL(check[0].second.notes, notes2);
96 BOOST_CHECK(check[0].second.utc_offset == utc_offset2);
97 BOOST_CHECK(check[1].second.name == name1);
98 BOOST_CHECK(check[1].second.emails == emails1);
99 BOOST_CHECK_EQUAL(check[1].second.notes, notes1);
100 BOOST_CHECK(check[1].second.utc_offset == utc_offset1);
102 cinemas.remove_cinema(id1);
104 auto const check2 = cinemas.cinemas();
105 BOOST_REQUIRE_EQUAL(check2.size(), 1U);
106 BOOST_CHECK(check2[0].second.name == name2);
107 BOOST_CHECK(check2[0].second.emails == emails2);
108 BOOST_CHECK_EQUAL(check2[0].second.notes, notes2);
112 BOOST_AUTO_TEST_CASE(update_cinema_test)
114 auto const db = setup("update_cinema_test");
116 auto const name1 = "Bob's Zero-G Cinema";
117 auto const emails1 = vector<string>{"zerogbob@hotmail.com"};
118 auto const notes1 = "Nice enough place but the popcorn keeps floating away";
119 auto const utc_offset1 = dcp::UTCOffset{-4, -30};
121 auto const name2 = "Angie's Infinite-Screen Cinema";
122 auto const emails2 = vector<string>{"angie@infinitium.com", "projection-screen912341235@infinitium.com"};
123 auto const notes2 = "Nice enough place but it's very hard to find the right screen";
124 auto const utc_offset2 = dcp::UTCOffset{9, 0};
126 CinemaList cinemas(db);
127 auto const id = cinemas.add_cinema({name1, emails1, notes1, utc_offset1});
128 cinemas.add_cinema({name2, emails2, notes2, utc_offset2});
130 auto check = cinemas.cinemas();
131 BOOST_REQUIRE_EQUAL(check.size(), 2U);
132 /* Alphabetically ordered so first is 2 */
133 BOOST_CHECK_EQUAL(check[0].second.name, name2);
134 BOOST_CHECK(check[0].second.emails == emails2);
135 BOOST_CHECK_EQUAL(check[0].second.notes, notes2);
136 BOOST_CHECK(check[0].second.utc_offset == utc_offset2);
138 BOOST_CHECK_EQUAL(check[1].second.name, name1);
139 BOOST_CHECK(check[1].second.emails == emails1);
140 BOOST_CHECK_EQUAL(check[1].second.notes, notes1);
141 BOOST_CHECK(check[1].second.utc_offset == utc_offset1);
143 cinemas.update_cinema(id, Cinema{name1, vector<string>{"bob@zerogkino.com"}, notes1, utc_offset1});
145 check = cinemas.cinemas();
146 BOOST_REQUIRE_EQUAL(check.size(), 2U);
147 BOOST_CHECK_EQUAL(check[0].second.name, name2);
148 BOOST_CHECK(check[0].second.emails == emails2);
149 BOOST_CHECK_EQUAL(check[0].second.notes, notes2);
150 BOOST_CHECK(check[0].second.utc_offset == utc_offset2);
151 BOOST_CHECK_EQUAL(check[1].second.name, name1);
152 BOOST_CHECK(check[1].second.emails == vector<string>{"bob@zerogkino.com"});
153 BOOST_CHECK_EQUAL(check[1].second.notes, notes1);
154 BOOST_CHECK(check[1].second.utc_offset == utc_offset1);
158 BOOST_AUTO_TEST_CASE(add_screen_test)
160 auto const db = setup("add_screen_test");
162 CinemaList cinemas(db);
163 auto const cinema_id = cinemas.add_cinema({"Name", { "foo@bar.com" }, "", dcp::UTCOffset()});
164 auto const screen_id = cinemas.add_screen(
169 dcp::Certificate(dcp::file_to_string("test/data/cert.pem")),
170 string("test/data/cert.pem"),
171 vector<TrustedDevice>{}
174 auto check = cinemas.screens(cinema_id);
175 BOOST_REQUIRE_EQUAL(check.size(), 1U);
176 BOOST_CHECK(check[0].first == screen_id);
177 BOOST_CHECK_EQUAL(check[0].second.name, "Screen 1");
178 BOOST_CHECK_EQUAL(check[0].second.notes, "Smells of popcorn");
179 BOOST_CHECK(check[0].second.recipient == dcp::Certificate(dcp::file_to_string("test/data/cert.pem")));
180 BOOST_CHECK(check[0].second.recipient_file == string("test/data/cert.pem"));
184 BOOST_AUTO_TEST_CASE(cinemas_list_copy_from_xml_test)
186 Config::override_path = "build/test/cinemas_list_copy_config";
187 dcp::filesystem::remove_all(*Config::override_path);
188 dcp::filesystem::create_directories(*Config::override_path);
189 dcp::filesystem::copy_file("test/data/cinemas2.xml", *Config::override_path / "cinemas2.xml");
192 CinemaList cinema_list;
193 cinema_list.read_legacy_file(Config::instance()->read_path("cinemas2.xml"));
194 auto cinemas = cinema_list.cinemas();
195 BOOST_REQUIRE_EQUAL(cinemas.size(), 3U);
197 auto cinema_iter = cinemas.begin();
198 BOOST_CHECK_EQUAL(cinema_iter->second.name, "Great");
199 BOOST_CHECK_EQUAL(cinema_iter->second.emails.size(), 1U);
200 BOOST_CHECK_EQUAL(cinema_iter->second.emails[0], "julie@tinyscreen.com");
201 BOOST_CHECK(cinema_iter->second.utc_offset == dcp::UTCOffset(1, 0));
204 BOOST_CHECK_EQUAL(cinema_iter->second.name, "classy joint");
205 BOOST_CHECK_EQUAL(cinema_iter->second.notes, "Can't stand this place");
208 BOOST_CHECK_EQUAL(cinema_iter->second.name, "stinking dump");
209 BOOST_CHECK_EQUAL(cinema_iter->second.emails.size(), 2U);
210 BOOST_CHECK_EQUAL(cinema_iter->second.emails[0], "bob@odourscreen.com");
211 BOOST_CHECK_EQUAL(cinema_iter->second.emails[1], "alice@whiff.com");
212 BOOST_CHECK_EQUAL(cinema_iter->second.notes, "Great cinema, smells of roses");
213 BOOST_CHECK(cinema_iter->second.utc_offset == dcp::UTCOffset(-7, 0));
214 auto screens = cinema_list.screens(cinema_iter->first);
215 BOOST_CHECK_EQUAL(screens.size(), 2U);
216 auto screen_iter = screens.begin();
217 BOOST_CHECK_EQUAL(screen_iter->second.name, "1");
218 BOOST_CHECK(screen_iter->second.recipient);
219 BOOST_CHECK_EQUAL(screen_iter->second.recipient->subject_dn_qualifier(), "CVsuuv9eYsQZSl8U4fDpvOmzZhI=");
221 BOOST_CHECK_EQUAL(screen_iter->second.name, "2");
222 BOOST_CHECK(screen_iter->second.recipient);
223 BOOST_CHECK_EQUAL(screen_iter->second.recipient->subject_dn_qualifier(), "CVsuuv9eYsQZSl8U4fDpvOmzZhI=");