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 /* Check that recovery from a partially-written MXF works */
21 BOOST_AUTO_TEST_CASE (recovery)
23 Kumu::libdcp_test = true;
25 string const picture = "test/data/32x32_red_square.j2c";
26 int const size = boost::filesystem::file_size (picture);
27 uint8_t* data = new uint8_t[size];
29 FILE* f = fopen (picture.c_str(), "rb");
31 fread (data, 1, size, f);
36 /* XXX: fix this posix-only stuff */
37 Kumu::ResetTestRNG ();
40 boost::filesystem::remove_all ("build/test/baz");
41 boost::filesystem::create_directories ("build/test/baz");
42 shared_ptr<libdcp::MonoPictureAsset> mp (new libdcp::MonoPictureAsset ("build/test/baz", "video1.mxf", 24, libdcp::Size (32, 32)));
43 shared_ptr<libdcp::MonoPictureAssetWriter> writer = mp->start_write (false);
46 for (int i = 0; i < 24; ++i) {
47 libdcp::FrameInfo info = writer->write (data, size);
48 written_size = info.size;
54 boost::filesystem::copy_file ("build/test/baz/video1.mxf", "build/test/baz/video2.mxf");
55 boost::filesystem::resize_file ("build/test/baz/video2.mxf", 16384 + 353 * 11);
58 FILE* f = fopen ("build/test/baz/video2.mxf", "r+");
61 memset (zeros, 0, 256);
62 fwrite (zeros, 1, 256, f);
67 Kumu::ResetTestRNG ();
70 mp.reset (new libdcp::MonoPictureAsset ("build/test/baz", "video2.mxf", 24, libdcp::Size (32, 32)));
71 writer = mp->start_write (true);
73 writer->write (data, size);
75 for (int i = 1; i < 4; ++i) {
76 writer->fake_write (written_size);
79 for (int i = 4; i < 24; ++i) {
80 writer->write (data, size);