summaryrefslogtreecommitdiffstats
path: root/src/tests/common/scratch_buffer.cpp
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2022-12-20 04:40:50 +0100
committerameerj <52414509+ameerj@users.noreply.github.com>2022-12-20 04:40:50 +0100
commitc6590ad07b384762fd90ee8852796ec681a69286 (patch)
treec0d8d2d157f3bb4be01331f2da459c0f68ca4d7b /src/tests/common/scratch_buffer.cpp
parenttests: Add ScratchBuffer tests (diff)
downloadyuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar
yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.gz
yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.bz2
yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.lz
yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.xz
yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.zst
yuzu-c6590ad07b384762fd90ee8852796ec681a69286.zip
Diffstat (limited to '')
-rw-r--r--src/tests/common/scratch_buffer.cpp78
1 files changed, 75 insertions, 3 deletions
diff --git a/src/tests/common/scratch_buffer.cpp b/src/tests/common/scratch_buffer.cpp
index a59490f55..b602c8d0a 100644
--- a/src/tests/common/scratch_buffer.cpp
+++ b/src/tests/common/scratch_buffer.cpp
@@ -29,7 +29,7 @@ TEST_CASE("ScratchBuffer: Basic Test", "[common]") {
}
}
-TEST_CASE("ScratchBuffer: Resize Grow", "[common]") {
+TEST_CASE("ScratchBuffer: resize_destructive Grow", "[common]") {
std::array<u8, 10> payload;
payload.fill(66);
@@ -38,14 +38,86 @@ TEST_CASE("ScratchBuffer: Resize Grow", "[common]") {
REQUIRE(buf.capacity() == payload.size());
// Increasing the size should reallocate the buffer
- buf.resize(payload.size() * 2);
+ buf.resize_destructive(payload.size() * 2);
REQUIRE(buf.size() == payload.size() * 2);
REQUIRE(buf.capacity() == payload.size() * 2);
// Since the buffer is not value initialized, reading its data will be garbage
}
-TEST_CASE("ScratchBuffer: Resize Shrink", "[common]") {
+TEST_CASE("ScratchBuffer: resize_destructive Shrink", "[common]") {
+ std::array<u8, 10> payload;
+ payload.fill(66);
+
+ ScratchBuffer<u8> buf(payload.size());
+ REQUIRE(buf.size() == payload.size());
+ REQUIRE(buf.capacity() == payload.size());
+
+ std::memcpy(buf.data(), payload.data(), payload.size());
+ for (size_t i = 0; i < payload.size(); ++i) {
+ REQUIRE(buf[i] == payload[i]);
+ }
+
+ // Decreasing the size should not cause a buffer reallocation
+ // This can be tested by ensuring the buffer capacity and data has not changed,
+ buf.resize_destructive(1U);
+ REQUIRE(buf.size() == 1U);
+ REQUIRE(buf.capacity() == payload.size());
+
+ for (size_t i = 0; i < payload.size(); ++i) {
+ REQUIRE(buf[i] == payload[i]);
+ }
+}
+
+TEST_CASE("ScratchBuffer: resize Grow u8", "[common]") {
+ std::array<u8, 10> payload;
+ payload.fill(66);
+
+ ScratchBuffer<u8> buf(payload.size());
+ REQUIRE(buf.size() == payload.size());
+ REQUIRE(buf.capacity() == payload.size());
+
+ std::memcpy(buf.data(), payload.data(), payload.size());
+ for (size_t i = 0; i < payload.size(); ++i) {
+ REQUIRE(buf[i] == payload[i]);
+ }
+
+ // Increasing the size should reallocate the buffer
+ buf.resize(payload.size() * 2);
+ REQUIRE(buf.size() == payload.size() * 2);
+ REQUIRE(buf.capacity() == payload.size() * 2);
+
+ // resize() keeps the previous data intact
+ for (size_t i = 0; i < payload.size(); ++i) {
+ REQUIRE(buf[i] == payload[i]);
+ }
+}
+
+TEST_CASE("ScratchBuffer: resize Grow u64", "[common]") {
+ std::array<u64, 10> payload;
+ payload.fill(6666);
+
+ ScratchBuffer<u64> buf(payload.size());
+ REQUIRE(buf.size() == payload.size());
+ REQUIRE(buf.capacity() == payload.size());
+
+ std::memcpy(buf.data(), payload.data(), payload.size() * sizeof(u64));
+ for (size_t i = 0; i < payload.size(); ++i) {
+ REQUIRE(buf[i] == payload[i]);
+ }
+
+ // Increasing the size should reallocate the buffer
+ buf.resize(payload.size() * 2);
+ REQUIRE(buf.size() == payload.size() * 2);
+ REQUIRE(buf.capacity() == payload.size() * 2);
+
+ // resize() keeps the previous data intact
+ for (size_t i = 0; i < payload.size(); ++i) {
+ REQUIRE(buf[i] == payload[i]);
+ }
+}
+
+TEST_CASE("ScratchBuffer: resize Shrink", "[common]") {
std::array<u8, 10> payload;
payload.fill(66);