Search in sources :

Example 1 with FakeDataSource

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

the class CacheDataSourceTest method createCacheDataSource.

private CacheDataSource createCacheDataSource(boolean setReadException, boolean simulateUnknownLength, @CacheDataSource.Flags int flags, CacheDataSink cacheWriteDataSink) {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    if (setReadException) {
        builder.appendReadError(new IOException("Shouldn't read from upstream"));
    }
    FakeDataSource upstream = builder.setSimulateUnknownLength(simulateUnknownLength).appendReadData(TEST_DATA).build();
    return new CacheDataSource(simpleCache, upstream, new FileDataSource(), cacheWriteDataSink, flags, null);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) IOException(java.io.IOException)

Example 2 with FakeDataSource

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

the class DefaultExtractorInputTest method testSkipFullyWithFailingDataSource.

public void testSkipFullyWithFailingDataSource() throws Exception {
    FakeDataSource testDataSource = buildFailingDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    try {
        input.skipFully(TEST_DATA.length);
        fail();
    } catch (IOException e) {
    // Expected.
    }
    // The position should not have advanced.
    assertEquals(0, input.getPosition());
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) IOException(java.io.IOException)

Example 3 with FakeDataSource

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

the class DefaultExtractorInputTest method testReadFullyWithFailingDataSource.

public void testReadFullyWithFailingDataSource() throws Exception {
    FakeDataSource testDataSource = buildFailingDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    try {
        byte[] target = new byte[TEST_DATA.length];
        input.readFully(target, 0, TEST_DATA.length);
        fail();
    } catch (IOException e) {
    // Expected.
    }
    // The position should not have advanced.
    assertEquals(0, input.getPosition());
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) IOException(java.io.IOException)

Example 4 with FakeDataSource

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

the class DefaultExtractorInputTest method buildLargeDataSource.

private static FakeDataSource buildLargeDataSource() throws Exception {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(new byte[LARGE_TEST_DATA_LENGTH]);
    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 5 with FakeDataSource

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

the class DefaultExtractorInputTest method testInitialPosition.

public void testInitialPosition() throws Exception {
    FakeDataSource testDataSource = buildDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 123, C.LENGTH_UNSET);
    assertEquals(123, input.getPosition());
}
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