aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RecordPatternTest.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-12-11 07:07:37 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-11 07:07:38 -0800
commit2ff1fcede1e9525285c5de1f35fb2dcb0fab32bd (patch)
treed031604a9c76281aa645c56a94ada8422b5b291d /tests/RecordPatternTest.cpp
parent8da8e9d7511c2f60855c2e3334ae0fe27365bc96 (diff)
Defer saves() until they're needed
patch from issue 759443006 at patchset 40001 (http://crrev.com/759443006#ps40001) BUG=skia: Review URL: https://codereview.chromium.org/767333002
Diffstat (limited to 'tests/RecordPatternTest.cpp')
-rw-r--r--tests/RecordPatternTest.cpp92
1 files changed, 20 insertions, 72 deletions
diff --git a/tests/RecordPatternTest.cpp b/tests/RecordPatternTest.cpp
index 5f4d006683..1f5ce2c046 100644
--- a/tests/RecordPatternTest.cpp
+++ b/tests/RecordPatternTest.cpp
@@ -75,56 +75,19 @@ DEF_TEST(RecordPattern_Star, r) {
SkRecord record;
SkRecorder recorder(&record, 1920, 1200);
-
- recorder.save();
- recorder.restore();
- REPORTER_ASSERT(r, pattern.match(&record, 0));
+ int index = 0;
recorder.save();
recorder.clipRect(SkRect::MakeWH(300, 200));
recorder.restore();
- REPORTER_ASSERT(r, pattern.match(&record, 2));
+ REPORTER_ASSERT(r, pattern.match(&record, index));
+ index += 3;
recorder.save();
recorder.clipRect(SkRect::MakeWH(300, 200));
recorder.clipRect(SkRect::MakeWH(100, 100));
recorder.restore();
- 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);
+ REPORTER_ASSERT(r, pattern.match(&record, index));
}
DEF_TEST(RecordPattern_Complex, r) {
@@ -136,54 +99,39 @@ DEF_TEST(RecordPattern_Complex, r) {
SkRecord record;
SkRecorder recorder(&record, 1920, 1200);
+ unsigned start, begin, end;
- 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);
-
+ start = record.count();
recorder.save();
recorder.clipRect(SkRect::MakeWH(300, 200));
recorder.restore();
- REPORTER_ASSERT(r, pattern.match(&record, 6) == 9);
+ 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());
+ 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, 9));
+ REPORTER_ASSERT(r, !pattern.match(&record, start));
+ end = start;
+ REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
+ 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, 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 == 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.match(&record, start) == record.count());
+ end = start;
REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
- REPORTER_ASSERT(r, begin == 13);
- REPORTER_ASSERT(r, end == 19);
+ REPORTER_ASSERT(r, begin == start);
+ REPORTER_ASSERT(r, end == record.count());
REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
}