X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Faudio_buffers_test.cc;h=49df0964633227516bcda636613feb1f6619a4f2;hb=HEAD;hp=c9231ae7f71f1eee49705cbb7f6d295e1235819b;hpb=58dce923b9d438a27ce1cd7e3125370f74d46e3a;p=dcpomatic.git diff --git a/test/audio_buffers_test.cc b/test/audio_buffers_test.cc index c9231ae7f..49df09646 100644 --- a/test/audio_buffers_test.cc +++ b/test/audio_buffers_test.cc @@ -19,7 +19,8 @@ */ /** @file test/audio_buffers_test.cc - * @brief Test AudioBuffers in various ways. + * @brief Test AudioBuffers class. + * @ingroup selfcontained */ #include @@ -78,7 +79,7 @@ BOOST_AUTO_TEST_CASE (audio_buffers_extend_test) random_fill (buffers); /* Extend */ - buffers.ensure_size (299); + buffers.set_frames (299); srand (1); random_check (buffers, 0, 150); @@ -302,3 +303,85 @@ BOOST_AUTO_TEST_CASE (audio_buffers_accumulate_frames) } } } + + +BOOST_AUTO_TEST_CASE (audio_buffers_data) +{ + AudioBuffers a (94, 512); + + for (int i = 0; i < 94; ++i) { + BOOST_CHECK_EQUAL (a.data()[i], a.data(i)); + } + + a.set_frames (2048); + + for (int i = 0; i < 94; ++i) { + BOOST_CHECK_EQUAL (a.data()[i], a.data(i)); + } +} + + +BOOST_AUTO_TEST_CASE (audio_buffers_trim_start) +{ + AudioBuffers a (13, 999); + + srand (55); + random_fill (a); + + a.trim_start (101); + + srand (55); + + /* Burn the first 101 numbers in the sequence */ + for (int i = 0; i < 101 * 13; ++i) { + random_float (); + } + + for (int i = 0; i < (999 - 101); ++i) { + for (int j = 0; j < 13; ++j) { + BOOST_CHECK_CLOSE (a.data(j)[i], random_float(), tolerance); + } + } +} + + +BOOST_AUTO_TEST_CASE(audio_buffers_set_channels_lower) +{ + AudioBuffers buffers(9, 9933); + srand(4); + random_fill(buffers); + + buffers.set_channels(4); + BOOST_REQUIRE_EQUAL(buffers.channels(), 4); + + srand(4); + for (int i = 0; i < 9933; ++i) { + for (int c = 0; c < 4; ++c) { + BOOST_CHECK_EQUAL(buffers.data(c)[i], random_float()); + } + for (int c = 4; c < 9; ++c) { + random_float(); + } + } +} + + +BOOST_AUTO_TEST_CASE(audio_buffers_set_channels_higher) +{ + AudioBuffers buffers(9, 9933); + srand(4); + random_fill(buffers); + + buffers.set_channels(13); + BOOST_REQUIRE_EQUAL(buffers.channels(), 13); + + srand(4); + for (int i = 0; i < 9933; ++i) { + for (int c = 0; c < 9; ++c) { + BOOST_CHECK_EQUAL(buffers.data(c)[i], random_float()); + } + for (int c = 9; c < 13; ++c) { + BOOST_CHECK_EQUAL(buffers.data(c)[i], 0); + } + } +}