Search in sources :

Example 11 with FakeDataSource

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

the class CacheDataSourceTest2 method testReads.

private void testReads(boolean useEncryption) throws IOException {
    FakeDataSource upstreamSource = buildFakeUpstreamSource();
    CacheDataSource source = buildCacheDataSource(getContext(), upstreamSource, useEncryption);
    // First read, should arrive from upstream.
    testRead(END_ON_BOUNDARY, source);
    assertSingleOpen(upstreamSource, 0, OFFSET_ON_BOUNDARY);
    // Second read, should arrive from upstream.
    testRead(START_OFF_BOUNDARY, source);
    assertSingleOpen(upstreamSource, OFFSET_OFF_BOUNDARY, DATA.length);
    // Second read, should arrive part from cache and part from upstream.
    testRead(END_OFF_BOUNDARY, source);
    assertSingleOpen(upstreamSource, OFFSET_ON_BOUNDARY, OFFSET_OFF_BOUNDARY);
    // Third read, should arrive from cache.
    testRead(FULL, source);
    assertNoOpen(upstreamSource);
    // Various reads, should all arrive from cache.
    testRead(FULL, source);
    assertNoOpen(upstreamSource);
    testRead(START_ON_BOUNDARY, source);
    assertNoOpen(upstreamSource);
    testRead(END_ON_BOUNDARY, source);
    assertNoOpen(upstreamSource);
    testRead(START_OFF_BOUNDARY, source);
    assertNoOpen(upstreamSource);
    testRead(END_OFF_BOUNDARY, source);
    assertNoOpen(upstreamSource);
}
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