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 top and bottom coordinates of [other] are smaller than those of region. 75 * 76 * Also checks that the left and right positions, as well as area, don't change 77 * 78 * @throws AssertionError 79 */ 80 fun isHigher(other: Rect): IRegionSubject 81 82 /** 83 * Asserts that the top and bottom coordinates of [other] are smaller than those of region. 84 * 85 * Also checks that the left and right positions, as well as area, don't change 86 * 87 * @throws AssertionError 88 */ 89 fun isHigher(other: Region): IRegionSubject 90 91 /** 92 * Asserts that the top and bottom coordinates of [other] are greater than those of region. 93 * 94 * Also checks that the left and right positions, as well as area, don't change 95 * 96 * @throws AssertionError 97 */ 98 fun isLower(other: Rect): IRegionSubject 99 100 /** 101 * Asserts that the top and bottom coordinates of [other] are greater than those of region. 102 * 103 * Also checks that the left and right positions, as well as area, don't change 104 * 105 * @throws AssertionError 106 */ 107 fun isLower(other: Region): IRegionSubject 108 109 /** 110 * Asserts that region covers at most [other], that is, its area doesn't cover any point outside 111 * of [other]. 112 * 113 * @param other Expected covered area 114 * @throws AssertionError 115 */ 116 fun coversAtMost(other: Region): IRegionSubject 117 118 /** 119 * Asserts that region covers at most [other], that is, its area doesn't cover any point outside 120 * of [other]. 121 * 122 * @param other Expected covered area 123 * @throws AssertionError 124 */ 125 fun coversAtMost(other: Rect): IRegionSubject 126 127 /** 128 * Asserts that region is not bigger than [other], even if the regions don't overlap. 129 * 130 * @param other Area to compare to 131 * @throws AssertionError 132 */ 133 fun notBiggerThan(other: Region): IRegionSubject 134 135 /** 136 * Asserts that region is positioned to the right and bottom from [other], but the regions can 137 * overlap and region can be smaller than [other] 138 * 139 * @param other Area to compare to 140 * @param threshold Offset threshold by which the position might be off 141 * @throws AssertionError 142 */ 143 fun isToTheRightBottom(other: Region, threshold: Int): IRegionSubject 144 145 /** 146 * Asserts that [other] contains the center of the region. 147 * 148 * @param other Expected area that the center should be in 149 * @throws AssertionError 150 */ 151 fun regionsCenterPointInside(other: Rect): IRegionSubject 152 153 /** 154 * Asserts that region covers at least [other], that is, its area covers each point in the 155 * region 156 * 157 * @param other Expected covered area 158 * @throws AssertionError 159 */ 160 fun coversAtLeast(other: Region): IRegionSubject 161 162 /** 163 * Asserts that region covers at least [other], that is, its area covers each point in the 164 * region 165 * 166 * @param other Expected covered area 167 * @throws AssertionError 168 */ 169 fun coversAtLeast(other: Rect): IRegionSubject 170 171 /** 172 * Asserts that region covers at exactly [other] 173 * 174 * @param other Expected covered area 175 * @throws AssertionError 176 */ 177 fun coversExactly(other: Region): IRegionSubject 178 179 /** 180 * Asserts that region covers at exactly [other] 181 * 182 * @param other Expected covered area 183 * @throws AssertionError 184 */ 185 fun coversExactly(other: Rect): IRegionSubject 186 187 /** 188 * Asserts that region and [other] overlap 189 * 190 * @param other Other area 191 * @throws AssertionError 192 */ 193 fun overlaps(other: Region): IRegionSubject 194 195 /** 196 * Asserts that region and [other] overlap 197 * 198 * @param other Other area 199 * @throws AssertionError 200 */ 201 fun overlaps(other: Rect): IRegionSubject 202 203 /** 204 * Asserts that region and [other] don't overlap 205 * 206 * @param other Other area 207 * @throws AssertionError 208 */ 209 fun notOverlaps(other: Region): IRegionSubject 210 211 /** 212 * Asserts that region and [other] don't overlap 213 * 214 * @param other Other area 215 * @throws AssertionError 216 */ 217 fun notOverlaps(other: Rect): IRegionSubject 218 219 /** 220 * Asserts that region and [other] have same aspect ratio, margin of error up to 0.1. 221 * 222 * @param other Other region 223 * @throws AssertionError 224 */ 225 fun isSameAspectRatio(other: Region, threshold: Double): IRegionSubject 226 227 /** 228 * Asserts that region has the same top coordinates as [displayRect] 229 * 230 * @param displayRect Display area 231 * @throws AssertionError 232 */ 233 fun hasSameTopPosition(displayRect: Rect): IRegionSubject 234 235 /** 236 * Asserts that region has the same bottom coordinates as [displayRect] 237 * 238 * @param displayRect Display area 239 * @throws AssertionError 240 */ 241 fun hasSameBottomPosition(displayRect: Rect): IRegionSubject 242 243 /** 244 * Asserts that region has the same right coordinates as [displayRect] 245 * 246 * @param displayRect Display area 247 * @throws AssertionError 248 */ 249 fun hasSameRightPosition(displayRect: Rect): IRegionSubject 250 251 /** 252 * Asserts that region has the same left coordinates as [displayRect] 253 * 254 * @param displayRect Display area 255 * @throws AssertionError 256 */ 257 fun hasSameLeftPosition(displayRect: Rect): IRegionSubject 258 } 259