• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.tools.flicker.subject.region
18 
19 import android.graphics.Rect
20 import android.graphics.Region
21 import android.tools.flicker.subject.exceptions.IncorrectRegionException
22 
23 interface IRegionSubject {
24     /**
25      * Asserts that the top and bottom coordinates of [other] are smaller or equal to those of
26      * region.
27      *
28      * Also checks that the left and right positions, as well as area, don't change
29      *
30      * @throws IncorrectRegionException
31      */
isHigherOrEqualnull32     fun isHigherOrEqual(other: Rect): IRegionSubject
33 
34     /**
35      * Asserts that the top and bottom coordinates of [other] are smaller or equal to those of
36      * region.
37      *
38      * Also checks that the left and right positions, as well as area, don't change
39      *
40      * @throws IncorrectRegionException
41      */
42     fun isHigherOrEqual(other: Region): IRegionSubject
43 
44     /**
45      * Asserts that the top and bottom coordinates of [other] are greater or equal to those of
46      * region.
47      *
48      * Also checks that the left and right positions, as well as area, don't change
49      *
50      * @throws IncorrectRegionException
51      */
52     fun isLowerOrEqual(other: Rect): IRegionSubject
53 
54     /**
55      * Asserts that the top and bottom coordinates of [other] are greater or equal to those of
56      * region.
57      *
58      * Also checks that the left and right positions, as well as area, don't change
59      *
60      * @throws AssertionError
61      */
62     fun isLowerOrEqual(other: Region): IRegionSubject
63 
64     /**
65      * Asserts that the left and right coordinates of [other] are lower or equal to those of region.
66      *
67      * Also checks that the top and bottom positions, as well as area, don't change
68      *
69      * @throws AssertionError
70      */
71     fun isToTheRight(other: Region): IRegionSubject
72 
73     /**
74      * Asserts that the left coordinates of [other] are lower or equal to those of region.
75      *
76      * @throws AssertionError
77      */
78     fun isLeftEdgeToTheRight(other: Region): IRegionSubject
79 
80     /**
81      * Asserts that the top and bottom coordinates of [other] are smaller than those of region.
82      *
83      * Also checks that the left and right positions, as well as area, don't change
84      *
85      * @throws AssertionError
86      */
87     fun isHigher(other: Rect): IRegionSubject
88 
89     /**
90      * Asserts that the top and bottom coordinates of [other] are smaller than those of region.
91      *
92      * Also checks that the left and right positions, as well as area, don't change
93      *
94      * @throws AssertionError
95      */
96     fun isHigher(other: Region): IRegionSubject
97 
98     /**
99      * Asserts that the top and bottom coordinates of [other] are greater than those of region.
100      *
101      * Also checks that the left and right positions, as well as area, don't change
102      *
103      * @throws AssertionError
104      */
105     fun isLower(other: Rect): IRegionSubject
106 
107     /**
108      * Asserts that the top and bottom coordinates of [other] are greater than those of region.
109      *
110      * Also checks that the left and right positions, as well as area, don't change
111      *
112      * @throws AssertionError
113      */
114     fun isLower(other: Region): IRegionSubject
115 
116     /**
117      * Asserts that region covers at most [other], that is, its area doesn't cover any point outside
118      * of [other].
119      *
120      * @param other Expected covered area
121      * @throws AssertionError
122      */
123     fun coversAtMost(other: Region): IRegionSubject
124 
125     /**
126      * Asserts that region covers at most [other], that is, its area doesn't cover any point outside
127      * of [other].
128      *
129      * @param other Expected covered area
130      * @throws AssertionError
131      */
132     fun coversAtMost(other: Rect): IRegionSubject
133 
134     /**
135      * Asserts that region is not bigger than [other], even if the regions don't overlap.
136      *
137      * @param other Area to compare to
138      * @throws AssertionError
139      */
140     fun notBiggerThan(other: Region): IRegionSubject
141 
142     /**
143      * Asserts that region is not smaller than [other], even if the regions don't overlap.
144      *
145      * @param other Area to compare to
146      * @throws AssertionError
147      */
148     fun notSmallerThan(other: Region): IRegionSubject
149 
150     /**
151      * Asserts that region is positioned to the right and bottom from [other], but the regions can
152      * overlap and region can be smaller than [other]
153      *
154      * @param other Area to compare to
155      * @param threshold Offset threshold by which the position might be off
156      * @throws AssertionError
157      */
158     fun isToTheRightBottom(other: Region, threshold: Int): IRegionSubject
159 
160     /**
161      * Asserts that [other] contains the center of the region.
162      *
163      * @param other Expected area that the center should be in
164      * @throws AssertionError
165      */
166     fun regionsCenterPointInside(other: Rect): IRegionSubject
167 
168     /**
169      * Asserts that region covers at least [other], that is, its area covers each point in the
170      * region
171      *
172      * @param other Expected covered area
173      * @throws AssertionError
174      */
175     fun coversAtLeast(other: Region): IRegionSubject
176 
177     /**
178      * Asserts that region covers at least [other], that is, its area covers each point in the
179      * region
180      *
181      * @param other Expected covered area
182      * @throws AssertionError
183      */
184     fun coversAtLeast(other: Rect): IRegionSubject
185 
186     /**
187      * Asserts that region covers at exactly [other]
188      *
189      * @param other Expected covered area
190      * @throws AssertionError
191      */
192     fun coversExactly(other: Region): IRegionSubject
193 
194     /**
195      * Asserts that region covers at exactly [other]
196      *
197      * @param other Expected covered area
198      * @throws AssertionError
199      */
200     fun coversExactly(other: Rect): IRegionSubject
201 
202     /**
203      * Asserts that region and [other] overlap
204      *
205      * @param other Other area
206      * @throws AssertionError
207      */
208     fun overlaps(other: Region): IRegionSubject
209 
210     /**
211      * Asserts that region and [other] overlap
212      *
213      * @param other Other area
214      * @throws AssertionError
215      */
216     fun overlaps(other: Rect): IRegionSubject
217 
218     /**
219      * Asserts that region and [other] don't overlap
220      *
221      * @param other Other area
222      * @throws AssertionError
223      */
224     fun notOverlaps(other: Region): IRegionSubject
225 
226     /**
227      * Asserts that region and [other] don't overlap
228      *
229      * @param other Other area
230      * @throws AssertionError
231      */
232     fun notOverlaps(other: Rect): IRegionSubject
233 
234     /**
235      * Asserts that region and [other] have same aspect ratio, margin of error up to 0.1.
236      *
237      * @param other Other region
238      * @throws AssertionError
239      */
240     fun isSameAspectRatio(other: Region, threshold: Double): IRegionSubject
241 
242     /**
243      * Asserts that region has the same top coordinates as [displayRect]
244      *
245      * @param displayRect Display area
246      * @throws AssertionError
247      */
248     fun hasSameTopPosition(displayRect: Rect): IRegionSubject
249 
250     /**
251      * Asserts that region has the same bottom coordinates as [displayRect]
252      *
253      * @param displayRect Display area
254      * @throws AssertionError
255      */
256     fun hasSameBottomPosition(displayRect: Rect): IRegionSubject
257 
258     /**
259      * Asserts that region has the same right coordinates as [displayRect]
260      *
261      * @param displayRect Display area
262      * @throws AssertionError
263      */
264     fun hasSameRightPosition(displayRect: Rect): IRegionSubject
265 
266     /**
267      * Asserts that region has the same left coordinates as [displayRect]
268      *
269      * @param displayRect Display area
270      * @throws AssertionError
271      */
272     fun hasSameLeftPosition(displayRect: Rect): IRegionSubject
273 }
274