Remove Image and ARGBImage and just dump RGB data into
[libdcp.git] / test / round_trip_test.cc
index 899734f48ac1893c7fe96c8884450f43e1e461f8..dcaa6939999326d39b2c6b0b4ca8a70d43df6718 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #include "test.h"
 #include "cpl.h"
 #include "mono_picture_frame.h"
-#include "argb_frame.h"
-#include "signer_chain.h"
+#include "certificate_chain.h"
 #include "mono_picture_mxf_writer.h"
 #include "reel_picture_asset.h"
 #include "reel_mono_picture_asset.h"
 #include "file.h"
+#include "xyz_image.h"
+#include "rgb_xyz.h"
+#include "colour_conversion.h"
 #include <boost/test/unit_test.hpp>
+#include <boost/scoped_array.hpp>
 #include <iostream>
 
 using std::list;
 using boost::shared_ptr;
+using boost::scoped_array;
 
 /* Build an encrypted picture MXF and a KDM for it and check that the KDM can be decrypted */
 BOOST_AUTO_TEST_CASE (round_trip_test)
 {
-       boost::filesystem::remove_all ("build/test/signer");
-       boost::filesystem::create_directory ("build/test/signer");
-       dcp::make_signer_chain ("build/test/signer", "openssl");
-       
-       dcp::CertificateChain chain;
-       chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("build/test/signer/ca.self-signed.pem"))));
-       chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("build/test/signer/intermediate.signed.pem"))));
-       chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("build/test/signer/leaf.signed.pem"))));
-
-       shared_ptr<dcp::Signer> signer (
-               new dcp::Signer (
-                       chain,
-                       dcp::file_to_string ("test/data/signer.key")
-                       )
-               );
+       shared_ptr<dcp::Signer> signer (new dcp::Signer ("openssl"));
 
        boost::filesystem::path work_dir = "build/test/round_trip_test";
        boost::filesystem::create_directory (work_dir);
@@ -81,6 +71,7 @@ BOOST_AUTO_TEST_CASE (round_trip_test)
        /* A KDM using our certificate chain's leaf key pair */
        dcp::DecryptedKDM kdm_A (
                cpl,
+               key,
                dcp::LocalTime ("2013-01-01T00:00:00+00:00"),
                dcp::LocalTime ("2013-01-08T00:00:00+00:00"),
                "libdcp",
@@ -93,7 +84,7 @@ BOOST_AUTO_TEST_CASE (round_trip_test)
        kdm_A.encrypt(signer, signer->certificates().leaf(), dcp::MODIFIED_TRANSITIONAL_1).as_xml (kdm_file);
 
        /* Reload the KDM, using our private key to decrypt it */
-       dcp::DecryptedKDM kdm_B (dcp::EncryptedKDM (kdm_file), "build/test/signer/leaf.key");
+       dcp::DecryptedKDM kdm_B (dcp::EncryptedKDM (dcp::file_to_string (kdm_file)), signer->key ());
 
        /* Check that the decrypted KDMKeys are the same as the ones we started with */
        BOOST_CHECK_EQUAL (kdm_A.keys().size(), kdm_B.keys().size());
@@ -115,9 +106,16 @@ BOOST_AUTO_TEST_CASE (round_trip_test)
        BOOST_CHECK (!kdm_B.keys().empty ());
        mxf_B->set_key (kdm_B.keys().front().key());
 
-       shared_ptr<dcp::ARGBFrame> frame_A = mxf_A->get_frame(0)->argb_frame ();
-       shared_ptr<dcp::ARGBFrame> frame_B = mxf_B->get_frame(0)->argb_frame ();
-       BOOST_CHECK_EQUAL (frame_A->size().width, frame_B->size().width);
-       BOOST_CHECK_EQUAL (frame_A->size().height, frame_B->size().height);
-       BOOST_CHECK_EQUAL (memcmp (frame_A->data(), frame_B->data(), frame_A->size().width * frame_A->size().height), 0);
+       shared_ptr<dcp::XYZImage> xyz_A = mxf_A->get_frame(0)->xyz_image ();
+       shared_ptr<dcp::XYZImage> xyz_B = mxf_B->get_frame(0)->xyz_image ();
+
+       scoped_array<uint8_t> frame_A (new uint8_t[xyz_A->size().width * xyz_A->size().height * 4]);
+       dcp::xyz_to_rgba (xyz_A, dcp::ColourConversion::xyz_to_srgb(), frame_A.get());
+       
+       scoped_array<uint8_t> frame_B (new uint8_t[xyz_B->size().width * xyz_B->size().height * 4]);
+       dcp::xyz_to_rgba (xyz_B, dcp::ColourConversion::xyz_to_srgb(), frame_B.get());
+
+       BOOST_CHECK_EQUAL (xyz_A->size().width, xyz_B->size().width);
+       BOOST_CHECK_EQUAL (xyz_A->size().height, xyz_B->size().height);
+       BOOST_CHECK_EQUAL (memcmp (frame_A.get(), frame_B.get(), xyz_A->size().width * xyz_A->size().height * 4), 0);
 }