Commit e154cb17 by ibaker Committed by Oliver Woodman

Fix calls to readExactly in DataSourceContractTest

The length needs to change depending on the positition/length parameters
passed to DataSpec, so it doesn't really make sense to keep this private
method - it's clearer to in-line the calls in each test.

PiperOrigin-RevId: 348749254
parent 525f151f
...@@ -88,7 +88,10 @@ public abstract class DataSourceContractTest { ...@@ -88,7 +88,10 @@ public abstract class DataSourceContractTest {
DataSource dataSource = createDataSource(); DataSource dataSource = createDataSource();
try { try {
long length = dataSource.open(new DataSpec(resource.getUri())); long length = dataSource.open(new DataSpec(resource.getUri()));
byte[] data = readToEnd(dataSource, resource); byte[] data =
resource.isEndOfInputExpected()
? Util.readToEnd(dataSource)
: Util.readExactly(dataSource, resource.getExpectedBytes().length);
assertThat(length).isEqualTo(resource.getExpectedResolvedLength()); assertThat(length).isEqualTo(resource.getExpectedResolvedLength());
assertThat(data).isEqualTo(resource.getExpectedBytes()); assertThat(data).isEqualTo(resource.getExpectedBytes());
...@@ -112,7 +115,10 @@ public abstract class DataSourceContractTest { ...@@ -112,7 +115,10 @@ public abstract class DataSourceContractTest {
long length = long length =
dataSource.open( dataSource.open(
new DataSpec.Builder().setUri(resource.getUri()).setPosition(3).build()); new DataSpec.Builder().setUri(resource.getUri()).setPosition(3).build());
byte[] data = readToEnd(dataSource, resource); byte[] data =
resource.isEndOfInputExpected()
? Util.readToEnd(dataSource)
: Util.readExactly(dataSource, resource.getExpectedBytes().length - 3);
if (resource.getExpectedResolvedLength() != C.LENGTH_UNSET) { if (resource.getExpectedResolvedLength() != C.LENGTH_UNSET) {
assertThat(length).isEqualTo(resource.getExpectedResolvedLength() - 3); assertThat(length).isEqualTo(resource.getExpectedResolvedLength() - 3);
...@@ -139,7 +145,10 @@ public abstract class DataSourceContractTest { ...@@ -139,7 +145,10 @@ public abstract class DataSourceContractTest {
try { try {
long length = long length =
dataSource.open(new DataSpec.Builder().setUri(resource.getUri()).setLength(4).build()); dataSource.open(new DataSpec.Builder().setUri(resource.getUri()).setLength(4).build());
byte[] data = readToEnd(dataSource, resource); byte[] data =
resource.isEndOfInputExpected()
? Util.readToEnd(dataSource)
: Util.readExactly(dataSource, /* length= */ 4);
assertThat(length).isEqualTo(4); assertThat(length).isEqualTo(4);
byte[] expectedData = Arrays.copyOf(resource.getExpectedBytes(), 4); byte[] expectedData = Arrays.copyOf(resource.getExpectedBytes(), 4);
...@@ -168,7 +177,10 @@ public abstract class DataSourceContractTest { ...@@ -168,7 +177,10 @@ public abstract class DataSourceContractTest {
.setPosition(2) .setPosition(2)
.setLength(2) .setLength(2)
.build()); .build());
byte[] data = readToEnd(dataSource, resource); byte[] data =
resource.isEndOfInputExpected()
? Util.readToEnd(dataSource)
: Util.readExactly(dataSource, /* length= */ 2);
assertThat(length).isEqualTo(2); assertThat(length).isEqualTo(2);
byte[] expectedData = Arrays.copyOfRange(resource.getExpectedBytes(), 2, 4); byte[] expectedData = Arrays.copyOfRange(resource.getExpectedBytes(), 2, 4);
...@@ -201,13 +213,6 @@ public abstract class DataSourceContractTest { ...@@ -201,13 +213,6 @@ public abstract class DataSourceContractTest {
} }
} }
private static byte[] readToEnd(DataSource dataSource, TestResource expectedResource)
throws IOException {
return expectedResource.isEndOfInputExpected()
? Util.readToEnd(dataSource)
: Util.readExactly(dataSource, expectedResource.getExpectedBytes().length);
}
/** Information about a resource that can be used to test the {@link DataSource} instance. */ /** Information about a resource that can be used to test the {@link DataSource} instance. */
public static final class TestResource { public static final class TestResource {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment