X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Ftest.cc;h=0c2f324e05de99126375bba104bd508cb23091d9;hb=ca545930f35fde9f60f76a6d66de475da5cb098c;hp=b02fa99c95bb50a3591022f28b446eed06f486c0;hpb=7d651ec877927e0887da48ce441e5c5158e1f34f;p=dcpomatic.git diff --git a/test/test.cc b/test/test.cc index b02fa99c9..0c2f324e0 100644 --- a/test/test.cc +++ b/test/test.cc @@ -32,8 +32,15 @@ #include "lib/encode_server_finder.h" #include "lib/image.h" #include "lib/ratio.h" +#include "lib/dcp_content_type.h" #include "lib/log_entry.h" #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -44,6 +51,7 @@ extern "C" { #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE dcpomatic_test #include +#include #include #include #include @@ -57,6 +65,7 @@ using std::list; using std::abs; using boost::shared_ptr; using boost::scoped_array; +using boost::dynamic_pointer_cast; boost::filesystem::path private_data = boost::filesystem::path ("..") / boost::filesystem::path ("dcpomatic-test-private"); @@ -87,10 +96,16 @@ struct TestConfig 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_automatic_audio_analysis (false); EncodeServerFinder::instance()->stop (); signal_manager = new TestSignalManager (); + + char* env_private = getenv("DCPOMATIC_TEST_PRIVATE"); + if (env_private) { + private_data = env_private; + } } ~TestConfig () @@ -124,6 +139,21 @@ new_test_film (string name) return film; } +shared_ptr +new_test_film2 (string name) +{ + boost::filesystem::path p = test_film_dir (name); + if (boost::filesystem::exists (p)) { + boost::filesystem::remove_all (p); + } + + shared_ptr film = shared_ptr (new Film (p)); + film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST")); + film->set_container (Ratio::from_id ("185")); + film->write_metadata (); + return film; +} + void check_wav_file (boost::filesystem::path ref, boost::filesystem::path check) { @@ -206,7 +236,11 @@ check_image (boost::filesystem::path ref, boost::filesystem::path check) ref_image.read (ref.string ()); Magick::Image check_image; check_image.read (check.string ()); - BOOST_CHECK_MESSAGE (ref_image.compare (check_image), ref << " differs from " << check); + BOOST_CHECK_MESSAGE ( + !ref_image.compare(check_image), + ref << " differs from " << check << " " + << ref_image.meanErrorPerPixel() << " " << ref_image.normalizedMaxError() << " " << ref_image.normalizedMeanError() + ); } void @@ -392,53 +426,44 @@ write_image (shared_ptr image, boost::filesystem::path file, string m.write (file.string ()); } -class Reader +void +check_ffmpeg (boost::filesystem::path ref, boost::filesystem::path check) { -public: - Reader (boost::filesystem::path file) - { - format_context = avformat_alloc_context (); - BOOST_REQUIRE (format_context); - BOOST_REQUIRE (avformat_open_input (&format_context, file.string().c_str(), 0, 0) >= 0); - BOOST_REQUIRE (avformat_find_stream_info (format_context, 0) >= 0); - } - - ~Reader () - { - avformat_close_input (&format_context); - } - - AVFormatContext* format_context; -}; - + int const r = system (string("ffcmp " + ref.string() + " " + check.string()).c_str()); + BOOST_REQUIRE_EQUAL (WEXITSTATUS(r), 0); +} void -check_ffmpeg (boost::filesystem::path ref, boost::filesystem::path check, int skip_packet_stream) +check_one_frame (boost::filesystem::path dcp_dir, int64_t index, boost::filesystem::path ref) { - Reader ref_r (ref); - Reader check_r (check); + dcp::DCP dcp (dcp_dir); + dcp.read (); + shared_ptr asset = dynamic_pointer_cast (dcp.cpls().front()->reels().front()->main_picture()->asset()); + BOOST_REQUIRE (asset); + shared_ptr frame = asset->start_read()->get_frame(index); - BOOST_REQUIRE_EQUAL (ref_r.format_context->nb_streams, check_r.format_context->nb_streams); + boost::uintmax_t const ref_size = boost::filesystem::file_size(ref); + BOOST_CHECK_EQUAL (frame->j2k_size(), ref_size); - AVPacket ref_p; - AVPacket check_p; + FILE* ref_file = fopen_boost(ref, "rb"); + BOOST_REQUIRE (ref_file); - bool skipped = false; + uint8_t* ref_data = new uint8_t[ref_size]; + fread (ref_data, ref_size, 1, ref_file); + fclose (ref_file); - while (true) { - int p = av_read_frame (ref_r.format_context, &ref_p); - int q = av_read_frame (check_r.format_context, &check_p); - if (ref_p.stream_index == skip_packet_stream && check_p.stream_index == skip_packet_stream && !skipped) { - skipped = true; - continue; - } - BOOST_REQUIRE_EQUAL (p, q); - BOOST_REQUIRE (p == 0 || p == AVERROR_EOF); - if (p == AVERROR_EOF) { - break; - } + BOOST_CHECK (memcmp(ref_data, frame->j2k_data(), ref_size) == 0); + delete[] ref_data; +} - BOOST_REQUIRE_EQUAL (ref_p.buf->size, check_p.buf->size); - BOOST_REQUIRE_EQUAL (memcmp (ref_p.buf->data, check_p.buf->data, ref_p.buf->size), 0); +boost::filesystem::path +dcp_file (shared_ptr film, string prefix) +{ + boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->dir(film->dcp_name())); + while (i != boost::filesystem::directory_iterator() && !boost::algorithm::starts_with (i->path().leaf().string(), prefix)) { + ++i; } + + BOOST_REQUIRE (i != boost::filesystem::directory_iterator()); + return i->path(); }