2 Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "picture_asset_writer.h"
22 /* Check that recovery from a partially-written MXF works */
23 BOOST_AUTO_TEST_CASE (recovery)
25 Kumu::libdcp_test = true;
27 string const picture = "test/data/32x32_red_square.j2c";
28 int const size = boost::filesystem::file_size (picture);
29 uint8_t* data = new uint8_t[size];
31 FILE* f = fopen (picture.c_str(), "rb");
33 fread (data, 1, size, f);
38 /* XXX: fix this posix-only stuff */
39 Kumu::ResetTestRNG ();
42 boost::filesystem::remove_all ("build/test/baz");
43 boost::filesystem::create_directories ("build/test/baz");
44 shared_ptr<libdcp::MonoPictureAsset> mp (new libdcp::MonoPictureAsset ("build/test/baz", "video1.mxf", 24, libdcp::Size (32, 32)));
45 shared_ptr<libdcp::PictureAssetWriter> writer = mp->start_write (false, false);
48 for (int i = 0; i < 24; ++i) {
49 libdcp::FrameInfo info = writer->write (data, size);
50 written_size = info.size;
56 boost::filesystem::copy_file ("build/test/baz/video1.mxf", "build/test/baz/video2.mxf");
57 boost::filesystem::resize_file ("build/test/baz/video2.mxf", 16384 + 353 * 11);
60 FILE* f = fopen ("build/test/baz/video2.mxf", "r+");
63 memset (zeros, 0, 256);
64 fwrite (zeros, 1, 256, f);
69 Kumu::ResetTestRNG ();
72 mp.reset (new libdcp::MonoPictureAsset ("build/test/baz", "video2.mxf", 24, libdcp::Size (32, 32)));
73 writer = mp->start_write (true, false);
75 writer->write (data, size);
77 for (int i = 1; i < 4; ++i) {
78 writer->fake_write (written_size);
81 for (int i = 4; i < 24; ++i) {
82 writer->write (data, size);