+using std::string;
+using std::vector;
+using std::dynamic_pointer_cast;
+using std::shared_ptr;
+using std::make_shared;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
+
+
+/** Test creation of a 2D SMPTE DCP from very simple inputs */
+BOOST_AUTO_TEST_CASE (dcp_test1)
+{
+ RNGFixer fixer;
+
+ auto dcp = make_simple("build/test/DCP/dcp_test1");
+ dcp->set_issuer("OpenDCP 0.0.25");
+ dcp->set_creator("OpenDCP 0.0.25");
+ dcp->set_issue_date("2012-07-17T04:45:18+00:00");
+ dcp->set_annotation_text("A Test DCP");
+ dcp->write_xml();
+
+ /* build/test/DCP/dcp_test1 is checked against test/ref/DCP/dcp_test1 by run/tests */
+}
+
+/** Test creation of a 3D DCP from very simple inputs */
+BOOST_AUTO_TEST_CASE (dcp_test2)
+{
+ RNGFixer fix;
+
+ /* Some known metadata */
+ 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_test2 */
+ boost::filesystem::remove_all ("build/test/DCP/dcp_test2");
+ boost::filesystem::create_directories ("build/test/DCP/dcp_test2");
+ dcp::DCP d ("build/test/DCP/dcp_test2");
+ auto cpl = make_shared<dcp::CPL>("A Test DCP", dcp::ContentKind::FEATURE, dcp::Standard::SMPTE);
+ cpl->set_content_version (
+ dcp::ContentVersion("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00", "81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00")
+ );
+ cpl->set_issuer ("OpenDCP 0.0.25");
+ cpl->set_creator ("OpenDCP 0.0.25");
+ cpl->set_issue_date ("2012-07-17T04:45:18+00:00");
+ cpl->set_annotation_text ("A Test DCP");
+
+ auto mp = make_shared<dcp::StereoPictureAsset>(dcp::Fraction (24, 1), dcp::Standard::SMPTE);
+ mp->set_metadata (mxf_meta);
+ auto picture_writer = mp->start_write ("build/test/DCP/dcp_test2/video.mxf", false);
+ dcp::ArrayData j2c ("test/data/flat_red.j2c");
+ for (int i = 0; i < 24; ++i) {
+ /* Left */
+ picture_writer->write (j2c.data (), j2c.size ());
+ /* Right */
+ picture_writer->write (j2c.data (), j2c.size ());
+ }
+ picture_writer->finalize ();
+
+ auto ms = make_shared<dcp::SoundAsset>(dcp::Fraction(24, 1), 48000, 1, dcp::LanguageTag("en-GB"), dcp::Standard::SMPTE);
+ ms->set_metadata (mxf_meta);
+ auto sound_writer = ms->start_write ("build/test/DCP/dcp_test2/audio.mxf");
+
+ SF_INFO info;
+ info.format = 0;
+ auto 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) {
+ auto N = sf_readf_float (sndfile, buffer, 4096);
+ sound_writer->write (channels, N);
+ if (N < 4096) {
+ break;
+ }
+ }
+
+ sound_writer->finalize ();
+
+ cpl->add (make_shared<dcp::Reel>(
+ make_shared<dcp::ReelStereoPictureAsset>(mp, 0),
+ make_shared<dcp::ReelSoundAsset>(ms, 0)
+ ));
+
+ d.add (cpl);
+
+ d.set_issuer("OpenDCP 0.0.25");
+ d.set_creator("OpenDCP 0.0.25");
+ d.set_issue_date("2012-07-17T04:45:18+00:00");
+ d.set_annotation_text("Created by libdcp");
+ d.write_xml();
+
+ /* build/test/DCP/dcp_test2 is checked against test/ref/DCP/dcp_test2 by run/tests */
+}
+
+static void
+note (dcp::NoteType, string)
+{
+
+}
+
+/** Test comparison of a DCP with itself */
+BOOST_AUTO_TEST_CASE (dcp_test3)
+{
+ dcp::DCP A ("test/ref/DCP/dcp_test1");
+ A.read ();
+ dcp::DCP B ("test/ref/DCP/dcp_test1");
+ B.read ();
+
+ BOOST_CHECK (A.equals (B, dcp::EqualityOptions(), boost::bind (¬e, _1, _2)));
+}
+
+/** Test comparison of a DCP with a different DCP */
+BOOST_AUTO_TEST_CASE (dcp_test4)
+{
+ dcp::DCP A ("test/ref/DCP/dcp_test1");
+ A.read ();
+ dcp::DCP B ("test/ref/DCP/dcp_test2");
+ B.read ();
+
+ BOOST_CHECK (!A.equals (B, dcp::EqualityOptions(), boost::bind (¬e, _1, _2)));
+}
+
+static
+void
+test_rewriting_sound(string name, bool modify)
+{
+ using namespace boost::filesystem;
+
+ dcp::DCP A ("test/ref/DCP/dcp_test1");
+ A.read ();
+
+ BOOST_REQUIRE (!A.cpls().empty());
+ BOOST_REQUIRE (!A.cpls().front()->reels().empty());
+ auto A_picture = dynamic_pointer_cast<dcp::ReelMonoPictureAsset>(A.cpls().front()->reels().front()->main_picture());
+ BOOST_REQUIRE (A_picture);
+ auto A_sound = dynamic_pointer_cast<dcp::ReelSoundAsset>(A.cpls().front()->reels().front()->main_sound());
+
+ string const picture = "j2c_5279f9aa-94d7-42a6-b0e0-e4eaec4e2a15.mxf";
+
+ remove_all ("build/test/" + name);
+ dcp::DCP B ("build/test/" + name);
+ auto reel = make_shared<dcp::Reel>();
+
+ BOOST_REQUIRE (A_picture->mono_asset());
+ BOOST_REQUIRE (A_picture->mono_asset()->file());
+ copy_file (A_picture->mono_asset()->file().get(), path("build") / "test" / name / picture);
+ reel->add(make_shared<dcp::ReelMonoPictureAsset>(make_shared<dcp::MonoPictureAsset>(path("build") / "test" / name / picture), 0));
+
+ auto reader = A_sound->asset()->start_read();
+ auto sound = make_shared<dcp::SoundAsset>(A_sound->asset()->edit_rate(), A_sound->asset()->sampling_rate(), A_sound->asset()->channels(), dcp::LanguageTag("en-US"), dcp::Standard::SMPTE);
+ auto writer = sound->start_write(path("build") / "test" / name / "pcm_8246f87f-e1df-4c42-a290-f3b3069ff021.mxf", {});
+
+ bool need_to_modify = modify;
+ for (int i = 0; i < A_sound->asset()->intrinsic_duration(); ++i) {
+ auto sf = reader->get_frame (i);
+ float* out[sf->channels()];
+ for (int j = 0; j < sf->channels(); ++j) {
+ out[j] = new float[sf->samples()];
+ }
+ for (int j = 0; j < sf->samples(); ++j) {
+ for (int k = 0; k < sf->channels(); ++k) {
+ out[k][j] = static_cast<float>(sf->get(k, j)) / (1 << 23);
+ if (need_to_modify) {
+ out[k][j] += 1.0 / (1 << 23);
+ need_to_modify = false;
+ }
+ }
+ }
+ writer->write (out, sf->samples());
+ for (int j = 0; j < sf->channels(); ++j) {
+ delete[] out[j];
+ }
+ }
+ writer->finalize();
+
+ reel->add(make_shared<dcp::ReelSoundAsset>(sound, 0));
+ reel->add(simple_markers());