Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6858671 authored by Tyler Freeman's avatar Tyler Freeman
Browse files

fix(non linear font scaling): fix tests polluting the cache

The allFeasibleScalesAndConversionsDoNotCrash() test puts like every
possible value into the cache, which causes
missingLookupTable_cachesInterpolated() to find a value where it's not
expecting one.

Thus we restore the original default values at the end of every test.

Also fix the test tolerance to be larger.

Fix: 316968558
Fix: 317159831
Test: atest FontScaleConverterFactoryTest
Flag: N/A

Change-Id: I2117a22fdf985af69a02a91ecf490d98c3c865c6
parent c436c976
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -20,12 +20,15 @@ import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresFlagsEnabled
import android.platform.test.flag.junit.CheckFlagsRule
import android.platform.test.flag.junit.DeviceFlagsValueProvider
import android.util.SparseArray
import androidx.core.util.forEach
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.filters.SmallTest
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
import org.junit.After
import org.junit.Before
import org.junit.Rule
import kotlin.math.ceil
import kotlin.math.floor
@@ -45,6 +48,19 @@ class FontScaleConverterFactoryTest {
    @get:Rule
    val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule()

    private lateinit var defaultLookupTables: SparseArray<FontScaleConverter>

    @Before
    fun setup() {
        defaultLookupTables = FontScaleConverterFactory.sLookupTables.clone()
    }

    @After
    fun teardown() {
        // Restore the default tables (since some tests will have added extras to the cache)
        FontScaleConverterFactory.sLookupTables = defaultLookupTables
    }

    @Test
    fun scale200IsTwiceAtSmallSizes() {
        val table = FontScaleConverterFactory.forScale(2F)!!
@@ -245,7 +261,7 @@ class FontScaleConverterFactoryTest {
    }

    companion object {
        private const val CONVERSION_TOLERANCE = 0.05f
        private const val CONVERSION_TOLERANCE = 0.18f
    }
}