Add some more tests.
authorCarl Hetherington <cth@carlh.net>
Wed, 5 May 2021 21:01:34 +0000 (23:01 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 7 May 2021 07:29:58 +0000 (09:29 +0200)
test/content_test.cc
test/test.h

index ef3b710e76618d57e0c34545e2045fbd38299435..dcf5f4504bd887fdc046218712e71340991bf38b 100644 (file)
@@ -132,10 +132,23 @@ BOOST_AUTO_TEST_CASE (content_test4)
        BOOST_REQUIRE (!wait_for_jobs());
 
        video->set_trim_end (dcpomatic::ContentTime(3000));
-       BOOST_CHECK (video->length_after_trim(film) == DCPTime::from_frames(299, 24));
+       CHECK_DCP_TIME_CLOSE (video->length_after_trim(film), DCPTime::from_frames(299, 24), 1);
 }
 
 
+BOOST_AUTO_TEST_CASE (video_content_length_is_correct_with_speed_change)
+{
+       auto video = content_factory("test/data/count300bd24.m2ts").front();
+       auto film = new_test_film2 ("content_test4", { video });
+
+       film->set_video_frame_rate (25);
+
+       /* It's 300 frames and they will effectively be delivered at 25fps */
+       CHECK_DCP_TIME_CLOSE (video->length_after_trim(film), DCPTime::from_frames(300, 25), 1);
+}
+
+
+
 /** Content containing no video will not have its length rounded to the nearest video frame */
 BOOST_AUTO_TEST_CASE (content_test5)
 {
@@ -144,7 +157,36 @@ BOOST_AUTO_TEST_CASE (content_test5)
 
        audio->set_trim_end (dcpomatic::ContentTime(3000));
 
-       BOOST_CHECK (audio->length_after_trim(film) == DCPTime(957000));
+       CHECK_DCP_TIME_CLOSE (audio->length_after_trim(film), DCPTime(957000), 1);
+}
+
+
+/** 44.1k audio will have its length reported correctly when it will be resampled to 48k
+ *  without any speed change.
+ */
+BOOST_AUTO_TEST_CASE (audio_content_length_is_correct_when_resampled)
+{
+       auto audio = content_factory("test/data/white.wav").front();
+       auto film = new_test_film2 ("audio_content_length_is_correct_when_resampled", { audio });
+       /* 220500 frames @ 44.1k is 5 seconds */
+       CHECK_DCP_TIME_CLOSE (audio->length_after_trim(film), DCPTime::from_seconds(5), 1);
+}
+
+
+/** 44.1k audio will have its length reported correctly when it will be resampled to 48k
+ *  without any speed change.
+ */
+BOOST_AUTO_TEST_CASE (audio_content_length_is_correct_when_resampled_with_speed_change)
+{
+       auto video = content_factory("test/data/flat_red.png").front();
+       auto audio = content_factory("test/data/white.wav").front();
+       auto film = new_test_film2 ("audio_content_length_is_correct_when_resampled_with_speed_change", { video, audio });
+
+       video->set_video_frame_rate (25);
+       film->set_video_frame_rate (24);
+
+       /* Was 5 seconds but will now be run slower so will last longer */
+       CHECK_DCP_TIME_CLOSE (audio->length_after_trim(film), DCPTime::from_seconds(5 * 25.0 / 24), 2);
 }
 
 
index 217b738f48d2144d81fba4f4dc589f7f745fd09f..8e6f90f94ffaeff1c21448b152951ec816c99407 100644 (file)
@@ -79,6 +79,8 @@ extern void make_and_verify_dcp (std::shared_ptr<Film> film, std::vector<dcp::Ve
 extern void check_int_close (int a, int b, int d);
 extern void check_int_close (std::pair<int, int>, std::pair<int, int>, int d);
 
+#define CHECK_DCP_TIME_CLOSE(a, b, d) BOOST_CHECK_MESSAGE(std::abs(a.get() - b.get()) < d, to_string(a) << " != " << to_string(b));
+
 
 class LogSwitcher
 {