Use an enum instead of a bool in PictureAsset::start_write().
[libdcp.git] / test / decryption_test.cc
index 0f32a6f46bc2e9109f77896e3ef1199ae6e65318..1e2ca94beedb4a10e2373d05449ad20ce6fd20af 100644 (file)
 
 using std::dynamic_pointer_cast;
 using std::make_pair;
-using std::make_shared;
 using std::map;
 using std::pair;
 using std::shared_ptr;
 using std::string;
+using std::vector;
 using boost::optional;
 using boost::scoped_array;
 
 
-pair<uint8_t*, dcp::Size>
+pair<vector<uint8_t>, dcp::Size>
 get_frame (dcp::DCP const & dcp)
 {
-       shared_ptr<const dcp::Reel> reel = dcp.cpls().front()->reels().front ();
-       shared_ptr<dcp::PictureAsset> picture = reel->main_picture()->asset ();
+       auto reel = dcp.cpls().front()->reels()[0];
+       auto picture = reel->main_picture()->asset();
        BOOST_CHECK (picture);
 
-       shared_ptr<const dcp::MonoPictureAsset> mono_picture = dynamic_pointer_cast<const dcp::MonoPictureAsset> (picture);
-       shared_ptr<const dcp::MonoPictureAssetReader> reader = mono_picture->start_read ();
-       shared_ptr<const dcp::MonoPictureFrame> j2k_frame = reader->get_frame (0);
-       shared_ptr<dcp::OpenJPEGImage> xyz = j2k_frame->xyz_image();
+       auto mono_picture = dynamic_pointer_cast<const dcp::MonoPictureAsset>(picture);
+       auto reader = mono_picture->start_read();
+       auto j2k_frame = reader->get_frame(0);
+       auto xyz = j2k_frame->xyz_image();
 
-       uint8_t* argb = new uint8_t[xyz->size().width * xyz->size().height * 4];
-       dcp::xyz_to_rgba (j2k_frame->xyz_image(), dcp::ColourConversion::srgb_to_xyz(), argb, xyz->size().width * 4);
+       std::vector<uint8_t> argb(xyz->size().width * xyz->size().height * 4);
+       dcp::xyz_to_rgba(j2k_frame->xyz_image(), dcp::ColourConversion::srgb_to_xyz(), argb.data(), xyz->size().width * 4);
        return make_pair (argb, xyz->size ());
 }
 
 /** Decrypt an encrypted test DCP and check that its first frame is the same as the unencrypted version */
 BOOST_AUTO_TEST_CASE (decryption_test1)
 {
-       boost::filesystem::path plaintext_path = private_test;
+       auto plaintext_path = private_test;
        plaintext_path /= "TONEPLATES-SMPTE-PLAINTEXT_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV";
        dcp::DCP plaintext (plaintext_path.string ());
        plaintext.read ();
        BOOST_CHECK_EQUAL (plaintext.any_encrypted(), false);
 
-       boost::filesystem::path encrypted_path = private_test;
+       auto encrypted_path = private_test;
        encrypted_path /= "TONEPLATES-SMPTE-ENCRYPTED_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV";
        dcp::DCP encrypted (encrypted_path.string ());
        encrypted.read ();
@@ -114,8 +114,8 @@ BOOST_AUTO_TEST_CASE (decryption_test1)
 
        encrypted.add (kdm);
 
-       pair<uint8_t *, dcp::Size> plaintext_frame = get_frame (plaintext);
-       pair<uint8_t *, dcp::Size> encrypted_frame = get_frame (encrypted);
+       auto plaintext_frame = get_frame(plaintext);
+       auto encrypted_frame = get_frame(encrypted);
 
        /* Check that plaintext and encrypted are the same */
 
@@ -123,15 +123,12 @@ BOOST_AUTO_TEST_CASE (decryption_test1)
 
        BOOST_CHECK_EQUAL (
                memcmp (
-                       plaintext_frame.first,
-                       encrypted_frame.first,
+                       plaintext_frame.first.data(),
+                       encrypted_frame.first.data(),
                        plaintext_frame.second.width * plaintext_frame.second.height * 4
                        ),
                0
                );
-
-       delete[] plaintext_frame.first;
-       delete[] encrypted_frame.first;
 }
 
 /** Load in a KDM that didn't work at first */
