Search in sources :

Example 1 with FakeDataSet

use of androidx.media3.test.utils.FakeDataSet in project media by androidx.

the class DashDownloaderTest method progressiveDownloadSeparatePeriods.

@Test
public void progressiveDownloadSeparatePeriods() 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("period_2_segment_1", 1).setRandomData("period_2_segment_2", 2).setRandomData("period_2_segment_3", 3);
    FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
    FakeDataSource.Factory factory = mock(FakeDataSource.Factory.class);
    when(factory.createDataSource()).thenReturn(fakeDataSource);
    DashDownloader dashDownloader = getDashDownloader(factory, new StreamKey(0, 0, 0), new StreamKey(1, 0, 0));
    dashDownloader.download(progressListener);
    DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
    assertThat(openedDataSpecs.length).isEqualTo(8);
    assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
    assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
    assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
    assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("audio_segment_2");
    assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_3");
    assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("period_2_segment_1");
    assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("period_2_segment_2");
    assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("period_2_segment_3");
}
Also used : FakeDataSource(androidx.media3.test.utils.FakeDataSource) FakeDataSet(androidx.media3.test.utils.FakeDataSet) DataSpec(androidx.media3.datasource.DataSpec) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 2 with FakeDataSet

use of androidx.media3.test.utils.FakeDataSet in project media by androidx.

the class DashDownloaderTest method downloadRepresentation.

@Test
public void downloadRepresentation() 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);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    dashDownloader.download(progressListener);
    assertCachedData(cache, new RequestSet(fakeDataSet).useBoundedDataSpecFor("audio_init_data"));
}
Also used : RequestSet(androidx.media3.test.utils.CacheAsserts.RequestSet) FakeDataSet(androidx.media3.test.utils.FakeDataSet) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 3 with FakeDataSet

use of androidx.media3.test.utils.FakeDataSet in project media by androidx.

the class DashDownloaderTest method progressiveDownload.

@Test
public void progressiveDownload() 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);
    FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
    FakeDataSource.Factory factory = mock(FakeDataSource.Factory.class);
    when(factory.createDataSource()).thenReturn(fakeDataSource);
    DashDownloader dashDownloader = getDashDownloader(factory, new StreamKey(0, 0, 0), new StreamKey(0, 1, 0));
    dashDownloader.download(progressListener);
    DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
    assertThat(openedDataSpecs.length).isEqualTo(8);
    assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
    assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
    assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
    assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("text_segment_1");
    assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_2");
    assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("text_segment_2");
    assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("audio_segment_3");
    assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("text_segment_3");
}
Also used : FakeDataSource(androidx.media3.test.utils.FakeDataSource) FakeDataSet(androidx.media3.test.utils.FakeDataSet) DataSpec(androidx.media3.datasource.DataSpec) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 4 with FakeDataSet

use of androidx.media3.test.utils.FakeDataSet in project media by androidx.

the class DashDownloaderTest method representationWithoutIndex.

@Test
public void representationWithoutIndex() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD_NO_INDEX).setRandomData("test_segment_1", 4);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    try {
        dashDownloader.download(progressListener);
        fail();
    } catch (DownloadException e) {
    // Expected.
    }
    dashDownloader.remove();
    assertCacheEmpty(cache);
}
Also used : DownloadException(androidx.media3.exoplayer.offline.DownloadException) FakeDataSet(androidx.media3.test.utils.FakeDataSet) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 5 with FakeDataSet

use of androidx.media3.test.utils.FakeDataSet in project media by androidx.

the class DashDownloaderTest method downloadRepresentationFailure.

@Test
public void downloadRepresentationFailure() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).newData("audio_segment_2").appendReadData(TestUtil.buildTestData(2)).appendReadError(new IOException()).appendReadData(TestUtil.buildTestData(3)).endData().setRandomData("audio_segment_3", 6);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    try {
        dashDownloader.download(progressListener);
        fail();
    } catch (IOException e) {
    // Expected.
    }
    dashDownloader.download(progressListener);
    assertCachedData(cache, new RequestSet(fakeDataSet).useBoundedDataSpecFor("audio_init_data"));
}
Also used : RequestSet(androidx.media3.test.utils.CacheAsserts.RequestSet) FakeDataSet(androidx.media3.test.utils.FakeDataSet) IOException(java.io.IOException) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 FakeDataSet (androidx.media3.test.utils.FakeDataSet)23 DataSpec (androidx.media3.datasource.DataSpec)16 FakeDataSource (androidx.media3.test.utils.FakeDataSource)14 StreamKey (androidx.media3.common.StreamKey)11 Uri (android.net.Uri)6 IOException (java.io.IOException)6 RequestSet (androidx.media3.test.utils.CacheAsserts.RequestSet)5 CacheDataSource (androidx.media3.datasource.cache.CacheDataSource)4 DataSource (androidx.media3.datasource.DataSource)3 NoOpCacheEvictor (androidx.media3.datasource.cache.NoOpCacheEvictor)3 SimpleCache (androidx.media3.datasource.cache.SimpleCache)3 Before (org.junit.Before)3 MediaItem (androidx.media3.common.MediaItem)2 DefaultDownloadIndex (androidx.media3.exoplayer.offline.DefaultDownloadIndex)2 DefaultDownloaderFactory (androidx.media3.exoplayer.offline.DefaultDownloaderFactory)2 DownloadManager (androidx.media3.exoplayer.offline.DownloadManager)2 DummyMainThread (androidx.media3.test.utils.DummyMainThread)2 FailOnCloseDataSink (androidx.media3.test.utils.FailOnCloseDataSink)2 TestDownloadManagerListener (androidx.media3.test.utils.robolectric.TestDownloadManagerListener)2