Fixes for the bad distros.
[libdcp.git] / test / frame_info_hash_test.cc
1 /*
2     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp 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     libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "mono_picture_asset.h"
21 #include "mono_picture_asset_writer.h"
22 #include "j2k.h"
23 #include "openjpeg_image.h"
24 #include <boost/test/unit_test.hpp>
25
26 using std::string;
27 using boost::shared_ptr;
28
29 static void
30 check (unsigned int* seed, shared_ptr<dcp::PictureAssetWriter> writer, string hash)
31 {
32         shared_ptr<dcp::OpenJPEGImage> xyz (new dcp::OpenJPEGImage (dcp::Size (1998, 1080)));
33         for (int c = 0; c < 3; ++c) {
34                 for (int p = 0; p < (1998 * 1080); ++p) {
35                         xyz->data(c)[p] = rand_r (seed);
36                 }
37         }
38
39         dcp::Data data = dcp::compress_j2k (xyz, 100000000, 24, false, false);
40
41         dcp::FrameInfo info = writer->write (data.data().get(), data.size());
42         BOOST_CHECK_EQUAL (info.hash, hash);
43 }
44
45 /** Test the hashing of data written to JPEG2000 MXFs with some random inputs */
46 BOOST_AUTO_TEST_CASE (frame_info_hash_test)
47 {
48         shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1)));
49         shared_ptr<dcp::PictureAssetWriter> writer = mp->start_write ("build/test/frame_info_hash_test.mxf", dcp::SMPTE, false);
50
51         unsigned int seed = 42;
52
53         /* Check a few random frames */
54         check (&seed, writer, "7ddfb4f5cec76f95138c4377a829dd6f");
55         check (&seed, writer, "d6a91028bab60995b4fc49fbccd5c2ba");
56         check (&seed, writer, "9d8653644f49f692e4bbac34106a4897");
57 }