Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions
EventQueueTest.cpp File Reference
#include "modules/bentleyottmann/include/EventQueue.h"
#include "tests/Test.h"

Go to the source code of this file.

Classes

class  bentleyottmann::EventQueueTestingPeer
 
struct  TestEventHandler
 

Namespaces

namespace  bentleyottmann
 

Enumerations

enum  HasDeletions { kHasDeletions , kHasNoDeletions }
 

Functions

 DEF_TEST (BO_EventQueueOrdering, reporter)
 
 DEF_TEST (BO_EventQueueBasic, reporter)
 
 DEF_TEST (BO_EventQueueHandlerInterface, reporter)
 

Enumeration Type Documentation

◆ HasDeletions

Enumerator
kHasDeletions 
kHasNoDeletions 

Definition at line 130 of file EventQueueTest.cpp.

130 {
131 kHasDeletions, // The handleDeletions call should be called.
132 kHasNoDeletions // The handleDeletions call should not be called.
133};
@ kHasDeletions
@ kHasNoDeletions

Function Documentation

◆ DEF_TEST() [1/3]

DEF_TEST ( BO_EventQueueBasic  ,
reporter   
)

Definition at line 51 of file EventQueueTest.cpp.

51 {
52 {
54 EventQueue eq{std::move(q)};
55 REPORTER_ASSERT(reporter, !eq.hasMoreEvents());
56 }
57 {
59 Point eventPoint = {100, 100};
60 q.insert({eventPoint, Lower{} });
61 EventQueue eq{std::move(q)};
62 {
63 REPORTER_ASSERT(reporter, eq.hasMoreEvents());
65 REPORTER_ASSERT(reporter, e.where == eventPoint);
66 REPORTER_ASSERT(reporter, !eq.hasMoreEvents());
67 }
68 }
69 { // Check that Lower events are de-duplicated.
71 Point eventPoint = {100, 100};
72 q.insert({eventPoint, Lower{}});
73 q.insert({eventPoint, Lower{}});
74 EventQueue eq{std::move(q)};
75 {
76 // There should be only one lower because of queue de-duplication
77 REPORTER_ASSERT(reporter, eq.hasMoreEvents());
79 REPORTER_ASSERT(reporter, p == eventPoint);
80 REPORTER_ASSERT(reporter, !eq.hasMoreEvents());
81 }
82 }
83 { // Check that Lower distinct Lower events are distinct.
85 Point eventPoint1 = {100, 100};
86 Point eventPoint2 = {100, 101};
87
88 q.insert({eventPoint1, Lower{}});
89 q.insert({eventPoint2, Lower{}});
90 EventQueue eq{std::move(q)};
91 {
92 // There should be only one lower because of queue de-duplication
93 REPORTER_ASSERT(reporter, eq.hasMoreEvents());
95 REPORTER_ASSERT(reporter, p == eventPoint1);
96 }
97 {
98 // There should be only one lower because of queue de-duplication
99 REPORTER_ASSERT(reporter, eq.hasMoreEvents());
101 REPORTER_ASSERT(reporter, p == eventPoint2);
102 REPORTER_ASSERT(reporter, !eq.hasMoreEvents());
103 }
104 }
105 { // Check that non-Lower events are separate.
107 Segment s0 {{0, 0}, {100, 100}};
108 Segment s1 {{0, 0}, {-100, 100}};
109 q.insert({Point{0, 0}, Upper{s0}});
110 q.insert({Point{0, 0}, Upper{s1}});
111 EventQueue eq{std::move(q)};
112 {
113 REPORTER_ASSERT(reporter, eq.hasMoreEvents());
115 Point upperPt = Point{0, 0};
116 REPORTER_ASSERT(reporter, e.where == upperPt);
117 REPORTER_ASSERT(reporter, e.type.index() == 2);
118 Upper upper = std::get<Upper>(e.type);
119 REPORTER_ASSERT(reporter, !(upper < Upper{s1}) && !(Upper{s1} < upper));
121 REPORTER_ASSERT(reporter, e2.where == upperPt);
122 REPORTER_ASSERT(reporter, e2.type.index() == 2);
123 Upper upper2 = std::get<Upper>(e2.type);
124 REPORTER_ASSERT(reporter, !(upper2 < Upper{s0}) && !(Upper{s0} < upper2));
125 REPORTER_ASSERT(reporter, !eq.hasMoreEvents());
126 }
127 }
128}
reporter
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
Definition M44Test.cpp:18
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static Event NextEvent(EventQueue *eq)
std::set< Event > Queue
Definition EventQueue.h:63

