OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkChunkAlloc.h" | 8 #include "SkChunkAlloc.h" |
9 #include "SkUtils.h" | 9 #include "SkUtils.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
12 static void check_alloc(skiatest::Reporter* reporter, const SkChunkAlloc& alloc, | 12 static void check_alloc(skiatest::Reporter* reporter, const SkChunkAlloc& alloc, |
13 size_t capacity, size_t used, int numBlocks) { | 13 size_t capacity, size_t used, int numBlocks) { |
14 REPORTER_ASSERT(reporter, alloc.totalCapacity() >= capacity); | 14 REPORTER_ASSERT(reporter, alloc.totalCapacity() >= capacity); |
15 REPORTER_ASSERT(reporter, alloc.totalUsed() == used); | 15 REPORTER_ASSERT(reporter, alloc.totalUsed() == used); |
16 SkDEBUGCODE(REPORTER_ASSERT(reporter, alloc.blockCount() == numBlocks);) | 16 SkDEBUGCODE(REPORTER_ASSERT(reporter, alloc.blockCount() == numBlocks);) |
17 } | 17 } |
18 | 18 |
19 static void* simple_alloc(skiatest::Reporter* reporter, SkChunkAlloc* alloc, siz
e_t size) { | 19 static void* simple_alloc(skiatest::Reporter* reporter, SkChunkAlloc* alloc, siz
e_t size) { |
20 void* ptr = alloc->allocThrow(size); | 20 void* ptr = alloc->allocThrow(size); |
21 check_alloc(reporter, *alloc, size, size, 1); | 21 check_alloc(reporter, *alloc, size, size, 1); |
22 REPORTER_ASSERT(reporter, alloc->contains(ptr)); | 22 REPORTER_ASSERT(reporter, alloc->contains(ptr)); |
23 return ptr; | 23 return ptr; |
24 } | 24 } |
25 | 25 |
26 static void test_chunkalloc(skiatest::Reporter* reporter) { | 26 static void test_chunkalloc(skiatest::Reporter* reporter) { |
27 static const size_t kMin = 1024; | 27 static const size_t kMin = 1024; |
28 SkChunkAlloc alloc(kMin); | 28 SkChunkAlloc alloc(kMin); |
29 | 29 |
30 //------------------------------------------------------------------------ | 30 //------------------------------------------------------------------------ |
31 // check empty | 31 // check empty |
32 check_alloc(reporter, alloc, 0, 0, 0); | 32 check_alloc(reporter, alloc, 0, 0, 0); |
33 REPORTER_ASSERT(reporter, !alloc.contains(nullptr)); | 33 REPORTER_ASSERT(reporter, !alloc.contains(nullptr)); |
34 REPORTER_ASSERT(reporter, !alloc.contains(reporter)); | 34 REPORTER_ASSERT(reporter, !alloc.contains(reporter)); |
35 | 35 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 * Test sk_memset16 and sk_memset32. | 153 * Test sk_memset16 and sk_memset32. |
154 * For performance considerations, implementations may take different paths | 154 * For performance considerations, implementations may take different paths |
155 * depending on the alignment of the dst, and/or the size of the count. | 155 * depending on the alignment of the dst, and/or the size of the count. |
156 */ | 156 */ |
157 DEF_TEST(Memset, reporter) { | 157 DEF_TEST(Memset, reporter) { |
158 test_16(reporter); | 158 test_16(reporter); |
159 test_32(reporter); | 159 test_32(reporter); |
160 | 160 |
161 test_chunkalloc(reporter); | 161 test_chunkalloc(reporter); |
162 } | 162 } |
OLD | NEW |