Some C++11 stuff.
[dcpomatic.git] / test / torture_test.cc
index 3736b3e65c2bff132c6b4c8996fe8fb0587a0a26..434ed0b5ec408228264fd920bacf9525d3c952e3 100644 (file)
@@ -43,8 +43,9 @@
 
 using std::list;
 using std::cout;
-using boost::shared_ptr;
-using boost::dynamic_pointer_cast;
+using std::shared_ptr;
+using std::dynamic_pointer_cast;
+using namespace dcpomatic;
 
 /** Test start/end trim and positioning of some audio content */
 BOOST_AUTO_TEST_CASE (torture_test1)
@@ -55,56 +56,56 @@ BOOST_AUTO_TEST_CASE (torture_test1)
        film->set_container (Ratio::from_id ("185"));
        film->set_sequence (false);
 
-       /* Staircase at an offset of 2000 samples, trimmed both start and end, with a gain of 6dB */
-       shared_ptr<Content> staircase = content_factory(film, "test/data/staircase.wav").front ();
+       /* Staircase at an offset of 2000 samples, trimmed both start and end, with a gain of exactly 2 (linear) */
+       shared_ptr<Content> staircase = content_factory("test/data/staircase.wav").front ();
        film->examine_and_add_content (staircase);
-       wait_for_jobs ();
-       staircase->set_position (DCPTime::from_frames (2000, film->audio_frame_rate()));
+       BOOST_REQUIRE (!wait_for_jobs());
+       staircase->set_position (film, DCPTime::from_frames (2000, film->audio_frame_rate()));
        staircase->set_trim_start (ContentTime::from_frames (12, 48000));
        staircase->set_trim_end (ContentTime::from_frames (35, 48000));
        staircase->audio->set_gain (20 * log10(2));
 
-       /* And again at an offset of 50000 samples, trimmed both start and end, with a gain of 6dB */
-       staircase = content_factory(film, "test/data/staircase.wav").front ();
+       /* And again at an offset of 50000 samples, trimmed both start and end, with a gain of exactly 2 (linear) */
+       staircase = content_factory("test/data/staircase.wav").front ();
        film->examine_and_add_content (staircase);
-       wait_for_jobs ();
-       staircase->set_position (DCPTime::from_frames (50000, film->audio_frame_rate()));
+       BOOST_REQUIRE (!wait_for_jobs());
+       staircase->set_position (film, DCPTime::from_frames(50000, film->audio_frame_rate()));
        staircase->set_trim_start (ContentTime::from_frames (12, 48000));
        staircase->set_trim_end (ContentTime::from_frames (35, 48000));
        staircase->audio->set_gain (20 * log10(2));
 
        /* 1s of red at 5s in */
-       shared_ptr<Content> red = content_factory(film, "test/data/flat_red.png").front ();
+       shared_ptr<Content> red = content_factory("test/data/flat_red.png").front ();
        film->examine_and_add_content (red);
-       wait_for_jobs ();
-       red->set_position (DCPTime::from_seconds (5));
+       BOOST_REQUIRE (!wait_for_jobs());
+       red->set_position (film, DCPTime::from_seconds(5));
        red->video->set_length (24);
 
        film->set_video_frame_rate (24);
        film->write_metadata ();
        film->make_dcp ();
-       wait_for_jobs ();
+       BOOST_REQUIRE (!wait_for_jobs());
 
        dcp::DCP dcp ("build/test/torture_test1/" + film->dcp_name(false));
        dcp.read ();
 
-       list<shared_ptr<dcp::CPL> > cpls = dcp.cpls ();
-       BOOST_REQUIRE_EQUAL (cpls.size(), 1);
-       list<shared_ptr<dcp::Reel> > reels = cpls.front()->reels ();
-       BOOST_REQUIRE_EQUAL (reels.size(), 1);
+       auto cpls = dcp.cpls ();
+       BOOST_REQUIRE_EQUAL (cpls.size(), 1U);
+       auto reels = cpls.front()->reels ();
+       BOOST_REQUIRE_EQUAL (reels.size(), 1U);
 
        /* Check sound */
 
-       shared_ptr<dcp::ReelSoundAsset> reel_sound = reels.front()->main_sound();
+       auto reel_sound = reels.front()->main_sound();
        BOOST_REQUIRE (reel_sound);
-       shared_ptr<dcp::SoundAsset> sound = reel_sound->asset();
+       auto sound = reel_sound->asset();
        BOOST_REQUIRE (sound);
        BOOST_CHECK_EQUAL (sound->intrinsic_duration(), 144);
 
        shared_ptr<dcp::SoundAssetReader> sound_reader = sound->start_read ();
 
        /* First frame silent */
