Move make_simple() into test.{cc,h}
authorCarl Hetherington <cth@carlh.net>
Wed, 9 Sep 2020 21:18:28 +0000 (23:18 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 9 Sep 2020 21:18:28 +0000 (23:18 +0200)
test/dcp_test.cc
test/test.cc
test/test.h

index 41dba0334ba640560362880e7a864f3856d384ad..4ac924e086bf3af1c017124eecbe15e00ca75721 100644 (file)
 using std::string;
 using boost::shared_ptr;
 
-static shared_ptr<dcp::DCP>
-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<dcp::DCP> d (new dcp::DCP (path));
-       shared_ptr<dcp::CPL> 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<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::SMPTE));
-       mp->set_metadata (mxf_meta);
-       shared_ptr<dcp::PictureAssetWriter> 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<dcp::SoundAsset> ms (new dcp::SoundAsset (dcp::Fraction (24, 1), 48000, 1, dcp::SMPTE));
-       ms->set_metadata (mxf_meta);
-       shared_ptr<dcp::SoundAssetWriter> 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<dcp::Reel> (
-                         new dcp::Reel (
-                                 shared_ptr<dcp::ReelMonoPictureAsset> (new dcp::ReelMonoPictureAsset (mp, 0)),
-                                 shared_ptr<dcp::ReelSoundAsset> (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)
index b5b2535f2f6052c4425e14d2c9551bb7819f3d92..a53eedc91aa0e406ea765fa238a3d7a7a48c050f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
 
 #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 <asdcp/KM_util.h>
 #include <asdcp/KM_prng.h>
+#include <sndfile.h>
 #include <libxml++/libxml++.h>
 #include <boost/test/unit_test.hpp>
 #include <cstdio>
@@ -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<dcp::DCP>
+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<dcp::DCP> d (new dcp::DCP (path));
+       shared_ptr<dcp::CPL> 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<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::SMPTE));
+       mp->set_metadata (mxf_meta);
+       shared_ptr<dcp::PictureAssetWriter> 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<dcp::SoundAsset> ms (new dcp::SoundAsset (dcp::Fraction (24, 1), 48000, 1, dcp::SMPTE));
+       ms->set_metadata (mxf_meta);
+       shared_ptr<dcp::SoundAssetWriter> 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<dcp::Reel> (
+                         new dcp::Reel (
+                                 shared_ptr<dcp::ReelMonoPictureAsset> (new dcp::ReelMonoPictureAsset (mp, 0)),
+                                 shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (ms, 0))
+                                 )
+                         ));
+
+       d->add (cpl);
+       return d;
+}
+
+
 BOOST_GLOBAL_FIXTURE (TestConfig);
index db33067c1b4c0f795bc23e3f10aff54bfb58cb4d..4d53d49fad3928e2b7253e2e4e5f5a8d60c2a4de 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
 
     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<std::string> ignore);
 extern void check_xml (std::string ref, std::string test, std::list<std::string> ignore);
 extern void check_file (boost::filesystem::path ref, boost::filesystem::path check);
+extern boost::shared_ptr<dcp::DCP> make_simple (boost::filesystem::path path);
 
 /** Creating an object of this class will make asdcplib's random number generation
  *  (more) predictable.