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

Unified Diff: tests/PictureTest.cpp

Issue 150653010: Add unit test for unbalanced save and restores in pictures. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix typo Created 6 years, 10 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 | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PictureTest.cpp
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 002fe8f441544ad22ab3fc269de4cbef0e2f9f99..93eff797c3b1a0101764c098baf9cc9e3f7977f1 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -681,6 +681,62 @@ static void rand_op(SkCanvas* canvas, SkRandom& rand) {
}
}
+static void set_canvas_to_save_count_4(SkCanvas* canvas) {
+ canvas->restoreToCount(1);
+ canvas->save();
+ canvas->save();
+ canvas->save();
+}
+
+static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
+ SkCanvas testCanvas(100, 100);
+ set_canvas_to_save_count_4(&testCanvas);
+
+ REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
+
+ SkPaint paint;
+ SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000);
+
+ SkPicture extra_save_picture;
+ extra_save_picture.beginRecording(100, 100);
+ extra_save_picture.getRecordingCanvas()->save();
+ extra_save_picture.getRecordingCanvas()->translate(10, 10);
+ extra_save_picture.getRecordingCanvas()->drawRect(rect, paint);
+ extra_save_picture.getRecordingCanvas()->save();
+ extra_save_picture.getRecordingCanvas()->translate(10, 10);
+ extra_save_picture.getRecordingCanvas()->drawRect(rect, paint);
+
+ testCanvas.drawPicture(extra_save_picture);
+ REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
+
+ set_canvas_to_save_count_4(&testCanvas);
+
+ SkPicture extra_restore_picture;
+ extra_restore_picture.beginRecording(100, 100);
+ extra_restore_picture.getRecordingCanvas()->save();
+ extra_restore_picture.getRecordingCanvas()->translate(10, 10);
+ extra_restore_picture.getRecordingCanvas()->drawRect(rect, paint);
+ extra_restore_picture.getRecordingCanvas()->save();
+ extra_restore_picture.getRecordingCanvas()->translate(10, 10);
+ extra_restore_picture.getRecordingCanvas()->drawRect(rect, paint);
+ extra_restore_picture.getRecordingCanvas()->restore();
+ extra_restore_picture.getRecordingCanvas()->restore();
+ extra_restore_picture.getRecordingCanvas()->restore();
+ extra_restore_picture.getRecordingCanvas()->restore();
+
+ testCanvas.drawPicture(extra_save_picture);
+ REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
+
+ SkPicture no_save_picture;
+ extra_restore_picture.beginRecording(100, 100);
+ extra_restore_picture.getRecordingCanvas()->translate(10, 10);
+ extra_restore_picture.getRecordingCanvas()->drawRect(rect, paint);
+
+ testCanvas.drawPicture(extra_save_picture);
+ REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
+ REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity());
+}
+
static void test_peephole() {
SkRandom rand;
@@ -1022,6 +1078,7 @@ DEF_TEST(Picture, reporter) {
#else
test_bad_bitmap();
#endif
+ test_unbalanced_save_restores(reporter);
test_peephole();
test_gatherpixelrefs(reporter);
test_gatherpixelrefsandrects(reporter);
« no previous file with comments | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698