+
+static
+shared_ptr<dcp::OpenJPEGImage>
+random_image ()
+{
+ shared_ptr<dcp::OpenJPEGImage> image(new dcp::OpenJPEGImage(dcp::Size(1998, 1080)));
+ int const pixels = 1998 * 1080;
+ for (int i = 0; i < 3; ++i) {
+ int* p = image->data(i);
+ for (int j = 0; j < pixels; ++j) {
+ *p++ = rand();
+ }
+ }
+ return image;
+}
+
+
+static
+void
+dcp_from_frame (dcp::Data const& frame, boost::filesystem::path dir)
+{
+ shared_ptr<dcp::MonoPictureAsset> asset(new dcp::MonoPictureAsset(dcp::Fraction(24, 1), dcp::SMPTE));
+ boost::filesystem::create_directories (dir);
+ shared_ptr<dcp::PictureAssetWriter> writer = asset->start_write (dir / "pic.mxf", true);
+ for (int i = 0; i < 24; ++i) {
+ writer->write (frame.data().get(), frame.size());
+ }
+ writer->finalize ();
+
+ shared_ptr<dcp::ReelAsset> reel_asset(new dcp::ReelMonoPictureAsset(asset, 0));
+ shared_ptr<dcp::Reel> reel(new dcp::Reel());
+ reel->add (reel_asset);
+ shared_ptr<dcp::CPL> cpl(new dcp::CPL("hello", dcp::FEATURE));
+ cpl->add (reel);
+ shared_ptr<dcp::DCP> dcp(new dcp::DCP(dir));
+ dcp->add (cpl);
+ dcp->write_xml (dcp::SMPTE);
+}
+
+
+/* DCP with an over-sized JPEG2000 frame */
+BOOST_AUTO_TEST_CASE (verify_test15)
+{
+ /* Compress a random image with a bandwidth of 500Mbit/s */
+ shared_ptr<dcp::OpenJPEGImage> image = random_image ();
+ dcp::Data frame = dcp::compress_j2k (image, 500000000, 24, false, false);
+
+ boost::filesystem::path const dir("build/test/verify_test15");
+ dcp_from_frame (frame, dir);
+
+ vector<boost::filesystem::path> dirs;
+ dirs.push_back (dir);
+ list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, "xsd");
+ BOOST_REQUIRE_EQUAL (notes.size(), 1);
+ BOOST_CHECK_EQUAL (notes.front().code(), dcp::VerificationNote::PICTURE_FRAME_TOO_LARGE);
+}
+
+
+/* DCP with a nearly over-sized JPEG2000 frame */
+BOOST_AUTO_TEST_CASE (verify_test16)
+{
+ /* Compress a random image with a bandwidth of 500Mbit/s */
+ shared_ptr<dcp::OpenJPEGImage> image = random_image ();
+ dcp::Data frame = dcp::compress_j2k (image, 240000000, 24, false, false);
+
+ boost::filesystem::path const dir("build/test/verify_test16");
+ dcp_from_frame (frame, dir);
+
+ vector<boost::filesystem::path> dirs;
+ dirs.push_back (dir);
+ list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, "xsd");
+ BOOST_REQUIRE_EQUAL (notes.size(), 1);
+ BOOST_CHECK_EQUAL (notes.front().code(), dcp::VerificationNote::PICTURE_FRAME_NEARLY_TOO_LARGE);
+}
+
+
+/* DCP with a within-range JPEG2000 frame */
+BOOST_AUTO_TEST_CASE (verify_test17)
+{
+ /* Compress a random image with a bandwidth of 500Mbit/s */
+ shared_ptr<dcp::OpenJPEGImage> image = random_image ();
+ dcp::Data frame = dcp::compress_j2k (image, 100000000, 24, false, false);
+
+ boost::filesystem::path const dir("build/test/verify_test17");
+ dcp_from_frame (frame, dir);
+
+ vector<boost::filesystem::path> dirs;
+ dirs.push_back (dir);
+ list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, "xsd");
+ BOOST_REQUIRE_EQUAL (notes.size(), 0);
+}
+