Add some tests for the buffer counter

This commit is contained in:
Jean Pierre Cimalando 2020-04-19 18:48:11 +02:00
parent f7e80452c4
commit 4562201455
2 changed files with 57 additions and 0 deletions

View file

@ -211,6 +211,14 @@ public:
_counter.bufferDeleted(largerSize * sizeof(value_type));
}
/**
* @brief Get the size of the larger block which is actually allocated
*/
size_t allocationSize() const noexcept
{
return largerSize;
}
/**
* @brief Construct a new Buffer object from an existing one
*

View file

@ -145,3 +145,52 @@ TEST_CASE("[Buffer] Copy and move")
checkBoundaries(moveConstructed, baseSize);
REQUIRE(std::all_of(moveConstructed.begin(), moveConstructed.end(), [](float value) { return value == 1.0f; }));
}
TEST_CASE("[Buffer] Buffer counter")
{
sfz::BufferCounter& counter = sfz::Buffer<float>::counter();
REQUIRE(counter.getNumBuffers() == 0);
REQUIRE(counter.getTotalBytes() == 0);
// create an empty buffer
sfz::Buffer<float> b1;
REQUIRE(counter.getNumBuffers() == 0);
REQUIRE(counter.getTotalBytes() == 0);
// clear an empty buffer
b1.clear();
REQUIRE(counter.getNumBuffers() == 0);
REQUIRE(counter.getTotalBytes() == 0);
// create a sized buffer
sfz::Buffer<float> b2(5);
REQUIRE(counter.getNumBuffers() == 1);
REQUIRE(counter.getTotalBytes() == (b2.allocationSize()) * sizeof(float));
// resize an empty buffer
b1.resize(3);
REQUIRE(counter.getNumBuffers() == 2);
REQUIRE(counter.getTotalBytes() == (b1.allocationSize() + b2.allocationSize()) * sizeof(float));
// resize a non-empty buffer
b1.resize(7);
REQUIRE(counter.getNumBuffers() == 2);
REQUIRE(counter.getTotalBytes() == (b1.allocationSize() + b2.allocationSize()) * sizeof(float));
// clear a non-empty buffer
b2.clear();
REQUIRE(counter.getNumBuffers() == 1);
REQUIRE(counter.getTotalBytes() == (b1.allocationSize()) * sizeof(float));
// move an empty buffer into a non-empty one
b1 = std::move(b2);
REQUIRE(counter.getNumBuffers() == 0);
REQUIRE(counter.getTotalBytes() == 0);
// move a non-empty buffer into an empty one
b1.resize(3);
b2 = std::move(b1);
REQUIRE(counter.getNumBuffers() == 1);
REQUIRE(counter.getTotalBytes() == (b2.allocationSize()) * sizeof(float));
}