@@ -139,7 +136,7 @@ BOOST_AUTO_TEST_CASE (failing_kdm_test)
 {
        dcp::DecryptedKDM kdm (
                dcp::EncryptedKDM (dcp::file_to_string ("test/data/target.pem.crt.de5d4eba-e683-41ca-bdda-aa4ad96af3f4.kdm.xml")),
-               dcp::file_to_string ("test/data/private.key")
+               dcp::file_to_string("test/data/failing-private.key")
                );
 }
 
@@ -155,20 +152,20 @@ BOOST_AUTO_TEST_CASE (decryption_test2)
        auto context_id = dcp::make_uuid();
        dcp::Key key;
 
-       auto picture_asset = make_shared<dcp::MonoPictureAsset>(dcp::Fraction(24, 1), dcp::Standard::SMPTE);
+       auto picture_asset = std::make_shared<dcp::MonoPictureAsset>(dcp::Fraction(24, 1), dcp::Standard::SMPTE);
        picture_asset->set_key (key);
        picture_asset->set_context_id (context_id);
-       auto picture_writer = picture_asset->start_write(dir / "picture.mxf", false);
+       auto picture_writer = picture_asset->start_write(dir / "picture.mxf", dcp::PictureAsset::Behaviour::MAKE_NEW);
        dcp::ArrayData picture("test/data/flat_red.j2c");
        for (int i = 0; i < 24; ++i) {
                picture_writer->write(picture);
        }
        picture_writer->finalize();
 
-       auto sound_asset = make_shared<dcp::SoundAsset>(dcp::Fraction(24, 1), 48000, 2, dcp::LanguageTag("en-GB"), dcp::Standard::SMPTE);
+       auto sound_asset = std::make_shared<dcp::SoundAsset>(dcp::Fraction(24, 1), 48000, 2, dcp::LanguageTag("en-GB"), dcp::Standard::SMPTE);
        sound_asset->set_key (key);
        sound_asset->set_context_id (context_id);
-       auto sound_writer = sound_asset->start_write(dir / "sound.mxf");
+       auto sound_writer = sound_asset->start_write(dir / "sound.mxf", {}, dcp::SoundAsset::AtmosSync::DISABLED, dcp::SoundAsset::MCASubDescriptors::ENABLED);
        std::array<float, 48000> left;
        std::array<float, 48000> right;
        for (int i = 0; i < 48000; ++i) {
@@ -178,13 +175,13 @@ BOOST_AUTO_TEST_CASE (decryption_test2)
        std::array<float*, 2> audio;
        audio[0] = left.data();
        audio[1] = right.data();
-       sound_writer->write (audio.data(), 48000);
+       sound_writer->write(audio.data(), 2, 48000);
        sound_writer->finalize ();
 
-       auto subs_asset = make_shared<dcp::SMPTESubtitleAsset>();
+       auto subs_asset = std::make_shared<dcp::SMPTESubtitleAsset>();
        subs_asset->set_key (key);
        subs_asset->set_context_id (context_id);
-       subs_asset->add(make_shared<dcp::SubtitleString>(
+       subs_asset->add(std::make_shared<dcp::SubtitleString>(
                optional<string>(),
                false, false, false,
                dcp::Colour(255, 255, 255),
@@ -203,10 +200,10 @@ BOOST_AUTO_TEST_CASE (decryption_test2)
                ));
        subs_asset->write (dir / "subs.mxf");
 
-       auto reel = make_shared<dcp::Reel>();
-       auto reel_picture_asset = make_shared<dcp::ReelMonoPictureAsset>(picture_asset, 0);
-       auto reel_sound_asset = make_shared<dcp::ReelSoundAsset>(sound_asset, 0);
-       auto reel_subs_asset = make_shared<dcp::ReelSMPTESubtitleAsset>(subs_asset, dcp::Fraction(24, 1), 120, 0);
+       auto reel = std::make_shared<dcp::Reel>();
+       auto reel_picture_asset = std::make_shared<dcp::ReelMonoPictureAsset>(picture_asset, 0);
+       auto reel_sound_asset = std::make_shared<dcp::ReelSoundAsset>(sound_asset, 0);
+       auto reel_subs_asset = std::make_shared<dcp::ReelSMPTESubtitleAsset>(subs_asset, dcp::Fraction(24, 1), 120, 0);
        reel->add(reel_picture_asset);
        reel->add(reel_sound_asset);
        reel->add(reel_subs_asset);