2 Copyright (C) 2015-2021 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 /** @file test/image_filename_sorter_test.cc
23 * @brief Test ImageFilenameSorter
24 * @ingroup selfcontained
28 #include "lib/image_filename_sorter.h"
29 #include "lib/compose.hpp"
30 #include <boost/test/unit_test.hpp>
33 using std::random_shuffle;
38 BOOST_AUTO_TEST_CASE (image_filename_sorter_test1)
40 ImageFilenameSorter x;
41 BOOST_CHECK (x("abc0000000001", "abc0000000002"));
42 BOOST_CHECK (x("1", "2"));
43 BOOST_CHECK (x("1", "0002"));
44 BOOST_CHECK (x("0001", "2"));
45 BOOST_CHECK (x("1", "999"));
46 BOOST_CHECK (x("00057.tif", "00166.tif"));
47 BOOST_CHECK (x("/my/numeric999/path/00057.tif", "/my/numeric999/path/00166.tif"));
48 BOOST_CHECK (x("1_01.tif", "1_02.tif"));
49 BOOST_CHECK (x("EWS_DCP_092815_000000.j2c", "EWS_DCP_092815_000001.j2c"));
50 BOOST_CHECK (x("ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86352.dpx", "ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86353.dpx"));
52 BOOST_CHECK (!x("abc0000000002", "abc0000000001"));
53 BOOST_CHECK (!x("2", "1"));
54 BOOST_CHECK (!x("0002", "1"));
55 BOOST_CHECK (!x("2", "0001"));
56 BOOST_CHECK (!x("999", "1"));
57 BOOST_CHECK (!x("/my/numeric999/path/00166.tif", "/my/numeric999/path/00057.tif"));
58 BOOST_CHECK (!x("1_02.tif", "1_01.tif"));
59 BOOST_CHECK (!x("EWS_DCP_092815_000000.j2c", "EWS_DCP_092815_000000.j2c"));
60 BOOST_CHECK (!x("EWS_DCP_092815_000100.j2c", "EWS_DCP_092815_000000.j2c"));
61 BOOST_CHECK (!x("ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86353.dpx", "ap_trlr_178_uhd_bt1886_txt_e5c1_033115.86352.dpx"));
65 /** Test a sort of a lot of paths. Mostly useful for profiling. */
66 BOOST_AUTO_TEST_CASE (image_filename_sorter_test2)
68 vector<boost::filesystem::path> paths;
69 for (int i = 0; i < 100000; ++i) {
70 paths.push_back(String::compose("some.filename.with.%1.number.tiff", i));
72 random_shuffle (paths.begin(), paths.end());
73 sort (paths.begin(), paths.end(), ImageFilenameSorter());
74 for (int i = 0; i < 100000; ++i) {
75 BOOST_CHECK_EQUAL(paths[i].string(), String::compose("some.filename.with.%1.number.tiff", i));