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
30beb9b3
authored
Apr 10, 2019
by
olly
Committed by
Oliver Woodman
Apr 13, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add DownloadAction merge tests
PiperOrigin-RevId: 242851294
parent
8688bd2d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
20 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadAction.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadActionTest.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadAction.java
View file @
30beb9b3
...
@@ -29,7 +29,7 @@ import java.util.Arrays;
...
@@ -29,7 +29,7 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
/**
Contains the necessary parameters for a download action
. */
/**
Defines content to be downloaded
. */
public
final
class
DownloadAction
implements
Parcelable
{
public
final
class
DownloadAction
implements
Parcelable
{
/** Thrown when the encoded action data belongs to an unsupported DownloadAction type. */
/** Thrown when the encoded action data belongs to an unsupported DownloadAction type. */
...
@@ -108,14 +108,20 @@ public final class DownloadAction implements Parcelable {
...
@@ -108,14 +108,20 @@ public final class DownloadAction implements Parcelable {
}
}
/**
/**
* Returns the result of merging {@code newAction} into this action.
* Returns the result of merging {@code newAction} into this action. The actions must have the
* same {@link #id} and {@link #type}.
*
*
* @param newAction The new action.
* <p>If the actions have different {@link #uri}, {@link #customCacheKey} and {@link #data}
* values, then those from the action being merged are included in the result.
*
* @param newAction The action being merged.
* @return The merged result.
* @return The merged result.
* @throws IllegalArgumentException If the actions do not have the same {@link #id} and {@link
* #type}.
*/
*/
public
DownloadAction
copyWithMergedAction
(
DownloadAction
newAction
)
{
public
DownloadAction
copyWithMergedAction
(
DownloadAction
newAction
)
{
Assertions
.
check
State
(
id
.
equals
(
newAction
.
id
));
Assertions
.
check
Argument
(
id
.
equals
(
newAction
.
id
));
Assertions
.
check
State
(
type
.
equals
(
newAction
.
type
));
Assertions
.
check
Argument
(
type
.
equals
(
newAction
.
type
));
List
<
StreamKey
>
mergedKeys
;
List
<
StreamKey
>
mergedKeys
;
if
(
streamKeys
.
isEmpty
()
||
newAction
.
streamKeys
.
isEmpty
())
{
if
(
streamKeys
.
isEmpty
()
||
newAction
.
streamKeys
.
isEmpty
())
{
// If either streamKeys is empty then all streams should be downloaded.
// If either streamKeys is empty then all streams should be downloaded.
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadActionTest.java
View file @
30beb9b3
...
@@ -16,7 +16,9 @@
...
@@ -16,7 +16,9 @@
package
com
.
google
.
android
.
exoplayer2
.
offline
;
package
com
.
google
.
android
.
exoplayer2
.
offline
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadAction
.
TYPE_DASH
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadAction
.
TYPE_DASH
;
import
static
com
.
google
.
android
.
exoplayer2
.
offline
.
DownloadAction
.
TYPE_HLS
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Parcel
;
import
android.os.Parcel
;
...
@@ -42,6 +44,128 @@ public class DownloadActionTest {
...
@@ -42,6 +44,128 @@ public class DownloadActionTest {
}
}
@Test
@Test
public
void
testMergeActions_withDifferentIds_fails
()
{
DownloadAction
action1
=
new
DownloadAction
(
"id1"
,
TYPE_DASH
,
uri1
,
/* streamKeys= */
Collections
.
emptyList
(),
/* customCacheKey= */
null
,
/* data= */
null
);
DownloadAction
action2
=
new
DownloadAction
(
"id2"
,
TYPE_DASH
,
uri2
,
/* streamKeys= */
Collections
.
emptyList
(),
/* customCacheKey= */
null
,
/* data= */
null
);
try
{
action1
.
copyWithMergedAction
(
action2
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
// Expected.
}
}
@Test
public
void
testMergeActions_withDifferentTypes_fails
()
{
DownloadAction
action1
=
new
DownloadAction
(
"id1"
,
TYPE_DASH
,
uri1
,
/* streamKeys= */
Collections
.
emptyList
(),
/* customCacheKey= */
null
,
/* data= */
null
);
DownloadAction
action2
=
new
DownloadAction
(
"id1"
,
TYPE_HLS
,
uri1
,
/* streamKeys= */
Collections
.
emptyList
(),
/* customCacheKey= */
null
,
/* data= */
null
);
try
{
action1
.
copyWithMergedAction
(
action2
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
// Expected.
}
}
@Test
public
void
testMergeAction_withSameAction
()
{
DownloadAction
action1
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
));
DownloadAction
mergedAction
=
action1
.
copyWithMergedAction
(
action1
);
assertEqual
(
action1
,
mergedAction
);
}
@Test
public
void
testMergeActions_withEmptyStreamKeys
()
{
DownloadAction
action1
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
));
DownloadAction
action2
=
createAction
(
uri1
);
// If either of the actions have empty streamKeys, the merge should have empty streamKeys.
DownloadAction
mergedAction
=
action1
.
copyWithMergedAction
(
action2
);
assertThat
(
mergedAction
.
streamKeys
).
isEmpty
();
mergedAction
=
action2
.
copyWithMergedAction
(
action1
);
assertThat
(
mergedAction
.
streamKeys
).
isEmpty
();
}
@Test
public
void
testMergeActions_withOverlappingStreamKeys
()
{
StreamKey
streamKey1
=
new
StreamKey
(
0
,
1
,
2
);
StreamKey
streamKey2
=
new
StreamKey
(
3
,
4
,
5
);
StreamKey
streamKey3
=
new
StreamKey
(
6
,
7
,
8
);
DownloadAction
action1
=
createAction
(
uri1
,
streamKey1
,
streamKey2
);
DownloadAction
action2
=
createAction
(
uri1
,
streamKey2
,
streamKey3
);
// Merged streamKeys should be in their original order without duplicates.
DownloadAction
mergedAction
=
action1
.
copyWithMergedAction
(
action2
);
assertThat
(
mergedAction
.
streamKeys
).
containsExactly
(
streamKey1
,
streamKey2
,
streamKey3
);
mergedAction
=
action2
.
copyWithMergedAction
(
action1
);
assertThat
(
mergedAction
.
streamKeys
).
containsExactly
(
streamKey2
,
streamKey3
,
streamKey1
);
}
@Test
public
void
testMergeActions_withDifferentFields
()
{
byte
[]
data1
=
new
byte
[]
{
0
,
1
,
2
};
byte
[]
data2
=
new
byte
[]
{
3
,
4
,
5
};
DownloadAction
action1
=
new
DownloadAction
(
"id1"
,
TYPE_DASH
,
uri1
,
/* streamKeys= */
Collections
.
emptyList
(),
"key1"
,
/* data= */
data1
);
DownloadAction
action2
=
new
DownloadAction
(
"id1"
,
TYPE_DASH
,
uri2
,
/* streamKeys= */
Collections
.
emptyList
(),
"key2"
,
/* data= */
data2
);
// uri, customCacheKey and data should be from the action being merged.
DownloadAction
mergedAction
=
action1
.
copyWithMergedAction
(
action2
);
assertThat
(
mergedAction
.
uri
).
isEqualTo
(
uri2
);
assertThat
(
mergedAction
.
customCacheKey
).
isEqualTo
(
"key2"
);
assertThat
(
mergedAction
.
data
).
isEqualTo
(
data2
);
mergedAction
=
action2
.
copyWithMergedAction
(
action1
);
assertThat
(
mergedAction
.
uri
).
isEqualTo
(
uri1
);
assertThat
(
mergedAction
.
customCacheKey
).
isEqualTo
(
"key1"
);
assertThat
(
mergedAction
.
data
).
isEqualTo
(
data1
);
}
@Test
public
void
testParcelable
()
{
public
void
testParcelable
()
{
ArrayList
<
StreamKey
>
streamKeys
=
new
ArrayList
<>();
ArrayList
<
StreamKey
>
streamKeys
=
new
ArrayList
<>();
streamKeys
.
add
(
new
StreamKey
(
1
,
2
,
3
));
streamKeys
.
add
(
new
StreamKey
(
1
,
2
,
3
));
...
@@ -74,29 +198,29 @@ public class DownloadActionTest {
...
@@ -74,29 +198,29 @@ public class DownloadActionTest {
DownloadAction
action3
=
createAction
(
uri1
);
DownloadAction
action3
=
createAction
(
uri1
);
assertEqual
(
action2
,
action3
);
assertEqual
(
action2
,
action3
);
DownloadAction
action6
=
createAction
(
uri1
);
DownloadAction
action4
=
createAction
(
uri1
);
DownloadAction
action5
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
));
assertNotEqual
(
action4
,
action5
);
DownloadAction
action6
=
createAction
(
uri1
,
new
StreamKey
(
0
,
1
,
1
));
DownloadAction
action7
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
));
DownloadAction
action7
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
));
assertNotEqual
(
action6
,
action7
);
assertNotEqual
(
action6
,
action7
);
DownloadAction
action8
=
createAction
(
uri1
,
new
StreamKey
(
0
,
1
,
1
)
);
DownloadAction
action8
=
createAction
(
uri1
);
DownloadAction
action9
=
createAction
(
uri
1
,
new
StreamKey
(
0
,
0
,
0
)
);
DownloadAction
action9
=
createAction
(
uri
2
);
assertNotEqual
(
action8
,
action9
);
assertNotEqual
(
action8
,
action9
);
DownloadAction
action10
=
createAction
(
uri1
);
DownloadAction
action10
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
),
new
StreamKey
(
0
,
1
,
1
)
);
DownloadAction
action11
=
createAction
(
uri
2
);
DownloadAction
action11
=
createAction
(
uri
1
,
new
StreamKey
(
0
,
1
,
1
),
new
StreamKey
(
0
,
0
,
0
)
);
assert
Not
Equal
(
action10
,
action11
);
assertEqual
(
action10
,
action11
);
DownloadAction
action12
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
)
,
new
StreamKey
(
0
,
1
,
1
)
);
DownloadAction
action12
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
));
DownloadAction
action13
=
createAction
(
uri1
,
new
StreamKey
(
0
,
1
,
1
),
new
StreamKey
(
0
,
0
,
0
));
DownloadAction
action13
=
createAction
(
uri1
,
new
StreamKey
(
0
,
1
,
1
),
new
StreamKey
(
0
,
0
,
0
));
assertEqual
(
action12
,
action13
);
assertNotEqual
(
action12
,
action13
);
DownloadAction
action14
=
createAction
(
uri1
,
new
StreamKey
(
0
,
0
,
0
));
DownloadAction
action15
=
createAction
(
uri1
,
new
StreamKey
(
0
,
1
,
1
),
new
StreamKey
(
0
,
0
,
0
));
assertNotEqual
(
action14
,
action15
);
DownloadAction
action1
6
=
createAction
(
uri1
);
DownloadAction
action1
4
=
createAction
(
uri1
);
DownloadAction
action1
7
=
createAction
(
uri1
);
DownloadAction
action1
5
=
createAction
(
uri1
);
assertEqual
(
action1
6
,
action17
);
assertEqual
(
action1
4
,
action15
);
}
}
private
static
void
assertNotEqual
(
DownloadAction
action1
,
DownloadAction
action2
)
{
private
static
void
assertNotEqual
(
DownloadAction
action1
,
DownloadAction
action2
)
{
...
...
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