mirror of
https://github.com/samsonjs/media.git
synced 2026-04-03 10:55:48 +00:00
Use Truth instead of framework asserts in all tests.
This achieves two things: 1. All our tests use the same type of assertions. 2. The tests currently run as instrumentation test can be moved to Robolectric without changing the assertions. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=182910542
This commit is contained in:
parent
aa1b41bf2f
commit
e991a8015b
60 changed files with 1470 additions and 1234 deletions
|
|
@ -15,8 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.ext.cronet;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
|
|
@ -53,13 +52,13 @@ public final class ByteArrayUploadDataProviderTest {
|
|||
|
||||
@Test
|
||||
public void testGetLength() {
|
||||
assertEquals(TEST_DATA.length, byteArrayUploadDataProvider.getLength());
|
||||
assertThat(byteArrayUploadDataProvider.getLength()).isEqualTo(TEST_DATA.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFullBuffer() throws IOException {
|
||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||
assertArrayEquals(TEST_DATA, byteBuffer.array());
|
||||
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -69,12 +68,12 @@ public final class ByteArrayUploadDataProviderTest {
|
|||
byteBuffer = ByteBuffer.allocate(TEST_DATA.length / 2);
|
||||
// Read half of the data.
|
||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||
assertArrayEquals(firstHalf, byteBuffer.array());
|
||||
assertThat(byteBuffer.array()).isEqualTo(firstHalf);
|
||||
|
||||
// Read the second half of the data.
|
||||
byteBuffer.rewind();
|
||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||
assertArrayEquals(secondHalf, byteBuffer.array());
|
||||
assertThat(byteBuffer.array()).isEqualTo(secondHalf);
|
||||
verify(mockUploadDataSink, times(2)).onReadSucceeded(false);
|
||||
}
|
||||
|
||||
|
|
@ -82,13 +81,13 @@ public final class ByteArrayUploadDataProviderTest {
|
|||
public void testRewind() throws IOException {
|
||||
// Read all the data.
|
||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||
assertArrayEquals(TEST_DATA, byteBuffer.array());
|
||||
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
|
||||
|
||||
// Rewind and make sure it can be read again.
|
||||
byteBuffer.clear();
|
||||
byteArrayUploadDataProvider.rewind(mockUploadDataSink);
|
||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||
assertArrayEquals(TEST_DATA, byteBuffer.array());
|
||||
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
|
||||
verify(mockUploadDataSink).onRewindSucceeded();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.ext.cronet;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
|
|
@ -222,7 +219,7 @@ public final class CronetDataSourceTest {
|
|||
@Test
|
||||
public void testRequestOpen() throws HttpDataSourceException {
|
||||
mockResponseStartSuccess();
|
||||
assertEquals(TEST_CONTENT_LENGTH, dataSourceUnderTest.open(testDataSpec));
|
||||
assertThat(dataSourceUnderTest.open(testDataSpec)).isEqualTo(TEST_CONTENT_LENGTH);
|
||||
verify(mockTransferListener).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||
}
|
||||
|
||||
|
|
@ -234,7 +231,7 @@ public final class CronetDataSourceTest {
|
|||
testResponseHeader.put("Content-Length", Long.toString(50L));
|
||||
mockResponseStartSuccess();
|
||||
|
||||
assertEquals(5000 /* contentLength */, dataSourceUnderTest.open(testDataSpec));
|
||||
assertThat(dataSourceUnderTest.open(testDataSpec)).isEqualTo(5000 /* contentLength */);
|
||||
verify(mockTransferListener).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||
}
|
||||
|
||||
|
|
@ -247,7 +244,7 @@ public final class CronetDataSourceTest {
|
|||
fail("HttpDataSource.HttpDataSourceException expected");
|
||||
} catch (HttpDataSourceException e) {
|
||||
// Check for connection not automatically closed.
|
||||
assertFalse(e.getCause() instanceof UnknownHostException);
|
||||
assertThat(e.getCause() instanceof UnknownHostException).isFalse();
|
||||
verify(mockUrlRequest, never()).cancel();
|
||||
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||
}
|
||||
|
|
@ -264,7 +261,7 @@ public final class CronetDataSourceTest {
|
|||
fail("HttpDataSource.HttpDataSourceException expected");
|
||||
} catch (HttpDataSourceException e) {
|
||||
// Check for connection not automatically closed.
|
||||
assertTrue(e.getCause() instanceof UnknownHostException);
|
||||
assertThat(e.getCause() instanceof UnknownHostException).isTrue();
|
||||
verify(mockUrlRequest, never()).cancel();
|
||||
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||
}
|
||||
|
|
@ -279,7 +276,7 @@ public final class CronetDataSourceTest {
|
|||
dataSourceUnderTest.open(testDataSpec);
|
||||
fail("HttpDataSource.HttpDataSourceException expected");
|
||||
} catch (HttpDataSourceException e) {
|
||||
assertTrue(e instanceof HttpDataSource.InvalidResponseCodeException);
|
||||
assertThat(e instanceof HttpDataSource.InvalidResponseCodeException).isTrue();
|
||||
// Check for connection not automatically closed.
|
||||
verify(mockUrlRequest, never()).cancel();
|
||||
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||
|
|
@ -295,7 +292,7 @@ public final class CronetDataSourceTest {
|
|||
dataSourceUnderTest.open(testDataSpec);
|
||||
fail("HttpDataSource.HttpDataSourceException expected");
|
||||
} catch (HttpDataSourceException e) {
|
||||
assertTrue(e instanceof HttpDataSource.InvalidContentTypeException);
|
||||
assertThat(e instanceof HttpDataSource.InvalidContentTypeException).isTrue();
|
||||
// Check for connection not automatically closed.
|
||||
verify(mockUrlRequest, never()).cancel();
|
||||
verify(mockContentTypePredicate).evaluate(TEST_CONTENT_TYPE);
|
||||
|
|
@ -307,7 +304,7 @@ public final class CronetDataSourceTest {
|
|||
mockResponseStartSuccess();
|
||||
|
||||
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
|
||||
assertEquals(TEST_CONTENT_LENGTH, dataSourceUnderTest.open(testPostDataSpec));
|
||||
assertThat(dataSourceUnderTest.open(testPostDataSpec)).isEqualTo(TEST_CONTENT_LENGTH);
|
||||
verify(mockTransferListener).onTransferStart(dataSourceUnderTest, testPostDataSpec);
|
||||
}
|
||||
|
||||
|
|
@ -346,13 +343,13 @@ public final class CronetDataSourceTest {
|
|||
|
||||
byte[] returnedBuffer = new byte[8];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||
assertArrayEquals(buildTestDataArray(0, 8), returnedBuffer);
|
||||
assertEquals(8, bytesRead);
|
||||
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(0, 8));
|
||||
assertThat(bytesRead).isEqualTo(8);
|
||||
|
||||
returnedBuffer = new byte[8];
|
||||
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||
assertArrayEquals(buildTestDataArray(8, 8), returnedBuffer);
|
||||
assertEquals(8, bytesRead);
|
||||
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(8, 8));
|
||||
assertThat(bytesRead).isEqualTo(8);
|
||||
|
||||
// Should have only called read on cronet once.
|
||||
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
||||
|
|
@ -378,11 +375,11 @@ public final class CronetDataSourceTest {
|
|||
dataSourceUnderTest.open(testDataSpec);
|
||||
returnedBuffer = new byte[16];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
||||
assertEquals(10, bytesRead);
|
||||
assertThat(bytesRead).isEqualTo(10);
|
||||
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
||||
assertEquals(6, bytesRead);
|
||||
assertThat(bytesRead).isEqualTo(6);
|
||||
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
||||
assertEquals(C.RESULT_END_OF_INPUT, bytesRead);
|
||||
assertThat(bytesRead).isEqualTo(C.RESULT_END_OF_INPUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -394,8 +391,8 @@ public final class CronetDataSourceTest {
|
|||
|
||||
byte[] returnedBuffer = new byte[16];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 8, 8);
|
||||
assertEquals(8, bytesRead);
|
||||
assertArrayEquals(prefixZeros(buildTestDataArray(0, 8), 16), returnedBuffer);
|
||||
assertThat(bytesRead).isEqualTo(8);
|
||||
assertThat(returnedBuffer).isEqualTo(prefixZeros(buildTestDataArray(0, 8), 16));
|
||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 8);
|
||||
}
|
||||
|
||||
|
|
@ -410,8 +407,8 @@ public final class CronetDataSourceTest {
|
|||
|
||||
byte[] returnedBuffer = new byte[16];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||
assertEquals(16, bytesRead);
|
||||
assertArrayEquals(buildTestDataArray(1000, 16), returnedBuffer);
|
||||
assertThat(bytesRead).isEqualTo(16);
|
||||
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(1000, 16));
|
||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
||||
}
|
||||
|
||||
|
|
@ -426,8 +423,8 @@ public final class CronetDataSourceTest {
|
|||
|
||||
byte[] returnedBuffer = new byte[16];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||
assertEquals(16, bytesRead);
|
||||
assertArrayEquals(buildTestDataArray(1000, 16), returnedBuffer);
|
||||
assertThat(bytesRead).isEqualTo(16);
|
||||
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(1000, 16));
|
||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
||||
}
|
||||
|
||||
|
|
@ -441,8 +438,8 @@ public final class CronetDataSourceTest {
|
|||
|
||||
byte[] returnedBuffer = new byte[16];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 8, 8);
|
||||
assertArrayEquals(prefixZeros(buildTestDataArray(0, 8), 16), returnedBuffer);
|
||||
assertEquals(8, bytesRead);
|
||||
assertThat(returnedBuffer).isEqualTo(prefixZeros(buildTestDataArray(0, 8), 16));
|
||||
assertThat(bytesRead).isEqualTo(8);
|
||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 8);
|
||||
}
|
||||
|
||||
|
|
@ -455,8 +452,8 @@ public final class CronetDataSourceTest {
|
|||
|
||||
byte[] returnedBuffer = new byte[24];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 24);
|
||||
assertArrayEquals(suffixZeros(buildTestDataArray(0, 16), 24), returnedBuffer);
|
||||
assertEquals(16, bytesRead);
|
||||
assertThat(returnedBuffer).isEqualTo(suffixZeros(buildTestDataArray(0, 16), 24));
|
||||
assertThat(bytesRead).isEqualTo(16);
|
||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
||||
}
|
||||
|
||||
|
|
@ -470,8 +467,8 @@ public final class CronetDataSourceTest {
|
|||
|
||||
byte[] returnedBuffer = new byte[8];
|
||||
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||
assertArrayEquals(buildTestDataArray(0, 8), returnedBuffer);
|
||||
assertEquals(8, bytesRead);
|
||||
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(0, 8));
|
||||
assertThat(bytesRead).isEqualTo(8);
|
||||
|
||||
dataSourceUnderTest.close();
|
||||
verify(mockTransferListener).onTransferEnd(dataSourceUnderTest);
|
||||
|
|
@ -484,7 +481,7 @@ public final class CronetDataSourceTest {
|
|||
}
|
||||
|
||||
// 16 bytes were attempted but only 8 should have been successfully read.
|
||||
assertEquals(8, bytesRead);
|
||||
assertThat(bytesRead).isEqualTo(8);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -498,20 +495,20 @@ public final class CronetDataSourceTest {
|
|||
|
||||
byte[] returnedBuffer = new byte[8];
|
||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||
assertEquals(8, bytesRead);
|
||||
assertArrayEquals(buildTestDataArray(0, 8), returnedBuffer);
|
||||
assertThat(bytesRead).isEqualTo(8);
|
||||
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(0, 8));
|
||||
|
||||
// The current buffer is kept if not completely consumed by DataSource reader.
|
||||
returnedBuffer = new byte[8];
|
||||
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 6);
|
||||
assertEquals(14, bytesRead);
|
||||
assertArrayEquals(suffixZeros(buildTestDataArray(8, 6), 8), returnedBuffer);
|
||||
assertThat(bytesRead).isEqualTo(14);
|
||||
assertThat(returnedBuffer).isEqualTo(suffixZeros(buildTestDataArray(8, 6), 8));
|
||||
|
||||
// 2 bytes left at this point.
|
||||
returnedBuffer = new byte[8];
|
||||
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||
assertEquals(16, bytesRead);
|
||||
assertArrayEquals(suffixZeros(buildTestDataArray(14, 2), 8), returnedBuffer);
|
||||
assertThat(bytesRead).isEqualTo(16);
|
||||
assertThat(returnedBuffer).isEqualTo(suffixZeros(buildTestDataArray(14, 2), 8));
|
||||
|
||||
// Should have only called read on cronet once.
|
||||
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
||||
|
|
@ -524,8 +521,8 @@ public final class CronetDataSourceTest {
|
|||
// Return C.RESULT_END_OF_INPUT
|
||||
returnedBuffer = new byte[16];
|
||||
int bytesOverRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||
assertEquals(C.RESULT_END_OF_INPUT, bytesOverRead);
|
||||
assertArrayEquals(new byte[16], returnedBuffer);
|
||||
assertThat(bytesOverRead).isEqualTo(C.RESULT_END_OF_INPUT);
|
||||
assertThat(returnedBuffer).isEqualTo(new byte[16]);
|
||||
// C.RESULT_END_OF_INPUT should not be reported though the TransferListener.
|
||||
verify(mockTransferListener, never()).onBytesTransferred(dataSourceUnderTest,
|
||||
C.RESULT_END_OF_INPUT);
|
||||
|
|
@ -533,7 +530,7 @@ public final class CronetDataSourceTest {
|
|||
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
||||
// Check for connection not automatically closed.
|
||||
verify(mockUrlRequest, never()).cancel();
|
||||
assertEquals(16, bytesRead);
|
||||
assertThat(bytesRead).isEqualTo(16);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -550,11 +547,10 @@ public final class CronetDataSourceTest {
|
|||
fail();
|
||||
} catch (HttpDataSourceException e) {
|
||||
// Expected.
|
||||
assertTrue(e instanceof CronetDataSource.OpenException);
|
||||
assertTrue(e.getCause() instanceof SocketTimeoutException);
|
||||
assertEquals(
|
||||
TEST_CONNECTION_STATUS,
|
||||
((CronetDataSource.OpenException) e).cronetConnectionStatus);
|
||||
assertThat(e instanceof CronetDataSource.OpenException).isTrue();
|
||||
assertThat(e.getCause() instanceof SocketTimeoutException).isTrue();
|
||||
assertThat(((CronetDataSource.OpenException) e).cronetConnectionStatus)
|
||||
.isEqualTo(TEST_CONNECTION_STATUS);
|
||||
timedOutCondition.open();
|
||||
}
|
||||
}
|
||||
|
|
@ -562,10 +558,10 @@ public final class CronetDataSourceTest {
|
|||
startCondition.block();
|
||||
|
||||
// We should still be trying to open.
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// We should still be trying to open as we approach the timeout.
|
||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// Now we timeout.
|
||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS);
|
||||
timedOutCondition.block();
|
||||
|
|
@ -588,11 +584,10 @@ public final class CronetDataSourceTest {
|
|||
fail();
|
||||
} catch (HttpDataSourceException e) {
|
||||
// Expected.
|
||||
assertTrue(e instanceof CronetDataSource.OpenException);
|
||||
assertTrue(e.getCause() instanceof CronetDataSource.InterruptedIOException);
|
||||
assertEquals(
|
||||
TEST_INVALID_CONNECTION_STATUS,
|
||||
((CronetDataSource.OpenException) e).cronetConnectionStatus);
|
||||
assertThat(e instanceof CronetDataSource.OpenException).isTrue();
|
||||
assertThat(e.getCause() instanceof CronetDataSource.InterruptedIOException).isTrue();
|
||||
assertThat(((CronetDataSource.OpenException) e).cronetConnectionStatus)
|
||||
.isEqualTo(TEST_INVALID_CONNECTION_STATUS);
|
||||
timedOutCondition.open();
|
||||
}
|
||||
}
|
||||
|
|
@ -601,10 +596,10 @@ public final class CronetDataSourceTest {
|
|||
startCondition.block();
|
||||
|
||||
// We should still be trying to open.
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// We should still be trying to open as we approach the timeout.
|
||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// Now we interrupt.
|
||||
thread.interrupt();
|
||||
timedOutCondition.block();
|
||||
|
|
@ -632,10 +627,10 @@ public final class CronetDataSourceTest {
|
|||
startCondition.block();
|
||||
|
||||
// We should still be trying to open.
|
||||
assertFalse(openCondition.block(50));
|
||||
assertThat(openCondition.block(50)).isFalse();
|
||||
// We should still be trying to open as we approach the timeout.
|
||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
||||
assertFalse(openCondition.block(50));
|
||||
assertThat(openCondition.block(50)).isFalse();
|
||||
// The response arrives just in time.
|
||||
dataSourceUnderTest.onResponseStarted(mockUrlRequest, testUrlResponseInfo);
|
||||
openCondition.block();
|
||||
|
|
@ -656,8 +651,8 @@ public final class CronetDataSourceTest {
|
|||
fail();
|
||||
} catch (HttpDataSourceException e) {
|
||||
// Expected.
|
||||
assertTrue(e instanceof CronetDataSource.OpenException);
|
||||
assertTrue(e.getCause() instanceof SocketTimeoutException);
|
||||
assertThat(e instanceof CronetDataSource.OpenException).isTrue();
|
||||
assertThat(e.getCause() instanceof SocketTimeoutException).isTrue();
|
||||
openExceptions.getAndIncrement();
|
||||
timedOutCondition.open();
|
||||
}
|
||||
|
|
@ -666,10 +661,10 @@ public final class CronetDataSourceTest {
|
|||
startCondition.block();
|
||||
|
||||
// We should still be trying to open.
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// We should still be trying to open as we approach the timeout.
|
||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// A redirect arrives just in time.
|
||||
dataSourceUnderTest.onRedirectReceived(mockUrlRequest, testUrlResponseInfo,
|
||||
"RandomRedirectedUrl1");
|
||||
|
|
@ -677,9 +672,9 @@ public final class CronetDataSourceTest {
|
|||
long newTimeoutMs = 2 * TEST_CONNECT_TIMEOUT_MS - 1;
|
||||
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs - 1);
|
||||
// Give the thread some time to run.
|
||||
assertFalse(timedOutCondition.block(newTimeoutMs));
|
||||
assertThat(timedOutCondition.block(newTimeoutMs)).isFalse();
|
||||
// We should still be trying to open as we approach the new timeout.
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// A redirect arrives just in time.
|
||||
dataSourceUnderTest.onRedirectReceived(mockUrlRequest, testUrlResponseInfo,
|
||||
"RandomRedirectedUrl2");
|
||||
|
|
@ -687,15 +682,15 @@ public final class CronetDataSourceTest {
|
|||
newTimeoutMs = 3 * TEST_CONNECT_TIMEOUT_MS - 2;
|
||||
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs - 1);
|
||||
// Give the thread some time to run.
|
||||
assertFalse(timedOutCondition.block(newTimeoutMs));
|
||||
assertThat(timedOutCondition.block(newTimeoutMs)).isFalse();
|
||||
// We should still be trying to open as we approach the new timeout.
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// Now we timeout.
|
||||
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs);
|
||||
timedOutCondition.block();
|
||||
|
||||
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||
assertEquals(1, openExceptions.get());
|
||||
assertThat(openExceptions.get()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -855,7 +850,7 @@ public final class CronetDataSourceTest {
|
|||
fail();
|
||||
} catch (HttpDataSourceException e) {
|
||||
// Expected.
|
||||
assertTrue(e.getCause() instanceof CronetDataSource.InterruptedIOException);
|
||||
assertThat(e.getCause() instanceof CronetDataSource.InterruptedIOException).isTrue();
|
||||
timedOutCondition.open();
|
||||
}
|
||||
}
|
||||
|
|
@ -863,7 +858,7 @@ public final class CronetDataSourceTest {
|
|||
thread.start();
|
||||
startCondition.block();
|
||||
|
||||
assertFalse(timedOutCondition.block(50));
|
||||
assertThat(timedOutCondition.block(50)).isFalse();
|
||||
// Now we interrupt.
|
||||
thread.interrupt();
|
||||
timedOutCondition.block();
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
compile project(modulePrefix + 'library-core')
|
||||
androidTestCompile 'com.google.truth:truth:' + truthVersion
|
||||
}
|
||||
|
||||
ext {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.ext.vp9;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Looper;
|
||||
|
|
@ -73,8 +75,8 @@ public class VpxPlaybackTest extends InstrumentationTestCase {
|
|||
playUri(INVALID_BITSTREAM_URI);
|
||||
fail();
|
||||
} catch (Exception e) {
|
||||
assertNotNull(e.getCause());
|
||||
assertTrue(e.getCause() instanceof VpxDecoderException);
|
||||
assertThat(e.getCause()).isNotNull();
|
||||
assertThat(e.getCause()).isInstanceOf(VpxDecoderException.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ dependencies {
|
|||
compile 'com.android.support:support-annotations:' + supportLibraryVersion
|
||||
androidTestCompile 'com.google.dexmaker:dexmaker:' + dexmakerVersion
|
||||
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:' + dexmakerVersion
|
||||
androidTestCompile 'com.google.truth:truth:' + truthVersion
|
||||
androidTestCompile 'org.mockito:mockito-core:' + mockitoVersion
|
||||
testCompile 'com.google.truth:truth:' + truthVersion
|
||||
testCompile 'junit:junit:' + junitVersion
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.view.Surface;
|
||||
import com.google.android.exoplayer2.Player.DefaultEventListener;
|
||||
import com.google.android.exoplayer2.Player.EventListener;
|
||||
|
|
@ -66,7 +68,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
Timeline timeline = Timeline.EMPTY;
|
||||
FakeRenderer renderer = new FakeRenderer();
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setRenderers(renderer)
|
||||
.build()
|
||||
|
|
@ -74,9 +76,9 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.blockUntilEnded(TIMEOUT_MS);
|
||||
testRunner.assertNoPositionDiscontinuities();
|
||||
testRunner.assertTimelinesEqual(timeline);
|
||||
assertEquals(0, renderer.formatReadCount);
|
||||
assertEquals(0, renderer.bufferReadCount);
|
||||
assertFalse(renderer.isEnded);
|
||||
assertThat(renderer.formatReadCount).isEqualTo(0);
|
||||
assertThat(renderer.bufferReadCount).isEqualTo(0);
|
||||
assertThat(renderer.isEnded).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,17 +88,22 @@ public final class ExoPlayerTest extends TestCase {
|
|||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||
Object manifest = new Object();
|
||||
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
||||
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
|
||||
.setTimeline(timeline).setManifest(manifest).setRenderers(renderer)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setManifest(manifest)
|
||||
.setRenderers(renderer)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
testRunner.assertNoPositionDiscontinuities();
|
||||
testRunner.assertTimelinesEqual(timeline);
|
||||
testRunner.assertManifestsEqual(manifest);
|
||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||
testRunner.assertTrackGroupsEqual(new TrackGroupArray(new TrackGroup(Builder.VIDEO_FORMAT)));
|
||||
assertEquals(1, renderer.formatReadCount);
|
||||
assertEquals(1, renderer.bufferReadCount);
|
||||
assertTrue(renderer.isEnded);
|
||||
assertThat(renderer.formatReadCount).isEqualTo(1);
|
||||
assertThat(renderer.bufferReadCount).isEqualTo(1);
|
||||
assertThat(renderer.isEnded).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -105,17 +112,21 @@ public final class ExoPlayerTest extends TestCase {
|
|||
public void testPlayMultiPeriodTimeline() throws Exception {
|
||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 3);
|
||||
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
||||
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
|
||||
.setTimeline(timeline).setRenderers(renderer)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setRenderers(renderer)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
testRunner.assertPositionDiscontinuityReasonsEqual(
|
||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||
testRunner.assertTimelinesEqual(timeline);
|
||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||
assertEquals(3, renderer.formatReadCount);
|
||||
assertEquals(1, renderer.bufferReadCount);
|
||||
assertTrue(renderer.isEnded);
|
||||
assertThat(renderer.formatReadCount).isEqualTo(3);
|
||||
assertThat(renderer.bufferReadCount).isEqualTo(1);
|
||||
assertThat(renderer.isEnded).isTrue();
|
||||
}
|
||||
|
||||
/** Tests playback of periods with very short duration. */
|
||||
|
|
@ -125,20 +136,20 @@ public final class ExoPlayerTest extends TestCase {
|
|||
new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */ 100, /* id= */ 0));
|
||||
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setRenderers(renderer)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
int[] expectedReasons = new int[99];
|
||||
Integer[] expectedReasons = new Integer[99];
|
||||
Arrays.fill(expectedReasons, Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||
testRunner.assertPositionDiscontinuityReasonsEqual(expectedReasons);
|
||||
testRunner.assertTimelinesEqual(timeline);
|
||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||
assertEquals(100, renderer.formatReadCount);
|
||||
assertEquals(1, renderer.bufferReadCount);
|
||||
assertTrue(renderer.isEnded);
|
||||
assertThat(renderer.formatReadCount).isEqualTo(100);
|
||||
assertThat(renderer.bufferReadCount).isEqualTo(1);
|
||||
assertThat(renderer.isEnded).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -175,17 +186,21 @@ public final class ExoPlayerTest extends TestCase {
|
|||
}
|
||||
|
||||
};
|
||||
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
|
||||
.setTimeline(timeline).setRenderers(videoRenderer, audioRenderer)
|
||||
.setSupportedFormats(Builder.VIDEO_FORMAT, Builder.AUDIO_FORMAT)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setRenderers(videoRenderer, audioRenderer)
|
||||
.setSupportedFormats(Builder.VIDEO_FORMAT, Builder.AUDIO_FORMAT)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
testRunner.assertPositionDiscontinuityReasonsEqual(
|
||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||
testRunner.assertTimelinesEqual(timeline);
|
||||
assertEquals(1, audioRenderer.positionResetCount);
|
||||
assertTrue(videoRenderer.isEnded);
|
||||
assertTrue(audioRenderer.isEnded);
|
||||
assertThat(audioRenderer.positionResetCount).isEqualTo(1);
|
||||
assertThat(videoRenderer.isEnded).isTrue();
|
||||
assertThat(audioRenderer.isEnded).isTrue();
|
||||
}
|
||||
|
||||
public void testRepreparationGivesFreshSourceInfo() throws Exception {
|
||||
|
|
@ -196,21 +211,25 @@ public final class ExoPlayerTest extends TestCase {
|
|||
Builder.VIDEO_FORMAT);
|
||||
final CountDownLatch queuedSourceInfoCountDownLatch = new CountDownLatch(1);
|
||||
final CountDownLatch completePreparationCountDownLatch = new CountDownLatch(1);
|
||||
MediaSource secondSource = new FakeMediaSource(timeline, new Object(), Builder.VIDEO_FORMAT) {
|
||||
@Override
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
super.prepareSource(player, isTopLevelSource, listener);
|
||||
// We've queued a source info refresh on the playback thread's event queue. Allow the test
|
||||
// thread to prepare the player with the third source, and block this thread (the playback
|
||||
// thread) until the test thread's call to prepare() has returned.
|
||||
queuedSourceInfoCountDownLatch.countDown();
|
||||
try {
|
||||
completePreparationCountDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
MediaSource secondSource =
|
||||
new FakeMediaSource(timeline, new Object(), Builder.VIDEO_FORMAT) {
|
||||
@Override
|
||||
public synchronized void prepareSource(
|
||||
ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
super.prepareSource(player, isTopLevelSource, listener);
|
||||
// We've queued a source info refresh on the playback thread's event queue. Allow the
|
||||
// test
|
||||
// thread to prepare the player with the third source, and block this thread (the
|
||||
// playback
|
||||
// thread) until the test thread's call to prepare() has returned.
|
||||
queuedSourceInfoCountDownLatch.countDown();
|
||||
try {
|
||||
completePreparationCountDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
Object thirdSourceManifest = new Object();
|
||||
MediaSource thirdSource = new FakeMediaSource(timeline, thirdSourceManifest,
|
||||
Builder.VIDEO_FORMAT);
|
||||
|
|
@ -240,9 +259,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
}
|
||||
})
|
||||
.build();
|
||||
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
|
||||
.setMediaSource(firstSource).setRenderers(renderer).setActionSchedule(actionSchedule)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new Builder()
|
||||
.setMediaSource(firstSource)
|
||||
.setRenderers(renderer)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
testRunner.assertNoPositionDiscontinuities();
|
||||
// The first source's preparation completed with a non-empty timeline. When the player was
|
||||
// re-prepared with the second source, it immediately exposed an empty timeline, but the source
|
||||
|
|
@ -252,7 +276,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED,
|
||||
Player.TIMELINE_CHANGE_REASON_RESET, Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||
testRunner.assertTrackGroupsEqual(new TrackGroupArray(new TrackGroup(Builder.VIDEO_FORMAT)));
|
||||
assertTrue(renderer.isEnded);
|
||||
assertThat(renderer.isEnded).isTrue();
|
||||
}
|
||||
|
||||
public void testRepeatModeChanges() throws Exception {
|
||||
|
|
@ -293,7 +317,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||
testRunner.assertTimelinesEqual(timeline);
|
||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||
assertTrue(renderer.isEnded);
|
||||
assertThat(renderer.isEnded).isTrue();
|
||||
}
|
||||
|
||||
public void testShuffleModeEnabledChanges() throws Exception {
|
||||
|
|
@ -328,22 +352,26 @@ public final class ExoPlayerTest extends TestCase {
|
|||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||
assertTrue(renderer.isEnded);
|
||||
assertThat(renderer.isEnded).isTrue();
|
||||
}
|
||||
|
||||
public void testPeriodHoldersReleasedAfterSeekWithRepeatModeAll() throws Exception {
|
||||
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
||||
ActionSchedule actionSchedule = new ActionSchedule.Builder("testPeriodHoldersReleased")
|
||||
.setRepeatMode(Player.REPEAT_MODE_ALL)
|
||||
.waitForPositionDiscontinuity()
|
||||
.seek(0) // Seek with repeat mode set to REPEAT_MODE_ALL.
|
||||
.waitForPositionDiscontinuity()
|
||||
.setRepeatMode(Player.REPEAT_MODE_OFF) // Turn off repeat so that playback can finish.
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
.setRenderers(renderer).setActionSchedule(actionSchedule)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(renderer.isEnded);
|
||||
ActionSchedule actionSchedule =
|
||||
new ActionSchedule.Builder("testPeriodHoldersReleased")
|
||||
.setRepeatMode(Player.REPEAT_MODE_ALL)
|
||||
.waitForPositionDiscontinuity()
|
||||
.seek(0) // Seek with repeat mode set to Player.REPEAT_MODE_ALL.
|
||||
.waitForPositionDiscontinuity()
|
||||
.setRepeatMode(Player.REPEAT_MODE_OFF) // Turn off repeat so that playback can finish.
|
||||
.build();
|
||||
new Builder()
|
||||
.setRenderers(renderer)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertThat(renderer.isEnded).isTrue();
|
||||
}
|
||||
|
||||
public void testSeekProcessedCallback() throws Exception {
|
||||
|
|
@ -359,7 +387,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.seek(2)
|
||||
.seek(10)
|
||||
// Wait until media source prepared and re-seek to same position. Expect a seek
|
||||
// processed while still being in STATE_READY.
|
||||
// processed while still being in Player.STATE_READY.
|
||||
.waitForPlaybackState(Player.STATE_READY)
|
||||
.seek(10)
|
||||
// Start playback and wait until playback reaches second window.
|
||||
|
|
@ -371,19 +399,20 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.seek(60)
|
||||
.build();
|
||||
final List<Integer> playbackStatesWhenSeekProcessed = new ArrayList<>();
|
||||
Player.EventListener eventListener = new Player.DefaultEventListener() {
|
||||
private int currentPlaybackState = Player.STATE_IDLE;
|
||||
EventListener eventListener =
|
||||
new DefaultEventListener() {
|
||||
private int currentPlaybackState = Player.STATE_IDLE;
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
currentPlaybackState = playbackState;
|
||||
}
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
currentPlaybackState = playbackState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSeekProcessed() {
|
||||
playbackStatesWhenSeekProcessed.add(currentPlaybackState);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void onSeekProcessed() {
|
||||
playbackStatesWhenSeekProcessed.add(currentPlaybackState);
|
||||
}
|
||||
};
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
.setTimeline(timeline)
|
||||
|
|
@ -400,11 +429,13 @@ public final class ExoPlayerTest extends TestCase {
|
|||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
||||
Player.DISCONTINUITY_REASON_SEEK,
|
||||
Player.DISCONTINUITY_REASON_SEEK);
|
||||
assertEquals(4, playbackStatesWhenSeekProcessed.size());
|
||||
assertEquals(Player.STATE_BUFFERING, (int) playbackStatesWhenSeekProcessed.get(0));
|
||||
assertEquals(Player.STATE_BUFFERING, (int) playbackStatesWhenSeekProcessed.get(1));
|
||||
assertEquals(Player.STATE_READY, (int) playbackStatesWhenSeekProcessed.get(2));
|
||||
assertEquals(Player.STATE_BUFFERING, (int) playbackStatesWhenSeekProcessed.get(3));
|
||||
assertThat(playbackStatesWhenSeekProcessed)
|
||||
.containsExactly(
|
||||
Player.STATE_BUFFERING,
|
||||
Player.STATE_BUFFERING,
|
||||
Player.STATE_READY,
|
||||
Player.STATE_BUFFERING)
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
public void testSeekProcessedCalledWithIllegalSeekPosition() throws Exception {
|
||||
|
|
@ -427,17 +458,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
}
|
||||
};
|
||||
ExoPlayerTestRunner testRunner =
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
.setActionSchedule(actionSchedule)
|
||||
.setEventListener(listener)
|
||||
.build();
|
||||
new Builder().setActionSchedule(actionSchedule).setEventListener(listener).build();
|
||||
try {
|
||||
testRunner.start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
|
||||
fail();
|
||||
} catch (ExoPlaybackException e) {
|
||||
// Expected exception.
|
||||
}
|
||||
assertTrue(onSeekProcessedCalled[0]);
|
||||
assertThat(onSeekProcessedCalled[0]).isTrue();
|
||||
}
|
||||
|
||||
public void testSeekDiscontinuity() throws Exception {
|
||||
|
|
@ -514,24 +542,26 @@ public final class ExoPlayerTest extends TestCase {
|
|||
FakeRenderer audioRenderer = new FakeRenderer(Builder.AUDIO_FORMAT);
|
||||
FakeTrackSelector trackSelector = new FakeTrackSelector();
|
||||
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setMediaSource(mediaSource)
|
||||
.setRenderers(videoRenderer, audioRenderer)
|
||||
.setTrackSelector(trackSelector)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
|
||||
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
||||
int numSelectionsEnabled = 0;
|
||||
// Assert that all tracks selection are disabled at the end of the playback.
|
||||
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
||||
assertFalse(trackSelection.isEnabled);
|
||||
assertThat(trackSelection.isEnabled).isFalse();
|
||||
numSelectionsEnabled += trackSelection.enableCount;
|
||||
}
|
||||
// There are 2 renderers, and track selections are made once (1 period).
|
||||
// Track selections are not reused, so there are 2 track selections made.
|
||||
assertEquals(2, createdTrackSelections.size());
|
||||
assertThat(createdTrackSelections).hasSize(2);
|
||||
// There should be 2 track selections enabled in total.
|
||||
assertEquals(2, numSelectionsEnabled);
|
||||
assertThat(numSelectionsEnabled).isEqualTo(2);
|
||||
}
|
||||
|
||||
public void testAllActivatedTrackSelectionAreReleasedForMultiPeriods() throws Exception {
|
||||
|
|
@ -542,24 +572,26 @@ public final class ExoPlayerTest extends TestCase {
|
|||
FakeRenderer audioRenderer = new FakeRenderer(Builder.AUDIO_FORMAT);
|
||||
FakeTrackSelector trackSelector = new FakeTrackSelector();
|
||||
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setMediaSource(mediaSource)
|
||||
.setRenderers(videoRenderer, audioRenderer)
|
||||
.setTrackSelector(trackSelector)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
|
||||
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
||||
int numSelectionsEnabled = 0;
|
||||
// Assert that all tracks selection are disabled at the end of the playback.
|
||||
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
||||
assertFalse(trackSelection.isEnabled);
|
||||
assertThat(trackSelection.isEnabled).isFalse();
|
||||
numSelectionsEnabled += trackSelection.enableCount;
|
||||
}
|
||||
// There are 2 renderers, and track selections are made twice (2 periods).
|
||||
// Track selections are not reused, so there are 4 track selections made.
|
||||
assertEquals(4, createdTrackSelections.size());
|
||||
assertThat(createdTrackSelections).hasSize(4);
|
||||
// There should be 4 track selections enabled in total.
|
||||
assertEquals(4, numSelectionsEnabled);
|
||||
assertThat(numSelectionsEnabled).isEqualTo(4);
|
||||
}
|
||||
|
||||
public void testAllActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreRemade()
|
||||
|
|
@ -584,26 +616,28 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.play()
|
||||
.build();
|
||||
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setMediaSource(mediaSource)
|
||||
.setRenderers(videoRenderer, audioRenderer)
|
||||
.setTrackSelector(trackSelector)
|
||||
.setActionSchedule(disableTrackAction)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
|
||||
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
||||
int numSelectionsEnabled = 0;
|
||||
// Assert that all tracks selection are disabled at the end of the playback.
|
||||
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
||||
assertFalse(trackSelection.isEnabled);
|
||||
assertThat(trackSelection.isEnabled).isFalse();
|
||||
numSelectionsEnabled += trackSelection.enableCount;
|
||||
}
|
||||
// There are 2 renderers, and track selections are made twice.
|
||||
// Track selections are not reused, so there are 4 track selections made.
|
||||
assertEquals(4, createdTrackSelections.size());
|
||||
assertThat(createdTrackSelections).hasSize(4);
|
||||
// Initially there are 2 track selections enabled.
|
||||
// The second time one renderer is disabled, so only 1 track selection should be enabled.
|
||||
assertEquals(3, numSelectionsEnabled);
|
||||
assertThat(numSelectionsEnabled).isEqualTo(3);
|
||||
}
|
||||
|
||||
public void testAllActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreUsed()
|
||||
|
|
@ -628,26 +662,28 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.play()
|
||||
.build();
|
||||
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setMediaSource(mediaSource)
|
||||
.setRenderers(videoRenderer, audioRenderer)
|
||||
.setTrackSelector(trackSelector)
|
||||
.setActionSchedule(disableTrackAction)
|
||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
|
||||
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
||||
int numSelectionsEnabled = 0;
|
||||
// Assert that all tracks selection are disabled at the end of the playback.
|
||||
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
||||
assertFalse(trackSelection.isEnabled);
|
||||
assertThat(trackSelection.isEnabled).isFalse();
|
||||
numSelectionsEnabled += trackSelection.enableCount;
|
||||
}
|
||||
// There are 2 renderers, and track selections are made twice.
|
||||
// TrackSelections are reused, so there are only 2 track selections made for 2 renderers.
|
||||
assertEquals(2, createdTrackSelections.size());
|
||||
assertThat(createdTrackSelections).hasSize(2);
|
||||
// Initially there are 2 track selections enabled.
|
||||
// The second time one renderer is disabled, so only 1 track selection should be enabled.
|
||||
assertEquals(3, numSelectionsEnabled);
|
||||
assertThat(numSelectionsEnabled).isEqualTo(3);
|
||||
}
|
||||
|
||||
public void testDynamicTimelineChangeReason() throws Exception {
|
||||
|
|
@ -779,7 +815,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
testRunner.assertTimelinesEqual(timeline);
|
||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||
testRunner.assertNoPositionDiscontinuities();
|
||||
assertTrue(positionHolder[0] >= 50);
|
||||
assertThat(positionHolder[0]).isAtLeast(50L);
|
||||
}
|
||||
|
||||
public void testStopWithoutResetDoesNotResetPosition() throws Exception {
|
||||
|
|
@ -810,7 +846,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
testRunner.assertTimelinesEqual(timeline);
|
||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||
testRunner.assertNoPositionDiscontinuities();
|
||||
assertTrue(positionHolder[0] >= 50);
|
||||
assertThat(positionHolder[0]).isAtLeast(50L);
|
||||
}
|
||||
|
||||
public void testStopWithResetDoesResetPosition() throws Exception {
|
||||
|
|
@ -842,7 +878,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED,
|
||||
Player.TIMELINE_CHANGE_REASON_RESET);
|
||||
testRunner.assertNoPositionDiscontinuities();
|
||||
assertEquals(0, positionHolder[0]);
|
||||
assertThat(positionHolder[0]).isEqualTo(0);
|
||||
}
|
||||
|
||||
public void testStopWithoutResetReleasesMediaSource() throws Exception {
|
||||
|
|
@ -1058,8 +1094,8 @@ public final class ExoPlayerTest extends TestCase {
|
|||
Player.TIMELINE_CHANGE_REASON_PREPARED, Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||
testRunner.assertPositionDiscontinuityReasonsEqual(
|
||||
Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_SEEK);
|
||||
assertEquals(50, positionHolder[0]);
|
||||
assertEquals(50, positionHolder[1]);
|
||||
assertThat(positionHolder[0]).isEqualTo(50);
|
||||
assertThat(positionHolder[1]).isEqualTo(50);
|
||||
}
|
||||
|
||||
public void testPlaybackErrorDuringSourceInfoRefreshStillUpdatesTimeline() throws Exception {
|
||||
|
|
@ -1107,13 +1143,13 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.sendMessage(target, /* positionMs= */ 50)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesAfterPreparation() throws Exception {
|
||||
|
|
@ -1126,13 +1162,13 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.sendMessage(target, /* positionMs= */ 50)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testMultipleSendMessages() throws Exception {
|
||||
|
|
@ -1147,15 +1183,15 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.sendMessage(target50, /* positionMs= */ 50)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target50.positionMs >= 50);
|
||||
assertTrue(target80.positionMs >= 80);
|
||||
assertTrue(target80.positionMs >= target50.positionMs);
|
||||
assertThat(target50.positionMs >= 50).isTrue();
|
||||
assertThat(target80.positionMs >= 80).isTrue();
|
||||
assertThat(target80.positionMs).isAtLeast(target50.positionMs);
|
||||
}
|
||||
|
||||
public void testMultipleSendMessagesAtSameTime() throws Exception {
|
||||
|
|
@ -1170,14 +1206,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.sendMessage(target2, /* positionMs= */ 50)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target1.positionMs >= 50);
|
||||
assertTrue(target2.positionMs >= 50);
|
||||
assertThat(target1.positionMs >= 50).isTrue();
|
||||
assertThat(target2.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesMultiPeriodResolution() throws Exception {
|
||||
|
|
@ -1191,13 +1227,13 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.sendMessage(target, /* positionMs= */ 50)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesAtStartAndEndOfPeriod() throws Exception {
|
||||
|
|
@ -1226,21 +1262,21 @@ public final class ExoPlayerTest extends TestCase {
|
|||
/* resetState= */ true)
|
||||
.waitForPlaybackState(Player.STATE_READY)
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilActionScheduleFinished(TIMEOUT_MS)
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(0, targetStartFirstPeriod.windowIndex);
|
||||
assertTrue(targetStartFirstPeriod.positionMs >= 0);
|
||||
assertEquals(0, targetEndMiddlePeriod.windowIndex);
|
||||
assertTrue(targetEndMiddlePeriod.positionMs >= duration1Ms);
|
||||
assertEquals(1, targetStartMiddlePeriod.windowIndex);
|
||||
assertTrue(targetStartMiddlePeriod.positionMs >= 0);
|
||||
assertEquals(1, targetEndLastPeriod.windowIndex);
|
||||
assertTrue(targetEndLastPeriod.positionMs >= duration2Ms);
|
||||
assertThat(targetStartFirstPeriod.windowIndex).isEqualTo(0);
|
||||
assertThat(targetStartFirstPeriod.positionMs).isAtLeast(0L);
|
||||
assertThat(targetEndMiddlePeriod.windowIndex).isEqualTo(0);
|
||||
assertThat(targetEndMiddlePeriod.positionMs).isAtLeast(duration1Ms);
|
||||
assertThat(targetStartMiddlePeriod.windowIndex).isEqualTo(1);
|
||||
assertThat(targetStartMiddlePeriod.positionMs).isAtLeast(0L);
|
||||
assertThat(targetEndLastPeriod.windowIndex).isEqualTo(1);
|
||||
assertThat(targetEndLastPeriod.positionMs).isAtLeast(duration2Ms);
|
||||
}
|
||||
|
||||
public void testSendMessagesSeekOnDeliveryTimeDuringPreparation() throws Exception {
|
||||
|
|
@ -1252,13 +1288,13 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.sendMessage(target, /* positionMs= */ 50)
|
||||
.seek(/* positionMs= */ 50)
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesSeekOnDeliveryTimeAfterPreparation() throws Exception {
|
||||
|
|
@ -1271,13 +1307,13 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.waitForTimelineChanged(timeline)
|
||||
.seek(/* positionMs= */ 50)
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesSeekAfterDeliveryTimeDuringPreparation() throws Exception {
|
||||
|
|
@ -1291,13 +1327,13 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.seek(/* positionMs= */ 51)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(C.POSITION_UNSET, target.positionMs);
|
||||
assertThat(target.positionMs).isEqualTo(C.POSITION_UNSET);
|
||||
}
|
||||
|
||||
public void testSendMessagesSeekAfterDeliveryTimeAfterPreparation() throws Exception {
|
||||
|
|
@ -1311,13 +1347,13 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.seek(/* positionMs= */ 51)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(C.POSITION_UNSET, target.positionMs);
|
||||
assertThat(target.positionMs).isEqualTo(C.POSITION_UNSET);
|
||||
}
|
||||
|
||||
public void testSendMessagesRepeatDoesNotRepost() throws Exception {
|
||||
|
|
@ -1333,14 +1369,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.waitForPositionDiscontinuity()
|
||||
.setRepeatMode(Player.REPEAT_MODE_OFF)
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(1, target.messageCount);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.messageCount).isEqualTo(1);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesRepeatWithoutDeletingDoesRepost() throws Exception {
|
||||
|
|
@ -1361,14 +1397,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.setRepeatMode(Player.REPEAT_MODE_OFF)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(2, target.messageCount);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.messageCount).isEqualTo(2);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesMoveCurrentWindowIndex() throws Exception {
|
||||
|
|
@ -1395,14 +1431,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.waitForTimelineChanged(secondTimeline)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setMediaSource(mediaSource)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertEquals(1, target.windowIndex);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
assertThat(target.windowIndex).isEqualTo(1);
|
||||
}
|
||||
|
||||
public void testSendMessagesMultiWindowDuringPreparation() throws Exception {
|
||||
|
|
@ -1415,14 +1451,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.sendMessage(target, /* windowIndex = */ 2, /* positionMs= */ 50)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(2, target.windowIndex);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.windowIndex).isEqualTo(2);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesMultiWindowAfterPreparation() throws Exception {
|
||||
|
|
@ -1435,14 +1471,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.sendMessage(target, /* windowIndex = */ 2, /* positionMs= */ 50)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setTimeline(timeline)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(2, target.windowIndex);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertThat(target.windowIndex).isEqualTo(2);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
}
|
||||
|
||||
public void testSendMessagesMoveWindowIndex() throws Exception {
|
||||
|
|
@ -1472,14 +1508,14 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.seek(/* windowIndex= */ 0, /* positionMs= */ 0)
|
||||
.play()
|
||||
.build();
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
new Builder()
|
||||
.setMediaSource(mediaSource)
|
||||
.setActionSchedule(actionSchedule)
|
||||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertTrue(target.positionMs >= 50);
|
||||
assertEquals(0, target.windowIndex);
|
||||
assertThat(target.positionMs >= 50).isTrue();
|
||||
assertThat(target.windowIndex).isEqualTo(0);
|
||||
}
|
||||
|
||||
public void testSendMessagesNonLinearPeriodOrder() throws Exception {
|
||||
|
|
@ -1511,9 +1547,9 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.build()
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(0, target1.windowIndex);
|
||||
assertEquals(1, target2.windowIndex);
|
||||
assertEquals(2, target3.windowIndex);
|
||||
assertThat(target1.windowIndex).isEqualTo(0);
|
||||
assertThat(target2.windowIndex).isEqualTo(1);
|
||||
assertThat(target3.windowIndex).isEqualTo(2);
|
||||
}
|
||||
|
||||
public void testSetAndSwitchSurface() throws Exception {
|
||||
|
|
@ -1535,7 +1571,7 @@ public final class ExoPlayerTest extends TestCase {
|
|||
.start()
|
||||
.blockUntilActionScheduleFinished(TIMEOUT_MS)
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
assertEquals(2, Collections.frequency(rendererMessages, C.MSG_SET_SURFACE));
|
||||
assertThat(Collections.frequency(rendererMessages, C.MSG_SET_SURFACE)).isEqualTo(2);
|
||||
}
|
||||
|
||||
public void testSwitchSurfaceOnEndedState() throws Exception {
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.drm;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.test.MoreAsserts;
|
||||
import android.util.Pair;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
||||
|
|
@ -86,7 +86,7 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
|||
|
||||
byte[] offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(newDrmInitData());
|
||||
|
||||
assertNull(offlineLicenseKeySetId);
|
||||
assertThat(offlineLicenseKeySetId).isNull();
|
||||
}
|
||||
|
||||
public void testDownloadLicenseDoesNotFailIfDurationNotAvailable() throws Exception {
|
||||
|
|
@ -94,7 +94,7 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
|||
|
||||
byte[] offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(newDrmInitData());
|
||||
|
||||
assertNotNull(offlineLicenseKeySetId);
|
||||
assertThat(offlineLicenseKeySetId).isNotNull();
|
||||
}
|
||||
|
||||
public void testGetLicenseDurationRemainingSec() throws Exception {
|
||||
|
|
@ -108,8 +108,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
|||
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper
|
||||
.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
||||
|
||||
assertEquals(licenseDuration, (long) licenseDurationRemainingSec.first);
|
||||
assertEquals(playbackDuration, (long) licenseDurationRemainingSec.second);
|
||||
assertThat(licenseDurationRemainingSec.first).isEqualTo(licenseDuration);
|
||||
assertThat(licenseDurationRemainingSec.second).isEqualTo(playbackDuration);
|
||||
}
|
||||
|
||||
public void testGetLicenseDurationRemainingSecExpiredLicense() throws Exception {
|
||||
|
|
@ -123,8 +123,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
|||
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper
|
||||
.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
||||
|
||||
assertEquals(licenseDuration, (long) licenseDurationRemainingSec.first);
|
||||
assertEquals(playbackDuration, (long) licenseDurationRemainingSec.second);
|
||||
assertThat(licenseDurationRemainingSec.first).isEqualTo(licenseDuration);
|
||||
assertThat(licenseDurationRemainingSec.second).isEqualTo(playbackDuration);
|
||||
}
|
||||
|
||||
private void setDefaultStubKeySetId()
|
||||
|
|
@ -139,8 +139,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
|||
|
||||
private static void assertOfflineLicenseKeySetIdEqual(
|
||||
byte[] expectedKeySetId, byte[] actualKeySetId) throws Exception {
|
||||
assertNotNull(actualKeySetId);
|
||||
MoreAsserts.assertEquals(expectedKeySetId, actualKeySetId);
|
||||
assertThat(actualKeySetId).isNotNull();
|
||||
assertThat(actualKeySetId).isEqualTo(expectedKeySetId);
|
||||
}
|
||||
|
||||
private void setStubLicenseAndPlaybackDurationValues(long licenseDuration,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.extractor.ogg;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
|
|
@ -60,28 +63,33 @@ public final class DefaultOggSeekerTest extends TestCase {
|
|||
}
|
||||
|
||||
// Test granule 0 from file start
|
||||
assertEquals(0, seekTo(input, oggSeeker, 0, 0));
|
||||
assertEquals(0, input.getPosition());
|
||||
assertThat(seekTo(input, oggSeeker, 0, 0)).isEqualTo(0);
|
||||
assertThat(input.getPosition()).isEqualTo(0);
|
||||
|
||||
// Test granule 0 from file end
|
||||
assertEquals(0, seekTo(input, oggSeeker, 0, testFile.data.length - 1));
|
||||
assertEquals(0, input.getPosition());
|
||||
assertThat(seekTo(input, oggSeeker, 0, testFile.data.length - 1)).isEqualTo(0);
|
||||
assertThat(input.getPosition()).isEqualTo(0);
|
||||
|
||||
{ // Test last granule
|
||||
long currentGranule = seekTo(input, oggSeeker, testFile.lastGranule, 0);
|
||||
long position = testFile.data.length;
|
||||
assertTrue((testFile.lastGranule > currentGranule && position > input.getPosition())
|
||||
|| (testFile.lastGranule == currentGranule && position == input.getPosition()));
|
||||
assertThat(
|
||||
(testFile.lastGranule > currentGranule && position > input.getPosition())
|
||||
|| (testFile.lastGranule == currentGranule && position == input.getPosition()))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
{ // Test exact granule
|
||||
input.setPosition(testFile.data.length / 2);
|
||||
oggSeeker.skipToNextPage(input);
|
||||
assertTrue(pageHeader.populate(input, true));
|
||||
assertThat(pageHeader.populate(input, true)).isTrue();
|
||||
long position = input.getPosition() + pageHeader.headerSize + pageHeader.bodySize;
|
||||
long currentGranule = seekTo(input, oggSeeker, pageHeader.granulePosition, 0);
|
||||
assertTrue((pageHeader.granulePosition > currentGranule && position > input.getPosition())
|
||||
|| (pageHeader.granulePosition == currentGranule && position == input.getPosition()));
|
||||
assertThat(
|
||||
(pageHeader.granulePosition > currentGranule && position > input.getPosition())
|
||||
|| (pageHeader.granulePosition == currentGranule
|
||||
&& position == input.getPosition()))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; i += 1) {
|
||||
|
|
@ -91,16 +99,17 @@ public final class DefaultOggSeekerTest extends TestCase {
|
|||
long currentGranule = seekTo(input, oggSeeker, targetGranule, initialPosition);
|
||||
long currentPosition = input.getPosition();
|
||||
|
||||
assertTrue("getNextSeekPosition() didn't leave input on a page start.",
|
||||
pageHeader.populate(input, true));
|
||||
assertWithMessage("getNextSeekPosition() didn't leave input on a page start.")
|
||||
.that(pageHeader.populate(input, true))
|
||||
.isTrue();
|
||||
|
||||
if (currentGranule == 0) {
|
||||
assertEquals(0, currentPosition);
|
||||
assertThat(currentPosition).isEqualTo(0);
|
||||
} else {
|
||||
int previousPageStart = testFile.findPreviousPageStart(currentPosition);
|
||||
input.setPosition(previousPageStart);
|
||||
assertTrue(pageHeader.populate(input, true));
|
||||
assertEquals(pageHeader.granulePosition, currentGranule);
|
||||
assertThat(pageHeader.populate(input, true)).isTrue();
|
||||
assertThat(currentGranule).isEqualTo(pageHeader.granulePosition);
|
||||
}
|
||||
|
||||
input.setPosition((int) currentPosition);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.extractor.ogg;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
|
|
@ -56,44 +58,47 @@ public final class OggExtractorTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
public void testSniffVorbis() throws Exception {
|
||||
byte[] data = TestUtil.joinByteArrays(
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||
TestUtil.createByteArray(7), // Laces
|
||||
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
|
||||
assertTrue(sniff(data));
|
||||
byte[] data =
|
||||
TestUtil.joinByteArrays(
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||
TestUtil.createByteArray(7), // Laces
|
||||
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
|
||||
assertThat(sniff(data)).isTrue();
|
||||
}
|
||||
|
||||
public void testSniffFlac() throws Exception {
|
||||
byte[] data = TestUtil.joinByteArrays(
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||
TestUtil.createByteArray(5), // Laces
|
||||
new byte[] {0x7F, 'F', 'L', 'A', 'C'});
|
||||
assertTrue(sniff(data));
|
||||
byte[] data =
|
||||
TestUtil.joinByteArrays(
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||
TestUtil.createByteArray(5), // Laces
|
||||
new byte[] {0x7F, 'F', 'L', 'A', 'C'});
|
||||
assertThat(sniff(data)).isTrue();
|
||||
}
|
||||
|
||||
public void testSniffFailsOpusFile() throws Exception {
|
||||
byte[] data = TestUtil.joinByteArrays(
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 0x00),
|
||||
new byte[] {'O', 'p', 'u', 's'});
|
||||
assertFalse(sniff(data));
|
||||
byte[] data =
|
||||
TestUtil.joinByteArrays(
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 0x00), new byte[] {'O', 'p', 'u', 's'});
|
||||
assertThat(sniff(data)).isFalse();
|
||||
}
|
||||
|
||||
public void testSniffFailsInvalidOggHeader() throws Exception {
|
||||
byte[] data = OggTestData.buildOggHeader(0x00, 0, 1000, 0x00);
|
||||
assertFalse(sniff(data));
|
||||
assertThat(sniff(data)).isFalse();
|
||||
}
|
||||
|
||||
public void testSniffInvalidHeader() throws Exception {
|
||||
byte[] data = TestUtil.joinByteArrays(
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||
TestUtil.createByteArray(7), // Laces
|
||||
new byte[] {0x7F, 'X', 'o', 'r', 'b', 'i', 's'});
|
||||
assertFalse(sniff(data));
|
||||
byte[] data =
|
||||
TestUtil.joinByteArrays(
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||
TestUtil.createByteArray(7), // Laces
|
||||
new byte[] {0x7F, 'X', 'o', 'r', 'b', 'i', 's'});
|
||||
assertThat(sniff(data)).isFalse();
|
||||
}
|
||||
|
||||
public void testSniffFailsEOF() throws Exception {
|
||||
byte[] data = OggTestData.buildOggHeader(0x02, 0, 1000, 0x00);
|
||||
assertFalse(sniff(data));
|
||||
assertThat(sniff(data)).isFalse();
|
||||
}
|
||||
|
||||
private boolean sniff(byte[] data) throws InterruptedException, IOException {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.extractor.ogg;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.test.MoreAsserts;
|
||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
||||
import com.google.android.exoplayer2.testutil.OggTestData;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
|
|
@ -48,56 +49,58 @@ public final class OggPacketTest extends InstrumentationTestCase {
|
|||
byte[] thirdPacket = TestUtil.buildTestData(256, random);
|
||||
byte[] fourthPacket = TestUtil.buildTestData(271, random);
|
||||
|
||||
FakeExtractorInput input = OggTestData.createInput(
|
||||
TestUtil.joinByteArrays(
|
||||
// First page with a single packet.
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 0x01),
|
||||
TestUtil.createByteArray(0x08), // Laces
|
||||
firstPacket,
|
||||
// Second page with a single packet.
|
||||
OggTestData.buildOggHeader(0x00, 16, 1001, 0x02),
|
||||
TestUtil.createByteArray(0xFF, 0x11), // Laces
|
||||
secondPacket,
|
||||
// Third page with zero packets.
|
||||
OggTestData.buildOggHeader(0x00, 16, 1002, 0x00),
|
||||
// Fourth page with two packets.
|
||||
OggTestData.buildOggHeader(0x04, 128, 1003, 0x04),
|
||||
TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), // Laces
|
||||
thirdPacket,
|
||||
fourthPacket), true);
|
||||
FakeExtractorInput input =
|
||||
OggTestData.createInput(
|
||||
TestUtil.joinByteArrays(
|
||||
// First page with a single packet.
|
||||
OggTestData.buildOggHeader(0x02, 0, 1000, 0x01),
|
||||
TestUtil.createByteArray(0x08), // Laces
|
||||
firstPacket,
|
||||
// Second page with a single packet.
|
||||
OggTestData.buildOggHeader(0x00, 16, 1001, 0x02),
|
||||
TestUtil.createByteArray(0xFF, 0x11), // Laces
|
||||
secondPacket,
|
||||
// Third page with zero packets.
|
||||
OggTestData.buildOggHeader(0x00, 16, 1002, 0x00),
|
||||
// Fourth page with two packets.
|
||||
OggTestData.buildOggHeader(0x04, 128, 1003, 0x04),
|
||||
TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), // Laces
|
||||
thirdPacket,
|
||||
fourthPacket),
|
||||
true);
|
||||
|
||||
assertReadPacket(input, firstPacket);
|
||||
assertTrue((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
||||
assertFalse((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
||||
assertEquals(0x02, oggPacket.getPageHeader().type);
|
||||
assertEquals(27 + 1, oggPacket.getPageHeader().headerSize);
|
||||
assertEquals(8, oggPacket.getPageHeader().bodySize);
|
||||
assertEquals(0x00, oggPacket.getPageHeader().revision);
|
||||
assertEquals(1, oggPacket.getPageHeader().pageSegmentCount);
|
||||
assertEquals(1000, oggPacket.getPageHeader().pageSequenceNumber);
|
||||
assertEquals(4096, oggPacket.getPageHeader().streamSerialNumber);
|
||||
assertEquals(0, oggPacket.getPageHeader().granulePosition);
|
||||
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isTrue();
|
||||
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse();
|
||||
assertThat(oggPacket.getPageHeader().type).isEqualTo(0x02);
|
||||
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 1);
|
||||
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(8);
|
||||
assertThat(oggPacket.getPageHeader().revision).isEqualTo(0x00);
|
||||
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(1);
|
||||
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1000);
|
||||
assertThat(oggPacket.getPageHeader().streamSerialNumber).isEqualTo(4096);
|
||||
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(0);
|
||||
|
||||
assertReadPacket(input, secondPacket);
|
||||
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
||||
assertFalse((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
||||
assertEquals(0, oggPacket.getPageHeader().type);
|
||||
assertEquals(27 + 2, oggPacket.getPageHeader().headerSize);
|
||||
assertEquals(255 + 17, oggPacket.getPageHeader().bodySize);
|
||||
assertEquals(2, oggPacket.getPageHeader().pageSegmentCount);
|
||||
assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber);
|
||||
assertEquals(16, oggPacket.getPageHeader().granulePosition);
|
||||
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
|
||||
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse();
|
||||
assertThat(oggPacket.getPageHeader().type).isEqualTo(0);
|
||||
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 2);
|
||||
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 17);
|
||||
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(2);
|
||||
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001);
|
||||
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(16);
|
||||
|
||||
assertReadPacket(input, thirdPacket);
|
||||
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
||||
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
||||
assertEquals(4, oggPacket.getPageHeader().type);
|
||||
assertEquals(27 + 4, oggPacket.getPageHeader().headerSize);
|
||||
assertEquals(255 + 1 + 255 + 16, oggPacket.getPageHeader().bodySize);
|
||||
assertEquals(4, oggPacket.getPageHeader().pageSegmentCount);
|
||||
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
|
||||
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
|
||||
assertThat(oggPacket.getPageHeader().type).isEqualTo(4);
|
||||
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 4);
|
||||
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 1 + 255 + 16);
|
||||
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(4);
|
||||
// Page 1002 is empty, so current page is 1003.
|
||||
assertEquals(1003, oggPacket.getPageHeader().pageSequenceNumber);
|
||||
assertEquals(128, oggPacket.getPageHeader().granulePosition);
|
||||
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003);
|
||||
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(128);
|
||||
|
||||
assertReadPacket(input, fourthPacket);
|
||||
|
||||
|
|
@ -135,9 +138,9 @@ public final class OggPacketTest extends InstrumentationTestCase {
|
|||
Arrays.copyOfRange(firstPacket, 510, 510 + 8)), true);
|
||||
|
||||
assertReadPacket(input, firstPacket);
|
||||
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
||||
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
||||
assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber);
|
||||
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
|
||||
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
|
||||
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001);
|
||||
|
||||
assertReadEof(input);
|
||||
}
|
||||
|
|
@ -165,9 +168,9 @@ public final class OggPacketTest extends InstrumentationTestCase {
|
|||
Arrays.copyOfRange(firstPacket, 510 + 255 + 255, 510 + 255 + 255 + 8)), true);
|
||||
|
||||
assertReadPacket(input, firstPacket);
|
||||
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
||||
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
||||
assertEquals(1003, oggPacket.getPageHeader().pageSequenceNumber);
|
||||
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
|
||||
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
|
||||
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003);
|
||||
|
||||
assertReadEof(input);
|
||||
}
|
||||
|
|
@ -218,19 +221,19 @@ public final class OggPacketTest extends InstrumentationTestCase {
|
|||
while (readPacket(input)) {
|
||||
packetCounter++;
|
||||
}
|
||||
assertEquals(277, packetCounter);
|
||||
assertThat(packetCounter).isEqualTo(277);
|
||||
}
|
||||
|
||||
private void assertReadPacket(FakeExtractorInput extractorInput, byte[] expected)
|
||||
throws IOException, InterruptedException {
|
||||
assertTrue(readPacket(extractorInput));
|
||||
assertThat(readPacket(extractorInput)).isTrue();
|
||||
ParsableByteArray payload = oggPacket.getPayload();
|
||||
MoreAsserts.assertEquals(expected, Arrays.copyOf(payload.data, payload.limit()));
|
||||
assertThat(Arrays.copyOf(payload.data, payload.limit())).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void assertReadEof(FakeExtractorInput extractorInput)
|
||||
throws IOException, InterruptedException {
|
||||
assertFalse(readPacket(extractorInput));
|
||||
assertThat(readPacket(extractorInput)).isFalse();
|
||||
}
|
||||
|
||||
private boolean readPacket(FakeExtractorInput input)
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.extractor.ogg;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.android.exoplayer2.testutil.OggTestData;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Generates test data.
|
||||
|
|
@ -119,7 +120,7 @@ import junit.framework.Assert;
|
|||
return i;
|
||||
}
|
||||
}
|
||||
Assert.fail();
|
||||
fail();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.extractor.ts;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.util.SparseArray;
|
||||
import com.google.android.exoplayer2.C;
|
||||
|
|
@ -92,12 +94,11 @@ public final class TsExtractorTest extends InstrumentationTestCase {
|
|||
readResult = tsExtractor.read(input, seekPositionHolder);
|
||||
}
|
||||
CustomEsReader reader = factory.esReader;
|
||||
assertEquals(2, reader.packetsRead);
|
||||
assertThat(reader.packetsRead).isEqualTo(2);
|
||||
TrackOutput trackOutput = reader.getTrackOutput();
|
||||
assertTrue(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */));
|
||||
assertEquals(
|
||||
Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0),
|
||||
((FakeTrackOutput) trackOutput).format);
|
||||
assertThat(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */)).isTrue();
|
||||
assertThat(((FakeTrackOutput) trackOutput).format)
|
||||
.isEqualTo(Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0));
|
||||
}
|
||||
|
||||
public void testCustomInitialSectionReader() throws Exception {
|
||||
|
|
@ -115,7 +116,7 @@ public final class TsExtractorTest extends InstrumentationTestCase {
|
|||
while (readResult != Extractor.RESULT_END_OF_INPUT) {
|
||||
readResult = tsExtractor.read(input, seekPositionHolder);
|
||||
}
|
||||
assertEquals(1, factory.sdtReader.consumedSdts);
|
||||
assertThat(factory.sdtReader.consumedSdts).isEqualTo(1);
|
||||
}
|
||||
|
||||
private static void writeJunkData(ByteArrayOutputStream out, int length) {
|
||||
|
|
@ -145,7 +146,7 @@ public final class TsExtractorTest extends InstrumentationTestCase {
|
|||
@Override
|
||||
public SparseArray<TsPayloadReader> createInitialPayloadReaders() {
|
||||
if (provideSdtReader) {
|
||||
assertNull(sdtReader);
|
||||
assertThat(sdtReader).isNull();
|
||||
SparseArray<TsPayloadReader> mapping = new SparseArray<>();
|
||||
sdtReader = new SdtSectionReader();
|
||||
mapping.put(17, new SectionReader(sdtReader));
|
||||
|
|
@ -226,21 +227,21 @@ public final class TsExtractorTest extends InstrumentationTestCase {
|
|||
// original_network_id(16), reserved_future_use(8)
|
||||
sectionData.skipBytes(11);
|
||||
// Start of the service loop.
|
||||
assertEquals(0x5566 /* arbitrary service id */, sectionData.readUnsignedShort());
|
||||
assertThat(sectionData.readUnsignedShort()).isEqualTo(0x5566 /* arbitrary service id */);
|
||||
// reserved_future_use(6), EIT_schedule_flag(1), EIT_present_following_flag(1)
|
||||
sectionData.skipBytes(1);
|
||||
// Assert there is only one service.
|
||||
// Remove running_status(3), free_CA_mode(1) from the descriptors_loop_length with the mask.
|
||||
assertEquals(sectionData.readUnsignedShort() & 0xFFF, sectionData.bytesLeft());
|
||||
assertThat(sectionData.readUnsignedShort() & 0xFFF).isEqualTo(sectionData.bytesLeft());
|
||||
while (sectionData.bytesLeft() > 0) {
|
||||
int descriptorTag = sectionData.readUnsignedByte();
|
||||
int descriptorLength = sectionData.readUnsignedByte();
|
||||
if (descriptorTag == 72 /* service descriptor */) {
|
||||
assertEquals(1, sectionData.readUnsignedByte()); // Service type: Digital TV.
|
||||
assertThat(sectionData.readUnsignedByte()).isEqualTo(1); // Service type: Digital TV.
|
||||
int serviceProviderNameLength = sectionData.readUnsignedByte();
|
||||
assertEquals("Some provider", sectionData.readString(serviceProviderNameLength));
|
||||
assertThat(sectionData.readString(serviceProviderNameLength)).isEqualTo("Some provider");
|
||||
int serviceNameLength = sectionData.readUnsignedByte();
|
||||
assertEquals("Some Channel", sectionData.readString(serviceNameLength));
|
||||
assertThat(sectionData.readString(serviceNameLength)).isEqualTo("Some Channel");
|
||||
} else {
|
||||
sectionData.skipBytes(descriptorLength);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
|
|
@ -52,10 +54,12 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
|||
|
||||
Timeline clippedTimeline = getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US);
|
||||
|
||||
assertEquals(1, clippedTimeline.getWindowCount());
|
||||
assertEquals(1, clippedTimeline.getPeriodCount());
|
||||
assertEquals(TEST_PERIOD_DURATION_US, clippedTimeline.getWindow(0, window).getDurationUs());
|
||||
assertEquals(TEST_PERIOD_DURATION_US, clippedTimeline.getPeriod(0, period).getDurationUs());
|
||||
assertThat(clippedTimeline.getWindowCount()).isEqualTo(1);
|
||||
assertThat(clippedTimeline.getPeriodCount()).isEqualTo(1);
|
||||
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US);
|
||||
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US);
|
||||
}
|
||||
|
||||
public void testClippingUnseekableWindowThrows() throws IOException {
|
||||
|
|
@ -68,7 +72,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
|||
getClippedTimeline(timeline, 1, TEST_PERIOD_DURATION_US);
|
||||
fail("Expected clipping to fail.");
|
||||
} catch (IllegalClippingException e) {
|
||||
assertEquals(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START, e.reason);
|
||||
assertThat(e.reason).isEqualTo(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,10 +81,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
|||
|
||||
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
|
||||
TEST_PERIOD_DURATION_US);
|
||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
|
||||
clippedTimeline.getWindow(0, window).getDurationUs());
|
||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
|
||||
clippedTimeline.getPeriod(0, period).getDurationUs());
|
||||
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||
}
|
||||
|
||||
public void testClippingEnd() throws IOException {
|
||||
|
|
@ -88,10 +92,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
|||
|
||||
Timeline clippedTimeline = getClippedTimeline(timeline, 0,
|
||||
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
|
||||
clippedTimeline.getWindow(0, window).getDurationUs());
|
||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
|
||||
clippedTimeline.getPeriod(0, period).getDurationUs());
|
||||
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||
}
|
||||
|
||||
public void testClippingStartAndEndInitial() throws IOException {
|
||||
|
|
@ -103,10 +107,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
|||
|
||||
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
|
||||
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
|
||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
|
||||
clippedTimeline.getWindow(0, window).getDurationUs());
|
||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
|
||||
clippedTimeline.getPeriod(0, period).getDurationUs());
|
||||
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
|
||||
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
|
||||
}
|
||||
|
||||
public void testClippingStartAndEnd() throws IOException {
|
||||
|
|
@ -114,10 +118,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
|||
|
||||
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
|
||||
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
|
||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
|
||||
clippedTimeline.getWindow(0, window).getDurationUs());
|
||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
|
||||
clippedTimeline.getPeriod(0, period).getDurationUs());
|
||||
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
|
||||
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
|
||||
}
|
||||
|
||||
public void testWindowAndPeriodIndices() throws IOException {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
|
|
@ -77,8 +79,9 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testMultipleMediaSources() throws IOException {
|
||||
Timeline[] timelines = { createFakeTimeline(3, 111), createFakeTimeline(1, 222),
|
||||
createFakeTimeline(3, 333) };
|
||||
Timeline[] timelines = {
|
||||
createFakeTimeline(3, 111), createFakeTimeline(1, 222), createFakeTimeline(3, 333)
|
||||
};
|
||||
Timeline timeline = getConcatenatedTimeline(false, timelines);
|
||||
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
||||
TimelineAsserts.assertPeriodCounts(timeline, 3, 1, 3);
|
||||
|
|
@ -98,10 +101,10 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
|||
C.INDEX_UNSET, 0, 1);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
||||
assertEquals(0, timeline.getFirstWindowIndex(false));
|
||||
assertEquals(2, timeline.getLastWindowIndex(false));
|
||||
assertEquals(2, timeline.getFirstWindowIndex(true));
|
||||
assertEquals(0, timeline.getLastWindowIndex(true));
|
||||
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
|
||||
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
|
||||
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
|
||||
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
|
||||
|
||||
timeline = getConcatenatedTimeline(true, timelines);
|
||||
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
||||
|
|
@ -117,8 +120,8 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
|||
1, 2, C.INDEX_UNSET);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 1, 2, 0);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
|
||||
assertEquals(0, timeline.getFirstWindowIndex(shuffled));
|
||||
assertEquals(2, timeline.getLastWindowIndex(shuffled));
|
||||
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(0);
|
||||
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,9 +155,16 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
|||
|
||||
public void testEmptyTimelineMediaSources() throws IOException {
|
||||
// Empty timelines in the front, back, and the middle (single and multiple in a row).
|
||||
Timeline[] timelines = { Timeline.EMPTY, createFakeTimeline(1, 111), Timeline.EMPTY,
|
||||
Timeline.EMPTY, createFakeTimeline(2, 222), Timeline.EMPTY, createFakeTimeline(3, 333),
|
||||
Timeline.EMPTY };
|
||||
Timeline[] timelines = {
|
||||
Timeline.EMPTY,
|
||||
createFakeTimeline(1, 111),
|
||||
Timeline.EMPTY,
|
||||
Timeline.EMPTY,
|
||||
createFakeTimeline(2, 222),
|
||||
Timeline.EMPTY,
|
||||
createFakeTimeline(3, 333),
|
||||
Timeline.EMPTY
|
||||
};
|
||||
Timeline timeline = getConcatenatedTimeline(false, timelines);
|
||||
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
||||
TimelineAsserts.assertPeriodCounts(timeline, 1, 2, 3);
|
||||
|
|
@ -174,10 +184,10 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
|||
C.INDEX_UNSET, 0, 1);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
||||
assertEquals(0, timeline.getFirstWindowIndex(false));
|
||||
assertEquals(2, timeline.getLastWindowIndex(false));
|
||||
assertEquals(2, timeline.getFirstWindowIndex(true));
|
||||
assertEquals(0, timeline.getLastWindowIndex(true));
|
||||
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
|
||||
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
|
||||
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
|
||||
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
|
||||
|
||||
timeline = getConcatenatedTimeline(true, timelines);
|
||||
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
||||
|
|
@ -193,8 +203,8 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
|||
1, 2, C.INDEX_UNSET);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 1, 2, 0);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
|
||||
assertEquals(0, timeline.getFirstWindowIndex(shuffled));
|
||||
assertEquals(2, timeline.getLastWindowIndex(shuffled));
|
||||
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(0);
|
||||
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.os.ConditionVariable;
|
||||
|
|
@ -135,8 +136,8 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
C.INDEX_UNSET, 0, 1);
|
||||
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2);
|
||||
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 2, 0, 1);
|
||||
assertEquals(0, timeline.getFirstWindowIndex(false));
|
||||
assertEquals(timeline.getWindowCount() - 1, timeline.getLastWindowIndex(false));
|
||||
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
|
||||
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(timeline.getWindowCount() - 1);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, true,
|
||||
C.INDEX_UNSET, 0, 1);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||
|
|
@ -145,8 +146,8 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
1, 2, C.INDEX_UNSET);
|
||||
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 1, 2, 0);
|
||||
assertEquals(timeline.getWindowCount() - 1, timeline.getFirstWindowIndex(true));
|
||||
assertEquals(0, timeline.getLastWindowIndex(true));
|
||||
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(timeline.getWindowCount() - 1);
|
||||
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
|
||||
|
||||
// Assert all periods can be prepared.
|
||||
testRunner.assertPrepareAndReleaseAllPeriods();
|
||||
|
|
@ -258,7 +259,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
// called yet.
|
||||
MediaPeriod lazyPeriod = testRunner.createPeriod(new MediaPeriodId(0));
|
||||
ConditionVariable preparedCondition = testRunner.preparePeriod(lazyPeriod, 0);
|
||||
assertFalse(preparedCondition.block(1));
|
||||
assertThat(preparedCondition.block(1)).isFalse();
|
||||
|
||||
// Assert that a second period can also be created and released without problems.
|
||||
MediaPeriod secondLazyPeriod = testRunner.createPeriod(new MediaPeriodId(0));
|
||||
|
|
@ -276,7 +277,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
TimelineAsserts.assertPeriodCounts(timeline, 8, 1, 2, 9);
|
||||
TimelineAsserts.assertWindowIds(timeline, 888, 111, 222, 999);
|
||||
TimelineAsserts.assertWindowIsDynamic(timeline, false, false, false, false);
|
||||
assertTrue(preparedCondition.block(1));
|
||||
assertThat(preparedCondition.block(1)).isTrue();
|
||||
|
||||
// Release the period and source.
|
||||
testRunner.releasePeriod(lazyPeriod);
|
||||
|
|
@ -299,11 +300,13 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
timeline = testRunner.assertTimelineChangeBlocking();
|
||||
TimelineAsserts.assertEmpty(timeline);
|
||||
|
||||
mediaSource.addMediaSources(Arrays.asList(new MediaSource[] {
|
||||
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null),
|
||||
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null),
|
||||
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null)
|
||||
}));
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(
|
||||
new MediaSource[] {
|
||||
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null),
|
||||
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null),
|
||||
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null)
|
||||
}));
|
||||
timeline = testRunner.assertTimelineChangeBlocking();
|
||||
TimelineAsserts.assertEmpty(timeline);
|
||||
|
||||
|
|
@ -334,10 +337,10 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
C.INDEX_UNSET, 0, 1);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
||||
assertEquals(0, timeline.getFirstWindowIndex(false));
|
||||
assertEquals(2, timeline.getLastWindowIndex(false));
|
||||
assertEquals(2, timeline.getFirstWindowIndex(true));
|
||||
assertEquals(0, timeline.getLastWindowIndex(true));
|
||||
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
|
||||
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
|
||||
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
|
||||
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
|
||||
testRunner.assertPrepareAndReleaseAllPeriods();
|
||||
}
|
||||
|
||||
|
|
@ -439,7 +442,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
}
|
||||
});
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertEquals(1, timeline.getWindowCount());
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(1);
|
||||
} finally {
|
||||
dummyMainThread.release();
|
||||
}
|
||||
|
|
@ -450,16 +453,18 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
try {
|
||||
testRunner.prepareSource();
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
dummyMainThread.runOnMainThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
timelineGrabber);
|
||||
}
|
||||
});
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(
|
||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
timelineGrabber);
|
||||
}
|
||||
});
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertEquals(2, timeline.getWindowCount());
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||
} finally {
|
||||
dummyMainThread.release();
|
||||
}
|
||||
|
|
@ -477,7 +482,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
}
|
||||
});
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertEquals(1, timeline.getWindowCount());
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(1);
|
||||
} finally {
|
||||
dummyMainThread.release();
|
||||
}
|
||||
|
|
@ -488,16 +493,19 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
try {
|
||||
testRunner.prepareSource();
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
dummyMainThread.runOnMainThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSources(/* index */ 0,
|
||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
timelineGrabber);
|
||||
}
|
||||
});
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSources(
|
||||
/* index */ 0,
|
||||
Arrays.asList(
|
||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
timelineGrabber);
|
||||
}
|
||||
});
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertEquals(2, timeline.getWindowCount());
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||
} finally {
|
||||
dummyMainThread.release();
|
||||
}
|
||||
|
|
@ -523,7 +531,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
}
|
||||
});
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertEquals(0, timeline.getWindowCount());
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(0);
|
||||
} finally {
|
||||
dummyMainThread.release();
|
||||
}
|
||||
|
|
@ -533,13 +541,15 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
try {
|
||||
testRunner.prepareSource();
|
||||
dummyMainThread.runOnMainThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSources(Arrays.asList(
|
||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
||||
}
|
||||
});
|
||||
dummyMainThread.runOnMainThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(
|
||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
||||
}
|
||||
});
|
||||
testRunner.assertTimelineChangeBlocking();
|
||||
|
||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||
|
|
@ -551,7 +561,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
}
|
||||
});
|
||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||
assertEquals(2, timeline.getWindowCount());
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||
} finally {
|
||||
dummyMainThread.release();
|
||||
}
|
||||
|
|
@ -624,7 +634,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
finishedCondition.open();
|
||||
}
|
||||
});
|
||||
assertTrue(finishedCondition.block(MediaSourceTestRunner.TIMEOUT_MS));
|
||||
assertThat(finishedCondition.block(MediaSourceTestRunner.TIMEOUT_MS)).isTrue();
|
||||
}
|
||||
|
||||
public void release() {
|
||||
|
|
@ -657,7 +667,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
|||
}
|
||||
|
||||
public Timeline assertTimelineChangeBlocking() {
|
||||
assertTrue(finishedCondition.block(MediaSourceTestRunner.TIMEOUT_MS));
|
||||
assertThat(finishedCondition.block(MediaSourceTestRunner.TIMEOUT_MS)).isTrue();
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.source.MergingMediaSource.IllegalMergeException;
|
||||
|
|
@ -53,7 +55,7 @@ public class MergingMediaSourceTest extends TestCase {
|
|||
testMergingMediaSourcePrepare(firstTimeline, secondTimeline);
|
||||
fail("Expected merging to fail.");
|
||||
} catch (IllegalMergeException e) {
|
||||
assertEquals(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH, e.reason);
|
||||
assertThat(e.reason).isEqualTo(IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +73,7 @@ public class MergingMediaSourceTest extends TestCase {
|
|||
try {
|
||||
Timeline timeline = testRunner.prepareSource();
|
||||
// The merged timeline should always be the one from the first child.
|
||||
assertEquals(timelines[0], timeline);
|
||||
assertThat(timeline).isEqualTo(timelines[0]);
|
||||
} finally {
|
||||
testRunner.release();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.text.ssa;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import java.io.IOException;
|
||||
|
|
@ -38,8 +40,8 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY);
|
||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(0, subtitle.getEventTimeCount());
|
||||
assertTrue(subtitle.getCues(0).isEmpty());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(0);
|
||||
assertThat(subtitle.getCues(0).isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
public void testDecodeTypical() throws IOException {
|
||||
|
|
@ -47,7 +49,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL);
|
||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(6, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||
assertTypicalCue1(subtitle, 0);
|
||||
assertTypicalCue2(subtitle, 2);
|
||||
assertTypicalCue3(subtitle, 4);
|
||||
|
|
@ -63,7 +65,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_DIALOGUE_ONLY);
|
||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(6, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||
assertTypicalCue1(subtitle, 0);
|
||||
assertTypicalCue2(subtitle, 2);
|
||||
assertTypicalCue3(subtitle, 4);
|
||||
|
|
@ -75,7 +77,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), INVALID_TIMECODES);
|
||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(2, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||
assertTypicalCue3(subtitle, 0);
|
||||
}
|
||||
|
||||
|
|
@ -84,40 +86,40 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES);
|
||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(3, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(3);
|
||||
|
||||
assertEquals(0, subtitle.getEventTime(0));
|
||||
assertEquals("This is the first subtitle.",
|
||||
subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
|
||||
assertThat(subtitle.getEventTime(0)).isEqualTo(0);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString())
|
||||
.isEqualTo("This is the first subtitle.");
|
||||
|
||||
assertEquals(2340000, subtitle.getEventTime(1));
|
||||
assertEquals("This is the second subtitle \nwith a newline \nand another.",
|
||||
subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString());
|
||||
assertThat(subtitle.getEventTime(1)).isEqualTo(2340000);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString())
|
||||
.isEqualTo("This is the second subtitle \nwith a newline \nand another.");
|
||||
|
||||
assertEquals(4560000, subtitle.getEventTime(2));
|
||||
assertEquals("This is the third subtitle, with a comma.",
|
||||
subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString());
|
||||
assertThat(subtitle.getEventTime(2)).isEqualTo(4560000);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString())
|
||||
.isEqualTo("This is the third subtitle, with a comma.");
|
||||
}
|
||||
|
||||
private static void assertTypicalCue1(SsaSubtitle subtitle, int eventIndex) {
|
||||
assertEquals(0, subtitle.getEventTime(eventIndex));
|
||||
assertEquals("This is the first subtitle.",
|
||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
||||
assertEquals(1230000, subtitle.getEventTime(eventIndex + 1));
|
||||
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(0);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||
.isEqualTo("This is the first subtitle.");
|
||||
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(1230000);
|
||||
}
|
||||
|
||||
private static void assertTypicalCue2(SsaSubtitle subtitle, int eventIndex) {
|
||||
assertEquals(2340000, subtitle.getEventTime(eventIndex));
|
||||
assertEquals("This is the second subtitle \nwith a newline \nand another.",
|
||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
||||
assertEquals(3450000, subtitle.getEventTime(eventIndex + 1));
|
||||
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(2340000);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||
.isEqualTo("This is the second subtitle \nwith a newline \nand another.");
|
||||
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(3450000);
|
||||
}
|
||||
|
||||
private static void assertTypicalCue3(SsaSubtitle subtitle, int eventIndex) {
|
||||
assertEquals(4560000, subtitle.getEventTime(eventIndex));
|
||||
assertEquals("This is the third subtitle, with a comma.",
|
||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
||||
assertEquals(8900000, subtitle.getEventTime(eventIndex + 1));
|
||||
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(4560000);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||
.isEqualTo("This is the third subtitle, with a comma.");
|
||||
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(8900000);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.text.subrip;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import java.io.IOException;
|
||||
|
|
@ -39,8 +41,8 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY_FILE);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(0, subtitle.getEventTimeCount());
|
||||
assertTrue(subtitle.getCues(0).isEmpty());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(0);
|
||||
assertThat(subtitle.getCues(0).isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
public void testDecodeTypical() throws IOException {
|
||||
|
|
@ -48,7 +50,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_FILE);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(6, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||
assertTypicalCue1(subtitle, 0);
|
||||
assertTypicalCue2(subtitle, 2);
|
||||
assertTypicalCue3(subtitle, 4);
|
||||
|
|
@ -59,7 +61,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_WITH_BYTE_ORDER_MARK);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(6, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||
assertTypicalCue1(subtitle, 0);
|
||||
assertTypicalCue2(subtitle, 2);
|
||||
assertTypicalCue3(subtitle, 4);
|
||||
|
|
@ -70,7 +72,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_EXTRA_BLANK_LINE);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(6, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||
assertTypicalCue1(subtitle, 0);
|
||||
assertTypicalCue2(subtitle, 2);
|
||||
assertTypicalCue3(subtitle, 4);
|
||||
|
|
@ -82,7 +84,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_TIMECODE);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
assertTypicalCue1(subtitle, 0);
|
||||
assertTypicalCue3(subtitle, 2);
|
||||
}
|
||||
|
|
@ -93,7 +95,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_SEQUENCE);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
assertTypicalCue1(subtitle, 0);
|
||||
assertTypicalCue3(subtitle, 2);
|
||||
}
|
||||
|
|
@ -104,7 +106,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_NEGATIVE_TIMESTAMPS);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(2, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||
assertTypicalCue3(subtitle, 0);
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +116,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_UNEXPECTED_END);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
assertTypicalCue1(subtitle, 0);
|
||||
assertTypicalCue2(subtitle, 2);
|
||||
}
|
||||
|
|
@ -124,40 +126,40 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE);
|
||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
|
||||
assertEquals(3, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(3);
|
||||
|
||||
assertEquals(0, subtitle.getEventTime(0));
|
||||
assertEquals("SubRip doesn't technically allow missing end timecodes.",
|
||||
subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
|
||||
assertThat(subtitle.getEventTime(0)).isEqualTo(0);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString())
|
||||
.isEqualTo("SubRip doesn't technically allow missing end timecodes.");
|
||||
|
||||
assertEquals(2345000, subtitle.getEventTime(1));
|
||||
assertEquals("We interpret it to mean that a subtitle extends to the start of the next one.",
|
||||
subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString());
|
||||
assertThat(subtitle.getEventTime(1)).isEqualTo(2345000);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString())
|
||||
.isEqualTo("We interpret it to mean that a subtitle extends to the start of the next one.");
|
||||
|
||||
assertEquals(3456000, subtitle.getEventTime(2));
|
||||
assertEquals("Or to the end of the media.",
|
||||
subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString());
|
||||
assertThat(subtitle.getEventTime(2)).isEqualTo(3456000);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString())
|
||||
.isEqualTo("Or to the end of the media.");
|
||||
}
|
||||
|
||||
private static void assertTypicalCue1(SubripSubtitle subtitle, int eventIndex) {
|
||||
assertEquals(0, subtitle.getEventTime(eventIndex));
|
||||
assertEquals("This is the first subtitle.",
|
||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
||||
assertEquals(1234000, subtitle.getEventTime(eventIndex + 1));
|
||||
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(0);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||
.isEqualTo("This is the first subtitle.");
|
||||
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(1234000);
|
||||
}
|
||||
|
||||
private static void assertTypicalCue2(SubripSubtitle subtitle, int eventIndex) {
|
||||
assertEquals(2345000, subtitle.getEventTime(eventIndex));
|
||||
assertEquals("This is the second subtitle.\nSecond subtitle with second line.",
|
||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
||||
assertEquals(3456000, subtitle.getEventTime(eventIndex + 1));
|
||||
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(2345000);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||
.isEqualTo("This is the second subtitle.\nSecond subtitle with second line.");
|
||||
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(3456000);
|
||||
}
|
||||
|
||||
private static void assertTypicalCue3(SubripSubtitle subtitle, int eventIndex) {
|
||||
assertEquals(4567000, subtitle.getEventTime(eventIndex));
|
||||
assertEquals("This is the third subtitle.",
|
||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
||||
assertEquals(8901000, subtitle.getEventTime(eventIndex + 1));
|
||||
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(4567000);
|
||||
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||
.isEqualTo("This is the third subtitle.");
|
||||
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(8901000);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.text.ttml;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.text.Layout;
|
||||
import android.text.Spannable;
|
||||
|
|
@ -61,23 +64,23 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
|
||||
public void testInlineAttributes() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
TtmlNode root = subtitle.getRoot();
|
||||
|
||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||
TtmlNode firstDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0);
|
||||
TtmlStyle firstPStyle = queryChildrenForTag(firstDiv, TtmlNode.TAG_P, 0).style;
|
||||
assertEquals(ColorParser.parseTtmlColor("yellow"), firstPStyle.getFontColor());
|
||||
assertEquals(ColorParser.parseTtmlColor("blue"), firstPStyle.getBackgroundColor());
|
||||
assertEquals("serif", firstPStyle.getFontFamily());
|
||||
assertEquals(TtmlStyle.STYLE_BOLD_ITALIC, firstPStyle.getStyle());
|
||||
assertTrue(firstPStyle.isUnderline());
|
||||
assertThat(firstPStyle.getFontColor()).isEqualTo(ColorParser.parseTtmlColor("yellow"));
|
||||
assertThat(firstPStyle.getBackgroundColor()).isEqualTo(ColorParser.parseTtmlColor("blue"));
|
||||
assertThat(firstPStyle.getFontFamily()).isEqualTo("serif");
|
||||
assertThat(firstPStyle.getStyle()).isEqualTo(TtmlStyle.STYLE_BOLD_ITALIC);
|
||||
assertThat(firstPStyle.isUnderline()).isTrue();
|
||||
}
|
||||
|
||||
public void testInheritInlineAttributes() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
assertSpans(subtitle, 20, "text 2", "sansSerif", TtmlStyle.STYLE_ITALIC,
|
||||
0xFF00FFFF, ColorParser.parseTtmlColor("lime"), false, true, null);
|
||||
}
|
||||
|
|
@ -95,14 +98,14 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
*/
|
||||
public void testLime() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
assertSpans(subtitle, 20, "text 2", "sansSerif", TtmlStyle.STYLE_ITALIC, 0xFF00FFFF, 0xFF00FF00,
|
||||
false, true, null);
|
||||
}
|
||||
|
||||
public void testInheritGlobalStyle() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_STYLE_TTML_FILE);
|
||||
assertEquals(2, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||
assertSpans(subtitle, 10, "text 1", "serif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF,
|
||||
0xFFFFFF00, true, false, null);
|
||||
}
|
||||
|
|
@ -110,7 +113,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
public void testInheritGlobalStyleOverriddenByInlineAttributes() throws IOException,
|
||||
SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_STYLE_OVERRIDE_TTML_FILE);
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
assertSpans(subtitle, 10, "text 1", "serif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF,
|
||||
0xFFFFFF00, true, false, null);
|
||||
|
|
@ -120,7 +123,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
|
||||
public void testInheritGlobalAndParent() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_GLOBAL_AND_PARENT_TTML_FILE);
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
assertSpans(subtitle, 10, "text 1", "sansSerif", TtmlStyle.STYLE_NORMAL, 0xFFFF0000,
|
||||
ColorParser.parseTtmlColor("lime"), false, true, Layout.Alignment.ALIGN_CENTER);
|
||||
|
|
@ -130,7 +133,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
|
||||
public void testInheritMultipleStyles() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||
assertEquals(12, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||
assertSpans(subtitle, 10, "text 1", "sansSerif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF,
|
||||
0xFFFFFF00, false, true, null);
|
||||
}
|
||||
|
|
@ -138,7 +141,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
public void testInheritMultipleStylesWithoutLocalAttributes() throws IOException,
|
||||
SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||
assertEquals(12, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||
assertSpans(subtitle, 20, "text 2", "sansSerif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF,
|
||||
0xFF000000, false, true, null);
|
||||
}
|
||||
|
|
@ -146,7 +149,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
public void testMergeMultipleStylesWithParentStyle() throws IOException,
|
||||
SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||
assertEquals(12, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||
assertSpans(subtitle, 30, "text 2.5", "sansSerifInline", TtmlStyle.STYLE_ITALIC, 0xFFFF0000,
|
||||
0xFFFFFF00, true, true, null);
|
||||
}
|
||||
|
|
@ -154,231 +157,232 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
public void testMultipleRegions() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(MULTIPLE_REGIONS_TTML_FILE);
|
||||
List<Cue> output = subtitle.getCues(1000000);
|
||||
assertEquals(2, output.size());
|
||||
assertThat(output).hasSize(2);
|
||||
Cue ttmlCue = output.get(0);
|
||||
assertEquals("lorem", ttmlCue.text.toString());
|
||||
assertEquals(10f / 100f, ttmlCue.position);
|
||||
assertEquals(10f / 100f, ttmlCue.line);
|
||||
assertEquals(20f / 100f, ttmlCue.size);
|
||||
assertThat(ttmlCue.text.toString()).isEqualTo("lorem");
|
||||
assertThat(ttmlCue.position).isEqualTo(10f / 100f);
|
||||
assertThat(ttmlCue.line).isEqualTo(10f / 100f);
|
||||
assertThat(ttmlCue.size).isEqualTo(20f / 100f);
|
||||
|
||||
ttmlCue = output.get(1);
|
||||
assertEquals("amet", ttmlCue.text.toString());
|
||||
assertEquals(60f / 100f, ttmlCue.position);
|
||||
assertEquals(10f / 100f, ttmlCue.line);
|
||||
assertEquals(20f / 100f, ttmlCue.size);
|
||||
assertThat(ttmlCue.text.toString()).isEqualTo("amet");
|
||||
assertThat(ttmlCue.position).isEqualTo(60f / 100f);
|
||||
assertThat(ttmlCue.line).isEqualTo(10f / 100f);
|
||||
assertThat(ttmlCue.size).isEqualTo(20f / 100f);
|
||||
|
||||
output = subtitle.getCues(5000000);
|
||||
assertEquals(1, output.size());
|
||||
assertThat(output).hasSize(1);
|
||||
ttmlCue = output.get(0);
|
||||
assertEquals("ipsum", ttmlCue.text.toString());
|
||||
assertEquals(40f / 100f, ttmlCue.position);
|
||||
assertEquals(40f / 100f, ttmlCue.line);
|
||||
assertEquals(20f / 100f, ttmlCue.size);
|
||||
assertThat(ttmlCue.text.toString()).isEqualTo("ipsum");
|
||||
assertThat(ttmlCue.position).isEqualTo(40f / 100f);
|
||||
assertThat(ttmlCue.line).isEqualTo(40f / 100f);
|
||||
assertThat(ttmlCue.size).isEqualTo(20f / 100f);
|
||||
|
||||
output = subtitle.getCues(9000000);
|
||||
assertEquals(1, output.size());
|
||||
assertThat(output).hasSize(1);
|
||||
ttmlCue = output.get(0);
|
||||
assertEquals("dolor", ttmlCue.text.toString());
|
||||
assertEquals(Cue.DIMEN_UNSET, ttmlCue.position);
|
||||
assertEquals(Cue.DIMEN_UNSET, ttmlCue.line);
|
||||
assertEquals(Cue.DIMEN_UNSET, ttmlCue.size);
|
||||
assertThat(ttmlCue.text.toString()).isEqualTo("dolor");
|
||||
assertThat(ttmlCue.position).isEqualTo(Cue.DIMEN_UNSET);
|
||||
assertThat(ttmlCue.line).isEqualTo(Cue.DIMEN_UNSET);
|
||||
assertThat(ttmlCue.size).isEqualTo(Cue.DIMEN_UNSET);
|
||||
// TODO: Should be as below, once https://github.com/google/ExoPlayer/issues/2953 is fixed.
|
||||
// assertEquals(10f / 100f, ttmlCue.position);
|
||||
// assertEquals(80f / 100f, ttmlCue.line);
|
||||
// assertEquals(1f, ttmlCue.size);
|
||||
|
||||
output = subtitle.getCues(21000000);
|
||||
assertEquals(1, output.size());
|
||||
assertThat(output).hasSize(1);
|
||||
ttmlCue = output.get(0);
|
||||
assertEquals("She first said this", ttmlCue.text.toString());
|
||||
assertEquals(45f / 100f, ttmlCue.position);
|
||||
assertEquals(45f / 100f, ttmlCue.line);
|
||||
assertEquals(35f / 100f, ttmlCue.size);
|
||||
assertThat(ttmlCue.text.toString()).isEqualTo("She first said this");
|
||||
assertThat(ttmlCue.position).isEqualTo(45f / 100f);
|
||||
assertThat(ttmlCue.line).isEqualTo(45f / 100f);
|
||||
assertThat(ttmlCue.size).isEqualTo(35f / 100f);
|
||||
output = subtitle.getCues(25000000);
|
||||
ttmlCue = output.get(0);
|
||||
assertEquals("She first said this\nThen this", ttmlCue.text.toString());
|
||||
assertThat(ttmlCue.text.toString()).isEqualTo("She first said this\nThen this");
|
||||
output = subtitle.getCues(29000000);
|
||||
assertEquals(1, output.size());
|
||||
assertThat(output).hasSize(1);
|
||||
ttmlCue = output.get(0);
|
||||
assertEquals("She first said this\nThen this\nFinally this", ttmlCue.text.toString());
|
||||
assertEquals(45f / 100f, ttmlCue.position);
|
||||
assertEquals(45f / 100f, ttmlCue.line);
|
||||
assertThat(ttmlCue.text.toString()).isEqualTo("She first said this\nThen this\nFinally this");
|
||||
assertThat(ttmlCue.position).isEqualTo(45f / 100f);
|
||||
assertThat(ttmlCue.line).isEqualTo(45f / 100f);
|
||||
}
|
||||
|
||||
public void testEmptyStyleAttribute() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||
assertEquals(12, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||
|
||||
TtmlNode root = subtitle.getRoot();
|
||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||
TtmlNode fourthDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 3);
|
||||
|
||||
assertNull(queryChildrenForTag(fourthDiv, TtmlNode.TAG_P, 0).getStyleIds());
|
||||
assertThat(queryChildrenForTag(fourthDiv, TtmlNode.TAG_P, 0).getStyleIds()).isNull();
|
||||
}
|
||||
|
||||
public void testNonexistingStyleId() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||
assertEquals(12, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||
|
||||
TtmlNode root = subtitle.getRoot();
|
||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||
TtmlNode fifthDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 4);
|
||||
|
||||
assertEquals(1, queryChildrenForTag(fifthDiv, TtmlNode.TAG_P, 0).getStyleIds().length);
|
||||
assertThat(queryChildrenForTag(fifthDiv, TtmlNode.TAG_P, 0).getStyleIds()).hasLength(1);
|
||||
}
|
||||
|
||||
public void testNonExistingAndExistingStyleIdWithRedundantSpaces() throws IOException,
|
||||
SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||
assertEquals(12, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||
|
||||
TtmlNode root = subtitle.getRoot();
|
||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||
TtmlNode sixthDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 5);
|
||||
|
||||
String[] styleIds = queryChildrenForTag(sixthDiv, TtmlNode.TAG_P, 0).getStyleIds();
|
||||
assertEquals(2, styleIds.length);
|
||||
assertThat(styleIds).hasLength(2);
|
||||
}
|
||||
|
||||
public void testMultipleChaining() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(CHAIN_MULTIPLE_STYLES_TTML_FILE);
|
||||
assertEquals(2, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||
|
||||
Map<String, TtmlStyle> globalStyles = subtitle.getGlobalStyles();
|
||||
|
||||
TtmlStyle style = globalStyles.get("s2");
|
||||
assertEquals("serif", style.getFontFamily());
|
||||
assertEquals(0xFFFF0000, style.getBackgroundColor());
|
||||
assertEquals(0xFF000000, style.getFontColor());
|
||||
assertEquals(TtmlStyle.STYLE_BOLD_ITALIC, style.getStyle());
|
||||
assertTrue(style.isLinethrough());
|
||||
assertThat(style.getFontFamily()).isEqualTo("serif");
|
||||
assertThat(style.getBackgroundColor()).isEqualTo(0xFFFF0000);
|
||||
assertThat(style.getFontColor()).isEqualTo(0xFF000000);
|
||||
assertThat(style.getStyle()).isEqualTo(TtmlStyle.STYLE_BOLD_ITALIC);
|
||||
assertThat(style.isLinethrough()).isTrue();
|
||||
|
||||
style = globalStyles.get("s3");
|
||||
// only difference: color must be RED
|
||||
assertEquals(0xFFFF0000, style.getFontColor());
|
||||
assertEquals("serif", style.getFontFamily());
|
||||
assertEquals(0xFFFF0000, style.getBackgroundColor());
|
||||
assertEquals(TtmlStyle.STYLE_BOLD_ITALIC, style.getStyle());
|
||||
assertTrue(style.isLinethrough());
|
||||
assertThat(style.getFontColor()).isEqualTo(0xFFFF0000);
|
||||
assertThat(style.getFontFamily()).isEqualTo("serif");
|
||||
assertThat(style.getBackgroundColor()).isEqualTo(0xFFFF0000);
|
||||
assertThat(style.getStyle()).isEqualTo(TtmlStyle.STYLE_BOLD_ITALIC);
|
||||
assertThat(style.isLinethrough()).isTrue();
|
||||
}
|
||||
|
||||
public void testNoUnderline() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(NO_UNDERLINE_LINETHROUGH_TTML_FILE);
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
TtmlNode root = subtitle.getRoot();
|
||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||
TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0);
|
||||
|
||||
TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style;
|
||||
assertFalse("noUnderline from inline attribute expected", style.isUnderline());
|
||||
assertWithMessage("noUnderline from inline attribute expected")
|
||||
.that(style.isUnderline())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
public void testNoLinethrough() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(NO_UNDERLINE_LINETHROUGH_TTML_FILE);
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
TtmlNode root = subtitle.getRoot();
|
||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||
TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 1);
|
||||
|
||||
TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style;
|
||||
assertFalse("noLineThrough from inline attribute expected in second pNode",
|
||||
style.isLinethrough());
|
||||
assertWithMessage("noLineThrough from inline attribute expected in second pNode")
|
||||
.that(style.isLinethrough())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
public void testFontSizeSpans() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_TTML_FILE);
|
||||
assertEquals(10, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(10);
|
||||
|
||||
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("text 1", String.valueOf(spannable));
|
||||
assertThat(String.valueOf(spannable)).isEqualTo("text 1");
|
||||
assertAbsoluteFontSize(spannable, 32);
|
||||
|
||||
cues = subtitle.getCues(20 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("text 2", String.valueOf(cues.get(0).text));
|
||||
assertThat(String.valueOf(cues.get(0).text)).isEqualTo("text 2");
|
||||
assertRelativeFontSize(spannable, 2.2f);
|
||||
|
||||
cues = subtitle.getCues(30 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("text 3", String.valueOf(cues.get(0).text));
|
||||
assertThat(String.valueOf(cues.get(0).text)).isEqualTo("text 3");
|
||||
assertRelativeFontSize(spannable, 1.5f);
|
||||
|
||||
cues = subtitle.getCues(40 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("two values", String.valueOf(cues.get(0).text));
|
||||
assertThat(String.valueOf(cues.get(0).text)).isEqualTo("two values");
|
||||
assertAbsoluteFontSize(spannable, 16);
|
||||
|
||||
cues = subtitle.getCues(50 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("leading dot", String.valueOf(cues.get(0).text));
|
||||
assertThat(String.valueOf(cues.get(0).text)).isEqualTo("leading dot");
|
||||
assertRelativeFontSize(spannable, 0.5f);
|
||||
}
|
||||
|
||||
public void testFontSizeWithMissingUnitIsIgnored() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_MISSING_UNIT_TTML_FILE);
|
||||
assertEquals(2, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("no unit", String.valueOf(spannable));
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
||||
assertThat(String.valueOf(spannable)).isEqualTo("no unit");
|
||||
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||
}
|
||||
|
||||
public void testFontSizeWithInvalidValueIsIgnored() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_INVALID_TTML_FILE);
|
||||
assertEquals(6, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||
|
||||
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("invalid", String.valueOf(spannable));
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
||||
|
||||
assertThat(String.valueOf(spannable)).isEqualTo("invalid");
|
||||
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||
|
||||
cues = subtitle.getCues(20 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("invalid", String.valueOf(spannable));
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
||||
|
||||
assertThat(String.valueOf(spannable)).isEqualTo("invalid");
|
||||
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||
|
||||
cues = subtitle.getCues(30 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("invalid dot", String.valueOf(spannable));
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
||||
assertThat(String.valueOf(spannable)).isEqualTo("invalid dot");
|
||||
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||
}
|
||||
|
||||
public void testFontSizeWithEmptyValueIsIgnored() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_EMPTY_TTML_FILE);
|
||||
assertEquals(2, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
assertEquals("empty", String.valueOf(spannable));
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
||||
assertThat(String.valueOf(spannable)).isEqualTo("empty");
|
||||
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||
}
|
||||
|
||||
public void testFrameRate() throws IOException, SubtitleDecoderException {
|
||||
TtmlSubtitle subtitle = getSubtitle(FRAME_RATE_TTML_FILE);
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertEquals(1_000_000, subtitle.getEventTime(0));
|
||||
assertEquals(1_010_000, subtitle.getEventTime(1));
|
||||
assertEquals(1_001_000_000, subtitle.getEventTime(2), 1000);
|
||||
assertEquals(2_002_000_000, subtitle.getEventTime(3), 2000);
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
assertThat(subtitle.getEventTime(0)).isEqualTo(1_000_000);
|
||||
assertThat(subtitle.getEventTime(1)).isEqualTo(1_010_000);
|
||||
assertThat((double) subtitle.getEventTime(2)).isWithin(1000).of(1_001_000_000);
|
||||
assertThat((double) subtitle.getEventTime(3)).isWithin(2000).of(2_002_000_000);
|
||||
}
|
||||
|
||||
private void assertSpans(TtmlSubtitle subtitle, int second,
|
||||
|
|
@ -389,9 +393,9 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
long timeUs = second * 1000000;
|
||||
List<Cue> cues = subtitle.getCues(timeUs);
|
||||
|
||||
assertEquals(1, cues.size());
|
||||
assertEquals(text, String.valueOf(cues.get(0).text));
|
||||
assertEquals("single cue expected for timeUs: " + timeUs, 1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
assertThat(String.valueOf(cues.get(0).text)).isEqualTo(text);
|
||||
assertWithMessage("single cue expected for timeUs: " + timeUs).that(cues.size()).isEqualTo(1);
|
||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||
|
||||
assertFont(spannable, font);
|
||||
|
|
@ -407,67 +411,69 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
|||
private void assertAbsoluteFontSize(Spannable spannable, int absoluteFontSize) {
|
||||
AbsoluteSizeSpan[] absoluteSizeSpans = spannable.getSpans(0, spannable.length(),
|
||||
AbsoluteSizeSpan.class);
|
||||
assertEquals(1, absoluteSizeSpans.length);
|
||||
assertEquals(absoluteFontSize, absoluteSizeSpans[0].getSize());
|
||||
assertThat(absoluteSizeSpans).hasLength(1);
|
||||
assertThat(absoluteSizeSpans[0].getSize()).isEqualTo(absoluteFontSize);
|
||||
}
|
||||
|
||||
private void assertRelativeFontSize(Spannable spannable, float relativeFontSize) {
|
||||
RelativeSizeSpan[] relativeSizeSpans = spannable.getSpans(0, spannable.length(),
|
||||
RelativeSizeSpan.class);
|
||||
assertEquals(1, relativeSizeSpans.length);
|
||||
assertEquals(relativeFontSize, relativeSizeSpans[0].getSizeChange());
|
||||
assertThat(relativeSizeSpans).hasLength(1);
|
||||
assertThat(relativeSizeSpans[0].getSizeChange()).isEqualTo(relativeFontSize);
|
||||
}
|
||||
|
||||
private void assertFont(Spannable spannable, String font) {
|
||||
TypefaceSpan[] typefaceSpans = spannable.getSpans(0, spannable.length(), TypefaceSpan.class);
|
||||
assertEquals(font, typefaceSpans[typefaceSpans.length - 1].getFamily());
|
||||
assertThat(typefaceSpans[typefaceSpans.length - 1].getFamily()).isEqualTo(font);
|
||||
}
|
||||
|
||||
private void assertStyle(Spannable spannable, int fontStyle) {
|
||||
StyleSpan[] styleSpans = spannable.getSpans(0, spannable.length(), StyleSpan.class);
|
||||
assertEquals(fontStyle, styleSpans[styleSpans.length - 1].getStyle());
|
||||
assertThat(styleSpans[styleSpans.length - 1].getStyle()).isEqualTo(fontStyle);
|
||||
}
|
||||
|
||||
private void assertUnderline(Spannable spannable, boolean isUnderline) {
|
||||
UnderlineSpan[] underlineSpans = spannable.getSpans(0, spannable.length(), UnderlineSpan.class);
|
||||
assertEquals(isUnderline ? "must be underlined" : "must not be underlined",
|
||||
isUnderline ? 1 : 0, underlineSpans.length);
|
||||
assertWithMessage(isUnderline ? "must be underlined" : "must not be underlined")
|
||||
.that(underlineSpans)
|
||||
.hasLength(isUnderline ? 1 : 0);
|
||||
}
|
||||
|
||||
private void assertStrikethrough(Spannable spannable, boolean isStrikethrough) {
|
||||
StrikethroughSpan[] striketroughSpans = spannable.getSpans(0, spannable.length(),
|
||||
StrikethroughSpan.class);
|
||||
assertEquals(isStrikethrough ? "must be strikethrough" : "must not be strikethrough",
|
||||
isStrikethrough ? 1 : 0, striketroughSpans.length);
|
||||
assertWithMessage(isStrikethrough ? "must be strikethrough" : "must not be strikethrough")
|
||||
.that(striketroughSpans)
|
||||
.hasLength(isStrikethrough ? 1 : 0);
|
||||
}
|
||||
|
||||
private void assertBackground(Spannable spannable, int backgroundColor) {
|
||||
BackgroundColorSpan[] backgroundColorSpans =
|
||||
spannable.getSpans(0, spannable.length(), BackgroundColorSpan.class);
|
||||
if (backgroundColor != 0) {
|
||||
assertEquals(backgroundColor, backgroundColorSpans[backgroundColorSpans.length - 1]
|
||||
.getBackgroundColor());
|
||||
assertThat(backgroundColorSpans[backgroundColorSpans.length - 1].getBackgroundColor())
|
||||
.isEqualTo(backgroundColor);
|
||||
} else {
|
||||
assertEquals(0, backgroundColorSpans.length);
|
||||
assertThat(backgroundColorSpans).hasLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertForeground(Spannable spannable, int foregroundColor) {
|
||||
ForegroundColorSpan[] foregroundColorSpans =
|
||||
spannable.getSpans(0, spannable.length(), ForegroundColorSpan.class);
|
||||
assertEquals(foregroundColor,
|
||||
foregroundColorSpans[foregroundColorSpans.length - 1].getForegroundColor());
|
||||
assertThat(foregroundColorSpans[foregroundColorSpans.length - 1].getForegroundColor())
|
||||
.isEqualTo(foregroundColor);
|
||||
}
|
||||
|
||||
private void assertAlignment(Spannable spannable, Layout.Alignment alignment) {
|
||||
if (alignment != null) {
|
||||
AlignmentSpan.Standard[] alignmentSpans =
|
||||
spannable.getSpans(0, spannable.length(), AlignmentSpan.Standard.class);
|
||||
assertEquals(1, alignmentSpans.length);
|
||||
assertEquals(alignment, alignmentSpans[0].getAlignment());
|
||||
assertThat(alignmentSpans).hasLength(1);
|
||||
assertThat(alignmentSpans[0].getAlignment()).isEqualTo(alignment);
|
||||
} else {
|
||||
assertEquals(0, spannable.getSpans
|
||||
(0, spannable.length(), AlignmentSpan.Standard.class).length);
|
||||
assertThat(spannable.getSpans(0, spannable.length(), AlignmentSpan.Standard.class))
|
||||
.hasLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.text.tx3g;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
|
@ -52,7 +54,7 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
Tx3gDecoder decoder = new Tx3gDecoder(Collections.<byte[]>emptyList());
|
||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_SUBTITLE);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
assertTrue(subtitle.getCues(0).isEmpty());
|
||||
assertThat(subtitle.getCues(0)).isEmpty();
|
||||
}
|
||||
|
||||
public void testDecodeJustText() throws IOException, SubtitleDecoderException {
|
||||
|
|
@ -60,8 +62,8 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_JUST_TEXT);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("CC Test", text.toString());
|
||||
assertEquals(0, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("CC Test");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(0);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
||||
}
|
||||
|
||||
|
|
@ -70,13 +72,13 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("CC Test", text.toString());
|
||||
assertEquals(3, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("CC Test");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(3);
|
||||
StyleSpan styleSpan = findSpan(text, 0, 6, StyleSpan.class);
|
||||
assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
|
||||
assertThat(styleSpan.getStyle()).isEqualTo(Typeface.BOLD_ITALIC);
|
||||
findSpan(text, 0, 6, UnderlineSpan.class);
|
||||
ForegroundColorSpan colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class);
|
||||
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
|
||||
assertThat(colorSpan.getForegroundColor()).isEqualTo(Color.GREEN);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
||||
}
|
||||
|
||||
|
|
@ -85,8 +87,8 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL_ALL_DEFAULTS);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("CC Test", text.toString());
|
||||
assertEquals(0, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("CC Test");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(0);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
||||
}
|
||||
|
||||
|
|
@ -95,8 +97,8 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_UTF16_BE_NO_STYL);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("你好", text.toString());
|
||||
assertEquals(0, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("你好");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(0);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
||||
}
|
||||
|
||||
|
|
@ -105,8 +107,8 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_UTF16_LE_NO_STYL);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("你好", text.toString());
|
||||
assertEquals(0, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("你好");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(0);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
||||
}
|
||||
|
||||
|
|
@ -115,15 +117,15 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_MULTIPLE_STYL);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("Line 2\nLine 3", text.toString());
|
||||
assertEquals(4, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("Line 2\nLine 3");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(4);
|
||||
StyleSpan styleSpan = findSpan(text, 0, 5, StyleSpan.class);
|
||||
assertEquals(Typeface.ITALIC, styleSpan.getStyle());
|
||||
assertThat(styleSpan.getStyle()).isEqualTo(Typeface.ITALIC);
|
||||
findSpan(text, 7, 12, UnderlineSpan.class);
|
||||
ForegroundColorSpan colorSpan = findSpan(text, 0, 5, ForegroundColorSpan.class);
|
||||
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
|
||||
assertThat(colorSpan.getForegroundColor()).isEqualTo(Color.GREEN);
|
||||
colorSpan = findSpan(text, 7, 12, ForegroundColorSpan.class);
|
||||
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
|
||||
assertThat(colorSpan.getForegroundColor()).isEqualTo(Color.GREEN);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
||||
}
|
||||
|
||||
|
|
@ -132,12 +134,12 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_OTHER_EXTENSION);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("CC Test", text.toString());
|
||||
assertEquals(2, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("CC Test");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(2);
|
||||
StyleSpan styleSpan = findSpan(text, 0, 6, StyleSpan.class);
|
||||
assertEquals(Typeface.BOLD, styleSpan.getStyle());
|
||||
assertThat(styleSpan.getStyle()).isEqualTo(Typeface.BOLD);
|
||||
ForegroundColorSpan colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class);
|
||||
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
|
||||
assertThat(colorSpan.getForegroundColor()).isEqualTo(Color.GREEN);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
||||
}
|
||||
|
||||
|
|
@ -147,17 +149,17 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("CC Test", text.toString());
|
||||
assertEquals(5, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("CC Test");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(5);
|
||||
StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class);
|
||||
assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
|
||||
assertThat(styleSpan.getStyle()).isEqualTo(Typeface.BOLD_ITALIC);
|
||||
findSpan(text, 0, text.length(), UnderlineSpan.class);
|
||||
TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.class);
|
||||
assertEquals(C.SERIF_NAME, typefaceSpan.getFamily());
|
||||
assertThat(typefaceSpan.getFamily()).isEqualTo(C.SERIF_NAME);
|
||||
ForegroundColorSpan colorSpan = findSpan(text, 0, text.length(), ForegroundColorSpan.class);
|
||||
assertEquals(Color.RED, colorSpan.getForegroundColor());
|
||||
assertThat(colorSpan.getForegroundColor()).isEqualTo(Color.RED);
|
||||
colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class);
|
||||
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
|
||||
assertThat(colorSpan.getForegroundColor()).isEqualTo(Color.GREEN);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.1f);
|
||||
}
|
||||
|
||||
|
|
@ -167,15 +169,15 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_TBOX);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("CC Test", text.toString());
|
||||
assertEquals(4, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("CC Test");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(4);
|
||||
StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class);
|
||||
assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
|
||||
assertThat(styleSpan.getStyle()).isEqualTo(Typeface.BOLD_ITALIC);
|
||||
findSpan(text, 0, text.length(), UnderlineSpan.class);
|
||||
TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.class);
|
||||
assertEquals(C.SERIF_NAME, typefaceSpan.getFamily());
|
||||
assertThat(typefaceSpan.getFamily()).isEqualTo(C.SERIF_NAME);
|
||||
ForegroundColorSpan colorSpan = findSpan(text, 0, text.length(), ForegroundColorSpan.class);
|
||||
assertEquals(Color.RED, colorSpan.getForegroundColor());
|
||||
assertThat(colorSpan.getForegroundColor()).isEqualTo(Color.RED);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.1875f);
|
||||
}
|
||||
|
||||
|
|
@ -186,13 +188,13 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
|
||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||
assertEquals("CC Test", text.toString());
|
||||
assertEquals(3, text.getSpans(0, text.length(), Object.class).length);
|
||||
assertThat(text.toString()).isEqualTo("CC Test");
|
||||
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(3);
|
||||
StyleSpan styleSpan = findSpan(text, 0, 6, StyleSpan.class);
|
||||
assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
|
||||
assertThat(styleSpan.getStyle()).isEqualTo(Typeface.BOLD_ITALIC);
|
||||
findSpan(text, 0, 6, UnderlineSpan.class);
|
||||
ForegroundColorSpan colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class);
|
||||
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
|
||||
assertThat(colorSpan.getForegroundColor()).isEqualTo(Color.GREEN);
|
||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
||||
}
|
||||
|
||||
|
|
@ -210,9 +212,9 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
private static void assertFractionalLinePosition(Cue cue, float expectedFraction) {
|
||||
assertEquals(Cue.LINE_TYPE_FRACTION, cue.lineType);
|
||||
assertEquals(Cue.ANCHOR_TYPE_START, cue.lineAnchor);
|
||||
assertTrue(Math.abs(expectedFraction - cue.line) < 1e-6);
|
||||
assertThat(cue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
|
||||
assertThat(cue.lineAnchor).isEqualTo(Cue.ANCHOR_TYPE_START);
|
||||
assertThat(Math.abs(expectedFraction - cue.line) < 1e-6).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.text.webvtt;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.text.Layout.Alignment;
|
||||
|
|
@ -61,7 +63,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_FILE);
|
||||
|
||||
// Test event count.
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
// Test cues.
|
||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
||||
|
|
@ -72,7 +74,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_WITH_BAD_TIMESTAMPS);
|
||||
|
||||
// Test event count.
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
// Test cues.
|
||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
||||
|
|
@ -83,7 +85,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_WITH_IDS_FILE);
|
||||
|
||||
// Test event count.
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
// Test cues.
|
||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
||||
|
|
@ -94,7 +96,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_WITH_COMMENTS_FILE);
|
||||
|
||||
// test event count
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
// test cues
|
||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
||||
|
|
@ -105,7 +107,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_TAGS_FILE);
|
||||
|
||||
// Test event count.
|
||||
assertEquals(8, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(8);
|
||||
|
||||
// Test cues.
|
||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
||||
|
|
@ -117,7 +119,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
public void testDecodeWithPositioning() throws IOException, SubtitleDecoderException {
|
||||
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_POSITIONING_FILE);
|
||||
// Test event count.
|
||||
assertEquals(12, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||
// Test cues.
|
||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.", Alignment.ALIGN_NORMAL,
|
||||
Cue.DIMEN_UNSET, Cue.TYPE_UNSET, Cue.TYPE_UNSET, 0.1f, Cue.ANCHOR_TYPE_START, 0.35f);
|
||||
|
|
@ -142,7 +144,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_BAD_CUE_HEADER_FILE);
|
||||
|
||||
// Test event count.
|
||||
assertEquals(4, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||
|
||||
// Test cues.
|
||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
||||
|
|
@ -153,7 +155,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_CSS_STYLES);
|
||||
|
||||
// Test event count.
|
||||
assertEquals(8, subtitle.getEventTimeCount());
|
||||
assertThat(subtitle.getEventTimeCount()).isEqualTo(8);
|
||||
|
||||
// Test cues.
|
||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
||||
|
|
@ -163,43 +165,50 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
Spanned s2 = getUniqueSpanTextAt(subtitle, 2345000);
|
||||
Spanned s3 = getUniqueSpanTextAt(subtitle, 20000000);
|
||||
Spanned s4 = getUniqueSpanTextAt(subtitle, 25000000);
|
||||
assertEquals(1, s1.getSpans(0, s1.length(), ForegroundColorSpan.class).length);
|
||||
assertEquals(1, s1.getSpans(0, s1.length(), BackgroundColorSpan.class).length);
|
||||
assertEquals(2, s2.getSpans(0, s2.length(), ForegroundColorSpan.class).length);
|
||||
assertEquals(1, s3.getSpans(10, s3.length(), UnderlineSpan.class).length);
|
||||
assertEquals(2, s4.getSpans(0, 16, BackgroundColorSpan.class).length);
|
||||
assertEquals(1, s4.getSpans(17, s4.length(), StyleSpan.class).length);
|
||||
assertEquals(Typeface.BOLD, s4.getSpans(17, s4.length(), StyleSpan.class)[0].getStyle());
|
||||
assertThat(s1.getSpans(0, s1.length(), ForegroundColorSpan.class)).hasLength(1);
|
||||
assertThat(s1.getSpans(0, s1.length(), BackgroundColorSpan.class)).hasLength(1);
|
||||
assertThat(s2.getSpans(0, s2.length(), ForegroundColorSpan.class)).hasLength(2);
|
||||
assertThat(s3.getSpans(10, s3.length(), UnderlineSpan.class)).hasLength(1);
|
||||
assertThat(s4.getSpans(0, 16, BackgroundColorSpan.class)).hasLength(2);
|
||||
assertThat(s4.getSpans(17, s4.length(), StyleSpan.class)).hasLength(1);
|
||||
assertThat(s4.getSpans(17, s4.length(), StyleSpan.class)[0].getStyle())
|
||||
.isEqualTo(Typeface.BOLD);
|
||||
}
|
||||
|
||||
public void testWithComplexCssSelectors() throws IOException, SubtitleDecoderException {
|
||||
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_CSS_COMPLEX_SELECTORS);
|
||||
Spanned text = getUniqueSpanTextAt(subtitle, 0);
|
||||
assertEquals(1, text.getSpans(30, text.length(), ForegroundColorSpan.class).length);
|
||||
assertEquals(0xFFEE82EE,
|
||||
text.getSpans(30, text.length(), ForegroundColorSpan.class)[0].getForegroundColor());
|
||||
assertEquals(1, text.getSpans(30, text.length(), TypefaceSpan.class).length);
|
||||
assertEquals("courier", text.getSpans(30, text.length(), TypefaceSpan.class)[0].getFamily());
|
||||
assertThat(text.getSpans(30, text.length(), ForegroundColorSpan.class)).hasLength(1);
|
||||
assertThat(text.getSpans(30, text.length(), ForegroundColorSpan.class)[0].getForegroundColor())
|
||||
.isEqualTo(0xFFEE82EE);
|
||||
assertThat(text.getSpans(30, text.length(), TypefaceSpan.class)).hasLength(1);
|
||||
assertThat(text.getSpans(30, text.length(), TypefaceSpan.class)[0].getFamily())
|
||||
.isEqualTo("courier");
|
||||
|
||||
text = getUniqueSpanTextAt(subtitle, 2000000);
|
||||
assertEquals(1, text.getSpans(5, text.length(), TypefaceSpan.class).length);
|
||||
assertEquals("courier", text.getSpans(5, text.length(), TypefaceSpan.class)[0].getFamily());
|
||||
assertThat(text.getSpans(5, text.length(), TypefaceSpan.class)).hasLength(1);
|
||||
assertThat(text.getSpans(5, text.length(), TypefaceSpan.class)[0].getFamily())
|
||||
.isEqualTo("courier");
|
||||
|
||||
text = getUniqueSpanTextAt(subtitle, 2500000);
|
||||
assertEquals(1, text.getSpans(5, text.length(), StyleSpan.class).length);
|
||||
assertEquals(Typeface.BOLD, text.getSpans(5, text.length(), StyleSpan.class)[0].getStyle());
|
||||
assertEquals(1, text.getSpans(5, text.length(), TypefaceSpan.class).length);
|
||||
assertEquals("courier", text.getSpans(5, text.length(), TypefaceSpan.class)[0].getFamily());
|
||||
assertThat(text.getSpans(5, text.length(), StyleSpan.class)).hasLength(1);
|
||||
assertThat(text.getSpans(5, text.length(), StyleSpan.class)[0].getStyle())
|
||||
.isEqualTo(Typeface.BOLD);
|
||||
assertThat(text.getSpans(5, text.length(), TypefaceSpan.class)).hasLength(1);
|
||||
assertThat(text.getSpans(5, text.length(), TypefaceSpan.class)[0].getFamily())
|
||||
.isEqualTo("courier");
|
||||
|
||||
text = getUniqueSpanTextAt(subtitle, 4000000);
|
||||
assertEquals(0, text.getSpans(6, 22, StyleSpan.class).length);
|
||||
assertEquals(1, text.getSpans(30, text.length(), StyleSpan.class).length);
|
||||
assertEquals(Typeface.BOLD, text.getSpans(30, text.length(), StyleSpan.class)[0].getStyle());
|
||||
assertThat(text.getSpans(6, 22, StyleSpan.class)).hasLength(0);
|
||||
assertThat(text.getSpans(30, text.length(), StyleSpan.class)).hasLength(1);
|
||||
assertThat(text.getSpans(30, text.length(), StyleSpan.class)[0].getStyle())
|
||||
.isEqualTo(Typeface.BOLD);
|
||||
|
||||
text = getUniqueSpanTextAt(subtitle, 5000000);
|
||||
assertEquals(0, text.getSpans(9, 17, StyleSpan.class).length);
|
||||
assertEquals(1, text.getSpans(19, text.length(), StyleSpan.class).length);
|
||||
assertEquals(Typeface.ITALIC, text.getSpans(19, text.length(), StyleSpan.class)[0].getStyle());
|
||||
assertThat(text.getSpans(9, 17, StyleSpan.class)).hasLength(0);
|
||||
assertThat(text.getSpans(19, text.length(), StyleSpan.class)).hasLength(1);
|
||||
assertThat(text.getSpans(19, text.length(), StyleSpan.class)[0].getStyle())
|
||||
.isEqualTo(Typeface.ITALIC);
|
||||
}
|
||||
|
||||
private WebvttSubtitle getSubtitleForTestAsset(String asset) throws IOException,
|
||||
|
|
@ -222,20 +231,20 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
|||
private static void assertCue(WebvttSubtitle subtitle, int eventTimeIndex, long startTimeUs,
|
||||
int endTimeUs, String text, Alignment textAlignment, float line, int lineType, int lineAnchor,
|
||||
float position, int positionAnchor, float size) {
|
||||
assertEquals(startTimeUs, subtitle.getEventTime(eventTimeIndex));
|
||||
assertEquals(endTimeUs, subtitle.getEventTime(eventTimeIndex + 1));
|
||||
assertThat(subtitle.getEventTime(eventTimeIndex)).isEqualTo(startTimeUs);
|
||||
assertThat(subtitle.getEventTime(eventTimeIndex + 1)).isEqualTo(endTimeUs);
|
||||
List<Cue> cues = subtitle.getCues(subtitle.getEventTime(eventTimeIndex));
|
||||
assertEquals(1, cues.size());
|
||||
assertThat(cues).hasSize(1);
|
||||
// Assert cue properties.
|
||||
Cue cue = cues.get(0);
|
||||
assertEquals(text, cue.text.toString());
|
||||
assertEquals(textAlignment, cue.textAlignment);
|
||||
assertEquals(line, cue.line);
|
||||
assertEquals(lineType, cue.lineType);
|
||||
assertEquals(lineAnchor, cue.lineAnchor);
|
||||
assertEquals(position, cue.position);
|
||||
assertEquals(positionAnchor, cue.positionAnchor);
|
||||
assertEquals(size, cue.size);
|
||||
assertThat(cue.text.toString()).isEqualTo(text);
|
||||
assertThat(cue.textAlignment).isEqualTo(textAlignment);
|
||||
assertThat(cue.line).isEqualTo(line);
|
||||
assertThat(cue.lineType).isEqualTo(lineType);
|
||||
assertThat(cue.lineAnchor).isEqualTo(lineAnchor);
|
||||
assertThat(cue.position).isEqualTo(position);
|
||||
assertThat(cue.positionAnchor).isEqualTo(positionAnchor);
|
||||
assertThat(cue.size).isEqualTo(size);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.upstream;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentResolver;
|
||||
|
|
@ -75,7 +77,7 @@ public final class ContentDataSourceTest extends InstrumentationTestCase {
|
|||
fail();
|
||||
} catch (ContentDataSource.ContentDataSourceException e) {
|
||||
// Expected.
|
||||
assertTrue(e.getCause() instanceof FileNotFoundException);
|
||||
assertThat(e.getCause()).isInstanceOf(FileNotFoundException.class);
|
||||
} finally {
|
||||
dataSource.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
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.test.InstrumentationTestCase;
|
||||
import android.test.MoreAsserts;
|
||||
import android.util.SparseArray;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
|
@ -9,10 +11,8 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
/**
|
||||
* Tests {@link CachedContentIndex}.
|
||||
|
|
@ -56,47 +56,45 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
CachedContent cachedContent1 = new CachedContent(5, key1, 10);
|
||||
index.addNew(cachedContent1);
|
||||
CachedContent cachedContent2 = index.getOrAdd(key2);
|
||||
assertTrue(cachedContent1.id != cachedContent2.id);
|
||||
assertThat(cachedContent1.id != cachedContent2.id).isTrue();
|
||||
|
||||
// add a span
|
||||
File cacheSpanFile = SimpleCacheSpanTest
|
||||
.createCacheSpanFile(cacheDir, cachedContent1.id, 10, 20, 30);
|
||||
SimpleCacheSpan span = SimpleCacheSpan.createCacheEntry(cacheSpanFile, index);
|
||||
assertNotNull(span);
|
||||
assertThat(span).isNotNull();
|
||||
cachedContent1.addSpan(span);
|
||||
|
||||
// Check if they are added and get method returns null if the key isn't found
|
||||
assertEquals(cachedContent1, index.get(key1));
|
||||
assertEquals(cachedContent2, index.get(key2));
|
||||
assertNull(index.get(key3));
|
||||
assertThat(index.get(key1)).isEqualTo(cachedContent1);
|
||||
assertThat(index.get(key2)).isEqualTo(cachedContent2);
|
||||
assertThat(index.get(key3)).isNull();
|
||||
|
||||
// test getAll()
|
||||
Collection<CachedContent> cachedContents = index.getAll();
|
||||
assertEquals(2, cachedContents.size());
|
||||
assertTrue(Arrays.asList(cachedContent1, cachedContent2).containsAll(cachedContents));
|
||||
assertThat(cachedContents).containsExactly(cachedContent1, cachedContent2);
|
||||
|
||||
// test getKeys()
|
||||
Set<String> keys = index.getKeys();
|
||||
assertEquals(2, keys.size());
|
||||
assertTrue(Arrays.asList(key1, key2).containsAll(keys));
|
||||
assertThat(keys).containsExactly(key1, key2);
|
||||
|
||||
// test getKeyForId()
|
||||
assertEquals(key1, index.getKeyForId(cachedContent1.id));
|
||||
assertEquals(key2, index.getKeyForId(cachedContent2.id));
|
||||
assertThat(index.getKeyForId(cachedContent1.id)).isEqualTo(key1);
|
||||
assertThat(index.getKeyForId(cachedContent2.id)).isEqualTo(key2);
|
||||
|
||||
// test remove()
|
||||
index.maybeRemove(key2);
|
||||
index.maybeRemove(key3);
|
||||
assertEquals(cachedContent1, index.get(key1));
|
||||
assertNull(index.get(key2));
|
||||
assertTrue(cacheSpanFile.exists());
|
||||
assertThat(index.get(key1)).isEqualTo(cachedContent1);
|
||||
assertThat(index.get(key2)).isNull();
|
||||
assertThat(cacheSpanFile.exists()).isTrue();
|
||||
|
||||
// test removeEmpty()
|
||||
index.addNew(cachedContent2);
|
||||
index.removeEmpty();
|
||||
assertEquals(cachedContent1, index.get(key1));
|
||||
assertNull(index.get(key2));
|
||||
assertTrue(cacheSpanFile.exists());
|
||||
assertThat(index.get(key1)).isEqualTo(cachedContent1);
|
||||
assertThat(index.get(key2)).isNull();
|
||||
assertThat(cacheSpanFile.exists()).isTrue();
|
||||
}
|
||||
|
||||
public void testStoreAndLoad() throws Exception {
|
||||
|
|
@ -109,11 +107,11 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
fos.close();
|
||||
|
||||
index.load();
|
||||
assertEquals(2, index.getAll().size());
|
||||
assertEquals(5, index.assignIdForKey("ABCDE"));
|
||||
assertEquals(10, index.getContentLength("ABCDE"));
|
||||
assertEquals(2, index.assignIdForKey("KLMNO"));
|
||||
assertEquals(2560, index.getContentLength("KLMNO"));
|
||||
assertThat(index.getAll()).hasSize(2);
|
||||
assertThat(index.assignIdForKey("ABCDE")).isEqualTo(5);
|
||||
assertThat(index.getContentLength("ABCDE")).isEqualTo(10);
|
||||
assertThat(index.assignIdForKey("KLMNO")).isEqualTo(2);
|
||||
assertThat(index.getContentLength("KLMNO")).isEqualTo(2560);
|
||||
}
|
||||
|
||||
public void testStoreV1() throws Exception {
|
||||
|
|
@ -124,13 +122,13 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
|
||||
byte[] buffer = new byte[testIndexV1File.length];
|
||||
FileInputStream fos = new FileInputStream(new File(cacheDir, CachedContentIndex.FILE_NAME));
|
||||
assertEquals(testIndexV1File.length, fos.read(buffer));
|
||||
assertEquals(-1, fos.read());
|
||||
assertThat(fos.read(buffer)).isEqualTo(testIndexV1File.length);
|
||||
assertThat(fos.read()).isEqualTo(-1);
|
||||
fos.close();
|
||||
|
||||
// TODO: The order of the CachedContent stored in index file isn't defined so this test may fail
|
||||
// on a different implementation of the underlying set
|
||||
MoreAsserts.assertEquals(testIndexV1File, buffer);
|
||||
assertThat(buffer).isEqualTo(testIndexV1File);
|
||||
}
|
||||
|
||||
public void testAssignIdForKeyAndGetKeyForId() throws Exception {
|
||||
|
|
@ -138,29 +136,29 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
final String key2 = "key2";
|
||||
int id1 = index.assignIdForKey(key1);
|
||||
int id2 = index.assignIdForKey(key2);
|
||||
assertEquals(key1, index.getKeyForId(id1));
|
||||
assertEquals(key2, index.getKeyForId(id2));
|
||||
assertTrue(id1 != id2);
|
||||
assertEquals(id1, index.assignIdForKey(key1));
|
||||
assertEquals(id2, index.assignIdForKey(key2));
|
||||
assertThat(index.getKeyForId(id1)).isEqualTo(key1);
|
||||
assertThat(index.getKeyForId(id2)).isEqualTo(key2);
|
||||
assertThat(id1 != id2).isTrue();
|
||||
assertThat(index.assignIdForKey(key1)).isEqualTo(id1);
|
||||
assertThat(index.assignIdForKey(key2)).isEqualTo(id2);
|
||||
}
|
||||
|
||||
public void testSetGetContentLength() throws Exception {
|
||||
final String key1 = "key1";
|
||||
assertEquals(C.LENGTH_UNSET, index.getContentLength(key1));
|
||||
assertThat(index.getContentLength(key1)).isEqualTo(C.LENGTH_UNSET);
|
||||
index.setContentLength(key1, 10);
|
||||
assertEquals(10, index.getContentLength(key1));
|
||||
assertThat(index.getContentLength(key1)).isEqualTo(10);
|
||||
}
|
||||
|
||||
public void testGetNewId() throws Exception {
|
||||
SparseArray<String> idToKey = new SparseArray<>();
|
||||
assertEquals(0, CachedContentIndex.getNewId(idToKey));
|
||||
assertThat(CachedContentIndex.getNewId(idToKey)).isEqualTo(0);
|
||||
idToKey.put(10, "");
|
||||
assertEquals(11, CachedContentIndex.getNewId(idToKey));
|
||||
assertThat(CachedContentIndex.getNewId(idToKey)).isEqualTo(11);
|
||||
idToKey.put(Integer.MAX_VALUE, "");
|
||||
assertEquals(0, CachedContentIndex.getNewId(idToKey));
|
||||
assertThat(CachedContentIndex.getNewId(idToKey)).isEqualTo(0);
|
||||
idToKey.put(0, "");
|
||||
assertEquals(1, CachedContentIndex.getNewId(idToKey));
|
||||
assertThat(CachedContentIndex.getNewId(idToKey)).isEqualTo(1);
|
||||
}
|
||||
|
||||
public void testEncryption() throws Exception {
|
||||
|
|
@ -173,36 +171,40 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
// Rename the index file from the test above
|
||||
File file1 = new File(cacheDir, CachedContentIndex.FILE_NAME);
|
||||
File file2 = new File(cacheDir, "file2compare");
|
||||
assertTrue(file1.renameTo(file2));
|
||||
assertThat(file1.renameTo(file2)).isTrue();
|
||||
|
||||
// Write a new index file
|
||||
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
||||
new CachedContentIndex(cacheDir, key));
|
||||
|
||||
assertEquals(file2.length(), file1.length());
|
||||
assertThat(file1.length()).isEqualTo(file2.length());
|
||||
// Assert file content is different
|
||||
FileInputStream fis1 = new FileInputStream(file1);
|
||||
FileInputStream fis2 = new FileInputStream(file2);
|
||||
for (int b; (b = fis1.read()) == fis2.read(); ) {
|
||||
assertTrue(b != -1);
|
||||
assertThat(b != -1).isTrue();
|
||||
}
|
||||
|
||||
boolean threw = false;
|
||||
try {
|
||||
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
||||
new CachedContentIndex(cacheDir, key2));
|
||||
} catch (AssertionFailedError e) {
|
||||
} catch (AssertionError e) {
|
||||
threw = true;
|
||||
}
|
||||
assertTrue("Encrypted index file can not be read with different encryption key", threw);
|
||||
assertWithMessage("Encrypted index file can not be read with different encryption key")
|
||||
.that(threw)
|
||||
.isTrue();
|
||||
|
||||
try {
|
||||
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
||||
new CachedContentIndex(cacheDir));
|
||||
} catch (AssertionFailedError e) {
|
||||
} catch (AssertionError e) {
|
||||
threw = true;
|
||||
}
|
||||
assertTrue("Encrypted index file can not be read without encryption key", threw);
|
||||
assertWithMessage("Encrypted index file can not be read without encryption key")
|
||||
.that(threw)
|
||||
.isTrue();
|
||||
|
||||
// Non encrypted index file can be read even when encryption key provided.
|
||||
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir),
|
||||
|
|
@ -221,7 +223,7 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
|
||||
index.maybeRemove(cachedContent.key);
|
||||
|
||||
assertNull(index.get(cachedContent.key));
|
||||
assertThat(index.get(cachedContent.key)).isNull();
|
||||
}
|
||||
|
||||
public void testCantRemoveNotEmptyCachedContent() throws Exception {
|
||||
|
|
@ -234,7 +236,7 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
|
||||
index.maybeRemove(cachedContent.key);
|
||||
|
||||
assertNotNull(index.get(cachedContent.key));
|
||||
assertThat(index.get(cachedContent.key)).isNotNull();
|
||||
}
|
||||
|
||||
public void testCantRemoveLockedCachedContent() throws Exception {
|
||||
|
|
@ -244,7 +246,7 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
|
||||
index.maybeRemove(cachedContent.key);
|
||||
|
||||
assertNotNull(index.get(cachedContent.key));
|
||||
assertThat(index.get(cachedContent.key)).isNotNull();
|
||||
}
|
||||
|
||||
private void assertStoredAndLoadedEqual(CachedContentIndex index, CachedContentIndex index2)
|
||||
|
|
@ -256,10 +258,10 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
|||
index2.load();
|
||||
Set<String> keys = index.getKeys();
|
||||
Set<String> keys2 = index2.getKeys();
|
||||
assertEquals(keys, keys2);
|
||||
assertThat(keys2).isEqualTo(keys);
|
||||
for (String key : keys) {
|
||||
assertEquals(index.getContentLength(key), index2.getContentLength(key));
|
||||
assertEquals(index.get(key).getSpans(), index2.get(key).getSpans());
|
||||
assertThat(index2.getContentLength(key)).isEqualTo(index.getContentLength(key));
|
||||
assertThat(index2.get(key).getSpans()).isEqualTo(index.get(key).getSpans());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.upstream.cache;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
|
@ -67,8 +68,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
public void testGetRegion_noSpansInCache() {
|
||||
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(100));
|
||||
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(150));
|
||||
assertThat(tracker.getRegionEndTimeMs(100)).isEqualTo(CachedRegionTracker.NOT_CACHED);
|
||||
assertThat(tracker.getRegionEndTimeMs(150)).isEqualTo(CachedRegionTracker.NOT_CACHED);
|
||||
}
|
||||
|
||||
public void testGetRegion_fullyCached() throws Exception {
|
||||
|
|
@ -76,8 +77,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
|||
cache,
|
||||
newCacheSpan(100, 100));
|
||||
|
||||
assertEquals(CachedRegionTracker.CACHED_TO_END, tracker.getRegionEndTimeMs(101));
|
||||
assertEquals(CachedRegionTracker.CACHED_TO_END, tracker.getRegionEndTimeMs(121));
|
||||
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(CachedRegionTracker.CACHED_TO_END);
|
||||
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(CachedRegionTracker.CACHED_TO_END);
|
||||
}
|
||||
|
||||
public void testGetRegion_partiallyCached() throws Exception {
|
||||
|
|
@ -85,8 +86,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
|||
cache,
|
||||
newCacheSpan(100, 40));
|
||||
|
||||
assertEquals(200, tracker.getRegionEndTimeMs(101));
|
||||
assertEquals(200, tracker.getRegionEndTimeMs(121));
|
||||
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
|
||||
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(200);
|
||||
}
|
||||
|
||||
public void testGetRegion_multipleSpanAddsJoinedCorrectly() throws Exception {
|
||||
|
|
@ -97,8 +98,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
|||
cache,
|
||||
newCacheSpan(120, 20));
|
||||
|
||||
assertEquals(200, tracker.getRegionEndTimeMs(101));
|
||||
assertEquals(200, tracker.getRegionEndTimeMs(121));
|
||||
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
|
||||
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(200);
|
||||
}
|
||||
|
||||
public void testGetRegion_fullyCachedThenPartiallyRemoved() throws Exception {
|
||||
|
|
@ -112,10 +113,10 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
|||
cache,
|
||||
newCacheSpan(140, 40));
|
||||
|
||||
assertEquals(200, tracker.getRegionEndTimeMs(101));
|
||||
assertEquals(200, tracker.getRegionEndTimeMs(121));
|
||||
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
|
||||
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(200);
|
||||
|
||||
assertEquals(CachedRegionTracker.CACHED_TO_END, tracker.getRegionEndTimeMs(181));
|
||||
assertThat(tracker.getRegionEndTimeMs(181)).isEqualTo(CachedRegionTracker.CACHED_TO_END);
|
||||
}
|
||||
|
||||
public void testGetRegion_subchunkEstimation() throws Exception {
|
||||
|
|
@ -123,8 +124,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
|||
cache,
|
||||
newCacheSpan(100, 10));
|
||||
|
||||
assertEquals(50, tracker.getRegionEndTimeMs(101));
|
||||
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(111));
|
||||
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(50);
|
||||
assertThat(tracker.getRegionEndTimeMs(111)).isEqualTo(CachedRegionTracker.NOT_CACHED);
|
||||
}
|
||||
|
||||
private CacheSpan newCacheSpan(int position, int length) throws IOException {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
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.test.InstrumentationTestCase;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.File;
|
||||
|
|
@ -88,39 +91,39 @@ public class SimpleCacheSpanTest extends InstrumentationTestCase {
|
|||
for (File file : cacheDir.listFiles()) {
|
||||
SimpleCacheSpan cacheEntry = SimpleCacheSpan.createCacheEntry(file, index);
|
||||
if (file.equals(wrongEscapedV2file)) {
|
||||
assertNull(cacheEntry);
|
||||
assertThat(cacheEntry).isNull();
|
||||
} else {
|
||||
assertNotNull(cacheEntry);
|
||||
assertThat(cacheEntry).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(v3file.exists());
|
||||
assertFalse(v2file.exists());
|
||||
assertTrue(wrongEscapedV2file.exists());
|
||||
assertFalse(v1File.exists());
|
||||
assertThat(v3file.exists()).isTrue();
|
||||
assertThat(v2file.exists()).isFalse();
|
||||
assertThat(wrongEscapedV2file.exists()).isTrue();
|
||||
assertThat(v1File.exists()).isFalse();
|
||||
|
||||
File[] files = cacheDir.listFiles();
|
||||
assertEquals(4, files.length);
|
||||
assertThat(files).hasLength(4);
|
||||
|
||||
Set<String> keys = index.getKeys();
|
||||
assertEquals("There should be only one key for all files.", 1, keys.size());
|
||||
assertTrue(keys.contains(key));
|
||||
assertWithMessage("There should be only one key for all files.").that(keys).hasSize(1);
|
||||
assertThat(keys).contains(key);
|
||||
|
||||
TreeSet<SimpleCacheSpan> spans = index.get(key).getSpans();
|
||||
assertTrue("upgradeOldFiles() shouldn't add any spans.", spans.isEmpty());
|
||||
assertWithMessage("upgradeOldFiles() shouldn't add any spans.").that(spans.isEmpty()).isTrue();
|
||||
|
||||
HashMap<Long, Long> cachedPositions = new HashMap<>();
|
||||
for (File file : files) {
|
||||
SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(file, index);
|
||||
if (cacheSpan != null) {
|
||||
assertEquals(key, cacheSpan.key);
|
||||
assertThat(cacheSpan.key).isEqualTo(key);
|
||||
cachedPositions.put(cacheSpan.position, cacheSpan.lastAccessTimestamp);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(1, (long) cachedPositions.get((long) 0));
|
||||
assertEquals(2, (long) cachedPositions.get((long) 1));
|
||||
assertEquals(6, (long) cachedPositions.get((long) 5));
|
||||
assertThat(cachedPositions.get((long) 0)).isEqualTo(1);
|
||||
assertThat(cachedPositions.get((long) 1)).isEqualTo(2);
|
||||
assertThat(cachedPositions.get((long) 5)).isEqualTo(6);
|
||||
}
|
||||
|
||||
private static void createTestFile(File file, int length) throws IOException {
|
||||
|
|
@ -143,14 +146,14 @@ public class SimpleCacheSpanTest extends InstrumentationTestCase {
|
|||
File cacheFile = createCacheSpanFile(cacheDir, id, offset, 1, lastAccessTimestamp);
|
||||
SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index);
|
||||
String message = cacheFile.toString();
|
||||
assertNotNull(message, cacheSpan);
|
||||
assertEquals(message, cacheDir, cacheFile.getParentFile());
|
||||
assertEquals(message, key, cacheSpan.key);
|
||||
assertEquals(message, offset, cacheSpan.position);
|
||||
assertEquals(message, 1, cacheSpan.length);
|
||||
assertTrue(message, cacheSpan.isCached);
|
||||
assertEquals(message, cacheFile, cacheSpan.file);
|
||||
assertEquals(message, lastAccessTimestamp, cacheSpan.lastAccessTimestamp);
|
||||
assertWithMessage(message).that(cacheSpan).isNotNull();
|
||||
assertWithMessage(message).that(cacheFile.getParentFile()).isEqualTo(cacheDir);
|
||||
assertWithMessage(message).that(cacheSpan.key).isEqualTo(key);
|
||||
assertWithMessage(message).that(cacheSpan.position).isEqualTo(offset);
|
||||
assertWithMessage(message).that(cacheSpan.length).isEqualTo(1);
|
||||
assertWithMessage(message).that(cacheSpan.isCached).isTrue();
|
||||
assertWithMessage(message).that(cacheSpan.file).isEqualTo(cacheFile);
|
||||
assertWithMessage(message).that(cacheSpan.lastAccessTimestamp).isEqualTo(lastAccessTimestamp);
|
||||
}
|
||||
|
||||
private void assertNullCacheSpan(File parent, String key, long offset,
|
||||
|
|
@ -158,7 +161,7 @@ public class SimpleCacheSpanTest extends InstrumentationTestCase {
|
|||
File cacheFile = SimpleCacheSpan.getCacheFile(parent, index.assignIdForKey(key), offset,
|
||||
lastAccessTimestamp);
|
||||
CacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index);
|
||||
assertNull(cacheFile.toString(), cacheSpan);
|
||||
assertWithMessage(cacheFile.toString()).that(cacheSpan).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,10 +142,7 @@ public class DefaultEbmlReaderTest {
|
|||
// Check that we really did get to the end of input.
|
||||
assertThat(input.readFully(new byte[1], 0, 1, true)).isFalse();
|
||||
|
||||
assertThat(output.events).hasSize(expectedEvents.size());
|
||||
for (int i = 0; i < expectedEvents.size(); i++) {
|
||||
assertThat(output.events.get(i)).isEqualTo(expectedEvents.get(i));
|
||||
}
|
||||
assertThat(output.events).containsExactlyElementsIn(expectedEvents).inOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -83,11 +83,9 @@ public class SimpleCacheTest {
|
|||
addCache(simpleCache, KEY_1, 0, 15);
|
||||
|
||||
Set<String> cachedKeys = simpleCache.getKeys();
|
||||
assertThat(cachedKeys).hasSize(1);
|
||||
assertThat(cachedKeys.contains(KEY_1)).isTrue();
|
||||
assertThat(cachedKeys).containsExactly(KEY_1);
|
||||
cachedSpans = simpleCache.getCachedSpans(KEY_1);
|
||||
assertThat(cachedSpans).hasSize(1);
|
||||
assertThat(cachedSpans.contains(cacheSpan1)).isTrue();
|
||||
assertThat(cachedSpans).contains(cacheSpan1);
|
||||
assertThat(simpleCache.getCacheSpace()).isEqualTo(15);
|
||||
|
||||
simpleCache.releaseHoleSpan(cacheSpan1);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ package com.google.android.exoplayer2.util;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static java.nio.charset.Charset.forName;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.dash;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.drm.DrmInitData;
|
||||
|
|
@ -36,25 +38,25 @@ public final class DashUtilTest extends TestCase {
|
|||
public void testLoadDrmInitDataFromManifest() throws Exception {
|
||||
Period period = newPeriod(newAdaptationSets(newRepresentations(newDrmInitData())));
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||
assertEquals(newDrmInitData(), drmInitData);
|
||||
assertThat(drmInitData).isEqualTo(newDrmInitData());
|
||||
}
|
||||
|
||||
public void testLoadDrmInitDataMissing() throws Exception {
|
||||
Period period = newPeriod(newAdaptationSets(newRepresentations(null /* no init data */)));
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||
assertNull(drmInitData);
|
||||
assertThat(drmInitData).isNull();
|
||||
}
|
||||
|
||||
public void testLoadDrmInitDataNoRepresentations() throws Exception {
|
||||
Period period = newPeriod(newAdaptationSets(/* no representation */));
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||
assertNull(drmInitData);
|
||||
assertThat(drmInitData).isNull();
|
||||
}
|
||||
|
||||
public void testLoadDrmInitDataNoAdaptationSets() throws Exception {
|
||||
Period period = newPeriod(/* no adaptation set */);
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||
assertNull(drmInitData);
|
||||
assertThat(drmInitData).isNull();
|
||||
}
|
||||
|
||||
private static Period newPeriod(AdaptationSet... adaptationSets) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.dash.manifest;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
|
|
@ -50,22 +52,24 @@ public class DashManifestParserTest extends InstrumentationTestCase {
|
|||
DashManifest mpd = parser.parse(Uri.parse("https://example.com/test.mpd"),
|
||||
TestUtil.getInputStream(getInstrumentation(), SAMPLE_MPD_3_SEGMENT_TEMPLATE));
|
||||
|
||||
assertEquals(1, mpd.getPeriodCount());
|
||||
assertThat(mpd.getPeriodCount()).isEqualTo(1);
|
||||
|
||||
Period period = mpd.getPeriod(0);
|
||||
assertNotNull(period);
|
||||
assertEquals(2, period.adaptationSets.size());
|
||||
assertThat(period).isNotNull();
|
||||
assertThat(period.adaptationSets).hasSize(2);
|
||||
|
||||
for (AdaptationSet adaptationSet : period.adaptationSets) {
|
||||
assertNotNull(adaptationSet);
|
||||
assertThat(adaptationSet).isNotNull();
|
||||
for (Representation representation : adaptationSet.representations) {
|
||||
if (representation instanceof Representation.MultiSegmentRepresentation) {
|
||||
Representation.MultiSegmentRepresentation multiSegmentRepresentation =
|
||||
(Representation.MultiSegmentRepresentation) representation;
|
||||
int firstSegmentIndex = multiSegmentRepresentation.getFirstSegmentNum();
|
||||
RangedUri uri = multiSegmentRepresentation.getSegmentUrl(firstSegmentIndex);
|
||||
assertTrue(uri.resolveUriString(representation.baseUrl).contains(
|
||||
"redirector.googlevideo.com"));
|
||||
assertThat(
|
||||
uri.resolveUriString(representation.baseUrl)
|
||||
.contains("redirector.googlevideo.com"))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,90 +82,141 @@ public class DashManifestParserTest extends InstrumentationTestCase {
|
|||
TestUtil.getInputStream(getInstrumentation(), SAMPLE_MPD_4_EVENT_STREAM));
|
||||
|
||||
Period period = mpd.getPeriod(0);
|
||||
assertEquals(3, period.eventStreams.size());
|
||||
assertThat(period.eventStreams).hasSize(3);
|
||||
|
||||
// assert text-only event stream
|
||||
EventStream eventStream1 = period.eventStreams.get(0);
|
||||
assertEquals(1, eventStream1.events.length);
|
||||
assertThat(eventStream1.events.length).isEqualTo(1);
|
||||
EventMessage expectedEvent1 = new EventMessage("urn:uuid:XYZY", "call", 10000, 0,
|
||||
"+ 1 800 10101010".getBytes(), 0);
|
||||
assertEquals(expectedEvent1, eventStream1.events[0]);
|
||||
assertThat(eventStream1.events[0]).isEqualTo(expectedEvent1);
|
||||
|
||||
// assert CData-structured event stream
|
||||
EventStream eventStream2 = period.eventStreams.get(1);
|
||||
assertEquals(1, eventStream2.events.length);
|
||||
assertEquals(
|
||||
new EventMessage("urn:dvb:iptv:cpm:2014", "", 1500000, 1,
|
||||
("<![CDATA[<BroadcastEvent>\n"
|
||||
+ " <Program crid=\"crid://broadcaster.example.com/ABCDEF\"/>\n"
|
||||
+ " <InstanceDescription>\n"
|
||||
+ " <Title xml:lang=\"en\">The title</Title>\n"
|
||||
+ " <Synopsis xml:lang=\"en\" length=\"medium\">The description</Synopsis>\n"
|
||||
+ " <ParentalGuidance>\n"
|
||||
+ " <mpeg7:ParentalRating href=\"urn:dvb:iptv:rating:2014:15\"/>\n"
|
||||
+ " <mpeg7:Region>GB</mpeg7:Region>\n"
|
||||
+ " </ParentalGuidance>\n"
|
||||
+ " </InstanceDescription>\n"
|
||||
+ " </BroadcastEvent>]]>").getBytes(), 300000000),
|
||||
eventStream2.events[0]);
|
||||
assertThat(eventStream2.events.length).isEqualTo(1);
|
||||
assertThat(eventStream2.events[0])
|
||||
.isEqualTo(
|
||||
new EventMessage(
|
||||
"urn:dvb:iptv:cpm:2014",
|
||||
"",
|
||||
1500000,
|
||||
1,
|
||||
("<![CDATA[<BroadcastEvent>\n"
|
||||
+ " <Program crid=\"crid://broadcaster.example.com/ABCDEF\"/>\n"
|
||||
+ " <InstanceDescription>\n"
|
||||
+ " <Title xml:lang=\"en\">The title</Title>\n"
|
||||
+ " <Synopsis xml:lang=\"en\" length=\"medium\">"
|
||||
+ "The description</Synopsis>\n"
|
||||
+ " <ParentalGuidance>\n"
|
||||
+ " <mpeg7:ParentalRating href=\"urn:dvb:iptv:rating:2014:15\"/>\n"
|
||||
+ " <mpeg7:Region>GB</mpeg7:Region>\n"
|
||||
+ " </ParentalGuidance>\n"
|
||||
+ " </InstanceDescription>\n"
|
||||
+ " </BroadcastEvent>]]>")
|
||||
.getBytes(),
|
||||
300000000));
|
||||
|
||||
// assert xml-structured event stream
|
||||
EventStream eventStream3 = period.eventStreams.get(2);
|
||||
assertEquals(1, eventStream3.events.length);
|
||||
assertEquals(
|
||||
new EventMessage("urn:scte:scte35:2014:xml+bin", "", 1000000, 2,
|
||||
("<scte35:Signal>\n"
|
||||
+ " <scte35:Binary>\n"
|
||||
+ " /DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==\n"
|
||||
+ " </scte35:Binary>\n"
|
||||
+ " </scte35:Signal>").getBytes(), 1000000000),
|
||||
eventStream3.events[0]);
|
||||
assertThat(eventStream3.events.length).isEqualTo(1);
|
||||
assertThat(eventStream3.events[0])
|
||||
.isEqualTo(
|
||||
new EventMessage(
|
||||
"urn:scte:scte35:2014:xml+bin",
|
||||
"",
|
||||
1000000,
|
||||
2,
|
||||
("<scte35:Signal>\n"
|
||||
+ " <scte35:Binary>\n"
|
||||
+ " /DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==\n"
|
||||
+ " </scte35:Binary>\n"
|
||||
+ " </scte35:Signal>")
|
||||
.getBytes(),
|
||||
1000000000));
|
||||
}
|
||||
|
||||
public void testParseCea608AccessibilityChannel() {
|
||||
assertEquals(1, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC1=eng")));
|
||||
assertEquals(2, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC2=eng")));
|
||||
assertEquals(3, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC3=eng")));
|
||||
assertEquals(4, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC4=eng")));
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC1=eng")))
|
||||
.isEqualTo(1);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC2=eng")))
|
||||
.isEqualTo(2);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC3=eng")))
|
||||
.isEqualTo(3);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC4=eng")))
|
||||
.isEqualTo(4);
|
||||
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors(null)));
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("")));
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC0=eng")));
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC5=eng")));
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("Wrong format")));
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors(null)))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("")))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC0=eng")))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("CC5=eng")))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea608AccessibilityChannel(
|
||||
buildCea608AccessibilityDescriptors("Wrong format")))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
}
|
||||
|
||||
public void testParseCea708AccessibilityChannel() {
|
||||
assertEquals(1, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("1=lang:eng")));
|
||||
assertEquals(2, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("2=lang:eng")));
|
||||
assertEquals(3, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("3=lang:eng")));
|
||||
assertEquals(62, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("62=lang:eng")));
|
||||
assertEquals(63, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("63=lang:eng")));
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("1=lang:eng")))
|
||||
.isEqualTo(1);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("2=lang:eng")))
|
||||
.isEqualTo(2);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("3=lang:eng")))
|
||||
.isEqualTo(3);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("62=lang:eng")))
|
||||
.isEqualTo(62);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("63=lang:eng")))
|
||||
.isEqualTo(63);
|
||||
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors(null)));
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("")));
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("0=lang:eng")));
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("64=lang:eng")));
|
||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("Wrong format")));
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors(null)))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("")))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("0=lang:eng")))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("64=lang:eng")))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
assertThat(
|
||||
DashManifestParser.parseCea708AccessibilityChannel(
|
||||
buildCea708AccessibilityDescriptors("Wrong format")))
|
||||
.isEqualTo(Format.NO_VALUE);
|
||||
}
|
||||
|
||||
private static List<Descriptor> buildCea608AccessibilityDescriptors(String value) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.dash.manifest;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
|
||||
|
|
@ -129,33 +131,35 @@ public class DashManifestTest extends TestCase {
|
|||
}
|
||||
|
||||
private static void assertManifestEquals(DashManifest expected, DashManifest actual) {
|
||||
assertEquals(expected.availabilityStartTimeMs, actual.availabilityStartTimeMs);
|
||||
assertEquals(expected.durationMs, actual.durationMs);
|
||||
assertEquals(expected.minBufferTimeMs, actual.minBufferTimeMs);
|
||||
assertEquals(expected.dynamic, actual.dynamic);
|
||||
assertEquals(expected.minUpdatePeriodMs, actual.minUpdatePeriodMs);
|
||||
assertEquals(expected.timeShiftBufferDepthMs, actual.timeShiftBufferDepthMs);
|
||||
assertEquals(expected.suggestedPresentationDelayMs, actual.suggestedPresentationDelayMs);
|
||||
assertEquals(expected.publishTimeMs, actual.publishTimeMs);
|
||||
assertEquals(expected.utcTiming, actual.utcTiming);
|
||||
assertEquals(expected.location, actual.location);
|
||||
assertEquals(expected.getPeriodCount(), actual.getPeriodCount());
|
||||
assertThat(actual.availabilityStartTimeMs).isEqualTo(expected.availabilityStartTimeMs);
|
||||
assertThat(actual.durationMs).isEqualTo(expected.durationMs);
|
||||
assertThat(actual.minBufferTimeMs).isEqualTo(expected.minBufferTimeMs);
|
||||
assertThat(actual.dynamic).isEqualTo(expected.dynamic);
|
||||
assertThat(actual.minUpdatePeriodMs).isEqualTo(expected.minUpdatePeriodMs);
|
||||
assertThat(actual.timeShiftBufferDepthMs).isEqualTo(expected.timeShiftBufferDepthMs);
|
||||
assertThat(actual.suggestedPresentationDelayMs)
|
||||
.isEqualTo(expected.suggestedPresentationDelayMs);
|
||||
assertThat(actual.publishTimeMs).isEqualTo(expected.publishTimeMs);
|
||||
assertThat(actual.utcTiming).isEqualTo(expected.utcTiming);
|
||||
assertThat(actual.location).isEqualTo(expected.location);
|
||||
assertThat(actual.getPeriodCount()).isEqualTo(expected.getPeriodCount());
|
||||
for (int i = 0; i < expected.getPeriodCount(); i++) {
|
||||
Period expectedPeriod = expected.getPeriod(i);
|
||||
Period actualPeriod = actual.getPeriod(i);
|
||||
assertEquals(expectedPeriod.id, actualPeriod.id);
|
||||
assertEquals(expectedPeriod.startMs, actualPeriod.startMs);
|
||||
assertThat(actualPeriod.id).isEqualTo(expectedPeriod.id);
|
||||
assertThat(actualPeriod.startMs).isEqualTo(expectedPeriod.startMs);
|
||||
List<AdaptationSet> expectedAdaptationSets = expectedPeriod.adaptationSets;
|
||||
List<AdaptationSet> actualAdaptationSets = actualPeriod.adaptationSets;
|
||||
assertEquals(expectedAdaptationSets.size(), actualAdaptationSets.size());
|
||||
assertThat(actualAdaptationSets).hasSize(expectedAdaptationSets.size());
|
||||
for (int j = 0; j < expectedAdaptationSets.size(); j++) {
|
||||
AdaptationSet expectedAdaptationSet = expectedAdaptationSets.get(j);
|
||||
AdaptationSet actualAdaptationSet = actualAdaptationSets.get(j);
|
||||
assertEquals(expectedAdaptationSet.id, actualAdaptationSet.id);
|
||||
assertEquals(expectedAdaptationSet.type, actualAdaptationSet.type);
|
||||
assertEquals(expectedAdaptationSet.accessibilityDescriptors,
|
||||
actualAdaptationSet.accessibilityDescriptors);
|
||||
assertEquals(expectedAdaptationSet.representations, actualAdaptationSet.representations);
|
||||
assertThat(actualAdaptationSet.id).isEqualTo(expectedAdaptationSet.id);
|
||||
assertThat(actualAdaptationSet.type).isEqualTo(expectedAdaptationSet.type);
|
||||
assertThat(actualAdaptationSet.accessibilityDescriptors)
|
||||
.isEqualTo(expectedAdaptationSet.accessibilityDescriptors);
|
||||
assertThat(actualAdaptationSet.representations)
|
||||
.isEqualTo(expectedAdaptationSet.representations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.dash.manifest;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -72,16 +74,16 @@ public class RangedUriTest extends TestCase {
|
|||
|
||||
private void assertMerge(RangedUri rangeA, RangedUri rangeB, RangedUri expected, String baseUrl) {
|
||||
RangedUri merged = rangeA.attemptMerge(rangeB, baseUrl);
|
||||
assertEquals(expected, merged);
|
||||
assertThat(merged).isEqualTo(expected);
|
||||
merged = rangeB.attemptMerge(rangeA, baseUrl);
|
||||
assertEquals(expected, merged);
|
||||
assertThat(merged).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void assertNonMerge(RangedUri rangeA, RangedUri rangeB, String baseUrl) {
|
||||
RangedUri merged = rangeA.attemptMerge(rangeB, baseUrl);
|
||||
assertNull(merged);
|
||||
assertThat(merged).isNull();
|
||||
merged = rangeB.attemptMerge(rangeA, baseUrl);
|
||||
assertNull(merged);
|
||||
assertThat(merged).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.dash.manifest;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
|
|
@ -32,13 +34,13 @@ public class RepresentationTest extends TestCase {
|
|||
MimeTypes.VIDEO_H264, 2500000, 1920, 1080, Format.NO_VALUE, null, 0);
|
||||
Representation representation = Representation.newInstance("test_stream_1", 3, format, uri,
|
||||
base);
|
||||
assertEquals("test_stream_1.0.3", representation.getCacheKey());
|
||||
assertThat(representation.getCacheKey()).isEqualTo("test_stream_1.0.3");
|
||||
|
||||
format = Format.createVideoContainerFormat("150", MimeTypes.APPLICATION_MP4, null,
|
||||
MimeTypes.VIDEO_H264, 2500000, 1920, 1080, Format.NO_VALUE, null, 0);
|
||||
representation = Representation.newInstance("test_stream_1", Representation.REVISION_ID_DEFAULT,
|
||||
format, uri, base);
|
||||
assertEquals("test_stream_1.150.-1", representation.getCacheKey());
|
||||
assertThat(representation.getCacheKey()).isEqualTo("test_stream_1.150.-1");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.dash.manifest;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -26,31 +28,31 @@ public class UrlTemplateTest extends TestCase {
|
|||
String template = "QualityLevels($Bandwidth$)/Fragments(video=$Time$,format=mpd-time-csf)";
|
||||
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
||||
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
||||
assertEquals("QualityLevels(650000)/Fragments(video=5000,format=mpd-time-csf)", url);
|
||||
assertThat(url).isEqualTo("QualityLevels(650000)/Fragments(video=5000,format=mpd-time-csf)");
|
||||
|
||||
template = "$RepresentationID$/$Number$";
|
||||
urlTemplate = UrlTemplate.compile(template);
|
||||
url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
||||
assertEquals("abc1/10", url);
|
||||
assertThat(url).isEqualTo("abc1/10");
|
||||
|
||||
template = "chunk_ctvideo_cfm4s_rid$RepresentationID$_cn$Number$_w2073857842_mpd.m4s";
|
||||
urlTemplate = UrlTemplate.compile(template);
|
||||
url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
||||
assertEquals("chunk_ctvideo_cfm4s_ridabc1_cn10_w2073857842_mpd.m4s", url);
|
||||
assertThat(url).isEqualTo("chunk_ctvideo_cfm4s_ridabc1_cn10_w2073857842_mpd.m4s");
|
||||
}
|
||||
|
||||
public void testFull() {
|
||||
String template = "$Bandwidth$_a_$RepresentationID$_b_$Time$_c_$Number$";
|
||||
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
||||
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
||||
assertEquals("650000_a_abc1_b_5000_c_10", url);
|
||||
assertThat(url).isEqualTo("650000_a_abc1_b_5000_c_10");
|
||||
}
|
||||
|
||||
public void testFullWithDollarEscaping() {
|
||||
String template = "$$$Bandwidth$$$_a$$_$RepresentationID$_b_$Time$_c_$Number$$$";
|
||||
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
||||
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
||||
assertEquals("$650000$_a$_abc1_b_5000_c_10$", url);
|
||||
assertThat(url).isEqualTo("$650000$_a$_abc1_b_5000_c_10$");
|
||||
}
|
||||
|
||||
public void testInvalidSubstitution() {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ import static com.google.android.exoplayer2.source.dash.offline.DashDownloadTest
|
|||
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCacheEmpty;
|
||||
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData;
|
||||
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertDataCached;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import com.google.android.exoplayer2.C;
|
||||
|
|
@ -73,7 +76,7 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
|||
|
||||
DashManifest manifest = dashDownloader.getManifest();
|
||||
|
||||
assertNotNull(manifest);
|
||||
assertThat(manifest).isNotNull();
|
||||
assertCachedData(cache, fakeDataSet);
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +104,7 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
|||
// on the second try it downloads the rest of the data
|
||||
DashManifest manifest = dashDownloader.getManifest();
|
||||
|
||||
assertNotNull(manifest);
|
||||
assertThat(manifest).isNotNull();
|
||||
assertCachedData(cache, fakeDataSet);
|
||||
}
|
||||
|
||||
|
|
@ -203,8 +206,8 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
|||
.setRandomData("text_segment_2", 2)
|
||||
.setRandomData("text_segment_3", 3);
|
||||
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
|
||||
Factory factory = Mockito.mock(Factory.class);
|
||||
Mockito.when(factory.createDataSource()).thenReturn(fakeDataSource);
|
||||
Factory factory = mock(Factory.class);
|
||||
when(factory.createDataSource()).thenReturn(fakeDataSource);
|
||||
DashDownloader dashDownloader = new DashDownloader(TEST_MPD_URI,
|
||||
new DownloaderConstructorHelper(cache, factory));
|
||||
|
||||
|
|
@ -213,15 +216,15 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
|||
dashDownloader.download(null);
|
||||
|
||||
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
|
||||
assertEquals(8, openedDataSpecs.length);
|
||||
assertEquals(TEST_MPD_URI, openedDataSpecs[0].uri);
|
||||
assertEquals("audio_init_data", openedDataSpecs[1].uri.getPath());
|
||||
assertEquals("audio_segment_1", openedDataSpecs[2].uri.getPath());
|
||||
assertEquals("text_segment_1", openedDataSpecs[3].uri.getPath());
|
||||
assertEquals("audio_segment_2", openedDataSpecs[4].uri.getPath());
|
||||
assertEquals("text_segment_2", openedDataSpecs[5].uri.getPath());
|
||||
assertEquals("audio_segment_3", openedDataSpecs[6].uri.getPath());
|
||||
assertEquals("text_segment_3", openedDataSpecs[7].uri.getPath());
|
||||
assertThat(openedDataSpecs.length).isEqualTo(8);
|
||||
assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
|
||||
assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
|
||||
assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
|
||||
assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("text_segment_1");
|
||||
assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_2");
|
||||
assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("text_segment_2");
|
||||
assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("audio_segment_3");
|
||||
assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("text_segment_3");
|
||||
}
|
||||
|
||||
public void testProgressiveDownloadSeparatePeriods() throws Exception {
|
||||
|
|
@ -235,8 +238,8 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
|||
.setRandomData("period_2_segment_2", 2)
|
||||
.setRandomData("period_2_segment_3", 3);
|
||||
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
|
||||
Factory factory = Mockito.mock(Factory.class);
|
||||
Mockito.when(factory.createDataSource()).thenReturn(fakeDataSource);
|
||||
Factory factory = mock(Factory.class);
|
||||
when(factory.createDataSource()).thenReturn(fakeDataSource);
|
||||
DashDownloader dashDownloader = new DashDownloader(TEST_MPD_URI,
|
||||
new DownloaderConstructorHelper(cache, factory));
|
||||
|
||||
|
|
@ -245,15 +248,15 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
|||
dashDownloader.download(null);
|
||||
|
||||
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
|
||||
assertEquals(8, openedDataSpecs.length);
|
||||
assertEquals(TEST_MPD_URI, openedDataSpecs[0].uri);
|
||||
assertEquals("audio_init_data", openedDataSpecs[1].uri.getPath());
|
||||
assertEquals("audio_segment_1", openedDataSpecs[2].uri.getPath());
|
||||
assertEquals("audio_segment_2", openedDataSpecs[3].uri.getPath());
|
||||
assertEquals("audio_segment_3", openedDataSpecs[4].uri.getPath());
|
||||
assertEquals("period_2_segment_1", openedDataSpecs[5].uri.getPath());
|
||||
assertEquals("period_2_segment_2", openedDataSpecs[6].uri.getPath());
|
||||
assertEquals("period_2_segment_3", openedDataSpecs[7].uri.getPath());
|
||||
assertThat(openedDataSpecs.length).isEqualTo(8);
|
||||
assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
|
||||
assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
|
||||
assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
|
||||
assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("audio_segment_2");
|
||||
assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_3");
|
||||
assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("period_2_segment_1");
|
||||
assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("period_2_segment_2");
|
||||
assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("period_2_segment_3");
|
||||
}
|
||||
|
||||
public void testDownloadRepresentationFailure() throws Exception {
|
||||
|
|
@ -400,9 +403,9 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
|||
|
||||
private static void assertCounters(DashDownloader dashDownloader, int totalSegments,
|
||||
int downloadedSegments, int downloadedBytes) {
|
||||
assertEquals(totalSegments, dashDownloader.getTotalSegments());
|
||||
assertEquals(downloadedSegments, dashDownloader.getDownloadedSegments());
|
||||
assertEquals(downloadedBytes, dashDownloader.getDownloadedBytes());
|
||||
assertThat(dashDownloader.getTotalSegments()).isEqualTo(totalSegments);
|
||||
assertThat(dashDownloader.getDownloadedSegments()).isEqualTo(downloadedSegments);
|
||||
assertThat(dashDownloader.getDownloadedBytes()).isEqualTo(downloadedBytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import static com.google.android.exoplayer2.source.hls.offline.HlsDownloadTestDa
|
|||
import static com.google.android.exoplayer2.source.hls.offline.HlsDownloadTestData.MEDIA_PLAYLIST_DATA;
|
||||
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCacheEmpty;
|
||||
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
|
@ -78,7 +79,7 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
|
|||
public void testDownloadManifest() throws Exception {
|
||||
HlsMasterPlaylist manifest = hlsDownloader.getManifest();
|
||||
|
||||
assertNotNull(manifest);
|
||||
assertThat(manifest).isNotNull();
|
||||
assertCachedData(cache, fakeDataSet, MASTER_PLAYLIST_URI);
|
||||
}
|
||||
|
||||
|
|
@ -97,9 +98,10 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
|
|||
hlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
|
||||
hlsDownloader.download(null);
|
||||
|
||||
assertEquals(4, hlsDownloader.getTotalSegments());
|
||||
assertEquals(4, hlsDownloader.getDownloadedSegments());
|
||||
assertEquals(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12, hlsDownloader.getDownloadedBytes());
|
||||
assertThat(hlsDownloader.getTotalSegments()).isEqualTo(4);
|
||||
assertThat(hlsDownloader.getDownloadedSegments()).isEqualTo(4);
|
||||
assertThat(hlsDownloader.getDownloadedBytes())
|
||||
.isEqualTo(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12);
|
||||
}
|
||||
|
||||
public void testInitStatus() throws Exception {
|
||||
|
|
@ -111,9 +113,10 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
|
|||
newHlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
|
||||
newHlsDownloader.init();
|
||||
|
||||
assertEquals(4, newHlsDownloader.getTotalSegments());
|
||||
assertEquals(4, newHlsDownloader.getDownloadedSegments());
|
||||
assertEquals(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12, newHlsDownloader.getDownloadedBytes());
|
||||
assertThat(newHlsDownloader.getTotalSegments()).isEqualTo(4);
|
||||
assertThat(newHlsDownloader.getDownloadedSegments()).isEqualTo(4);
|
||||
assertThat(newHlsDownloader.getDownloadedBytes())
|
||||
.isEqualTo(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12);
|
||||
}
|
||||
|
||||
public void testDownloadRepresentation() throws Exception {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.hls.playlist;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
|
|
@ -23,7 +25,6 @@ import com.google.android.exoplayer2.util.MimeTypes;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -89,43 +90,43 @@ public class HlsMasterPlaylistParserTest extends TestCase {
|
|||
+ "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"aud2\",LANGUAGE=\"en\",NAME=\"English\","
|
||||
+ "AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"6\",URI=\"a2/prog_index.m3u8\"\n";
|
||||
|
||||
public void testParseMasterPlaylist() throws IOException{
|
||||
public void testParseMasterPlaylist() throws IOException {
|
||||
HlsMasterPlaylist masterPlaylist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_SIMPLE);
|
||||
|
||||
List<HlsMasterPlaylist.HlsUrl> variants = masterPlaylist.variants;
|
||||
assertEquals(5, variants.size());
|
||||
assertNull(masterPlaylist.muxedCaptionFormats);
|
||||
assertThat(variants).hasSize(5);
|
||||
assertThat(masterPlaylist.muxedCaptionFormats).isNull();
|
||||
|
||||
assertEquals(1280000, variants.get(0).format.bitrate);
|
||||
assertEquals("mp4a.40.2,avc1.66.30", variants.get(0).format.codecs);
|
||||
assertEquals(304, variants.get(0).format.width);
|
||||
assertEquals(128, variants.get(0).format.height);
|
||||
assertEquals("http://example.com/low.m3u8", variants.get(0).url);
|
||||
assertThat(variants.get(0).format.bitrate).isEqualTo(1280000);
|
||||
assertThat(variants.get(0).format.codecs).isEqualTo("mp4a.40.2,avc1.66.30");
|
||||
assertThat(variants.get(0).format.width).isEqualTo(304);
|
||||
assertThat(variants.get(0).format.height).isEqualTo(128);
|
||||
assertThat(variants.get(0).url).isEqualTo("http://example.com/low.m3u8");
|
||||
|
||||
assertEquals(1280000, variants.get(1).format.bitrate);
|
||||
assertEquals("mp4a.40.2 , avc1.66.30 ", variants.get(1).format.codecs);
|
||||
assertEquals("http://example.com/spaces_in_codecs.m3u8", variants.get(1).url);
|
||||
assertThat(variants.get(1).format.bitrate).isEqualTo(1280000);
|
||||
assertThat(variants.get(1).format.codecs).isEqualTo("mp4a.40.2 , avc1.66.30 ");
|
||||
assertThat(variants.get(1).url).isEqualTo("http://example.com/spaces_in_codecs.m3u8");
|
||||
|
||||
assertEquals(2560000, variants.get(2).format.bitrate);
|
||||
assertNull(variants.get(2).format.codecs);
|
||||
assertEquals(384, variants.get(2).format.width);
|
||||
assertEquals(160, variants.get(2).format.height);
|
||||
assertEquals(25.0f, variants.get(2).format.frameRate);
|
||||
assertEquals("http://example.com/mid.m3u8", variants.get(2).url);
|
||||
assertThat(variants.get(2).format.bitrate).isEqualTo(2560000);
|
||||
assertThat(variants.get(2).format.codecs).isNull();
|
||||
assertThat(variants.get(2).format.width).isEqualTo(384);
|
||||
assertThat(variants.get(2).format.height).isEqualTo(160);
|
||||
assertThat(variants.get(2).format.frameRate).isEqualTo(25.0f);
|
||||
assertThat(variants.get(2).url).isEqualTo("http://example.com/mid.m3u8");
|
||||
|
||||
assertEquals(7680000, variants.get(3).format.bitrate);
|
||||
assertNull(variants.get(3).format.codecs);
|
||||
assertEquals(Format.NO_VALUE, variants.get(3).format.width);
|
||||
assertEquals(Format.NO_VALUE, variants.get(3).format.height);
|
||||
assertEquals(29.997f, variants.get(3).format.frameRate);
|
||||
assertEquals("http://example.com/hi.m3u8", variants.get(3).url);
|
||||
assertThat(variants.get(3).format.bitrate).isEqualTo(7680000);
|
||||
assertThat(variants.get(3).format.codecs).isNull();
|
||||
assertThat(variants.get(3).format.width).isEqualTo(Format.NO_VALUE);
|
||||
assertThat(variants.get(3).format.height).isEqualTo(Format.NO_VALUE);
|
||||
assertThat(variants.get(3).format.frameRate).isEqualTo(29.997f);
|
||||
assertThat(variants.get(3).url).isEqualTo("http://example.com/hi.m3u8");
|
||||
|
||||
assertEquals(65000, variants.get(4).format.bitrate);
|
||||
assertEquals("mp4a.40.5", variants.get(4).format.codecs);
|
||||
assertEquals(Format.NO_VALUE, variants.get(4).format.width);
|
||||
assertEquals(Format.NO_VALUE, variants.get(4).format.height);
|
||||
assertEquals((float) Format.NO_VALUE, variants.get(4).format.frameRate);
|
||||
assertEquals("http://example.com/audio-only.m3u8", variants.get(4).url);
|
||||
assertThat(variants.get(4).format.bitrate).isEqualTo(65000);
|
||||
assertThat(variants.get(4).format.codecs).isEqualTo("mp4a.40.5");
|
||||
assertThat(variants.get(4).format.width).isEqualTo(Format.NO_VALUE);
|
||||
assertThat(variants.get(4).format.height).isEqualTo(Format.NO_VALUE);
|
||||
assertThat(variants.get(4).format.frameRate).isEqualTo((float) Format.NO_VALUE);
|
||||
assertThat(variants.get(4).url).isEqualTo("http://example.com/audio-only.m3u8");
|
||||
}
|
||||
|
||||
public void testMasterPlaylistWithBandwdithAverage() throws IOException {
|
||||
|
|
@ -134,8 +135,8 @@ public class HlsMasterPlaylistParserTest extends TestCase {
|
|||
|
||||
List<HlsMasterPlaylist.HlsUrl> variants = masterPlaylist.variants;
|
||||
|
||||
assertEquals(1280000, variants.get(0).format.bitrate);
|
||||
assertEquals(1270000, variants.get(1).format.bitrate);
|
||||
assertThat(variants.get(0).format.bitrate).isEqualTo(1280000);
|
||||
assertThat(variants.get(1).format.bitrate).isEqualTo(1270000);
|
||||
}
|
||||
|
||||
public void testPlaylistWithInvalidHeader() throws IOException {
|
||||
|
|
@ -149,28 +150,28 @@ public class HlsMasterPlaylistParserTest extends TestCase {
|
|||
|
||||
public void testPlaylistWithClosedCaption() throws IOException {
|
||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_CC);
|
||||
assertEquals(1, playlist.muxedCaptionFormats.size());
|
||||
assertThat(playlist.muxedCaptionFormats).hasSize(1);
|
||||
Format closedCaptionFormat = playlist.muxedCaptionFormats.get(0);
|
||||
assertEquals(MimeTypes.APPLICATION_CEA708, closedCaptionFormat.sampleMimeType);
|
||||
assertEquals(4, closedCaptionFormat.accessibilityChannel);
|
||||
assertEquals("es", closedCaptionFormat.language);
|
||||
assertThat(closedCaptionFormat.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_CEA708);
|
||||
assertThat(closedCaptionFormat.accessibilityChannel).isEqualTo(4);
|
||||
assertThat(closedCaptionFormat.language).isEqualTo("es");
|
||||
}
|
||||
|
||||
public void testPlaylistWithoutClosedCaptions() throws IOException {
|
||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITHOUT_CC);
|
||||
assertEquals(Collections.emptyList(), playlist.muxedCaptionFormats);
|
||||
assertThat(playlist.muxedCaptionFormats).isEmpty();
|
||||
}
|
||||
|
||||
public void testCodecPropagation() throws IOException {
|
||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_AUDIO_MEDIA_TAG);
|
||||
|
||||
Format firstAudioFormat = playlist.audios.get(0).format;
|
||||
assertEquals("mp4a.40.2", firstAudioFormat.codecs);
|
||||
assertEquals(MimeTypes.AUDIO_AAC, firstAudioFormat.sampleMimeType);
|
||||
assertThat(firstAudioFormat.codecs).isEqualTo("mp4a.40.2");
|
||||
assertThat(firstAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
|
||||
|
||||
Format secondAudioFormat = playlist.audios.get(1).format;
|
||||
assertEquals("ac-3", secondAudioFormat.codecs);
|
||||
assertEquals(MimeTypes.AUDIO_AC3, secondAudioFormat.sampleMimeType);
|
||||
assertThat(secondAudioFormat.codecs).isEqualTo("ac-3");
|
||||
assertThat(secondAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AC3);
|
||||
}
|
||||
|
||||
private static HlsMasterPlaylist parseMasterPlaylist(String uri, String playlistString)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.hls.playlist;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment;
|
||||
|
|
@ -69,67 +71,71 @@ public class HlsMediaPlaylistParserTest extends TestCase {
|
|||
playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
|
||||
try {
|
||||
HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUri, inputStream);
|
||||
assertNotNull(playlist);
|
||||
assertThat(playlist).isNotNull();
|
||||
|
||||
HlsMediaPlaylist mediaPlaylist = (HlsMediaPlaylist) playlist;
|
||||
assertEquals(HlsMediaPlaylist.PLAYLIST_TYPE_VOD, mediaPlaylist.playlistType);
|
||||
assertEquals(mediaPlaylist.durationUs - 25000000, mediaPlaylist.startOffsetUs);
|
||||
assertThat(mediaPlaylist.playlistType).isEqualTo(HlsMediaPlaylist.PLAYLIST_TYPE_VOD);
|
||||
assertThat(mediaPlaylist.startOffsetUs).isEqualTo(mediaPlaylist.durationUs - 25000000);
|
||||
|
||||
assertEquals(2679, mediaPlaylist.mediaSequence);
|
||||
assertEquals(3, mediaPlaylist.version);
|
||||
assertTrue(mediaPlaylist.hasEndTag);
|
||||
assertThat(mediaPlaylist.mediaSequence).isEqualTo(2679);
|
||||
assertThat(mediaPlaylist.version).isEqualTo(3);
|
||||
assertThat(mediaPlaylist.hasEndTag).isTrue();
|
||||
List<Segment> segments = mediaPlaylist.segments;
|
||||
assertNotNull(segments);
|
||||
assertEquals(5, segments.size());
|
||||
assertThat(segments).isNotNull();
|
||||
assertThat(segments).hasSize(5);
|
||||
|
||||
Segment segment = segments.get(0);
|
||||
assertEquals(4, mediaPlaylist.discontinuitySequence + segment.relativeDiscontinuitySequence);
|
||||
assertEquals(7975000, segment.durationUs);
|
||||
assertNull(segment.fullSegmentEncryptionKeyUri);
|
||||
assertNull(segment.encryptionIV);
|
||||
assertEquals(51370, segment.byterangeLength);
|
||||
assertEquals(0, segment.byterangeOffset);
|
||||
assertEquals("https://priv.example.com/fileSequence2679.ts", segment.url);
|
||||
assertThat(mediaPlaylist.discontinuitySequence + segment.relativeDiscontinuitySequence)
|
||||
.isEqualTo(4);
|
||||
assertThat(segment.durationUs).isEqualTo(7975000);
|
||||
assertThat(segment.fullSegmentEncryptionKeyUri).isNull();
|
||||
assertThat(segment.encryptionIV).isNull();
|
||||
assertThat(segment.byterangeLength).isEqualTo(51370);
|
||||
assertThat(segment.byterangeOffset).isEqualTo(0);
|
||||
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2679.ts");
|
||||
|
||||
segment = segments.get(1);
|
||||
assertEquals(0, segment.relativeDiscontinuitySequence);
|
||||
assertEquals(7975000, segment.durationUs);
|
||||
assertEquals("https://priv.example.com/key.php?r=2680", segment.fullSegmentEncryptionKeyUri);
|
||||
assertEquals("0x1566B", segment.encryptionIV);
|
||||
assertEquals(51501, segment.byterangeLength);
|
||||
assertEquals(2147483648L, segment.byterangeOffset);
|
||||
assertEquals("https://priv.example.com/fileSequence2680.ts", segment.url);
|
||||
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(0);
|
||||
assertThat(segment.durationUs).isEqualTo(7975000);
|
||||
assertThat(segment.fullSegmentEncryptionKeyUri)
|
||||
.isEqualTo("https://priv.example.com/key.php?r=2680");
|
||||
assertThat(segment.encryptionIV).isEqualTo("0x1566B");
|
||||
assertThat(segment.byterangeLength).isEqualTo(51501);
|
||||
assertThat(segment.byterangeOffset).isEqualTo(2147483648L);
|
||||
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2680.ts");
|
||||
|
||||
segment = segments.get(2);
|
||||
assertEquals(0, segment.relativeDiscontinuitySequence);
|
||||
assertEquals(7941000, segment.durationUs);
|
||||
assertNull(segment.fullSegmentEncryptionKeyUri);
|
||||
assertEquals(null, segment.encryptionIV);
|
||||
assertEquals(51501, segment.byterangeLength);
|
||||
assertEquals(2147535149L, segment.byterangeOffset);
|
||||
assertEquals("https://priv.example.com/fileSequence2681.ts", segment.url);
|
||||
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(0);
|
||||
assertThat(segment.durationUs).isEqualTo(7941000);
|
||||
assertThat(segment.fullSegmentEncryptionKeyUri).isNull();
|
||||
assertThat(segment.encryptionIV).isEqualTo(null);
|
||||
assertThat(segment.byterangeLength).isEqualTo(51501);
|
||||
assertThat(segment.byterangeOffset).isEqualTo(2147535149L);
|
||||
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2681.ts");
|
||||
|
||||
segment = segments.get(3);
|
||||
assertEquals(1, segment.relativeDiscontinuitySequence);
|
||||
assertEquals(7975000, segment.durationUs);
|
||||
assertEquals("https://priv.example.com/key.php?r=2682", segment.fullSegmentEncryptionKeyUri);
|
||||
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(1);
|
||||
assertThat(segment.durationUs).isEqualTo(7975000);
|
||||
assertThat(segment.fullSegmentEncryptionKeyUri)
|
||||
.isEqualTo("https://priv.example.com/key.php?r=2682");
|
||||
// 0xA7A == 2682.
|
||||
assertNotNull(segment.encryptionIV);
|
||||
assertEquals("A7A", segment.encryptionIV.toUpperCase(Locale.getDefault()));
|
||||
assertEquals(51740, segment.byterangeLength);
|
||||
assertEquals(2147586650L, segment.byterangeOffset);
|
||||
assertEquals("https://priv.example.com/fileSequence2682.ts", segment.url);
|
||||
assertThat(segment.encryptionIV).isNotNull();
|
||||
assertThat(segment.encryptionIV.toUpperCase(Locale.getDefault())).isEqualTo("A7A");
|
||||
assertThat(segment.byterangeLength).isEqualTo(51740);
|
||||
assertThat(segment.byterangeOffset).isEqualTo(2147586650L);
|
||||
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2682.ts");
|
||||
|
||||
segment = segments.get(4);
|
||||
assertEquals(1, segment.relativeDiscontinuitySequence);
|
||||
assertEquals(7975000, segment.durationUs);
|
||||
assertEquals("https://priv.example.com/key.php?r=2682", segment.fullSegmentEncryptionKeyUri);
|
||||
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(1);
|
||||
assertThat(segment.durationUs).isEqualTo(7975000);
|
||||
assertThat(segment.fullSegmentEncryptionKeyUri)
|
||||
.isEqualTo("https://priv.example.com/key.php?r=2682");
|
||||
// 0xA7B == 2683.
|
||||
assertNotNull(segment.encryptionIV);
|
||||
assertEquals("A7B", segment.encryptionIV.toUpperCase(Locale.getDefault()));
|
||||
assertEquals(C.LENGTH_UNSET, segment.byterangeLength);
|
||||
assertEquals(0, segment.byterangeOffset);
|
||||
assertEquals("https://priv.example.com/fileSequence2683.ts", segment.url);
|
||||
assertThat(segment.encryptionIV).isNotNull();
|
||||
assertThat(segment.encryptionIV.toUpperCase(Locale.getDefault())).isEqualTo("A7B");
|
||||
assertThat(segment.byterangeLength).isEqualTo(C.LENGTH_UNSET);
|
||||
assertThat(segment.byterangeOffset).isEqualTo(0);
|
||||
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts");
|
||||
} catch (IOException exception) {
|
||||
fail(exception.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.source.smoothstreaming.manifest;
|
||||
|
||||
import android.test.MoreAsserts;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.ProtectionElement;
|
||||
|
|
@ -75,28 +76,28 @@ public class SsManifestTest extends TestCase {
|
|||
}
|
||||
|
||||
private static void assertManifestEquals(SsManifest expected, SsManifest actual) {
|
||||
assertEquals(expected.durationUs, actual.durationUs);
|
||||
assertEquals(expected.dvrWindowLengthUs, actual.dvrWindowLengthUs);
|
||||
assertEquals(expected.isLive, actual.isLive);
|
||||
assertEquals(expected.lookAheadCount, actual.lookAheadCount);
|
||||
assertEquals(expected.majorVersion, actual.majorVersion);
|
||||
assertEquals(expected.minorVersion, actual.minorVersion);
|
||||
assertEquals(expected.protectionElement.uuid, actual.protectionElement.uuid);
|
||||
assertEquals(expected.protectionElement, actual.protectionElement);
|
||||
assertThat(actual.durationUs).isEqualTo(expected.durationUs);
|
||||
assertThat(actual.dvrWindowLengthUs).isEqualTo(expected.dvrWindowLengthUs);
|
||||
assertThat(actual.isLive).isEqualTo(expected.isLive);
|
||||
assertThat(actual.lookAheadCount).isEqualTo(expected.lookAheadCount);
|
||||
assertThat(actual.majorVersion).isEqualTo(expected.majorVersion);
|
||||
assertThat(actual.minorVersion).isEqualTo(expected.minorVersion);
|
||||
assertThat(actual.protectionElement.uuid).isEqualTo(expected.protectionElement.uuid);
|
||||
assertThat(actual.protectionElement).isEqualTo(expected.protectionElement);
|
||||
for (int i = 0; i < expected.streamElements.length; i++) {
|
||||
StreamElement expectedStreamElement = expected.streamElements[i];
|
||||
StreamElement actualStreamElement = actual.streamElements[i];
|
||||
assertEquals(expectedStreamElement.chunkCount, actualStreamElement.chunkCount);
|
||||
assertEquals(expectedStreamElement.displayHeight, actualStreamElement.displayHeight);
|
||||
assertEquals(expectedStreamElement.displayWidth, actualStreamElement.displayWidth);
|
||||
assertEquals(expectedStreamElement.language, actualStreamElement.language);
|
||||
assertEquals(expectedStreamElement.maxHeight, actualStreamElement.maxHeight);
|
||||
assertEquals(expectedStreamElement.maxWidth, actualStreamElement.maxWidth);
|
||||
assertEquals(expectedStreamElement.name, actualStreamElement.name);
|
||||
assertEquals(expectedStreamElement.subType, actualStreamElement.subType);
|
||||
assertEquals(expectedStreamElement.timescale, actualStreamElement.timescale);
|
||||
assertEquals(expectedStreamElement.type, actualStreamElement.type);
|
||||
MoreAsserts.assertEquals(expectedStreamElement.formats, actualStreamElement.formats);
|
||||
assertThat(actualStreamElement.chunkCount).isEqualTo(expectedStreamElement.chunkCount);
|
||||
assertThat(actualStreamElement.displayHeight).isEqualTo(expectedStreamElement.displayHeight);
|
||||
assertThat(actualStreamElement.displayWidth).isEqualTo(expectedStreamElement.displayWidth);
|
||||
assertThat(actualStreamElement.language).isEqualTo(expectedStreamElement.language);
|
||||
assertThat(actualStreamElement.maxHeight).isEqualTo(expectedStreamElement.maxHeight);
|
||||
assertThat(actualStreamElement.maxWidth).isEqualTo(expectedStreamElement.maxWidth);
|
||||
assertThat(actualStreamElement.name).isEqualTo(expectedStreamElement.name);
|
||||
assertThat(actualStreamElement.subType).isEqualTo(expectedStreamElement.subType);
|
||||
assertThat(actualStreamElement.timescale).isEqualTo(expectedStreamElement.timescale);
|
||||
assertThat(actualStreamElement.type).isEqualTo(expectedStreamElement.type);
|
||||
assertThat(actualStreamElement.formats).isEqualTo(expectedStreamElement.formats);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.playbacktests.gts;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
|
@ -89,15 +92,16 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2<Hos
|
|||
|
||||
// Download representations
|
||||
DashDownloader dashDownloader = downloadContent(false, Float.NaN);
|
||||
assertEquals(cache.getCacheSpace() - manifestLength, dashDownloader.getDownloadedBytes());
|
||||
assertThat(dashDownloader.getDownloadedBytes())
|
||||
.isEqualTo(cache.getCacheSpace() - manifestLength);
|
||||
|
||||
testRunner.setStreamName("test_h264_fixed_download").
|
||||
setDataSourceFactory(newOfflineCacheDataSourceFactory()).run();
|
||||
|
||||
dashDownloader.remove();
|
||||
|
||||
assertEquals("There should be no content left.", 0, cache.getKeys().size());
|
||||
assertEquals("There should be no content left.", 0, cache.getCacheSpace());
|
||||
assertWithMessage("There should be no content left.").that(cache.getKeys().size()).isEqualTo(0);
|
||||
assertWithMessage("There should be no content left.").that(cache.getCacheSpace()).isEqualTo(0);
|
||||
}
|
||||
|
||||
public void testPartialDownload() throws Exception {
|
||||
|
|
@ -114,7 +118,7 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2<Hos
|
|||
|
||||
// Make sure it doesn't download any data
|
||||
dashDownloader = downloadContent(true, Float.NaN);
|
||||
assertEquals(downloadedBytes, dashDownloader.getDownloadedBytes());
|
||||
assertThat(dashDownloader.getDownloadedBytes()).isEqualTo(downloadedBytes);
|
||||
|
||||
testRunner.setStreamName("test_h264_fixed_partial_download")
|
||||
.setDataSourceFactory(newOfflineCacheDataSourceFactory()).run();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.playbacktests.gts;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
|
|
@ -603,8 +605,8 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
|
|||
return;
|
||||
}
|
||||
MediaCodecInfo decoderInfo = MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H264, false);
|
||||
assertNotNull(decoderInfo);
|
||||
assertTrue(Util.SDK_INT < 21 || decoderInfo.adaptive);
|
||||
assertThat(decoderInfo).isNotNull();
|
||||
assertThat(Util.SDK_INT < 21 || decoderInfo.adaptive).isTrue();
|
||||
}
|
||||
|
||||
public void testDecoderInfoH265V24() throws DecoderQueryException {
|
||||
|
|
@ -612,7 +614,7 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
|
|||
// Pass.
|
||||
return;
|
||||
}
|
||||
assertTrue(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H265, false).adaptive);
|
||||
assertThat(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H265, false).adaptive).isTrue();
|
||||
}
|
||||
|
||||
public void testDecoderInfoVP9V24() throws DecoderQueryException {
|
||||
|
|
@ -620,7 +622,7 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
|
|||
// Pass.
|
||||
return;
|
||||
}
|
||||
assertTrue(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_VP9, false).adaptive);
|
||||
assertThat(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_VP9, false).adaptive).isTrue();
|
||||
}
|
||||
|
||||
// Internal.
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ import com.google.android.exoplayer2.util.Util;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
/** {@link DashHostedTest} builder. */
|
||||
public final class DashTestRunner {
|
||||
|
|
@ -362,7 +361,7 @@ public final class DashTestRunner {
|
|||
// Assert that consecutive dropped frames were within limit.
|
||||
DecoderCountersUtil.assertConsecutiveDroppedBufferLimit(tag + VIDEO_TAG_SUFFIX,
|
||||
videoCounters, MAX_CONSECUTIVE_DROPPED_VIDEO_FRAMES);
|
||||
} catch (AssertionFailedError e) {
|
||||
} catch (AssertionError e) {
|
||||
if (trackSelector.includedAdditionalVideoFormats) {
|
||||
// Retry limiting to CDD mandated formats (b/28220076).
|
||||
Log.e(tag, "Too many dropped or consecutive dropped frames.", e);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.playbacktests.gts;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.media.MediaDrm.MediaDrmStateException;
|
||||
import android.net.Uri;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
|
@ -33,7 +36,6 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
|||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.IOException;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Tests Widevine encrypted DASH playbacks using offline keys.
|
||||
|
|
@ -98,7 +100,7 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
|
|||
|
||||
// Renew license after playback should still work
|
||||
offlineLicenseKeySetId = offlineLicenseHelper.renewLicense(offlineLicenseKeySetId);
|
||||
Assert.assertNotNull(offlineLicenseKeySetId);
|
||||
assertThat(offlineLicenseKeySetId).isNotNull();
|
||||
}
|
||||
|
||||
public void testWidevineOfflineReleasedLicenseV22() throws Throwable {
|
||||
|
|
@ -136,8 +138,10 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
|
|||
// Wait until the license expires
|
||||
long licenseDuration =
|
||||
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId).first;
|
||||
assertTrue("License duration should be less than 30 sec. "
|
||||
+ "Server settings might have changed.", licenseDuration < 30);
|
||||
assertWithMessage(
|
||||
"License duration should be less than 30 sec. " + "Server settings might have changed.")
|
||||
.that(licenseDuration < 30)
|
||||
.isTrue();
|
||||
while (licenseDuration > 0) {
|
||||
synchronized (this) {
|
||||
wait(licenseDuration * 1000 + 2000);
|
||||
|
|
@ -145,7 +149,9 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
|
|||
long previousDuration = licenseDuration;
|
||||
licenseDuration =
|
||||
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId).first;
|
||||
assertTrue("License duration should be decreasing.", previousDuration > licenseDuration);
|
||||
assertWithMessage("License duration should be decreasing.")
|
||||
.that(previousDuration > licenseDuration)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
// DefaultDrmSessionManager should renew the license and stream play fine
|
||||
|
|
@ -162,8 +168,10 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
|
|||
Pair<Long, Long> licenseDurationRemainingSec =
|
||||
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
||||
long licenseDuration = licenseDurationRemainingSec.first;
|
||||
assertTrue("License duration should be less than 30 sec. "
|
||||
+ "Server settings might have changed.", licenseDuration < 30);
|
||||
assertWithMessage(
|
||||
"License duration should be less than 30 sec. " + "Server settings might have changed.")
|
||||
.that(licenseDuration < 30)
|
||||
.isTrue();
|
||||
ActionSchedule schedule = new ActionSchedule.Builder(TAG)
|
||||
.waitForPlaybackState(Player.STATE_READY)
|
||||
.delay(3000).pause().delay(licenseDuration * 1000 + 2000).play().build();
|
||||
|
|
@ -178,8 +186,8 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
|
|||
Uri.parse(DashTestData.WIDEVINE_H264_MANIFEST));
|
||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(dataSource, dashManifest.getPeriod(0));
|
||||
offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(drmInitData);
|
||||
Assert.assertNotNull(offlineLicenseKeySetId);
|
||||
Assert.assertTrue(offlineLicenseKeySetId.length > 0);
|
||||
assertThat(offlineLicenseKeySetId).isNotNull();
|
||||
assertThat(offlineLicenseKeySetId.length).isGreaterThan(0);
|
||||
testRunner.setOfflineLicenseKeySetId(offlineLicenseKeySetId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,4 +27,5 @@ android {
|
|||
dependencies {
|
||||
compile project(modulePrefix + 'library-core')
|
||||
compile 'org.mockito:mockito-core:' + mockitoVersion
|
||||
compile 'com.google.truth:truth:' + truthVersion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,10 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.test.MoreAsserts;
|
||||
import com.google.android.exoplayer2.testutil.FakeDataSet.FakeData;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||
|
|
@ -76,7 +75,7 @@ public final class CacheAsserts {
|
|||
assertDataCached(cache, uri, data);
|
||||
totalLength += data.length;
|
||||
}
|
||||
assertEquals(totalLength, cache.getCacheSpace());
|
||||
assertThat(cache.getCacheSpace()).isEqualTo(totalLength);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -112,8 +111,9 @@ public final class CacheAsserts {
|
|||
dataSource.open(dataSpec);
|
||||
try {
|
||||
byte[] bytes = TestUtil.readToEnd(dataSource);
|
||||
MoreAsserts.assertEquals(
|
||||
"Cached data doesn't match expected for '" + dataSpec.uri + "',", expected, bytes);
|
||||
assertWithMessage("Cached data doesn't match expected for '" + dataSpec.uri + "',")
|
||||
.that(bytes)
|
||||
.isEqualTo(expected);
|
||||
} finally {
|
||||
dataSource.close();
|
||||
}
|
||||
|
|
@ -122,15 +122,15 @@ public final class CacheAsserts {
|
|||
/** Asserts that there is no cache content for the given {@code uriStrings}. */
|
||||
public static void assertDataNotCached(Cache cache, String... uriStrings) {
|
||||
for (String uriString : uriStrings) {
|
||||
assertTrue(
|
||||
"There is cached data for '" + uriString + "',",
|
||||
cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))).isEmpty());
|
||||
assertWithMessage("There is cached data for '" + uriString + "',")
|
||||
.that(cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))).isEmpty())
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
/** Asserts that the cache is empty. */
|
||||
public static void assertCacheEmpty(Cache cache) {
|
||||
assertEquals(0, cache.getCacheSpace());
|
||||
assertThat(cache.getCacheSpace()).isEqualTo(0);
|
||||
}
|
||||
|
||||
private CacheAsserts() {}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.android.exoplayer2.decoder.DecoderCounters;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Assertions for {@link DecoderCounters}.
|
||||
|
|
@ -41,30 +42,60 @@ public final class DecoderCountersUtil {
|
|||
int expected) {
|
||||
counters.ensureUpdated();
|
||||
int actual = counters.skippedOutputBufferCount;
|
||||
TestCase.assertEquals("Codec(" + name + ") skipped " + actual + " buffers. Expected "
|
||||
+ expected + ".", expected, actual);
|
||||
assertWithMessage(
|
||||
"Codec(" + name + ") skipped " + actual + " buffers. Expected " + expected + ".")
|
||||
.that(actual)
|
||||
.isEqualTo(expected);
|
||||
}
|
||||
|
||||
public static void assertTotalBufferCount(String name, DecoderCounters counters, int minCount,
|
||||
int maxCount) {
|
||||
int actual = getTotalBufferCount(counters);
|
||||
TestCase.assertTrue("Codec(" + name + ") output " + actual + " buffers. Expected in range ["
|
||||
+ minCount + ", " + maxCount + "].", minCount <= actual && actual <= maxCount);
|
||||
assertWithMessage(
|
||||
"Codec("
|
||||
+ name
|
||||
+ ") output "
|
||||
+ actual
|
||||
+ " buffers. Expected in range ["
|
||||
+ minCount
|
||||
+ ", "
|
||||
+ maxCount
|
||||
+ "].")
|
||||
.that(minCount <= actual && actual <= maxCount)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
public static void assertDroppedBufferLimit(String name, DecoderCounters counters, int limit) {
|
||||
counters.ensureUpdated();
|
||||
int actual = counters.droppedBufferCount;
|
||||
TestCase.assertTrue("Codec(" + name + ") was late decoding: " + actual + " buffers. "
|
||||
+ "Limit: " + limit + ".", actual <= limit);
|
||||
assertWithMessage(
|
||||
"Codec("
|
||||
+ name
|
||||
+ ") was late decoding: "
|
||||
+ actual
|
||||
+ " buffers. "
|
||||
+ "Limit: "
|
||||
+ limit
|
||||
+ ".")
|
||||
.that(actual)
|
||||
.isAtMost(limit);
|
||||
}
|
||||
|
||||
public static void assertConsecutiveDroppedBufferLimit(String name, DecoderCounters counters,
|
||||
int limit) {
|
||||
counters.ensureUpdated();
|
||||
int actual = counters.maxConsecutiveDroppedBufferCount;
|
||||
TestCase.assertTrue("Codec(" + name + ") was late decoding: " + actual
|
||||
+ " buffers consecutively. " + "Limit: " + limit + ".", actual <= limit);
|
||||
assertWithMessage(
|
||||
"Codec("
|
||||
+ name
|
||||
+ ") was late decoding: "
|
||||
+ actual
|
||||
+ " buffers consecutively. "
|
||||
+ "Limit: "
|
||||
+ limit
|
||||
+ ".")
|
||||
.that(actual)
|
||||
.isAtMost(limit);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.os.ConditionVariable;
|
||||
import android.os.Looper;
|
||||
import android.os.SystemClock;
|
||||
|
|
@ -46,7 +48,6 @@ import com.google.android.exoplayer2.util.Clock;
|
|||
import com.google.android.exoplayer2.util.HandlerWrapper;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* A {@link HostedTest} for {@link ExoPlayer} playback tests.
|
||||
|
|
@ -219,9 +220,12 @@ public abstract class ExoHostedTest extends Player.DefaultEventListener implemen
|
|||
// Assert that the playback spanned the correct duration of time.
|
||||
long minAllowedActualPlayingTimeMs = playingTimeToAssertMs - MAX_PLAYING_TIME_DISCREPANCY_MS;
|
||||
long maxAllowedActualPlayingTimeMs = playingTimeToAssertMs + MAX_PLAYING_TIME_DISCREPANCY_MS;
|
||||
Assert.assertTrue("Total playing time: " + totalPlayingTimeMs + ". Expected: "
|
||||
+ playingTimeToAssertMs, minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
|
||||
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs);
|
||||
assertWithMessage(
|
||||
"Total playing time: " + totalPlayingTimeMs + ". Expected: " + playingTimeToAssertMs)
|
||||
.that(
|
||||
minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
|
||||
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs)
|
||||
.isTrue();
|
||||
}
|
||||
// Make any additional assertions.
|
||||
assertPassed(audioDecoderCounters, videoDecoderCounters);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.os.HandlerThread;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||
|
|
@ -22,7 +24,6 @@ import com.google.android.exoplayer2.ExoPlaybackException;
|
|||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.LoadControl;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
||||
import com.google.android.exoplayer2.Renderer;
|
||||
import com.google.android.exoplayer2.RenderersFactory;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
|
|
@ -41,10 +42,10 @@ import com.google.android.exoplayer2.util.HandlerWrapper;
|
|||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Helper class to run an ExoPlayer test.
|
||||
|
|
@ -97,7 +98,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
* @return This builder.
|
||||
*/
|
||||
public Builder setTimeline(Timeline timeline) {
|
||||
Assert.assertNull(mediaSource);
|
||||
assertThat(mediaSource).isNull();
|
||||
this.timeline = timeline;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -111,7 +112,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
* @return This builder.
|
||||
*/
|
||||
public Builder setManifest(Object manifest) {
|
||||
Assert.assertNull(mediaSource);
|
||||
assertThat(mediaSource).isNull();
|
||||
this.manifest = manifest;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -127,8 +128,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
* @return This builder.
|
||||
*/
|
||||
public Builder setMediaSource(MediaSource mediaSource) {
|
||||
Assert.assertNull(timeline);
|
||||
Assert.assertNull(manifest);
|
||||
assertThat(timeline).isNull();
|
||||
assertThat(manifest).isNull();
|
||||
this.mediaSource = mediaSource;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -182,7 +183,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
* @return This builder.
|
||||
*/
|
||||
public Builder setRenderers(Renderer... renderers) {
|
||||
Assert.assertNull(renderersFactory);
|
||||
assertThat(renderersFactory).isNull();
|
||||
this.renderers = renderers;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -196,7 +197,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
* @return This builder.
|
||||
*/
|
||||
public Builder setRenderersFactory(RenderersFactory renderersFactory) {
|
||||
Assert.assertNull(renderers);
|
||||
assertThat(renderers).isNull();
|
||||
this.renderersFactory = renderersFactory;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -478,10 +479,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
* @param timelines A list of expected {@link Timeline}s.
|
||||
*/
|
||||
public void assertTimelinesEqual(Timeline... timelines) {
|
||||
Assert.assertEquals(timelines.length, this.timelines.size());
|
||||
for (int i = 0; i < timelines.length; i++) {
|
||||
Assert.assertEquals(timelines[i], this.timelines.get(i));
|
||||
}
|
||||
assertThat(this.timelines).containsExactlyElementsIn(Arrays.asList(timelines)).inOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -492,22 +490,16 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
* @param manifests A list of expected manifests.
|
||||
*/
|
||||
public void assertManifestsEqual(Object... manifests) {
|
||||
Assert.assertEquals(manifests.length, this.manifests.size());
|
||||
for (int i = 0; i < manifests.length; i++) {
|
||||
Assert.assertEquals(manifests[i], this.manifests.get(i));
|
||||
}
|
||||
assertThat(this.manifests).containsExactlyElementsIn(Arrays.asList(manifests)).inOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the timeline change reasons reported by
|
||||
* {@link Player.EventListener#onTimelineChanged(Timeline, Object, int)} are equal to the provided
|
||||
* Asserts that the timeline change reasons reported by {@link
|
||||
* Player.EventListener#onTimelineChanged(Timeline, Object, int)} are equal to the provided
|
||||
* timeline change reasons.
|
||||
*/
|
||||
public void assertTimelineChangeReasonsEqual(@Player.TimelineChangeReason int... reasons) {
|
||||
Assert.assertEquals(reasons.length, timelineChangeReasons.size());
|
||||
for (int i = 0; i < reasons.length; i++) {
|
||||
Assert.assertEquals(reasons[i], (int) timelineChangeReasons.get(i));
|
||||
}
|
||||
public void assertTimelineChangeReasonsEqual(Integer... reasons) {
|
||||
assertThat(timelineChangeReasons).containsExactlyElementsIn(Arrays.asList(reasons)).inOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -518,28 +510,26 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
* @param trackGroupArray The expected {@link TrackGroupArray}.
|
||||
*/
|
||||
public void assertTrackGroupsEqual(TrackGroupArray trackGroupArray) {
|
||||
Assert.assertEquals(trackGroupArray, this.trackGroups);
|
||||
assertThat(this.trackGroups).isEqualTo(trackGroupArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that {@link Player.EventListener#onPositionDiscontinuity(int)} was not called.
|
||||
*/
|
||||
public void assertNoPositionDiscontinuities() {
|
||||
Assert.assertTrue(discontinuityReasons.isEmpty());
|
||||
assertThat(discontinuityReasons).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the discontinuity reasons reported by
|
||||
* {@link Player.EventListener#onPositionDiscontinuity(int)} are equal to the provided values.
|
||||
* Asserts that the discontinuity reasons reported by {@link
|
||||
* Player.EventListener#onPositionDiscontinuity(int)} are equal to the provided values.
|
||||
*
|
||||
* @param discontinuityReasons The expected discontinuity reasons.
|
||||
*/
|
||||
public void assertPositionDiscontinuityReasonsEqual(
|
||||
@DiscontinuityReason int... discontinuityReasons) {
|
||||
Assert.assertEquals(discontinuityReasons.length, this.discontinuityReasons.size());
|
||||
for (int i = 0; i < discontinuityReasons.length; i++) {
|
||||
Assert.assertEquals(discontinuityReasons[i], (int) this.discontinuityReasons.get(i));
|
||||
}
|
||||
public void assertPositionDiscontinuityReasonsEqual(Integer... discontinuityReasons) {
|
||||
assertThat(this.discontinuityReasons)
|
||||
.containsExactlyElementsIn(Arrays.asList(discontinuityReasons))
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -550,11 +540,10 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
|||
*
|
||||
* @param periodIndices A list of expected period indices.
|
||||
*/
|
||||
public void assertPlayedPeriodIndices(int... periodIndices) {
|
||||
Assert.assertEquals(periodIndices.length, this.periodIndices.size());
|
||||
for (int i = 0; i < periodIndices.length; i++) {
|
||||
Assert.assertEquals(periodIndices[i], (int) this.periodIndices.get(i));
|
||||
}
|
||||
public void assertPlayedPeriodIndices(Integer... periodIndices) {
|
||||
assertThat(this.periodIndices)
|
||||
.containsExactlyElementsIn(Arrays.asList(periodIndices))
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
// Private implementation details.
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
|
|
@ -26,7 +28,6 @@ import com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOExce
|
|||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Assertion methods for {@link Extractor}.
|
||||
|
|
@ -126,7 +127,7 @@ public final class ExtractorAsserts {
|
|||
.setSimulatePartialReads(simulatePartialReads).build();
|
||||
|
||||
if (sniffFirst) {
|
||||
Assert.assertTrue(TestUtil.sniffTestData(extractor, input));
|
||||
assertThat(TestUtil.sniffTestData(extractor, input)).isTrue();
|
||||
input.resetPeekPosition();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.util.SparseBooleanArray;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* A fake {@link ExtractorInput} capable of simulating various scenarios.
|
||||
|
|
@ -84,7 +85,7 @@ public final class FakeExtractorInput implements ExtractorInput {
|
|||
* @param position The position to set.
|
||||
*/
|
||||
public void setPosition(int position) {
|
||||
Assert.assertTrue(0 <= position && position <= data.length);
|
||||
assertThat(0 <= position && position <= data.length).isTrue();
|
||||
readPosition = position;
|
||||
peekPosition = position;
|
||||
}
|
||||
|
|
@ -180,7 +181,7 @@ public final class FakeExtractorInput implements ExtractorInput {
|
|||
|
||||
@Override
|
||||
public <E extends Throwable> void setRetryPosition(long position, E e) throws E {
|
||||
Assert.assertTrue(position >= 0);
|
||||
assertThat(position >= 0).isTrue();
|
||||
readPosition = (int) position;
|
||||
throw e;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.util.SparseArray;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorOutput;
|
||||
|
|
@ -22,7 +25,6 @@ import com.google.android.exoplayer2.extractor.SeekMap;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* A fake {@link ExtractorOutput}.
|
||||
|
|
@ -50,7 +52,7 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
|||
public FakeTrackOutput track(int id, int type) {
|
||||
FakeTrackOutput output = trackOutputs.get(id);
|
||||
if (output == null) {
|
||||
Assert.assertFalse(tracksEnded);
|
||||
assertThat(tracksEnded).isFalse();
|
||||
numberOfTracks++;
|
||||
output = new FakeTrackOutput();
|
||||
trackOutputs.put(id, output);
|
||||
|
|
@ -69,19 +71,19 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
|||
}
|
||||
|
||||
public void assertEquals(FakeExtractorOutput expected) {
|
||||
Assert.assertEquals(expected.numberOfTracks, numberOfTracks);
|
||||
Assert.assertEquals(expected.tracksEnded, tracksEnded);
|
||||
assertThat(numberOfTracks).isEqualTo(expected.numberOfTracks);
|
||||
assertThat(tracksEnded).isEqualTo(expected.tracksEnded);
|
||||
if (expected.seekMap == null) {
|
||||
Assert.assertNull(seekMap);
|
||||
assertThat(seekMap).isNull();
|
||||
} else {
|
||||
// TODO: Bulk up this check if possible.
|
||||
Assert.assertNotNull(seekMap);
|
||||
Assert.assertEquals(expected.seekMap.getClass(), seekMap.getClass());
|
||||
Assert.assertEquals(expected.seekMap.isSeekable(), seekMap.isSeekable());
|
||||
Assert.assertEquals(expected.seekMap.getSeekPoints(0), seekMap.getSeekPoints(0));
|
||||
assertThat(seekMap).isNotNull();
|
||||
assertThat(seekMap.getClass()).isEqualTo(expected.seekMap.getClass());
|
||||
assertThat(seekMap.isSeekable()).isEqualTo(expected.seekMap.isSeekable());
|
||||
assertThat(seekMap.getSeekPoints(0)).isEqualTo(expected.seekMap.getSeekPoints(0));
|
||||
}
|
||||
for (int i = 0; i < numberOfTracks; i++) {
|
||||
Assert.assertEquals(expected.trackOutputs.keyAt(i), trackOutputs.keyAt(i));
|
||||
assertThat(trackOutputs.keyAt(i)).isEqualTo(expected.trackOutputs.keyAt(i));
|
||||
trackOutputs.valueAt(i).assertEquals(expected.trackOutputs.valueAt(i));
|
||||
}
|
||||
}
|
||||
|
|
@ -107,7 +109,7 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
|||
out.close();
|
||||
} else {
|
||||
String expected = TestUtil.getString(instrumentation, dumpFile);
|
||||
Assert.assertEquals(dumpFile, expected, actual);
|
||||
assertWithMessage(dumpFile).that(actual).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
|
|
@ -25,7 +27,6 @@ import com.google.android.exoplayer2.source.TrackGroup;
|
|||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import java.io.IOException;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Fake {@link MediaPeriod} that provides tracks from the given {@link TrackGroupArray}. Selecting
|
||||
|
|
@ -119,14 +120,14 @@ public class FakeMediaPeriod implements MediaPeriod {
|
|||
|
||||
@Override
|
||||
public TrackGroupArray getTrackGroups() {
|
||||
Assert.assertTrue(prepared);
|
||||
assertThat(prepared).isTrue();
|
||||
return trackGroupArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
|
||||
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
|
||||
Assert.assertTrue(prepared);
|
||||
assertThat(prepared).isTrue();
|
||||
int rendererCount = selections.length;
|
||||
for (int i = 0; i < rendererCount; i++) {
|
||||
if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
|
||||
|
|
@ -134,12 +135,12 @@ public class FakeMediaPeriod implements MediaPeriod {
|
|||
}
|
||||
if (streams[i] == null && selections[i] != null) {
|
||||
TrackSelection selection = selections[i];
|
||||
Assert.assertTrue(1 <= selection.length());
|
||||
assertThat(selection.length()).isAtLeast(1);
|
||||
TrackGroup trackGroup = selection.getTrackGroup();
|
||||
Assert.assertTrue(trackGroupArray.indexOf(trackGroup) != C.INDEX_UNSET);
|
||||
assertThat(trackGroupArray.indexOf(trackGroup) != C.INDEX_UNSET).isTrue();
|
||||
int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
|
||||
Assert.assertTrue(0 <= indexInTrackGroup);
|
||||
Assert.assertTrue(indexInTrackGroup < trackGroup.length);
|
||||
assertThat(indexInTrackGroup).isAtLeast(0);
|
||||
assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
|
||||
streams[i] = createSampleStream(selection);
|
||||
streamResetFlags[i] = true;
|
||||
}
|
||||
|
|
@ -159,7 +160,7 @@ public class FakeMediaPeriod implements MediaPeriod {
|
|||
|
||||
@Override
|
||||
public long readDiscontinuity() {
|
||||
Assert.assertTrue(prepared);
|
||||
assertThat(prepared).isTrue();
|
||||
long positionDiscontinuityUs = this.discontinuityPositionUs;
|
||||
this.discontinuityPositionUs = C.TIME_UNSET;
|
||||
return positionDiscontinuityUs;
|
||||
|
|
@ -167,13 +168,13 @@ public class FakeMediaPeriod implements MediaPeriod {
|
|||
|
||||
@Override
|
||||
public long getBufferedPositionUs() {
|
||||
Assert.assertTrue(prepared);
|
||||
assertThat(prepared).isTrue();
|
||||
return C.TIME_END_OF_SOURCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seekToUs(long positionUs) {
|
||||
Assert.assertTrue(prepared);
|
||||
assertThat(prepared).isTrue();
|
||||
return positionUs + seekOffsetUs;
|
||||
}
|
||||
|
||||
|
|
@ -184,13 +185,13 @@ public class FakeMediaPeriod implements MediaPeriod {
|
|||
|
||||
@Override
|
||||
public long getNextLoadPositionUs() {
|
||||
Assert.assertTrue(prepared);
|
||||
assertThat(prepared).isTrue();
|
||||
return C.TIME_END_OF_SOURCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueLoading(long positionUs) {
|
||||
Assert.assertTrue(prepared);
|
||||
assertThat(prepared).isTrue();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
|
|
@ -28,7 +30,6 @@ import com.google.android.exoplayer2.upstream.Allocator;
|
|||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Fake {@link MediaSource} that provides a given timeline. Creating the period will return a
|
||||
|
|
@ -75,7 +76,7 @@ public class FakeMediaSource implements MediaSource {
|
|||
@Override
|
||||
public synchronized void prepareSource(
|
||||
ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
Assert.assertFalse(preparedSource);
|
||||
assertThat(preparedSource).isFalse();
|
||||
preparedSource = true;
|
||||
this.listener = listener;
|
||||
sourceInfoRefreshHandler = new Handler();
|
||||
|
|
@ -86,13 +87,13 @@ public class FakeMediaSource implements MediaSource {
|
|||
|
||||
@Override
|
||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
||||
Assert.assertTrue(preparedSource);
|
||||
assertThat(preparedSource).isTrue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
|
||||
Assert.assertTrue(preparedSource);
|
||||
Assert.assertFalse(releasedSource);
|
||||
assertThat(preparedSource).isTrue();
|
||||
assertThat(releasedSource).isFalse();
|
||||
Assertions.checkIndex(id.periodIndex, 0, timeline.getPeriodCount());
|
||||
FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator);
|
||||
activeMediaPeriods.add(mediaPeriod);
|
||||
|
|
@ -102,18 +103,18 @@ public class FakeMediaSource implements MediaSource {
|
|||
|
||||
@Override
|
||||
public void releasePeriod(MediaPeriod mediaPeriod) {
|
||||
Assert.assertTrue(preparedSource);
|
||||
Assert.assertFalse(releasedSource);
|
||||
assertThat(preparedSource).isTrue();
|
||||
assertThat(releasedSource).isFalse();
|
||||
FakeMediaPeriod fakeMediaPeriod = (FakeMediaPeriod) mediaPeriod;
|
||||
Assert.assertTrue(activeMediaPeriods.remove(fakeMediaPeriod));
|
||||
assertThat(activeMediaPeriods.remove(fakeMediaPeriod)).isTrue();
|
||||
fakeMediaPeriod.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
Assert.assertTrue(preparedSource);
|
||||
Assert.assertFalse(releasedSource);
|
||||
Assert.assertTrue(activeMediaPeriods.isEmpty());
|
||||
assertThat(preparedSource).isTrue();
|
||||
assertThat(releasedSource).isFalse();
|
||||
assertThat(activeMediaPeriods.isEmpty()).isTrue();
|
||||
releasedSource = true;
|
||||
}
|
||||
|
||||
|
|
@ -127,8 +128,8 @@ public class FakeMediaSource implements MediaSource {
|
|||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Assert.assertFalse(releasedSource);
|
||||
Assert.assertTrue(preparedSource);
|
||||
assertThat(releasedSource).isFalse();
|
||||
assertThat(preparedSource).isTrue();
|
||||
timeline = newTimeline;
|
||||
manifest = newManifest;
|
||||
listener.onSourceInfoRefreshed(FakeMediaSource.this, timeline, manifest);
|
||||
|
|
@ -144,14 +145,14 @@ public class FakeMediaSource implements MediaSource {
|
|||
* Assert that the source and all periods have been released.
|
||||
*/
|
||||
public void assertReleased() {
|
||||
Assert.assertTrue(releasedSource || !preparedSource);
|
||||
assertThat(releasedSource || !preparedSource).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that a media period for the given id has been created.
|
||||
*/
|
||||
public void assertMediaPeriodCreated(MediaPeriodId mediaPeriodId) {
|
||||
Assert.assertTrue(createdMediaPeriods.contains(mediaPeriodId));
|
||||
assertThat(createdMediaPeriods).contains(mediaPeriodId);
|
||||
}
|
||||
|
||||
protected FakeMediaPeriod createFakeMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.BaseRenderer;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||
|
|
@ -26,7 +28,6 @@ import com.google.android.exoplayer2.util.MimeTypes;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Fake {@link Renderer} that supports any format with the matching MIME type. The renderer
|
||||
|
|
@ -65,7 +66,7 @@ public class FakeRenderer extends BaseRenderer {
|
|||
buffer.data = null;
|
||||
if (result == C.RESULT_FORMAT_READ) {
|
||||
formatReadCount++;
|
||||
Assert.assertTrue(expectedFormats.contains(formatHolder.format));
|
||||
assertThat(expectedFormats).contains(formatHolder.format);
|
||||
} else if (result == C.RESULT_BUFFER_READ) {
|
||||
bufferReadCount++;
|
||||
if (buffer.isEndOfStream()) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import android.test.MoreAsserts;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||
|
|
@ -25,7 +26,6 @@ import java.io.EOFException;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* A fake {@link TrackOutput}.
|
||||
|
|
@ -98,15 +98,15 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
|||
}
|
||||
|
||||
public void assertSampleCount(int count) {
|
||||
Assert.assertEquals(count, sampleTimesUs.size());
|
||||
assertThat(sampleTimesUs).hasSize(count);
|
||||
}
|
||||
|
||||
public void assertSample(int index, byte[] data, long timeUs, int flags, CryptoData cryptoData) {
|
||||
byte[] actualData = getSampleData(index);
|
||||
MoreAsserts.assertEquals(data, actualData);
|
||||
Assert.assertEquals(timeUs, (long) sampleTimesUs.get(index));
|
||||
Assert.assertEquals(flags, (int) sampleFlags.get(index));
|
||||
Assert.assertEquals(cryptoData, cryptoDatas.get(index));
|
||||
assertThat(actualData).isEqualTo(data);
|
||||
assertThat(sampleTimesUs.get(index)).isEqualTo(timeUs);
|
||||
assertThat(sampleFlags.get(index)).isEqualTo(flags);
|
||||
assertThat(cryptoDatas.get(index)).isEqualTo(cryptoData);
|
||||
}
|
||||
|
||||
public byte[] getSampleData(int index) {
|
||||
|
|
@ -115,18 +115,18 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
|||
}
|
||||
|
||||
public void assertEquals(FakeTrackOutput expected) {
|
||||
Assert.assertEquals(expected.format, format);
|
||||
Assert.assertEquals(expected.sampleTimesUs.size(), sampleTimesUs.size());
|
||||
MoreAsserts.assertEquals(expected.sampleData, sampleData);
|
||||
assertThat(format).isEqualTo(expected.format);
|
||||
assertThat(sampleTimesUs).hasSize(expected.sampleTimesUs.size());
|
||||
assertThat(sampleData).isEqualTo(expected.sampleData);
|
||||
for (int i = 0; i < sampleTimesUs.size(); i++) {
|
||||
Assert.assertEquals(expected.sampleTimesUs.get(i), sampleTimesUs.get(i));
|
||||
Assert.assertEquals(expected.sampleFlags.get(i), sampleFlags.get(i));
|
||||
Assert.assertEquals(expected.sampleStartOffsets.get(i), sampleStartOffsets.get(i));
|
||||
Assert.assertEquals(expected.sampleEndOffsets.get(i), sampleEndOffsets.get(i));
|
||||
assertThat(sampleTimesUs.get(i)).isEqualTo(expected.sampleTimesUs.get(i));
|
||||
assertThat(sampleFlags.get(i)).isEqualTo(expected.sampleFlags.get(i));
|
||||
assertThat(sampleStartOffsets.get(i)).isEqualTo(expected.sampleStartOffsets.get(i));
|
||||
assertThat(sampleEndOffsets.get(i)).isEqualTo(expected.sampleEndOffsets.get(i));
|
||||
if (expected.cryptoDatas.get(i) == null) {
|
||||
Assert.assertNull(cryptoDatas.get(i));
|
||||
assertThat(cryptoDatas.get(i)).isNull();
|
||||
} else {
|
||||
Assert.assertEquals(expected.cryptoDatas.get(i), cryptoDatas.get(i));
|
||||
assertThat(cryptoDatas.get(i)).isEqualTo(expected.cryptoDatas.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,14 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.source.TrackGroup;
|
||||
import com.google.android.exoplayer2.source.chunk.MediaChunk;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import java.util.List;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* A fake {@link TrackSelection} that only returns 1 fixed track, and allows querying the number
|
||||
|
|
@ -42,7 +43,7 @@ public final class FakeTrackSelection implements TrackSelection {
|
|||
@Override
|
||||
public void enable() {
|
||||
// assert that track selection is in disabled state before this call.
|
||||
Assert.assertFalse(isEnabled);
|
||||
assertThat(isEnabled).isFalse();
|
||||
enableCount++;
|
||||
isEnabled = true;
|
||||
}
|
||||
|
|
@ -50,7 +51,7 @@ public final class FakeTrackSelection implements TrackSelection {
|
|||
@Override
|
||||
public void disable() {
|
||||
// assert that track selection is in enabled state before this call.
|
||||
Assert.assertTrue(isEnabled);
|
||||
assertThat(isEnabled).isTrue();
|
||||
releaseCount++;
|
||||
isEnabled = false;
|
||||
}
|
||||
|
|
@ -77,7 +78,7 @@ public final class FakeTrackSelection implements TrackSelection {
|
|||
|
||||
@Override
|
||||
public int indexOf(Format format) {
|
||||
Assert.assertTrue(isEnabled);
|
||||
assertThat(isEnabled).isTrue();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -119,18 +120,18 @@ public final class FakeTrackSelection implements TrackSelection {
|
|||
@Override
|
||||
public void updateSelectedTrack(long playbackPositionUs, long bufferedDurationUs,
|
||||
long availableDurationUs) {
|
||||
Assert.assertTrue(isEnabled);
|
||||
assertThat(isEnabled).isTrue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue) {
|
||||
Assert.assertTrue(isEnabled);
|
||||
assertThat(isEnabled).isTrue();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blacklist(int index, long blacklistDurationMs) {
|
||||
Assert.assertTrue(isEnabled);
|
||||
assertThat(isEnabled).isTrue();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static junit.framework.Assert.fail;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.os.ConditionVariable;
|
||||
import android.os.Handler;
|
||||
|
|
@ -90,7 +89,7 @@ public class MediaSourceTestRunner {
|
|||
}
|
||||
}
|
||||
});
|
||||
assertTrue(finishedCondition.block(TIMEOUT_MS));
|
||||
assertThat(finishedCondition.block(TIMEOUT_MS)).isTrue();
|
||||
if (throwable[0] != null) {
|
||||
Util.sneakyThrow(throwable[0]);
|
||||
}
|
||||
|
|
@ -138,7 +137,7 @@ public class MediaSourceTestRunner {
|
|||
holder[0] = mediaSource.createPeriod(periodId, allocator);
|
||||
}
|
||||
});
|
||||
assertNotNull(holder[0]);
|
||||
assertThat(holder[0]).isNotNull();
|
||||
return holder[0];
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +200,7 @@ public class MediaSourceTestRunner {
|
|||
* runner was created if neither method has been called).
|
||||
*/
|
||||
public void assertNoTimelineChange() {
|
||||
assertTrue(timelines.isEmpty());
|
||||
assertThat(timelines.isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -224,7 +223,7 @@ public class MediaSourceTestRunner {
|
|||
public Timeline assertTimelineChangeBlocking() {
|
||||
try {
|
||||
timeline = timelines.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(timeline); // Null indicates the poll timed out.
|
||||
assertThat(timeline).isNotNull(); // Null indicates the poll timed out.
|
||||
assertNoTimelineChange();
|
||||
return timeline;
|
||||
} catch (InterruptedException e) {
|
||||
|
|
@ -254,12 +253,12 @@ public class MediaSourceTestRunner {
|
|||
private void assertPrepareAndReleasePeriod(MediaPeriodId mediaPeriodId) {
|
||||
MediaPeriod mediaPeriod = createPeriod(mediaPeriodId);
|
||||
ConditionVariable preparedCondition = preparePeriod(mediaPeriod, 0);
|
||||
assertTrue(preparedCondition.block(TIMEOUT_MS));
|
||||
assertThat(preparedCondition.block(TIMEOUT_MS)).isTrue();
|
||||
// MediaSource is supposed to support multiple calls to createPeriod with the same id without an
|
||||
// intervening call to releasePeriod.
|
||||
MediaPeriod secondMediaPeriod = createPeriod(mediaPeriodId);
|
||||
ConditionVariable secondPreparedCondition = preparePeriod(secondMediaPeriod, 0);
|
||||
assertTrue(secondPreparedCondition.block(TIMEOUT_MS));
|
||||
assertThat(secondPreparedCondition.block(TIMEOUT_MS)).isTrue();
|
||||
// Release the periods.
|
||||
releasePeriod(mediaPeriod);
|
||||
releasePeriod(secondMediaPeriod);
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.test.MoreAsserts;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException;
|
||||
|
|
@ -29,7 +31,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Utility methods for tests.
|
||||
|
|
@ -71,7 +72,7 @@ public class TestUtil {
|
|||
while (position < length) {
|
||||
int bytesRead = dataSource.read(data, position, data.length - position);
|
||||
if (bytesRead == C.RESULT_END_OF_INPUT) {
|
||||
Assert.fail("Not enough data could be read: " + position + " < " + length);
|
||||
fail("Not enough data could be read: " + position + " < " + length);
|
||||
} else {
|
||||
position += bytesRead;
|
||||
}
|
||||
|
|
@ -164,13 +165,14 @@ public class TestUtil {
|
|||
* data length. If false then it's asserted that {@link C#LENGTH_UNSET} is returned.
|
||||
* @throws IOException If an error occurs reading fom the {@link DataSource}.
|
||||
*/
|
||||
public static void assertDataSourceContent(DataSource dataSource, DataSpec dataSpec,
|
||||
byte[] expectedData, boolean expectKnownLength) throws IOException {
|
||||
public static void assertDataSourceContent(
|
||||
DataSource dataSource, DataSpec dataSpec, byte[] expectedData, boolean expectKnownLength)
|
||||
throws IOException {
|
||||
try {
|
||||
long length = dataSource.open(dataSpec);
|
||||
Assert.assertEquals(expectKnownLength ? expectedData.length : C.LENGTH_UNSET, length);
|
||||
byte[] readData = TestUtil.readToEnd(dataSource);
|
||||
MoreAsserts.assertEquals(expectedData, readData);
|
||||
assertThat(length).isEqualTo(expectKnownLength ? expectedData.length : C.LENGTH_UNSET);
|
||||
byte[] readData = readToEnd(dataSource);
|
||||
assertThat(readData).isEqualTo(expectedData);
|
||||
} finally {
|
||||
dataSource.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
|
|
@ -27,6 +28,10 @@ import com.google.android.exoplayer2.Timeline.Window;
|
|||
*/
|
||||
public final class TimelineAsserts {
|
||||
|
||||
private static final int[] REPEAT_MODES = {
|
||||
Player.REPEAT_MODE_OFF, Player.REPEAT_MODE_ONE, Player.REPEAT_MODE_ALL
|
||||
};
|
||||
|
||||
private TimelineAsserts() {}
|
||||
|
||||
/**
|
||||
|
|
@ -36,8 +41,8 @@ public final class TimelineAsserts {
|
|||
assertWindowIds(timeline);
|
||||
assertPeriodCounts(timeline);
|
||||
for (boolean shuffled : new boolean[] {false, true}) {
|
||||
assertEquals(C.INDEX_UNSET, timeline.getFirstWindowIndex(shuffled));
|
||||
assertEquals(C.INDEX_UNSET, timeline.getLastWindowIndex(shuffled));
|
||||
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET);
|
||||
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,11 +54,11 @@ public final class TimelineAsserts {
|
|||
*/
|
||||
public static void assertWindowIds(Timeline timeline, Object... expectedWindowIds) {
|
||||
Window window = new Window();
|
||||
assertEquals(expectedWindowIds.length, timeline.getWindowCount());
|
||||
assertThat(timeline.getWindowCount()).isEqualTo(expectedWindowIds.length);
|
||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||
timeline.getWindow(i, window, true);
|
||||
if (expectedWindowIds[i] != null) {
|
||||
assertEquals(expectedWindowIds[i], window.id);
|
||||
assertThat(window.id).isEqualTo(expectedWindowIds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +70,7 @@ public final class TimelineAsserts {
|
|||
Window window = new Window();
|
||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||
timeline.getWindow(i, window, true);
|
||||
assertEquals(windowIsDynamic[i], window.isDynamic);
|
||||
assertThat(window.isDynamic).isEqualTo(windowIsDynamic[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +82,8 @@ public final class TimelineAsserts {
|
|||
@Player.RepeatMode int repeatMode, boolean shuffleModeEnabled,
|
||||
int... expectedPreviousWindowIndices) {
|
||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||
assertEquals(expectedPreviousWindowIndices[i],
|
||||
timeline.getPreviousWindowIndex(i, repeatMode, shuffleModeEnabled));
|
||||
assertThat(timeline.getPreviousWindowIndex(i, repeatMode, shuffleModeEnabled))
|
||||
.isEqualTo(expectedPreviousWindowIndices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,8 +94,8 @@ public final class TimelineAsserts {
|
|||
public static void assertNextWindowIndices(Timeline timeline, @Player.RepeatMode int repeatMode,
|
||||
boolean shuffleModeEnabled, int... expectedNextWindowIndices) {
|
||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||
assertEquals(expectedNextWindowIndices[i],
|
||||
timeline.getNextWindowIndex(i, repeatMode, shuffleModeEnabled));
|
||||
assertThat(timeline.getNextWindowIndex(i, repeatMode, shuffleModeEnabled))
|
||||
.isEqualTo(expectedNextWindowIndices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,14 +111,14 @@ public final class TimelineAsserts {
|
|||
for (int i = 0; i < windowCount; i++) {
|
||||
accumulatedPeriodCounts[i + 1] = accumulatedPeriodCounts[i] + expectedPeriodCounts[i];
|
||||
}
|
||||
assertEquals(accumulatedPeriodCounts[accumulatedPeriodCounts.length - 1],
|
||||
timeline.getPeriodCount());
|
||||
assertThat(timeline.getPeriodCount())
|
||||
.isEqualTo(accumulatedPeriodCounts[accumulatedPeriodCounts.length - 1]);
|
||||
Window window = new Window();
|
||||
Period period = new Period();
|
||||
for (int i = 0; i < windowCount; i++) {
|
||||
timeline.getWindow(i, window, true);
|
||||
assertEquals(accumulatedPeriodCounts[i], window.firstPeriodIndex);
|
||||
assertEquals(accumulatedPeriodCounts[i + 1] - 1, window.lastPeriodIndex);
|
||||
assertThat(window.firstPeriodIndex).isEqualTo(accumulatedPeriodCounts[i]);
|
||||
assertThat(window.lastPeriodIndex).isEqualTo(accumulatedPeriodCounts[i + 1] - 1);
|
||||
}
|
||||
int expectedWindowIndex = 0;
|
||||
for (int i = 0; i < timeline.getPeriodCount(); i++) {
|
||||
|
|
@ -121,18 +126,18 @@ public final class TimelineAsserts {
|
|||
while (i >= accumulatedPeriodCounts[expectedWindowIndex + 1]) {
|
||||
expectedWindowIndex++;
|
||||
}
|
||||
assertEquals(expectedWindowIndex, period.windowIndex);
|
||||
assertEquals(i, timeline.getIndexOfPeriod(period.uid));
|
||||
for (@Player.RepeatMode int repeatMode
|
||||
: new int[] {Player.REPEAT_MODE_OFF, Player.REPEAT_MODE_ONE, Player.REPEAT_MODE_ALL}) {
|
||||
assertThat(period.windowIndex).isEqualTo(expectedWindowIndex);
|
||||
assertThat(timeline.getIndexOfPeriod(period.uid)).isEqualTo(i);
|
||||
for (int repeatMode : REPEAT_MODES) {
|
||||
if (i < accumulatedPeriodCounts[expectedWindowIndex + 1] - 1) {
|
||||
assertEquals(i + 1, timeline.getNextPeriodIndex(i, period, window, repeatMode, false));
|
||||
assertThat(timeline.getNextPeriodIndex(i, period, window, repeatMode, false))
|
||||
.isEqualTo(i + 1);
|
||||
} else {
|
||||
int nextWindow = timeline.getNextWindowIndex(expectedWindowIndex, repeatMode, false);
|
||||
int nextPeriod = nextWindow == C.INDEX_UNSET ? C.INDEX_UNSET
|
||||
: accumulatedPeriodCounts[nextWindow];
|
||||
assertEquals(nextPeriod, timeline.getNextPeriodIndex(i, period, window, repeatMode,
|
||||
false));
|
||||
assertThat(timeline.getNextPeriodIndex(i, period, window, repeatMode, false))
|
||||
.isEqualTo(nextPeriod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -145,7 +150,7 @@ public final class TimelineAsserts {
|
|||
Period period = new Period();
|
||||
for (int i = 0; i < timeline.getPeriodCount(); i++) {
|
||||
timeline.getPeriod(i, period);
|
||||
assertEquals(expectedAdGroupCounts[i], period.getAdGroupCount());
|
||||
assertThat(period.getAdGroupCount()).isEqualTo(expectedAdGroupCounts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue