diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AndroidTestUtil.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AndroidTestUtil.java index ba35de44f8..4e693aab73 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AndroidTestUtil.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AndroidTestUtil.java @@ -53,18 +53,20 @@ public final class AndroidTestUtil { * @param transformer The {@link Transformer} that performs the transformation. * @param uriString The uri (as a {@link String}) that will be transformed. * @param timeoutSeconds The transformer timeout. An exception is thrown if this is exceeded. - * @return The {@link TransformationResult}. + * @return The {@link TestTransformationResult}. * @throws Exception The cause of the transformation not completing. */ - public static TransformationResult runTransformer( + public static TestTransformationResult runTransformer( Context context, String testId, Transformer transformer, String uriString, int timeoutSeconds) throws Exception { JSONObject resultJson = new JSONObject(); try { - TransformationResult transformationResult = + TestTransformationResult testTransformationResult = runTransformerInternal(context, testId, transformer, uriString, timeoutSeconds); - resultJson.put("transformationResult", getTransformationResultJson(transformationResult)); - return transformationResult; + resultJson.put( + "transformationResult", + getTransformationResultJson(testTransformationResult.transformationResult)); + return testTransformationResult; } catch (Exception e) { resultJson.put("exception", getExceptionJson(e)); throw e; @@ -73,7 +75,7 @@ public final class AndroidTestUtil { } } - private static TransformationResult runTransformerInternal( + private static TestTransformationResult runTransformerInternal( Context context, String testId, Transformer transformer, String uriString, int timeoutSeconds) throws Exception { AtomicReference<@NullableType TransformationException> transformationExceptionReference = @@ -137,10 +139,13 @@ public final class AndroidTestUtil { // If both exceptions are null, the Transformation must have succeeded, and a // transformationResult will be available. - return checkNotNull(transformationResultReference.get()) - .buildUpon() - .setFileSizeBytes(outputVideoFile.length()) - .build(); + TransformationResult transformationResult = + checkNotNull(transformationResultReference.get()) + .buildUpon() + .setFileSizeBytes(outputVideoFile.length()) + .build(); + + return new TestTransformationResult(transformationResult, outputVideoFile.getPath()); } private static void writeTestSummaryToFile(Context context, String testId, JSONObject resultJson) diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TestTransformationResult.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TestTransformationResult.java new file mode 100644 index 0000000000..edc6c1a045 --- /dev/null +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TestTransformationResult.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.transformer; + +/** A test only class for holding additional details alongside a {@link TransformationResult}. */ +public class TestTransformationResult { + public final TransformationResult transformationResult; + public final String filePath; + + public TestTransformationResult(TransformationResult transformationResult, String filePath) { + this.transformationResult = transformationResult; + this.filePath = filePath; + } +} diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/RepeatedTranscodeTransformationTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/RepeatedTranscodeTransformationTest.java index d49b8d00de..ec50ad4090 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/RepeatedTranscodeTransformationTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/RepeatedTranscodeTransformationTest.java @@ -16,6 +16,7 @@ package com.google.android.exoplayer2.transformer.mh; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer; +import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.common.truth.Truth.assertWithMessage; import android.content.Context; @@ -23,10 +24,9 @@ import android.graphics.Matrix; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.transformer.AndroidTestUtil; +import com.google.android.exoplayer2.transformer.TestTransformationResult; import com.google.android.exoplayer2.transformer.TransformationRequest; -import com.google.android.exoplayer2.transformer.TransformationResult; import com.google.android.exoplayer2.transformer.Transformer; -import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.MimeTypes; import java.util.HashSet; import java.util.Set; @@ -58,14 +58,14 @@ public final class RepeatedTranscodeTransformationTest { Set differentOutputSizesBytes = new HashSet<>(); for (int i = 0; i < TRANSCODE_COUNT; i++) { // Use a long video in case an error occurs a while after the start of the video. - TransformationResult result = + TestTransformationResult testResult = runTransformer( context, /* testId= */ "repeatedTranscode_givesConsistentLengthOutput_" + i, transformer, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, /* timeoutSeconds= */ 120); - differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes)); + differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes)); } assertWithMessage( @@ -92,14 +92,14 @@ public final class RepeatedTranscodeTransformationTest { Set differentOutputSizesBytes = new HashSet<>(); for (int i = 0; i < TRANSCODE_COUNT; i++) { // Use a long video in case an error occurs a while after the start of the video. - TransformationResult result = + TestTransformationResult testResult = runTransformer( context, /* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput_" + i, transformer, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, /* timeoutSeconds= */ 120); - differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes)); + differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes)); } assertWithMessage( @@ -123,14 +123,14 @@ public final class RepeatedTranscodeTransformationTest { Set differentOutputSizesBytes = new HashSet<>(); for (int i = 0; i < TRANSCODE_COUNT; i++) { // Use a long video in case an error occurs a while after the start of the video. - TransformationResult result = + TestTransformationResult testResult = runTransformer( context, /* testId= */ "repeatedTranscodeNoVideo_givesConsistentLengthOutput_" + i, transformer, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, /* timeoutSeconds= */ 120); - differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes)); + differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes)); } assertWithMessage(