Chromium Code Reviews| Index: tests/StackAllocatorTest.cpp |
| diff --git a/tests/StackAllocatorTest.cpp b/tests/StackAllocatorTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bf16c584f84959a7e3b9e06c1e04a1e130de49d9 |
| --- /dev/null |
| +++ b/tests/StackAllocatorTest.cpp |
| @@ -0,0 +1,49 @@ |
| +/* |
| + * Copyright 2014 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" |
|
tfarina
2014/02/27 17:33:15
could you keep this sorted?
scroggo
2014/03/05 20:25:52
Done.
|
| +#include "SkStackAllocator.h" |
| +#include "SkTypes.h" |
| + |
| +class CountingClass { |
| +public: |
| + CountingClass() { |
| + kCount++; |
| + } |
| + |
| + ~CountingClass() { |
| + kCount--; |
| + } |
| + |
| + static int GetCount() { return kCount; } |
| + |
| +private: |
| + static int kCount; |
| +}; |
| + |
| +int CountingClass::kCount; |
| + |
| +template<size_t size> void test_allocator(skiatest::Reporter* reporter) { |
| + { |
| + SkStackAllocator<size> alloc; |
| + for (int i = 0; i < 99; ++i) { |
| + void* buf = alloc.template reserveT<CountingClass>(); |
| + SkNEW_PLACEMENT(buf, CountingClass); |
| + CountingClass* c = static_cast<CountingClass*>(buf); |
| + REPORTER_ASSERT(reporter, c != NULL); |
| + REPORTER_ASSERT(reporter, CountingClass::GetCount() == i+1); |
| + } |
| + } |
| + REPORTER_ASSERT(reporter, CountingClass::GetCount() == 0); |
| +} |
| + |
| +DEF_TEST(StackAllocator, reporter) { |
| + test_allocator<0>(reporter); |
| + test_allocator<5>(reporter); |
| + test_allocator<50>(reporter); |
| + test_allocator<100>(reporter); |
| +} |