use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
the class FakeDataSourceTest method testReadPartialBounded.
@Test
public void testReadPartialBounded() throws IOException {
FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
assertThat(dataSource.open(new DataSpec(uri, 9, 3))).isEqualTo(3);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(1);
assertBuffer(TEST_DATA_PART_1, 9, 1);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(2);
assertBuffer(TEST_DATA_PART_2, 0, 2);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
dataSource.close();
assertThat(dataSource.open(new DataSpec(uri, 11, 4))).isEqualTo(4);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(4);
assertBuffer(TEST_DATA_PART_2, 1, 4);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
dataSource.close();
}
use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
the class FakeDataSourceTest method testReadFull.
@Test
public void testReadFull() throws IOException {
FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
assertThat(dataSource.open(new DataSpec(uri))).isEqualTo(15);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(10);
assertBuffer(TEST_DATA_PART_1);
assertThat(dataSource.read(BUFFER, 10, BUFFER.length)).isEqualTo(5);
assertBuffer(TEST_DATA);
assertThat(dataSource.read(BUFFER, 15, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
assertBuffer(TEST_DATA);
assertThat(dataSource.read(BUFFER, 20, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
dataSource.close();
}
use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
the class FakeDataSourceTest method testRunnable.
@Test
public void testRunnable() throws IOException {
TestRunnable[] runnables = new TestRunnable[3];
for (int i = 0; i < 3; i++) {
runnables[i] = new TestRunnable();
}
FakeDataSource dataSource = new FakeDataSource(new FakeDataSet().newData(uri.toString()).appendReadData(TEST_DATA).appendReadAction(runnables[0]).appendReadData(TEST_DATA).appendReadAction(runnables[1]).appendReadAction(runnables[2]).appendReadData(TEST_DATA).endData());
assertThat(dataSource.open(new DataSpec(uri))).isEqualTo(45);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
assertBuffer(TEST_DATA);
for (int i = 0; i < 3; i++) {
assertThat(runnables[i].ran).isFalse();
}
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
assertBuffer(TEST_DATA);
assertThat(runnables[0].ran).isTrue();
assertThat(runnables[1].ran).isFalse();
assertThat(runnables[2].ran).isFalse();
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
assertBuffer(TEST_DATA);
for (int i = 0; i < 3; i++) {
assertThat(runnables[i].ran).isTrue();
}
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
dataSource.close();
}
use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
the class FakeDataSourceTest method testReadPartialOpenEnded.
@Test
public void testReadPartialOpenEnded() throws IOException {
FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
assertThat(dataSource.open(new DataSpec(uri, 7, C.LENGTH_UNSET))).isEqualTo(8);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(3);
assertBuffer(TEST_DATA_PART_1, 7, 3);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(5);
assertBuffer(TEST_DATA_PART_2);
assertThat(dataSource.read(BUFFER, 15, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
dataSource.close();
}
use of androidx.media3.test.utils.FakeDataSet in project media by androidx.
the class FakeDataSourceTest method testFakeData.
@Test
public void testFakeData() throws IOException {
FakeDataSource dataSource = new FakeDataSource(new FakeDataSet().newData(uri.toString()).appendReadData(100).appendReadData(TEST_DATA).appendReadData(200).endData());
assertThat(dataSource.open(new DataSpec(uri))).isEqualTo(315);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(100);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(15);
assertBuffer(TEST_DATA);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(200);
assertThat(dataSource.read(BUFFER, 0, BUFFER.length)).isEqualTo(C.RESULT_END_OF_INPUT);
dataSource.close();
}
Aggregations