Search in sources :

Example 6 with FakeData

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

the class FakeAdaptiveDataSetTest method assertChunkData.

private void assertChunkData(FakeAdaptiveDataSet dataSet, long chunkDuration) {
    for (int i = 0; i < dataSet.getChunkCount(); i++) {
        assertThat(dataSet.getStartTime(i)).isEqualTo(chunkDuration * i);
    }
    for (int s = 0; s < TEST_FORMATS.length; s++) {
        FakeData data = dataSet.getData(dataSet.getUri(s));
        assertThat(data.getSegments().size()).isEqualTo(dataSet.getChunkCount());
        for (int i = 0; i < data.getSegments().size(); i++) {
            long expectedLength = TEST_FORMATS[s].bitrate * dataSet.getChunkDuration(i) / (8 * C.MICROS_PER_SECOND);
            assertThat(data.getSegments().get(i).length).isEqualTo(expectedLength);
        }
    }
}
Also used : FakeData(com.google.android.exoplayer2.testutil.FakeDataSet.FakeData)

Example 7 with FakeData

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

the class CacheDataSourceTest method switchToCacheSourceWithReadOnlyCacheDataSource.

@Test
public void switchToCacheSourceWithReadOnlyCacheDataSource() throws Exception {
    // Create a fake data source with a 1 MB default data.
    FakeDataSource upstream = new FakeDataSource();
    FakeData fakeData = upstream.getDataSet().newDefaultData().appendReadData(1024 * 1024 - 1);
    // Insert an action just before the end of the data to fail the test if reading from upstream
    // reaches end of the data.
    fakeData.appendReadAction(() -> fail("Read from upstream shouldn't reach to the end of the data.")).appendReadData(1);
    // Create cache read-only CacheDataSource.
    CacheDataSource cacheDataSource = new CacheDataSource(cache, upstream, new FileDataSource(), null, 0, null);
    // Open source and read some data from upstream as the data hasn't cached yet.
    cacheDataSource.open(unboundedDataSpec);
    byte[] buffer = new byte[1024];
    cacheDataSource.read(buffer, 0, buffer.length);
    // Cache the data. Although we use another FakeDataSource instance, it shouldn't matter.
    FakeDataSource upstream2 = new FakeDataSource(new FakeDataSource().getDataSet().newDefaultData().appendReadData(1024 * 1024).endData());
    CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, upstream2), unboundedDataSpec, /* temporaryBuffer= */
    null, /* progressListener= */
    null);
    cacheWriter.cache();
    // Read the rest of the data.
    DataSourceUtil.readToEnd(cacheDataSource);
    cacheDataSource.close();
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) FakeData(com.google.android.exoplayer2.testutil.FakeDataSet.FakeData) Test(org.junit.Test)

Aggregations

FakeData (com.google.android.exoplayer2.testutil.FakeDataSet.FakeData)6 Segment (com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment)3 Test (org.junit.Test)3 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 IOException (java.io.IOException)2 DataSourceException (com.google.android.exoplayer2.upstream.DataSourceException)1 FileDataSource (com.google.android.exoplayer2.upstream.FileDataSource)1 Random (java.util.Random)1