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

Commit 9369d873 authored by Ang Li's avatar Ang Li Committed by Android (Google) Code Review
Browse files

Merge "Add unit tests for TurbulenceNoiseShader setters" into main

parents 2db2b68c 70132b8e
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.systemui.surfaceeffects.turbulencenoise

import android.graphics.Color
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -22,6 +23,7 @@ import com.android.systemui.surfaceeffects.turbulencenoise.TurbulenceNoiseShader
import com.android.systemui.surfaceeffects.turbulencenoise.TurbulenceNoiseShader.Companion.Type.SIMPLEX_NOISE_FRACTAL
import com.android.systemui.surfaceeffects.turbulencenoise.TurbulenceNoiseShader.Companion.Type.SIMPLEX_NOISE_SIMPLE
import com.android.systemui.surfaceeffects.turbulencenoise.TurbulenceNoiseShader.Companion.Type.SIMPLEX_NOISE_SPARKLE
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@@ -48,4 +50,58 @@ class TurbulenceNoiseShaderTest : SysuiTestCase() {
    fun compilesSparkleNoise() {
        TurbulenceNoiseShader(baseType = SIMPLEX_NOISE_SPARKLE)
    }

    @Test
    fun simplexSimpleShader_settersDoNotCrash() {
        // Verifies that setting uniforms on the SIMPLEX_NOISE_SIMPLE shader does not crash.
        // This is important as the shader code was modified to use the in_opacity uniform.
        val shader = TurbulenceNoiseShader(baseType = SIMPLEX_NOISE_SIMPLE)

        // Set opacity and other uniforms to ensure the shader's public API is stable.
        shader.setOpacity(0.5f)
        shader.setColor(Color.RED)
        shader.setScreenColor(Color.BLUE)
        shader.setSize(100f, 200f)
        shader.setNoiseMove(0.1f, 0.2f, 0.3f)
        shader.setBackgroundColor(Color.BLACK)
        shader.setGridCount(2.0f)
        shader.setPixelDensity(1.5f)
        shader.setLumaMatteFactors(0.8f, 0.2f)
        shader.setInverseNoiseLuminosity(true)

        // Verify noise offsets are updated correctly as they are the only public state.
        assertThat(shader.noiseOffsetX).isEqualTo(0.1f)
        assertThat(shader.noiseOffsetY).isEqualTo(0.2f)
        assertThat(shader.noiseOffsetZ).isEqualTo(0.3f)
    }

    @Test
    fun applyConfig_setsAllUniforms() {
        // Verifies that the applyConfig convenience method correctly sets all relevant properties
        // and does not crash.
        val shader = TurbulenceNoiseShader(baseType = SIMPLEX_NOISE_SIMPLE)
        val config =
            TurbulenceNoiseAnimationConfig(
                width = 200f,
                height = 300f,
                color = Color.GREEN,
                screenColor = Color.YELLOW,
                pixelDensity = 2.5f,
                gridCount = 2f,
                lumaMatteBlendFactor = 0.5f,
                lumaMatteOverallBrightness = 0.2f,
                shouldInverseNoiseLuminosity = true,
                noiseOffsetX = 1f,
                noiseOffsetY = 2f,
                noiseOffsetZ = 3f
            )

        shader.applyConfig(config)

        // Only noise offsets are publicly readable, so we can verify them.
        // The other setters are verified implicitly by not crashing.
        assertThat(shader.noiseOffsetX).isEqualTo(1f)
        assertThat(shader.noiseOffsetY).isEqualTo(2f)
        assertThat(shader.noiseOffsetZ).isEqualTo(3f)
    }
}