X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Fframe_info_hash_test.cc;h=ed91491665340ee56f4efe7ac3a7dd8fbc6c35f4;hb=b995947a86a583a44bbe667e9bbd031296bf7e88;hp=d1f81d2c729a3b2756d46df55ba4865697d9dc00;hpb=96b6e2689b26e41ca1ba760ade3754b365fc9fc2;p=libdcp.git diff --git a/test/frame_info_hash_test.cc b/test/frame_info_hash_test.cc index d1f81d2c..ed914916 100644 --- a/test/frame_info_hash_test.cc +++ b/test/frame_info_hash_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington + Copyright (C) 2016-2019 Carl Hetherington This file is part of libdcp. @@ -15,43 +15,65 @@ You should have received a copy of the GNU General Public License along with libdcp. If not, see . + + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations + including the two. + + You must obey the GNU General Public License in all respects + for all of the code used other than OpenSSL. If you modify + file(s) with this exception, you may extend this exception to your + version of the file(s), but you are not obligated to do so. If you + do not wish to do so, delete this exception statement from your + version. If you delete this exception statement from all source + files in the program, then also delete it here. */ + +#include "j2k_transcode.h" #include "mono_picture_asset.h" #include "mono_picture_asset_writer.h" -#include "j2k.h" #include "openjpeg_image.h" +#include #include +#include + +using std::make_shared; +using std::shared_ptr; using std::string; -using boost::shared_ptr; + static void -check (unsigned int* seed, shared_ptr writer, string hash) +check (shared_ptr writer, boost::random::uniform_int_distribution<>& dist, boost::random::mt19937& rng, string hash) { - shared_ptr xyz (new dcp::OpenJPEGImage (dcp::Size (1998, 1080))); + auto xyz = make_shared(dcp::Size(1998, 1080)); for (int c = 0; c < 3; ++c) { for (int p = 0; p < (1998 * 1080); ++p) { - xyz->data(c)[p] = rand_r (seed) & 0xfff; + xyz->data(c)[p] = dist(rng); } } - dcp::Data data = dcp::compress_j2k (xyz, 100000000, 24, false, false); + auto data = dcp::compress_j2k (xyz, 100000000, 24, false, false); - dcp::FrameInfo info = writer->write (data.data().get(), data.size()); + auto info = writer->write (data.data(), data.size()); BOOST_CHECK_EQUAL (info.hash, hash); } + /** Test the hashing of data written to JPEG2000 MXFs with some random inputs */ BOOST_AUTO_TEST_CASE (frame_info_hash_test) { - shared_ptr mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::SMPTE)); - shared_ptr writer = mp->start_write ("build/test/frame_info_hash_test.mxf", false); + auto mp = make_shared(dcp::Fraction (24, 1), dcp::Standard::SMPTE); + auto writer = mp->start_write ("build/test/frame_info_hash_test.mxf", false); - unsigned int seed = 42; + boost::random::mt19937 rng(1); + boost::random::uniform_int_distribution<> dist(0, 4095); /* Check a few random frames */ - check (&seed, writer, "bb19bc96466d1b65708dabafa2e2ec0f"); - check (&seed, writer, "426ec5ac52d7a27fe278f7736d53151f"); - check (&seed, writer, "fafb05a0039cb9fc604279c90a13cb87"); + check(writer, dist, rng, "a9e772602a2fd3135d940cfd727ab8ff"); + check(writer, dist, rng, "b075369922e42b23e1852a586ec43224"); + check(writer, dist, rng, "402395e76152db05b03c8f24ddfd7732"); }