Chromium Code Reviews| Index: tests/PaintTest.cpp |
| diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp |
| index e25c7c3f08a8efe41d3168050dd15e32b6cb7b6a..3a7fc503ce17dc2da8b22e7f410cd87f145de58c 100644 |
| --- a/tests/PaintTest.cpp |
| +++ b/tests/PaintTest.cpp |
| @@ -133,6 +133,19 @@ static void test_filterlevel(skiatest::Reporter* reporter) { |
| } |
| } |
| +// Helper to test equality between paints when we know nothing has mutated. |
| +class PaintEqualityHelper { |
| +public: |
| + static bool PaintEquals(const SkPaint& a, const SkPaint &b) { |
|
mtklein
2013/08/05 18:18:14
I think we can ditch the class and just have a fre
|
| + #ifdef SK_BUILD_FOR_ANDROID |
| + return !memcmp(&a, &b, SK_OFFSETOF(SkPaint, fGenerationID)); |
| + #else |
| + return !memcmp(&a, &b, sizeof(a)); |
| + #endif |
| +} |
| + |
| +}; |
| + |
| static void test_copy(skiatest::Reporter* reporter) { |
| SkPaint paint; |
| // set a few member variables |
| @@ -147,19 +160,19 @@ static void test_copy(skiatest::Reporter* reporter) { |
| // copy the paint using the copy constructor and check they are the same |
| SkPaint copiedPaint = paint; |
| - REPORTER_ASSERT(reporter, paint == copiedPaint); |
| + REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(paint, copiedPaint)); |
| #ifdef SK_BUILD_FOR_ANDROID |
| // the copy constructor should preserve the Generation ID |
| uint32_t paintGenID = paint.getGenerationID(); |
| uint32_t copiedPaintGenID = copiedPaint.getGenerationID(); |
| REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID); |
| - REPORTER_ASSERT(reporter, !memcmp(&paint, &copiedPaint, sizeof(paint))); |
| + REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(paint, copiedPaint)); |
| #endif |
| // copy the paint using the equal operator and check they are the same |
| copiedPaint = paint; |
| - REPORTER_ASSERT(reporter, paint == copiedPaint); |
| + REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(paint, copiedPaint)); |
| #ifdef SK_BUILD_FOR_ANDROID |
| // the equals operator should increment the Generation ID |
| @@ -173,15 +186,15 @@ static void test_copy(skiatest::Reporter* reporter) { |
| SkPaint cleanPaint; |
| paint.reset(); |
| copiedPaint.reset(); |
| - REPORTER_ASSERT(reporter, cleanPaint == paint); |
| - REPORTER_ASSERT(reporter, cleanPaint == copiedPaint); |
| + REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(cleanPaint, paint)); |
| + REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(cleanPaint, copiedPaint)); |
| #ifdef SK_BUILD_FOR_ANDROID |
| // the reset function should increment the Generation ID |
| REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID); |
| REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID); |
| - REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &paint, sizeof(cleanPaint))); |
| - REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &copiedPaint, sizeof(cleanPaint))); |
| + REPORTER_ASSERT(reporter, !PaintEqualityHelper::PaintEquals(cleanPaint, paint)); |
| + REPORTER_ASSERT(reporter, !PaintEqualityHelper::PaintEquals(cleanPaint, copiedPaint)); |
| #endif |
| } |