Search in sources :

Example 6 with FakeDataSource

use of com.google.android.exoplayer2.testutil.FakeDataSource in project ExoPlayer by google.

the class DefaultExtractorInputTest method buildDataSource.

private static FakeDataSource buildDataSource() throws Exception {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 0, 3));
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 3, 6));
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    return testDataSource;
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Example 7 with FakeDataSource

use of com.google.android.exoplayer2.testutil.FakeDataSource in project ExoPlayer by google.

the class DefaultExtractorInputTest method testSkipFullyLarge.

public void testSkipFullyLarge() throws Exception {
    // Tests skipping an amount of data that's larger than any internal scratch space.
    int largeSkipSize = 1024 * 1024;
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(new byte[largeSkipSize]);
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    input.skipFully(largeSkipSize);
    assertEquals(largeSkipSize, input.getPosition());
    // Check that we fail with EOFException we skip again.
    try {
        input.skipFully(1);
        fail();
    } catch (EOFException e) {
    // Expected.
    }
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) EOFException(java.io.EOFException) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Example 8 with FakeDataSource

use of com.google.android.exoplayer2.testutil.FakeDataSource in project ExoPlayer by google.

the class DefaultExtractorInputTest method testSkip.

public void testSkip() throws Exception {
    FakeDataSource testDataSource = buildDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    // We expect to perform three skips of three bytes, as setup in buildTestDataSource.
    for (int i = 0; i < 3; i++) {
        assertEquals(3, input.skip(TEST_DATA.length));
    }
    // Check we're now indicated that the end of input is reached.
    int expectedEndOfInput = input.skip(TEST_DATA.length);
    assertEquals(C.RESULT_END_OF_INPUT, expectedEndOfInput);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource)

Example 9 with FakeDataSource

use of com.google.android.exoplayer2.testutil.FakeDataSource in project ExoPlayer by google.

the class DefaultExtractorInputTest method buildFailingDataSource.

private static FakeDataSource buildFailingDataSource() throws Exception {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 0, 6));
    builder.appendReadError(new IOException());
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    return testDataSource;
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) IOException(java.io.IOException)

Example 10 with FakeDataSource

use of com.google.android.exoplayer2.testutil.FakeDataSource in project ExoPlayer by google.

the class DefaultExtractorInputTest method testLargeSkip.

public void testLargeSkip() throws Exception {
    FakeDataSource testDataSource = buildLargeDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    // Check that skipping the entire data source succeeds.
    int bytesToSkip = LARGE_TEST_DATA_LENGTH;
    while (bytesToSkip > 0) {
        bytesToSkip -= input.skip(bytesToSkip);
    }
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource)

Aggregations

FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)11 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)4 IOException (java.io.IOException)4 FileDataSource (com.google.android.exoplayer2.upstream.FileDataSource)1 EOFException (java.io.EOFException)1