Back to Exoplayer

DataSourceContractTest (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/testutil/DataSourceContractTest.html

latest14.7 KB
Original Source

Package com.google.android.exoplayer2.testutil

Class DataSourceContractTest

  • java.lang.Object

    • com.google.android.exoplayer2.testutil.DataSourceContractTest

@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 Class Summary

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. |

Field Summary

Fields | Modifier and Type | Field | Description | | --- | --- | --- | | AdditionalFailureInfo | additionalFailureInfo | |

Constructor Summary

Constructors | Constructor | Description | | --- | --- | | DataSourceContractTest() | |

Method Summary

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() | |

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

- 

additionalFailureInfo

public final[AdditionalFailureInfo](AdditionalFailureInfo.html "class in com.google.android.exoplayer2.testutil")additionalFailureInfo

Constructor Detail

- 

DataSourceContractTest

public DataSourceContractTest()

Method Detail

- 

createDataSource

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

- 

getTransferListenerDataSource

@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.

- 

unboundedReadsAreIndefinite

protected boolean unboundedReadsAreIndefinite()

Returns whether the DataSource will continue reading indefinitely for unbounded DataSpecs.

- 

getTestResources

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

- 

getNotFoundUri

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.

- 

unboundedDataSpec_readUntilEnd

public void unboundedDataSpec_readUntilEnd()
                                    throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

dataSpecWithPosition_readUntilEnd

public void dataSpecWithPosition_readUntilEnd()
                                       throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

dataSpecWithLength_readExpectedRange

public void dataSpecWithLength_readExpectedRange()
                                          throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

dataSpecWithPositionAndLength_readExpectedRange

public void dataSpecWithPositionAndLength_readExpectedRange()
                                                     throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

dataSpecWithPositionAtEnd_readsZeroBytes

public void dataSpecWithPositionAtEnd_readsZeroBytes()
                                              throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

dataSpecWithPositionAtEndAndLength_readsZeroBytes

public void dataSpecWithPositionAtEndAndLength_readsZeroBytes()
                                                       throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException

public void dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException()
                                                                      throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

dataSpecWithEndPositionOutOfRange_readsToEnd

public void dataSpecWithEndPositionOutOfRange_readsToEnd()
                                                  throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

unboundedDataSpecWithGzipFlag_readUntilEnd

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

- 

uriSchemeIsCaseInsensitive

public void uriSchemeIsCaseInsensitive()
                                throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

resourceNotFound

public void resourceNotFound()
                      throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

transferListenerCallbacks

public void transferListenerCallbacks()
                               throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

resourceNotFound_transferListenerCallbacks

public void resourceNotFound_transferListenerCallbacks()
                                                throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

getUri_returnsNonNullValueOnlyWhileOpen

public void getUri_returnsNonNullValueOnlyWhileOpen()
                                             throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

getUri_resourceNotFound_returnsNullIfNotOpened

public void getUri_resourceNotFound_returnsNullIfNotOpened()
                                                    throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

getResponseHeaders_noNullKeysOrValues

public void getResponseHeaders_noNullKeysOrValues()
                                           throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

getResponseHeaders_caseInsensitive

public void getResponseHeaders_caseInsensitive()
                                        throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

getResponseHeaders_isEmptyWhileNotOpen

public void getResponseHeaders_isEmptyWhileNotOpen()
                                            throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception

- 

getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen

public void getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen()
                                                             throws[Exception](https://developer.android.com/reference/java/lang/Exception.html "class or interface in java.lang")

Throws:Exception