Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnalyzerWaveformTest refactoring as a foundation for more tests #11488

Merged
merged 3 commits into from
Apr 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
AnalyzerWaveformTest integrate simpleAnalyze test
daschuer committed Apr 17, 2023
commit d46920e9eaeb5edbaa415de02a163b6073d0ad8c
28 changes: 7 additions & 21 deletions src/test/analyserwaveformtest.cpp
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ class AnalyzerWaveformTest : public MixxxTest {
protected:
AnalyzerWaveformTest()
: aw(config(), QSqlDatabase()),
bigbuf(nullptr),
canaryBigBuf(nullptr) {
}

@@ -31,10 +30,6 @@ class AnalyzerWaveformTest : public MixxxTest {
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 canaryBigBuf looks like
// [ canary | big buf | canary ]

@@ -48,38 +43,29 @@ class AnalyzerWaveformTest : public MixxxTest {
}

void TearDown() override {
delete[] bigbuf;
delete[] canaryBigBuf;
}

protected:
AnalyzerWaveform aw;
TrackPointer tio;
CSAMPLE* bigbuf;
CSAMPLE* 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++) {
int i = 0;
for (; i < CANARY_SIZE; i++) {
EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT);
}
for (int i = CANARY_SIZE + BIGBUF_SIZE; i < 2 * CANARY_SIZE + BIGBUF_SIZE; i++) {
for (; i < CANARY_SIZE + BIGBUF_SIZE; i++) {
EXPECT_FLOAT_EQ(canaryBigBuf[i], MAGIC_FLOAT);
}
for (; i < 2 * CANARY_SIZE + BIGBUF_SIZE; i++) {
EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT);
}
}