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
aacb212c
authored
Nov 27, 2018
by
olly
Committed by
Andrew Lewis
Nov 27, 2018
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Remove duplicate CacheAsserts class
PiperOrigin-RevId: 222963935
parent
e3173059
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
164 deletions
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheAsserts.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheUtilTest.java
testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/CacheAsserts.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheAsserts.java
deleted
100644 → 0
View file @
e3173059
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertWithMessage
;
import
android.net.Uri
;
import
com.google.android.exoplayer2.testutil.FakeDataSet
;
import
com.google.android.exoplayer2.testutil.FakeDataSet.FakeData
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DataSourceInputStream
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.DummyDataSource
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.IOException
;
import
java.util.ArrayList
;
/** Assertion methods for {@link com.google.android.exoplayer2.upstream.cache.Cache}. */
/* package */
final
class
CacheAsserts
{
/**
* Asserts that the cache content is equal to the data in the {@code fakeDataSet}.
*
* @throws IOException If an error occurred reading from the Cache.
*/
public
static
void
assertCachedData
(
Cache
cache
,
FakeDataSet
fakeDataSet
)
throws
IOException
{
ArrayList
<
FakeData
>
allData
=
fakeDataSet
.
getAllData
();
Uri
[]
uris
=
new
Uri
[
allData
.
size
()];
for
(
int
i
=
0
;
i
<
allData
.
size
();
i
++)
{
uris
[
i
]
=
allData
.
get
(
i
).
uri
;
}
assertCachedData
(
cache
,
fakeDataSet
,
uris
);
}
/**
* Asserts that the cache content is equal to the given subset of data in the {@code fakeDataSet}.
*
* @throws IOException If an error occurred reading from the Cache.
*/
public
static
void
assertCachedData
(
Cache
cache
,
FakeDataSet
fakeDataSet
,
String
...
uriStrings
)
throws
IOException
{
Uri
[]
uris
=
new
Uri
[
uriStrings
.
length
];
for
(
int
i
=
0
;
i
<
uriStrings
.
length
;
i
++)
{
uris
[
i
]
=
Uri
.
parse
(
uriStrings
[
i
]);
}
assertCachedData
(
cache
,
fakeDataSet
,
uris
);
}
/**
* Asserts that the cache content is equal to the given subset of data in the {@code fakeDataSet}.
*
* @throws IOException If an error occurred reading from the Cache.
*/
public
static
void
assertCachedData
(
Cache
cache
,
FakeDataSet
fakeDataSet
,
Uri
...
uris
)
throws
IOException
{
int
totalLength
=
0
;
for
(
Uri
uri
:
uris
)
{
byte
[]
data
=
fakeDataSet
.
getData
(
uri
).
getData
();
assertDataCached
(
cache
,
uri
,
data
);
totalLength
+=
data
.
length
;
}
assertThat
(
cache
.
getCacheSpace
()).
isEqualTo
(
totalLength
);
}
/**
* Asserts that the cache contains the given subset of data in the {@code fakeDataSet}.
*
* @throws IOException If an error occurred reading from the Cache.
*/
public
static
void
assertDataCached
(
Cache
cache
,
FakeDataSet
fakeDataSet
,
Uri
...
uris
)
throws
IOException
{
for
(
Uri
uri
:
uris
)
{
assertDataCached
(
cache
,
uri
,
fakeDataSet
.
getData
(
uri
).
getData
());
}
}
/**
* Asserts that the cache contains the given data for {@code uriString} or not.
*
* @throws IOException If an error occurred reading from the Cache.
*/
public
static
void
assertDataCached
(
Cache
cache
,
Uri
uri
,
byte
[]
expected
)
throws
IOException
{
DataSource
dataSource
=
new
CacheDataSource
(
cache
,
DummyDataSource
.
INSTANCE
,
0
);
DataSpec
dataSpec
=
new
DataSpec
(
uri
,
DataSpec
.
FLAG_ALLOW_CACHING_UNKNOWN_LENGTH
);
String
messageToPrepend
=
"Cached data doesn't match expected for '"
+
uri
+
"'"
;
assertReadData
(
dataSource
,
dataSpec
,
expected
,
messageToPrepend
);
}
/**
* Asserts that the read data from {@code dataSource} specified by {@code dataSpec} is equal to
* {@code expected} or not.
*
* @throws IOException If an error occurred reading from the Cache.
*/
public
static
void
assertReadData
(
DataSource
dataSource
,
DataSpec
dataSpec
,
byte
[]
expected
,
String
messageToPrepend
)
throws
IOException
{
DataSourceInputStream
inputStream
=
new
DataSourceInputStream
(
dataSource
,
dataSpec
);
byte
[]
bytes
=
null
;
try
{
bytes
=
Util
.
toByteArray
(
inputStream
);
}
catch
(
IOException
e
)
{
// Ignore
}
finally
{
inputStream
.
close
();
}
assertWithMessage
(
messageToPrepend
).
that
(
bytes
).
isEqualTo
(
expected
);
}
/** Asserts that there is no cache content for the given {@code uriStrings}. */
public
static
void
assertDataNotCached
(
Cache
cache
,
String
...
uriStrings
)
{
for
(
String
uriString
:
uriStrings
)
{
assertWithMessage
(
"There is cached data for '"
+
uriString
+
"'"
)
.
that
(
cache
.
getCachedSpans
(
CacheUtil
.
generateKey
(
Uri
.
parse
(
uriString
))))
.
isEmpty
();
}
}
/** Asserts that the cache is empty. */
public
static
void
assertCacheEmpty
(
Cache
cache
)
{
assertThat
(
cache
.
getCacheSpace
()).
isEqualTo
(
0
);
}
private
CacheAsserts
()
{}
}
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest.java
View file @
aacb212c
...
@@ -15,12 +15,13 @@
...
@@ -15,12 +15,13 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
;
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
.
CacheAsserts
.
assertCacheEmpty
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
CacheAsserts
.
assertCacheEmpty
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.
fail
;
import
android.net.Uri
;
import
android.net.Uri
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.testutil.CacheAsserts
;
import
com.google.android.exoplayer2.testutil.FakeDataSet.FakeData
;
import
com.google.android.exoplayer2.testutil.FakeDataSet.FakeData
;
import
com.google.android.exoplayer2.testutil.FakeDataSource
;
import
com.google.android.exoplayer2.testutil.FakeDataSource
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
...
@@ -566,8 +567,7 @@ public final class CacheDataSourceTest {
...
@@ -566,8 +567,7 @@ public final class CacheDataSourceTest {
cacheDataSource
.
close
();
cacheDataSource
.
close
();
byte
[]
expected
=
Arrays
.
copyOfRange
(
TEST_DATA
,
position
,
position
+
testDataLength
);
byte
[]
expected
=
Arrays
.
copyOfRange
(
TEST_DATA
,
position
,
position
+
testDataLength
);
CacheAsserts
.
assertReadData
(
CacheAsserts
.
assertReadData
(
cacheDataSource
,
dataSpec
,
expected
);
cacheDataSource
,
dataSpec
,
expected
,
"Cached data doesn't match the original data"
);
}
}
private
CacheDataSource
createCacheDataSource
(
boolean
setReadException
,
private
CacheDataSource
createCacheDataSource
(
boolean
setReadException
,
...
...
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheUtilTest.java
View file @
aacb212c
...
@@ -18,8 +18,8 @@ package com.google.android.exoplayer2.upstream.cache;
...
@@ -18,8 +18,8 @@ package com.google.android.exoplayer2.upstream.cache;
import
static
android
.
net
.
Uri
.
EMPTY
;
import
static
android
.
net
.
Uri
.
EMPTY
;
import
static
android
.
net
.
Uri
.
parse
;
import
static
android
.
net
.
Uri
.
parse
;
import
static
com
.
google
.
android
.
exoplayer2
.
C
.
LENGTH_UNSET
;
import
static
com
.
google
.
android
.
exoplayer2
.
C
.
LENGTH_UNSET
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
.
CacheAsserts
.
assertCacheEmpty
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
CacheAsserts
.
assertCacheEmpty
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
.
CacheAsserts
.
assertCachedData
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
CacheAsserts
.
assertCachedData
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
.
CacheUtil
.
generateKey
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
.
CacheUtil
.
generateKey
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
.
CacheUtil
.
getKey
;
import
static
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
.
CacheUtil
.
getKey
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
...
...
testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/CacheAsserts.java
View file @
aacb212c
...
@@ -21,11 +21,12 @@ import static com.google.common.truth.Truth.assertWithMessage;
...
@@ -21,11 +21,12 @@ import static com.google.common.truth.Truth.assertWithMessage;
import
android.net.Uri
;
import
android.net.Uri
;
import
com.google.android.exoplayer2.testutil.FakeDataSet.FakeData
;
import
com.google.android.exoplayer2.testutil.FakeDataSet.FakeData
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DataSourceInputStream
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.DummyDataSource
;
import
com.google.android.exoplayer2.upstream.DummyDataSource
;
import
com.google.android.exoplayer2.upstream.cache.Cache
;
import
com.google.android.exoplayer2.upstream.cache.Cache
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSource
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSource
;
import
com.google.android.exoplayer2.u
pstream.cache.Cache
Util
;
import
com.google.android.exoplayer2.u
til.
Util
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -77,18 +78,6 @@ public final class CacheAsserts {
...
@@ -77,18 +78,6 @@ public final class CacheAsserts {
}
}
/**
/**
* Asserts that the cache contains the given subset of data in the {@code fakeDataSet}.
*
* @throws IOException If an error occurred reading from the Cache.
*/
public
static
void
assertDataCached
(
Cache
cache
,
FakeDataSet
fakeDataSet
,
Uri
...
uris
)
throws
IOException
{
for
(
Uri
uri
:
uris
)
{
assertDataCached
(
cache
,
uri
,
fakeDataSet
.
getData
(
uri
).
getData
());
}
}
/**
* Asserts that the cache contains the given data for {@code uriString}.
* Asserts that the cache contains the given data for {@code uriString}.
*
*
* @throws IOException If an error occurred reading from the Cache.
* @throws IOException If an error occurred reading from the Cache.
...
@@ -117,13 +106,24 @@ public final class CacheAsserts {
...
@@ -117,13 +106,24 @@ public final class CacheAsserts {
}
}
}
}
/** Asserts that there is no cache content for the given {@code uriStrings}. */
/**
public
static
void
assertDataNotCached
(
Cache
cache
,
String
...
uriStrings
)
{
* Asserts that the read data from {@code dataSource} specified by {@code dataSpec} is equal to
for
(
String
uriString
:
uriStrings
)
{
* {@code expected} or not.
assertWithMessage
(
"There is cached data for '"
+
uriString
+
"',"
)
*
.
that
(
cache
.
getCachedSpans
(
CacheUtil
.
generateKey
(
Uri
.
parse
(
uriString
))).
isEmpty
())
* @throws IOException If an error occurred reading from the Cache.
.
isTrue
();
*/
public
static
void
assertReadData
(
DataSource
dataSource
,
DataSpec
dataSpec
,
byte
[]
expected
)
throws
IOException
{
DataSourceInputStream
inputStream
=
new
DataSourceInputStream
(
dataSource
,
dataSpec
);
byte
[]
bytes
=
null
;
try
{
bytes
=
Util
.
toByteArray
(
inputStream
);
}
catch
(
IOException
e
)
{
// Ignore
}
finally
{
inputStream
.
close
();
}
}
assertThat
(
bytes
).
isEqualTo
(
expected
);
}
}
/** Asserts that the cache is empty. */
/** Asserts that the cache is empty. */
...
...
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