DEF_TEST(Paint_copy, reporter) { SkPaint paint; // set a few member variables paint.setStyle(SkPaint::kStrokeAndFill_Style); paint.setTextAlign(SkPaint::kLeft_Align); paint.setStrokeWidth(SkIntToScalar(2)); // set a few pointers SkLayerDrawLooper::Builder looperBuilder; SkLayerDrawLooper* looper = looperBuilder.detachLooper(); paint.setLooper(looper)->unref(); SkMaskFilter* mask = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1))); paint.setMaskFilter(mask)->unref(); // copy the paint using the copy constructor and check they are the same SkPaint copiedPaint = paint; REPORTER_ASSERT(reporter, 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, paint == copiedPaint); #endif // copy the paint using the equal operator and check they are the same copiedPaint = paint; REPORTER_ASSERT(reporter, paint == copiedPaint); #ifdef SK_BUILD_FOR_ANDROID // the equals operator should increment the Generation ID REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID); REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID); copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value REPORTER_ASSERT(reporter, paint == copiedPaint); // operator== ignores fGenerationID #endif // clean the paint and check they are back to their initial states SkPaint cleanPaint; paint.reset(); copiedPaint.reset(); REPORTER_ASSERT(reporter, cleanPaint == paint); REPORTER_ASSERT(reporter, 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); // operator== ignores fGenerationID REPORTER_ASSERT(reporter, cleanPaint == paint); REPORTER_ASSERT(reporter, cleanPaint == copiedPaint); #endif }
static void test_copy(skiatest::Reporter* reporter) { SkPaint paint; // set a few member variables paint.setStyle(SkPaint::kStrokeAndFill_Style); paint.setTextAlign(SkPaint::kLeft_Align); paint.setStrokeWidth(SkIntToScalar(2)); // set a few pointers SkLayerDrawLooper* looper = new SkLayerDrawLooper(); paint.setLooper(looper)->unref(); SkMaskFilter* mask = SkBlurMaskFilter::Create(1, SkBlurMaskFilter::kNormal_BlurStyle); paint.setMaskFilter(mask)->unref(); // copy the paint using the copy constructor and check they are the same SkPaint copiedPaint = paint; REPORTER_ASSERT(reporter, 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))); #endif // copy the paint using the equal operator and check they are the same copiedPaint = paint; REPORTER_ASSERT(reporter, paint == copiedPaint); #ifdef SK_BUILD_FOR_ANDROID // the equals operator should increment the Generation ID REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID); REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID); copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value REPORTER_ASSERT(reporter, memcmp(&paint, &copiedPaint, sizeof(paint))); #endif // clean the paint and check they are back to their initial states SkPaint cleanPaint; paint.reset(); copiedPaint.reset(); REPORTER_ASSERT(reporter, cleanPaint == paint); REPORTER_ASSERT(reporter, 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))); #endif }