Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: tests/RecordTest.cpp

Issue 517073002: Align all SkRecord::alloc() calls up to at least a pointer size. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkAlignPtr Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkRecord.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RecordTest.cpp
diff --git a/tests/RecordTest.cpp b/tests/RecordTest.cpp
index 2240ae985825ee270525ba51a0299d56f52fdd0f..2a0e615516d01df8391a6fee2a7f32f8d56cbf95 100644
--- a/tests/RecordTest.cpp
+++ b/tests/RecordTest.cpp
@@ -78,3 +78,28 @@ DEF_TEST(Record, r) {
#undef APPEND
+template <typename T>
+static bool is_aligned(const T* p) {
+ return (((uintptr_t)p) & (sizeof(T) - 1)) == 0;
+}
+
+DEF_TEST(Record_Alignment, r) {
+ SkRecord record;
+
+ // Of course a byte's always aligned.
+ REPORTER_ASSERT(r, is_aligned(record.alloc<uint8_t>()));
+
+ // (If packed tightly, the rest below here would be off by one.)
+
+ // It happens that the first implementation always aligned to 4 bytes,
+ // so these two were always correct.
+ REPORTER_ASSERT(r, is_aligned(record.alloc<uint16_t>()));
+ REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>()));
+
+ // These two are regression tests (void* only on 64-bit machines).
+ REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>()));
+ REPORTER_ASSERT(r, is_aligned(record.alloc<void*>()));
+
+ // We're not testing beyond sizeof(void*), which is where the current implementation will break.
+}
+
« no previous file with comments | « src/core/SkRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698