Skip to content

Commit

Permalink
Simplify the internal FakeImage implementation. (#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite authored Nov 19, 2024
1 parent 764f1b3 commit bc5452a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package coil3.memory
import coil3.Image
import coil3.memory.MemoryCache.Key
import coil3.memory.MemoryCache.Value
import coil3.test.utils.DEFAULT_FAKE_IMAGE_SIZE
import coil3.test.utils.FakeImage
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -15,7 +14,7 @@ class StrongMemoryCacheTest {
@Test
fun canRetrieveCachedValue() {
val weakCache = FakeWeakMemoryCache()
val strongCache = RealStrongMemoryCache(2 * DEFAULT_FAKE_IMAGE_SIZE, weakCache)
val strongCache = RealStrongMemoryCache(2 * FakeImage().size, weakCache)

val image = FakeImage()
strongCache.set(Key("1"), image, emptyMap(), image.size)
Expand All @@ -26,7 +25,7 @@ class StrongMemoryCacheTest {
@Test
fun leastRecentlyUsedValueIsEvicted() {
val weakCache = FakeWeakMemoryCache()
val strongCache = RealStrongMemoryCache(2 * DEFAULT_FAKE_IMAGE_SIZE, weakCache)
val strongCache = RealStrongMemoryCache(2 * FakeImage().size, weakCache)

val first = FakeImage()
strongCache.set(Key("1"), first, emptyMap(), first.size)
Expand All @@ -44,7 +43,7 @@ class StrongMemoryCacheTest {
@Test
fun valueCanBeRemoved() {
val weakCache = FakeWeakMemoryCache()
val strongCache = RealStrongMemoryCache(2 * DEFAULT_FAKE_IMAGE_SIZE, weakCache)
val strongCache = RealStrongMemoryCache(2 * FakeImage().size, weakCache)

val image = FakeImage()
strongCache.set(Key("1"), image, emptyMap(), image.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import coil3.request.ErrorResult
import coil3.request.ImageRequest
import coil3.request.SuccessResult
import coil3.test.FakeImageLoaderEngine.OptionalInterceptor
import coil3.test.utils.FakeImage
import coil3.test.utils.RobolectricTest
import coil3.test.utils.context
import kotlin.test.Test
Expand Down
1 change: 1 addition & 0 deletions internal/test-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("com.android.library")
id("kotlin-multiplatform")
id("org.jetbrains.kotlinx.atomicfu")
id("dev.drewhamilton.poko")
}

addAllMultiplatformTargets(libs.versions.skiko)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package coil3.test.utils

import coil3.Canvas
import coil3.Image
import coil3.annotation.Poko

expect class FakeImage(
width: Int = 100,
height: Int = 100,
size: Long = 4L * width * height,
shareable: Boolean = true,
/** An [Image] that renders nothing. */
@Poko
class FakeImage(
override val width: Int = 100,
override val height: Int = 100,
override val size: Long = 4L * width * height,
override val shareable: Boolean = true,
) : Image {
override val size: Long
override val width: Int
override val height: Int
override val shareable: Boolean
override fun draw(canvas: Canvas)
override fun draw(canvas: Canvas) {
// Draw nothing.
}
}

const val DEFAULT_FAKE_IMAGE_SIZE = 4L * 100 * 100

This file was deleted.

0 comments on commit bc5452a

Please sign in to comment.