|
| 1 | +package io.flutter.embedding.engine.renderer; |
| 2 | + |
| 3 | +import static junit.framework.TestCase.*; |
| 4 | +import static org.mockito.Mockito.*; |
| 5 | + |
| 6 | +import android.graphics.SurfaceTexture; |
| 7 | +import androidx.test.ext.junit.runners.AndroidJUnit4; |
| 8 | +import org.junit.Test; |
| 9 | +import org.junit.runner.RunWith; |
| 10 | + |
| 11 | +@RunWith(AndroidJUnit4.class) |
| 12 | +public class SurfaceTextureWrapperTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + public void attachToGLContext() { |
| 16 | + final SurfaceTexture tx = mock(SurfaceTexture.class); |
| 17 | + final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx); |
| 18 | + |
| 19 | + wrapper.attachToGLContext(0); |
| 20 | + verify(tx, times(1)).attachToGLContext(0); |
| 21 | + verifyNoMoreInteractions(tx); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void attachToGLContext_detachesFromCurrentContext() { |
| 26 | + final SurfaceTexture tx = mock(SurfaceTexture.class); |
| 27 | + final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx); |
| 28 | + |
| 29 | + wrapper.attachToGLContext(0); |
| 30 | + |
| 31 | + reset(tx); |
| 32 | + |
| 33 | + wrapper.attachToGLContext(0); |
| 34 | + verify(tx, times(1)).detachFromGLContext(); |
| 35 | + verify(tx, times(1)).attachToGLContext(0); |
| 36 | + verifyNoMoreInteractions(tx); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void attachToGLContext_doesNotDetacheFromCurrentContext() { |
| 41 | + final SurfaceTexture tx = mock(SurfaceTexture.class); |
| 42 | + final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx); |
| 43 | + |
| 44 | + wrapper.attachToGLContext(0); |
| 45 | + |
| 46 | + wrapper.detachFromGLContext(); |
| 47 | + |
| 48 | + reset(tx); |
| 49 | + |
| 50 | + wrapper.attachToGLContext(0); |
| 51 | + verify(tx, times(1)).attachToGLContext(0); |
| 52 | + verifyNoMoreInteractions(tx); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void detachFromGLContext() { |
| 57 | + final SurfaceTexture tx = mock(SurfaceTexture.class); |
| 58 | + final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx); |
| 59 | + |
| 60 | + wrapper.attachToGLContext(0); |
| 61 | + reset(tx); |
| 62 | + |
| 63 | + wrapper.detachFromGLContext(); |
| 64 | + verify(tx, times(1)).detachFromGLContext(); |
| 65 | + verifyNoMoreInteractions(tx); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void release() { |
| 70 | + final SurfaceTexture tx = mock(SurfaceTexture.class); |
| 71 | + final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx); |
| 72 | + |
| 73 | + wrapper.release(); |
| 74 | + |
| 75 | + verify(tx, times(1)).release(); |
| 76 | + reset(tx); |
| 77 | + |
| 78 | + wrapper.detachFromGLContext(); |
| 79 | + wrapper.attachToGLContext(0); |
| 80 | + verifyNoMoreInteractions(tx); |
| 81 | + } |
| 82 | +} |
0 commit comments