Search in sources :

Example 6 with FakeDataSet

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

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(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 7 with FakeDataSet

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

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(com.google.android.exoplayer2.offline.DownloadException) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 8 with FakeDataSet

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

the class HlsDownloaderTest method setUp.

@Before
public void setUp() throws Exception {
    tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    progressListener = new ProgressListener();
    fakeDataSet = new FakeDataSet().setData(MULTIVARIANT_PLAYLIST_URI, MULTIVARIANT_PLAYLIST_DATA).setData(MEDIA_PLAYLIST_1_URI, MEDIA_PLAYLIST_DATA).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence0.ts", 10).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence1.ts", 11).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence2.ts", 12).setData(MEDIA_PLAYLIST_2_URI, MEDIA_PLAYLIST_DATA).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence0.ts", 13).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence1.ts", 14).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence2.ts", 15);
}
Also used : SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) Before(org.junit.Before)

Example 9 with FakeDataSet

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

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(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 10 with FakeDataSet

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

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(com.google.android.exoplayer2.upstream.DataSpec) IOException(java.io.IOException) 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