From 5a4d82c7c2fd5ceb7a78cc4af7227fcf69123e80 Mon Sep 17 00:00:00 2001 From: eguven Date: Tue, 31 May 2016 07:22:11 -0700 Subject: [PATCH] TestUtil.assertOutput() uses "*.unklen.dump" file if only it exists and simulateUnknownLength is true. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=123638992 --- .../android/exoplayer/testutil/TestUtil.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/library/src/androidTest/java/com/google/android/exoplayer/testutil/TestUtil.java b/library/src/androidTest/java/com/google/android/exoplayer/testutil/TestUtil.java index f366fd0dd8..b29f9d6ac5 100644 --- a/library/src/androidTest/java/com/google/android/exoplayer/testutil/TestUtil.java +++ b/library/src/androidTest/java/com/google/android/exoplayer/testutil/TestUtil.java @@ -29,6 +29,7 @@ import org.mockito.MockitoAnnotations; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.Random; /** @@ -44,7 +45,7 @@ public class TestUtil { } private static final String DUMP_EXTENSION = ".dump"; - private static final String UNKNOWN_LENGTH_EXTENSION = ".unklen"; + private static final String UNKNOWN_LENGTH_EXTENSION = ".unklen" + DUMP_EXTENSION; private TestUtil() {} @@ -158,6 +159,15 @@ public class TestUtil { MockitoAnnotations.initMocks(instrumentationTestCase); } + public static boolean assetExists(Instrumentation instrumentation, String fileName) + throws IOException { + int i = fileName.lastIndexOf('/'); + String path = i >= 0 ? fileName.substring(0, i) : ""; + String file = i >= 0 ? fileName.substring(i + 1) : fileName; + return Arrays.asList(instrumentation.getContext().getResources().getAssets().list(path)) + .contains(file); + } + public static byte[] getByteArray(Instrumentation instrumentation, String fileName) throws IOException { InputStream is = instrumentation.getContext().getResources().getAssets().open(fileName); @@ -199,9 +209,9 @@ public class TestUtil { /** * Asserts that {@code extractor} consumes {@code sampleFile} successfully and its output equals - * to a prerecorded output dump file. The prerecorded output dump file name is determined by - * appending "{@value UNKNOWN_LENGTH_EXTENSION}" if {@code simulateUnknownLength} is true and - * appending "{@value DUMP_EXTENSION}" to the end of {@code sampleFile}. + * to a prerecorded output dump file with the name {@code sampleFile} + "{@value + * #DUMP_EXTENSION}". If {@code simulateUnknownLength} is true and {@code sampleFile} + "{@value + * #UNKNOWN_LENGTH_EXTENSION}" exists, it's preferred. * * @param extractor The {@link Extractor} to be tested. * @param sampleFile The path to the input sample. @@ -226,12 +236,12 @@ public class TestUtil { input.resetPeekPosition(); FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, true); - String dumpFile = sampleFile; - if (simulateUnknownLength) { - dumpFile += UNKNOWN_LENGTH_EXTENSION; + if (simulateUnknownLength + && assetExists(instrumentation, sampleFile + UNKNOWN_LENGTH_EXTENSION)) { + extractorOutput.assertOutput(instrumentation, sampleFile + UNKNOWN_LENGTH_EXTENSION); + } else { + extractorOutput.assertOutput(instrumentation, sampleFile + DUMP_EXTENSION); } - dumpFile += DUMP_EXTENSION; - extractorOutput.assertOutput(instrumentation, dumpFile); return extractorOutput; }