OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 Stretch stretch; | 71 Stretch stretch; |
72 stretch.apply(&record); | 72 stretch.apply(&record); |
73 | 73 |
74 // Now its area should be 100 + 400. | 74 // Now its area should be 100 + 400. |
75 summer.apply(record); | 75 summer.apply(record); |
76 REPORTER_ASSERT(r, summer.area() == 500); | 76 REPORTER_ASSERT(r, summer.area() == 500); |
77 } | 77 } |
78 | 78 |
79 #undef APPEND | 79 #undef APPEND |
80 | 80 |
| 81 template <typename T> |
| 82 static bool is_aligned(const T* p) { |
| 83 return (((uintptr_t)p) & (sizeof(T) - 1)) == 0; |
| 84 } |
| 85 |
| 86 DEF_TEST(Record_Alignment, r) { |
| 87 SkRecord record; |
| 88 |
| 89 // Of course a byte's always aligned. |
| 90 REPORTER_ASSERT(r, is_aligned(record.alloc<uint8_t>())); |
| 91 |
| 92 // (If packed tightly, the rest below here would be off by one.) |
| 93 |
| 94 // It happens that the first implementation always aligned to 4 bytes, |
| 95 // so these two were always correct. |
| 96 REPORTER_ASSERT(r, is_aligned(record.alloc<uint16_t>())); |
| 97 REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>())); |
| 98 |
| 99 // These two are regression tests (void* only on 64-bit machines). |
| 100 REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>())); |
| 101 REPORTER_ASSERT(r, is_aligned(record.alloc<void*>())); |
| 102 |
| 103 // We're not testing beyond sizeof(void*), which is where the current implem
entation will break. |
| 104 } |
| 105 |
OLD | NEW |