diff --git a/src/test/analyserwaveformtest.cpp b/src/test/analyserwaveformtest.cpp index bab8c448926..9845c7035a6 100644 --- a/src/test/analyserwaveformtest.cpp +++ b/src/test/analyserwaveformtest.cpp @@ -8,79 +8,68 @@ #include "library/dao/analysisdao.h" #include "track/track.h" -#define BIGBUF_SIZE (1024 * 1024) //Megabyte -#define CANARY_SIZE (1024 * 4) -#define MAGIC_FLOAT 1234.567890f -#define CANARY_FLOAT 0.0f - namespace { +constexpr std::size_t kBigBufSize = 1024 * 1024; // Megabyte +constexpr std::size_t kCanarySize = 1024 * 4; +constexpr float kMagicFloat = 1234.567890f; +constexpr float kCanaryFloat = 0.0f; + class AnalyzerWaveformTest : public MixxxTest { protected: AnalyzerWaveformTest() - : aw(config(), QSqlDatabase()), - bigbuf(nullptr), - canaryBigBuf(nullptr) { + : m_aw(config(), QSqlDatabase()), + m_canaryBigBuf(nullptr) { } void SetUp() override { - tio = Track::newTemporary(); - tio->setAudioProperties( + m_pTrack = Track::newTemporary(); + m_pTrack->setAudioProperties( mixxx::audio::ChannelCount(2), mixxx::audio::SampleRate(44100), mixxx::audio::Bitrate(), mixxx::Duration::fromMillis(1000)); - bigbuf = new CSAMPLE[BIGBUF_SIZE]; - for (int i = 0; i < BIGBUF_SIZE; i++) - bigbuf[i] = MAGIC_FLOAT; + // Memory layout for m_canaryBigBuf looks like + // [ canary | big buf | canary ] - //Memory layout for canaryBigBuf looks like - // [ canary | big buf | canary ] - - canaryBigBuf = new CSAMPLE[BIGBUF_SIZE + 2 * CANARY_SIZE]; - for (int i = 0; i < CANARY_SIZE; i++) - canaryBigBuf[i] = CANARY_FLOAT; - for (int i = CANARY_SIZE; i < CANARY_SIZE + BIGBUF_SIZE; i++) - canaryBigBuf[i] = MAGIC_FLOAT; - for (int i = CANARY_SIZE + BIGBUF_SIZE; i < 2 * CANARY_SIZE + BIGBUF_SIZE; i++) - canaryBigBuf[i] = CANARY_FLOAT; + m_canaryBigBuf = new CSAMPLE[kBigBufSize + 2 * kCanarySize]; + for (std::size_t i = 0; i < kCanarySize; i++) { + m_canaryBigBuf[i] = kCanaryFloat; + } + for (std::size_t i = kCanarySize; i < kCanarySize + kBigBufSize; i++) { + m_canaryBigBuf[i] = kMagicFloat; + } + for (std::size_t i = kCanarySize + kBigBufSize; i < 2 * kCanarySize + kBigBufSize; i++) { + m_canaryBigBuf[i] = kCanaryFloat; + } } void TearDown() override { - delete[] bigbuf; - delete[] canaryBigBuf; + delete[] m_canaryBigBuf; } protected: - AnalyzerWaveform aw; - TrackPointer tio; - CSAMPLE* bigbuf; - CSAMPLE* canaryBigBuf; + AnalyzerWaveform m_aw; + TrackPointer m_pTrack; + CSAMPLE* m_canaryBigBuf; }; -//Test to make sure we don't modify the source buffer. -TEST_F(AnalyzerWaveformTest, simpleAnalyze) { - aw.initialize(tio, tio->getSampleRate(), BIGBUF_SIZE); - aw.processSamples(bigbuf, BIGBUF_SIZE); - aw.storeResults(tio); - aw.cleanup(); - for (int i = 0; i < BIGBUF_SIZE; i++) { - EXPECT_FLOAT_EQ(bigbuf[i], MAGIC_FLOAT); - } -} - -//Basic test to make sure we don't step out of bounds. +// Basic test to make sure we don't alter the input buffer and don't step out of bounds. TEST_F(AnalyzerWaveformTest, canary) { - aw.initialize(tio, tio->getSampleRate(), BIGBUF_SIZE); - aw.processSamples(&canaryBigBuf[CANARY_SIZE], BIGBUF_SIZE); - aw.storeResults(tio); - aw.cleanup(); - for (int i = 0; i < CANARY_SIZE; i++) { - EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT); + m_aw.initialize(m_pTrack, m_pTrack->getSampleRate(), kBigBufSize); + m_aw.processSamples(&m_canaryBigBuf[kCanarySize], kBigBufSize); + m_aw.storeResults(m_pTrack); + m_aw.cleanup(); + std::size_t i = 0; + for (; i < kCanarySize; i++) { + EXPECT_FLOAT_EQ(m_canaryBigBuf[i], kCanaryFloat); + } + for (; i < kCanarySize + kBigBufSize; i++) { + EXPECT_FLOAT_EQ(m_canaryBigBuf[i], kMagicFloat); } - for (int i = CANARY_SIZE + BIGBUF_SIZE; i < 2 * CANARY_SIZE + BIGBUF_SIZE; i++) { - EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT); + for (; i < 2 * kCanarySize + kBigBufSize; i++) { + EXPECT_FLOAT_EQ(m_canaryBigBuf[i], kCanaryFloat); } }