From 62f9fadc0424dfab6debcc342a210b33c5e189e6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 9 Sep 2020 23:18:28 +0200 Subject: [PATCH] Move make_simple() into test.{cc,h} --- test/dcp_test.cc | 63 ------------------------------------- test/test.cc | 81 ++++++++++++++++++++++++++++++++++++++++++++++-- test/test.h | 7 ++++- 3 files changed, 85 insertions(+), 66 deletions(-) diff --git a/test/dcp_test.cc b/test/dcp_test.cc index 41dba033..4ac924e0 100644 --- a/test/dcp_test.cc +++ b/test/dcp_test.cc @@ -54,69 +54,6 @@ using std::string; using boost::shared_ptr; -static shared_ptr -make_simple (boost::filesystem::path path) -{ - /* Some known metadata */ - dcp::XMLMetadata xml_meta; - xml_meta.annotation_text = "A Test DCP"; - xml_meta.issuer = "OpenDCP 0.0.25"; - xml_meta.creator = "OpenDCP 0.0.25"; - xml_meta.issue_date = "2012-07-17T04:45:18+00:00"; - dcp::MXFMetadata mxf_meta; - mxf_meta.company_name = "OpenDCP"; - mxf_meta.product_name = "OpenDCP"; - mxf_meta.product_version = "0.0.25"; - - /* We're making build/test/DCP/dcp_test1 */ - boost::filesystem::remove_all (path); - boost::filesystem::create_directories (path); - shared_ptr d (new dcp::DCP (path)); - shared_ptr cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE)); - cpl->set_content_version_id ("urn:uuid:75ac29aa-42ac-1234-ecae-49251abefd11"); - cpl->set_content_version_label_text ("content-version-label-text"); - cpl->set_metadata (xml_meta); - - shared_ptr mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::SMPTE)); - mp->set_metadata (mxf_meta); - shared_ptr picture_writer = mp->start_write (path / "video.mxf", false); - dcp::File j2c ("test/data/32x32_red_square.j2c"); - for (int i = 0; i < 24; ++i) { - picture_writer->write (j2c.data (), j2c.size ()); - } - picture_writer->finalize (); - - shared_ptr ms (new dcp::SoundAsset (dcp::Fraction (24, 1), 48000, 1, dcp::SMPTE)); - ms->set_metadata (mxf_meta); - shared_ptr sound_writer = ms->start_write (path / "audio.mxf"); - - SF_INFO info; - info.format = 0; - SNDFILE* sndfile = sf_open ("test/data/1s_24-bit_48k_silence.wav", SFM_READ, &info); - BOOST_CHECK (sndfile); - float buffer[4096*6]; - float* channels[1]; - channels[0] = buffer; - while (1) { - sf_count_t N = sf_readf_float (sndfile, buffer, 4096); - sound_writer->write (channels, N); - if (N < 4096) { - break; - } - } - - sound_writer->finalize (); - - cpl->add (shared_ptr ( - new dcp::Reel ( - shared_ptr (new dcp::ReelMonoPictureAsset (mp, 0)), - shared_ptr (new dcp::ReelSoundAsset (ms, 0)) - ) - )); - - d->add (cpl); - return d; -} /** Test creation of a 2D SMPTE DCP from very simple inputs */ BOOST_AUTO_TEST_CASE (dcp_test1) diff --git a/test/test.cc b/test/test.cc index b5b2535f..a53eedc9 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2019 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This file is part of libdcp. @@ -33,10 +33,21 @@ #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE libdcp_test -#include "util.h" +#include "cpl.h" +#include "dcp.h" +#include "file.h" +#include "mono_picture_asset.h" +#include "picture_asset_writer.h" +#include "reel.h" +#include "reel_mono_picture_asset.h" +#include "reel_sound_asset.h" +#include "sound_asset.h" +#include "sound_asset_writer.h" #include "test.h" +#include "util.h" #include #include +#include #include #include #include @@ -45,6 +56,7 @@ using std::string; using std::min; using std::list; +using boost::shared_ptr; boost::filesystem::path private_test; boost::filesystem::path xsd_test = "build/test/xsd with spaces"; @@ -190,4 +202,69 @@ RNGFixer::~RNGFixer () } +shared_ptr +make_simple (boost::filesystem::path path) +{ + /* Some known metadata */ + dcp::XMLMetadata xml_meta; + xml_meta.annotation_text = "A Test DCP"; + xml_meta.issuer = "OpenDCP 0.0.25"; + xml_meta.creator = "OpenDCP 0.0.25"; + xml_meta.issue_date = "2012-07-17T04:45:18+00:00"; + dcp::MXFMetadata mxf_meta; + mxf_meta.company_name = "OpenDCP"; + mxf_meta.product_name = "OpenDCP"; + mxf_meta.product_version = "0.0.25"; + + /* We're making build/test/DCP/dcp_test1 */ + boost::filesystem::remove_all (path); + boost::filesystem::create_directories (path); + shared_ptr d (new dcp::DCP (path)); + shared_ptr cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE)); + cpl->set_content_version_id ("urn:uuid:75ac29aa-42ac-1234-ecae-49251abefd11"); + cpl->set_content_version_label_text ("content-version-label-text"); + cpl->set_metadata (xml_meta); + + shared_ptr mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::SMPTE)); + mp->set_metadata (mxf_meta); + shared_ptr picture_writer = mp->start_write (path / "video.mxf", false); + dcp::File j2c ("test/data/32x32_red_square.j2c"); + for (int i = 0; i < 24; ++i) { + picture_writer->write (j2c.data (), j2c.size ()); + } + picture_writer->finalize (); + + shared_ptr ms (new dcp::SoundAsset (dcp::Fraction (24, 1), 48000, 1, dcp::SMPTE)); + ms->set_metadata (mxf_meta); + shared_ptr sound_writer = ms->start_write (path / "audio.mxf"); + + SF_INFO info; + info.format = 0; + SNDFILE* sndfile = sf_open ("test/data/1s_24-bit_48k_silence.wav", SFM_READ, &info); + BOOST_CHECK (sndfile); + float buffer[4096*6]; + float* channels[1]; + channels[0] = buffer; + while (true) { + sf_count_t N = sf_readf_float (sndfile, buffer, 4096); + sound_writer->write (channels, N); + if (N < 4096) { + break; + } + } + + sound_writer->finalize (); + + cpl->add (shared_ptr ( + new dcp::Reel ( + shared_ptr (new dcp::ReelMonoPictureAsset (mp, 0)), + shared_ptr (new dcp::ReelSoundAsset (ms, 0)) + ) + )); + + d->add (cpl); + return d; +} + + BOOST_GLOBAL_FIXTURE (TestConfig); diff --git a/test/test.h b/test/test.h index db33067c..4d53d49f 100644 --- a/test/test.h +++ b/test/test.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This file is part of libdcp. @@ -23,12 +23,17 @@ namespace xmlpp { class Element; } +namespace dcp { + class DCP; +} + extern boost::filesystem::path private_test; extern boost::filesystem::path xsd_test; extern void check_xml (xmlpp::Element* ref, xmlpp::Element* test, std::list ignore); extern void check_xml (std::string ref, std::string test, std::list ignore); extern void check_file (boost::filesystem::path ref, boost::filesystem::path check); +extern boost::shared_ptr make_simple (boost::filesystem::path path); /** Creating an object of this class will make asdcplib's random number generation * (more) predictable. -- 2.30.2