Add a TestTransformationResult class for additional test values.

This class will contain additional details such as frame count, once implemented.

#mse-bug-week

PiperOrigin-RevId: 429567678
This commit is contained in:
samrobinson 2022-02-18 16:05:43 +00:00 committed by Ian Baker
parent e36ea3b77d
commit dfb7df542d
3 changed files with 50 additions and 18 deletions

View File

@ -53,18 +53,20 @@ public final class AndroidTestUtil {
* @param transformer The {@link Transformer} that performs the transformation. * @param transformer The {@link Transformer} that performs the transformation.
* @param uriString The uri (as a {@link String}) that will be transformed. * @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. * @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. * @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) Context context, String testId, Transformer transformer, String uriString, int timeoutSeconds)
throws Exception { throws Exception {
JSONObject resultJson = new JSONObject(); JSONObject resultJson = new JSONObject();
try { try {
TransformationResult transformationResult = TestTransformationResult testTransformationResult =
runTransformerInternal(context, testId, transformer, uriString, timeoutSeconds); runTransformerInternal(context, testId, transformer, uriString, timeoutSeconds);
resultJson.put("transformationResult", getTransformationResultJson(transformationResult)); resultJson.put(
return transformationResult; "transformationResult",
getTransformationResultJson(testTransformationResult.transformationResult));
return testTransformationResult;
} catch (Exception e) { } catch (Exception e) {
resultJson.put("exception", getExceptionJson(e)); resultJson.put("exception", getExceptionJson(e));
throw 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) Context context, String testId, Transformer transformer, String uriString, int timeoutSeconds)
throws Exception { throws Exception {
AtomicReference<@NullableType TransformationException> transformationExceptionReference = AtomicReference<@NullableType TransformationException> transformationExceptionReference =
@ -137,10 +139,13 @@ public final class AndroidTestUtil {
// If both exceptions are null, the Transformation must have succeeded, and a // If both exceptions are null, the Transformation must have succeeded, and a
// transformationResult will be available. // transformationResult will be available.
return checkNotNull(transformationResultReference.get()) TransformationResult transformationResult =
checkNotNull(transformationResultReference.get())
.buildUpon() .buildUpon()
.setFileSizeBytes(outputVideoFile.length()) .setFileSizeBytes(outputVideoFile.length())
.build(); .build();
return new TestTransformationResult(transformationResult, outputVideoFile.getPath());
} }
private static void writeTestSummaryToFile(Context context, String testId, JSONObject resultJson) private static void writeTestSummaryToFile(Context context, String testId, JSONObject resultJson)

View File

@ -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;
}
}

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.transformer.mh; package com.google.android.exoplayer2.transformer.mh;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer; 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 static com.google.common.truth.Truth.assertWithMessage;
import android.content.Context; import android.content.Context;
@ -23,10 +24,9 @@ import android.graphics.Matrix;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.transformer.AndroidTestUtil; 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.TransformationRequest;
import com.google.android.exoplayer2.transformer.TransformationResult;
import com.google.android.exoplayer2.transformer.Transformer; import com.google.android.exoplayer2.transformer.Transformer;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -58,14 +58,14 @@ public final class RepeatedTranscodeTransformationTest {
Set<Long> differentOutputSizesBytes = new HashSet<>(); Set<Long> differentOutputSizesBytes = new HashSet<>();
for (int i = 0; i < TRANSCODE_COUNT; i++) { 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. // Use a long video in case an error occurs a while after the start of the video.
TransformationResult result = TestTransformationResult testResult =
runTransformer( runTransformer(
context, context,
/* testId= */ "repeatedTranscode_givesConsistentLengthOutput_" + i, /* testId= */ "repeatedTranscode_givesConsistentLengthOutput_" + i,
transformer, transformer,
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
/* timeoutSeconds= */ 120); /* timeoutSeconds= */ 120);
differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes)); differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes));
} }
assertWithMessage( assertWithMessage(
@ -92,14 +92,14 @@ public final class RepeatedTranscodeTransformationTest {
Set<Long> differentOutputSizesBytes = new HashSet<>(); Set<Long> differentOutputSizesBytes = new HashSet<>();
for (int i = 0; i < TRANSCODE_COUNT; i++) { 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. // Use a long video in case an error occurs a while after the start of the video.
TransformationResult result = TestTransformationResult testResult =
runTransformer( runTransformer(
context, context,
/* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput_" + i, /* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput_" + i,
transformer, transformer,
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
/* timeoutSeconds= */ 120); /* timeoutSeconds= */ 120);
differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes)); differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes));
} }
assertWithMessage( assertWithMessage(
@ -123,14 +123,14 @@ public final class RepeatedTranscodeTransformationTest {
Set<Long> differentOutputSizesBytes = new HashSet<>(); Set<Long> differentOutputSizesBytes = new HashSet<>();
for (int i = 0; i < TRANSCODE_COUNT; i++) { 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. // Use a long video in case an error occurs a while after the start of the video.
TransformationResult result = TestTransformationResult testResult =
runTransformer( runTransformer(
context, context,
/* testId= */ "repeatedTranscodeNoVideo_givesConsistentLengthOutput_" + i, /* testId= */ "repeatedTranscodeNoVideo_givesConsistentLengthOutput_" + i,
transformer, transformer,
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
/* timeoutSeconds= */ 120); /* timeoutSeconds= */ 120);
differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes)); differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes));
} }
assertWithMessage( assertWithMessage(