X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=test%2Ftest.cc;h=3ec78e68b3c16377bcb821a90399473909c7671f;hp=318ac479952c8cc3c0c391f2c1516fbb8307b605;hb=6eec3fea764f2fe35723089d60c51005616905bf;hpb=f0a2a52ddd1118236d4ce5640339c24bae88aa12 diff --git a/test/test.cc b/test/test.cc index 318ac4799..3ec78e68b 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington This file is part of DCP-o-matic. @@ -35,6 +35,8 @@ #include "lib/dcp_content_type.h" #include "lib/log_entry.h" #include "lib/compose.hpp" +#include "lib/file_log.h" +#include "lib/dcpomatic_log.h" #include "test.h" #include #include @@ -69,12 +71,13 @@ using boost::shared_ptr; using boost::scoped_array; using boost::dynamic_pointer_cast; -boost::filesystem::path private_data = boost::filesystem::canonical(boost::filesystem::path ("..") / boost::filesystem::path ("dcpomatic-test-private")); +boost::filesystem::path TestPaths::TestPaths::private_data = boost::filesystem::canonical(boost::filesystem::path ("..") / boost::filesystem::path ("dcpomatic-test-private")); +boost::filesystem::path TestPaths::xsd = boost::filesystem::canonical(boost::filesystem::path("..") / boost::filesystem::path("libdcp") / boost::filesystem::path("xsd")); void setup_test_config () { - Config::instance()->set_master_encoding_threads (1); + Config::instance()->set_master_encoding_threads (boost::thread::hardware_concurrency()); Config::instance()->set_server_encoding_threads (1); Config::instance()->set_server_port_base (61921); Config::instance()->set_default_isdcf_metadata (ISDCFMetadata ()); @@ -84,7 +87,7 @@ setup_test_config () Config::instance()->set_default_j2k_bandwidth (100000000); Config::instance()->set_default_interop (false); Config::instance()->set_default_still_length (10); - Config::instance()->set_log_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR); + Config::instance()->set_log_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_THREED | LogEntry::TYPE_DEBUG_ENCODE); Config::instance()->set_automatic_audio_analysis (false); } @@ -111,8 +114,10 @@ struct TestConfig char* env_private = getenv("DCPOMATIC_TEST_PRIVATE"); if (env_private) { - private_data = env_private; + TestPaths::TestPaths::private_data = env_private; } + + dcpomatic_log.reset (new FileLog("build/test/log")); } ~TestConfig () @@ -292,6 +297,14 @@ note (dcp::NoteType t, string n) } } + +void +check_dcp (boost::filesystem::path ref, shared_ptr film) +{ + check_dcp (ref, film->dir(film->dcp_name())); +} + + void check_dcp (boost::filesystem::path ref, boost::filesystem::path check) { @@ -417,11 +430,11 @@ wait_for_jobs () } void -write_image (shared_ptr image, boost::filesystem::path file, string format) +write_image (shared_ptr image, boost::filesystem::path file, string format, MagickCore::StorageType pixel_type) { using namespace MagickCore; - Magick::Image m (image->size().width, image->size().height, format.c_str(), CharPixel, (void *) image->data()[0]); + Magick::Image m (image->size().width, image->size().height, format.c_str(), pixel_type, (void *) image->data()[0]); m.write (file.string ()); } @@ -495,3 +508,40 @@ subtitle_file (shared_ptr 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 (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); +} + + +LogSwitcher::LogSwitcher (shared_ptr log) + : _old (dcpomatic_log) +{ + dcpomatic_log = log; +} + + +LogSwitcher::~LogSwitcher () +{ + dcpomatic_log = _old; +} +