diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-06-18 20:24:25 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-06-21 18:55:16 +0200 |
| commit | 2c43d6e1068704cc4f4d6383217ed9a1a07bb67d (patch) | |
| tree | 75097f03edf862d9594f9c7d98fe2fcbbeaef0fe /test | |
| parent | 6fe11fc6d50bdcd913d92601567aece6716c7112 (diff) | |
Use boost::random for make_random_file to make it repeatable across platforms.
Diffstat (limited to 'test')
| -rw-r--r-- | test/test.cc | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/test/test.cc b/test/test.cc index 105939473..fd9c6941b 100644 --- a/test/test.cc +++ b/test/test.cc @@ -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; } } |
