Search in sources :

Example 96 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class DataSourceContractTest method getResponseHeaders_isEmptyWhileNotOpen.

@Test
public void getResponseHeaders_isEmptyWhileNotOpen() throws Exception {
    ImmutableList<TestResource> resources = getTestResources();
    Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
    for (int i = 0; i < resources.size(); i++) {
        additionalFailureInfo.setInfo(getFailureLabel(resources, i));
        TestResource resource = resources.get(i);
        DataSource dataSource = createDataSource();
        try {
            assertThat(dataSource.getResponseHeaders()).isEmpty();
            dataSource.open(new DataSpec(resource.getUri()));
        } finally {
            dataSource.close();
        }
        assertThat(dataSource.getResponseHeaders()).isEmpty();
        additionalFailureInfo.setInfo(null);
    }
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) DataSource(com.google.android.exoplayer2.upstream.DataSource) Test(org.junit.Test)

Example 97 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class DataSourceContractTest method unboundedDataSpec_readUntilEnd.

@Test
public void unboundedDataSpec_readUntilEnd() throws Exception {
    ImmutableList<TestResource> resources = getTestResources();
    Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
    for (int i = 0; i < resources.size(); i++) {
        additionalFailureInfo.setInfo(getFailureLabel(resources, i));
        TestResource resource = resources.get(i);
        DataSource dataSource = createDataSource();
        try {
            long length = dataSource.open(new DataSpec(resource.getUri()));
            byte[] data = unboundedReadsAreIndefinite() ? DataSourceUtil.readExactly(dataSource, resource.getExpectedBytes().length) : DataSourceUtil.readToEnd(dataSource);
            if (length != C.LENGTH_UNSET) {
                assertThat(length).isEqualTo(resource.getExpectedBytes().length);
            }
            assertThat(data).isEqualTo(resource.getExpectedBytes());
        } finally {
            dataSource.close();
        }
        additionalFailureInfo.setInfo(null);
    }
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) DataSource(com.google.android.exoplayer2.upstream.DataSource) Test(org.junit.Test)

Example 98 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class DataSourceContractTest method resourceNotFound.

@Test
public void resourceNotFound() throws Exception {
    DataSource dataSource = createDataSource();
    assertThrows(IOException.class, () -> dataSource.open(new DataSpec(getNotFoundUri())));
    dataSource.close();
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) DataSource(com.google.android.exoplayer2.upstream.DataSource) Test(org.junit.Test)

Example 99 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class DataSourceContractTest method getResponseHeaders_caseInsensitive.

@Test
public void getResponseHeaders_caseInsensitive() throws Exception {
    ImmutableList<TestResource> resources = getTestResources();
    Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
    for (int i = 0; i < resources.size(); i++) {
        additionalFailureInfo.setInfo(getFailureLabel(resources, i));
        TestResource resource = resources.get(i);
        DataSource dataSource = createDataSource();
        try {
            dataSource.open(new DataSpec(resource.getUri()));
            Map<String, List<String>> responseHeaders = dataSource.getResponseHeaders();
            for (String key : responseHeaders.keySet()) {
                String caseFlippedKey = invertAsciiCaseOfEveryOtherCharacter(key);
                assertWithMessage("key='%s', caseFlippedKey='%s'", key, caseFlippedKey).that(responseHeaders.get(caseFlippedKey)).isEqualTo(responseHeaders.get(key));
            }
        } finally {
            dataSource.close();
        }
        additionalFailureInfo.setInfo(null);
    }
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DataSource(com.google.android.exoplayer2.upstream.DataSource) Test(org.junit.Test)

Example 100 with DataSpec

use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.

the class DataSourceContractTest method dataSpecWithPositionAtEnd_readsZeroBytes.

@Test
public void dataSpecWithPositionAtEnd_readsZeroBytes() throws Exception {
    ImmutableList<TestResource> resources = getTestResources();
    Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
    for (int i = 0; i < resources.size(); i++) {
        additionalFailureInfo.setInfo(getFailureLabel(resources, i));
        TestResource resource = resources.get(i);
        int resourceLength = resource.getExpectedBytes().length;
        DataSource dataSource = createDataSource();
        DataSpec dataSpec = new DataSpec.Builder().setUri(resource.getUri()).setPosition(resourceLength).build();
        try {
            long length = dataSource.open(dataSpec);
            byte[] data = unboundedReadsAreIndefinite() ? Util.EMPTY_BYTE_ARRAY : DataSourceUtil.readToEnd(dataSource);
            // fewer bytes will be read in this case.
            if (length != C.LENGTH_UNSET) {
                assertThat(length).isEqualTo(0);
            }
            assertThat(data).isEmpty();
        } finally {
            dataSource.close();
        }
        additionalFailureInfo.setInfo(null);
    }
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) DataSource(com.google.android.exoplayer2.upstream.DataSource) Test(org.junit.Test)

Aggregations

DataSpec (com.google.android.exoplayer2.upstream.DataSpec)118 Test (org.junit.Test)79 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)28 DataSource (com.google.android.exoplayer2.upstream.DataSource)22 Uri (android.net.Uri)17 Nullable (androidx.annotation.Nullable)17 IOException (java.io.IOException)17 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)9 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)9 HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)8 ArrayList (java.util.ArrayList)7 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)6 InterruptedIOException (java.io.InterruptedIOException)5 List (java.util.List)5 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)4 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)4 DataSourceException (com.google.android.exoplayer2.upstream.DataSourceException)4 DataSourceInputStream (com.google.android.exoplayer2.upstream.DataSourceInputStream)4 HttpDataSource (com.google.android.exoplayer2.upstream.HttpDataSource)4 ByteBuffer (java.nio.ByteBuffer)4