docs/doc/reference/com/google/android/exoplayer2/testutil/DataSourceContractTest.html
Package com.google.android.exoplayer2.testutil
@RequiresApi(19)
public abstract classDataSourceContractTestextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")
A collection of contract tests for DataSource implementations.
Subclasses should only include the logic necessary to construct the DataSource and allow it to successfully read data. They shouldn't include any new @Test methods - implementation-specific tests should be in a separate class.
Most implementations should pass all these tests. If necessary, subclasses can disable tests by overriding the @Test method with a no-op implementation. It's recommended (but not required) to also annotate this @Ignore so that JUnit correctly reports the test as skipped/ignored instead of passing.
Nested Classes | Modifier and Type | Class | Description |
| --- | --- | --- |
| static class | DataSourceContractTest.FakeTransferListener |
A TransferListener that only keeps track of the transferred bytes.
|
| static class | DataSourceContractTest.TestResource |
Information about a resource that can be used to test the DataSource instance.
|
Fields | Modifier and Type | Field | Description |
| --- | --- | --- |
| AdditionalFailureInfo | additionalFailureInfo | |
Constructors | Constructor | Description |
| --- | --- |
| DataSourceContractTest() | |
All Methods Instance Methods Abstract Methods Concrete Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| protected abstract DataSource | createDataSource() |
Creates and returns an instance of the DataSource.
|
| void | dataSpecWithEndPositionOutOfRange_readsToEnd() | |
| void | dataSpecWithLength_readExpectedRange() | |
| void | dataSpecWithPosition_readUntilEnd() | |
| void | dataSpecWithPositionAndLength_readExpectedRange() | |
| void | dataSpecWithPositionAtEnd_readsZeroBytes() | |
| void | dataSpecWithPositionAtEndAndLength_readsZeroBytes() | |
| void | dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException() | |
| protected abstract Uri | getNotFoundUri() |
Returns a Uri that doesn't resolve.
|
| void | getResponseHeaders_caseInsensitive() | |
| void | getResponseHeaders_isEmptyWhileNotOpen() | |
| void | getResponseHeaders_noNullKeysOrValues() | |
| void | getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen() | |
| protected abstract ImmutableList<DataSourceContractTest.TestResource> | getTestResources() |
Returns DataSourceContractTest.TestResource instances.
|
| protected DataSource | getTransferListenerDataSource() |
Returns the DataSource that will be included in the TransferListener callbacks for the DataSource most recently created by createDataSource().
|
| void | getUri_resourceNotFound_returnsNullIfNotOpened() | |
| void | getUri_returnsNonNullValueOnlyWhileOpen() | |
| void | resourceNotFound() | |
| void | resourceNotFound_transferListenerCallbacks() | |
| void | transferListenerCallbacks() | |
| void | unboundedDataSpec_readUntilEnd() | |
| void | unboundedDataSpecWithGzipFlag_readUntilEnd() |
DataSpec.FLAG_ALLOW_GZIP should either be ignored by DataSource implementations, or correctly handled (i.e.
|
| protected boolean | unboundedReadsAreIndefinite() |
Returns whether the DataSource will continue reading indefinitely for unbounded DataSpecs.
|
| void | uriSchemeIsCaseInsensitive() | |
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
public final[AdditionalFailureInfo](AdditionalFailureInfo.html "class in com.google.android.exoplayer2.testutil")additionalFailureInfo
-
public DataSourceContractTest()
-
protected abstract[DataSource](../upstream/DataSource.html "interface in com.google.android.exoplayer2.upstream")createDataSource()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Creates and returns an instance of the DataSource.
Throws:Exception
-
@Nullable
protected[DataSource](../upstream/DataSource.html "interface in com.google.android.exoplayer2.upstream")getTransferListenerDataSource()
Returns the DataSource that will be included in the TransferListener callbacks for the DataSource most recently created by createDataSource(). If it's the same DataSource then null can be returned.
-
protected boolean unboundedReadsAreIndefinite()
Returns whether the DataSource will continue reading indefinitely for unbounded DataSpecs.
-
protected abstract[ImmutableList](https://guava.dev/releases/31.1-android/api/docs/com/google/common/collect/ImmutableList.html?is-external=true "class or interface in com.google.common.collect")<[DataSourceContractTest.TestResource](DataSourceContractTest.TestResource.html "class in com.google.android.exoplayer2.testutil")> getTestResources()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Returns DataSourceContractTest.TestResource instances.
Each resource will be used to exercise the DataSource instance, allowing different behaviours to be tested.
If multiple resources are returned, it's recommended to disambiguate them using DataSourceContractTest.TestResource.Builder.setName(String).
Throws:Exception
-
protected abstract[Uri](https://developer.android.com/reference/android/net/Uri.html "class or interface in android.net")getNotFoundUri()
Returns a Uri that doesn't resolve.
This is used to test how a DataSource handles nonexistent data.
-
public void unboundedDataSpec_readUntilEnd()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void dataSpecWithPosition_readUntilEnd()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void dataSpecWithLength_readExpectedRange()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void dataSpecWithPositionAndLength_readExpectedRange()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void dataSpecWithPositionAtEnd_readsZeroBytes()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void dataSpecWithPositionAtEndAndLength_readsZeroBytes()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void dataSpecWithEndPositionOutOfRange_readsToEnd()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void unboundedDataSpecWithGzipFlag_readUntilEnd()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
DataSpec.FLAG_ALLOW_GZIP should either be ignored by DataSource implementations, or correctly handled (i.e. the data is decompressed before being returned from DataReader.read(byte[], int, int)).
Throws:Exception
-
public void uriSchemeIsCaseInsensitive()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void resourceNotFound()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void transferListenerCallbacks()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void resourceNotFound_transferListenerCallbacks()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void getUri_returnsNonNullValueOnlyWhileOpen()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void getUri_resourceNotFound_returnsNullIfNotOpened()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void getResponseHeaders_noNullKeysOrValues()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void getResponseHeaders_caseInsensitive()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void getResponseHeaders_isEmptyWhileNotOpen()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception
-
public void getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen()
throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")
Throws:Exception