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
02719fd5
authored
Oct 13, 2021
by
olly
Committed by
Oliver Woodman
Oct 13, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Move test asset ContentProvider to testutil
PiperOrigin-RevId: 402772598
parent
91da6a34
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
15 deletions
library/core/src/androidTest/AndroidManifest.xml
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/ContentDataSourceContractTest.java
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/ContentDataSourceTest.java
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/TestContentProvider.java → testutils/src/main/java/com/google/android/exoplayer2/testutil/AssetContentProvider.java
library/core/src/androidTest/AndroidManifest.xml
View file @
02719fd5
...
@@ -27,8 +27,8 @@
...
@@ -27,8 +27,8 @@
tools:ignore=
"MissingApplicationIcon,HardcodedDebugMode"
tools:ignore=
"MissingApplicationIcon,HardcodedDebugMode"
android:usesCleartextTraffic=
"true"
>
android:usesCleartextTraffic=
"true"
>
<provider
<provider
android:authorities=
"com.google.android.exoplayer2.
core.test
"
android:authorities=
"com.google.android.exoplayer2.
testutil.AssetContentProvider
"
android:name=
"com.google.android.exoplayer2.
upstream.Tes
tContentProvider"
/>
android:name=
"com.google.android.exoplayer2.
testutil.Asse
tContentProvider"
/>
</application>
</application>
<instrumentation
<instrumentation
...
...
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/ContentDataSourceContractTest.java
View file @
02719fd5
...
@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.upstream;
...
@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.upstream;
import
android.net.Uri
;
import
android.net.Uri
;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.testutil.AssetContentProvider
;
import
com.google.android.exoplayer2.testutil.DataSourceContractTest
;
import
com.google.android.exoplayer2.testutil.DataSourceContractTest
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
...
@@ -41,18 +42,18 @@ public final class ContentDataSourceContractTest extends DataSourceContractTest
...
@@ -41,18 +42,18 @@ public final class ContentDataSourceContractTest extends DataSourceContractTest
return
ImmutableList
.
of
(
return
ImmutableList
.
of
(
new
TestResource
.
Builder
()
new
TestResource
.
Builder
()
.
setName
(
"simple (pipe=false)"
)
.
setName
(
"simple (pipe=false)"
)
.
setUri
(
Tes
tContentProvider
.
buildUri
(
DATA_PATH
,
/* pipeMode= */
false
))
.
setUri
(
Asse
tContentProvider
.
buildUri
(
DATA_PATH
,
/* pipeMode= */
false
))
.
setExpectedBytes
(
completeData
)
.
setExpectedBytes
(
completeData
)
.
build
(),
.
build
(),
new
TestResource
.
Builder
()
new
TestResource
.
Builder
()
.
setName
(
"simple (pipe=true)"
)
.
setName
(
"simple (pipe=true)"
)
.
setUri
(
Tes
tContentProvider
.
buildUri
(
DATA_PATH
,
/* pipeMode= */
true
))
.
setUri
(
Asse
tContentProvider
.
buildUri
(
DATA_PATH
,
/* pipeMode= */
true
))
.
setExpectedBytes
(
completeData
)
.
setExpectedBytes
(
completeData
)
.
build
());
.
build
());
}
}
@Override
@Override
protected
Uri
getNotFoundUri
()
{
protected
Uri
getNotFoundUri
()
{
return
Tes
tContentProvider
.
buildUri
(
"not/a/real/path"
,
/* pipeMode= */
false
);
return
Asse
tContentProvider
.
buildUri
(
"not/a/real/path"
,
/* pipeMode= */
false
);
}
}
}
}
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/ContentDataSourceTest.java
View file @
02719fd5
...
@@ -22,6 +22,7 @@ import android.net.Uri;
...
@@ -22,6 +22,7 @@ import android.net.Uri;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.testutil.AssetContentProvider
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -69,7 +70,7 @@ public final class ContentDataSourceTest {
...
@@ -69,7 +70,7 @@ public final class ContentDataSourceTest {
public
void
readInvalidUri
()
throws
Exception
{
public
void
readInvalidUri
()
throws
Exception
{
ContentDataSource
dataSource
=
ContentDataSource
dataSource
=
new
ContentDataSource
(
ApplicationProvider
.
getApplicationContext
());
new
ContentDataSource
(
ApplicationProvider
.
getApplicationContext
());
Uri
contentUri
=
Tes
tContentProvider
.
buildUri
(
"does/not.exist"
,
false
);
Uri
contentUri
=
Asse
tContentProvider
.
buildUri
(
"does/not.exist"
,
false
);
DataSpec
dataSpec
=
new
DataSpec
(
contentUri
);
DataSpec
dataSpec
=
new
DataSpec
(
contentUri
);
try
{
try
{
dataSource
.
open
(
dataSpec
);
dataSource
.
open
(
dataSpec
);
...
@@ -83,7 +84,7 @@ public final class ContentDataSourceTest {
...
@@ -83,7 +84,7 @@ public final class ContentDataSourceTest {
}
}
private
static
void
assertData
(
int
offset
,
int
length
,
boolean
pipeMode
)
throws
IOException
{
private
static
void
assertData
(
int
offset
,
int
length
,
boolean
pipeMode
)
throws
IOException
{
Uri
contentUri
=
Tes
tContentProvider
.
buildUri
(
DATA_PATH
,
pipeMode
);
Uri
contentUri
=
Asse
tContentProvider
.
buildUri
(
DATA_PATH
,
pipeMode
);
ContentDataSource
dataSource
=
ContentDataSource
dataSource
=
new
ContentDataSource
(
ApplicationProvider
.
getApplicationContext
());
new
ContentDataSource
(
ApplicationProvider
.
getApplicationContext
());
try
{
try
{
...
...
library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/Tes
tContentProvider.java
→
testutils/src/main/java/com/google/android/exoplayer2/testutil/Asse
tContentProvider.java
View file @
02719fd5
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
package
com
.
google
.
android
.
exoplayer2
.
testutil
;
import
android.content.ContentProvider
;
import
android.content.ContentProvider
;
import
android.content.ContentResolver
;
import
android.content.ContentResolver
;
...
@@ -26,16 +26,17 @@ import android.os.ParcelFileDescriptor;
...
@@ -26,16 +26,17 @@ import android.os.ParcelFileDescriptor;
import
android.system.ErrnoException
;
import
android.system.ErrnoException
;
import
android.system.OsConstants
;
import
android.system.OsConstants
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.
testutil.Test
Util
;
import
com.google.android.exoplayer2.
util.
Util
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
/** A {@link ContentProvider} for
tests of {@link ContentDataSource}
. */
/** A {@link ContentProvider} for
reading asset data
. */
public
final
class
Tes
tContentProvider
extends
ContentProvider
public
final
class
Asse
tContentProvider
extends
ContentProvider
implements
ContentProvider
.
PipeDataWriter
<
Object
>
{
implements
ContentProvider
.
PipeDataWriter
<
Object
>
{
private
static
final
String
AUTHORITY
=
"com.google.android.exoplayer2.core.test"
;
private
static
final
String
AUTHORITY
=
"com.google.android.exoplayer2.testutil.AssetContentProvider"
;
private
static
final
String
PARAM_PIPE_MODE
=
"pipe-mode"
;
private
static
final
String
PARAM_PIPE_MODE
=
"pipe-mode"
;
public
static
Uri
buildUri
(
String
filePath
,
boolean
pipeMode
)
{
public
static
Uri
buildUri
(
String
filePath
,
boolean
pipeMode
)
{
...
@@ -45,7 +46,7 @@ public final class TestContentProvider extends ContentProvider
...
@@ -45,7 +46,7 @@ public final class TestContentProvider extends ContentProvider
.
authority
(
AUTHORITY
)
.
authority
(
AUTHORITY
)
.
path
(
filePath
);
.
path
(
filePath
);
if
(
pipeMode
)
{
if
(
pipeMode
)
{
builder
.
appendQueryParameter
(
TestContentProvider
.
PARAM_PIPE_MODE
,
"1"
);
builder
.
appendQueryParameter
(
PARAM_PIPE_MODE
,
"1"
);
}
}
return
builder
.
build
();
return
builder
.
build
();
}
}
...
@@ -116,8 +117,7 @@ public final class TestContentProvider extends ContentProvider
...
@@ -116,8 +117,7 @@ public final class TestContentProvider extends ContentProvider
byte
[]
data
=
TestUtil
.
getByteArray
(
getContext
(),
getFileName
(
uri
));
byte
[]
data
=
TestUtil
.
getByteArray
(
getContext
(),
getFileName
(
uri
));
outputStream
.
write
(
data
);
outputStream
.
write
(
data
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
if
(
e
.
getCause
()
instanceof
ErrnoException
if
(
isBrokenPipe
(
e
))
{
&&
((
ErrnoException
)
e
.
getCause
()).
errno
==
OsConstants
.
EPIPE
)
{
// Swallow the exception if it's caused by a broken pipe - this indicates the reader has
// Swallow the exception if it's caused by a broken pipe - this indicates the reader has
// closed the pipe and is therefore no longer interested in the data being written.
// closed the pipe and is therefore no longer interested in the data being written.
// [See internal b/186728171].
// [See internal b/186728171].
...
@@ -130,4 +130,10 @@ public final class TestContentProvider extends ContentProvider
...
@@ -130,4 +130,10 @@ public final class TestContentProvider extends ContentProvider
private
static
String
getFileName
(
Uri
uri
)
{
private
static
String
getFileName
(
Uri
uri
)
{
return
uri
.
getPath
().
replaceFirst
(
"/"
,
""
);
return
uri
.
getPath
().
replaceFirst
(
"/"
,
""
);
}
}
private
static
boolean
isBrokenPipe
(
IOException
e
)
{
return
Util
.
SDK_INT
>=
21
&&
e
.
getCause
()
instanceof
ErrnoException
&&
((
ErrnoException
)
e
.
getCause
()).
errno
==
OsConstants
.
EPIPE
;
}
}
}
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