Remove support for building with OpenJPEG 1.x.
[libdcp.git] / test / frame_info_hash_test.cc
index d1f81d2c729a3b2756d46df55ba4865697d9dc00..ed91491665340ee56f4efe7ac3a7dd8fbc6c35f4 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
 
     You should have received a copy of the GNU General Public License
     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
+
+    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 <boost/random.hpp>
 #include <boost/test/unit_test.hpp>
+#include <memory>
 
+
+using std::make_shared;
+using std::shared_ptr;
 using std::string;
-using boost::shared_ptr;
+
 
 static void
-check (unsigned int* seed, shared_ptr<dcp::PictureAssetWriter> writer, string hash)
+check (shared_ptr<dcp::PictureAssetWriter> writer, boost::random::uniform_int_distribution<>& dist, boost::random::mt19937& rng, string hash)
 {
-       shared_ptr<dcp::OpenJPEGImage> xyz (new dcp::OpenJPEGImage (dcp::Size (1998, 1080)));
+       auto xyz = make_shared<dcp::OpenJPEGImage>(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<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::SMPTE));
-       shared_ptr<dcp::PictureAssetWriter> writer = mp->start_write ("build/test/frame_info_hash_test.mxf", false);
+       auto mp = make_shared<dcp::MonoPictureAsset>(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");
 }