diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-07-08 00:13:12 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-07-08 00:13:12 +0100 |
| commit | 2ab45d37b7f67542540956cffabea5e41c59654c (patch) | |
| tree | 646e43926f843535778baf9b867ec05871b228cc /test/decryption_test.cc | |
| parent | 932b942a51bef4e2dd2de9f83aa5b68ad07f60f9 (diff) | |
Check decryption works in the tests.
Diffstat (limited to 'test/decryption_test.cc')
| -rw-r--r-- | test/decryption_test.cc | 63 |
1 files changed, 20 insertions, 43 deletions
diff --git a/test/decryption_test.cc b/test/decryption_test.cc index 507d2efd..7f919898 100644 --- a/test/decryption_test.cc +++ b/test/decryption_test.cc @@ -24,6 +24,19 @@ using boost::dynamic_pointer_cast; +static shared_ptr<const libdcp::ARGBFrame> +get_frame (libdcp::DCP const & dcp) +{ + shared_ptr<const libdcp::Reel> reel = dcp.cpls().front()->reels().front (); + shared_ptr<const libdcp::PictureAsset> picture = reel->main_picture (); + BOOST_CHECK (picture); + + shared_ptr<const libdcp::MonoPictureAsset> mono_picture = dynamic_pointer_cast<const libdcp::MonoPictureAsset> (picture); + shared_ptr<const libdcp::MonoPictureFrame> j2k_frame = mono_picture->get_frame (0); + return j2k_frame->argb_frame (); +} + +/** Decrypt an encrypted test DCP and check that its first frame is the same as the unencrypted version */ BOOST_AUTO_TEST_CASE (decryption_test) { boost::filesystem::path plaintext_path = test_corpus; @@ -45,48 +58,12 @@ BOOST_AUTO_TEST_CASE (decryption_test) encrypted.add_kdm (kdm); - shared_ptr<const libdcp::Reel> encrypted_reel = encrypted.cpls().front()->reels().front (); - shared_ptr<const libdcp::PictureAsset> encrypted_picture = encrypted_reel->main_picture (); - BOOST_CHECK (encrypted_picture); - - shared_ptr<const libdcp::MonoPictureAsset> encrypted_mono_picture = dynamic_pointer_cast<const libdcp::MonoPictureAsset> (encrypted_picture); - shared_ptr<const libdcp::MonoPictureFrame> j2k_frame = encrypted_mono_picture->get_frame (0); - - shared_ptr<const libdcp::ARGBFrame> argb_frame = j2k_frame->argb_frame (); - - - - uint8_t* tiff_frame = new uint8_t[1998 * 3 * 1080]; - - uint8_t* t = tiff_frame; - uint8_t* r = argb_frame->data (); - for (int y = 0; y < 1080; ++y) { - for (int x = 0; x < 1998; ++x) { - /* Our data is first-byte blue, second-byte green, third-byte red, fourth-byte alpha, - so we need to twiddle here. - */ - - t[0] = r[2]; // red - t[1] = r[1]; // green - t[2] = r[0]; // blue - t += 3; - r += 4; - } - } - - TIFF* output = TIFFOpen ("foo.tiff", "w"); - BOOST_CHECK (output); - - TIFFSetField (output, TIFFTAG_IMAGEWIDTH, 1998); - TIFFSetField (output, TIFFTAG_IMAGELENGTH, 1080); - TIFFSetField (output, TIFFTAG_COMPRESSION, COMPRESSION_NONE); - TIFFSetField (output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); - TIFFSetField (output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); - TIFFSetField (output, TIFFTAG_BITSPERSAMPLE, 8); - TIFFSetField (output, TIFFTAG_SAMPLESPERPIXEL, 3); - - BOOST_CHECK (TIFFWriteEncodedStrip (output, 0, tiff_frame, 1998 * 1080 * 3)); - TIFFClose (output); + shared_ptr<const libdcp::ARGBFrame> plaintext_frame = get_frame (plaintext); + shared_ptr<const libdcp::ARGBFrame> encrypted_frame = get_frame (encrypted); - delete[] tiff_frame; + /* Check that plaintext and encrypted are the same */ + BOOST_CHECK_EQUAL (plaintext_frame->stride(), encrypted_frame->stride()); + BOOST_CHECK_EQUAL (plaintext_frame->size().width, encrypted_frame->size().width); + BOOST_CHECK_EQUAL (plaintext_frame->size().height, encrypted_frame->size().height); + BOOST_CHECK_EQUAL (memcmp (plaintext_frame->data(), encrypted_frame->data(), plaintext_frame->stride() * plaintext_frame->size().height), 0); } |
