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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 #undef APPEND | 79 #undef APPEND |
80 | 80 |
81 template <typename T> | 81 template <typename T> |
82 static bool is_aligned(const T* p) { | 82 static bool is_aligned(const T* p) { |
83 return (((uintptr_t)p) & (sizeof(T) - 1)) == 0; | 83 return (((uintptr_t)p) & (sizeof(T) - 1)) == 0; |
84 } | 84 } |
85 | 85 |
86 DEF_TEST(Record_Alignment, r) { | 86 DEF_TEST(Record_Alignment, r) { |
87 SkRecord record; | 87 SkRecord record; |
88 | |
89 // Of course a byte's always aligned. | |
90 REPORTER_ASSERT(r, is_aligned(record.alloc<uint8_t>())); | 88 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>())); | 89 REPORTER_ASSERT(r, is_aligned(record.alloc<uint16_t>())); |
97 REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>())); | 90 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*>())); | 91 REPORTER_ASSERT(r, is_aligned(record.alloc<void*>())); |
102 | 92 |
103 // We're not testing beyond sizeof(void*), which is where the current implem
entation will break. | 93 // It's not clear if we care that 8-byte values are aligned on 32-bit machin
es. |
| 94 if (sizeof(void*) == 8) { |
| 95 REPORTER_ASSERT(r, is_aligned(record.alloc<double>())); |
| 96 REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>())); |
| 97 } |
104 } | 98 } |
105 | 99 |
OLD | NEW |