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);
}
}
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);
}
}
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();
}
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);
}
}
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);
}
}
Aggregations