f4235dec24d76dc375e80cba914e69f524d6a621
[dcpomatic.git] / test / file_naming_test.cc
1 /*
2     Copyright (C) 2016 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 "test.h"
22 #include "lib/config.h"
23 #include "lib/film.h"
24 #include "lib/ffmpeg_content.h"
25 #include "lib/dcp_content_type.h"
26 #include <boost/test/unit_test.hpp>
27 #include <boost/regex.hpp>
28
29 using std::string;
30 using boost::shared_ptr;
31
32 BOOST_AUTO_TEST_CASE (file_naming_test)
33 {
34         Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
35
36         shared_ptr<Film> film = new_test_film ("file_naming_test");
37         film->set_name ("file_naming_test");
38         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
39         shared_ptr<FFmpegContent> r (new FFmpegContent (film, "test/data/flat_red.png"));
40         film->examine_and_add_content (r);
41         shared_ptr<FFmpegContent> g (new FFmpegContent (film, "test/data/flat_green.png"));
42         film->examine_and_add_content (g);
43         shared_ptr<FFmpegContent> b (new FFmpegContent (film, "test/data/flat_blue.png"));
44         film->examine_and_add_content (b);
45         wait_for_jobs ();
46
47         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
48         film->make_dcp ();
49         wait_for_jobs ();
50
51         int got[3] = { 0, 0, 0 };
52         for (
53                 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
54                 i != boost::filesystem::directory_iterator();
55                 ++i) {
56                 if (boost::regex_match(i->path().string(), boost::regex(".*flat_red\\.png_.*\\.mxf"))) {
57                         ++got[0];
58                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
59                         ++got[1];
60                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
61                         ++got[2];
62                 }
63         }
64
65         for (int i = 0; i < 3; ++i) {
66                 BOOST_CHECK (got[i] == 2);
67         }
68 }
69
70 BOOST_AUTO_TEST_CASE (file_naming_test2)
71 {
72         Config::instance()->set_dcp_asset_filename_format (dcp::NameFormat ("%c"));
73
74         shared_ptr<Film> film = new_test_film ("file_naming_test2");
75         film->set_name ("file_naming_test2");
76         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
77         shared_ptr<FFmpegContent> r (new FFmpegContent (film, "test/data/flät_red.png"));
78         film->examine_and_add_content (r);
79         shared_ptr<FFmpegContent> g (new FFmpegContent (film, "test/data/flat_green.png"));
80         film->examine_and_add_content (g);
81         shared_ptr<FFmpegContent> b (new FFmpegContent (film, "test/data/flat_blue.png"));
82         film->examine_and_add_content (b);
83         wait_for_jobs ();
84
85         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
86         film->make_dcp ();
87         wait_for_jobs ();
88
89         int got[3] = { 0, 0, 0 };
90         for (
91                 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->file(film->dcp_name()));
92                 i != boost::filesystem::directory_iterator();
93                 ++i) {
94                 if (boost::regex_match(i->path().string(), boost::regex(".*flt_red\\.png_.*\\.mxf"))) {
95                         ++got[0];
96                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_green\\.png_.*\\.mxf"))) {
97                         ++got[1];
98                 } else if (boost::regex_match(i->path().string(), boost::regex(".*flat_blue\\.png_.*\\.mxf"))) {
99                         ++got[2];
100                 }
101         }
102
103         for (int i = 0; i < 3; ++i) {
104                 BOOST_CHECK (got[i] == 2);
105         }
106 }