diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-03-04 20:22:47 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-03-04 20:22:47 +0000 |
| commit | 1b1bc528ee5ca1fee1bd33f9fb6f79cd551e3b33 (patch) | |
| tree | d60b9fb573dd8d6ab89036fb8788cd1b1c69aada /test | |
| parent | 6d8bcba724be622739a749064466901486304cee (diff) | |
New DCPTime/ContentTime types.
Diffstat (limited to 'test')
| -rw-r--r-- | test/audio_merger_test.cc | 24 | ||||
| -rw-r--r-- | test/black_fill_test.cc | 8 | ||||
| -rw-r--r-- | test/ffmpeg_seek_test.cc | 14 | ||||
| -rw-r--r-- | test/long_ffmpeg_seek_test.cc | 4 | ||||
| -rw-r--r-- | test/play_test.cc | 6 | ||||
| -rw-r--r-- | test/scaling_test.cc | 2 | ||||
| -rw-r--r-- | test/seek_zero_test.cc | 4 | ||||
| -rw-r--r-- | test/subrip_test.cc | 32 | ||||
| -rw-r--r-- | test/util_test.cc | 20 |
9 files changed, 55 insertions, 59 deletions
diff --git a/test/audio_merger_test.cc b/test/audio_merger_test.cc index 31d055ab7..e8af22d2a 100644 --- a/test/audio_merger_test.cc +++ b/test/audio_merger_test.cc @@ -29,27 +29,22 @@ using boost::bind; static shared_ptr<const AudioBuffers> last_audio; -static int -pass_through (int x) -{ - return x; -} - BOOST_AUTO_TEST_CASE (audio_merger_test1) { - AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1)); + int const frame_rate = 48000; + AudioMerger merger (1, frame_rate); /* Push 64 samples, 0 -> 63 at time 0 */ shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64)); for (int i = 0; i < 64; ++i) { buffers->data()[0][i] = i; } - merger.push (buffers, 0); + merger.push (buffers, DCPTime ()); /* Push 64 samples, 0 -> 63 at time 22 */ - merger.push (buffers, 22); + merger.push (buffers, DCPTime::from_frames (22, frame_rate)); - TimedAudioBuffers<int> tb = merger.pull (22); + TimedAudioBuffers<DCPTime> tb = merger.pull (DCPTime::from_frames (22, frame_rate)); BOOST_CHECK (tb.audio != shared_ptr<const AudioBuffers> ()); BOOST_CHECK_EQUAL (tb.audio->frames(), 22); BOOST_CHECK_EQUAL (tb.time, 0); @@ -63,7 +58,7 @@ BOOST_AUTO_TEST_CASE (audio_merger_test1) /* That flush should give us 64 samples at 22 */ BOOST_CHECK_EQUAL (tb.audio->frames(), 64); - BOOST_CHECK_EQUAL (tb.time, 22); + BOOST_CHECK_EQUAL (tb.time, DCPTime::from_frames (22, frame_rate)); /* Check the sample values */ for (int i = 0; i < 64; ++i) { @@ -77,16 +72,17 @@ BOOST_AUTO_TEST_CASE (audio_merger_test1) BOOST_AUTO_TEST_CASE (audio_merger_test2) { - AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1)); + int const frame_rate = 48000; + AudioMerger merger (1, frame_rate); /* Push 64 samples, 0 -> 63 at time 9 */ shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64)); for (int i = 0; i < 64; ++i) { buffers->data()[0][i] = i; } - merger.push (buffers, 9); + merger.push (buffers, DCPTime::from_frames (9, frame_rate)); - TimedAudioBuffers<int> tb = merger.pull (9); + TimedAudioBuffers<DCPTime> tb = merger.pull (DCPTime::from_frames (9, frame_rate)); BOOST_CHECK_EQUAL (tb.audio->frames(), 9); BOOST_CHECK_EQUAL (tb.time, 0); diff --git a/test/black_fill_test.cc b/test/black_fill_test.cc index 9e8aa381b..101fe0523 100644 --- a/test/black_fill_test.cc +++ b/test/black_fill_test.cc @@ -46,10 +46,10 @@ BOOST_AUTO_TEST_CASE (black_fill_test) film->examine_and_add_content (contentB); wait_for_jobs (); - contentA->set_video_length (3); - contentA->set_position (film->video_frames_to_time (2)); - contentB->set_video_length (1); - contentB->set_position (film->video_frames_to_time (7)); + contentA->set_video_length (ContentTime::from_frames (3, 24)); + contentA->set_position (DCPTime::from_frames (2, film->video_frame_rate ())); + contentB->set_video_length (ContentTime::from_frames (1, 24)); + contentB->set_position (DCPTime::from_frames (7, film->video_frame_rate ())); film->make_dcp (); diff --git a/test/ffmpeg_seek_test.cc b/test/ffmpeg_seek_test.cc index 3c175f08c..235a1a1d6 100644 --- a/test/ffmpeg_seek_test.cc +++ b/test/ffmpeg_seek_test.cc @@ -62,7 +62,7 @@ static string print_time (DCPTime t, float fps) { stringstream s; - s << t << " " << (float(t) / TIME_HZ) << "s " << (float(t) * fps / TIME_HZ) << "f"; + s << t << " " << t.seconds() << "s " << t.frames (fps) << "f"; return s.str (); } @@ -90,8 +90,8 @@ check (shared_ptr<Player> p, DCPTime t) BOOST_CHECK (first_video.get() >= t); BOOST_CHECK (first_audio.get() >= t); /* And should be rounded to frame boundaries */ - BOOST_CHECK ((first_video.get() % (TIME_HZ / film->video_frame_rate())) == 0); - BOOST_CHECK ((first_audio.get() % (TIME_HZ / film->audio_frame_rate())) == 0); + BOOST_CHECK (first_video.get() == first_video.get().round_up (film->video_frame_rate())); + BOOST_CHECK (first_audio.get() == first_audio.get().round_up (film->audio_frame_rate())); } /* Test basic seeking */ @@ -110,8 +110,8 @@ BOOST_AUTO_TEST_CASE (ffmpeg_seek_test) player->Video.connect (boost::bind (&process_video, _1, _2, _3, _4, _5)); player->Audio.connect (boost::bind (&process_audio, _1, _2)); - check (player, 0); - check (player, 0.1 * TIME_HZ); - check (player, 0.2 * TIME_HZ); - check (player, 0.3 * TIME_HZ); + check (player, DCPTime::from_seconds (0)); + check (player, DCPTime::from_seconds (0.1)); + check (player, DCPTime::from_seconds (0.2)); + check (player, DCPTime::from_seconds (0.3)); } diff --git a/test/long_ffmpeg_seek_test.cc b/test/long_ffmpeg_seek_test.cc index 5285d4481..fedd8749b 100644 --- a/test/long_ffmpeg_seek_test.cc +++ b/test/long_ffmpeg_seek_test.cc @@ -54,7 +54,7 @@ static string print_time (DCPTime t, float fps) { stringstream s; - s << t << " " << (float(t) / TIME_HZ) << "s " << (float(t) * fps / TIME_HZ) << "f"; + s << t << " " << t.seconds() << "s " << t.frames(fps) << "f"; return s.str (); } @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE (long_ffmpeg_seek_test) player->Audio.connect (boost::bind (&process_audio, _1, _2)); for (float i = 0; i < 10; i += 0.1) { - check (player, i * TIME_HZ); + check (player, DCPTime::from_seconds (i)); } } diff --git a/test/play_test.cc b/test/play_test.cc index 54fe2699f..5ffc55a8e 100644 --- a/test/play_test.cc +++ b/test/play_test.cc @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE (play_test) BOOST_CHECK_EQUAL (A->position(), 0); /* A is 16 frames long at 25 fps */ - BOOST_CHECK_EQUAL (B->position(), 16 * TIME_HZ / 25); + BOOST_CHECK_EQUAL (B->position(), DCPTime::from_frames (16, 25)); shared_ptr<Player> player = film->make_player (); PlayerWrapper wrap (player); @@ -117,10 +117,10 @@ BOOST_AUTO_TEST_CASE (play_test) } } - player->seek (6 * TIME_HZ / 25, true); + player->seek (DCPTime::from_frames (6, 25), true); optional<Video> v = wrap.get_video (); BOOST_CHECK (v); - BOOST_CHECK_EQUAL (v.get().time, 6 * TIME_HZ / 25); + BOOST_CHECK_EQUAL (v.get().time, DCPTime::from_frames (6, 25)); } #endif diff --git a/test/scaling_test.cc b/test/scaling_test.cc index c936fe8d4..7002019dd 100644 --- a/test/scaling_test.cc +++ b/test/scaling_test.cc @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (scaling_test) wait_for_jobs (); - imc->set_video_length (1); + imc->set_video_length (ContentTime::from_frames (1, 24)); scaling_test_for (film, imc, "133", "185"); scaling_test_for (film, imc, "185", "185"); diff --git a/test/seek_zero_test.cc b/test/seek_zero_test.cc index c20c99ee7..e0c52e2bf 100644 --- a/test/seek_zero_test.cc +++ b/test/seek_zero_test.cc @@ -47,11 +47,11 @@ BOOST_AUTO_TEST_CASE (seek_zero_test) FFmpegDecoder decoder (film, content, true, false); shared_ptr<DecodedVideo> a = dynamic_pointer_cast<DecodedVideo> (decoder.peek ()); - decoder.seek (0, true); + decoder.seek (ContentTime(), true); shared_ptr<DecodedVideo> b = dynamic_pointer_cast<DecodedVideo> (decoder.peek ()); /* a will be after no seek, and b after a seek to zero, which should have the same effect. */ - BOOST_CHECK_EQUAL (a->frame, b->frame); + BOOST_CHECK_EQUAL (a->content_time, b->content_time); } diff --git a/test/subrip_test.cc b/test/subrip_test.cc index e2eda078c..d8c2d75de 100644 --- a/test/subrip_test.cc +++ b/test/subrip_test.cc @@ -34,8 +34,8 @@ using boost::dynamic_pointer_cast; /** Test SubRip::convert_time */ BOOST_AUTO_TEST_CASE (subrip_time_test) { - BOOST_CHECK_EQUAL (SubRip::convert_time ("00:03:10,500"), rint (((3 * 60) + 10 + 0.5) * TIME_HZ)); - BOOST_CHECK_EQUAL (SubRip::convert_time ("04:19:51,782"), rint (((4 * 3600) + (19 * 60) + 51 + 0.782) * TIME_HZ)); + BOOST_CHECK_EQUAL (SubRip::convert_time ("00:03:10,500"), ContentTime::from_seconds ((3 * 60) + 10 + 0.5)); + BOOST_CHECK_EQUAL (SubRip::convert_time ("04:19:51,782"), ContentTime::from_seconds ((4 * 3600) + (19 * 60) + 51 + 0.782)); } /** Test SubRip::convert_coordinate */ @@ -123,52 +123,52 @@ BOOST_AUTO_TEST_CASE (subrip_parse_test) { shared_ptr<SubRipContent> content (new SubRipContent (shared_ptr<Film> (), "test/data/subrip.srt")); content->examine (shared_ptr<Job> ()); - BOOST_CHECK_EQUAL (content->full_length(), ((3 * 60) + 56.471) * TIME_HZ); + BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471)); SubRip s (content); vector<SubRipSubtitle>::const_iterator i = s._subtitles.begin(); BOOST_CHECK (i != s._subtitles.end ()); - BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 49.200) * TIME_HZ); - BOOST_CHECK_EQUAL (i->to, ((1 * 60) + 52.351) * TIME_HZ); + BOOST_CHECK_EQUAL (i->from, DCPTime::from_seconds ((1 * 60) + 49.200)); + BOOST_CHECK_EQUAL (i->to, DCPTime::from_seconds ((1 * 60) + 52.351)); BOOST_CHECK_EQUAL (i->pieces.size(), 1); BOOST_CHECK_EQUAL (i->pieces.front().text, "This is a subtitle, and it goes over two lines."); ++i; BOOST_CHECK (i != s._subtitles.end ()); - BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 52.440) * TIME_HZ); - BOOST_CHECK_EQUAL (i->to, ((1 * 60) + 54.351) * TIME_HZ); + BOOST_CHECK_EQUAL (i->from, DCPTime::from_seconds ((1 * 60) + 52.440)); + BOOST_CHECK_EQUAL (i->to, DCPTime::from_seconds ((1 * 60) + 54.351)); BOOST_CHECK_EQUAL (i->pieces.size(), 1); BOOST_CHECK_EQUAL (i->pieces.front().text, "We have emboldened this"); BOOST_CHECK_EQUAL (i->pieces.front().bold, true); ++i; BOOST_CHECK (i != s._subtitles.end ()); - BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 54.440) * TIME_HZ); - BOOST_CHECK_EQUAL (i->to, ((1 * 60) + 56.590) * TIME_HZ); + BOOST_CHECK_EQUAL (i->from, DCPTime::from_seconds ((1 * 60) + 54.440)); + BOOST_CHECK_EQUAL (i->to, DCPTime::from_seconds ((1 * 60) + 56.590)); BOOST_CHECK_EQUAL (i->pieces.size(), 1); BOOST_CHECK_EQUAL (i->pieces.front().text, "And italicised this."); BOOST_CHECK_EQUAL (i->pieces.front().italic, true); ++i; BOOST_CHECK (i != s._subtitles.end ()); - BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 56.680) * TIME_HZ); - BOOST_CHECK_EQUAL (i->to, ((1 * 60) + 58.955) * TIME_HZ); + BOOST_CHECK_EQUAL (i->from, DCPTime::from_seconds ((1 * 60) + 56.680)); + BOOST_CHECK_EQUAL (i->to, DCPTime::from_seconds ((1 * 60) + 58.955)); BOOST_CHECK_EQUAL (i->pieces.size(), 1); BOOST_CHECK_EQUAL (i->pieces.front().text, "Shall I compare thee to a summers' day?"); ++i; BOOST_CHECK (i != s._subtitles.end ()); - BOOST_CHECK_EQUAL (i->from, ((2 * 60) + 0.840) * TIME_HZ); - BOOST_CHECK_EQUAL (i->to, ((2 * 60) + 3.400) * TIME_HZ); + BOOST_CHECK_EQUAL (i->from, DCPTime::from_seconds ((2 * 60) + 0.840)); + BOOST_CHECK_EQUAL (i->to, DCPTime::from_seconds ((2 * 60) + 3.400)); BOOST_CHECK_EQUAL (i->pieces.size(), 1); BOOST_CHECK_EQUAL (i->pieces.front().text, "Is this a dagger I see before me?"); ++i; BOOST_CHECK (i != s._subtitles.end ()); - BOOST_CHECK_EQUAL (i->from, ((3 * 60) + 54.560) * TIME_HZ); - BOOST_CHECK_EQUAL (i->to, ((3 * 60) + 56.471) * TIME_HZ); + BOOST_CHECK_EQUAL (i->from, DCPTime::from_seconds ((3 * 60) + 54.560)); + BOOST_CHECK_EQUAL (i->to, DCPTime::from_seconds ((3 * 60) + 56.471)); BOOST_CHECK_EQUAL (i->pieces.size(), 1); BOOST_CHECK_EQUAL (i->pieces.front().text, "Hello world."); @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE (subrip_render_test) { shared_ptr<SubRipContent> content (new SubRipContent (shared_ptr<Film> (), "test/data/subrip.srt")); content->examine (shared_ptr<Job> ()); - BOOST_CHECK_EQUAL (content->full_length(), ((3 * 60) + 56.471) * TIME_HZ); + BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471)); shared_ptr<Film> film = new_test_film ("subrip_render_test"); diff --git a/test/util_test.cc b/test/util_test.cc index 37dee00c9..3373bf86b 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -54,18 +54,18 @@ BOOST_AUTO_TEST_CASE (md5_digest_test) BOOST_CHECK_THROW (md5_digest (p, shared_ptr<Job> ()), std::runtime_error); } -/* Straightforward test of time_round_up_test */ -BOOST_AUTO_TEST_CASE (time_round_up_test) +/* Straightforward test of DCPTime::round_up */ +BOOST_AUTO_TEST_CASE (dcptime_round_up_test) { - BOOST_CHECK_EQUAL (time_round_up (0, 2), 0); - BOOST_CHECK_EQUAL (time_round_up (1, 2), 2); - BOOST_CHECK_EQUAL (time_round_up (2, 2), 2); - BOOST_CHECK_EQUAL (time_round_up (3, 2), 4); + BOOST_CHECK_EQUAL (DCPTime (0).round_up (DCPTime::HZ / 2), 0); + BOOST_CHECK_EQUAL (DCPTime (1).round_up (DCPTime::HZ / 2), 2); + BOOST_CHECK_EQUAL (DCPTime (2).round_up (DCPTime::HZ / 2), 2); + BOOST_CHECK_EQUAL (DCPTime (3).round_up (DCPTime::HZ / 2), 4); - BOOST_CHECK_EQUAL (time_round_up (0, 42), 0); - BOOST_CHECK_EQUAL (time_round_up (1, 42), 42); - BOOST_CHECK_EQUAL (time_round_up (42, 42), 42); - BOOST_CHECK_EQUAL (time_round_up (43, 42), 84); + BOOST_CHECK_EQUAL (DCPTime (0).round_up (DCPTime::HZ / 42), 0); + BOOST_CHECK_EQUAL (DCPTime (1).round_up (DCPTime::HZ / 42), 42); + BOOST_CHECK_EQUAL (DCPTime (42).round_up (DCPTime::HZ / 42), 42); + BOOST_CHECK_EQUAL (DCPTime (43).round_up (DCPTime::HZ / 42), 84); } |
