com.google.android.exoplayer.testutil.FakeDataSource

Here are the examples of the java api class com.google.android.exoplayer.testutil.FakeDataSource taken from open source projects.

1. DefaultExtractorInputTest#testSkipFullyLarge()

View license
public void testSkipFullyLarge() throws IOException, InterruptedException {
    // Tests skipping an amount of data that's larger than any internal scratch space.
    int largeSkipSize = 1024 * 1024;
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(new byte[largeSkipSize]);
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNBOUNDED);
    input.skipFully(largeSkipSize);
    assertEquals(largeSkipSize, input.getPosition());
    // Check that we fail with EOFException we skip again.
    try {
        input.skipFully(1);
        fail();
    } catch (EOFException e) {
    }
}

2. DefaultExtractorInputTest#testReadFullyWithFailingDataSource()

View license
public void testReadFullyWithFailingDataSource() throws IOException, InterruptedException {
    FakeDataSource testDataSource = buildFailingDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNBOUNDED);
    try {
        byte[] target = new byte[TEST_DATA.length];
        input.readFully(target, 0, TEST_DATA.length);
        fail();
    } catch (IOException e) {
    }
    // The position should not have advanced.
    assertEquals(0, input.getPosition());
}

3. DefaultExtractorInputTest#testSkipFullyWithFailingDataSource()

View license
public void testSkipFullyWithFailingDataSource() throws IOException, InterruptedException {
    FakeDataSource testDataSource = buildFailingDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNBOUNDED);
    try {
        input.skipFully(TEST_DATA.length);
        fail();
    } catch (IOException e) {
    }
    // The position should not have advanced.
    assertEquals(0, input.getPosition());
}

4. DefaultExtractorInputTest#buildDataSource()

View license
private static FakeDataSource buildDataSource() throws IOException {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 0, 3));
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 3, 6));
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    return testDataSource;
}

5. DefaultExtractorInputTest#buildFailingDataSource()

View license
private static FakeDataSource buildFailingDataSource() throws IOException {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 0, 6));
    builder.appendReadError(new IOException());
    builder.appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    return testDataSource;
}

6. DefaultExtractorInputTest#buildLargeDataSource()

View license
private static FakeDataSource buildLargeDataSource() throws IOException {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(new byte[LARGE_TEST_DATA_LENGTH]);
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    return testDataSource;
}

7. DefaultExtractorInputTest#testInitialPosition()

View license
public void testInitialPosition() throws IOException {
    FakeDataSource testDataSource = buildDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 123, C.LENGTH_UNBOUNDED);
    assertEquals(123, input.getPosition());
}

8. DefaultExtractorInputTest#testSkip()

View license
public void testSkip() throws IOException, InterruptedException {
    FakeDataSource testDataSource = buildDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNBOUNDED);
    // We expect to perform three skips of three bytes, as setup in buildTestDataSource.
    for (int i = 0; i < 3; i++) {
        assertEquals(3, input.skip(TEST_DATA.length));
    }
    // Check we're now indicated that the end of input is reached.
    int expectedEndOfInput = input.skip(TEST_DATA.length);
    assertEquals(-1, expectedEndOfInput);
}

9. DefaultExtractorInputTest#testLargeSkip()

View license
public void testLargeSkip() throws IOException, InterruptedException {
    FakeDataSource testDataSource = buildLargeDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNBOUNDED);
    // Check that skipping the entire data source succeeds.
    int bytesToSkip = LARGE_TEST_DATA_LENGTH;
    while (bytesToSkip > 0) {
        bytesToSkip -= input.skip(bytesToSkip);
    }
}

10. DefaultExtractorInputTest#createDefaultExtractorInput()

View license
private static DefaultExtractorInput createDefaultExtractorInput() throws IOException {
    FakeDataSource testDataSource = buildDataSource();
    return new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNBOUNDED);
}