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
811cdf06
authored
May 30, 2019
by
eguven
Committed by
Oliver Woodman
May 31, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Modify DashDownloaderTest to test if content length is stored
PiperOrigin-RevId: 250655481
parent
bbf8a9ac
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
53 deletions
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DashDownloaderTest.java
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DownloadManagerDashTest.java
library/hls/src/test/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloaderTest.java
testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/CacheAsserts.java
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DashDownloaderTest.java
View file @
811cdf06
...
@@ -35,6 +35,7 @@ import com.google.android.exoplayer2.offline.Downloader;
...
@@ -35,6 +35,7 @@ import com.google.android.exoplayer2.offline.Downloader;
import
com.google.android.exoplayer2.offline.DownloaderConstructorHelper
;
import
com.google.android.exoplayer2.offline.DownloaderConstructorHelper
;
import
com.google.android.exoplayer2.offline.DownloaderFactory
;
import
com.google.android.exoplayer2.offline.DownloaderFactory
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet
;
import
com.google.android.exoplayer2.testutil.FakeDataSet
;
import
com.google.android.exoplayer2.testutil.FakeDataSet
;
import
com.google.android.exoplayer2.testutil.FakeDataSource
;
import
com.google.android.exoplayer2.testutil.FakeDataSource
;
import
com.google.android.exoplayer2.testutil.FakeDataSource.Factory
;
import
com.google.android.exoplayer2.testutil.FakeDataSource.Factory
;
...
@@ -108,7 +109,7 @@ public class DashDownloaderTest {
...
@@ -108,7 +109,7 @@ public class DashDownloaderTest {
DashDownloader
dashDownloader
=
getDashDownloader
(
fakeDataSet
,
new
StreamKey
(
0
,
0
,
0
));
DashDownloader
dashDownloader
=
getDashDownloader
(
fakeDataSet
,
new
StreamKey
(
0
,
0
,
0
));
dashDownloader
.
download
(
progressListener
);
dashDownloader
.
download
(
progressListener
);
assertCachedData
(
cache
,
fakeDataSet
);
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
).
useBoundedDataSpecFor
(
"audio_init_data"
)
);
}
}
@Test
@Test
...
@@ -127,7 +128,7 @@ public class DashDownloaderTest {
...
@@ -127,7 +128,7 @@ public class DashDownloaderTest {
DashDownloader
dashDownloader
=
getDashDownloader
(
fakeDataSet
,
new
StreamKey
(
0
,
0
,
0
));
DashDownloader
dashDownloader
=
getDashDownloader
(
fakeDataSet
,
new
StreamKey
(
0
,
0
,
0
));
dashDownloader
.
download
(
progressListener
);
dashDownloader
.
download
(
progressListener
);
assertCachedData
(
cache
,
fakeDataSet
);
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
).
useBoundedDataSpecFor
(
"audio_init_data"
)
);
}
}
@Test
@Test
...
@@ -146,7 +147,7 @@ public class DashDownloaderTest {
...
@@ -146,7 +147,7 @@ public class DashDownloaderTest {
DashDownloader
dashDownloader
=
DashDownloader
dashDownloader
=
getDashDownloader
(
fakeDataSet
,
new
StreamKey
(
0
,
0
,
0
),
new
StreamKey
(
0
,
1
,
0
));
getDashDownloader
(
fakeDataSet
,
new
StreamKey
(
0
,
0
,
0
),
new
StreamKey
(
0
,
1
,
0
));
dashDownloader
.
download
(
progressListener
);
dashDownloader
.
download
(
progressListener
);
assertCachedData
(
cache
,
fakeDataSet
);
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
).
useBoundedDataSpecFor
(
"audio_init_data"
)
);
}
}
@Test
@Test
...
@@ -167,7 +168,7 @@ public class DashDownloaderTest {
...
@@ -167,7 +168,7 @@ public class DashDownloaderTest {
DashDownloader
dashDownloader
=
getDashDownloader
(
fakeDataSet
);
DashDownloader
dashDownloader
=
getDashDownloader
(
fakeDataSet
);
dashDownloader
.
download
(
progressListener
);
dashDownloader
.
download
(
progressListener
);
assertCachedData
(
cache
,
fakeDataSet
);
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
).
useBoundedDataSpecFor
(
"audio_init_data"
)
);
}
}
@Test
@Test
...
@@ -256,7 +257,7 @@ public class DashDownloaderTest {
...
@@ -256,7 +257,7 @@ public class DashDownloaderTest {
// Expected.
// Expected.
}
}
dashDownloader
.
download
(
progressListener
);
dashDownloader
.
download
(
progressListener
);
assertCachedData
(
cache
,
fakeDataSet
);
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
).
useBoundedDataSpecFor
(
"audio_init_data"
)
);
}
}
@Test
@Test
...
...
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DownloadManagerDashTest.java
View file @
811cdf06
...
@@ -33,6 +33,7 @@ import com.google.android.exoplayer2.offline.DownloadRequest;
...
@@ -33,6 +33,7 @@ import com.google.android.exoplayer2.offline.DownloadRequest;
import
com.google.android.exoplayer2.offline.DownloaderConstructorHelper
;
import
com.google.android.exoplayer2.offline.DownloaderConstructorHelper
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.scheduler.Requirements
;
import
com.google.android.exoplayer2.scheduler.Requirements
;
import
com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet
;
import
com.google.android.exoplayer2.testutil.DummyMainThread
;
import
com.google.android.exoplayer2.testutil.DummyMainThread
;
import
com.google.android.exoplayer2.testutil.DummyMainThread.TestRunnable
;
import
com.google.android.exoplayer2.testutil.DummyMainThread.TestRunnable
;
import
com.google.android.exoplayer2.testutil.FakeDataSet
;
import
com.google.android.exoplayer2.testutil.FakeDataSet
;
...
@@ -154,7 +155,7 @@ public class DownloadManagerDashTest {
...
@@ -154,7 +155,7 @@ public class DownloadManagerDashTest {
public
void
testHandleDownloadRequest
()
throws
Throwable
{
public
void
testHandleDownloadRequest
()
throws
Throwable
{
handleDownloadRequest
(
fakeStreamKey1
,
fakeStreamKey2
);
handleDownloadRequest
(
fakeStreamKey1
,
fakeStreamKey2
);
blockUntilTasksCompleteAndThrowAnyDownloadError
();
blockUntilTasksCompleteAndThrowAnyDownloadError
();
assertCachedData
(
cache
,
fakeDataSet
);
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
).
useBoundedDataSpecFor
(
"audio_init_data"
)
);
}
}
@Test
@Test
...
@@ -162,7 +163,7 @@ public class DownloadManagerDashTest {
...
@@ -162,7 +163,7 @@ public class DownloadManagerDashTest {
handleDownloadRequest
(
fakeStreamKey1
);
handleDownloadRequest
(
fakeStreamKey1
);
handleDownloadRequest
(
fakeStreamKey2
);
handleDownloadRequest
(
fakeStreamKey2
);
blockUntilTasksCompleteAndThrowAnyDownloadError
();
blockUntilTasksCompleteAndThrowAnyDownloadError
();
assertCachedData
(
cache
,
fakeDataSet
);
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
).
useBoundedDataSpecFor
(
"audio_init_data"
)
);
}
}
@Test
@Test
...
@@ -176,7 +177,7 @@ public class DownloadManagerDashTest {
...
@@ -176,7 +177,7 @@ public class DownloadManagerDashTest {
handleDownloadRequest
(
fakeStreamKey1
);
handleDownloadRequest
(
fakeStreamKey1
);
blockUntilTasksCompleteAndThrowAnyDownloadError
();
blockUntilTasksCompleteAndThrowAnyDownloadError
();
assertCachedData
(
cache
,
fakeDataSet
);
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
).
useBoundedDataSpecFor
(
"audio_init_data"
)
);
}
}
@Test
@Test
...
...
library/hls/src/test/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloaderTest.java
View file @
811cdf06
...
@@ -44,6 +44,7 @@ import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
...
@@ -44,6 +44,7 @@ import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import
com.google.android.exoplayer2.offline.DownloaderFactory
;
import
com.google.android.exoplayer2.offline.DownloaderFactory
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist
;
import
com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist
;
import
com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet
;
import
com.google.android.exoplayer2.testutil.FakeDataSet
;
import
com.google.android.exoplayer2.testutil.FakeDataSet
;
import
com.google.android.exoplayer2.testutil.FakeDataSource.Factory
;
import
com.google.android.exoplayer2.testutil.FakeDataSource.Factory
;
import
com.google.android.exoplayer2.upstream.DummyDataSource
;
import
com.google.android.exoplayer2.upstream.DummyDataSource
;
...
@@ -129,12 +130,13 @@ public class HlsDownloaderTest {
...
@@ -129,12 +130,13 @@ public class HlsDownloaderTest {
assertCachedData
(
assertCachedData
(
cache
,
cache
,
fakeDataSet
,
new
RequestSet
(
fakeDataSet
)
MASTER_PLAYLIST_URI
,
.
subset
(
MEDIA_PLAYLIST_1_URI
,
MASTER_PLAYLIST_URI
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence0.ts"
,
MEDIA_PLAYLIST_1_URI
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence1.ts"
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence0.ts"
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence2.ts"
);
MEDIA_PLAYLIST_1_DIR
+
"fileSequence1.ts"
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence2.ts"
));
}
}
@Test
@Test
...
@@ -186,11 +188,12 @@ public class HlsDownloaderTest {
...
@@ -186,11 +188,12 @@ public class HlsDownloaderTest {
assertCachedData
(
assertCachedData
(
cache
,
cache
,
fakeDataSet
,
new
RequestSet
(
fakeDataSet
)
MEDIA_PLAYLIST_1_URI
,
.
subset
(
MEDIA_PLAYLIST_1_DIR
+
"fileSequence0.ts"
,
MEDIA_PLAYLIST_1_URI
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence1.ts"
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence0.ts"
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence2.ts"
);
MEDIA_PLAYLIST_1_DIR
+
"fileSequence1.ts"
,
MEDIA_PLAYLIST_1_DIR
+
"fileSequence2.ts"
));
}
}
@Test
@Test
...
...
testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/CacheAsserts.java
View file @
811cdf06
...
@@ -33,59 +33,89 @@ import java.util.ArrayList;
...
@@ -33,59 +33,89 @@ import java.util.ArrayList;
/** Assertion methods for {@link Cache}. */
/** Assertion methods for {@link Cache}. */
public
final
class
CacheAsserts
{
public
final
class
CacheAsserts
{
/**
/** Defines a set of data requests. */
* Asserts that the cache content is equal to the data in the {@code fakeDataSet}.
public
static
final
class
RequestSet
{
*
* @throws IOException If an error occurred reading from the Cache.
private
final
FakeDataSet
fakeDataSet
;
*/
private
DataSpec
[]
dataSpecs
;
public
static
void
assertCachedData
(
Cache
cache
,
FakeDataSet
fakeDataSet
)
throws
IOException
{
ArrayList
<
FakeData
>
allData
=
fakeDataSet
.
getAllData
();
public
RequestSet
(
FakeDataSet
fakeDataSet
)
{
Uri
[]
uris
=
new
Uri
[
allData
.
size
()];
this
.
fakeDataSet
=
fakeDataSet
;
for
(
int
i
=
0
;
i
<
allData
.
size
();
i
++)
{
ArrayList
<
FakeData
>
allData
=
fakeDataSet
.
getAllData
();
uris
[
i
]
=
allData
.
get
(
i
).
uri
;
dataSpecs
=
new
DataSpec
[
allData
.
size
()];
for
(
int
i
=
0
;
i
<
dataSpecs
.
length
;
i
++)
{
dataSpecs
[
i
]
=
new
DataSpec
(
allData
.
get
(
i
).
uri
);
}
}
}
assertCachedData
(
cache
,
fakeDataSet
,
uris
);
}
/**
public
RequestSet
subset
(
String
...
uriStrings
)
{
* Asserts that the cache content is equal to the given subset of data in the {@code fakeDataSet}.
dataSpecs
=
new
DataSpec
[
uriStrings
.
length
];
*
for
(
int
i
=
0
;
i
<
dataSpecs
.
length
;
i
++)
{
* @throws IOException If an error occurred reading from the Cache.
dataSpecs
[
i
]
=
new
DataSpec
(
Uri
.
parse
(
uriStrings
[
i
]));
*/
}
public
static
void
assertCachedData
(
Cache
cache
,
FakeDataSet
fakeDataSet
,
String
...
uriStrings
)
return
this
;
throws
IOException
{
}
Uri
[]
uris
=
new
Uri
[
uriStrings
.
length
];
for
(
int
i
=
0
;
i
<
uriStrings
.
length
;
i
++)
{
public
RequestSet
subset
(
Uri
...
uris
)
{
uris
[
i
]
=
Uri
.
parse
(
uriStrings
[
i
]);
dataSpecs
=
new
DataSpec
[
uris
.
length
];
for
(
int
i
=
0
;
i
<
dataSpecs
.
length
;
i
++)
{
dataSpecs
[
i
]
=
new
DataSpec
(
uris
[
i
]);
}
return
this
;
}
public
RequestSet
subset
(
DataSpec
...
dataSpecs
)
{
this
.
dataSpecs
=
dataSpecs
;
return
this
;
}
public
int
getCount
()
{
return
dataSpecs
.
length
;
}
public
byte
[]
getData
(
int
i
)
{
return
fakeDataSet
.
getData
(
dataSpecs
[
i
].
uri
).
getData
();
}
public
DataSpec
getDataSpec
(
int
i
)
{
return
dataSpecs
[
i
];
}
public
RequestSet
useBoundedDataSpecFor
(
String
uriString
)
{
FakeData
data
=
fakeDataSet
.
getData
(
uriString
);
for
(
int
i
=
0
;
i
<
dataSpecs
.
length
;
i
++)
{
DataSpec
spec
=
dataSpecs
[
i
];
if
(
spec
.
uri
.
getPath
().
equals
(
uriString
))
{
dataSpecs
[
i
]
=
spec
.
subrange
(
0
,
data
.
getData
().
length
);
return
this
;
}
}
throw
new
IllegalStateException
();
}
}
assertCachedData
(
cache
,
fakeDataSet
,
uris
);
}
}
/**
/**
* Asserts that the cache cont
ent is equal to the given subset of data in the {@code fakeData
Set}.
* Asserts that the cache cont
ains necessary data for the {@code request
Set}.
*
*
* @throws IOException If an error occurred reading from the Cache.
* @throws IOException If an error occurred reading from the Cache.
*/
*/
public
static
void
assertCachedData
(
Cache
cache
,
FakeDataSet
fakeDataSet
,
Uri
...
uris
)
public
static
void
assertCachedData
(
Cache
cache
,
RequestSet
requestSet
)
throws
IOException
{
throws
IOException
{
int
totalLength
=
0
;
int
totalLength
=
0
;
for
(
Uri
uri
:
uris
)
{
for
(
int
i
=
0
;
i
<
requestSet
.
getCount
();
i
++
)
{
byte
[]
data
=
fakeDataSet
.
getData
(
uri
).
getData
(
);
byte
[]
data
=
requestSet
.
getData
(
i
);
assertDataCached
(
cache
,
uri
,
data
);
assertDataCached
(
cache
,
requestSet
.
getDataSpec
(
i
)
,
data
);
totalLength
+=
data
.
length
;
totalLength
+=
data
.
length
;
}
}
assertThat
(
cache
.
getCacheSpace
()).
isEqualTo
(
totalLength
);
assertThat
(
cache
.
getCacheSpace
()).
isEqualTo
(
totalLength
);
}
}
/**
/**
* Asserts that the cache cont
ains the given data for {@code uriString
}.
* Asserts that the cache cont
ent is equal to the data in the {@code fakeDataSet
}.
*
*
* @throws IOException If an error occurred reading from the Cache.
* @throws IOException If an error occurred reading from the Cache.
*/
*/
public
static
void
assertDataCached
(
Cache
cache
,
Uri
uri
,
byte
[]
expected
)
throws
IOException
{
public
static
void
assertCachedData
(
Cache
cache
,
FakeDataSet
fakeDataSet
)
throws
IOException
{
// TODO Make tests specify if the content length is stored in cache metadata.
assertCachedData
(
cache
,
new
RequestSet
(
fakeDataSet
));
DataSpec
dataSpec
=
new
DataSpec
(
uri
,
0
,
expected
.
length
,
null
,
0
);
assertDataCached
(
cache
,
dataSpec
,
expected
);
}
}
/**
/**
...
...
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