summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ahaan Ugale <augale@google.com> 2023-04-11 03:48:42 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-04-11 03:48:42 +0000
commit91995a1d1ff76b065ee90f781dadcfa1f8854afc (patch)
treeff671cfbef4206c8bc97f5dc78bf83fe723fd8a9
parent3d500d4c58cae58d565fab0bb92d49c90906b1a1 (diff)
parent74517ae01f714fbb6d176e2f150a71a4addabc08 (diff)
Merge "PC: Add KotlinUtilsTest, with convertToBitmap tests" into udc-dev am: 74517ae01f
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Permission/+/22538565 Change-Id: Iac9f048cda619480ec66c75694b848283a91dac8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--PermissionController/tests/inprocess/src/com/android/permissioncontroller/permission/util/KotlinUtilsTest.kt63
1 files changed, 63 insertions, 0 deletions
diff --git a/PermissionController/tests/inprocess/src/com/android/permissioncontroller/permission/util/KotlinUtilsTest.kt b/PermissionController/tests/inprocess/src/com/android/permissioncontroller/permission/util/KotlinUtilsTest.kt
new file mode 100644
index 000000000..435f89903
--- /dev/null
+++ b/PermissionController/tests/inprocess/src/com/android/permissioncontroller/permission/util/KotlinUtilsTest.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.permissioncontroller.permission.util
+
+import android.graphics.Bitmap
+import android.graphics.Canvas
+import android.graphics.ColorFilter
+import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.Drawable
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.permissioncontroller.permission.utils.KotlinUtils
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertFailsWith
+
+/**
+ * Unit tests for [KotlinUtils].
+ */
+@RunWith(AndroidJUnit4::class)
+class KotlinUtilsTest {
+ private val targetContext = InstrumentationRegistry.getInstrumentation().targetContext
+
+ @Test
+ fun convertToBitmap_argb888BitmapDrawable_returnsSameBitmap() {
+ val bitmap = Bitmap.createBitmap(/* width= */ 5, /* height= */ 10, Bitmap.Config.ARGB_8888)
+ val drawable = BitmapDrawable(targetContext.resources, bitmap)
+
+ assertThat(KotlinUtils.convertToBitmap(drawable).sameAs(bitmap)).isTrue()
+ }
+
+ @Test
+ fun convertToBitmap_noIntrinsicSize_throws() {
+ val drawable = FakeDrawable(intrinsicSize = 0)
+ assertFailsWith<IllegalArgumentException> { KotlinUtils.convertToBitmap(drawable) }
+ }
+
+ class FakeDrawable(private val intrinsicSize: Int) : Drawable() {
+ override fun getIntrinsicWidth() = intrinsicSize
+ override fun getIntrinsicHeight() = intrinsicSize
+
+ override fun draw(canvas: Canvas) = Unit // no-op
+ override fun getOpacity() = throw UnsupportedOperationException()
+ override fun setAlpha(alpha: Int) = throw UnsupportedOperationException()
+ override fun setColorFilter(colorFilter: ColorFilter?) =
+ throw UnsupportedOperationException()
+ }
+} \ No newline at end of file