Search in sources :

Example 21 with FakeDataSet

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

the class DashDownloaderTest method downloadAllRepresentations.

@Test
public void downloadAllRepresentations() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3).setRandomData("period_2_segment_1", 1).setRandomData("period_2_segment_2", 2).setRandomData("period_2_segment_3", 3);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet);
    dashDownloader.download(progressListener);
    assertCachedData(cache, new RequestSet(fakeDataSet).useBoundedDataSpecFor("audio_init_data"));
}
Also used : RequestSet(com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) Test(org.junit.Test)

Example 22 with FakeDataSet

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

the class DashDownloaderTest method downloadRepresentations.

@Test
public void downloadRepresentations() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0), new StreamKey(0, 1, 0));
    dashDownloader.download(progressListener);
    assertCachedData(cache, new RequestSet(fakeDataSet).useBoundedDataSpecFor("audio_init_data"));
}
Also used : RequestSet(com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 23 with FakeDataSet

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

the class FakeDataSetTest method testSegmentTypes.

@Test
public void testSegmentTypes() {
    byte[] testData = TestUtil.buildTestData(3);
    Runnable runnable = () -> {
    // Do nothing.
    };
    IOException exception = new IOException();
    FakeDataSet fakeDataSet = new FakeDataSet().newDefaultData().appendReadData(testData).appendReadData(testData).appendReadData(50).appendReadAction(runnable).appendReadError(exception).endData();
    List<Segment> segments = fakeDataSet.getData((Uri) null).getSegments();
    assertThat(segments.size()).isEqualTo(5);
    assertSegment(segments.get(0), testData, 3, 0, null, null);
    assertSegment(segments.get(1), testData, 3, 3, null, null);
    assertSegment(segments.get(2), null, 50, 6, null, null);
    assertSegment(segments.get(3), null, 0, 56, runnable, null);
    assertSegment(segments.get(4), null, 0, 56, null, exception);
    byte[] allData = new byte[6];
    System.arraycopy(testData, 0, allData, 0, 3);
    System.arraycopy(testData, 0, allData, 3, 3);
    assertThat(fakeDataSet.getData((Uri) null).getData()).isEqualTo(allData);
}
Also used : IOException(java.io.IOException) Uri(android.net.Uri) Segment(com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment) Test(org.junit.Test)

Example 24 with FakeDataSet

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

the class FakeDataSourceTest method testReadFull.

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

Example 25 with FakeDataSet

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

the class FakeDataSourceTest method testReadPartialBounded.

@Test
public void testReadPartialBounded() throws IOException {
    FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
    assertThat(dataSource.open(new DataSpec(uri, 9, 3))).isEqualTo(3);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(1);
    assertBuffer(TEST_DATA_PART_1, 9, 1);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(2);
    assertBuffer(TEST_DATA_PART_2, 0, 2);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
    dataSource.close();
    assertThat(dataSource.open(new DataSpec(uri, 11, 4))).isEqualTo(4);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(4);
    assertBuffer(TEST_DATA_PART_2, 1, 4);
    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)

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