◆ DEF_TEST() [2/3]

DEF_TEST ( BO_EventQueueHandlerInterface  ,
reporter   
)

Definition at line 191 of file EventQueueTest.cpp.

191 {
192 { // Check that a Lower event is added while processing the Upper event.
194 static constexpr Point eventPoint = {100, 100};
195 static constexpr Point endPoint = {200, 200};
196 static constexpr Segment s = {eventPoint, endPoint};
197 q.insert(Event{eventPoint, Upper{s}});
198 EventQueue eq{std::move(q)};
199
200 REPORTER_ASSERT(reporter, eq.hasMoreEvents());
201
202
203 TestEventHandler eh1{reporter, eventPoint, {}, {s}, {}, kHasNoDeletions};
204 eq.handleNextEventPoint(&eh1);
205
206 TestEventHandler eh2{reporter, endPoint, {}, {}, {}};
207 eq.handleNextEventPoint(&eh2);
208
209 REPORTER_ASSERT(reporter, !eq.hasMoreEvents());
210 }
211
212 { // Check an entire crossing event.
214 static constexpr Point b0 = {100, 100};
215 static constexpr Point e0 = {200, 200};
216 static constexpr Segment s0 = {b0, e0};
217 static constexpr Point b1 = {200, 100};
218 static constexpr Point e1 = {100, 200};
219 static constexpr Segment s1 = {b1, e1};
220 static constexpr Point crossingPoint = {150, 150};
221
222 // Load crossing segments into the queue
223 q.insert(Event{b0, Upper{s0}});
224 q.insert(Event{b1, Upper{s1}});
225 EventQueue eq{std::move(q)};
226
227 REPORTER_ASSERT(reporter, eq.hasMoreEvents());
228
229 TestEventHandler eh1{reporter, b0, {}, {s0}, {}, kHasNoDeletions};
230 eq.handleNextEventPoint(&eh1);
231
232 TestEventHandler eh2{reporter, b1, {}, {s1}, {{s0, s1, crossingPoint}}, kHasNoDeletions};
233 eq.handleNextEventPoint(&eh2);
234
235 TestEventHandler eh3{reporter, crossingPoint, {s0, s1}, {s0, s1}, {}};
236 eq.handleNextEventPoint(&eh3);
237
238 TestEventHandler eh4{reporter, e1, {}, {}, {}};
239 eq.handleNextEventPoint(&eh4);
240
241 TestEventHandler eh5{reporter, e0, {}, {}, {}};
242 eq.handleNextEventPoint(&eh5);
243
244 REPORTER_ASSERT(reporter, !eq.hasMoreEvents());
245 }
246}
float e1
float e0
struct MyStruct s

◆ DEF_TEST() [3/3]

DEF_TEST ( BO_EventQueueOrdering  ,
reporter   
)

Definition at line 28 of file EventQueueTest.cpp.

28 {
29 { // Check that event types are ordered correctly.
31
32 // Insert the events in reverse order.
33 Point eventPoint = {100, 100};
34 Segment s = {{100, 100}, {200, 200}};
35 q.insert(Event{eventPoint, Upper{s}});
36 Segment s0 = {{50, 50}, {150, 150}},
37 s1 = {{150, 50}, {50, 150}};
38 q.insert(Event{eventPoint, Cross{s0, s1}});
39 q.insert(Event{eventPoint, Lower{}});
40
41 // Make sure that the events are in the right order.
42 auto cursor = q.begin();
43 REPORTER_ASSERT(reporter, std::holds_alternative<Lower>(cursor->type));
44 ++cursor;
45 REPORTER_ASSERT(reporter, std::holds_alternative<Cross>(cursor->type));
46 ++cursor;
47 REPORTER_ASSERT(reporter, std::holds_alternative<Upper>(cursor->type));
48 }
49}