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

Unified Diff: tests/RecordPatternTest.cpp

Issue 798593003: Revert of Defer saves() until they're needed (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 | « tests/RecordOptsTest.cpp ('k') | tests/RecordReplaceDrawTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RecordPatternTest.cpp
diff --git a/tests/RecordPatternTest.cpp b/tests/RecordPatternTest.cpp
index 1f5ce2c046c28573b72d077af394be8251deb2e4..5f4d00668345f2957e54123e8c9001c16392ad1c 100644
--- a/tests/RecordPatternTest.cpp
+++ b/tests/RecordPatternTest.cpp
@@ -75,19 +75,56 @@
SkRecord record;
SkRecorder recorder(&record, 1920, 1200);
- int index = 0;
+
+ recorder.save();
+ recorder.restore();
+ REPORTER_ASSERT(r, pattern.match(&record, 0));
recorder.save();
recorder.clipRect(SkRect::MakeWH(300, 200));
recorder.restore();
- REPORTER_ASSERT(r, pattern.match(&record, index));
- index += 3;
+ REPORTER_ASSERT(r, pattern.match(&record, 2));
recorder.save();
recorder.clipRect(SkRect::MakeWH(300, 200));
recorder.clipRect(SkRect::MakeWH(100, 100));
recorder.restore();
- REPORTER_ASSERT(r, pattern.match(&record, index));
+ REPORTER_ASSERT(r, pattern.match(&record, 5));
+}
+
+DEF_TEST(RecordPattern_IsDraw, r) {
+ Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern;
+
+ SkRecord record;
+ SkRecorder recorder(&record, 1920, 1200);
+
+ recorder.save();
+ recorder.clipRect(SkRect::MakeWH(300, 200));
+ recorder.restore();
+
+ REPORTER_ASSERT(r, !pattern.match(&record, 0));
+
+ SkPaint paint;
+
+ recorder.save();
+ paint.setColor(0xEEAA8822);
+ recorder.drawRect(SkRect::MakeWH(300, 200), paint);
+ recorder.restore();
+
+ recorder.save();
+ paint.setColor(0xFACEFACE);
+ recorder.drawPaint(paint);
+ recorder.restore();
+
+ REPORTER_ASSERT(r, pattern.match(&record, 3));
+ REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
+ REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xEEAA8822);
+ REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
+
+ REPORTER_ASSERT(r, pattern.match(&record, 6));
+ REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
+ REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xFACEFACE);
+ REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
}
DEF_TEST(RecordPattern_Complex, r) {
@@ -99,39 +136,54 @@
SkRecord record;
SkRecorder recorder(&record, 1920, 1200);
- unsigned start, begin, end;
- start = record.count();
+ recorder.save();
+ recorder.restore();
+ REPORTER_ASSERT(r, pattern.match(&record, 0) == 2);
+
+ recorder.save();
+ recorder.save();
+ recorder.restore();
+ recorder.restore();
+ REPORTER_ASSERT(r, !pattern.match(&record, 2));
+ REPORTER_ASSERT(r, pattern.match(&record, 3) == 5);
+
recorder.save();
recorder.clipRect(SkRect::MakeWH(300, 200));
recorder.restore();
- REPORTER_ASSERT(r, pattern.match(&record, 0) == record.count());
- end = start;
- REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
- REPORTER_ASSERT(r, begin == start);
- REPORTER_ASSERT(r, end == record.count());
+ REPORTER_ASSERT(r, pattern.match(&record, 6) == 9);
- start = record.count();
recorder.save();
recorder.clipRect(SkRect::MakeWH(300, 200));
recorder.drawRect(SkRect::MakeWH(100, 3000), SkPaint());
recorder.restore();
- REPORTER_ASSERT(r, !pattern.match(&record, start));
- end = start;
- REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
+ REPORTER_ASSERT(r, !pattern.match(&record, 9));
- start = record.count();
recorder.save();
recorder.pushCull(SkRect::MakeWH(300, 200));
recorder.clipRect(SkRect::MakeWH(300, 200));
recorder.clipRect(SkRect::MakeWH(100, 400));
recorder.popCull();
recorder.restore();
- REPORTER_ASSERT(r, pattern.match(&record, start) == record.count());
- end = start;
+ REPORTER_ASSERT(r, pattern.match(&record, 13) == 19);
+
+ // Same as above, but using pattern.search to step through matches.
+ unsigned begin, end = 0;
REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
- REPORTER_ASSERT(r, begin == start);
- REPORTER_ASSERT(r, end == record.count());
+ REPORTER_ASSERT(r, begin == 0);
+ REPORTER_ASSERT(r, end == 2);
+
+ REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
+ REPORTER_ASSERT(r, begin == 3);
+ REPORTER_ASSERT(r, end == 5);
+
+ REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
+ REPORTER_ASSERT(r, begin == 6);
+ REPORTER_ASSERT(r, end == 9);
+
+ REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
+ REPORTER_ASSERT(r, begin == 13);
+ REPORTER_ASSERT(r, end == 19);
REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
}
« no previous file with comments | « tests/RecordOptsTest.cpp ('k') | tests/RecordReplaceDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698