-       shared_ptr<const dcp::SoundFrame> fr = sound_reader->get_frame (0);
+       auto fr = sound_reader->get_frame (0);
        for (int i = 0; i < fr->samples(); ++i) {
                for (int j = 0; j < 6; ++j) {
                        BOOST_CHECK_EQUAL (fr->get(j, i), 0);
@@ -117,49 +118,57 @@ BOOST_AUTO_TEST_CASE (torture_test1)
 
        int stair = 12;
 
-       fr = sound_reader->get_frame (1);
-       for (int i = 0; i < fr->samples(); ++i) {
-               for (int j = 0; j < 6; ++j) {
-                       if (j == 2) {
-                               BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
-                               ++stair;
-                       } else {
-                               BOOST_CHECK_EQUAL (fr->get(j, i), 0);
+       BOOST_TEST_CONTEXT("First staircase, frame #1") {
+               fr = sound_reader->get_frame (1);
+               for (int i = 0; i < fr->samples(); ++i) {
+                       for (int j = 0; j < 6; ++j) {
+                               if (j == 2) {
+                                       BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
+                                       ++stair;
+                               } else {
+                                       BOOST_CHECK_EQUAL (fr->get(j, i), 0);
+                               }
                        }
                }
        }
 
-       fr = sound_reader->get_frame (2);
-       for (int i = 0; i < fr->samples(); ++i) {
-               for (int j = 0; j < 6; ++j) {
-                       if (j == 2) {
-                               BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
-                               ++stair;
-                       } else {
-                               BOOST_CHECK_EQUAL (fr->get(j, i), 0);
+       BOOST_TEST_CONTEXT("First staircase, frame #2") {
+               fr = sound_reader->get_frame (2);
+               for (int i = 0; i < fr->samples(); ++i) {
+                       for (int j = 0; j < 6; ++j) {
+                               if (j == 2) {
+                                       BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
+                                       ++stair;
+                               } else {
+                                       BOOST_CHECK_EQUAL (fr->get(j, i), 0);
+                               }
                        }
                }
        }
 
-       fr = sound_reader->get_frame (3);
-       for (int i = 0; i < fr->samples(); ++i) {
-               for (int j = 0; j < 6; ++j) {
-                       if (j == 2 && i < (4753 - (2000 * 2))) {
-                               BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
-                               ++stair;
-                       } else {
-                               BOOST_CHECK_EQUAL (fr->get(j, i), 0);
+       BOOST_TEST_CONTEXT("First staircase, frame #3") {
+               fr = sound_reader->get_frame (3);
+               for (int i = 0; i < fr->samples(); ++i) {
+                       for (int j = 0; j < 6; ++j) {
+                               if (j == 2 && i < (4753 - (2000 * 2))) {
+                                       BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
+                                       ++stair;
+                               } else {
+                                       BOOST_CHECK_EQUAL (fr->get(j, i), 0);
+                               }
                        }
                }
        }
 
        /* Then some silence */
 
-       for (int i = 4; i < 24; ++i) {
-               fr = sound_reader->get_frame (i);
-               for (int j = 0; j < fr->samples(); ++j) {
-                       for (int k = 0; k < 6; ++k) {
-                               BOOST_CHECK_EQUAL (fr->get(k, j), 0);
+       BOOST_TEST_CONTEXT("Silence") {
+               for (int i = 4; i < 24; ++i) {
+                       fr = sound_reader->get_frame (i);
+                       for (int j = 0; j < fr->samples(); ++j) {
+                               for (int k = 0; k < 6; ++k) {
+                                       BOOST_CHECK_EQUAL (fr->get(k, j), 0);
+                               }
                        }
                }
        }
@@ -225,7 +234,7 @@ BOOST_AUTO_TEST_CASE (torture_test1)
 
        shared_ptr<dcp::MonoPictureAssetReader> picture_reader = picture->start_read ();
 
-       /* First 5 * 24 = 120 frames should be black */
+       /* First 5 * 24 = 120 frames should be black, possibly with a little noise to raise the bitrate */
 
        shared_ptr<dcp::OpenJPEGImage> ref;
        for (int i = 0; i < 120; ++i) {
@@ -233,15 +242,17 @@ BOOST_AUTO_TEST_CASE (torture_test1)
                shared_ptr<dcp::OpenJPEGImage> image = fr->xyz_image ();
                dcp::Size const size = image->size ();
                if (i == 0) {
+                       /* Check the first frame pixel by pixel... */
                        for (int c = 0; c < 3; ++c) {
                                for (int y = 0; y < size.height; ++y) {
                                        for (int x = 0; x < size.width; ++x) {
-                                               BOOST_REQUIRE_EQUAL (image->data(c)[y * size.height + x], 0);
+                                               BOOST_REQUIRE (image->data(c)[y * size.height + x] <= 3);
                                        }
                                }
                        }
                        ref = image;
                } else {
+                       /* ... then all the others should be the same */
                        for (int c = 0; c < 3; ++c) {
                                BOOST_REQUIRE_MESSAGE (
                                        memcmp (image->data(c), ref->data(c), size.width * size.height * sizeof(int)) == 0,
@@ -251,7 +262,7 @@ BOOST_AUTO_TEST_CASE (torture_test1)
                }
        }
 
-       /* Then 24 red */
+       /* Then 24 red, perhaps also with some noise */
 
        for (int i = 120; i < 144; ++i) {
                shared_ptr<const dcp::MonoPictureFrame> fr = picture_reader->get_frame (i);
@@ -261,15 +272,15 @@ BOOST_AUTO_TEST_CASE (torture_test1)
                        for (int y = 0; y < size.height; ++y) {
                                for (int x = 0; x < size.width; ++x) {
                                        BOOST_REQUIRE_MESSAGE (
-                                               abs(image->data(0)[y * size.height + x] - 2808) <= 2,
+                                               abs(image->data(0)[y * size.height + x] - 2808) <= 5,
                                                "failed on frame " << i << " with image data " << image->data(0)[y * size.height + x]
                                                );
                                        BOOST_REQUIRE_MESSAGE (
-                                               abs(image->data(1)[y * size.height + x] - 2176) <= 2,
+                                               abs(image->data(1)[y * size.height + x] - 2176) <= 5,
                                                "failed on frame " << i << " with image data " << image->data(1)[y * size.height + x]
                                                );
                                        BOOST_REQUIRE_MESSAGE (
-                                               abs(image->data(2)[y * size.height + x] - 865) <= 2,
+                                               abs(image->data(2)[y * size.height + x] - 865) <= 5,
                                                "failed on frame " << i << " with image data " << image->data(2)[y * size.height + x]
                                                );
                                }