Use boost::random for make_random_file to make it repeatable across platforms.
authorCarl Hetherington <cth@carlh.net>
Sat, 18 Jun 2022 18:24:25 +0000 (20:24 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 21 Jun 2022 16:55:16 +0000 (18:55 +0200)
cscript
test/test.cc

diff --git a/cscript b/cscript
index 0ce8c48cba42e5ace14e8dea439e34e297ae2d89..90480a34398ad40220e15ca0f6f0751416957ac7 100644 (file)
--- a/cscript
+++ b/cscript
@@ -427,8 +427,8 @@ def dependencies(target, options):
         # Use distro-provided FFmpeg on Arch
         deps = []
 
-    deps.append(('libdcp', 'v1.8.21'))
-    deps.append(('libsub', 'v1.6.22'))
+    deps.append(('libdcp', 'v1.8.22'))
+    deps.append(('libsub', 'v1.6.23'))
     deps.append(('leqm-nrt', '93ae9e6'))
     deps.append(('rtaudio', 'f619b76'))
     # We get our OpenSSL libraries from the environment, but we
index 1059394731a9e21917683807f15ffbba64fe9e09..fd9c6941be30e4aac818a3debf3f2b6706df865b 100644 (file)
@@ -50,6 +50,7 @@
 #include <dcp/openjpeg_image.h>
 #include <dcp/reel.h>
 #include <dcp/reel_picture_asset.h>
+#include <dcp/warnings.h>
 #include <asdcp/AS_DCP.h>
 #include <png.h>
 #include <sndfile.h>
@@ -59,8 +60,11 @@ extern "C" {
 }
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_MODULE dcpomatic_test
-#include <boost/test/unit_test.hpp>
 #include <boost/algorithm/string.hpp>
+LIBDCP_DISABLE_WARNINGS
+#include <boost/random.hpp>
+LIBDCP_ENABLE_WARNINGS
+#include <boost/test/unit_test.hpp>
 #include <iostream>
 #include <list>
 #include <vector>
@@ -818,14 +822,21 @@ subtitle_file (shared_ptr<Film> film)
        return boost::filesystem::path("/");
 }
 
+
 void
 make_random_file (boost::filesystem::path path, size_t size)
 {
-       dcp::File t(path, "wb");
-       BOOST_REQUIRE (t);
-       for (size_t i = 0; i < size; ++i) {
-               uint8_t r = rand() & 0xff;
-               t.write(&r, 1, 1);
+       dcp::File random_file(path, "wb");
+       BOOST_REQUIRE (random_file);
+
+       boost::random::mt19937 rng(1);
+       boost::random::uniform_int_distribution<uint64_t> dist(0);
+
+       while (size > 0) {
+               auto this_time = std::min(size, size_t(8));
+               uint64_t random = dist(rng);
+               random_file.write(&random, this_time, 1);
+               size -= this_time;
        }
 }