diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/test.cc | 23 | ||||
| -rw-r--r-- | test/test.h | 1 | ||||
| -rw-r--r-- | test/util_test.cc | 26 |
3 files changed, 49 insertions, 1 deletions
diff --git a/test/test.cc b/test/test.cc index 318ac4799..c5bc417f3 100644 --- a/test/test.cc +++ b/test/test.cc @@ -495,3 +495,26 @@ subtitle_file (shared_ptr<Film> film) /* Remove warning */ return boost::filesystem::path("/"); } + +void +make_random_file (boost::filesystem::path path, size_t size) +{ + size_t const chunk = 128 * 1024; + uint8_t* buffer = static_cast<uint8_t*> (malloc(chunk)); + BOOST_REQUIRE (buffer); + FILE* r = fopen("/dev/urandom", "rb"); + BOOST_REQUIRE (r); + FILE* t = fopen_boost(path, "wb"); + BOOST_REQUIRE (t); + while (size) { + size_t this_time = min (size, chunk); + size_t N = fread (buffer, 1, this_time, r); + BOOST_REQUIRE (N == this_time); + N = fwrite (buffer, 1, this_time, t); + BOOST_REQUIRE (N == this_time); + size -= this_time; + } + fclose (t); + fclose (r); + free (buffer); +} diff --git a/test/test.h b/test/test.h index 4020dc772..86b13cde5 100644 --- a/test/test.h +++ b/test/test.h @@ -42,3 +42,4 @@ extern void write_image (boost::shared_ptr<const Image> image, boost::filesystem boost::filesystem::path dcp_file (boost::shared_ptr<const Film> film, std::string prefix); void check_one_frame (boost::filesystem::path dcp, int64_t index, boost::filesystem::path ref); extern boost::filesystem::path subtitle_file (boost::shared_ptr<Film> film); +extern void make_random_file (boost::filesystem::path path, size_t size); diff --git a/test/util_test.cc b/test/util_test.cc index 709bb0827..1c1091f28 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -26,11 +26,14 @@ #include "lib/util.h" #include "lib/cross.h" #include "lib/exceptions.h" +#include "test.h" #include <dcp/certificate_chain.h> #include <boost/test/unit_test.hpp> +#include <boost/bind.hpp> using std::string; using std::vector; +using std::list; using boost::shared_ptr; using namespace dcpomatic; @@ -129,3 +132,24 @@ BOOST_AUTO_TEST_CASE (careful_string_filter_test) BOOST_CHECK_EQUAL ("hello_world", careful_string_filter("héllo_wörld")); BOOST_CHECK_EQUAL ("hello_world_a", careful_string_filter("héllo_wörld_à")); } + +static list<float> progress_values; + +static void +progress (float p) +{ + progress_values.push_back (p); +} + +BOOST_AUTO_TEST_CASE (copy_in_bits_test) +{ + for (int i = 0; i < 32; ++i) { + make_random_file ("build/test/random.dat", rand() % (256 * 1024 * 1024)); + + progress_values.clear (); + copy_in_bits ("build/test/random.dat", "build/test/random.dat2", boost::bind(&progress, _1)); + BOOST_CHECK (!progress_values.empty()); + + check_file ("build/test/random.dat", "build/test/random.dat2"); + } +} |
