diff options
author | Herb Derby <herb@google.com> | 2017-01-13 17:34:33 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-16 17:01:57 +0000 |
commit | ac04fef619ad3939a25e66bdaef6f6b1e7f5ca50 (patch) | |
tree | d30efcbac91ac1a4b434d910a64487e70efbde0d /tests/ArenaAllocTest.cpp | |
parent | 26e73c057755df4fbffeee372be98e430867034d (diff) |
Remove SkFallbackAlloc and SkFixedAlloc.
CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-ASAN;skia.primary:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-MSAN
TBR=reed@google.com
Change-Id: I1000dc9ed8ad65b249798759d9af99f47fc237d2
Reviewed-on: https://skia-review.googlesource.com/6809
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.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/tests/ArenaAllocTest.cpp b/tests/ArenaAllocTest.cpp new file mode 100644 index 0000000000..647ea25283 --- /dev/null +++ b/tests/ArenaAllocTest.cpp @@ -0,0 +1,116 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "Test.h" +#include "SkArenaAlloc.h" + +namespace { + + static int created, destroyed; + + struct Foo { + Foo() : x(-2), y(-3.0f) { created++; } + Foo(int X, float Y) : x(X), y(Y) { created++; } + ~Foo() { destroyed++; } + + int x; + float y; + }; + + struct Big { + Big() {} + uint32_t array[128]; + }; + +} + +struct WithDtor { + ~WithDtor() { } +}; + +DEF_TEST(ArenaAlloc, r) { + + { + created = 0; + destroyed = 0; + + SkArenaAlloc arena{nullptr, 0}; + REPORTER_ASSERT(r, *arena.make<int>(3) == 3); + Foo* foo = arena.make<Foo>(3, 4.0f); + REPORTER_ASSERT(r, foo->x == 3); + REPORTER_ASSERT(r, foo->y == 4.0f); + REPORTER_ASSERT(r, created == 1); + REPORTER_ASSERT(r, destroyed == 0); + arena.makeArrayDefault<int>(10); + int* zeroed = arena.makeArray<int>(10); + for (int i = 0; i < 10; i++) { + REPORTER_ASSERT(r, zeroed[i] == 0); + } + Foo* fooArray = arena.makeArrayDefault<Foo>(10); + REPORTER_ASSERT(r, fooArray[3].x == -2); + REPORTER_ASSERT(r, fooArray[4].y == -3.0f); + REPORTER_ASSERT(r, created == 11); + REPORTER_ASSERT(r, destroyed == 0); + arena.make<typename std::aligned_storage<10,8>::type>(); + } + REPORTER_ASSERT(r, created == 11); + REPORTER_ASSERT(r, destroyed == 11); + + { + created = 0; + destroyed = 0; + char block[1024]; + SkArenaAlloc arena{block}; + + REPORTER_ASSERT(r, *arena.make<int>(3) == 3); + Foo* foo = arena.make<Foo>(3, 4.0f); + REPORTER_ASSERT(r, foo->x == 3); + REPORTER_ASSERT(r, foo->y == 4.0f); + REPORTER_ASSERT(r, created == 1); + REPORTER_ASSERT(r, destroyed == 0); + arena.makeArrayDefault<int>(10); + int* zeroed = arena.makeArray<int>(10); + for (int i = 0; i < 10; i++) { + REPORTER_ASSERT(r, zeroed[i] == 0); + } + Foo* fooArray = arena.makeArrayDefault<Foo>(10); + REPORTER_ASSERT(r, fooArray[3].x == -2); + REPORTER_ASSERT(r, fooArray[4].y == -3.0f); + REPORTER_ASSERT(r, created == 11); + REPORTER_ASSERT(r, destroyed == 0); + arena.make<typename std::aligned_storage<10,8>::type>(); + } + REPORTER_ASSERT(r, created == 11); + REPORTER_ASSERT(r, destroyed == 11); + + { + created = 0; + destroyed = 0; + std::unique_ptr<char[]> block{new char[1024]}; + SkArenaAlloc arena{block.get(), 1024}; + + REPORTER_ASSERT(r, *arena.make<int>(3) == 3); + Foo* foo = arena.make<Foo>(3, 4.0f); + REPORTER_ASSERT(r, foo->x == 3); + REPORTER_ASSERT(r, foo->y == 4.0f); + REPORTER_ASSERT(r, created == 1); + REPORTER_ASSERT(r, destroyed == 0); + arena.makeArrayDefault<int>(10); + int* zeroed = arena.makeArray<int>(10); + for (int i = 0; i < 10; i++) { + REPORTER_ASSERT(r, zeroed[i] == 0); + } + Foo* fooArray = arena.makeArrayDefault<Foo>(10); + REPORTER_ASSERT(r, fooArray[3].x == -2); + REPORTER_ASSERT(r, fooArray[4].y == -3.0f); + REPORTER_ASSERT(r, created == 11); + REPORTER_ASSERT(r, destroyed == 0); + arena.make<typename std::aligned_storage<10,8>::type>(); + } + REPORTER_ASSERT(r, created == 11); + REPORTER_ASSERT(r, destroyed == 11); +} |