Search in sources :

Example 16 with FakeDataSet

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

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(androidx.media3.datasource.DataSpec) Test(org.junit.Test)

Example 17 with FakeDataSet

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

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(androidx.media3.datasource.DataSpec) Test(org.junit.Test)

Example 18 with FakeDataSet

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

the class FakeDataSourceTest method testRunnable.

@Test
public void testRunnable() throws IOException {
    TestRunnable[] runnables = new TestRunnable[3];
    for (int i = 0; i < 3; i++) {
        runnables[i] = new TestRunnable();
    }
    FakeDataSource dataSource = new FakeDataSource(new FakeDataSet().newData(uri.toString()).appendReadData(TEST_DATA).appendReadAction(runnables[0]).appendReadData(TEST_DATA).appendReadAction(runnables[1]).appendReadAction(runnables[2]).appendReadData(TEST_DATA).endData());
    assertThat(dataSource.open(new DataSpec(uri))).isEqualTo(45);
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
    assertBuffer(TEST_DATA);
    for (int i = 0; i < 3; i++) {
        assertThat(runnables[i].ran).isFalse();
    }
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
    assertBuffer(TEST_DATA);
    assertThat(runnables[0].ran).isTrue();
    assertThat(runnables[1].ran).isFalse();
    assertThat(runnables[2].ran).isFalse();
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
    assertBuffer(TEST_DATA);
    for (int i = 0; i < 3; i++) {
        assertThat(runnables[i].ran).isTrue();
    }
    assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
    dataSource.close();
}
Also used : DataSpec(androidx.media3.datasource.DataSpec) Test(org.junit.Test)

Example 19 with FakeDataSet

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

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(androidx.media3.datasource.DataSpec) Test(org.junit.Test)

Example 20 with FakeDataSet

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

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(androidx.media3.datasource.DataSpec) 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