Search in sources :

Example 26 with FakeDataSet

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

the class FakeDataSourceTest method testFakeData.

@Test
public void testFakeData() throws IOException {
    FakeDataSource dataSource = new FakeDataSource(new FakeDataSet().newData(uri.toString()).appendReadData(100).appendReadData(TEST_DATA).appendReadData(200).endData());
    assertThat(dataSource.open(new DataSpec(uri))).isEqualTo(315);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(100);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
    assertBuffer(TEST_DATA);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(200);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
    dataSource.close();
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 27 with FakeDataSet

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

the class FakeDataSourceTest method testReadPartialOpenEnded.

@Test
public void testReadPartialOpenEnded() throws IOException {
    FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
    assertThat(dataSource.open(new DataSpec(uri, 7, C.LENGTH_UNSET))).isEqualTo(8);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(3);
    assertBuffer(TEST_DATA_PART_1, 7, 3);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(5);
    assertBuffer(TEST_DATA_PART_2);
    assertThat(dataSource.read(BUFFER, 15, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
    dataSource.close();
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 28 with FakeDataSet

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

the class CacheDataSourceContractTest method createDataSource.

@Override
protected DataSource createDataSource() throws IOException {
    File tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    SimpleCache cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    upstreamDataSource = new FakeDataSource(fakeDataSet);
    return new CacheDataSource(cache, upstreamDataSource);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) File(java.io.File)

Example 29 with FakeDataSet

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

the class CacheWriterTest method cacheLengthExceedsActualDataLength.

@Test
public void cacheLengthExceedsActualDataLength() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setRandomData("test_data", 100);
    FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
    Uri testUri = Uri.parse("test_data");
    DataSpec dataSpec = new DataSpec(testUri, /* position= */
    0, /* length= */
    1000);
    CachingCounters counters = new CachingCounters();
    CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), dataSpec, /* temporaryBuffer= */
    null, counters);
    cacheWriter.cache();
    counters.assertValues(0, 100, 100);
    assertCachedData(cache, fakeDataSet);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Uri(android.net.Uri) Test(org.junit.Test)

Example 30 with FakeDataSet

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

the class CacheWriterTest method cacheUnknownLength.

@Test
public void cacheUnknownLength() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data").setSimulateUnknownLength(true).appendReadData(TestUtil.buildTestData(100)).endData();
    FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
    DataSpec dataSpec = new DataSpec(Uri.parse("test_data"));
    CachingCounters counters = new CachingCounters();
    CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), dataSpec, /* temporaryBuffer= */
    null, counters);
    cacheWriter.cache();
    counters.assertValues(0, 100, 100);
    assertCachedData(cache, fakeDataSet);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)23 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)16 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)14 StreamKey (com.google.android.exoplayer2.offline.StreamKey)11 Uri (android.net.Uri)6 IOException (java.io.IOException)6 RequestSet (com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet)5 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)4 DataSource (com.google.android.exoplayer2.upstream.DataSource)3 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)3 SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)3 Before (org.junit.Before)3 MediaItem (com.google.android.exoplayer2.MediaItem)2 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)2 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)2 DownloadManager (com.google.android.exoplayer2.offline.DownloadManager)2 TestDownloadManagerListener (com.google.android.exoplayer2.robolectric.TestDownloadManagerListener)2 DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)2 FailOnCloseDataSink (com.google.android.exoplayer2.testutil.FailOnCloseDataSink)2