aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ArenaAllocTest.cpp
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2017-01-18 17:07:48 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-18 22:47:03 +0000
commit412a86d014783be99a7a9a0fae407791b95806e8 (patch)
tree975f558737da818017a56cfc2727137e5c0628ba /tests/ArenaAllocTest.cpp
parent95acbad4fee03a2fa2c0419da70a1b85e21739ef (diff)
Fix reset and deleting behavior.
* Reset the Arena state. * Call all the dtors before deleting the blocks. TBR=mtklein@google.com Change-Id: Iac320fec16e572cc9a6184c1f580089ab720f036 Reviewed-on: https://skia-review.googlesource.com/7221 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);
}