Merge branch 'v2.15.x' of ssh://main.carlh.net/home/carl/git/dcpomatic into v2.15.x
[dcpomatic.git] / test / reel_writer_test.cc
1 /*
2     Copyright (C) 2019 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 /** @file  test/reel_writer_test.cc
22  *  @brief Test ReelWriter class.
23  *  @ingroup selfcontained
24  */
25
26 #include "lib/reel_writer.h"
27 #include "lib/film.h"
28 #include "lib/cross.h"
29 #include "test.h"
30 #include <boost/test/unit_test.hpp>
31
32 using std::string;
33 using boost::shared_ptr;
34 using boost::optional;
35
36 static bool equal (dcp::FrameInfo a, ReelWriter const & writer, shared_ptr<InfoFileHandle> file, Frame frame, Eyes eyes)
37 {
38         dcp::FrameInfo b = writer.read_frame_info(file, frame, eyes);
39         return a.offset == b.offset && a.size == b.size && a.hash == b.hash;
40 }
41
42 BOOST_AUTO_TEST_CASE (write_frame_info_test)
43 {
44         shared_ptr<Film> film = new_test_film2 ("write_frame_info_test");
45         dcpomatic::DCPTimePeriod const period (dcpomatic::DCPTime(0), dcpomatic::DCPTime(96000));
46         ReelWriter writer (film, period, shared_ptr<Job>(), 0, 1, optional<string>());
47
48         /* Write the first one */
49
50         dcp::FrameInfo info1(0, 123, "12345678901234567890123456789012");
51         writer.write_frame_info (0, EYES_LEFT, info1);
52         {
53                 shared_ptr<InfoFileHandle> file = film->info_file_handle(period, true);
54                 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
55         }
56
57         /* Write some more */
58
59         dcp::FrameInfo info2(596, 14921, "123acb789f1234ae782012n456339522");
60         writer.write_frame_info (5, EYES_RIGHT, info2);
61
62         {
63                 shared_ptr<InfoFileHandle> file = film->info_file_handle(period, true);
64                 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
65                 BOOST_CHECK (equal(info2, writer, file, 5, EYES_RIGHT));
66         }
67
68         dcp::FrameInfo info3(12494, 99157123, "xxxxyyyyabc12356ffsfdsf456339522");
69         writer.write_frame_info (10, EYES_LEFT, info3);
70
71         {
72                 shared_ptr<InfoFileHandle> file = film->info_file_handle(period, true);
73                 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
74                 BOOST_CHECK (equal(info2, writer, file, 5, EYES_RIGHT));
75                 BOOST_CHECK (equal(info3, writer, file, 10, EYES_LEFT));
76         }
77
78         /* Overwrite one */
79
80         dcp::FrameInfo info4(55512494, 123599157123, "ABCDEFGyabc12356ffsfdsf4563395ZZ");
81         writer.write_frame_info (5, EYES_RIGHT, info4);
82
83         {
84                 shared_ptr<InfoFileHandle> file = film->info_file_handle(period, true);
85                 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
86                 BOOST_CHECK (equal(info4, writer, file, 5, EYES_RIGHT));
87                 BOOST_CHECK (equal(info3, writer, file, 10, EYES_LEFT));
88         }
89 }