Search in sources :

Example 6 with FakeDataSet

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

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(androidx.media3.test.utils.CacheAsserts.RequestSet) FakeDataSet(androidx.media3.test.utils.FakeDataSet) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 7 with FakeDataSet

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

the class DashDownloaderTest method counters.

@Test
public void counters() 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) {
    // Failure expected after downloading init data, segment 1 and 2 bytes in segment 2.
    }
    progressListener.assertBytesDownloaded(10 + 4 + 2);
    dashDownloader.download(progressListener);
    progressListener.assertBytesDownloaded(10 + 4 + 5 + 6);
}
Also used : FakeDataSet(androidx.media3.test.utils.FakeDataSet) IOException(java.io.IOException) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 8 with FakeDataSet

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

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(androidx.media3.test.utils.FakeDataSet.FakeData.Segment) Test(org.junit.Test)

Example 9 with FakeDataSet

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

the class FakeDataSourceTest method testOpenSourceFailures.

@Test
public void testOpenSourceFailures() {
    // Empty data.
    FakeDataSource dataSource = new FakeDataSource(new FakeDataSet().newData(uri.toString()).endData());
    try {
        dataSource.open(new DataSpec(uri));
        fail("IOException expected.");
    } catch (IOException e) {
    // Expected.
    } finally {
        dataSource.close();
    }
    // Non-existent data
    dataSource = new FakeDataSource(new FakeDataSet());
    try {
        dataSource.open(new DataSpec(uri));
        fail("IOException expected.");
    } catch (IOException e) {
    // Expected.
    } finally {
        dataSource.close();
    }
}
Also used : DataSpec(androidx.media3.datasource.DataSpec) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with FakeDataSet

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

the class FakeDataSourceTest method testException.

@Test
public void testException() throws IOException {
    String errorMessage = "error, error, error";
    IOException exception = new IOException(errorMessage);
    FakeDataSource dataSource = new FakeDataSource(new FakeDataSet().newData(uri.toString()).appendReadData(TEST_DATA).appendReadError(exception).appendReadData(TEST_DATA).endData());
    assertThat(dataSource.open(new DataSpec(uri))).isEqualTo(30);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
    assertBuffer(TEST_DATA);
    try {
        dataSource.read(BUFFER, 0, BUFFER.length);
        fail("IOException expected.");
    } catch (IOException e) {
        assertThat(e).hasMessageThat().isEqualTo(errorMessage);
    }
    try {
        dataSource.read(BUFFER, 0, BUFFER.length);
        fail("IOException expected.");
    } catch (IOException e) {
        assertThat(e).hasMessageThat().isEqualTo(errorMessage);
    }
    dataSource.close();
    assertThat(dataSource.open(new DataSpec(uri, 15, 15))).isEqualTo(15);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
    assertBuffer(TEST_DATA);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
    dataSource.close();
}
Also used : DataSpec(androidx.media3.datasource.DataSpec) IOException(java.io.IOException) 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