From 4302102cf0bc3dcdc8d5ac53471eba67ba3a0c6e Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Tue, 1 Aug 2023 18:28:20 +0000 Subject: [PATCH] Test: Use TestName in media3.effects tests. Instead of duplicating strings PiperOrigin-RevId: 552865414 --- .../media3/effect/ContrastPixelTest.java | 23 ++++++-- .../androidx/media3/effect/CropPixelTest.java | 19 ++++++- .../effect/DefaultShaderProgramPixelTest.java | 21 +++++-- ...deoFrameProcessorImageFrameOutputTest.java | 21 ++++--- .../DefaultVideoFrameProcessorPixelTest.java | 55 ++++++++++++------- .../androidx/media3/effect/FrameDropTest.java | 17 +++--- .../effect/OverlayShaderProgramPixelTest.java | 39 ++++++++----- .../media3/effect/PresentationPixelTest.java | 27 ++++++--- .../media3/effect/RgbAdjustmentPixelTest.java | 29 +++++++--- .../media3/effect/RgbFilterPixelTest.java | 17 +++++- .../effect/SingleColorLutPixelTest.java | 29 +++++++--- .../test/utils/BitmapPixelTestUtil.java | 1 + .../DefaultVideoCompositorPixelTest.java | 31 +++++++---- 13 files changed, 231 insertions(+), 98 deletions(-) diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/ContrastPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/ContrastPixelTest.java index 70f02091dd..77c383e46b 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/ContrastPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/ContrastPixelTest.java @@ -38,10 +38,14 @@ import androidx.media3.common.util.GlUtil; import androidx.media3.common.util.Size; import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.test.ext.junit.runners.AndroidJUnit4; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -54,6 +58,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public class ContrastPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/linear_colors/original.png"; private static final String INCREASE_CONTRAST_PNG_ASSET_PATH = @@ -68,6 +74,7 @@ public class ContrastPixelTest { private final Context context = getApplicationContext(); + private @MonotonicNonNull String testId; private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLSurface placeholderEglSurface; @@ -88,6 +95,12 @@ public class ContrastPixelTest { inputTexId = createGlTextureFromBitmap(inputBitmap); } + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { if (contrastShaderProgram != null) { @@ -97,8 +110,8 @@ public class ContrastPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_noContrastChange_leavesFrameUnchanged() throws Exception { - String testId = "drawFrame_noContrastChange"; contrastShaderProgram = new Contrast(/* contrast= */ 0.0f).toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); @@ -116,8 +129,8 @@ public class ContrastPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_minimumContrast_producesAllGrayFrame() throws Exception { - String testId = "drawFrame_minimumContrast"; contrastShaderProgram = new Contrast(/* contrast= */ -1.0f).toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); @@ -140,9 +153,9 @@ public class ContrastPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_decreaseContrast_decreasesPixelsGreaterEqual128IncreasesBelow() throws Exception { - String testId = "drawFrame_decreaseContrast"; contrastShaderProgram = new Contrast(/* contrast= */ -0.75f).toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); @@ -160,9 +173,9 @@ public class ContrastPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_increaseContrast_increasesPixelsGreaterEqual128DecreasesBelow() throws Exception { - String testId = "drawFrame_increaseContrast"; contrastShaderProgram = new Contrast(/* contrast= */ 0.75f).toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); @@ -180,8 +193,8 @@ public class ContrastPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_maximumContrast_pixelEither0or255() throws Exception { - String testId = "drawFrame_maximumContrast"; contrastShaderProgram = new Contrast(/* contrast= */ 1.0f).toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/CropPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/CropPixelTest.java index 0a91c4c7e7..e49fa81307 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/CropPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/CropPixelTest.java @@ -36,10 +36,14 @@ import androidx.media3.common.util.Size; import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.io.IOException; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -52,6 +56,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public final class CropPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; private static final String CROP_SMALLER_PNG_ASSET_PATH = @@ -61,6 +67,7 @@ public final class CropPixelTest { private final Context context = getApplicationContext(); + private @MonotonicNonNull String testId; private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull SingleFrameGlShaderProgram cropShaderProgram; @@ -81,6 +88,12 @@ public final class CropPixelTest { inputTexId = createGlTextureFromBitmap(inputBitmap); } + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { if (cropShaderProgram != null) { @@ -92,8 +105,8 @@ public final class CropPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_noEdits_matchesGoldenFile() throws Exception { - String testId = "drawFrame_noEdits"; cropShaderProgram = new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1) .toGlShaderProgram(context, /* useHdr= */ false); @@ -113,8 +126,8 @@ public final class CropPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_cropSmaller_matchesGoldenFile() throws Exception { - String testId = "drawFrame_cropSmaller"; cropShaderProgram = new Crop(/* left= */ -0.9f, /* right= */ 0.1f, /* bottom= */ -1f, /* top= */ 0.5f) .toGlShaderProgram(context, /* useHdr= */ false); @@ -134,8 +147,8 @@ public final class CropPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_cropLarger_matchesGoldenFile() throws Exception { - String testId = "drawFrame_cropLarger"; cropShaderProgram = new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f) .toGlShaderProgram(context, /* useHdr= */ false); diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultShaderProgramPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultShaderProgramPixelTest.java index 0feef12e8c..7c82be032e 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultShaderProgramPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultShaderProgramPixelTest.java @@ -35,10 +35,14 @@ import androidx.media3.common.util.GlUtil; import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.io.IOException; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -51,6 +55,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public final class DefaultShaderProgramPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; private static final String TRANSLATE_RIGHT_PNG_ASSET_PATH = @@ -62,6 +68,7 @@ public final class DefaultShaderProgramPixelTest { private final Context context = getApplicationContext(); + private @MonotonicNonNull String testId; private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; @@ -87,6 +94,12 @@ public final class DefaultShaderProgramPixelTest { eglDisplay, eglContext, placeholderEglSurface, frameBuffer, inputWidth, inputHeight); } + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { if (defaultShaderProgram != null) { @@ -98,8 +111,8 @@ public final class DefaultShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_noEdits_matchesGoldenFile() throws Exception { - String testId = "drawFrame_noEdits"; Matrix identityMatrix = new Matrix(); MatrixTransformation noEditsTransformation = (long presentationTimeUs) -> identityMatrix; defaultShaderProgram = noEditsTransformation.toGlShaderProgram(context, /* useHdr= */ false); @@ -117,8 +130,8 @@ public final class DefaultShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_translateRight_matchesGoldenFile() throws Exception { - String testId = "drawFrame_translateRight"; Matrix translateRightMatrix = new Matrix(); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); MatrixTransformation translateRightTransformation = @@ -139,8 +152,8 @@ public final class DefaultShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_scaleNarrow_matchesGoldenFile() throws Exception { - String testId = "drawFrame_scaleNarrow"; Matrix scaleNarrowMatrix = new Matrix(); scaleNarrowMatrix.postScale(.5f, 1.2f); MatrixTransformation scaleNarrowTransformation = (long presentationTimeUs) -> scaleNarrowMatrix; @@ -160,8 +173,8 @@ public final class DefaultShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_rotate90_matchesGoldenFile() throws Exception { - String testId = "drawFrame_rotate90"; Matrix rotate90Matrix = new Matrix(); rotate90Matrix.postRotate(/* degrees= */ 90); MatrixTransformation rotate90Transformation = (long presentationTimeUs) -> rotate90Matrix; diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorImageFrameOutputTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorImageFrameOutputTest.java index 18eea571ae..acbb1c6d62 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorImageFrameOutputTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorImageFrameOutputTest.java @@ -31,12 +31,16 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** Tests for frame queuing and output in {@link DefaultVideoFrameProcessor} given image input. */ @RunWith(AndroidJUnit4.class) public class DefaultVideoFrameProcessorImageFrameOutputTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; private static final String SCALE_WIDE_PNG_ASSET_PATH = @@ -44,13 +48,15 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest { private static final String BITMAP_OVERLAY_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/overlay_bitmap_FrameProcessor.png"; + private @MonotonicNonNull String testId; private @MonotonicNonNull VideoFrameProcessorTestRunner videoFrameProcessorTestRunner; private @MonotonicNonNull AtomicInteger framesProduced; - @EnsuresNonNull("framesProduced") @Before + @EnsuresNonNull({"framesProduced", "testId"}) public void setUp() { framesProduced = new AtomicInteger(); + testId = testName.getMethodName(); } @After @@ -58,10 +64,9 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest { checkNotNull(videoFrameProcessorTestRunner).release(); } - @RequiresNonNull("framesProduced") @Test + @RequiresNonNull({"framesProduced", "testId"}) public void imageInput_queueThreeBitmaps_outputsCorrectNumberOfFrames() throws Exception { - String testId = "imageInput_queueThreeBitmaps_outputsCorrectNumberOfFrames"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build(); videoFrameProcessorTestRunner.queueInputBitmap( @@ -85,10 +90,9 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest { assertThat(actualFrameCount).isEqualTo(/* expected= */ 20); } - @RequiresNonNull("framesProduced") @Test + @RequiresNonNull({"framesProduced", "testId"}) public void imageInput_queueTwentyBitmaps_outputsCorrectNumberOfFrames() throws Exception { - String testId = "imageInput_queueTwentyBitmaps_outputsCorrectNumberOfFrames"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build(); for (int i = 0; i < 20; i++) { @@ -104,8 +108,8 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest { assertThat(actualFrameCount).isEqualTo(/* expected= */ 20); } - @RequiresNonNull("framesProduced") @Test + @RequiresNonNull({"framesProduced", "testId"}) public void imageInput_queueOneWithStartOffset_outputsFramesAtTheCorrectPresentationTimesUs() throws Exception { String testId = @@ -128,11 +132,10 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest { .inOrder(); } - @RequiresNonNull("framesProduced") @Test + @RequiresNonNull({"framesProduced", "testId"}) public void imageInput_queueWithStartOffsets_outputsFramesAtTheCorrectPresentationTimesUs() throws Exception { - String testId = "imageInput_queueWithStartOffsets_outputsFramesAtTheCorrectPresentationTimesUs"; Queue actualPresentationTimesUs = new ConcurrentLinkedQueue<>(); videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) @@ -161,8 +164,8 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest { .inOrder(); } - @RequiresNonNull("framesProduced") @Test + @RequiresNonNull({"framesProduced", "testId"}) public void imageInput_queueEndAndQueueAgain_outputsFirstSetOfFramesOnlyAtTheCorrectPresentationTimesUs() throws Exception { diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorPixelTest.java index 152efa7c0d..233c0d26d1 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorPixelTest.java @@ -34,9 +34,14 @@ import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.VideoFrameProcessorTestRunner; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.common.collect.ImmutableList; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -52,6 +57,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public final class DefaultVideoFrameProcessorPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; private static final String OVERLAY_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png"; @@ -91,16 +98,23 @@ public final class DefaultVideoFrameProcessorPixelTest { private static final GlEffect NO_OP_EFFECT = new GlEffectWrapper(new ScaleAndRotateTransformation.Builder().build()); + private @MonotonicNonNull String testId; private @MonotonicNonNull VideoFrameProcessorTestRunner videoFrameProcessorTestRunner; + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() { checkNotNull(videoFrameProcessorTestRunner).release(); } @Test + @RequiresNonNull("testId") public void noEffects_matchesGoldenFile() throws Exception { - String testId = "noEffects_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build(); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); @@ -114,8 +128,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void noEffects_withFrameCache_matchesGoldenFile() throws Exception { - String testId = "noEffects_withFrameCache_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setEffects(new FrameCache(/* capacity= */ 5)) @@ -132,8 +146,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void noEffects_withDisabledColorTransfers_matchesGoldenFile() throws Exception { - String testId = "noEffects_withDisabledColorTransfers_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setVideoFrameProcessorFactory( @@ -153,8 +167,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void noEffects_withImageInput_matchesGoldenFile() throws Exception { - String testId = "noEffects_withImageInput_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setInputColorInfo(ColorInfo.SRGB_BT709_FULL) @@ -174,8 +188,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void wrappedCrop_withImageInput_matchesGoldenFile() throws Exception { - String testId = "wrappedCrop_withImageInput_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setInputColorInfo(ColorInfo.SRGB_BT709_FULL) @@ -202,9 +216,9 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void noOpEffect_withImageInputAndDisabledColorTransfers_matchesGoldenFile() throws Exception { - String testId = "noOpEffect_withImageInputAndDisabledColorTransfers_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setVideoFrameProcessorFactory( @@ -228,8 +242,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void setPixelWidthHeightRatio_matchesGoldenFile() throws Exception { - String testId = "setPixelWidthHeightRatio_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).setPixelWidthHeightRatio(2f).build(); Bitmap expectedBitmap = readBitmap(SCALE_WIDE_PNG_ASSET_PATH); @@ -244,8 +258,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void matrixTransformation_matchesGoldenFile() throws Exception { - String testId = "matrixTransformation_matchesGoldenFile"; Matrix translateRightMatrix = new Matrix(); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); videoFrameProcessorTestRunner = @@ -264,8 +278,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void matrixAndScaleAndRotateTransformation_matchesGoldenFile() throws Exception { - String testId = "matrixAndScaleAndRotateTransformation_matchesGoldenFile"; Matrix translateRightMatrix = new Matrix(); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); videoFrameProcessorTestRunner = @@ -286,8 +300,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void bitmapOverlay_matchesGoldenFile() throws Exception { - String testId = "bitmapOverlay_matchesGoldenFile"; Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay(overlayBitmap); videoFrameProcessorTestRunner = @@ -306,8 +320,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void scaleAndRotateAndMatrixTransformation_matchesGoldenFile() throws Exception { - String testId = "scaleAndRotateAndMatrixTransformation_matchesGoldenFile"; Matrix translateRightMatrix = new Matrix(); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); videoFrameProcessorTestRunner = @@ -328,8 +342,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void presentation_createForHeight_matchesGoldenFile() throws Exception { - String testId = "presentation_createForHeight_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setEffects(Presentation.createForHeight(480)) @@ -346,8 +360,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void cropThenPresentation_matchesGoldenFile() throws Exception { - String testId = "cropThenPresentation_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setEffects( @@ -368,8 +382,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void scaleAndRotateTransformation_rotate45_matchesGoldenFile() throws Exception { - String testId = "scaleAndRotateTransformation_rotate45_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setEffects(new ScaleAndRotateTransformation.Builder().setRotationDegrees(45).build()) @@ -386,8 +400,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void twoWrappedScaleAndRotateTransformations_matchesGoldenFile() throws Exception { - String testId = "twoWrappedScaleAndRotateTransformations_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setEffects( @@ -410,8 +424,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void manyComposedMatrixEffects_matchesSingleEffect() throws Exception { - String testId = "manyComposedMatrixEffects_matchesSingleEffect"; Crop centerCrop = new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f); ImmutableList.Builder full10StepRotationAndCenterCrop = new ImmutableList.Builder<>(); @@ -444,8 +458,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void increaseBrightness_matchesGoldenFile() throws Exception { - String testId = "increaseBrightness_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).setEffects(new Brightness(0.5f)).build(); Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH); @@ -460,9 +474,9 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void manyComposedMatrixAndRgbEffects_producesSameOutputAsCombinedEffects() throws Exception { - String testId = "manyComposedMatrixAndRgbEffects_producesSameOutputAsCombinedEffects"; Crop centerCrop = new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f); ImmutableList increaseBrightnessFullRotationCenterCrop = @@ -506,10 +520,9 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void manyComposedMatrixAndRgbEffects_withFrameCache_producesSameOutputAsCombinedEffects() throws Exception { - String testId = - "manyComposedMatrixAndRgbEffects_withFrameCache_producesSameOutputAsCombinedEffects"; Crop centerCrop = new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f); ImmutableList increaseBrightnessFullRotationCenterCrop = @@ -554,8 +567,8 @@ public final class DefaultVideoFrameProcessorPixelTest { } @Test + @RequiresNonNull("testId") public void grayscaleThenIncreaseRedChannel_matchesGoldenFile() throws Exception { - String testId = "grayscaleThenIncreaseRedChannel_matchesGoldenFile"; videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId) .setEffects( diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/FrameDropTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/FrameDropTest.java index 1064c81064..3a438a73e3 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/FrameDropTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/FrameDropTest.java @@ -52,23 +52,29 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** Tests for {@link FrameDropEffect}. */ @RunWith(AndroidJUnit4.class) public class FrameDropTest { + @Rule public final TestName testName = new TestName(); + private static final String ASSET_PATH = "media/bitmap/FrameDropTest"; private static final int BLANK_FRAME_WIDTH = 100; private static final int BLANK_FRAME_HEIGHT = 50; + private @MonotonicNonNull String testId; private @MonotonicNonNull TextureBitmapReader textureBitmapReader; private @MonotonicNonNull DefaultVideoFrameProcessor defaultVideoFrameProcessor; - @EnsuresNonNull("textureBitmapReader") + @EnsuresNonNull({"textureBitmapReader", "testId"}) @Before public void setUp() { textureBitmapReader = new TextureBitmapReader(); + testId = testName.getMethodName(); } @After @@ -76,11 +82,10 @@ public class FrameDropTest { checkNotNull(defaultVideoFrameProcessor).release(); } - @RequiresNonNull("textureBitmapReader") @Test + @RequiresNonNull({"textureBitmapReader", "testId"}) public void frameDrop_withDefaultStrategy_outputsFramesAtTheCorrectPresentationTimesUs() throws Exception { - String testId = "frameDrop_withDefaultStrategy_outputsFramesAtTheCorrectPresentationTimesUs"; ImmutableList frameTimesUs = ImmutableList.of(0L, 16_000L, 32_000L, 48_000L, 58_000L, 71_000L, 86_000L); @@ -92,11 +97,10 @@ public class FrameDropTest { getAndAssertOutputBitmaps(textureBitmapReader, actualPresentationTimesUs, testId); } - @RequiresNonNull("textureBitmapReader") @Test + @RequiresNonNull({"textureBitmapReader", "testId"}) public void frameDrop_withSimpleStrategy_outputsFramesAtTheCorrectPresentationTimesUs() throws Exception { - String testId = "frameDrop_withSimpleStrategy_outputsFramesAtTheCorrectPresentationTimesUs"; ImmutableList frameTimesUs = ImmutableList.of(0L, 250_000L, 500_000L, 750_000L, 1_000_000L, 1_500_000L); @@ -110,10 +114,9 @@ public class FrameDropTest { getAndAssertOutputBitmaps(textureBitmapReader, actualPresentationTimesUs, testId); } - @RequiresNonNull("textureBitmapReader") @Test + @RequiresNonNull({"textureBitmapReader", "testId"}) public void frameDrop_withSimpleStrategy_outputsAllFrames() throws Exception { - String testId = "frameDrop_withSimpleStrategy_outputsAllFrames"; ImmutableList frameTimesUs = ImmutableList.of(0L, 333_333L, 666_667L); ImmutableList actualPresentationTimesUs = diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/OverlayShaderProgramPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/OverlayShaderProgramPixelTest.java index 0659ec7c14..5382bda477 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/OverlayShaderProgramPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/OverlayShaderProgramPixelTest.java @@ -42,10 +42,14 @@ import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.common.collect.ImmutableList; import java.io.IOException; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -58,6 +62,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public class OverlayShaderProgramPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String OVERLAY_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png"; private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; @@ -87,6 +93,7 @@ public class OverlayShaderProgramPixelTest { private final Context context = getApplicationContext(); + private @MonotonicNonNull String testId; private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull SingleFrameGlShaderProgram overlayShaderProgram; @@ -107,6 +114,12 @@ public class OverlayShaderProgramPixelTest { inputTexId = createGlTextureFromBitmap(inputBitmap); } + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { if (overlayShaderProgram != null) { @@ -116,8 +129,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_noOverlay_leavesFrameUnchanged() throws Exception { - String testId = "drawFrame_noOverlay"; overlayShaderProgram = new OverlayEffect(/* textureOverlays= */ ImmutableList.of()) .toGlShaderProgram(context, /* useHdr= */ false); @@ -136,8 +149,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_bitmapOverlay_blendsBitmapIntoFrame() throws Exception { - String testId = "drawFrame_bitmapOverlay"; Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay(overlayBitmap); overlayShaderProgram = @@ -158,9 +171,9 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_anchoredAndTranslatedBitmapOverlay_blendsBitmapIntoTopLeftOfFrame() throws Exception { - String testId = "drawFrame_anchoredAndTranslatedBitmapOverlay"; Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); OverlaySettings overlaySettings = new OverlaySettings.Builder() @@ -187,9 +200,9 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_overlayAnchoredOnlyBitmapOverlay_anchorsOverlayFromTopLeftCornerOfFrame() throws Exception { - String testId = "drawFrame_anchoredAndTranslatedBitmapOverlay"; Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); OverlaySettings overlaySettings = new OverlaySettings.Builder().setOverlayAnchor(/* x= */ 1f, /* y= */ -1f).build(); @@ -213,8 +226,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_rotatedBitmapOverlay_blendsBitmapRotated90degrees() throws Exception { - String testId = "drawFrame_rotatedBitmapOverlay"; Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); OverlaySettings overlaySettings = new OverlaySettings.Builder().setRotationDegrees(90f).build(); BitmapOverlay staticBitmapOverlay = @@ -237,8 +250,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_translucentBitmapOverlay_blendsBitmapIntoFrame() throws Exception { - String testId = "drawFrame_translucentBitmapOverlay"; Bitmap bitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlpha(0.5f).build(); BitmapOverlay translucentBitmapOverlay = @@ -261,8 +274,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_transparentTextOverlay_blendsBitmapIntoFrame() throws Exception { - String testId = "drawFrame_transparentTextOverlay"; SpannableString overlayText = new SpannableString(/* source= */ "Text styling"); OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlpha(0f).build(); overlayText.setSpan( @@ -290,8 +303,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_textOverlay_blendsTextIntoFrame() throws Exception { - String testId = "drawFrame_textOverlay"; SpannableString overlayText = new SpannableString(/* source= */ "Text styling"); overlayText.setSpan( new ForegroundColorSpan(Color.GRAY), @@ -317,8 +330,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_textOverlayWithRelativeScaleSpan_blendsTextIntoFrame() throws Exception { - String testId = "drawFrame_textOverlayWithRelativeScaleSpan"; SpannableString overlayText = new SpannableString(/* source= */ "helllllloooo!!!"); overlayText.setSpan( new RelativeSizeSpan(2f), @@ -344,9 +357,9 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_anchoredTextOverlay_blendsTextIntoTheTopRightQuadrantOfFrame() throws Exception { - String testId = "drawFrame_anchoredTextOverlay"; SpannableString overlayText = new SpannableString(/* source= */ "Text styling"); overlayText.setSpan( new ForegroundColorSpan(Color.GRAY), @@ -375,8 +388,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_multipleOverlays_blendsBothIntoFrame() throws Exception { - String testId = "drawFrame_multipleOverlays"; SpannableString overlayText = new SpannableString(/* source= */ "Overlay 1"); overlayText.setSpan( new ForegroundColorSpan(Color.GRAY), @@ -407,8 +420,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_overlappingOverlays_blendsOnFifoOrder() throws Exception { - String testId = "drawFrame_overlappingOverlays"; SpannableString overlayText = new SpannableString(/* source= */ "Overlapping text"); overlayText.setSpan( new ForegroundColorSpan(Color.WHITE), @@ -441,8 +454,8 @@ public class OverlayShaderProgramPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_scaledBitmapOverlay_letterboxStretchesOverlay() throws Exception { - String testId = "drawFrame_scaledBitmapOverlay"; Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); overlayShaderProgram = new OverlayEffect(ImmutableList.of(new LetterBoxStretchedBitmapOverlay(overlayBitmap))) diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/PresentationPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/PresentationPixelTest.java index 7bbdf21ff0..08a9afe7b3 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/PresentationPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/PresentationPixelTest.java @@ -37,10 +37,14 @@ import androidx.media3.common.util.Size; import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.io.IOException; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -53,6 +57,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public final class PresentationPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; private static final String ASPECT_RATIO_SCALE_TO_FIT_NARROW_PNG_ASSET_PATH = @@ -70,6 +76,7 @@ public final class PresentationPixelTest { private final Context context = getApplicationContext(); + private @MonotonicNonNull String testId; private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull SingleFrameGlShaderProgram presentationShaderProgram; @@ -90,6 +97,12 @@ public final class PresentationPixelTest { inputTexId = createGlTextureFromBitmap(inputBitmap); } + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { if (presentationShaderProgram != null) { @@ -101,8 +114,8 @@ public final class PresentationPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_noEdits_matchesGoldenFile() throws Exception { - String testId = "drawFrame_noEdits"; presentationShaderProgram = Presentation.createForHeight(C.LENGTH_UNSET) .toGlShaderProgram(context, /* useHdr= */ false); @@ -122,8 +135,8 @@ public final class PresentationPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_changeAspectRatio_scaleToFit_narrow_matchesGoldenFile() throws Exception { - String testId = "drawFrame_changeAspectRatio_scaleToFit_narrow"; presentationShaderProgram = Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT) .toGlShaderProgram(context, /* useHdr= */ false); @@ -143,8 +156,8 @@ public final class PresentationPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_changeAspectRatio_scaleToFit_wide_matchesGoldenFile() throws Exception { - String testId = "drawFrame_changeAspectRatio_scaleToFit_wide"; presentationShaderProgram = Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT) .toGlShaderProgram(context, /* useHdr= */ false); @@ -164,9 +177,9 @@ public final class PresentationPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_changeAspectRatio_scaleToFitWithCrop_narrow_matchesGoldenFile() throws Exception { - String testId = "drawFrame_changeAspectRatio_scaleToFitWithCrop_narrow"; presentationShaderProgram = Presentation.createForAspectRatio( /* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP) @@ -187,9 +200,9 @@ public final class PresentationPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_changeAspectRatio_scaleToFitWithCrop_wide_matchesGoldenFile() throws Exception { - String testId = "drawFrame_changeAspectRatio_scaleToFitWithCrop_wide"; presentationShaderProgram = Presentation.createForAspectRatio( /* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP) @@ -210,8 +223,8 @@ public final class PresentationPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_changeAspectRatio_stretchToFit_narrow_matchesGoldenFile() throws Exception { - String testId = "drawFrame_changeAspectRatio_stretchToFit_narrow"; presentationShaderProgram = Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_STRETCH_TO_FIT) .toGlShaderProgram(context, /* useHdr= */ false); @@ -231,8 +244,8 @@ public final class PresentationPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_changeAspectRatio_stretchToFit_wide_matchesGoldenFile() throws Exception { - String testId = "drawFrame_changeAspectRatio_stretchToFit_wide"; presentationShaderProgram = Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_STRETCH_TO_FIT) .toGlShaderProgram(context, /* useHdr= */ false); diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbAdjustmentPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbAdjustmentPixelTest.java index f58e8b325f..0b47092363 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbAdjustmentPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbAdjustmentPixelTest.java @@ -40,10 +40,14 @@ import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.common.collect.ImmutableList; import java.io.IOException; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -56,6 +60,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public final class RgbAdjustmentPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/linear_colors/original.png"; private static final String ONLY_RED_CHANNEL_PNG_ASSET_PATH = @@ -67,6 +73,7 @@ public final class RgbAdjustmentPixelTest { private final Context context = getApplicationContext(); + private @MonotonicNonNull String testId; private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; @@ -98,6 +105,12 @@ public final class RgbAdjustmentPixelTest { inputHeight); } + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { if (defaultShaderProgram != null) { @@ -107,8 +120,8 @@ public final class RgbAdjustmentPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_identityMatrix_leavesFrameUnchanged() throws Exception { - String testId = "drawFrame_identityMatrix"; RgbMatrix identityMatrix = new RgbAdjustment.Builder().build(); defaultShaderProgram = identityMatrix.toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); @@ -125,8 +138,8 @@ public final class RgbAdjustmentPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_removeColors_producesBlackFrame() throws Exception { - String testId = "drawFrame_removeColors"; RgbMatrix removeColorMatrix = new RgbAdjustment.Builder().setRedScale(0).setGreenScale(0).setBlueScale(0).build(); defaultShaderProgram = removeColorMatrix.toGlShaderProgram(context, /* useHdr= */ false); @@ -146,8 +159,8 @@ public final class RgbAdjustmentPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_redOnlyFilter_removeBlueAndGreenValues() throws Exception { - String testId = "drawFrame_redOnlyFilter"; RgbMatrix redOnlyMatrix = new RgbAdjustment.Builder().setBlueScale(0).setGreenScale(0).build(); defaultShaderProgram = redOnlyMatrix.toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); @@ -164,8 +177,8 @@ public final class RgbAdjustmentPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_increaseRedChannel_producesBrighterAndRedderFrame() throws Exception { - String testId = "drawFrame_increaseRedChannel"; RgbMatrix increaseRedMatrix = new RgbAdjustment.Builder().setRedScale(5).build(); defaultShaderProgram = increaseRedMatrix.toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); @@ -182,8 +195,8 @@ public final class RgbAdjustmentPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_increaseBrightness_increasesAllValues() throws Exception { - String testId = "drawFrame_increaseBrightness"; RgbMatrix increaseBrightnessMatrix = new RgbAdjustment.Builder().setRedScale(5).setGreenScale(5).setBlueScale(5).build(); defaultShaderProgram = increaseBrightnessMatrix.toGlShaderProgram(context, /* useHdr= */ false); @@ -201,8 +214,8 @@ public final class RgbAdjustmentPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_removeRedGreenAndBlueValuesInAChain_producesBlackImage() throws Exception { - String testId = "drawFrame_removeRedGreenBlueValuesInAChain"; RgbMatrix noRed = new RgbAdjustment.Builder().setRedScale(0).build(); RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build(); RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build(); @@ -228,8 +241,8 @@ public final class RgbAdjustmentPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_removeBlueAndGreenValuesInAChain_producesOnlyRedImage() throws Exception { - String testId = "drawFrame_removeBlueAndGreenValuesInAChain"; RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build(); RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build(); defaultShaderProgram = @@ -252,8 +265,8 @@ public final class RgbAdjustmentPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_increasesAndDecreasesRed_producesNoChange() throws Exception { - String testId = "drawFrame_increaseAndDecreaseRed"; float redScale = 4; RgbMatrix scaleRedMatrix = new RgbAdjustment.Builder().setRedScale(redScale).build(); RgbMatrix scaleRedByInverseMatrix = diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbFilterPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbFilterPixelTest.java index eaa9fdf9a9..eb69548a25 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbFilterPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbFilterPixelTest.java @@ -37,10 +37,14 @@ import androidx.media3.common.util.Size; import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.io.IOException; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -53,6 +57,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public final class RgbFilterPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/linear_colors/original.png"; private static final String GRAYSCALE_PNG_ASSET_PATH = @@ -62,6 +68,7 @@ public final class RgbFilterPixelTest { private final Context context = getApplicationContext(); + private @MonotonicNonNull String testId; private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; @@ -93,6 +100,12 @@ public final class RgbFilterPixelTest { inputHeight); } + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { if (defaultShaderProgram != null) { @@ -102,8 +115,8 @@ public final class RgbFilterPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_grayscale_producesGrayscaleImage() throws Exception { - String testId = "drawFrame_grayscale"; RgbMatrix grayscaleMatrix = RgbFilter.createGrayscaleFilter(); defaultShaderProgram = grayscaleMatrix.toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); @@ -120,8 +133,8 @@ public final class RgbFilterPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_inverted_producesInvertedFrame() throws Exception { - String testId = "drawFrame_inverted"; RgbMatrix invertedMatrix = RgbFilter.createInvertedFilter(); defaultShaderProgram = invertedMatrix.toGlShaderProgram(context, /* useHdr= */ false); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/SingleColorLutPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/SingleColorLutPixelTest.java index bdc5d644d6..0ad9aa7466 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/SingleColorLutPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/SingleColorLutPixelTest.java @@ -37,10 +37,14 @@ import androidx.media3.common.util.GlUtil; import androidx.media3.common.util.Size; import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.test.ext.junit.runners.AndroidJUnit4; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; /** @@ -53,6 +57,8 @@ import org.junit.runner.RunWith; */ @RunWith(AndroidJUnit4.class) public class SingleColorLutPixelTest { + @Rule public final TestName testName = new TestName(); + private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/linear_colors/original.png"; private static final String LUT_MAP_WHITE_TO_GREEN_ASSET_PATH = @@ -67,6 +73,7 @@ public class SingleColorLutPixelTest { private final Context context = getApplicationContext(); + private @MonotonicNonNull String testId; private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLSurface placeholderEglSurface; @@ -87,6 +94,12 @@ public class SingleColorLutPixelTest { inputTexId = createGlTextureFromBitmap(inputBitmap); } + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { if (colorLutShaderProgram != null) { @@ -96,8 +109,8 @@ public class SingleColorLutPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_identityCubeLutSize2_leavesFrameUnchanged() throws Exception { - String testId = "drawFrame_identityLutCubeSize2"; int[][][] cubeIdentityLut = createIdentityLutCube(/* length= */ 2); colorLutShaderProgram = SingleColorLut.createFromCube(cubeIdentityLut) @@ -117,8 +130,8 @@ public class SingleColorLutPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_identityCubeLutSize64_leavesFrameUnchanged() throws Exception { - String testId = "drawFrame_identityLutCubeSize64"; int[][][] cubeIdentityLut = createIdentityLutCube(/* length= */ 64); colorLutShaderProgram = SingleColorLut.createFromCube(cubeIdentityLut) @@ -138,8 +151,8 @@ public class SingleColorLutPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_identityBitmapLutSize2_leavesFrameUnchanged() throws Exception { - String testId = "drawFrame_identityBitmapLutSize2"; Bitmap bitmapLut = createIdentityLutBitmap(/* length= */ 2); colorLutShaderProgram = SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false); @@ -158,8 +171,8 @@ public class SingleColorLutPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_identityBitmapLutSize64_leavesFrameUnchanged() throws Exception { - String testId = "drawFrame_identityBitmapLutSize64"; Bitmap bitmapLut = createIdentityLutBitmap(/* length= */ 64); colorLutShaderProgram = SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false); @@ -178,8 +191,8 @@ public class SingleColorLutPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_identityLutFromHaldImage_leavesFrameUnchanged() throws Exception { - String testId = "drawFrame_identityLutFromHaldImage"; Bitmap bitmapLut = readBitmap(VERTICAL_HALD_IDENTITY_LUT); colorLutShaderProgram = SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false); @@ -198,8 +211,8 @@ public class SingleColorLutPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_mapWhiteToGreen_producesGreenHighlights() throws Exception { - String testId = "drawFrame_mapWhiteToGreen"; int length = 3; int[][][] mapWhiteToGreen = createIdentityLutCube(length); mapWhiteToGreen[length - 1][length - 1][length - 1] = Color.GREEN; @@ -221,8 +234,8 @@ public class SingleColorLutPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_applyInvertedLut_producesInvertedFrame() throws Exception { - String testId = "drawFrame_applyInvertedLut"; Bitmap invertedLutBitmap = readBitmap(VERTICAL_HALD_INVERTED_LUT); colorLutShaderProgram = SingleColorLut.createFromBitmap(invertedLutBitmap) @@ -242,8 +255,8 @@ public class SingleColorLutPixelTest { } @Test + @RequiresNonNull("testId") public void drawFrame_applyGrayscaleLut_producesGrayscaleFrame() throws Exception { - String testId = "drawFrame_applyGrayscaleLut"; Bitmap grayscaleLutBitmap = readBitmap(VERTICAL_HALD_GRAYSCALE_LUT); colorLutShaderProgram = SingleColorLut.createFromBitmap(grayscaleLutBitmap) diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/BitmapPixelTestUtil.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/BitmapPixelTestUtil.java index e3326b2daf..a2f10325bd 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/BitmapPixelTestUtil.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/BitmapPixelTestUtil.java @@ -308,6 +308,7 @@ public class BitmapPixelTestUtil { */ public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888( Bitmap expected, Bitmap actual, @Nullable String testId) { + Log.e("TEST", "testId = " + testId); return getBitmapAveragePixelAbsoluteDifferenceArgb8888( expected, actual, testId, /* differencesBitmapPath= */ null); } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/DefaultVideoCompositorPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/DefaultVideoCompositorPixelTest.java index 80b07eefb5..f8e824cfee 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/DefaultVideoCompositorPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/DefaultVideoCompositorPixelTest.java @@ -48,9 +48,12 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicReference; +import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.junit.After; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -60,6 +63,13 @@ import org.junit.runners.Parameterized; /** Pixel test for {@link DefaultVideoCompositor} compositing 2 input frames into 1 output frame. */ @RunWith(Parameterized.class) public final class DefaultVideoCompositorPixelTest { + @Parameterized.Parameters(name = "useSharedExecutor={0}") + public static ImmutableList useSharedExecutor() { + return ImmutableList.of(true, false); + } + + @Parameterized.Parameter public boolean useSharedExecutor; + @Rule public final TestName testName = new TestName(); private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png"; private static final String GRAYSCALE_PNG_ASSET_PATH = @@ -69,16 +79,15 @@ public final class DefaultVideoCompositorPixelTest { private static final String GRAYSCALE_AND_ROTATE180_COMPOSITE_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/grayscaleAndRotate180Composite.png"; - @Parameterized.Parameters(name = "useSharedExecutor={0}") - public static ImmutableList useSharedExecutor() { - return ImmutableList.of(true, false); - } - - @Parameterized.Parameter public boolean useSharedExecutor; - @Rule public TestName testName = new TestName(); - + private @MonotonicNonNull String testId; private @MonotonicNonNull VideoCompositorTestRunner compositorTestRunner; + @Before + @EnsuresNonNull("testId") + public void setUpTestId() { + testId = testName.getMethodName(); + } + @After public void tearDown() { if (compositorTestRunner != null) { @@ -87,8 +96,8 @@ public final class DefaultVideoCompositorPixelTest { } @Test + @RequiresNonNull("testId") public void compositeTwoInputs_withOneFrameFromEach_matchesExpectedBitmap() throws Exception { - String testId = testName.getMethodName(); compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor); compositorTestRunner.queueBitmapsToBothInputs(/* count= */ 1); @@ -108,9 +117,9 @@ public final class DefaultVideoCompositorPixelTest { } @Test + @RequiresNonNull("testId") public void compositeTwoInputs_withFiveFramesFromEach_matchesExpectedTimestamps() throws Exception { - String testId = testName.getMethodName(); compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor); compositorTestRunner.queueBitmapsToBothInputs(/* count= */ 5); @@ -136,9 +145,9 @@ public final class DefaultVideoCompositorPixelTest { } @Test + @RequiresNonNull("testId") public void compositeTwoInputs_withTenFramesFromEach_matchesExpectedFrameCount() throws Exception { - String testId = testName.getMethodName(); compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor); int numberOfFramesToQueue = 10;