Flutter Engine
The Flutter Engine
Typedefs | Functions
RecordPatternTest.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "src/core/SkRecord.h"
#include "src/core/SkRecordPattern.h"
#include "src/core/SkRecorder.h"
#include "src/core/SkRecords.h"
#include "tests/Test.h"

Go to the source code of this file.

Typedefs

typedef Pattern< Is< Save >, Is< ClipRect >, Is< Restore > > SaveClipRectRestore
 

Functions

 DEF_TEST (RecordPattern_Simple, r)
 
 DEF_TEST (RecordPattern_StartingIndex, r)
 
 DEF_TEST (RecordPattern_DontMatchSubsequences, r)
 
 DEF_TEST (RecordPattern_Greedy, r)
 
 DEF_TEST (RecordPattern_Complex, r)
 
 DEF_TEST (RecordPattern_SaveLayerIsNotADraw, r)
 

Typedef Documentation

◆ SaveClipRectRestore

typedef Pattern<Is<Save>, Is<ClipRect>, Is<Restore> > SaveClipRectRestore

Definition at line 21 of file RecordPatternTest.cpp.

Function Documentation

◆ DEF_TEST() [1/6]

DEF_TEST ( RecordPattern_Complex  ,
 
)

Definition at line 102 of file RecordPatternTest.cpp.

102 {
106 IsDraw>>>,
107 Is<Restore>> pattern;
108
109 SkRecord record;
110 SkRecorder recorder(&record, 1920, 1200);
111 int start, begin, end;
112
113 start = record.count();
114 recorder.save();
115 recorder.clipRect(SkRect::MakeWH(300, 200));
116 recorder.restore();
117 REPORTER_ASSERT(r, pattern.match(&record, 0) == record.count());
118 end = start;
119 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
121 REPORTER_ASSERT(r, end == record.count());
122
123 start = record.count();
124 recorder.save();
125 recorder.clipRect(SkRect::MakeWH(300, 200));
126 recorder.drawRect(SkRect::MakeWH(100, 3000), SkPaint());
127 recorder.restore();
128 REPORTER_ASSERT(r, !pattern.match(&record, start));
129 end = start;
130 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
131
132 start = record.count();
133 recorder.save();
134 recorder.clipRect(SkRect::MakeWH(300, 200));
135 recorder.clipRect(SkRect::MakeWH(100, 400));
136 recorder.restore();
137 REPORTER_ASSERT(r, pattern.match(&record, start) == record.count());
138 end = start;
139 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end));
141 REPORTER_ASSERT(r, end == record.count());
142
143 REPORTER_ASSERT(r, !pattern.search(&record, &begin, &end));
144}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
int count() const
Definition: SkRecord.h:38
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
glong glong end
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ DEF_TEST() [2/6]

DEF_TEST ( RecordPattern_DontMatchSubsequences  ,
 
)

Definition at line 68 of file RecordPatternTest.cpp.

68 {
69 SaveClipRectRestore pattern;
70
71 SkRecord record;
72 SkRecorder recorder(&record, 1920, 1200);
73
74 recorder.save();
75 recorder.clipRect(SkRect::MakeWH(300, 200));
76 recorder.drawRect(SkRect::MakeWH(600, 300), SkPaint());
77 recorder.restore();
78
79 REPORTER_ASSERT(r, !pattern.match(&record, 0));
80}

◆ DEF_TEST() [3/6]

DEF_TEST ( RecordPattern_Greedy  ,
 
)

Definition at line 82 of file RecordPatternTest.cpp.

82 {
84
85 SkRecord record;
86 SkRecorder recorder(&record, 1920, 1200);
87 int index = 0;
88
89 recorder.save();
90 recorder.clipRect(SkRect::MakeWH(300, 200));
91 recorder.restore();
92 REPORTER_ASSERT(r, pattern.match(&record, index));
93 index += 3;
94
95 recorder.save();
96 recorder.clipRect(SkRect::MakeWH(300, 200));
97 recorder.clipRect(SkRect::MakeWH(100, 100));
98 recorder.restore();
99 REPORTER_ASSERT(r, pattern.match(&record, index));
100}

◆ DEF_TEST() [4/6]

DEF_TEST ( RecordPattern_SaveLayerIsNotADraw  ,
 
)

Definition at line 146 of file RecordPatternTest.cpp.

146 {
147 Pattern<IsDraw> pattern;
148
149 SkRecord record;
150 SkRecorder recorder(&record, 1920, 1200);
151 recorder.saveLayer(nullptr, nullptr);
152
153 REPORTER_ASSERT(r, !pattern.match(&record, 0));
154}

◆ DEF_TEST() [5/6]

DEF_TEST ( RecordPattern_Simple  ,
 
)

Definition at line 23 of file RecordPatternTest.cpp.

23 {
24 SaveClipRectRestore pattern;
25
26 SkRecord record;
27 REPORTER_ASSERT(r, !pattern.match(&record, 0));
28
29 SkRecorder recorder(&record, 1920, 1200);
30
31 // Build up a save-clip-restore block. The pattern will match only it's complete.
32 recorder.save();
33 REPORTER_ASSERT(r, !pattern.match(&record, 0));
34
35 recorder.clipRect(SkRect::MakeWH(300, 200));
36 REPORTER_ASSERT(r, !pattern.match(&record, 0));
37
38 recorder.restore();
39 REPORTER_ASSERT(r, pattern.match(&record, 0));
40 REPORTER_ASSERT(r, pattern.first<Save>() != nullptr);
41 REPORTER_ASSERT(r, pattern.second<ClipRect>() != nullptr);
42 REPORTER_ASSERT(r, pattern.third<Restore>() != nullptr);
43}

◆ DEF_TEST() [6/6]

DEF_TEST ( RecordPattern_StartingIndex  ,
 
)

Definition at line 45 of file RecordPatternTest.cpp.

45 {
46 SaveClipRectRestore pattern;
47
48 SkRecord record;
49 SkRecorder recorder(&record, 1920, 1200);
50
51 // There will be two save-clipRect-restore blocks [0,3) and [3,6).
52 for (int i = 0; i < 2; i++) {
53 recorder.save();
54 recorder.clipRect(SkRect::MakeWH(300, 200));
55 recorder.restore();
56 }
57
58 // We should match only at 0 and 3. Going over the length should fail gracefully.
59 for (int i = 0; i < 8; i++) {
60 if (i == 0 || i == 3) {
61 REPORTER_ASSERT(r, pattern.match(&record, i) == i + 3);
62 } else {
63 REPORTER_ASSERT(r, !pattern.match(&record, i));
64 }
65 }
66}