1 /* 2 * Copyright (C) 2024 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 package platform.test.screenshot 17 18 import android.graphics.Bitmap 19 import android.graphics.Rect 20 import platform.test.screenshot.matchers.BitmapMatcher 21 22 /** 23 * Asserts that a supplied bitmap matches a previously generated golden image. 24 * 25 * Assertion results are exported as a test artifact, to be uploaded to Scuba by the test harness. 26 * Throws an exception whenever the bitmap does not match the golden. 27 */ 28 interface BitmapDiffer { 29 /** 30 * Asserts the given bitmap against the golden identified by the given name. 31 * 32 * Note: The golden identifier should be unique per your test module (unless you want multiple 33 * tests to match the same golden). The name must not contain extension. You should also avoid 34 * adding strings like "golden", "image" and instead describe what is the golder referring to. 35 * 36 * @param actual The bitmap captured during the test. 37 * @param goldenIdentifier Name of the golden. Allowed characters: 'A-Za-z0-9_-' 38 * @param matcher The algorithm to be used to perform the matching. 39 * @param regions An optional array of interesting regions for partial screenshot diff. 40 * @throws IllegalArgumentException If the golden identifier contains forbidden characters or is 41 * empty. 42 * @see MSSIMMatcher 43 * @see PixelPerfectMatcher 44 * @see Bitmap.assertAgainstGolden 45 */ assertBitmapAgainstGoldennull46 fun assertBitmapAgainstGolden( 47 actual: Bitmap, 48 goldenIdentifier: String, 49 matcher: BitmapMatcher, 50 regions: List<Rect> = emptyList(), 51 ) 52 } 53