public class TestUtil extends Object
| Modifier and Type | Method | Description |
|---|---|---|
static void |
assertBitmapsAreSimilar(Bitmap expectedBitmap,
Bitmap actualBitmap,
double psnrThresholdDb) |
Asserts whether actual bitmap is very similar to the expected bitmap at some quality level.
|
static void |
assertBufferInfosEqual(MediaCodec.BufferInfo expected,
MediaCodec.BufferInfo actual) |
Returns whether two
BufferInfos are equal. |
static void |
assertDataSourceContent(DataSource dataSource,
DataSpec dataSpec,
byte[] expectedData,
boolean expectKnownLength) |
Asserts that data read from a
DataSource matches expected. |
static Uri |
buildAssetUri(String assetPath) |
Returns the
Uri for the given asset path. |
static byte[] |
buildTestData(int length) |
Equivalent to
buildTestData(length, length). |
static byte[] |
buildTestData(int length,
int seed) |
Generates an array of random bytes with the specified length.
|
static byte[] |
buildTestData(int length,
Random random) |
Generates an array of random bytes with the specified length.
|
static String |
buildTestString(int length,
Random random) |
Generates a random string with the specified length.
|
static byte[] |
createByteArray(int... bytes) |
Converts an array of integers in the range [0, 255] into an equivalent byte array.
|
static ImmutableList<Byte> |
createByteList(int... bytes) |
Converts an array of integers in the range [0, 255] into an equivalent byte list.
|
static MetadataInputBuffer |
createMetadataInputBuffer(byte[] data) |
|
static File |
createTestFile(File file,
long length) |
Writes test data with the specified length to the file and returns it.
|
static File |
createTestFile(File directory,
String name) |
Writes one byte long test data to the file and returns it.
|
static File |
createTestFile(File directory,
String name,
long length) |
Writes test data with the specified length to the file and returns it.
|
static FakeExtractorOutput |
extractAllSamplesFromFile(Extractor extractor,
Context context,
String fileName) |
Extracts all samples from the given file into a
FakeTrackOutput. |
static SeekMap |
extractSeekMap(Extractor extractor,
FakeExtractorOutput output,
DataSource dataSource,
Uri uri) |
|
static Bitmap |
getBitmap(Context context,
String fileName) |
Returns a
Bitmap read from an asset file. |
static byte[] |
getByteArray(Context context,
String fileName) |
Returns the bytes of an asset file.
|
static ExtractorInput |
getExtractorInputFromPosition(DataSource dataSource,
long position,
Uri uri) |
Returns an
ExtractorInput to read from the given input at given position. |
static DatabaseProvider |
getInMemoryDatabaseProvider() |
Returns a
DatabaseProvider that provides an in-memory database. |
static InputStream |
getInputStream(Context context,
String fileName) |
Returns an
InputStream for reading from an asset file. |
static String |
getString(Context context,
String fileName) |
Returns a
String read from an asset file. |
static int |
seekToTimeUs(Extractor extractor,
SeekMap seekMap,
long seekTimeUs,
DataSource dataSource,
FakeTrackOutput trackOutput,
Uri uri) |
Seeks to the given seek time of the stream from the given input, and keeps reading from the
input until we can extract at least one sample following the seek position, or until
end-of-input is reached.
|
public static byte[] buildTestData(int length)
buildTestData(length, length).length - The length of the array.public static byte[] buildTestData(int length,
int seed)
length - The length of the array.seed - A seed for an internally created source of randomness.public static byte[] buildTestData(int length,
Random random)
length - The length of the array.random - A source of randomness.public static String buildTestString(int length, Random random)
length - The length of the string.random - A source of randomness.public static byte[] createByteArray(int... bytes)
bytes - An array of integers, all of which must be in the range [0, 255].public static ImmutableList<Byte> createByteList(int... bytes)
bytes - An array of integers, all of which must be in the range [0, 255].public static File createTestFile(File directory, String name) throws IOException
IOExceptionpublic static File createTestFile(File directory, String name, long length) throws IOException
IOExceptionpublic static File createTestFile(File file, long length) throws IOException
IOExceptionpublic static byte[] getByteArray(Context context, String fileName) throws IOException
IOExceptionpublic static InputStream getInputStream(Context context, String fileName) throws IOException
InputStream for reading from an asset file.IOExceptionpublic static String getString(Context context, String fileName) throws IOException
String read from an asset file.IOExceptionpublic static Bitmap getBitmap(Context context, String fileName) throws IOException
Bitmap read from an asset file.IOExceptionpublic static DatabaseProvider getInMemoryDatabaseProvider()
DatabaseProvider that provides an in-memory database.public static void assertDataSourceContent(DataSource dataSource, DataSpec dataSpec, byte[] expectedData, boolean expectKnownLength) throws IOException
DataSource matches expected.dataSource - The DataSource through which to read.dataSpec - The DataSpec to use when opening the DataSource.expectedData - The expected data.expectKnownLength - Whether to assert that DataSource.open(com.google.android.exoplayer2.upstream.DataSpec) returns the expected
data length. If false then it's asserted that C.LENGTH_UNSET is returned.IOException - If an error occurs reading fom the DataSource.public static void assertBufferInfosEqual(MediaCodec.BufferInfo expected, MediaCodec.BufferInfo actual)
BufferInfos are equal.public static void assertBitmapsAreSimilar(Bitmap expectedBitmap, Bitmap actualBitmap, double psnrThresholdDb)
This is defined as their PSNR value is greater than or equal to the threshold. The higher the threshold, the more similar they are.
expectedBitmap - The expected bitmap.actualBitmap - The actual bitmap.psnrThresholdDb - The PSNR threshold (in dB), at or above which bitmaps are considered
very similar.public static Uri buildAssetUri(String assetPath)
Uri for the given asset path.public static SeekMap extractSeekMap(Extractor extractor, FakeExtractorOutput output, DataSource dataSource, Uri uri) throws IOException
Extractor, until it can produce the SeekMap and all of the track formats have been identified, or until the extractor encounters
EOF.extractor - The Extractor to extractor from input.output - The FakeTrackOutput to store the extracted SeekMap and track.dataSource - The DataSource that will be used to read from the input.uri - The Uri of the input.SeekMap.IOException - If an error occurred reading from the input, or if the extractor finishes
reading from input without extracting any SeekMap.public static FakeExtractorOutput extractAllSamplesFromFile(Extractor extractor, Context context, String fileName) throws IOException
FakeTrackOutput.extractor - The Extractor to extractor from input.context - A Context.fileName - The name of the input file.FakeTrackOutput containing the extracted samples.IOException - If an error occurred reading from the input, or if the extractor finishes
reading from input without extracting any SeekMap.public static int seekToTimeUs(Extractor extractor, SeekMap seekMap, long seekTimeUs, DataSource dataSource, FakeTrackOutput trackOutput, Uri uri) throws IOException
extractor - The Extractor to extract from input.seekMap - The SeekMap of the stream from the given input.seekTimeUs - The seek time, in micro-seconds.trackOutput - The FakeTrackOutput to store the extracted samples.dataSource - The DataSource that will be used to read from the input.uri - The Uri of the input.trackOutput after
the seek is completed, or C.INDEX_UNSET if the seek is completed without any
extracted sample.IOExceptionpublic static ExtractorInput getExtractorInputFromPosition(DataSource dataSource, long position, Uri uri) throws IOException
ExtractorInput to read from the given input at given position.IOExceptionpublic static MetadataInputBuffer createMetadataInputBuffer(byte[] data)