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

Commit 70132b8e authored by AI test gen's avatar AI test gen
Browse files

Add unit tests for TurbulenceNoiseShader setters


Please help fill out the survey for feedback: https://docs.google.com/forms/d/e/1FAIpQLSeKFKpHImCAqZIa_OR801cw72HQUreM2oGM25C3mKKT2tBFnw/viewform?usp=pp_url&entry.1586624956=ag/35612456

Please feel free to make changes to the generated tests based on your domain knowledge. If the test doesn't look good, please -1 and provide feedback to help us improve the system. For more context on the project please see go/ai-testgen

Original Change: ag/35462529 (Note tests are based on the original CL but may add coverage beyond the specific changes to improve overall code health)

Test: ATP tests passed http://go/forrest-run/L11000030017818566
Bug: 431235865
Flag: TEST_ONLY



Change-Id: I293a031eaafe9622fc394ba834d419b56a041836
parent 97fef960
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)
    }
}