Check decryption works in the tests.
authorCarl Hetherington <cth@carlh.net>
Sun, 7 Jul 2013 23:13:12 +0000 (00:13 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 7 Jul 2013 23:13:12 +0000 (00:13 +0100)
test/decryption_test.cc

index 507d2efdc350a1728eacafa7a081e5d4d16f2ec4..7f91989887af0e4d47d6a298b15c1af52ecaf257 100644 (file)
 
 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);
 }