summaryrefslogtreecommitdiff
path: root/test/reel_writer_test.cc
blob: db63ca8bf0247668b5980574e24f2e27af52627d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/

/** @file  test/reel_writer_test.cc
 *  @brief Test ReelWriter class.
 *  @ingroup selfcontained
 */

#include "lib/reel_writer.h"
#include "lib/film.h"
#include "lib/cross.h"
#include "test.h"
#include <boost/test/unit_test.hpp>

using std::string;
using boost::shared_ptr;
using boost::optional;

static bool equal (dcp::FrameInfo a, ReelWriter const & writer, boost::filesystem::path file, Frame frame, Eyes eyes)
{
	FILE* f = fopen_boost(file, "rb");
	BOOST_REQUIRE (f);
	dcp::FrameInfo b = writer.read_frame_info(f, frame, eyes);
	bool const r = a.offset == b.offset && a.size == b.size && a.hash == b.hash;
	fclose (f);
	return r;
}

BOOST_AUTO_TEST_CASE (write_frame_info_test)
{
	shared_ptr<Film> film = new_test_film2 ("write_frame_info_test");
	dcpomatic::DCPTimePeriod const period (dcpomatic::DCPTime(0), dcpomatic::DCPTime(96000));
	ReelWriter writer (film, period, shared_ptr<Job>(), 0, 1, optional<string>());

	/* Write the first one */

	boost::filesystem::path file = film->info_file (period);
	BOOST_CHECK (!boost::filesystem::exists(file));
	dcp::FrameInfo info1(0, 123, "12345678901234567890123456789012");
	writer.write_frame_info (0, EYES_LEFT, info1);
	BOOST_CHECK (boost::filesystem::exists(file));

	BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));

	/* Write some more */

	dcp::FrameInfo info2(596, 14921, "123acb789f1234ae782012n456339522");
	writer.write_frame_info (5, EYES_RIGHT, info2);
	BOOST_CHECK (boost::filesystem::exists(file));

	BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
	BOOST_CHECK (equal(info2, writer, file, 5, EYES_RIGHT));

	dcp::FrameInfo info3(12494, 99157123, "xxxxyyyyabc12356ffsfdsf456339522");
	writer.write_frame_info (10, EYES_LEFT, info3);
	BOOST_CHECK (boost::filesystem::exists(file));

	BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
	BOOST_CHECK (equal(info2, writer, file, 5, EYES_RIGHT));
	BOOST_CHECK (equal(info3, writer, file, 10, EYES_LEFT));

	/* Overwrite one */

	dcp::FrameInfo info4(55512494, 123599157123, "ABCDEFGyabc12356ffsfdsf4563395ZZ");
	writer.write_frame_info (5, EYES_RIGHT, info4);
	BOOST_CHECK (boost::filesystem::exists(file));

	BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
	BOOST_CHECK (equal(info4, writer, file, 5, EYES_RIGHT));
	BOOST_CHECK (equal(info3, writer, file, 10, EYES_LEFT));
}