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();
}
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();
}
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);
}
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);
}
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);
}
Aggregations