Clarify success message from dcpverify a little.
[libdcp.git] / test / test.cc
index a64725401ed030a16a6eae9920ef29ba7ca07f9e..2dac199fe316f62aa9115e5cfb683e0a27eb5ee3 100644 (file)
@@ -37,6 +37,7 @@
 #include "cpl.h"
 #include "dcp.h"
 #include "interop_subtitle_asset.h"
+#include "file.h"
 #include "j2k_transcode.h"
 #include "mono_picture_asset.h"
 #include "mono_picture_asset.h"
@@ -210,25 +211,25 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check)
 {
        uintmax_t size = boost::filesystem::file_size (ref);
        BOOST_CHECK_EQUAL (size, boost::filesystem::file_size(check));
-       auto ref_file = dcp::fopen_boost (ref, "rb");
+       dcp::File ref_file(ref, "rb");
        BOOST_REQUIRE (ref_file);
-       auto check_file = dcp::fopen_boost (check, "rb");
+       dcp::File check_file(check, "rb");
        BOOST_REQUIRE (check_file);
 
        int const buffer_size = 65536;
-       auto ref_buffer = new uint8_t[buffer_size];
-       auto check_buffer = new uint8_t[buffer_size];
+       std::vector<uint8_t> ref_buffer(buffer_size);
+       std::vector<uint8_t> check_buffer(buffer_size);
 
        uintmax_t pos = 0;
 
        while (pos < size) {
                uintmax_t this_time = min (uintmax_t(buffer_size), size - pos);
-               size_t r = fread (ref_buffer, 1, this_time, ref_file);
+               size_t r = ref_file.read(ref_buffer.data(), 1, this_time);
                BOOST_CHECK_EQUAL (r, this_time);
-               r = fread (check_buffer, 1, this_time, check_file);
+               r = check_file.read(check_buffer.data(), 1, this_time);
                BOOST_CHECK_EQUAL (r, this_time);
 
-               if (memcmp(ref_buffer, check_buffer, this_time) != 0) {
+               if (memcmp(ref_buffer.data(), check_buffer.data(), this_time) != 0) {
                        for (int i = 0; i < buffer_size; ++i) {
                                if (ref_buffer[i] != check_buffer[i]) {
                                        BOOST_CHECK_MESSAGE (
@@ -243,12 +244,6 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check)
 
                pos += this_time;
        }
-
-       delete[] ref_buffer;
-       delete[] check_buffer;
-
-       fclose (ref_file);
-       fclose (check_file);
 }
 
 
@@ -278,7 +273,7 @@ simple_picture (boost::filesystem::path path, string suffix, int frames, optiona
        if (key) {
                mp->set_key (*key);
        }
-       auto picture_writer = mp->start_write (path / dcp::String::compose("video%1.mxf", suffix), false);
+       auto picture_writer = mp->start_write(path / dcp::String::compose("video%1.mxf", suffix), dcp::PictureAsset::Behaviour::MAKE_NEW);
 
        dcp::Size const size (1998, 1080);
        auto image = make_shared<dcp::OpenJPEGImage>(size);
@@ -297,10 +292,8 @@ simple_picture (boost::filesystem::path path, string suffix, int frames, optiona
 
 
 shared_ptr<dcp::SoundAsset>
-simple_sound (boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_meta, string language, int frames, int sample_rate, optional<dcp::Key> key)
+simple_sound(boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_meta, string language, int frames, int sample_rate, optional<dcp::Key> key, int channels)
 {
-       int const channels = 6;
-
        /* Set a valid language, then overwrite it, so that the language parameter can be badly formed */
        auto ms = make_shared<dcp::SoundAsset>(dcp::Fraction(24, 1), sample_rate, channels, dcp::LanguageTag("en-US"), dcp::Standard::SMPTE);
        if (key) {
@@ -308,7 +301,7 @@ simple_sound (boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_
        }
        ms->_language = language;
        ms->set_metadata (mxf_meta);
-       shared_ptr<dcp::SoundAssetWriter> sound_writer = ms->start_write (path / dcp::String::compose("audio%1.mxf", suffix));
+       auto sound_writer = ms->start_write(path / dcp::String::compose("audio%1.mxf", suffix), {}, dcp::SoundAsset::AtmosSync::DISABLED, dcp::SoundAsset::MCASubDescriptors::ENABLED);
 
        int const samples_per_frame = sample_rate / 24;
 
@@ -319,7 +312,7 @@ simple_sound (boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_
        }
 
        for (auto i = 0; i < frames; ++i) {
-               sound_writer->write (silence, samples_per_frame);
+               sound_writer->write(silence, channels, samples_per_frame);
        }
 
        sound_writer->finalize ();
@@ -354,7 +347,7 @@ make_simple (boost::filesystem::path path, int reels, int frames, dcp::Standard
        cpl->set_content_version (
                dcp::ContentVersion("urn:uuid:75ac29aa-42ac-1234-ecae-49251abefd11", "content-version-label-text")
                );
-       cpl->set_main_sound_configuration("51/L,R,C,LFE,Ls,Rs");
+       cpl->set_main_sound_configuration(dcp::MainSoundConfiguration("51/L,R,C,LFE,Ls,Rs"));
        cpl->set_main_sound_sample_rate(sample_rate);
        cpl->set_main_picture_stored_area(dcp::Size(1998, 1080));
        cpl->set_main_picture_active_area(dcp::Size(1998, 1080));
@@ -371,7 +364,7 @@ make_simple (boost::filesystem::path path, int reels, int frames, dcp::Standard
                        shared_ptr<dcp::ReelSoundAsset>(new dcp::ReelSoundAsset(ms, 0))
                        );
 
-               auto markers = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(24, 1), frames, 0);
+               auto markers = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(24, 1), frames);
                if (i == 0) {
                        markers->set (dcp::Marker::FFOC, dcp::Time(0, 0, 0, 1, 24));
                }
@@ -391,7 +384,7 @@ make_simple (boost::filesystem::path path, int reels, int frames, dcp::Standard
 shared_ptr<dcp::Subtitle>
 simple_subtitle ()
 {
-       return make_shared<dcp::SubtitleString>(
+       return std::make_shared<dcp::SubtitleString>(
                optional<string>(),
                false,
                false,
@@ -405,6 +398,7 @@ simple_subtitle ()
                dcp::HAlign::CENTER,
                0.8,
                dcp::VAlign::TOP,
+               0,
                dcp::Direction::LTR,
                "Hello world",
                dcp::Effect::NONE,
@@ -419,7 +413,7 @@ simple_subtitle ()
 shared_ptr<dcp::ReelMarkersAsset>
 simple_markers (int frames)
 {
-       auto markers = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(24, 1), frames, 0);
+       auto markers = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(24, 1), frames);
        markers->set (dcp::Marker::FFOC, dcp::Time(1, 24, 24));
        markers->set (dcp::Marker::LFOC, dcp::Time(frames - 1, 24, 24));
        return markers;
@@ -436,6 +430,7 @@ make_simple_with_interop_subs (boost::filesystem::path path)
 
        boost::filesystem::create_directory (path / "subs");
        dcp::ArrayData data(4096);
+       memset(data.data(), 0, data.size());
        subs->add_font ("afont", data);
        subs->write (path / "subs" / "subs.xml");
 
@@ -521,7 +516,7 @@ black_picture_asset (boost::filesystem::path dir, int frames)
        auto asset = make_shared<dcp::MonoPictureAsset>(dcp::Fraction(24, 1), dcp::Standard::SMPTE);
        asset->set_metadata (dcp::MXFMetadata("libdcp", "libdcp", "1.6.4devel"));
        boost::filesystem::create_directories (dir);
-       auto writer = asset->start_write (dir / "pic.mxf", true);
+       auto writer = asset->start_write(dir / "pic.mxf", dcp::PictureAsset::Behaviour::MAKE_NEW);
        for (int i = 0; i < frames; ++i) {
                writer->write (frame.data(), frame.size());
        }