4 #include "SkRecordPattern.h"
5 #include "SkRecorder.h"
8 using namespace SkRecords;
9 typedef Pattern3<Is<Save>,
14 DEF_TEST(RecordPattern_Simple, r) {
15 SaveClipRectRestore pattern;
18 REPORTER_ASSERT(r, !pattern.match(&record, 0));
20 SkRecorder recorder(&record, 1920, 1200);
22 // Build up a save-clip-restore block. The pattern will match only it's complete.
24 REPORTER_ASSERT(r, !pattern.match(&record, 0));
26 recorder.clipRect(SkRect::MakeWH(300, 200));
27 REPORTER_ASSERT(r, !pattern.match(&record, 0));
30 REPORTER_ASSERT(r, pattern.match(&record, 0));
31 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
32 REPORTER_ASSERT(r, pattern.second<ClipRect>() != NULL);
33 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
36 DEF_TEST(RecordPattern_StartingIndex, r) {
37 SaveClipRectRestore pattern;
40 SkRecorder recorder(&record, 1920, 1200);
42 // There will be two save-clipRect-restore blocks [0,3) and [3,6).
43 for (int i = 0; i < 2; i++) {
45 recorder.clipRect(SkRect::MakeWH(300, 200));
49 // We should match only at 0 and 3. Going over the length should fail gracefully.
50 for (unsigned i = 0; i < 8; i++) {
51 if (i == 0 || i == 3) {
52 REPORTER_ASSERT(r, pattern.match(&record, i) == i + 3);
54 REPORTER_ASSERT(r, !pattern.match(&record, i));
59 DEF_TEST(RecordPattern_DontMatchSubsequences, r) {
60 SaveClipRectRestore pattern;
63 SkRecorder recorder(&record, 1920, 1200);
66 recorder.clipRect(SkRect::MakeWH(300, 200));
67 recorder.drawRect(SkRect::MakeWH(600, 300), SkPaint());
70 REPORTER_ASSERT(r, !pattern.match(&record, 0));
73 DEF_TEST(RecordPattern_Star, r) {
74 Pattern3<Is<Save>, Star<Is<ClipRect> >, Is<Restore> > pattern;
77 SkRecorder recorder(&record, 1920, 1200);
81 REPORTER_ASSERT(r, pattern.match(&record, 0));
84 recorder.clipRect(SkRect::MakeWH(300, 200));
86 REPORTER_ASSERT(r, pattern.match(&record, 2));
89 recorder.clipRect(SkRect::MakeWH(300, 200));
90 recorder.clipRect(SkRect::MakeWH(100, 100));
92 REPORTER_ASSERT(r, pattern.match(&record, 5));
95 DEF_TEST(RecordPattern_IsDraw, r) {
96 Pattern3<Is<Save>, IsDraw, Is<Restore> > pattern;
99 SkRecorder recorder(&record, 1920, 1200);
102 recorder.clipRect(SkRect::MakeWH(300, 200));
105 REPORTER_ASSERT(r, !pattern.match(&record, 0));
110 paint.setColor(0xEEAA8822);
111 recorder.drawRect(SkRect::MakeWH(300, 200), paint);
115 paint.setColor(0xFACEFACE);
116 recorder.drawPaint(paint);
119 REPORTER_ASSERT(r, pattern.match(&record, 3));
120 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
121 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xEEAA8822);
122 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
124 REPORTER_ASSERT(r, pattern.match(&record, 6));
125 REPORTER_ASSERT(r, pattern.first<Save>() != NULL);
126 REPORTER_ASSERT(r, pattern.second<SkPaint>()->getColor() == 0xFACEFACE);
127 REPORTER_ASSERT(r, pattern.third<Restore>() != NULL);
130 DEF_TEST(RecordPattern_Complex, r) {
132 Star<Not<Or3<Is<Save>,
135 Is<Restore> > pattern;
138 SkRecorder recorder(&record, 1920, 1200);
142 REPORTER_ASSERT(r, pattern.match(&record, 0) == 2);
148 REPORTER_ASSERT(r, !pattern.match(&record, 2));
149 REPORTER_ASSERT(r, pattern.match(&record, 3) == 5);
152 recorder.clipRect(SkRect::MakeWH(300, 200));
154 REPORTER_ASSERT(r, pattern.match(&record, 6) == 9);
157 recorder.clipRect(SkRect::MakeWH(300, 200));
158 recorder.drawRect(SkRect::MakeWH(100, 3000), SkPaint());
160 REPORTER_ASSERT(r, !pattern.match(&record, 9));
163 recorder.pushCull(SkRect::MakeWH(300, 200));
164 recorder.clipRect(SkRect::MakeWH(300, 200));
165 recorder.clipRect(SkRect::MakeWH(100, 400));
168 REPORTER_ASSERT(r, pattern.match(&record, 13) == 19);
170 // Same as above, but using pattern.search to step through matches.
171 unsigned begin, end = 0;
172 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
173 REPORTER_ASSERT(r, begin == 0);
174 REPORTER_ASSERT(r, end == 2);
176 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
177 REPORTER_ASSERT(r, begin == 3);
178 REPORTER_ASSERT(r, end == 5);
180 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
181 REPORTER_ASSERT(r, begin == 6);
182 REPORTER_ASSERT(r, end == 9);
184 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
185 REPORTER_ASSERT(r, begin == 13);
186 REPORTER_ASSERT(r, end == 19);
188 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
191 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) {
192 Pattern1<IsDraw> pattern;
195 SkRecorder recorder(&record, 1920, 1200);
196 recorder.saveLayer(NULL, NULL);
198 REPORTER_ASSERT(r, !pattern.match(&record, 0));