X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Faudio_merger_test.cc;h=d8e5b0e267cf5d8e1640fee0e7f8562853128285;hb=dd9be86db6cde0afa5da0d1d1ac43b42e05dca26;hp=2b6cdc267b1461b6c2518115c0737ae2a2e4db35;hpb=58dce923b9d438a27ce1cd7e3125370f74d46e3a;p=dcpomatic.git diff --git a/test/audio_merger_test.cc b/test/audio_merger_test.cc index 2b6cdc267..d8e5b0e26 100644 --- a/test/audio_merger_test.cc +++ b/test/audio_merger_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2017 Carl Hetherington + Copyright (C) 2013-2020 Carl Hetherington This file is part of DCP-o-matic. @@ -18,10 +18,19 @@ */ +/** @file test/audio_merger_test.cc + * @brief Test AudioMerger class. + * @ingroup selfcontained + */ + +#include "lib/cross.h" #include "lib/audio_merger.h" #include "lib/audio_buffers.h" +#include "lib/dcpomatic_time.h" +#include "test.h" +#include #include -#include +#include #include #include #include @@ -29,8 +38,10 @@ using std::pair; using std::list; using std::cout; -using boost::shared_ptr; +using std::string; +using std::shared_ptr; using boost::bind; +using namespace dcpomatic; static shared_ptr last_audio; @@ -55,7 +66,7 @@ BOOST_AUTO_TEST_CASE (audio_merger_test1) push (merger, 0, 64, 22); list, DCPTime> > tb = merger.pull (DCPTime::from_frames (22, sampling_rate)); - BOOST_REQUIRE (tb.size() == 1); + BOOST_REQUIRE (tb.size() == 1U); BOOST_CHECK (tb.front().first != shared_ptr ()); BOOST_CHECK_EQUAL (tb.front().first->frames(), 22); BOOST_CHECK_EQUAL (tb.front().second.get(), 0); @@ -66,7 +77,7 @@ BOOST_AUTO_TEST_CASE (audio_merger_test1) } tb = merger.pull (DCPTime::from_frames (22 + 64, sampling_rate)); - BOOST_REQUIRE (tb.size() == 1); + BOOST_REQUIRE (tb.size() == 1U); BOOST_CHECK_EQUAL (tb.front().first->frames(), 64); BOOST_CHECK_EQUAL (tb.front().second.get(), DCPTime::from_frames(22, sampling_rate).get()); @@ -89,7 +100,7 @@ BOOST_AUTO_TEST_CASE (audio_merger_test2) /* There's nothing from 0 to 9 */ list, DCPTime> > tb = merger.pull (DCPTime::from_frames (9, sampling_rate)); - BOOST_CHECK_EQUAL (tb.size(), 0); + BOOST_CHECK_EQUAL (tb.size(), 0U); /* Then there's our data at 9 */ tb = merger.pull (DCPTime::from_frames (9 + 64, sampling_rate)); @@ -114,7 +125,7 @@ BOOST_AUTO_TEST_CASE (audio_merger_test3) /* Get them back */ list, DCPTime> > tb = merger.pull (DCPTime::from_frames (100, sampling_rate)); - BOOST_REQUIRE (tb.size() == 1); + BOOST_REQUIRE (tb.size() == 1U); BOOST_CHECK_EQUAL (tb.front().first->frames(), 64); BOOST_CHECK_EQUAL (tb.front().second.get(), DCPTime::from_frames(17, sampling_rate).get()); for (int i = 0; i < 64; ++i) { @@ -122,10 +133,49 @@ BOOST_AUTO_TEST_CASE (audio_merger_test3) } tb = merger.pull (DCPTime::from_frames (200, sampling_rate)); - BOOST_REQUIRE (tb.size() == 1); + BOOST_REQUIRE (tb.size() == 1U); BOOST_CHECK_EQUAL (tb.front().first->frames(), 64); BOOST_CHECK_EQUAL (tb.front().second.get(), DCPTime::from_frames(114, sampling_rate).get()); for (int i = 0; i < 64; ++i) { BOOST_CHECK_EQUAL (tb.front().first->data()[0][i], i); } } + +/* Reply a sequence of calls to AudioMerger that resulted in a crash */ +BOOST_AUTO_TEST_CASE (audio_merger_test4) +{ + FILE* f = fopen_boost("test/data/audio_merger_bug1.log", "r"); + BOOST_REQUIRE (f); + list tokens; + char buf[64]; + while (fscanf(f, "%63s", buf) == 1) { + tokens.push_back (buf); + } + + shared_ptr merger; + list::const_iterator i = tokens.begin (); + while (i != tokens.end()) { + BOOST_CHECK (*i++ == "I/AM"); + string const cmd = *i++; + if (cmd == "frame_rate") { + BOOST_REQUIRE (i != tokens.end()); + merger.reset (new AudioMerger(dcp::raw_convert(*i++))); + } else if (cmd == "clear") { + merger->clear (); + } else if (cmd == "push") { + BOOST_REQUIRE (i != tokens.end()); + DCPTime time(dcp::raw_convert(*i++)); + BOOST_REQUIRE (i != tokens.end()); + int const frames = dcp::raw_convert(*i++); + shared_ptr buffers(new AudioBuffers(1, frames)); + BOOST_REQUIRE (merger); + merger->push (buffers, time); + } else if (cmd == "pull") { + BOOST_REQUIRE (i != tokens.end()); + DCPTime time(dcp::raw_convert(*i++)); + merger->pull (time); + } + } +} + +