2 Copyright (C) 2019 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/>.
21 /** @file test/reel_writer_test.cc
22 * @brief Test ReelWriter class.
23 * @ingroup selfcontained
26 #include "lib/reel_writer.h"
28 #include "lib/cross.h"
30 #include <boost/test/unit_test.hpp>
33 using boost::shared_ptr;
34 using boost::optional;
36 static bool equal (dcp::FrameInfo a, ReelWriter const & writer, boost::filesystem::path file, Frame frame, Eyes eyes)
38 FILE* f = fopen_boost(file, "rb");
40 dcp::FrameInfo b = writer.read_frame_info(f, frame, eyes);
41 bool const r = a.offset == b.offset && a.size == b.size && a.hash == b.hash;
46 BOOST_AUTO_TEST_CASE (write_frame_info_test)
48 shared_ptr<Film> film = new_test_film2 ("write_frame_info_test");
49 dcpomatic::DCPTimePeriod const period (dcpomatic::DCPTime(0), dcpomatic::DCPTime(96000));
50 ReelWriter writer (film, period, shared_ptr<Job>(), 0, 1, optional<string>());
52 /* Write the first one */
54 boost::filesystem::path file = film->info_file (period);
55 BOOST_CHECK (!boost::filesystem::exists(file));
56 dcp::FrameInfo info1(0, 123, "12345678901234567890123456789012");
57 writer.write_frame_info (0, EYES_LEFT, info1);
58 BOOST_CHECK (boost::filesystem::exists(file));
60 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
64 dcp::FrameInfo info2(596, 14921, "123acb789f1234ae782012n456339522");
65 writer.write_frame_info (5, EYES_RIGHT, info2);
66 BOOST_CHECK (boost::filesystem::exists(file));
68 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
69 BOOST_CHECK (equal(info2, writer, file, 5, EYES_RIGHT));
71 dcp::FrameInfo info3(12494, 99157123, "xxxxyyyyabc12356ffsfdsf456339522");
72 writer.write_frame_info (10, EYES_LEFT, info3);
73 BOOST_CHECK (boost::filesystem::exists(file));
75 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
76 BOOST_CHECK (equal(info2, writer, file, 5, EYES_RIGHT));
77 BOOST_CHECK (equal(info3, writer, file, 10, EYES_LEFT));
81 dcp::FrameInfo info4(55512494, 123599157123, "ABCDEFGyabc12356ffsfdsf4563395ZZ");
82 writer.write_frame_info (5, EYES_RIGHT, info4);
83 BOOST_CHECK (boost::filesystem::exists(file));
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));