From 173d986a5b62dced29bc33369c4ff812904640cc Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sun, 21 Dec 2025 12:14:53 -0800 Subject: [PATCH] Add a test for the server side texture cache fix (#1194) --- .../glsm/GLSM_TextureInfoCache_UnitTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_TextureInfoCache_UnitTest.java diff --git a/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_TextureInfoCache_UnitTest.java b/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_TextureInfoCache_UnitTest.java new file mode 100644 index 000000000..709854236 --- /dev/null +++ b/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_TextureInfoCache_UnitTest.java @@ -0,0 +1,53 @@ +package com.gtnewhorizons.angelica.glsm; + +import com.gtnewhorizons.angelica.AngelicaExtension; +import com.gtnewhorizons.angelica.glsm.texture.TextureInfo; +import com.gtnewhorizons.angelica.glsm.texture.TextureInfoCache; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; + +import java.lang.reflect.Field; +import java.nio.ByteBuffer; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(AngelicaExtension.class) +public class GLSM_TextureInfoCache_UnitTest { + + /** + * Texture deletion is server-side; cache must be invalidated regardless of client caching state. + */ + @Test + void testCacheRemovedOnDeleteWhenCachingDisabled() throws Exception { + int texId = GL11.glGenTextures(); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); + ByteBuffer pixels = BufferUtils.createByteBuffer(4 * 4 * 4); + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 4, 4, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixels); + + TextureInfo info = TextureInfoCache.INSTANCE.getInfo(texId); + assertNotNull(info); + + // Disable caching (simulate SharedDrawable context) + Field splashCompleteField = GLStateManager.class.getDeclaredField("splashComplete"); + splashCompleteField.setAccessible(true); + boolean original = splashCompleteField.getBoolean(null); + + try { + splashCompleteField.setBoolean(null, false); + GLStateManager.setCachingEnabled(false); + assertFalse(GLStateManager.isCachingEnabled()); + + GLStateManager.glDeleteTextures(texId); + + splashCompleteField.setBoolean(null, true); + + // Cache entry should be gone - we should get a fresh object + assertNotSame(info, TextureInfoCache.INSTANCE.getInfo(texId)); + } finally { + splashCompleteField.setBoolean(null, original); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + } +}