1 package com.airbnb.lottie.snapshots.tests 2 3 import android.graphics.Canvas 4 import android.view.View 5 import android.view.ViewGroup 6 import android.widget.FrameLayout 7 import android.widget.ImageView 8 import com.airbnb.lottie.snapshots.R 9 import com.airbnb.lottie.snapshots.SnapshotTestCase 10 import com.airbnb.lottie.snapshots.SnapshotTestCaseContext 11 import com.airbnb.lottie.snapshots.utils.SuspendingSemaphore 12 13 class FailureTestCase : SnapshotTestCase { runnull14 override suspend fun SnapshotTestCaseContext.run() { 15 val animationView = animationViewPool.acquire() 16 val semaphore = SuspendingSemaphore(0) 17 animationView.setFailureListener { semaphore.release() } 18 animationView.setFallbackResource(R.drawable.ic_close) 19 animationView.setAnimationFromJson("Not Valid Json", null) 20 semaphore.acquire() 21 animationView.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) 22 animationView.scaleType = ImageView.ScaleType.FIT_CENTER 23 val widthSpec = View.MeasureSpec.makeMeasureSpec( 24 context.resources.displayMetrics 25 .widthPixels, 26 View.MeasureSpec.EXACTLY 27 ) 28 val heightSpec = View.MeasureSpec.makeMeasureSpec( 29 context.resources.displayMetrics 30 .heightPixels, View.MeasureSpec.EXACTLY 31 ) 32 val animationViewContainer = animationView.parent as ViewGroup 33 animationViewContainer.measure(widthSpec, heightSpec) 34 animationViewContainer.layout(0, 0, animationViewContainer.measuredWidth, animationViewContainer.measuredHeight) 35 val bitmap = bitmapPool.acquire(animationView.width, animationView.height) 36 val canvas = Canvas(bitmap) 37 animationView.draw(canvas) 38 animationViewPool.release(animationView) 39 val snapshotName = "Failure" 40 val snapshotVariant = "Default" 41 snapshotter.record(bitmap, snapshotName, snapshotVariant) 42 bitmapPool.release(bitmap) 43 } 44 }