Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4570cd37
authored
Nov 06, 2019
by
olly
Committed by
Oliver Woodman
Nov 15, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Testutils: Add missing Javadoc + Misc cleanup
PiperOrigin-RevId: 278835106
parent
0a27d7b4
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
100 additions
and
35 deletions
library/core/src/test/java/com/google/android/exoplayer2/database/VersionTableTest.java
library/core/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorTest.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndexTest.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CachedRegionTrackerTest.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/SimpleCacheSpanTest.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/SimpleCacheTest.java
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DownloadManagerDashTest.java
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DownloadServiceDashTest.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/ExtractorAsserts.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/TestUtil.java
library/core/src/test/java/com/google/android/exoplayer2/database/VersionTableTest.java
View file @
4570cd37
...
...
@@ -38,7 +38,7 @@ public class VersionTableTest {
@Before
public
void
setUp
()
{
databaseProvider
=
TestUtil
.
get
Test
DatabaseProvider
();
databaseProvider
=
TestUtil
.
get
InMemory
DatabaseProvider
();
database
=
databaseProvider
.
getWritableDatabase
();
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorTest.java
View file @
4570cd37
...
...
@@ -15,7 +15,6 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
extractor
.
ogg
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.testutil.ExtractorAsserts
;
...
...
@@ -59,7 +58,7 @@ public final class OggExtractorTest {
OggTestData
.
buildOggHeader
(
0x02
,
0
,
1000
,
1
),
TestUtil
.
createByteArray
(
7
),
// Laces
new
byte
[]
{
0x01
,
'v'
,
'o'
,
'r'
,
'b'
,
'i'
,
's'
});
assert
That
(
sniff
(
data
)).
isTrue
(
);
assert
Sniff
(
data
,
/* expectedResult= */
true
);
}
@Test
...
...
@@ -69,7 +68,7 @@ public final class OggExtractorTest {
OggTestData
.
buildOggHeader
(
0x02
,
0
,
1000
,
1
),
TestUtil
.
createByteArray
(
5
),
// Laces
new
byte
[]
{
0x7F
,
'F'
,
'L'
,
'A'
,
'C'
});
assert
That
(
sniff
(
data
)).
isTrue
(
);
assert
Sniff
(
data
,
/* expectedResult= */
true
);
}
@Test
...
...
@@ -77,13 +76,13 @@ public final class OggExtractorTest {
byte
[]
data
=
TestUtil
.
joinByteArrays
(
OggTestData
.
buildOggHeader
(
0x02
,
0
,
1000
,
0x00
),
new
byte
[]
{
'O'
,
'p'
,
'u'
,
's'
});
assert
That
(
sniff
(
data
)).
isFalse
(
);
assert
Sniff
(
data
,
/* expectedResult= */
false
);
}
@Test
public
void
testSniffFailsInvalidOggHeader
()
throws
Exception
{
byte
[]
data
=
OggTestData
.
buildOggHeader
(
0x00
,
0
,
1000
,
0x00
);
assert
That
(
sniff
(
data
)).
isFalse
(
);
assert
Sniff
(
data
,
/* expectedResult= */
false
);
}
@Test
...
...
@@ -93,16 +92,17 @@ public final class OggExtractorTest {
OggTestData
.
buildOggHeader
(
0x02
,
0
,
1000
,
1
),
TestUtil
.
createByteArray
(
7
),
// Laces
new
byte
[]
{
0x7F
,
'X'
,
'o'
,
'r'
,
'b'
,
'i'
,
's'
});
assert
That
(
sniff
(
data
)).
isFalse
(
);
assert
Sniff
(
data
,
/* expectedResult= */
false
);
}
@Test
public
void
testSniffFailsEOF
()
throws
Exception
{
byte
[]
data
=
OggTestData
.
buildOggHeader
(
0x02
,
0
,
1000
,
0x00
);
assert
That
(
sniff
(
data
)).
isFalse
(
);
assert
Sniff
(
data
,
/* expectedResult= */
false
);
}
private
boolean
sniff
(
byte
[]
data
)
throws
InterruptedException
,
IOException
{
private
void
assertSniff
(
byte
[]
data
,
boolean
expectedResult
)
throws
InterruptedException
,
IOException
{
FakeExtractorInput
input
=
new
FakeExtractorInput
.
Builder
()
.
setData
(
data
)
...
...
@@ -110,6 +110,6 @@ public final class OggExtractorTest {
.
setSimulateUnknownLength
(
true
)
.
setSimulatePartialReads
(
true
)
.
build
();
return
TestUtil
.
sniffTestData
(
OGG_EXTRACTOR_FACTORY
.
create
(),
inpu
t
);
ExtractorAsserts
.
assertSniff
(
OGG_EXTRACTOR_FACTORY
.
create
(),
input
,
expectedResul
t
);
}
}
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
View file @
4570cd37
...
...
@@ -81,7 +81,7 @@ public class DownloadManagerTest {
uri2
=
Uri
.
parse
(
"http://abc.com/media2"
);
uri3
=
Uri
.
parse
(
"http://abc.com/media3"
);
dummyMainThread
=
new
DummyMainThread
();
downloadIndex
=
new
DefaultDownloadIndex
(
TestUtil
.
get
Test
DatabaseProvider
());
downloadIndex
=
new
DefaultDownloadIndex
(
TestUtil
.
get
InMemory
DatabaseProvider
());
downloaderFactory
=
new
FakeDownloaderFactory
();
setUpDownloadManager
(
100
);
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndexTest.java
View file @
4570cd37
...
...
@@ -334,7 +334,7 @@ public class CachedContentIndexTest {
}
private
CachedContentIndex
newInstance
()
{
return
new
CachedContentIndex
(
TestUtil
.
get
Test
DatabaseProvider
());
return
new
CachedContentIndex
(
TestUtil
.
get
InMemory
DatabaseProvider
());
}
private
CachedContentIndex
newLegacyInstance
()
{
...
...
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CachedRegionTrackerTest.java
View file @
4570cd37
...
...
@@ -66,7 +66,7 @@ public final class CachedRegionTrackerTest {
tracker
=
new
CachedRegionTracker
(
cache
,
CACHE_KEY
,
CHUNK_INDEX
);
cacheDir
=
Util
.
createTempDirectory
(
ApplicationProvider
.
getApplicationContext
(),
"ExoPlayerTest"
);
index
=
new
CachedContentIndex
(
TestUtil
.
get
Test
DatabaseProvider
());
index
=
new
CachedContentIndex
(
TestUtil
.
get
InMemory
DatabaseProvider
());
}
@After
...
...
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/SimpleCacheSpanTest.java
View file @
4570cd37
...
...
@@ -51,7 +51,7 @@ public class SimpleCacheSpanTest {
public
void
setUp
()
throws
Exception
{
cacheDir
=
Util
.
createTempDirectory
(
ApplicationProvider
.
getApplicationContext
(),
"ExoPlayerTest"
);
index
=
new
CachedContentIndex
(
TestUtil
.
get
Test
DatabaseProvider
());
index
=
new
CachedContentIndex
(
TestUtil
.
get
InMemory
DatabaseProvider
());
}
@After
...
...
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/SimpleCacheTest.java
View file @
4570cd37
...
...
@@ -322,7 +322,7 @@ public class SimpleCacheTest {
@Test
public
void
testExceptionDuringEvictionByLeastRecentlyUsedCacheEvictorNotHang
()
throws
Exception
{
CachedContentIndex
contentIndex
=
Mockito
.
spy
(
new
CachedContentIndex
(
TestUtil
.
get
Test
DatabaseProvider
()));
Mockito
.
spy
(
new
CachedContentIndex
(
TestUtil
.
get
InMemory
DatabaseProvider
()));
SimpleCache
simpleCache
=
new
SimpleCache
(
cacheDir
,
new
LeastRecentlyUsedCacheEvictor
(
20
),
contentIndex
,
/* fileIndex= */
null
);
...
...
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DownloadManagerDashTest.java
View file @
4570cd37
...
...
@@ -97,7 +97,7 @@ public class DownloadManagerDashTest {
fakeStreamKey1
=
new
StreamKey
(
0
,
0
,
0
);
fakeStreamKey2
=
new
StreamKey
(
0
,
1
,
0
);
downloadIndex
=
new
DefaultDownloadIndex
(
TestUtil
.
get
Test
DatabaseProvider
());
downloadIndex
=
new
DefaultDownloadIndex
(
TestUtil
.
get
InMemory
DatabaseProvider
());
createDownloadManager
();
}
...
...
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DownloadServiceDashTest.java
View file @
4570cd37
...
...
@@ -112,7 +112,7 @@ public class DownloadServiceDashTest {
dummyMainThread
.
runTestOnMainThread
(
()
->
{
DefaultDownloadIndex
downloadIndex
=
new
DefaultDownloadIndex
(
TestUtil
.
get
Test
DatabaseProvider
());
new
DefaultDownloadIndex
(
TestUtil
.
get
InMemory
DatabaseProvider
());
final
DownloadManager
dashDownloadManager
=
new
DownloadManager
(
ApplicationProvider
.
getApplicationContext
(),
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java
View file @
4570cd37
...
...
@@ -467,6 +467,7 @@ public final class ActionSchedule {
return
apply
(
new
ThrowPlaybackException
(
tag
,
exception
));
}
/** Builds the schedule. */
public
ActionSchedule
build
()
{
CallbackAction
callbackAction
=
new
CallbackAction
(
tag
);
apply
(
callbackAction
);
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/ExtractorAsserts.java
View file @
4570cd37
...
...
@@ -46,6 +46,29 @@ public final class ExtractorAsserts {
private
static
final
String
UNKNOWN_LENGTH_EXTENSION
=
".unklen"
+
DUMP_EXTENSION
;
/**
* Asserts that {@link Extractor#sniff(ExtractorInput)} returns the {@code expectedResult} for a
* given {@code input}, retrying repeatedly when {@link SimulatedIOException} is thrown.
*
* @param extractor The extractor to test.
* @param input The extractor input.
* @param expectedResult The expected return value.
* @throws IOException If reading from the input fails.
* @throws InterruptedException If interrupted while reading from the input.
*/
public
static
void
assertSniff
(
Extractor
extractor
,
FakeExtractorInput
input
,
boolean
expectedResult
)
throws
IOException
,
InterruptedException
{
while
(
true
)
{
try
{
assertThat
(
extractor
.
sniff
(
input
)).
isEqualTo
(
expectedResult
);
return
;
}
catch
(
SimulatedIOException
e
)
{
// Ignore.
}
}
}
/**
* Asserts that an extractor behaves correctly given valid input data. Can only be used from
* Robolectric tests.
*
...
...
@@ -164,7 +187,7 @@ public final class ExtractorAsserts {
.
setSimulatePartialReads
(
simulatePartialReads
).
build
();
if
(
sniffFirst
)
{
assert
That
(
TestUtil
.
sniffTestData
(
extractor
,
input
)).
isTrue
(
);
assert
Sniff
(
extractor
,
input
,
/* expectedResult= */
true
);
input
.
resetPeekPosition
();
}
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/TestUtil.java
View file @
4570cd37
...
...
@@ -33,7 +33,6 @@ import com.google.android.exoplayer2.extractor.Extractor;
import
com.google.android.exoplayer2.extractor.ExtractorInput
;
import
com.google.android.exoplayer2.extractor.PositionHolder
;
import
com.google.android.exoplayer2.extractor.SeekMap
;
import
com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.util.Assertions
;
...
...
@@ -50,17 +49,14 @@ public class TestUtil {
private
TestUtil
()
{}
public
static
boolean
sniffTestData
(
Extractor
extractor
,
FakeExtractorInput
input
)
throws
IOException
,
InterruptedException
{
while
(
true
)
{
try
{
return
extractor
.
sniff
(
input
);
}
catch
(
SimulatedIOException
e
)
{
// Ignore.
}
}
}
/**
* Given an open {@link DataSource}, repeatedly calls {@link DataSource#read(byte[], int, int)}
* until {@link C#RESULT_END_OF_INPUT} is returned.
*
* @param dataSource The source from which to read.
* @return The concatenation of all read data.
* @throws IOException If an error occurs reading from the source.
*/
public
static
byte
[]
readToEnd
(
DataSource
dataSource
)
throws
IOException
{
byte
[]
data
=
new
byte
[
1024
];
int
position
=
0
;
...
...
@@ -77,6 +73,14 @@ public class TestUtil {
return
Arrays
.
copyOf
(
data
,
position
);
}
/**
* Given an open {@link DataSource}, repeatedly calls {@link DataSource#read(byte[], int, int)}
* until exactly {@code length} bytes have been read.
*
* @param dataSource The source from which to read.
* @return The read data.
* @throws IOException If an error occurs reading from the source.
*/
public
static
byte
[]
readExactly
(
DataSource
dataSource
,
int
length
)
throws
IOException
{
byte
[]
data
=
new
byte
[
length
];
int
position
=
0
;
...
...
@@ -91,22 +95,49 @@ public class TestUtil {
return
data
;
}
/**
* Equivalent to {@code buildTestData(length, length)}.
*
* @param length The length of the array.
* @return The generated array.
*/
public
static
byte
[]
buildTestData
(
int
length
)
{
return
buildTestData
(
length
,
length
);
}
/**
* Generates an array of random bytes with the specified length.
*
* @param length The length of the array.
* @param seed A seed for an internally created {@link Random source of randomness}.
* @return The generated array.
*/
public
static
byte
[]
buildTestData
(
int
length
,
int
seed
)
{
return
buildTestData
(
length
,
new
Random
(
seed
));
}
/**
* Generates an array of random bytes with the specified length.
*
* @param length The length of the array.
* @param random A source of randomness.
* @return The generated array.
*/
public
static
byte
[]
buildTestData
(
int
length
,
Random
random
)
{
byte
[]
source
=
new
byte
[
length
];
random
.
nextBytes
(
source
);
return
source
;
}
public
static
String
buildTestString
(
int
maxLength
,
Random
random
)
{
int
length
=
random
.
nextInt
(
maxLength
);
/**
* Generates a random string with the specified maximum length.
*
* @param maximumLength The maximum length of the string.
* @param random A source of randomness.
* @return The generated string.
*/
public
static
String
buildTestString
(
int
maximumLength
,
Random
random
)
{
int
length
=
random
.
nextInt
(
maximumLength
);
StringBuilder
builder
=
new
StringBuilder
(
length
);
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
builder
.
append
((
char
)
random
.
nextInt
());
...
...
@@ -129,6 +160,12 @@ public class TestUtil {
return
byteArray
;
}
/**
* Concatenates the provided byte arrays.
*
* @param byteArrays The byte arrays to concatenate.
* @return The concatenated result.
*/
public
static
byte
[]
joinByteArrays
(
byte
[]...
byteArrays
)
{
int
length
=
0
;
for
(
byte
[]
byteArray
:
byteArrays
)
{
...
...
@@ -143,24 +180,28 @@ public class TestUtil {
return
joined
;
}
/** Returns the bytes of an asset file. */
public
static
byte
[]
getByteArray
(
Context
context
,
String
fileName
)
throws
IOException
{
return
Util
.
toByteArray
(
getInputStream
(
context
,
fileName
));
}
/** Returns an {@link InputStream} for reading from an asset file. */
public
static
InputStream
getInputStream
(
Context
context
,
String
fileName
)
throws
IOException
{
return
context
.
getResources
().
getAssets
().
open
(
fileName
);
}
/** Returns a {@link String} read from an asset file. */
public
static
String
getString
(
Context
context
,
String
fileName
)
throws
IOException
{
return
Util
.
fromUtf8Bytes
(
getByteArray
(
context
,
fileName
));
}
public
static
Bitmap
readBitmapFromFile
(
Context
context
,
String
fileName
)
throws
IOException
{
/** Returns a {@link Bitmap} read from an asset file. */
public
static
Bitmap
getBitmap
(
Context
context
,
String
fileName
)
throws
IOException
{
return
BitmapFactory
.
decodeStream
(
getInputStream
(
context
,
fileName
));
}
public
static
DatabaseProvider
getTestDatabaseProvider
()
{
// Provides an in-memory database.
/** Returns a {@link DatabaseProvider} that provides an in-memory database. */
public
static
DatabaseProvider
getInMemoryDatabaseProvider
()
{
return
new
DefaultDatabaseProvider
(
new
SQLiteOpenHelper
(
/* context= */
null
,
/* name= */
null
,
/* factory= */
null
,
/* version= */
1
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment