OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2014 Google, Inc | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "Test.h" | |
tfarina
2014/02/27 17:33:15
could you keep this sorted?
scroggo
2014/03/05 20:25:52
Done.
| |
9 #include "SkStackAllocator.h" | |
10 #include "SkTypes.h" | |
11 | |
12 class CountingClass { | |
13 public: | |
14 CountingClass() { | |
15 kCount++; | |
16 } | |
17 | |
18 ~CountingClass() { | |
19 kCount--; | |
20 } | |
21 | |
22 static int GetCount() { return kCount; } | |
23 | |
24 private: | |
25 static int kCount; | |
26 }; | |
27 | |
28 int CountingClass::kCount; | |
29 | |
30 template<size_t size> void test_allocator(skiatest::Reporter* reporter) { | |
31 { | |
32 SkStackAllocator<size> alloc; | |
33 for (int i = 0; i < 99; ++i) { | |
34 void* buf = alloc.template reserveT<CountingClass>(); | |
35 SkNEW_PLACEMENT(buf, CountingClass); | |
36 CountingClass* c = static_cast<CountingClass*>(buf); | |
37 REPORTER_ASSERT(reporter, c != NULL); | |
38 REPORTER_ASSERT(reporter, CountingClass::GetCount() == i+1); | |
39 } | |
40 } | |
41 REPORTER_ASSERT(reporter, CountingClass::GetCount() == 0); | |
42 } | |
43 | |
44 DEF_TEST(StackAllocator, reporter) { | |
45 test_allocator<0>(reporter); | |
46 test_allocator<5>(reporter); | |
47 test_allocator<50>(reporter); | |
48 test_allocator<100>(reporter); | |
49 } | |
OLD | NEW |