diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-09-25 17:19:59 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-09-25 17:19:59 +0100 |
| commit | e563727ee7b72881ee163db9b777559c8ceb5074 (patch) | |
| tree | 691966d59ee49912c6c020f67759ee13ece0a925 /test | |
| parent | 43465aa4037cec6d351a842a6624a50685d6c127 (diff) | |
Add round-trip KDM test. Fix various bugs in KDM generation. Some string -> path.
Diffstat (limited to 'test')
| -rw-r--r-- | test/error_test.cc | 2 | ||||
| -rw-r--r-- | test/round_trip_test.cc | 96 | ||||
| -rw-r--r-- | test/test.cc | 4 | ||||
| -rw-r--r-- | test/test.h | 4 | ||||
| -rw-r--r-- | test/wscript | 1 |
5 files changed, 102 insertions, 5 deletions
diff --git a/test/error_test.cc b/test/error_test.cc index 6992acff..a0f6a0f3 100644 --- a/test/error_test.cc +++ b/test/error_test.cc @@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE (error_test) libdcp::DCP d ("build/test/fred"); /* Random filename that does not exist */ - vector<string> p; + vector<boost::filesystem::path> p; p.push_back ("frobozz"); /* Trying to create video/audio MXFs using a non-existant file should throw an exception */ diff --git a/test/round_trip_test.cc b/test/round_trip_test.cc new file mode 100644 index 00000000..96563ee8 --- /dev/null +++ b/test/round_trip_test.cc @@ -0,0 +1,96 @@ +/* + Copyright (C) 2013 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <iostream> +#include <boost/test/unit_test.hpp> +#include "certificates.h" +#include "kdm.h" +#include "signer.h" +#include "picture_asset.h" +#include "sound_asset.h" +#include "reel.h" +#include "test.h" +#include "cpl.h" +#include "picture_frame.h" +#include "argb_frame.h" + +using boost::shared_ptr; + +/* 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) +{ + libdcp::CertificateChain chain; + chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("build/test/signer/ca.self-signed.pem")))); + chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("build/test/signer/intermediate.signed.pem")))); + chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("build/test/signer/leaf.signed.pem")))); + + shared_ptr<libdcp::Signer> signer ( + new libdcp::Signer ( + chain, + "test/data/signer.key" + ) + ); + + boost::filesystem::path work_dir = "build/test/round_trip_test"; + boost::filesystem::create_directory (work_dir); + + libdcp::MXFMetadata mxf_metadata; + + shared_ptr<libdcp::MonoPictureAsset> asset_A ( + new libdcp::MonoPictureAsset (j2c, work_dir, "video.mxf", 0, 24, 24, libdcp::Size (32, 32), false, mxf_metadata) + ); + + libdcp::Key key; + + asset_A->set_key (key); + + shared_ptr<libdcp::CPL> cpl (new libdcp::CPL (work_dir, "A Test DCP", libdcp::FEATURE, 24, 24)); + cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (asset_A, shared_ptr<libdcp::SoundAsset> (), shared_ptr<libdcp::SubtitleAsset> ()))); + + /* A KDM using our certificate chain's leaf key pair */ + libdcp::KDM kdm_A ( + cpl, + signer, + signer->certificates().leaf(), + boost::posix_time::time_from_string ("2013-01-01 00:00:00"), + boost::posix_time::time_from_string ("2013-01-08 00:00:00"), + "libdcp", + "2012-07-17T04:45:18+00:00" + ); + + boost::filesystem::path const kdm_file = work_dir / "kdm.xml"; + + kdm_A.as_xml (kdm_file); + + /* Reload the KDM, using our private key to decrypt it */ + libdcp::KDM kdm_B (kdm_file, "build/test/signer/leaf.key"); + + /* Reload the picture MXF */ + shared_ptr<libdcp::MonoPictureAsset> asset_B ( + new libdcp::MonoPictureAsset (work_dir, "video.mxf") + ); + + asset_B->set_key (kdm_B.keys().front().key()); + + shared_ptr<libdcp::ARGBFrame> frame_A = asset_A->get_frame(0)->argb_frame (); + shared_ptr<libdcp::ARGBFrame> frame_B = asset_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); +} diff --git a/test/test.cc b/test/test.cc index 926eb0fb..72d0c7dd 100644 --- a/test/test.cc +++ b/test/test.cc @@ -34,13 +34,13 @@ struct TestConfig BOOST_GLOBAL_FIXTURE (TestConfig); -string +boost::filesystem::path j2c (int) { return "test/data/32x32_red_square.j2c"; } -string +boost::filesystem::path wav (libdcp::Channel) { return "test/data/1s_24-bit_48k_silence.wav"; diff --git a/test/test.h b/test/test.h index de790364..d6691bc0 100644 --- a/test/test.h +++ b/test/test.h @@ -17,6 +17,6 @@ */ -extern std::string j2c (int); -extern std::string wav (libdcp::Channel); +extern boost::filesystem::path j2c (int); +extern boost::filesystem::path wav (libdcp::Channel); extern std::string test_corpus; diff --git a/test/wscript b/test/wscript index ec70288b..c0250255 100644 --- a/test/wscript +++ b/test/wscript @@ -36,6 +36,7 @@ def build(bld): kdm_test.cc subtitle_tests.cc util_test.cc + round_trip_test.cc """ obj.target = 'tests' obj.install_path = '' |
