aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ArenaAllocTest.cpp
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2017-01-19 14:28:49 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-19 20:34:36 +0000
commit593cb94d1ce6f68a5b616cbfe3f4b69dc70832c3 (patch)
tree3a0a28a57bfbcccc0b4f18f01ddd0825d46b9928 /tests/ArenaAllocTest.cpp
parentd8ee67c381129b5f96bd1afbb8abc62d04d9ace2 (diff)
Fix reset and deleting behavior.
* Reset the Arena state. * Call all the dtors before deleting the blocks. Change-Id: I6d90463966ac7bf9f0a4fda229f67d508c86bebb Reviewed-on: https://skia-review.googlesource.com/7308 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'tests/ArenaAllocTest.cpp')
-rw-r--r--tests/ArenaAllocTest.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/ArenaAllocTest.cpp b/tests/ArenaAllocTest.cpp
index 647ea25283..0836b0c49f 100644
--- a/tests/ArenaAllocTest.cpp
+++ b/tests/ArenaAllocTest.cpp
@@ -26,6 +26,26 @@ namespace {
uint32_t array[128];
};
+ struct Node {
+ Node(Node* n) : next(n) { created++; }
+ ~Node() {
+ destroyed++;
+ if (next) {
+ next->~Node();
+ }
+ }
+ Node *next;
+ };
+
+ struct Start {
+ ~Start() {
+ if (start) {
+ start->~Node();
+ }
+ }
+ Node* start;
+ };
+
}
struct WithDtor {
@@ -63,7 +83,7 @@ DEF_TEST(ArenaAlloc, r) {
{
created = 0;
destroyed = 0;
- char block[1024];
+ char block[64];
SkArenaAlloc arena{block};
REPORTER_ASSERT(r, *arena.make<int>(3) == 3);
@@ -113,4 +133,30 @@ DEF_TEST(ArenaAlloc, r) {
}
REPORTER_ASSERT(r, created == 11);
REPORTER_ASSERT(r, destroyed == 11);
+
+ {
+ char storage[64];
+ SkArenaAlloc arena{storage};
+ arena.makeArrayDefault<char>(256);
+ arena.reset();
+ arena.reset();
+ }
+
+ {
+ created = 0;
+ destroyed = 0;
+ char storage[64];
+ SkArenaAlloc arena{storage};
+
+ Start start;
+ Node* current = nullptr;
+ for (int i = 0; i < 128; i++) {
+ uint64_t* temp = arena.makeArrayDefault<uint64_t>(sizeof(Node) / sizeof(Node*));
+ current = new (temp)Node(current);
+ }
+ start.start = current;
+ }
+
+ REPORTER_ASSERT(r, created == 128);
+ REPORTER_ASSERT(r, destroyed == 128);
}