Skip to content

Commit

Permalink
Tests: DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnnz committed Mar 30, 2024
1 parent ced2280 commit 9bc7561
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions tests/audioBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ void fillBufferWithData(AudioBuffer& b)
});
}

void testMove(AudioBuffer& a, AudioBuffer& b, int sourceBufferSize, int sourceNumChannels)
{
REQUIRE(b.isAllocd() == false);
REQUIRE(b.countFrames() == 0);
REQUIRE(b.countSamples() == 0);
REQUIRE(b.countChannels() == 0);

REQUIRE(a.isAllocd() == true);
REQUIRE(a.countFrames() == sourceBufferSize);
REQUIRE(a.countSamples() == sourceBufferSize * sourceNumChannels);
REQUIRE(a.countChannels() == sourceNumChannels);

a.forEachFrame([](float* channels, int numFrame) {
REQUIRE(channels[0] == static_cast<float>(numFrame));
REQUIRE(channels[1] == static_cast<float>(numFrame));
});
}

TEST_CASE("AudioBuffer")
{

Expand Down Expand Up @@ -111,20 +129,7 @@ TEST_CASE("AudioBuffer")

AudioBuffer a(std::move(b));

REQUIRE(b.isAllocd() == false);
REQUIRE(b.countFrames() == 0);
REQUIRE(b.countSamples() == 0);
REQUIRE(b.countChannels() == 0);

REQUIRE(a.isAllocd() == true);
REQUIRE(a.countFrames() == BUFFER_SIZE);
REQUIRE(a.countSamples() == BUFFER_SIZE * numChannels);
REQUIRE(a.countChannels() == numChannels);

a.forEachFrame([](float* channels, int numFrame) {
REQUIRE(channels[0] == static_cast<float>(numFrame));
REQUIRE(channels[1] == static_cast<float>(numFrame));
});
testMove(a, b, BUFFER_SIZE, numChannels);
}

SECTION("with move assignment")
Expand All @@ -137,20 +142,7 @@ TEST_CASE("AudioBuffer")

a = std::move(b);

REQUIRE(b.isAllocd() == false);
REQUIRE(b.countFrames() == 0);
REQUIRE(b.countSamples() == 0);
REQUIRE(b.countChannels() == 0);

REQUIRE(a.isAllocd() == true);
REQUIRE(a.countFrames() == BUFFER_SIZE);
REQUIRE(a.countSamples() == BUFFER_SIZE * numChannels);
REQUIRE(a.countChannels() == numChannels);

a.forEachFrame([](float* channels, int numFrame) {
REQUIRE(channels[0] == static_cast<float>(numFrame));
REQUIRE(channels[1] == static_cast<float>(numFrame));
});
testMove(a, b, BUFFER_SIZE, numChannels);
}
}
}

0 comments on commit 9bc7561

Please sign in to comment.