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/font_id_allocator.h"
23 #include <boost/test/unit_test.hpp>
30 BOOST_AUTO_TEST_CASE(font_id_allocator_test_without_disambiguation)
32 FontIDAllocator allocator;
34 /* Reel 0 has just one asset with two fonts */
35 allocator.add_font(0, "asset1", "font");
36 allocator.add_font(0, "asset1", "font2");
38 /* Reel 1 has two assets each with two more fonts */
39 allocator.add_font(1, "asset2", "font");
40 allocator.add_font(1, "asset2", "font2");
41 allocator.add_font(1, "asset3", "font3");
42 allocator.add_font(1, "asset3", "font4");
46 BOOST_CHECK(allocator.font_id(0, "asset1", "font") == "0_font");
47 BOOST_CHECK(allocator.font_id(0, "asset1", "font2") == "0_font2");
48 BOOST_CHECK(allocator.font_id(1, "asset2", "font") == "1_font");
49 BOOST_CHECK(allocator.font_id(1, "asset2", "font2") == "1_font2");
50 BOOST_CHECK(allocator.font_id(1, "asset3", "font3") == "1_font3");
51 BOOST_CHECK(allocator.font_id(1, "asset3", "font4") == "1_font4");
55 BOOST_AUTO_TEST_CASE(font_id_allocator_test_with_disambiguation)
57 FontIDAllocator allocator;
59 /* Reel 0 has two assets each with a font with the same ID (perhaps a subtitle and a ccap).
60 * This would have crashed DCP-o-matic before the FontIDAllocator change (bug #2600)
61 * so it's OK if the second font gets a new index that we didn't see before.
63 allocator.add_font(0, "asset1", "font");
64 allocator.add_font(0, "asset2", "font");
66 /* Reel 1 has one asset with another font */
67 allocator.add_font(1, "asset3", "font1");
71 BOOST_CHECK(allocator.font_id(0, "asset1", "font") == "0_font");
72 /* This should get a prefix that is higher than any reel index */
73 BOOST_CHECK(allocator.font_id(0, "asset2", "font") == "2_font");
74 BOOST_CHECK(allocator.font_id(1, "asset3", "font1") == "1_font1");
78 /* Bug #2822: multiple reels, each with subs + closed captions, and each using the same
81 BOOST_AUTO_TEST_CASE(font_id_allocator_test_with_disambiguation2)
83 FontIDAllocator allocator;
85 allocator.add_font(0, "asset1", "font");
86 allocator.add_font(0, "asset2", "font");
88 allocator.add_font(1, "asset1", "font");
89 allocator.add_font(1, "asset2", "font");
92 vector<string> ids = {
93 allocator.font_id(0, "asset1", "font"),
94 allocator.font_id(0, "asset2", "font"),
95 allocator.font_id(1, "asset1", "font"),
96 allocator.font_id(1, "asset2", "font")
99 std::sort(ids.begin(), ids.end());
100 BOOST_CHECK(std::adjacent_find(ids.begin(), ids.end()) == ids.end());