Supporters update.
[dcpomatic.git] / test / font_id_allocator_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/font_id_allocator.h"
23 #include <boost/test/unit_test.hpp>
24
25
26 BOOST_AUTO_TEST_CASE(font_id_allocator_test_without_disambiguation)
27 {
28         FontIDAllocator allocator;
29
30         /* Reel 0 has just one asset with two fonts */
31         allocator.add_font(0, "asset1", "font");
32         allocator.add_font(0, "asset1", "font2");
33
34         /* Reel 1 has two assets each with two more fonts */
35         allocator.add_font(1, "asset2", "font");
36         allocator.add_font(1, "asset2", "font2");
37         allocator.add_font(1, "asset3", "font3");
38         allocator.add_font(1, "asset3", "font4");
39
40         allocator.allocate();
41
42         BOOST_CHECK(allocator.font_id(0, "asset1", "font") == "0_font");
43         BOOST_CHECK(allocator.font_id(0, "asset1", "font2") == "0_font2");
44         BOOST_CHECK(allocator.font_id(1, "asset2", "font") == "1_font");
45         BOOST_CHECK(allocator.font_id(1, "asset2", "font2") == "1_font2");
46         BOOST_CHECK(allocator.font_id(1, "asset3", "font3") == "1_font3");
47         BOOST_CHECK(allocator.font_id(1, "asset3", "font4") == "1_font4");
48 }
49
50
51 BOOST_AUTO_TEST_CASE(font_id_allocator_test_with_disambiguation)
52 {
53         FontIDAllocator allocator;
54
55         /* Reel 0 has two assets each with a font with the same ID (perhaps a subtitle and a ccap).
56          * This would have crashed DCP-o-matic before the FontIDAllocator change (bug #2600)
57          * so it's OK if the second font gets a new index that we didn't see before.
58          */
59         allocator.add_font(0, "asset1", "font");
60         allocator.add_font(0, "asset2", "font");
61
62         /* Reel 1 has one asset with another font */
63         allocator.add_font(1, "asset3", "font1");
64
65         allocator.allocate();
66
67         BOOST_CHECK(allocator.font_id(0, "asset1", "font") == "0_font");
68         /* This should get a prefix that is higher than any reel index */
69         BOOST_CHECK(allocator.font_id(0, "asset2", "font") == "2_font");
70         BOOST_CHECK(allocator.font_id(1, "asset3", "font1") == "1_font1");
71 }
72