mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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;
|
package com.google.android.exoplayer2.ext.cronet;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
|
@ -53,13 +52,13 @@ public final class ByteArrayUploadDataProviderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLength() {
|
public void testGetLength() {
|
||||||
assertEquals(TEST_DATA.length, byteArrayUploadDataProvider.getLength());
|
assertThat(byteArrayUploadDataProvider.getLength()).isEqualTo(TEST_DATA.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadFullBuffer() throws IOException {
|
public void testReadFullBuffer() throws IOException {
|
||||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||||
assertArrayEquals(TEST_DATA, byteBuffer.array());
|
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -69,12 +68,12 @@ public final class ByteArrayUploadDataProviderTest {
|
||||||
byteBuffer = ByteBuffer.allocate(TEST_DATA.length / 2);
|
byteBuffer = ByteBuffer.allocate(TEST_DATA.length / 2);
|
||||||
// Read half of the data.
|
// Read half of the data.
|
||||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||||
assertArrayEquals(firstHalf, byteBuffer.array());
|
assertThat(byteBuffer.array()).isEqualTo(firstHalf);
|
||||||
|
|
||||||
// Read the second half of the data.
|
// Read the second half of the data.
|
||||||
byteBuffer.rewind();
|
byteBuffer.rewind();
|
||||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||||
assertArrayEquals(secondHalf, byteBuffer.array());
|
assertThat(byteBuffer.array()).isEqualTo(secondHalf);
|
||||||
verify(mockUploadDataSink, times(2)).onReadSucceeded(false);
|
verify(mockUploadDataSink, times(2)).onReadSucceeded(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,13 +81,13 @@ public final class ByteArrayUploadDataProviderTest {
|
||||||
public void testRewind() throws IOException {
|
public void testRewind() throws IOException {
|
||||||
// Read all the data.
|
// Read all the data.
|
||||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||||
assertArrayEquals(TEST_DATA, byteBuffer.array());
|
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
|
||||||
|
|
||||||
// Rewind and make sure it can be read again.
|
// Rewind and make sure it can be read again.
|
||||||
byteBuffer.clear();
|
byteBuffer.clear();
|
||||||
byteArrayUploadDataProvider.rewind(mockUploadDataSink);
|
byteArrayUploadDataProvider.rewind(mockUploadDataSink);
|
||||||
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
byteArrayUploadDataProvider.read(mockUploadDataSink, byteBuffer);
|
||||||
assertArrayEquals(TEST_DATA, byteBuffer.array());
|
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
|
||||||
verify(mockUploadDataSink).onRewindSucceeded();
|
verify(mockUploadDataSink).onRewindSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.ext.cronet;
|
package com.google.android.exoplayer2.ext.cronet;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
|
|
@ -222,7 +219,7 @@ public final class CronetDataSourceTest {
|
||||||
@Test
|
@Test
|
||||||
public void testRequestOpen() throws HttpDataSourceException {
|
public void testRequestOpen() throws HttpDataSourceException {
|
||||||
mockResponseStartSuccess();
|
mockResponseStartSuccess();
|
||||||
assertEquals(TEST_CONTENT_LENGTH, dataSourceUnderTest.open(testDataSpec));
|
assertThat(dataSourceUnderTest.open(testDataSpec)).isEqualTo(TEST_CONTENT_LENGTH);
|
||||||
verify(mockTransferListener).onTransferStart(dataSourceUnderTest, testDataSpec);
|
verify(mockTransferListener).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,7 +231,7 @@ public final class CronetDataSourceTest {
|
||||||
testResponseHeader.put("Content-Length", Long.toString(50L));
|
testResponseHeader.put("Content-Length", Long.toString(50L));
|
||||||
mockResponseStartSuccess();
|
mockResponseStartSuccess();
|
||||||
|
|
||||||
assertEquals(5000 /* contentLength */, dataSourceUnderTest.open(testDataSpec));
|
assertThat(dataSourceUnderTest.open(testDataSpec)).isEqualTo(5000 /* contentLength */);
|
||||||
verify(mockTransferListener).onTransferStart(dataSourceUnderTest, testDataSpec);
|
verify(mockTransferListener).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,7 +244,7 @@ public final class CronetDataSourceTest {
|
||||||
fail("HttpDataSource.HttpDataSourceException expected");
|
fail("HttpDataSource.HttpDataSourceException expected");
|
||||||
} catch (HttpDataSourceException e) {
|
} catch (HttpDataSourceException e) {
|
||||||
// Check for connection not automatically closed.
|
// Check for connection not automatically closed.
|
||||||
assertFalse(e.getCause() instanceof UnknownHostException);
|
assertThat(e.getCause() instanceof UnknownHostException).isFalse();
|
||||||
verify(mockUrlRequest, never()).cancel();
|
verify(mockUrlRequest, never()).cancel();
|
||||||
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +261,7 @@ public final class CronetDataSourceTest {
|
||||||
fail("HttpDataSource.HttpDataSourceException expected");
|
fail("HttpDataSource.HttpDataSourceException expected");
|
||||||
} catch (HttpDataSourceException e) {
|
} catch (HttpDataSourceException e) {
|
||||||
// Check for connection not automatically closed.
|
// Check for connection not automatically closed.
|
||||||
assertTrue(e.getCause() instanceof UnknownHostException);
|
assertThat(e.getCause() instanceof UnknownHostException).isTrue();
|
||||||
verify(mockUrlRequest, never()).cancel();
|
verify(mockUrlRequest, never()).cancel();
|
||||||
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||||
}
|
}
|
||||||
|
|
@ -279,7 +276,7 @@ public final class CronetDataSourceTest {
|
||||||
dataSourceUnderTest.open(testDataSpec);
|
dataSourceUnderTest.open(testDataSpec);
|
||||||
fail("HttpDataSource.HttpDataSourceException expected");
|
fail("HttpDataSource.HttpDataSourceException expected");
|
||||||
} catch (HttpDataSourceException e) {
|
} catch (HttpDataSourceException e) {
|
||||||
assertTrue(e instanceof HttpDataSource.InvalidResponseCodeException);
|
assertThat(e instanceof HttpDataSource.InvalidResponseCodeException).isTrue();
|
||||||
// Check for connection not automatically closed.
|
// Check for connection not automatically closed.
|
||||||
verify(mockUrlRequest, never()).cancel();
|
verify(mockUrlRequest, never()).cancel();
|
||||||
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||||
|
|
@ -295,7 +292,7 @@ public final class CronetDataSourceTest {
|
||||||
dataSourceUnderTest.open(testDataSpec);
|
dataSourceUnderTest.open(testDataSpec);
|
||||||
fail("HttpDataSource.HttpDataSourceException expected");
|
fail("HttpDataSource.HttpDataSourceException expected");
|
||||||
} catch (HttpDataSourceException e) {
|
} catch (HttpDataSourceException e) {
|
||||||
assertTrue(e instanceof HttpDataSource.InvalidContentTypeException);
|
assertThat(e instanceof HttpDataSource.InvalidContentTypeException).isTrue();
|
||||||
// Check for connection not automatically closed.
|
// Check for connection not automatically closed.
|
||||||
verify(mockUrlRequest, never()).cancel();
|
verify(mockUrlRequest, never()).cancel();
|
||||||
verify(mockContentTypePredicate).evaluate(TEST_CONTENT_TYPE);
|
verify(mockContentTypePredicate).evaluate(TEST_CONTENT_TYPE);
|
||||||
|
|
@ -307,7 +304,7 @@ public final class CronetDataSourceTest {
|
||||||
mockResponseStartSuccess();
|
mockResponseStartSuccess();
|
||||||
|
|
||||||
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
|
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);
|
verify(mockTransferListener).onTransferStart(dataSourceUnderTest, testPostDataSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,13 +343,13 @@ public final class CronetDataSourceTest {
|
||||||
|
|
||||||
byte[] returnedBuffer = new byte[8];
|
byte[] returnedBuffer = new byte[8];
|
||||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||||
assertArrayEquals(buildTestDataArray(0, 8), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(0, 8));
|
||||||
assertEquals(8, bytesRead);
|
assertThat(bytesRead).isEqualTo(8);
|
||||||
|
|
||||||
returnedBuffer = new byte[8];
|
returnedBuffer = new byte[8];
|
||||||
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||||
assertArrayEquals(buildTestDataArray(8, 8), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(8, 8));
|
||||||
assertEquals(8, bytesRead);
|
assertThat(bytesRead).isEqualTo(8);
|
||||||
|
|
||||||
// Should have only called read on cronet once.
|
// Should have only called read on cronet once.
|
||||||
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
||||||
|
|
@ -378,11 +375,11 @@ public final class CronetDataSourceTest {
|
||||||
dataSourceUnderTest.open(testDataSpec);
|
dataSourceUnderTest.open(testDataSpec);
|
||||||
returnedBuffer = new byte[16];
|
returnedBuffer = new byte[16];
|
||||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
||||||
assertEquals(10, bytesRead);
|
assertThat(bytesRead).isEqualTo(10);
|
||||||
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
||||||
assertEquals(6, bytesRead);
|
assertThat(bytesRead).isEqualTo(6);
|
||||||
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 10);
|
||||||
assertEquals(C.RESULT_END_OF_INPUT, bytesRead);
|
assertThat(bytesRead).isEqualTo(C.RESULT_END_OF_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -394,8 +391,8 @@ public final class CronetDataSourceTest {
|
||||||
|
|
||||||
byte[] returnedBuffer = new byte[16];
|
byte[] returnedBuffer = new byte[16];
|
||||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 8, 8);
|
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 8, 8);
|
||||||
assertEquals(8, bytesRead);
|
assertThat(bytesRead).isEqualTo(8);
|
||||||
assertArrayEquals(prefixZeros(buildTestDataArray(0, 8), 16), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(prefixZeros(buildTestDataArray(0, 8), 16));
|
||||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 8);
|
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -410,8 +407,8 @@ public final class CronetDataSourceTest {
|
||||||
|
|
||||||
byte[] returnedBuffer = new byte[16];
|
byte[] returnedBuffer = new byte[16];
|
||||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||||
assertEquals(16, bytesRead);
|
assertThat(bytesRead).isEqualTo(16);
|
||||||
assertArrayEquals(buildTestDataArray(1000, 16), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(1000, 16));
|
||||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -426,8 +423,8 @@ public final class CronetDataSourceTest {
|
||||||
|
|
||||||
byte[] returnedBuffer = new byte[16];
|
byte[] returnedBuffer = new byte[16];
|
||||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||||
assertEquals(16, bytesRead);
|
assertThat(bytesRead).isEqualTo(16);
|
||||||
assertArrayEquals(buildTestDataArray(1000, 16), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(1000, 16));
|
||||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -441,8 +438,8 @@ public final class CronetDataSourceTest {
|
||||||
|
|
||||||
byte[] returnedBuffer = new byte[16];
|
byte[] returnedBuffer = new byte[16];
|
||||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 8, 8);
|
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 8, 8);
|
||||||
assertArrayEquals(prefixZeros(buildTestDataArray(0, 8), 16), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(prefixZeros(buildTestDataArray(0, 8), 16));
|
||||||
assertEquals(8, bytesRead);
|
assertThat(bytesRead).isEqualTo(8);
|
||||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 8);
|
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -455,8 +452,8 @@ public final class CronetDataSourceTest {
|
||||||
|
|
||||||
byte[] returnedBuffer = new byte[24];
|
byte[] returnedBuffer = new byte[24];
|
||||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 24);
|
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 24);
|
||||||
assertArrayEquals(suffixZeros(buildTestDataArray(0, 16), 24), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(suffixZeros(buildTestDataArray(0, 16), 24));
|
||||||
assertEquals(16, bytesRead);
|
assertThat(bytesRead).isEqualTo(16);
|
||||||
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
verify(mockTransferListener).onBytesTransferred(dataSourceUnderTest, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -470,8 +467,8 @@ public final class CronetDataSourceTest {
|
||||||
|
|
||||||
byte[] returnedBuffer = new byte[8];
|
byte[] returnedBuffer = new byte[8];
|
||||||
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||||
assertArrayEquals(buildTestDataArray(0, 8), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(0, 8));
|
||||||
assertEquals(8, bytesRead);
|
assertThat(bytesRead).isEqualTo(8);
|
||||||
|
|
||||||
dataSourceUnderTest.close();
|
dataSourceUnderTest.close();
|
||||||
verify(mockTransferListener).onTransferEnd(dataSourceUnderTest);
|
verify(mockTransferListener).onTransferEnd(dataSourceUnderTest);
|
||||||
|
|
@ -484,7 +481,7 @@ public final class CronetDataSourceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 16 bytes were attempted but only 8 should have been successfully read.
|
// 16 bytes were attempted but only 8 should have been successfully read.
|
||||||
assertEquals(8, bytesRead);
|
assertThat(bytesRead).isEqualTo(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -498,20 +495,20 @@ public final class CronetDataSourceTest {
|
||||||
|
|
||||||
byte[] returnedBuffer = new byte[8];
|
byte[] returnedBuffer = new byte[8];
|
||||||
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
int bytesRead = dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||||
assertEquals(8, bytesRead);
|
assertThat(bytesRead).isEqualTo(8);
|
||||||
assertArrayEquals(buildTestDataArray(0, 8), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(buildTestDataArray(0, 8));
|
||||||
|
|
||||||
// The current buffer is kept if not completely consumed by DataSource reader.
|
// The current buffer is kept if not completely consumed by DataSource reader.
|
||||||
returnedBuffer = new byte[8];
|
returnedBuffer = new byte[8];
|
||||||
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 6);
|
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 6);
|
||||||
assertEquals(14, bytesRead);
|
assertThat(bytesRead).isEqualTo(14);
|
||||||
assertArrayEquals(suffixZeros(buildTestDataArray(8, 6), 8), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(suffixZeros(buildTestDataArray(8, 6), 8));
|
||||||
|
|
||||||
// 2 bytes left at this point.
|
// 2 bytes left at this point.
|
||||||
returnedBuffer = new byte[8];
|
returnedBuffer = new byte[8];
|
||||||
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
bytesRead += dataSourceUnderTest.read(returnedBuffer, 0, 8);
|
||||||
assertEquals(16, bytesRead);
|
assertThat(bytesRead).isEqualTo(16);
|
||||||
assertArrayEquals(suffixZeros(buildTestDataArray(14, 2), 8), returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(suffixZeros(buildTestDataArray(14, 2), 8));
|
||||||
|
|
||||||
// Should have only called read on cronet once.
|
// Should have only called read on cronet once.
|
||||||
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
||||||
|
|
@ -524,8 +521,8 @@ public final class CronetDataSourceTest {
|
||||||
// Return C.RESULT_END_OF_INPUT
|
// Return C.RESULT_END_OF_INPUT
|
||||||
returnedBuffer = new byte[16];
|
returnedBuffer = new byte[16];
|
||||||
int bytesOverRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
int bytesOverRead = dataSourceUnderTest.read(returnedBuffer, 0, 16);
|
||||||
assertEquals(C.RESULT_END_OF_INPUT, bytesOverRead);
|
assertThat(bytesOverRead).isEqualTo(C.RESULT_END_OF_INPUT);
|
||||||
assertArrayEquals(new byte[16], returnedBuffer);
|
assertThat(returnedBuffer).isEqualTo(new byte[16]);
|
||||||
// C.RESULT_END_OF_INPUT should not be reported though the TransferListener.
|
// C.RESULT_END_OF_INPUT should not be reported though the TransferListener.
|
||||||
verify(mockTransferListener, never()).onBytesTransferred(dataSourceUnderTest,
|
verify(mockTransferListener, never()).onBytesTransferred(dataSourceUnderTest,
|
||||||
C.RESULT_END_OF_INPUT);
|
C.RESULT_END_OF_INPUT);
|
||||||
|
|
@ -533,7 +530,7 @@ public final class CronetDataSourceTest {
|
||||||
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
verify(mockUrlRequest, times(1)).read(any(ByteBuffer.class));
|
||||||
// Check for connection not automatically closed.
|
// Check for connection not automatically closed.
|
||||||
verify(mockUrlRequest, never()).cancel();
|
verify(mockUrlRequest, never()).cancel();
|
||||||
assertEquals(16, bytesRead);
|
assertThat(bytesRead).isEqualTo(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -550,11 +547,10 @@ public final class CronetDataSourceTest {
|
||||||
fail();
|
fail();
|
||||||
} catch (HttpDataSourceException e) {
|
} catch (HttpDataSourceException e) {
|
||||||
// Expected.
|
// Expected.
|
||||||
assertTrue(e instanceof CronetDataSource.OpenException);
|
assertThat(e instanceof CronetDataSource.OpenException).isTrue();
|
||||||
assertTrue(e.getCause() instanceof SocketTimeoutException);
|
assertThat(e.getCause() instanceof SocketTimeoutException).isTrue();
|
||||||
assertEquals(
|
assertThat(((CronetDataSource.OpenException) e).cronetConnectionStatus)
|
||||||
TEST_CONNECTION_STATUS,
|
.isEqualTo(TEST_CONNECTION_STATUS);
|
||||||
((CronetDataSource.OpenException) e).cronetConnectionStatus);
|
|
||||||
timedOutCondition.open();
|
timedOutCondition.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -562,10 +558,10 @@ public final class CronetDataSourceTest {
|
||||||
startCondition.block();
|
startCondition.block();
|
||||||
|
|
||||||
// We should still be trying to open.
|
// 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.
|
// We should still be trying to open as we approach the timeout.
|
||||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
||||||
assertFalse(timedOutCondition.block(50));
|
assertThat(timedOutCondition.block(50)).isFalse();
|
||||||
// Now we timeout.
|
// Now we timeout.
|
||||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS);
|
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS);
|
||||||
timedOutCondition.block();
|
timedOutCondition.block();
|
||||||
|
|
@ -588,11 +584,10 @@ public final class CronetDataSourceTest {
|
||||||
fail();
|
fail();
|
||||||
} catch (HttpDataSourceException e) {
|
} catch (HttpDataSourceException e) {
|
||||||
// Expected.
|
// Expected.
|
||||||
assertTrue(e instanceof CronetDataSource.OpenException);
|
assertThat(e instanceof CronetDataSource.OpenException).isTrue();
|
||||||
assertTrue(e.getCause() instanceof CronetDataSource.InterruptedIOException);
|
assertThat(e.getCause() instanceof CronetDataSource.InterruptedIOException).isTrue();
|
||||||
assertEquals(
|
assertThat(((CronetDataSource.OpenException) e).cronetConnectionStatus)
|
||||||
TEST_INVALID_CONNECTION_STATUS,
|
.isEqualTo(TEST_INVALID_CONNECTION_STATUS);
|
||||||
((CronetDataSource.OpenException) e).cronetConnectionStatus);
|
|
||||||
timedOutCondition.open();
|
timedOutCondition.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -601,10 +596,10 @@ public final class CronetDataSourceTest {
|
||||||
startCondition.block();
|
startCondition.block();
|
||||||
|
|
||||||
// We should still be trying to open.
|
// 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.
|
// We should still be trying to open as we approach the timeout.
|
||||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
||||||
assertFalse(timedOutCondition.block(50));
|
assertThat(timedOutCondition.block(50)).isFalse();
|
||||||
// Now we interrupt.
|
// Now we interrupt.
|
||||||
thread.interrupt();
|
thread.interrupt();
|
||||||
timedOutCondition.block();
|
timedOutCondition.block();
|
||||||
|
|
@ -632,10 +627,10 @@ public final class CronetDataSourceTest {
|
||||||
startCondition.block();
|
startCondition.block();
|
||||||
|
|
||||||
// We should still be trying to open.
|
// 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.
|
// We should still be trying to open as we approach the timeout.
|
||||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
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.
|
// The response arrives just in time.
|
||||||
dataSourceUnderTest.onResponseStarted(mockUrlRequest, testUrlResponseInfo);
|
dataSourceUnderTest.onResponseStarted(mockUrlRequest, testUrlResponseInfo);
|
||||||
openCondition.block();
|
openCondition.block();
|
||||||
|
|
@ -656,8 +651,8 @@ public final class CronetDataSourceTest {
|
||||||
fail();
|
fail();
|
||||||
} catch (HttpDataSourceException e) {
|
} catch (HttpDataSourceException e) {
|
||||||
// Expected.
|
// Expected.
|
||||||
assertTrue(e instanceof CronetDataSource.OpenException);
|
assertThat(e instanceof CronetDataSource.OpenException).isTrue();
|
||||||
assertTrue(e.getCause() instanceof SocketTimeoutException);
|
assertThat(e.getCause() instanceof SocketTimeoutException).isTrue();
|
||||||
openExceptions.getAndIncrement();
|
openExceptions.getAndIncrement();
|
||||||
timedOutCondition.open();
|
timedOutCondition.open();
|
||||||
}
|
}
|
||||||
|
|
@ -666,10 +661,10 @@ public final class CronetDataSourceTest {
|
||||||
startCondition.block();
|
startCondition.block();
|
||||||
|
|
||||||
// We should still be trying to open.
|
// 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.
|
// We should still be trying to open as we approach the timeout.
|
||||||
when(mockClock.elapsedRealtime()).thenReturn((long) TEST_CONNECT_TIMEOUT_MS - 1);
|
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.
|
// A redirect arrives just in time.
|
||||||
dataSourceUnderTest.onRedirectReceived(mockUrlRequest, testUrlResponseInfo,
|
dataSourceUnderTest.onRedirectReceived(mockUrlRequest, testUrlResponseInfo,
|
||||||
"RandomRedirectedUrl1");
|
"RandomRedirectedUrl1");
|
||||||
|
|
@ -677,9 +672,9 @@ public final class CronetDataSourceTest {
|
||||||
long newTimeoutMs = 2 * TEST_CONNECT_TIMEOUT_MS - 1;
|
long newTimeoutMs = 2 * TEST_CONNECT_TIMEOUT_MS - 1;
|
||||||
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs - 1);
|
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs - 1);
|
||||||
// Give the thread some time to run.
|
// 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.
|
// 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.
|
// A redirect arrives just in time.
|
||||||
dataSourceUnderTest.onRedirectReceived(mockUrlRequest, testUrlResponseInfo,
|
dataSourceUnderTest.onRedirectReceived(mockUrlRequest, testUrlResponseInfo,
|
||||||
"RandomRedirectedUrl2");
|
"RandomRedirectedUrl2");
|
||||||
|
|
@ -687,15 +682,15 @@ public final class CronetDataSourceTest {
|
||||||
newTimeoutMs = 3 * TEST_CONNECT_TIMEOUT_MS - 2;
|
newTimeoutMs = 3 * TEST_CONNECT_TIMEOUT_MS - 2;
|
||||||
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs - 1);
|
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs - 1);
|
||||||
// Give the thread some time to run.
|
// 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.
|
// 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.
|
// Now we timeout.
|
||||||
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs);
|
when(mockClock.elapsedRealtime()).thenReturn(newTimeoutMs);
|
||||||
timedOutCondition.block();
|
timedOutCondition.block();
|
||||||
|
|
||||||
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec);
|
||||||
assertEquals(1, openExceptions.get());
|
assertThat(openExceptions.get()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -855,7 +850,7 @@ public final class CronetDataSourceTest {
|
||||||
fail();
|
fail();
|
||||||
} catch (HttpDataSourceException e) {
|
} catch (HttpDataSourceException e) {
|
||||||
// Expected.
|
// Expected.
|
||||||
assertTrue(e.getCause() instanceof CronetDataSource.InterruptedIOException);
|
assertThat(e.getCause() instanceof CronetDataSource.InterruptedIOException).isTrue();
|
||||||
timedOutCondition.open();
|
timedOutCondition.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -863,7 +858,7 @@ public final class CronetDataSourceTest {
|
||||||
thread.start();
|
thread.start();
|
||||||
startCondition.block();
|
startCondition.block();
|
||||||
|
|
||||||
assertFalse(timedOutCondition.block(50));
|
assertThat(timedOutCondition.block(50)).isFalse();
|
||||||
// Now we interrupt.
|
// Now we interrupt.
|
||||||
thread.interrupt();
|
thread.interrupt();
|
||||||
timedOutCondition.block();
|
timedOutCondition.block();
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(modulePrefix + 'library-core')
|
compile project(modulePrefix + 'library-core')
|
||||||
|
androidTestCompile 'com.google.truth:truth:' + truthVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.ext.vp9;
|
package com.google.android.exoplayer2.ext.vp9;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
@ -73,8 +75,8 @@ public class VpxPlaybackTest extends InstrumentationTestCase {
|
||||||
playUri(INVALID_BITSTREAM_URI);
|
playUri(INVALID_BITSTREAM_URI);
|
||||||
fail();
|
fail();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertNotNull(e.getCause());
|
assertThat(e.getCause()).isNotNull();
|
||||||
assertTrue(e.getCause() instanceof VpxDecoderException);
|
assertThat(e.getCause()).isInstanceOf(VpxDecoderException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ dependencies {
|
||||||
compile 'com.android.support:support-annotations:' + supportLibraryVersion
|
compile 'com.android.support:support-annotations:' + supportLibraryVersion
|
||||||
androidTestCompile 'com.google.dexmaker:dexmaker:' + dexmakerVersion
|
androidTestCompile 'com.google.dexmaker:dexmaker:' + dexmakerVersion
|
||||||
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:' + dexmakerVersion
|
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:' + dexmakerVersion
|
||||||
|
androidTestCompile 'com.google.truth:truth:' + truthVersion
|
||||||
androidTestCompile 'org.mockito:mockito-core:' + mockitoVersion
|
androidTestCompile 'org.mockito:mockito-core:' + mockitoVersion
|
||||||
testCompile 'com.google.truth:truth:' + truthVersion
|
testCompile 'com.google.truth:truth:' + truthVersion
|
||||||
testCompile 'junit:junit:' + junitVersion
|
testCompile 'junit:junit:' + junitVersion
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2;
|
package com.google.android.exoplayer2;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import com.google.android.exoplayer2.Player.DefaultEventListener;
|
import com.google.android.exoplayer2.Player.DefaultEventListener;
|
||||||
import com.google.android.exoplayer2.Player.EventListener;
|
import com.google.android.exoplayer2.Player.EventListener;
|
||||||
|
|
@ -66,7 +68,7 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
Timeline timeline = Timeline.EMPTY;
|
Timeline timeline = Timeline.EMPTY;
|
||||||
FakeRenderer renderer = new FakeRenderer();
|
FakeRenderer renderer = new FakeRenderer();
|
||||||
ExoPlayerTestRunner testRunner =
|
ExoPlayerTestRunner testRunner =
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setRenderers(renderer)
|
.setRenderers(renderer)
|
||||||
.build()
|
.build()
|
||||||
|
|
@ -74,9 +76,9 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
testRunner.assertNoPositionDiscontinuities();
|
testRunner.assertNoPositionDiscontinuities();
|
||||||
testRunner.assertTimelinesEqual(timeline);
|
testRunner.assertTimelinesEqual(timeline);
|
||||||
assertEquals(0, renderer.formatReadCount);
|
assertThat(renderer.formatReadCount).isEqualTo(0);
|
||||||
assertEquals(0, renderer.bufferReadCount);
|
assertThat(renderer.bufferReadCount).isEqualTo(0);
|
||||||
assertFalse(renderer.isEnded);
|
assertThat(renderer.isEnded).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -86,17 +88,22 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
|
||||||
Object manifest = new Object();
|
Object manifest = new Object();
|
||||||
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
||||||
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
|
ExoPlayerTestRunner testRunner =
|
||||||
.setTimeline(timeline).setManifest(manifest).setRenderers(renderer)
|
new Builder()
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.setTimeline(timeline)
|
||||||
|
.setManifest(manifest)
|
||||||
|
.setRenderers(renderer)
|
||||||
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
testRunner.assertNoPositionDiscontinuities();
|
testRunner.assertNoPositionDiscontinuities();
|
||||||
testRunner.assertTimelinesEqual(timeline);
|
testRunner.assertTimelinesEqual(timeline);
|
||||||
testRunner.assertManifestsEqual(manifest);
|
testRunner.assertManifestsEqual(manifest);
|
||||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||||
testRunner.assertTrackGroupsEqual(new TrackGroupArray(new TrackGroup(Builder.VIDEO_FORMAT)));
|
testRunner.assertTrackGroupsEqual(new TrackGroupArray(new TrackGroup(Builder.VIDEO_FORMAT)));
|
||||||
assertEquals(1, renderer.formatReadCount);
|
assertThat(renderer.formatReadCount).isEqualTo(1);
|
||||||
assertEquals(1, renderer.bufferReadCount);
|
assertThat(renderer.bufferReadCount).isEqualTo(1);
|
||||||
assertTrue(renderer.isEnded);
|
assertThat(renderer.isEnded).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -105,17 +112,21 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
public void testPlayMultiPeriodTimeline() throws Exception {
|
public void testPlayMultiPeriodTimeline() throws Exception {
|
||||||
Timeline timeline = new FakeTimeline(/* windowCount= */ 3);
|
Timeline timeline = new FakeTimeline(/* windowCount= */ 3);
|
||||||
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
||||||
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
|
ExoPlayerTestRunner testRunner =
|
||||||
.setTimeline(timeline).setRenderers(renderer)
|
new Builder()
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.setTimeline(timeline)
|
||||||
|
.setRenderers(renderer)
|
||||||
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
testRunner.assertPositionDiscontinuityReasonsEqual(
|
testRunner.assertPositionDiscontinuityReasonsEqual(
|
||||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
||||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||||
testRunner.assertTimelinesEqual(timeline);
|
testRunner.assertTimelinesEqual(timeline);
|
||||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||||
assertEquals(3, renderer.formatReadCount);
|
assertThat(renderer.formatReadCount).isEqualTo(3);
|
||||||
assertEquals(1, renderer.bufferReadCount);
|
assertThat(renderer.bufferReadCount).isEqualTo(1);
|
||||||
assertTrue(renderer.isEnded);
|
assertThat(renderer.isEnded).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tests playback of periods with very short duration. */
|
/** 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));
|
new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */ 100, /* id= */ 0));
|
||||||
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
||||||
ExoPlayerTestRunner testRunner =
|
ExoPlayerTestRunner testRunner =
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setRenderers(renderer)
|
.setRenderers(renderer)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
int[] expectedReasons = new int[99];
|
Integer[] expectedReasons = new Integer[99];
|
||||||
Arrays.fill(expectedReasons, Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
Arrays.fill(expectedReasons, Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||||
testRunner.assertPositionDiscontinuityReasonsEqual(expectedReasons);
|
testRunner.assertPositionDiscontinuityReasonsEqual(expectedReasons);
|
||||||
testRunner.assertTimelinesEqual(timeline);
|
testRunner.assertTimelinesEqual(timeline);
|
||||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||||
assertEquals(100, renderer.formatReadCount);
|
assertThat(renderer.formatReadCount).isEqualTo(100);
|
||||||
assertEquals(1, renderer.bufferReadCount);
|
assertThat(renderer.bufferReadCount).isEqualTo(1);
|
||||||
assertTrue(renderer.isEnded);
|
assertThat(renderer.isEnded).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -175,17 +186,21 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
|
ExoPlayerTestRunner testRunner =
|
||||||
.setTimeline(timeline).setRenderers(videoRenderer, audioRenderer)
|
new Builder()
|
||||||
.setSupportedFormats(Builder.VIDEO_FORMAT, Builder.AUDIO_FORMAT)
|
.setTimeline(timeline)
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.setRenderers(videoRenderer, audioRenderer)
|
||||||
|
.setSupportedFormats(Builder.VIDEO_FORMAT, Builder.AUDIO_FORMAT)
|
||||||
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
testRunner.assertPositionDiscontinuityReasonsEqual(
|
testRunner.assertPositionDiscontinuityReasonsEqual(
|
||||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
||||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||||
testRunner.assertTimelinesEqual(timeline);
|
testRunner.assertTimelinesEqual(timeline);
|
||||||
assertEquals(1, audioRenderer.positionResetCount);
|
assertThat(audioRenderer.positionResetCount).isEqualTo(1);
|
||||||
assertTrue(videoRenderer.isEnded);
|
assertThat(videoRenderer.isEnded).isTrue();
|
||||||
assertTrue(audioRenderer.isEnded);
|
assertThat(audioRenderer.isEnded).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRepreparationGivesFreshSourceInfo() throws Exception {
|
public void testRepreparationGivesFreshSourceInfo() throws Exception {
|
||||||
|
|
@ -196,21 +211,25 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
Builder.VIDEO_FORMAT);
|
Builder.VIDEO_FORMAT);
|
||||||
final CountDownLatch queuedSourceInfoCountDownLatch = new CountDownLatch(1);
|
final CountDownLatch queuedSourceInfoCountDownLatch = new CountDownLatch(1);
|
||||||
final CountDownLatch completePreparationCountDownLatch = new CountDownLatch(1);
|
final CountDownLatch completePreparationCountDownLatch = new CountDownLatch(1);
|
||||||
MediaSource secondSource = new FakeMediaSource(timeline, new Object(), Builder.VIDEO_FORMAT) {
|
MediaSource secondSource =
|
||||||
@Override
|
new FakeMediaSource(timeline, new Object(), Builder.VIDEO_FORMAT) {
|
||||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
@Override
|
||||||
super.prepareSource(player, isTopLevelSource, listener);
|
public synchronized void prepareSource(
|
||||||
// We've queued a source info refresh on the playback thread's event queue. Allow the test
|
ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||||
// thread to prepare the player with the third source, and block this thread (the playback
|
super.prepareSource(player, isTopLevelSource, listener);
|
||||||
// thread) until the test thread's call to prepare() has returned.
|
// We've queued a source info refresh on the playback thread's event queue. Allow the
|
||||||
queuedSourceInfoCountDownLatch.countDown();
|
// test
|
||||||
try {
|
// thread to prepare the player with the third source, and block this thread (the
|
||||||
completePreparationCountDownLatch.await();
|
// playback
|
||||||
} catch (InterruptedException e) {
|
// thread) until the test thread's call to prepare() has returned.
|
||||||
throw new IllegalStateException(e);
|
queuedSourceInfoCountDownLatch.countDown();
|
||||||
}
|
try {
|
||||||
}
|
completePreparationCountDownLatch.await();
|
||||||
};
|
} catch (InterruptedException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Object thirdSourceManifest = new Object();
|
Object thirdSourceManifest = new Object();
|
||||||
MediaSource thirdSource = new FakeMediaSource(timeline, thirdSourceManifest,
|
MediaSource thirdSource = new FakeMediaSource(timeline, thirdSourceManifest,
|
||||||
Builder.VIDEO_FORMAT);
|
Builder.VIDEO_FORMAT);
|
||||||
|
|
@ -240,9 +259,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
|
ExoPlayerTestRunner testRunner =
|
||||||
.setMediaSource(firstSource).setRenderers(renderer).setActionSchedule(actionSchedule)
|
new Builder()
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.setMediaSource(firstSource)
|
||||||
|
.setRenderers(renderer)
|
||||||
|
.setActionSchedule(actionSchedule)
|
||||||
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
testRunner.assertNoPositionDiscontinuities();
|
testRunner.assertNoPositionDiscontinuities();
|
||||||
// The first source's preparation completed with a non-empty timeline. When the player was
|
// 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
|
// 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,
|
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED,
|
||||||
Player.TIMELINE_CHANGE_REASON_RESET, Player.TIMELINE_CHANGE_REASON_PREPARED);
|
Player.TIMELINE_CHANGE_REASON_RESET, Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||||
testRunner.assertTrackGroupsEqual(new TrackGroupArray(new TrackGroup(Builder.VIDEO_FORMAT)));
|
testRunner.assertTrackGroupsEqual(new TrackGroupArray(new TrackGroup(Builder.VIDEO_FORMAT)));
|
||||||
assertTrue(renderer.isEnded);
|
assertThat(renderer.isEnded).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRepeatModeChanges() throws Exception {
|
public void testRepeatModeChanges() throws Exception {
|
||||||
|
|
@ -293,7 +317,7 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION);
|
||||||
testRunner.assertTimelinesEqual(timeline);
|
testRunner.assertTimelinesEqual(timeline);
|
||||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||||
assertTrue(renderer.isEnded);
|
assertThat(renderer.isEnded).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShuffleModeEnabledChanges() throws Exception {
|
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,
|
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 {
|
public void testPeriodHoldersReleasedAfterSeekWithRepeatModeAll() throws Exception {
|
||||||
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
|
||||||
ActionSchedule actionSchedule = new ActionSchedule.Builder("testPeriodHoldersReleased")
|
ActionSchedule actionSchedule =
|
||||||
.setRepeatMode(Player.REPEAT_MODE_ALL)
|
new ActionSchedule.Builder("testPeriodHoldersReleased")
|
||||||
.waitForPositionDiscontinuity()
|
.setRepeatMode(Player.REPEAT_MODE_ALL)
|
||||||
.seek(0) // Seek with repeat mode set to REPEAT_MODE_ALL.
|
.waitForPositionDiscontinuity()
|
||||||
.waitForPositionDiscontinuity()
|
.seek(0) // Seek with repeat mode set to Player.REPEAT_MODE_ALL.
|
||||||
.setRepeatMode(Player.REPEAT_MODE_OFF) // Turn off repeat so that playback can finish.
|
.waitForPositionDiscontinuity()
|
||||||
.build();
|
.setRepeatMode(Player.REPEAT_MODE_OFF) // Turn off repeat so that playback can finish.
|
||||||
new ExoPlayerTestRunner.Builder()
|
.build();
|
||||||
.setRenderers(renderer).setActionSchedule(actionSchedule)
|
new Builder()
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.setRenderers(renderer)
|
||||||
assertTrue(renderer.isEnded);
|
.setActionSchedule(actionSchedule)
|
||||||
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
|
assertThat(renderer.isEnded).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSeekProcessedCallback() throws Exception {
|
public void testSeekProcessedCallback() throws Exception {
|
||||||
|
|
@ -359,7 +387,7 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.seek(2)
|
.seek(2)
|
||||||
.seek(10)
|
.seek(10)
|
||||||
// Wait until media source prepared and re-seek to same position. Expect a seek
|
// 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)
|
.waitForPlaybackState(Player.STATE_READY)
|
||||||
.seek(10)
|
.seek(10)
|
||||||
// Start playback and wait until playback reaches second window.
|
// Start playback and wait until playback reaches second window.
|
||||||
|
|
@ -371,19 +399,20 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.seek(60)
|
.seek(60)
|
||||||
.build();
|
.build();
|
||||||
final List<Integer> playbackStatesWhenSeekProcessed = new ArrayList<>();
|
final List<Integer> playbackStatesWhenSeekProcessed = new ArrayList<>();
|
||||||
Player.EventListener eventListener = new Player.DefaultEventListener() {
|
EventListener eventListener =
|
||||||
private int currentPlaybackState = Player.STATE_IDLE;
|
new DefaultEventListener() {
|
||||||
|
private int currentPlaybackState = Player.STATE_IDLE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||||
currentPlaybackState = playbackState;
|
currentPlaybackState = playbackState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSeekProcessed() {
|
public void onSeekProcessed() {
|
||||||
playbackStatesWhenSeekProcessed.add(currentPlaybackState);
|
playbackStatesWhenSeekProcessed.add(currentPlaybackState);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ExoPlayerTestRunner testRunner =
|
ExoPlayerTestRunner testRunner =
|
||||||
new ExoPlayerTestRunner.Builder()
|
new ExoPlayerTestRunner.Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
|
|
@ -400,11 +429,13 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
Player.DISCONTINUITY_REASON_PERIOD_TRANSITION,
|
||||||
Player.DISCONTINUITY_REASON_SEEK,
|
Player.DISCONTINUITY_REASON_SEEK,
|
||||||
Player.DISCONTINUITY_REASON_SEEK);
|
Player.DISCONTINUITY_REASON_SEEK);
|
||||||
assertEquals(4, playbackStatesWhenSeekProcessed.size());
|
assertThat(playbackStatesWhenSeekProcessed)
|
||||||
assertEquals(Player.STATE_BUFFERING, (int) playbackStatesWhenSeekProcessed.get(0));
|
.containsExactly(
|
||||||
assertEquals(Player.STATE_BUFFERING, (int) playbackStatesWhenSeekProcessed.get(1));
|
Player.STATE_BUFFERING,
|
||||||
assertEquals(Player.STATE_READY, (int) playbackStatesWhenSeekProcessed.get(2));
|
Player.STATE_BUFFERING,
|
||||||
assertEquals(Player.STATE_BUFFERING, (int) playbackStatesWhenSeekProcessed.get(3));
|
Player.STATE_READY,
|
||||||
|
Player.STATE_BUFFERING)
|
||||||
|
.inOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSeekProcessedCalledWithIllegalSeekPosition() throws Exception {
|
public void testSeekProcessedCalledWithIllegalSeekPosition() throws Exception {
|
||||||
|
|
@ -427,17 +458,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ExoPlayerTestRunner testRunner =
|
ExoPlayerTestRunner testRunner =
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder().setActionSchedule(actionSchedule).setEventListener(listener).build();
|
||||||
.setActionSchedule(actionSchedule)
|
|
||||||
.setEventListener(listener)
|
|
||||||
.build();
|
|
||||||
try {
|
try {
|
||||||
testRunner.start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
|
testRunner.start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
|
||||||
fail();
|
fail();
|
||||||
} catch (ExoPlaybackException e) {
|
} catch (ExoPlaybackException e) {
|
||||||
// Expected exception.
|
// Expected exception.
|
||||||
}
|
}
|
||||||
assertTrue(onSeekProcessedCalled[0]);
|
assertThat(onSeekProcessedCalled[0]).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSeekDiscontinuity() throws Exception {
|
public void testSeekDiscontinuity() throws Exception {
|
||||||
|
|
@ -514,24 +542,26 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
FakeRenderer audioRenderer = new FakeRenderer(Builder.AUDIO_FORMAT);
|
FakeRenderer audioRenderer = new FakeRenderer(Builder.AUDIO_FORMAT);
|
||||||
FakeTrackSelector trackSelector = new FakeTrackSelector();
|
FakeTrackSelector trackSelector = new FakeTrackSelector();
|
||||||
|
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setMediaSource(mediaSource)
|
.setMediaSource(mediaSource)
|
||||||
.setRenderers(videoRenderer, audioRenderer)
|
.setRenderers(videoRenderer, audioRenderer)
|
||||||
.setTrackSelector(trackSelector)
|
.setTrackSelector(trackSelector)
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
|
|
||||||
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
||||||
int numSelectionsEnabled = 0;
|
int numSelectionsEnabled = 0;
|
||||||
// Assert that all tracks selection are disabled at the end of the playback.
|
// Assert that all tracks selection are disabled at the end of the playback.
|
||||||
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
||||||
assertFalse(trackSelection.isEnabled);
|
assertThat(trackSelection.isEnabled).isFalse();
|
||||||
numSelectionsEnabled += trackSelection.enableCount;
|
numSelectionsEnabled += trackSelection.enableCount;
|
||||||
}
|
}
|
||||||
// There are 2 renderers, and track selections are made once (1 period).
|
// There are 2 renderers, and track selections are made once (1 period).
|
||||||
// Track selections are not reused, so there are 2 track selections made.
|
// 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.
|
// There should be 2 track selections enabled in total.
|
||||||
assertEquals(2, numSelectionsEnabled);
|
assertThat(numSelectionsEnabled).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllActivatedTrackSelectionAreReleasedForMultiPeriods() throws Exception {
|
public void testAllActivatedTrackSelectionAreReleasedForMultiPeriods() throws Exception {
|
||||||
|
|
@ -542,24 +572,26 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
FakeRenderer audioRenderer = new FakeRenderer(Builder.AUDIO_FORMAT);
|
FakeRenderer audioRenderer = new FakeRenderer(Builder.AUDIO_FORMAT);
|
||||||
FakeTrackSelector trackSelector = new FakeTrackSelector();
|
FakeTrackSelector trackSelector = new FakeTrackSelector();
|
||||||
|
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setMediaSource(mediaSource)
|
.setMediaSource(mediaSource)
|
||||||
.setRenderers(videoRenderer, audioRenderer)
|
.setRenderers(videoRenderer, audioRenderer)
|
||||||
.setTrackSelector(trackSelector)
|
.setTrackSelector(trackSelector)
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
|
|
||||||
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
||||||
int numSelectionsEnabled = 0;
|
int numSelectionsEnabled = 0;
|
||||||
// Assert that all tracks selection are disabled at the end of the playback.
|
// Assert that all tracks selection are disabled at the end of the playback.
|
||||||
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
||||||
assertFalse(trackSelection.isEnabled);
|
assertThat(trackSelection.isEnabled).isFalse();
|
||||||
numSelectionsEnabled += trackSelection.enableCount;
|
numSelectionsEnabled += trackSelection.enableCount;
|
||||||
}
|
}
|
||||||
// There are 2 renderers, and track selections are made twice (2 periods).
|
// There are 2 renderers, and track selections are made twice (2 periods).
|
||||||
// Track selections are not reused, so there are 4 track selections made.
|
// 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.
|
// There should be 4 track selections enabled in total.
|
||||||
assertEquals(4, numSelectionsEnabled);
|
assertThat(numSelectionsEnabled).isEqualTo(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreRemade()
|
public void testAllActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreRemade()
|
||||||
|
|
@ -584,26 +616,28 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setMediaSource(mediaSource)
|
.setMediaSource(mediaSource)
|
||||||
.setRenderers(videoRenderer, audioRenderer)
|
.setRenderers(videoRenderer, audioRenderer)
|
||||||
.setTrackSelector(trackSelector)
|
.setTrackSelector(trackSelector)
|
||||||
.setActionSchedule(disableTrackAction)
|
.setActionSchedule(disableTrackAction)
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
|
|
||||||
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
||||||
int numSelectionsEnabled = 0;
|
int numSelectionsEnabled = 0;
|
||||||
// Assert that all tracks selection are disabled at the end of the playback.
|
// Assert that all tracks selection are disabled at the end of the playback.
|
||||||
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
||||||
assertFalse(trackSelection.isEnabled);
|
assertThat(trackSelection.isEnabled).isFalse();
|
||||||
numSelectionsEnabled += trackSelection.enableCount;
|
numSelectionsEnabled += trackSelection.enableCount;
|
||||||
}
|
}
|
||||||
// There are 2 renderers, and track selections are made twice.
|
// There are 2 renderers, and track selections are made twice.
|
||||||
// Track selections are not reused, so there are 4 track selections made.
|
// 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.
|
// Initially there are 2 track selections enabled.
|
||||||
// The second time one renderer is disabled, so only 1 track selection should be 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()
|
public void testAllActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreUsed()
|
||||||
|
|
@ -628,26 +662,28 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setMediaSource(mediaSource)
|
.setMediaSource(mediaSource)
|
||||||
.setRenderers(videoRenderer, audioRenderer)
|
.setRenderers(videoRenderer, audioRenderer)
|
||||||
.setTrackSelector(trackSelector)
|
.setTrackSelector(trackSelector)
|
||||||
.setActionSchedule(disableTrackAction)
|
.setActionSchedule(disableTrackAction)
|
||||||
.build().start().blockUntilEnded(TIMEOUT_MS);
|
.build()
|
||||||
|
.start()
|
||||||
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
|
|
||||||
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
List<FakeTrackSelection> createdTrackSelections = trackSelector.getSelectedTrackSelections();
|
||||||
int numSelectionsEnabled = 0;
|
int numSelectionsEnabled = 0;
|
||||||
// Assert that all tracks selection are disabled at the end of the playback.
|
// Assert that all tracks selection are disabled at the end of the playback.
|
||||||
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
for (FakeTrackSelection trackSelection : createdTrackSelections) {
|
||||||
assertFalse(trackSelection.isEnabled);
|
assertThat(trackSelection.isEnabled).isFalse();
|
||||||
numSelectionsEnabled += trackSelection.enableCount;
|
numSelectionsEnabled += trackSelection.enableCount;
|
||||||
}
|
}
|
||||||
// There are 2 renderers, and track selections are made twice.
|
// There are 2 renderers, and track selections are made twice.
|
||||||
// TrackSelections are reused, so there are only 2 track selections made for 2 renderers.
|
// 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.
|
// Initially there are 2 track selections enabled.
|
||||||
// The second time one renderer is disabled, so only 1 track selection should be 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 {
|
public void testDynamicTimelineChangeReason() throws Exception {
|
||||||
|
|
@ -779,7 +815,7 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
testRunner.assertTimelinesEqual(timeline);
|
testRunner.assertTimelinesEqual(timeline);
|
||||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||||
testRunner.assertNoPositionDiscontinuities();
|
testRunner.assertNoPositionDiscontinuities();
|
||||||
assertTrue(positionHolder[0] >= 50);
|
assertThat(positionHolder[0]).isAtLeast(50L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStopWithoutResetDoesNotResetPosition() throws Exception {
|
public void testStopWithoutResetDoesNotResetPosition() throws Exception {
|
||||||
|
|
@ -810,7 +846,7 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
testRunner.assertTimelinesEqual(timeline);
|
testRunner.assertTimelinesEqual(timeline);
|
||||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||||
testRunner.assertNoPositionDiscontinuities();
|
testRunner.assertNoPositionDiscontinuities();
|
||||||
assertTrue(positionHolder[0] >= 50);
|
assertThat(positionHolder[0]).isAtLeast(50L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStopWithResetDoesResetPosition() throws Exception {
|
public void testStopWithResetDoesResetPosition() throws Exception {
|
||||||
|
|
@ -842,7 +878,7 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED,
|
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PREPARED,
|
||||||
Player.TIMELINE_CHANGE_REASON_RESET);
|
Player.TIMELINE_CHANGE_REASON_RESET);
|
||||||
testRunner.assertNoPositionDiscontinuities();
|
testRunner.assertNoPositionDiscontinuities();
|
||||||
assertEquals(0, positionHolder[0]);
|
assertThat(positionHolder[0]).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStopWithoutResetReleasesMediaSource() throws Exception {
|
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);
|
Player.TIMELINE_CHANGE_REASON_PREPARED, Player.TIMELINE_CHANGE_REASON_PREPARED);
|
||||||
testRunner.assertPositionDiscontinuityReasonsEqual(
|
testRunner.assertPositionDiscontinuityReasonsEqual(
|
||||||
Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_SEEK);
|
Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_SEEK);
|
||||||
assertEquals(50, positionHolder[0]);
|
assertThat(positionHolder[0]).isEqualTo(50);
|
||||||
assertEquals(50, positionHolder[1]);
|
assertThat(positionHolder[1]).isEqualTo(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPlaybackErrorDuringSourceInfoRefreshStillUpdatesTimeline() throws Exception {
|
public void testPlaybackErrorDuringSourceInfoRefreshStillUpdatesTimeline() throws Exception {
|
||||||
|
|
@ -1107,13 +1143,13 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.sendMessage(target, /* positionMs= */ 50)
|
.sendMessage(target, /* positionMs= */ 50)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesAfterPreparation() throws Exception {
|
public void testSendMessagesAfterPreparation() throws Exception {
|
||||||
|
|
@ -1126,13 +1162,13 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.sendMessage(target, /* positionMs= */ 50)
|
.sendMessage(target, /* positionMs= */ 50)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleSendMessages() throws Exception {
|
public void testMultipleSendMessages() throws Exception {
|
||||||
|
|
@ -1147,15 +1183,15 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.sendMessage(target50, /* positionMs= */ 50)
|
.sendMessage(target50, /* positionMs= */ 50)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target50.positionMs >= 50);
|
assertThat(target50.positionMs >= 50).isTrue();
|
||||||
assertTrue(target80.positionMs >= 80);
|
assertThat(target80.positionMs >= 80).isTrue();
|
||||||
assertTrue(target80.positionMs >= target50.positionMs);
|
assertThat(target80.positionMs).isAtLeast(target50.positionMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleSendMessagesAtSameTime() throws Exception {
|
public void testMultipleSendMessagesAtSameTime() throws Exception {
|
||||||
|
|
@ -1170,14 +1206,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.sendMessage(target2, /* positionMs= */ 50)
|
.sendMessage(target2, /* positionMs= */ 50)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target1.positionMs >= 50);
|
assertThat(target1.positionMs >= 50).isTrue();
|
||||||
assertTrue(target2.positionMs >= 50);
|
assertThat(target2.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesMultiPeriodResolution() throws Exception {
|
public void testSendMessagesMultiPeriodResolution() throws Exception {
|
||||||
|
|
@ -1191,13 +1227,13 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.sendMessage(target, /* positionMs= */ 50)
|
.sendMessage(target, /* positionMs= */ 50)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesAtStartAndEndOfPeriod() throws Exception {
|
public void testSendMessagesAtStartAndEndOfPeriod() throws Exception {
|
||||||
|
|
@ -1226,21 +1262,21 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
/* resetState= */ true)
|
/* resetState= */ true)
|
||||||
.waitForPlaybackState(Player.STATE_READY)
|
.waitForPlaybackState(Player.STATE_READY)
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilActionScheduleFinished(TIMEOUT_MS)
|
.blockUntilActionScheduleFinished(TIMEOUT_MS)
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertEquals(0, targetStartFirstPeriod.windowIndex);
|
assertThat(targetStartFirstPeriod.windowIndex).isEqualTo(0);
|
||||||
assertTrue(targetStartFirstPeriod.positionMs >= 0);
|
assertThat(targetStartFirstPeriod.positionMs).isAtLeast(0L);
|
||||||
assertEquals(0, targetEndMiddlePeriod.windowIndex);
|
assertThat(targetEndMiddlePeriod.windowIndex).isEqualTo(0);
|
||||||
assertTrue(targetEndMiddlePeriod.positionMs >= duration1Ms);
|
assertThat(targetEndMiddlePeriod.positionMs).isAtLeast(duration1Ms);
|
||||||
assertEquals(1, targetStartMiddlePeriod.windowIndex);
|
assertThat(targetStartMiddlePeriod.windowIndex).isEqualTo(1);
|
||||||
assertTrue(targetStartMiddlePeriod.positionMs >= 0);
|
assertThat(targetStartMiddlePeriod.positionMs).isAtLeast(0L);
|
||||||
assertEquals(1, targetEndLastPeriod.windowIndex);
|
assertThat(targetEndLastPeriod.windowIndex).isEqualTo(1);
|
||||||
assertTrue(targetEndLastPeriod.positionMs >= duration2Ms);
|
assertThat(targetEndLastPeriod.positionMs).isAtLeast(duration2Ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesSeekOnDeliveryTimeDuringPreparation() throws Exception {
|
public void testSendMessagesSeekOnDeliveryTimeDuringPreparation() throws Exception {
|
||||||
|
|
@ -1252,13 +1288,13 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.sendMessage(target, /* positionMs= */ 50)
|
.sendMessage(target, /* positionMs= */ 50)
|
||||||
.seek(/* positionMs= */ 50)
|
.seek(/* positionMs= */ 50)
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesSeekOnDeliveryTimeAfterPreparation() throws Exception {
|
public void testSendMessagesSeekOnDeliveryTimeAfterPreparation() throws Exception {
|
||||||
|
|
@ -1271,13 +1307,13 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.waitForTimelineChanged(timeline)
|
.waitForTimelineChanged(timeline)
|
||||||
.seek(/* positionMs= */ 50)
|
.seek(/* positionMs= */ 50)
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesSeekAfterDeliveryTimeDuringPreparation() throws Exception {
|
public void testSendMessagesSeekAfterDeliveryTimeDuringPreparation() throws Exception {
|
||||||
|
|
@ -1291,13 +1327,13 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.seek(/* positionMs= */ 51)
|
.seek(/* positionMs= */ 51)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertEquals(C.POSITION_UNSET, target.positionMs);
|
assertThat(target.positionMs).isEqualTo(C.POSITION_UNSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesSeekAfterDeliveryTimeAfterPreparation() throws Exception {
|
public void testSendMessagesSeekAfterDeliveryTimeAfterPreparation() throws Exception {
|
||||||
|
|
@ -1311,13 +1347,13 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.seek(/* positionMs= */ 51)
|
.seek(/* positionMs= */ 51)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertEquals(C.POSITION_UNSET, target.positionMs);
|
assertThat(target.positionMs).isEqualTo(C.POSITION_UNSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesRepeatDoesNotRepost() throws Exception {
|
public void testSendMessagesRepeatDoesNotRepost() throws Exception {
|
||||||
|
|
@ -1333,14 +1369,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.waitForPositionDiscontinuity()
|
.waitForPositionDiscontinuity()
|
||||||
.setRepeatMode(Player.REPEAT_MODE_OFF)
|
.setRepeatMode(Player.REPEAT_MODE_OFF)
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertEquals(1, target.messageCount);
|
assertThat(target.messageCount).isEqualTo(1);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesRepeatWithoutDeletingDoesRepost() throws Exception {
|
public void testSendMessagesRepeatWithoutDeletingDoesRepost() throws Exception {
|
||||||
|
|
@ -1361,14 +1397,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.setRepeatMode(Player.REPEAT_MODE_OFF)
|
.setRepeatMode(Player.REPEAT_MODE_OFF)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertEquals(2, target.messageCount);
|
assertThat(target.messageCount).isEqualTo(2);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesMoveCurrentWindowIndex() throws Exception {
|
public void testSendMessagesMoveCurrentWindowIndex() throws Exception {
|
||||||
|
|
@ -1395,14 +1431,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.waitForTimelineChanged(secondTimeline)
|
.waitForTimelineChanged(secondTimeline)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setMediaSource(mediaSource)
|
.setMediaSource(mediaSource)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
assertEquals(1, target.windowIndex);
|
assertThat(target.windowIndex).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesMultiWindowDuringPreparation() throws Exception {
|
public void testSendMessagesMultiWindowDuringPreparation() throws Exception {
|
||||||
|
|
@ -1415,14 +1451,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.sendMessage(target, /* windowIndex = */ 2, /* positionMs= */ 50)
|
.sendMessage(target, /* windowIndex = */ 2, /* positionMs= */ 50)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertEquals(2, target.windowIndex);
|
assertThat(target.windowIndex).isEqualTo(2);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesMultiWindowAfterPreparation() throws Exception {
|
public void testSendMessagesMultiWindowAfterPreparation() throws Exception {
|
||||||
|
|
@ -1435,14 +1471,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.sendMessage(target, /* windowIndex = */ 2, /* positionMs= */ 50)
|
.sendMessage(target, /* windowIndex = */ 2, /* positionMs= */ 50)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setTimeline(timeline)
|
.setTimeline(timeline)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertEquals(2, target.windowIndex);
|
assertThat(target.windowIndex).isEqualTo(2);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesMoveWindowIndex() throws Exception {
|
public void testSendMessagesMoveWindowIndex() throws Exception {
|
||||||
|
|
@ -1472,14 +1508,14 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.seek(/* windowIndex= */ 0, /* positionMs= */ 0)
|
.seek(/* windowIndex= */ 0, /* positionMs= */ 0)
|
||||||
.play()
|
.play()
|
||||||
.build();
|
.build();
|
||||||
new ExoPlayerTestRunner.Builder()
|
new Builder()
|
||||||
.setMediaSource(mediaSource)
|
.setMediaSource(mediaSource)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertTrue(target.positionMs >= 50);
|
assertThat(target.positionMs >= 50).isTrue();
|
||||||
assertEquals(0, target.windowIndex);
|
assertThat(target.windowIndex).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendMessagesNonLinearPeriodOrder() throws Exception {
|
public void testSendMessagesNonLinearPeriodOrder() throws Exception {
|
||||||
|
|
@ -1511,9 +1547,9 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
assertEquals(0, target1.windowIndex);
|
assertThat(target1.windowIndex).isEqualTo(0);
|
||||||
assertEquals(1, target2.windowIndex);
|
assertThat(target2.windowIndex).isEqualTo(1);
|
||||||
assertEquals(2, target3.windowIndex);
|
assertThat(target3.windowIndex).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetAndSwitchSurface() throws Exception {
|
public void testSetAndSwitchSurface() throws Exception {
|
||||||
|
|
@ -1535,7 +1571,7 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
.start()
|
.start()
|
||||||
.blockUntilActionScheduleFinished(TIMEOUT_MS)
|
.blockUntilActionScheduleFinished(TIMEOUT_MS)
|
||||||
.blockUntilEnded(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 {
|
public void testSwitchSurfaceOnEndedState() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,11 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.drm;
|
package com.google.android.exoplayer2.drm;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import android.test.MoreAsserts;
|
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
||||||
|
|
@ -86,7 +86,7 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
byte[] offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(newDrmInitData());
|
byte[] offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(newDrmInitData());
|
||||||
|
|
||||||
assertNull(offlineLicenseKeySetId);
|
assertThat(offlineLicenseKeySetId).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDownloadLicenseDoesNotFailIfDurationNotAvailable() throws Exception {
|
public void testDownloadLicenseDoesNotFailIfDurationNotAvailable() throws Exception {
|
||||||
|
|
@ -94,7 +94,7 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
byte[] offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(newDrmInitData());
|
byte[] offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(newDrmInitData());
|
||||||
|
|
||||||
assertNotNull(offlineLicenseKeySetId);
|
assertThat(offlineLicenseKeySetId).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetLicenseDurationRemainingSec() throws Exception {
|
public void testGetLicenseDurationRemainingSec() throws Exception {
|
||||||
|
|
@ -108,8 +108,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
||||||
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper
|
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper
|
||||||
.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
||||||
|
|
||||||
assertEquals(licenseDuration, (long) licenseDurationRemainingSec.first);
|
assertThat(licenseDurationRemainingSec.first).isEqualTo(licenseDuration);
|
||||||
assertEquals(playbackDuration, (long) licenseDurationRemainingSec.second);
|
assertThat(licenseDurationRemainingSec.second).isEqualTo(playbackDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetLicenseDurationRemainingSecExpiredLicense() throws Exception {
|
public void testGetLicenseDurationRemainingSecExpiredLicense() throws Exception {
|
||||||
|
|
@ -123,8 +123,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
||||||
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper
|
Pair<Long, Long> licenseDurationRemainingSec = offlineLicenseHelper
|
||||||
.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
||||||
|
|
||||||
assertEquals(licenseDuration, (long) licenseDurationRemainingSec.first);
|
assertThat(licenseDurationRemainingSec.first).isEqualTo(licenseDuration);
|
||||||
assertEquals(playbackDuration, (long) licenseDurationRemainingSec.second);
|
assertThat(licenseDurationRemainingSec.second).isEqualTo(playbackDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDefaultStubKeySetId()
|
private void setDefaultStubKeySetId()
|
||||||
|
|
@ -139,8 +139,8 @@ public class OfflineLicenseHelperTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
private static void assertOfflineLicenseKeySetIdEqual(
|
private static void assertOfflineLicenseKeySetIdEqual(
|
||||||
byte[] expectedKeySetId, byte[] actualKeySetId) throws Exception {
|
byte[] expectedKeySetId, byte[] actualKeySetId) throws Exception {
|
||||||
assertNotNull(actualKeySetId);
|
assertThat(actualKeySetId).isNotNull();
|
||||||
MoreAsserts.assertEquals(expectedKeySetId, actualKeySetId);
|
assertThat(actualKeySetId).isEqualTo(expectedKeySetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStubLicenseAndPlaybackDurationValues(long licenseDuration,
|
private void setStubLicenseAndPlaybackDurationValues(long licenseDuration,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.extractor.ogg;
|
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.C;
|
||||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
||||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||||
|
|
@ -60,28 +63,33 @@ public final class DefaultOggSeekerTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test granule 0 from file start
|
// Test granule 0 from file start
|
||||||
assertEquals(0, seekTo(input, oggSeeker, 0, 0));
|
assertThat(seekTo(input, oggSeeker, 0, 0)).isEqualTo(0);
|
||||||
assertEquals(0, input.getPosition());
|
assertThat(input.getPosition()).isEqualTo(0);
|
||||||
|
|
||||||
// Test granule 0 from file end
|
// Test granule 0 from file end
|
||||||
assertEquals(0, seekTo(input, oggSeeker, 0, testFile.data.length - 1));
|
assertThat(seekTo(input, oggSeeker, 0, testFile.data.length - 1)).isEqualTo(0);
|
||||||
assertEquals(0, input.getPosition());
|
assertThat(input.getPosition()).isEqualTo(0);
|
||||||
|
|
||||||
{ // Test last granule
|
{ // Test last granule
|
||||||
long currentGranule = seekTo(input, oggSeeker, testFile.lastGranule, 0);
|
long currentGranule = seekTo(input, oggSeeker, testFile.lastGranule, 0);
|
||||||
long position = testFile.data.length;
|
long position = testFile.data.length;
|
||||||
assertTrue((testFile.lastGranule > currentGranule && position > input.getPosition())
|
assertThat(
|
||||||
|| (testFile.lastGranule == currentGranule && position == input.getPosition()));
|
(testFile.lastGranule > currentGranule && position > input.getPosition())
|
||||||
|
|| (testFile.lastGranule == currentGranule && position == input.getPosition()))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Test exact granule
|
{ // Test exact granule
|
||||||
input.setPosition(testFile.data.length / 2);
|
input.setPosition(testFile.data.length / 2);
|
||||||
oggSeeker.skipToNextPage(input);
|
oggSeeker.skipToNextPage(input);
|
||||||
assertTrue(pageHeader.populate(input, true));
|
assertThat(pageHeader.populate(input, true)).isTrue();
|
||||||
long position = input.getPosition() + pageHeader.headerSize + pageHeader.bodySize;
|
long position = input.getPosition() + pageHeader.headerSize + pageHeader.bodySize;
|
||||||
long currentGranule = seekTo(input, oggSeeker, pageHeader.granulePosition, 0);
|
long currentGranule = seekTo(input, oggSeeker, pageHeader.granulePosition, 0);
|
||||||
assertTrue((pageHeader.granulePosition > currentGranule && position > input.getPosition())
|
assertThat(
|
||||||
|| (pageHeader.granulePosition == currentGranule && position == input.getPosition()));
|
(pageHeader.granulePosition > currentGranule && position > input.getPosition())
|
||||||
|
|| (pageHeader.granulePosition == currentGranule
|
||||||
|
&& position == input.getPosition()))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 100; i += 1) {
|
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 currentGranule = seekTo(input, oggSeeker, targetGranule, initialPosition);
|
||||||
long currentPosition = input.getPosition();
|
long currentPosition = input.getPosition();
|
||||||
|
|
||||||
assertTrue("getNextSeekPosition() didn't leave input on a page start.",
|
assertWithMessage("getNextSeekPosition() didn't leave input on a page start.")
|
||||||
pageHeader.populate(input, true));
|
.that(pageHeader.populate(input, true))
|
||||||
|
.isTrue();
|
||||||
|
|
||||||
if (currentGranule == 0) {
|
if (currentGranule == 0) {
|
||||||
assertEquals(0, currentPosition);
|
assertThat(currentPosition).isEqualTo(0);
|
||||||
} else {
|
} else {
|
||||||
int previousPageStart = testFile.findPreviousPageStart(currentPosition);
|
int previousPageStart = testFile.findPreviousPageStart(currentPosition);
|
||||||
input.setPosition(previousPageStart);
|
input.setPosition(previousPageStart);
|
||||||
assertTrue(pageHeader.populate(input, true));
|
assertThat(pageHeader.populate(input, true)).isTrue();
|
||||||
assertEquals(pageHeader.granulePosition, currentGranule);
|
assertThat(currentGranule).isEqualTo(pageHeader.granulePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
input.setPosition((int) currentPosition);
|
input.setPosition((int) currentPosition);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.extractor.ogg;
|
package com.google.android.exoplayer2.extractor.ogg;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.extractor.Extractor;
|
import com.google.android.exoplayer2.extractor.Extractor;
|
||||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||||
|
|
@ -56,44 +58,47 @@ public final class OggExtractorTest extends InstrumentationTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSniffVorbis() throws Exception {
|
public void testSniffVorbis() throws Exception {
|
||||||
byte[] data = TestUtil.joinByteArrays(
|
byte[] data =
|
||||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
TestUtil.joinByteArrays(
|
||||||
TestUtil.createByteArray(7), // Laces
|
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||||
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
|
TestUtil.createByteArray(7), // Laces
|
||||||
assertTrue(sniff(data));
|
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
|
||||||
|
assertThat(sniff(data)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSniffFlac() throws Exception {
|
public void testSniffFlac() throws Exception {
|
||||||
byte[] data = TestUtil.joinByteArrays(
|
byte[] data =
|
||||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
TestUtil.joinByteArrays(
|
||||||
TestUtil.createByteArray(5), // Laces
|
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||||
new byte[] {0x7F, 'F', 'L', 'A', 'C'});
|
TestUtil.createByteArray(5), // Laces
|
||||||
assertTrue(sniff(data));
|
new byte[] {0x7F, 'F', 'L', 'A', 'C'});
|
||||||
|
assertThat(sniff(data)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSniffFailsOpusFile() throws Exception {
|
public void testSniffFailsOpusFile() throws Exception {
|
||||||
byte[] data = TestUtil.joinByteArrays(
|
byte[] data =
|
||||||
OggTestData.buildOggHeader(0x02, 0, 1000, 0x00),
|
TestUtil.joinByteArrays(
|
||||||
new byte[] {'O', 'p', 'u', 's'});
|
OggTestData.buildOggHeader(0x02, 0, 1000, 0x00), new byte[] {'O', 'p', 'u', 's'});
|
||||||
assertFalse(sniff(data));
|
assertThat(sniff(data)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSniffFailsInvalidOggHeader() throws Exception {
|
public void testSniffFailsInvalidOggHeader() throws Exception {
|
||||||
byte[] data = OggTestData.buildOggHeader(0x00, 0, 1000, 0x00);
|
byte[] data = OggTestData.buildOggHeader(0x00, 0, 1000, 0x00);
|
||||||
assertFalse(sniff(data));
|
assertThat(sniff(data)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSniffInvalidHeader() throws Exception {
|
public void testSniffInvalidHeader() throws Exception {
|
||||||
byte[] data = TestUtil.joinByteArrays(
|
byte[] data =
|
||||||
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
TestUtil.joinByteArrays(
|
||||||
TestUtil.createByteArray(7), // Laces
|
OggTestData.buildOggHeader(0x02, 0, 1000, 1),
|
||||||
new byte[] {0x7F, 'X', 'o', 'r', 'b', 'i', 's'});
|
TestUtil.createByteArray(7), // Laces
|
||||||
assertFalse(sniff(data));
|
new byte[] {0x7F, 'X', 'o', 'r', 'b', 'i', 's'});
|
||||||
|
assertThat(sniff(data)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSniffFailsEOF() throws Exception {
|
public void testSniffFailsEOF() throws Exception {
|
||||||
byte[] data = OggTestData.buildOggHeader(0x02, 0, 1000, 0x00);
|
byte[] data = OggTestData.buildOggHeader(0x02, 0, 1000, 0x00);
|
||||||
assertFalse(sniff(data));
|
assertThat(sniff(data)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sniff(byte[] data) throws InterruptedException, IOException {
|
private boolean sniff(byte[] data) throws InterruptedException, IOException {
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.extractor.ogg;
|
package com.google.android.exoplayer2.extractor.ogg;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import android.test.MoreAsserts;
|
|
||||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
||||||
import com.google.android.exoplayer2.testutil.OggTestData;
|
import com.google.android.exoplayer2.testutil.OggTestData;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
|
|
@ -48,56 +49,58 @@ public final class OggPacketTest extends InstrumentationTestCase {
|
||||||
byte[] thirdPacket = TestUtil.buildTestData(256, random);
|
byte[] thirdPacket = TestUtil.buildTestData(256, random);
|
||||||
byte[] fourthPacket = TestUtil.buildTestData(271, random);
|
byte[] fourthPacket = TestUtil.buildTestData(271, random);
|
||||||
|
|
||||||
FakeExtractorInput input = OggTestData.createInput(
|
FakeExtractorInput input =
|
||||||
TestUtil.joinByteArrays(
|
OggTestData.createInput(
|
||||||
// First page with a single packet.
|
TestUtil.joinByteArrays(
|
||||||
OggTestData.buildOggHeader(0x02, 0, 1000, 0x01),
|
// First page with a single packet.
|
||||||
TestUtil.createByteArray(0x08), // Laces
|
OggTestData.buildOggHeader(0x02, 0, 1000, 0x01),
|
||||||
firstPacket,
|
TestUtil.createByteArray(0x08), // Laces
|
||||||
// Second page with a single packet.
|
firstPacket,
|
||||||
OggTestData.buildOggHeader(0x00, 16, 1001, 0x02),
|
// Second page with a single packet.
|
||||||
TestUtil.createByteArray(0xFF, 0x11), // Laces
|
OggTestData.buildOggHeader(0x00, 16, 1001, 0x02),
|
||||||
secondPacket,
|
TestUtil.createByteArray(0xFF, 0x11), // Laces
|
||||||
// Third page with zero packets.
|
secondPacket,
|
||||||
OggTestData.buildOggHeader(0x00, 16, 1002, 0x00),
|
// Third page with zero packets.
|
||||||
// Fourth page with two packets.
|
OggTestData.buildOggHeader(0x00, 16, 1002, 0x00),
|
||||||
OggTestData.buildOggHeader(0x04, 128, 1003, 0x04),
|
// Fourth page with two packets.
|
||||||
TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), // Laces
|
OggTestData.buildOggHeader(0x04, 128, 1003, 0x04),
|
||||||
thirdPacket,
|
TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), // Laces
|
||||||
fourthPacket), true);
|
thirdPacket,
|
||||||
|
fourthPacket),
|
||||||
|
true);
|
||||||
|
|
||||||
assertReadPacket(input, firstPacket);
|
assertReadPacket(input, firstPacket);
|
||||||
assertTrue((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isTrue();
|
||||||
assertFalse((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse();
|
||||||
assertEquals(0x02, oggPacket.getPageHeader().type);
|
assertThat(oggPacket.getPageHeader().type).isEqualTo(0x02);
|
||||||
assertEquals(27 + 1, oggPacket.getPageHeader().headerSize);
|
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 1);
|
||||||
assertEquals(8, oggPacket.getPageHeader().bodySize);
|
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(8);
|
||||||
assertEquals(0x00, oggPacket.getPageHeader().revision);
|
assertThat(oggPacket.getPageHeader().revision).isEqualTo(0x00);
|
||||||
assertEquals(1, oggPacket.getPageHeader().pageSegmentCount);
|
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(1);
|
||||||
assertEquals(1000, oggPacket.getPageHeader().pageSequenceNumber);
|
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1000);
|
||||||
assertEquals(4096, oggPacket.getPageHeader().streamSerialNumber);
|
assertThat(oggPacket.getPageHeader().streamSerialNumber).isEqualTo(4096);
|
||||||
assertEquals(0, oggPacket.getPageHeader().granulePosition);
|
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(0);
|
||||||
|
|
||||||
assertReadPacket(input, secondPacket);
|
assertReadPacket(input, secondPacket);
|
||||||
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
|
||||||
assertFalse((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse();
|
||||||
assertEquals(0, oggPacket.getPageHeader().type);
|
assertThat(oggPacket.getPageHeader().type).isEqualTo(0);
|
||||||
assertEquals(27 + 2, oggPacket.getPageHeader().headerSize);
|
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 2);
|
||||||
assertEquals(255 + 17, oggPacket.getPageHeader().bodySize);
|
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 17);
|
||||||
assertEquals(2, oggPacket.getPageHeader().pageSegmentCount);
|
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(2);
|
||||||
assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber);
|
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001);
|
||||||
assertEquals(16, oggPacket.getPageHeader().granulePosition);
|
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(16);
|
||||||
|
|
||||||
assertReadPacket(input, thirdPacket);
|
assertReadPacket(input, thirdPacket);
|
||||||
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
|
||||||
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
|
||||||
assertEquals(4, oggPacket.getPageHeader().type);
|
assertThat(oggPacket.getPageHeader().type).isEqualTo(4);
|
||||||
assertEquals(27 + 4, oggPacket.getPageHeader().headerSize);
|
assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 4);
|
||||||
assertEquals(255 + 1 + 255 + 16, oggPacket.getPageHeader().bodySize);
|
assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 1 + 255 + 16);
|
||||||
assertEquals(4, oggPacket.getPageHeader().pageSegmentCount);
|
assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(4);
|
||||||
// Page 1002 is empty, so current page is 1003.
|
// Page 1002 is empty, so current page is 1003.
|
||||||
assertEquals(1003, oggPacket.getPageHeader().pageSequenceNumber);
|
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003);
|
||||||
assertEquals(128, oggPacket.getPageHeader().granulePosition);
|
assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(128);
|
||||||
|
|
||||||
assertReadPacket(input, fourthPacket);
|
assertReadPacket(input, fourthPacket);
|
||||||
|
|
||||||
|
|
@ -135,9 +138,9 @@ public final class OggPacketTest extends InstrumentationTestCase {
|
||||||
Arrays.copyOfRange(firstPacket, 510, 510 + 8)), true);
|
Arrays.copyOfRange(firstPacket, 510, 510 + 8)), true);
|
||||||
|
|
||||||
assertReadPacket(input, firstPacket);
|
assertReadPacket(input, firstPacket);
|
||||||
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
|
||||||
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
|
||||||
assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber);
|
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001);
|
||||||
|
|
||||||
assertReadEof(input);
|
assertReadEof(input);
|
||||||
}
|
}
|
||||||
|
|
@ -165,9 +168,9 @@ public final class OggPacketTest extends InstrumentationTestCase {
|
||||||
Arrays.copyOfRange(firstPacket, 510 + 255 + 255, 510 + 255 + 255 + 8)), true);
|
Arrays.copyOfRange(firstPacket, 510 + 255 + 255, 510 + 255 + 255 + 8)), true);
|
||||||
|
|
||||||
assertReadPacket(input, firstPacket);
|
assertReadPacket(input, firstPacket);
|
||||||
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
|
assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
|
||||||
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
|
assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
|
||||||
assertEquals(1003, oggPacket.getPageHeader().pageSequenceNumber);
|
assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003);
|
||||||
|
|
||||||
assertReadEof(input);
|
assertReadEof(input);
|
||||||
}
|
}
|
||||||
|
|
@ -218,19 +221,19 @@ public final class OggPacketTest extends InstrumentationTestCase {
|
||||||
while (readPacket(input)) {
|
while (readPacket(input)) {
|
||||||
packetCounter++;
|
packetCounter++;
|
||||||
}
|
}
|
||||||
assertEquals(277, packetCounter);
|
assertThat(packetCounter).isEqualTo(277);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertReadPacket(FakeExtractorInput extractorInput, byte[] expected)
|
private void assertReadPacket(FakeExtractorInput extractorInput, byte[] expected)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
assertTrue(readPacket(extractorInput));
|
assertThat(readPacket(extractorInput)).isTrue();
|
||||||
ParsableByteArray payload = oggPacket.getPayload();
|
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)
|
private void assertReadEof(FakeExtractorInput extractorInput)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
assertFalse(readPacket(extractorInput));
|
assertThat(readPacket(extractorInput)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean readPacket(FakeExtractorInput input)
|
private boolean readPacket(FakeExtractorInput input)
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,12 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.extractor.ogg;
|
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.OggTestData;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates test data.
|
* Generates test data.
|
||||||
|
|
@ -119,7 +120,7 @@ import junit.framework.Assert;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Assert.fail();
|
fail();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.extractor.ts;
|
package com.google.android.exoplayer2.extractor.ts;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
|
@ -92,12 +94,11 @@ public final class TsExtractorTest extends InstrumentationTestCase {
|
||||||
readResult = tsExtractor.read(input, seekPositionHolder);
|
readResult = tsExtractor.read(input, seekPositionHolder);
|
||||||
}
|
}
|
||||||
CustomEsReader reader = factory.esReader;
|
CustomEsReader reader = factory.esReader;
|
||||||
assertEquals(2, reader.packetsRead);
|
assertThat(reader.packetsRead).isEqualTo(2);
|
||||||
TrackOutput trackOutput = reader.getTrackOutput();
|
TrackOutput trackOutput = reader.getTrackOutput();
|
||||||
assertTrue(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */));
|
assertThat(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */)).isTrue();
|
||||||
assertEquals(
|
assertThat(((FakeTrackOutput) trackOutput).format)
|
||||||
Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0),
|
.isEqualTo(Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0));
|
||||||
((FakeTrackOutput) trackOutput).format);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCustomInitialSectionReader() throws Exception {
|
public void testCustomInitialSectionReader() throws Exception {
|
||||||
|
|
@ -115,7 +116,7 @@ public final class TsExtractorTest extends InstrumentationTestCase {
|
||||||
while (readResult != Extractor.RESULT_END_OF_INPUT) {
|
while (readResult != Extractor.RESULT_END_OF_INPUT) {
|
||||||
readResult = tsExtractor.read(input, seekPositionHolder);
|
readResult = tsExtractor.read(input, seekPositionHolder);
|
||||||
}
|
}
|
||||||
assertEquals(1, factory.sdtReader.consumedSdts);
|
assertThat(factory.sdtReader.consumedSdts).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeJunkData(ByteArrayOutputStream out, int length) {
|
private static void writeJunkData(ByteArrayOutputStream out, int length) {
|
||||||
|
|
@ -145,7 +146,7 @@ public final class TsExtractorTest extends InstrumentationTestCase {
|
||||||
@Override
|
@Override
|
||||||
public SparseArray<TsPayloadReader> createInitialPayloadReaders() {
|
public SparseArray<TsPayloadReader> createInitialPayloadReaders() {
|
||||||
if (provideSdtReader) {
|
if (provideSdtReader) {
|
||||||
assertNull(sdtReader);
|
assertThat(sdtReader).isNull();
|
||||||
SparseArray<TsPayloadReader> mapping = new SparseArray<>();
|
SparseArray<TsPayloadReader> mapping = new SparseArray<>();
|
||||||
sdtReader = new SdtSectionReader();
|
sdtReader = new SdtSectionReader();
|
||||||
mapping.put(17, new SectionReader(sdtReader));
|
mapping.put(17, new SectionReader(sdtReader));
|
||||||
|
|
@ -226,21 +227,21 @@ public final class TsExtractorTest extends InstrumentationTestCase {
|
||||||
// original_network_id(16), reserved_future_use(8)
|
// original_network_id(16), reserved_future_use(8)
|
||||||
sectionData.skipBytes(11);
|
sectionData.skipBytes(11);
|
||||||
// Start of the service loop.
|
// 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)
|
// reserved_future_use(6), EIT_schedule_flag(1), EIT_present_following_flag(1)
|
||||||
sectionData.skipBytes(1);
|
sectionData.skipBytes(1);
|
||||||
// Assert there is only one service.
|
// Assert there is only one service.
|
||||||
// Remove running_status(3), free_CA_mode(1) from the descriptors_loop_length with the mask.
|
// 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) {
|
while (sectionData.bytesLeft() > 0) {
|
||||||
int descriptorTag = sectionData.readUnsignedByte();
|
int descriptorTag = sectionData.readUnsignedByte();
|
||||||
int descriptorLength = sectionData.readUnsignedByte();
|
int descriptorLength = sectionData.readUnsignedByte();
|
||||||
if (descriptorTag == 72 /* service descriptor */) {
|
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();
|
int serviceProviderNameLength = sectionData.readUnsignedByte();
|
||||||
assertEquals("Some provider", sectionData.readString(serviceProviderNameLength));
|
assertThat(sectionData.readString(serviceProviderNameLength)).isEqualTo("Some provider");
|
||||||
int serviceNameLength = sectionData.readUnsignedByte();
|
int serviceNameLength = sectionData.readUnsignedByte();
|
||||||
assertEquals("Some Channel", sectionData.readString(serviceNameLength));
|
assertThat(sectionData.readString(serviceNameLength)).isEqualTo("Some Channel");
|
||||||
} else {
|
} else {
|
||||||
sectionData.skipBytes(descriptorLength);
|
sectionData.skipBytes(descriptorLength);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source;
|
package com.google.android.exoplayer2.source;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Player;
|
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);
|
Timeline clippedTimeline = getClippedTimeline(timeline, 0, TEST_PERIOD_DURATION_US);
|
||||||
|
|
||||||
assertEquals(1, clippedTimeline.getWindowCount());
|
assertThat(clippedTimeline.getWindowCount()).isEqualTo(1);
|
||||||
assertEquals(1, clippedTimeline.getPeriodCount());
|
assertThat(clippedTimeline.getPeriodCount()).isEqualTo(1);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US, clippedTimeline.getWindow(0, window).getDurationUs());
|
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||||
assertEquals(TEST_PERIOD_DURATION_US, clippedTimeline.getPeriod(0, period).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US);
|
||||||
|
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||||
|
.isEqualTo(TEST_PERIOD_DURATION_US);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClippingUnseekableWindowThrows() throws IOException {
|
public void testClippingUnseekableWindowThrows() throws IOException {
|
||||||
|
|
@ -68,7 +72,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
||||||
getClippedTimeline(timeline, 1, TEST_PERIOD_DURATION_US);
|
getClippedTimeline(timeline, 1, TEST_PERIOD_DURATION_US);
|
||||||
fail("Expected clipping to fail.");
|
fail("Expected clipping to fail.");
|
||||||
} catch (IllegalClippingException e) {
|
} 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,
|
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
|
||||||
TEST_PERIOD_DURATION_US);
|
TEST_PERIOD_DURATION_US);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
|
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||||
clippedTimeline.getWindow(0, window).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
|
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||||
clippedTimeline.getPeriod(0, period).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClippingEnd() throws IOException {
|
public void testClippingEnd() throws IOException {
|
||||||
|
|
@ -88,10 +92,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
Timeline clippedTimeline = getClippedTimeline(timeline, 0,
|
Timeline clippedTimeline = getClippedTimeline(timeline, 0,
|
||||||
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
|
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||||
clippedTimeline.getWindow(0, window).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US,
|
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||||
clippedTimeline.getPeriod(0, period).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClippingStartAndEndInitial() throws IOException {
|
public void testClippingStartAndEndInitial() throws IOException {
|
||||||
|
|
@ -103,10 +107,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
|
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
|
||||||
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
|
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
|
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||||
clippedTimeline.getWindow(0, window).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
|
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||||
clippedTimeline.getPeriod(0, period).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClippingStartAndEnd() throws IOException {
|
public void testClippingStartAndEnd() throws IOException {
|
||||||
|
|
@ -114,10 +118,10 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
|
Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US,
|
||||||
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
|
TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 2);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
|
assertThat(clippedTimeline.getWindow(0, window).getDurationUs())
|
||||||
clippedTimeline.getWindow(0, window).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
|
||||||
assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3,
|
assertThat(clippedTimeline.getPeriod(0, period).getDurationUs())
|
||||||
clippedTimeline.getPeriod(0, period).getDurationUs());
|
.isEqualTo(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWindowAndPeriodIndices() throws IOException {
|
public void testWindowAndPeriodIndices() throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source;
|
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.C;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
|
|
@ -77,8 +79,9 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleMediaSources() throws IOException {
|
public void testMultipleMediaSources() throws IOException {
|
||||||
Timeline[] timelines = { createFakeTimeline(3, 111), createFakeTimeline(1, 222),
|
Timeline[] timelines = {
|
||||||
createFakeTimeline(3, 333) };
|
createFakeTimeline(3, 111), createFakeTimeline(1, 222), createFakeTimeline(3, 333)
|
||||||
|
};
|
||||||
Timeline timeline = getConcatenatedTimeline(false, timelines);
|
Timeline timeline = getConcatenatedTimeline(false, timelines);
|
||||||
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
||||||
TimelineAsserts.assertPeriodCounts(timeline, 3, 1, 3);
|
TimelineAsserts.assertPeriodCounts(timeline, 3, 1, 3);
|
||||||
|
|
@ -98,10 +101,10 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
||||||
C.INDEX_UNSET, 0, 1);
|
C.INDEX_UNSET, 0, 1);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
||||||
assertEquals(0, timeline.getFirstWindowIndex(false));
|
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
|
||||||
assertEquals(2, timeline.getLastWindowIndex(false));
|
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
|
||||||
assertEquals(2, timeline.getFirstWindowIndex(true));
|
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
|
||||||
assertEquals(0, timeline.getLastWindowIndex(true));
|
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
|
||||||
|
|
||||||
timeline = getConcatenatedTimeline(true, timelines);
|
timeline = getConcatenatedTimeline(true, timelines);
|
||||||
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
||||||
|
|
@ -117,8 +120,8 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
||||||
1, 2, C.INDEX_UNSET);
|
1, 2, C.INDEX_UNSET);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 1, 2, 0);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 1, 2, 0);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
|
||||||
assertEquals(0, timeline.getFirstWindowIndex(shuffled));
|
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(0);
|
||||||
assertEquals(2, timeline.getLastWindowIndex(shuffled));
|
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,9 +155,16 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
||||||
|
|
||||||
public void testEmptyTimelineMediaSources() throws IOException {
|
public void testEmptyTimelineMediaSources() throws IOException {
|
||||||
// Empty timelines in the front, back, and the middle (single and multiple in a row).
|
// 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[] timelines = {
|
||||||
Timeline.EMPTY, createFakeTimeline(2, 222), Timeline.EMPTY, createFakeTimeline(3, 333),
|
Timeline.EMPTY,
|
||||||
Timeline.EMPTY };
|
createFakeTimeline(1, 111),
|
||||||
|
Timeline.EMPTY,
|
||||||
|
Timeline.EMPTY,
|
||||||
|
createFakeTimeline(2, 222),
|
||||||
|
Timeline.EMPTY,
|
||||||
|
createFakeTimeline(3, 333),
|
||||||
|
Timeline.EMPTY
|
||||||
|
};
|
||||||
Timeline timeline = getConcatenatedTimeline(false, timelines);
|
Timeline timeline = getConcatenatedTimeline(false, timelines);
|
||||||
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
||||||
TimelineAsserts.assertPeriodCounts(timeline, 1, 2, 3);
|
TimelineAsserts.assertPeriodCounts(timeline, 1, 2, 3);
|
||||||
|
|
@ -174,10 +184,10 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
||||||
C.INDEX_UNSET, 0, 1);
|
C.INDEX_UNSET, 0, 1);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
||||||
assertEquals(0, timeline.getFirstWindowIndex(false));
|
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
|
||||||
assertEquals(2, timeline.getLastWindowIndex(false));
|
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
|
||||||
assertEquals(2, timeline.getFirstWindowIndex(true));
|
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
|
||||||
assertEquals(0, timeline.getLastWindowIndex(true));
|
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
|
||||||
|
|
||||||
timeline = getConcatenatedTimeline(true, timelines);
|
timeline = getConcatenatedTimeline(true, timelines);
|
||||||
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
|
||||||
|
|
@ -193,8 +203,8 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
||||||
1, 2, C.INDEX_UNSET);
|
1, 2, C.INDEX_UNSET);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 1, 2, 0);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 1, 2, 0);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
|
||||||
assertEquals(0, timeline.getFirstWindowIndex(shuffled));
|
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(0);
|
||||||
assertEquals(2, timeline.getLastWindowIndex(shuffled));
|
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source;
|
package com.google.android.exoplayer2.source;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.os.ConditionVariable;
|
import android.os.ConditionVariable;
|
||||||
|
|
@ -135,8 +136,8 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
C.INDEX_UNSET, 0, 1);
|
C.INDEX_UNSET, 0, 1);
|
||||||
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2);
|
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2);
|
||||||
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 2, 0, 1);
|
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 2, 0, 1);
|
||||||
assertEquals(0, timeline.getFirstWindowIndex(false));
|
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
|
||||||
assertEquals(timeline.getWindowCount() - 1, timeline.getLastWindowIndex(false));
|
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(timeline.getWindowCount() - 1);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, true,
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, true,
|
||||||
C.INDEX_UNSET, 0, 1);
|
C.INDEX_UNSET, 0, 1);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
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);
|
1, 2, C.INDEX_UNSET);
|
||||||
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||||
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 1, 2, 0);
|
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 1, 2, 0);
|
||||||
assertEquals(timeline.getWindowCount() - 1, timeline.getFirstWindowIndex(true));
|
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(timeline.getWindowCount() - 1);
|
||||||
assertEquals(0, timeline.getLastWindowIndex(true));
|
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
|
||||||
|
|
||||||
// Assert all periods can be prepared.
|
// Assert all periods can be prepared.
|
||||||
testRunner.assertPrepareAndReleaseAllPeriods();
|
testRunner.assertPrepareAndReleaseAllPeriods();
|
||||||
|
|
@ -258,7 +259,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
// called yet.
|
// called yet.
|
||||||
MediaPeriod lazyPeriod = testRunner.createPeriod(new MediaPeriodId(0));
|
MediaPeriod lazyPeriod = testRunner.createPeriod(new MediaPeriodId(0));
|
||||||
ConditionVariable preparedCondition = testRunner.preparePeriod(lazyPeriod, 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.
|
// Assert that a second period can also be created and released without problems.
|
||||||
MediaPeriod secondLazyPeriod = testRunner.createPeriod(new MediaPeriodId(0));
|
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.assertPeriodCounts(timeline, 8, 1, 2, 9);
|
||||||
TimelineAsserts.assertWindowIds(timeline, 888, 111, 222, 999);
|
TimelineAsserts.assertWindowIds(timeline, 888, 111, 222, 999);
|
||||||
TimelineAsserts.assertWindowIsDynamic(timeline, false, false, false, false);
|
TimelineAsserts.assertWindowIsDynamic(timeline, false, false, false, false);
|
||||||
assertTrue(preparedCondition.block(1));
|
assertThat(preparedCondition.block(1)).isTrue();
|
||||||
|
|
||||||
// Release the period and source.
|
// Release the period and source.
|
||||||
testRunner.releasePeriod(lazyPeriod);
|
testRunner.releasePeriod(lazyPeriod);
|
||||||
|
|
@ -299,11 +300,13 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
timeline = testRunner.assertTimelineChangeBlocking();
|
timeline = testRunner.assertTimelineChangeBlocking();
|
||||||
TimelineAsserts.assertEmpty(timeline);
|
TimelineAsserts.assertEmpty(timeline);
|
||||||
|
|
||||||
mediaSource.addMediaSources(Arrays.asList(new MediaSource[] {
|
mediaSource.addMediaSources(
|
||||||
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null),
|
Arrays.asList(
|
||||||
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null),
|
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),
|
||||||
|
new FakeMediaSource(Timeline.EMPTY, null), new FakeMediaSource(Timeline.EMPTY, null)
|
||||||
|
}));
|
||||||
timeline = testRunner.assertTimelineChangeBlocking();
|
timeline = testRunner.assertTimelineChangeBlocking();
|
||||||
TimelineAsserts.assertEmpty(timeline);
|
TimelineAsserts.assertEmpty(timeline);
|
||||||
|
|
||||||
|
|
@ -334,10 +337,10 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
C.INDEX_UNSET, 0, 1);
|
C.INDEX_UNSET, 0, 1);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
|
||||||
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
|
||||||
assertEquals(0, timeline.getFirstWindowIndex(false));
|
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
|
||||||
assertEquals(2, timeline.getLastWindowIndex(false));
|
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
|
||||||
assertEquals(2, timeline.getFirstWindowIndex(true));
|
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
|
||||||
assertEquals(0, timeline.getLastWindowIndex(true));
|
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
|
||||||
testRunner.assertPrepareAndReleaseAllPeriods();
|
testRunner.assertPrepareAndReleaseAllPeriods();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -439,7 +442,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||||
assertEquals(1, timeline.getWindowCount());
|
assertThat(timeline.getWindowCount()).isEqualTo(1);
|
||||||
} finally {
|
} finally {
|
||||||
dummyMainThread.release();
|
dummyMainThread.release();
|
||||||
}
|
}
|
||||||
|
|
@ -450,16 +453,18 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
try {
|
try {
|
||||||
testRunner.prepareSource();
|
testRunner.prepareSource();
|
||||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||||
dummyMainThread.runOnMainThread(new Runnable() {
|
dummyMainThread.runOnMainThread(
|
||||||
@Override
|
new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
mediaSource.addMediaSources(
|
public void run() {
|
||||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
mediaSource.addMediaSources(
|
||||||
timelineGrabber);
|
Arrays.asList(
|
||||||
}
|
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||||
});
|
timelineGrabber);
|
||||||
|
}
|
||||||
|
});
|
||||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||||
assertEquals(2, timeline.getWindowCount());
|
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||||
} finally {
|
} finally {
|
||||||
dummyMainThread.release();
|
dummyMainThread.release();
|
||||||
}
|
}
|
||||||
|
|
@ -477,7 +482,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||||
assertEquals(1, timeline.getWindowCount());
|
assertThat(timeline.getWindowCount()).isEqualTo(1);
|
||||||
} finally {
|
} finally {
|
||||||
dummyMainThread.release();
|
dummyMainThread.release();
|
||||||
}
|
}
|
||||||
|
|
@ -488,16 +493,19 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
try {
|
try {
|
||||||
testRunner.prepareSource();
|
testRunner.prepareSource();
|
||||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||||
dummyMainThread.runOnMainThread(new Runnable() {
|
dummyMainThread.runOnMainThread(
|
||||||
@Override
|
new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
mediaSource.addMediaSources(/* index */ 0,
|
public void run() {
|
||||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
mediaSource.addMediaSources(
|
||||||
timelineGrabber);
|
/* index */ 0,
|
||||||
}
|
Arrays.asList(
|
||||||
});
|
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||||
|
timelineGrabber);
|
||||||
|
}
|
||||||
|
});
|
||||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||||
assertEquals(2, timeline.getWindowCount());
|
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||||
} finally {
|
} finally {
|
||||||
dummyMainThread.release();
|
dummyMainThread.release();
|
||||||
}
|
}
|
||||||
|
|
@ -523,7 +531,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||||
assertEquals(0, timeline.getWindowCount());
|
assertThat(timeline.getWindowCount()).isEqualTo(0);
|
||||||
} finally {
|
} finally {
|
||||||
dummyMainThread.release();
|
dummyMainThread.release();
|
||||||
}
|
}
|
||||||
|
|
@ -533,13 +541,15 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||||
try {
|
try {
|
||||||
testRunner.prepareSource();
|
testRunner.prepareSource();
|
||||||
dummyMainThread.runOnMainThread(new Runnable() {
|
dummyMainThread.runOnMainThread(
|
||||||
@Override
|
new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
mediaSource.addMediaSources(Arrays.asList(
|
public void run() {
|
||||||
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
mediaSource.addMediaSources(
|
||||||
}
|
Arrays.asList(
|
||||||
});
|
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
||||||
|
}
|
||||||
|
});
|
||||||
testRunner.assertTimelineChangeBlocking();
|
testRunner.assertTimelineChangeBlocking();
|
||||||
|
|
||||||
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
|
||||||
|
|
@ -551,7 +561,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
|
||||||
assertEquals(2, timeline.getWindowCount());
|
assertThat(timeline.getWindowCount()).isEqualTo(2);
|
||||||
} finally {
|
} finally {
|
||||||
dummyMainThread.release();
|
dummyMainThread.release();
|
||||||
}
|
}
|
||||||
|
|
@ -624,7 +634,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
finishedCondition.open();
|
finishedCondition.open();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertTrue(finishedCondition.block(MediaSourceTestRunner.TIMEOUT_MS));
|
assertThat(finishedCondition.block(MediaSourceTestRunner.TIMEOUT_MS)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void release() {
|
public void release() {
|
||||||
|
|
@ -657,7 +667,7 @@ public final class DynamicConcatenatingMediaSourceTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timeline assertTimelineChangeBlocking() {
|
public Timeline assertTimelineChangeBlocking() {
|
||||||
assertTrue(finishedCondition.block(MediaSourceTestRunner.TIMEOUT_MS));
|
assertThat(finishedCondition.block(MediaSourceTestRunner.TIMEOUT_MS)).isTrue();
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source;
|
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.C;
|
||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
import com.google.android.exoplayer2.source.MergingMediaSource.IllegalMergeException;
|
import com.google.android.exoplayer2.source.MergingMediaSource.IllegalMergeException;
|
||||||
|
|
@ -53,7 +55,7 @@ public class MergingMediaSourceTest extends TestCase {
|
||||||
testMergingMediaSourcePrepare(firstTimeline, secondTimeline);
|
testMergingMediaSourcePrepare(firstTimeline, secondTimeline);
|
||||||
fail("Expected merging to fail.");
|
fail("Expected merging to fail.");
|
||||||
} catch (IllegalMergeException e) {
|
} 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 {
|
try {
|
||||||
Timeline timeline = testRunner.prepareSource();
|
Timeline timeline = testRunner.prepareSource();
|
||||||
// The merged timeline should always be the one from the first child.
|
// The merged timeline should always be the one from the first child.
|
||||||
assertEquals(timelines[0], timeline);
|
assertThat(timeline).isEqualTo(timelines[0]);
|
||||||
} finally {
|
} finally {
|
||||||
testRunner.release();
|
testRunner.release();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.text.ssa;
|
package com.google.android.exoplayer2.text.ssa;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -38,8 +40,8 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY);
|
||||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(0, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(0);
|
||||||
assertTrue(subtitle.getCues(0).isEmpty());
|
assertThat(subtitle.getCues(0).isEmpty()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDecodeTypical() throws IOException {
|
public void testDecodeTypical() throws IOException {
|
||||||
|
|
@ -47,7 +49,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL);
|
||||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(6, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||||
assertTypicalCue1(subtitle, 0);
|
assertTypicalCue1(subtitle, 0);
|
||||||
assertTypicalCue2(subtitle, 2);
|
assertTypicalCue2(subtitle, 2);
|
||||||
assertTypicalCue3(subtitle, 4);
|
assertTypicalCue3(subtitle, 4);
|
||||||
|
|
@ -63,7 +65,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_DIALOGUE_ONLY);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_DIALOGUE_ONLY);
|
||||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(6, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||||
assertTypicalCue1(subtitle, 0);
|
assertTypicalCue1(subtitle, 0);
|
||||||
assertTypicalCue2(subtitle, 2);
|
assertTypicalCue2(subtitle, 2);
|
||||||
assertTypicalCue3(subtitle, 4);
|
assertTypicalCue3(subtitle, 4);
|
||||||
|
|
@ -75,7 +77,7 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), INVALID_TIMECODES);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), INVALID_TIMECODES);
|
||||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(2, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||||
assertTypicalCue3(subtitle, 0);
|
assertTypicalCue3(subtitle, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,40 +86,40 @@ public final class SsaDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES);
|
||||||
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(3, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(3);
|
||||||
|
|
||||||
assertEquals(0, subtitle.getEventTime(0));
|
assertThat(subtitle.getEventTime(0)).isEqualTo(0);
|
||||||
assertEquals("This is the first subtitle.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString())
|
||||||
subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
|
.isEqualTo("This is the first subtitle.");
|
||||||
|
|
||||||
assertEquals(2340000, subtitle.getEventTime(1));
|
assertThat(subtitle.getEventTime(1)).isEqualTo(2340000);
|
||||||
assertEquals("This is the second subtitle \nwith a newline \nand another.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString())
|
||||||
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));
|
assertThat(subtitle.getEventTime(2)).isEqualTo(4560000);
|
||||||
assertEquals("This is the third subtitle, with a comma.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString())
|
||||||
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) {
|
private static void assertTypicalCue1(SsaSubtitle subtitle, int eventIndex) {
|
||||||
assertEquals(0, subtitle.getEventTime(eventIndex));
|
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(0);
|
||||||
assertEquals("This is the first subtitle.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
.isEqualTo("This is the first subtitle.");
|
||||||
assertEquals(1230000, subtitle.getEventTime(eventIndex + 1));
|
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(1230000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertTypicalCue2(SsaSubtitle subtitle, int eventIndex) {
|
private static void assertTypicalCue2(SsaSubtitle subtitle, int eventIndex) {
|
||||||
assertEquals(2340000, subtitle.getEventTime(eventIndex));
|
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(2340000);
|
||||||
assertEquals("This is the second subtitle \nwith a newline \nand another.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
.isEqualTo("This is the second subtitle \nwith a newline \nand another.");
|
||||||
assertEquals(3450000, subtitle.getEventTime(eventIndex + 1));
|
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(3450000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertTypicalCue3(SsaSubtitle subtitle, int eventIndex) {
|
private static void assertTypicalCue3(SsaSubtitle subtitle, int eventIndex) {
|
||||||
assertEquals(4560000, subtitle.getEventTime(eventIndex));
|
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(4560000);
|
||||||
assertEquals("This is the third subtitle, with a comma.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
.isEqualTo("This is the third subtitle, with a comma.");
|
||||||
assertEquals(8900000, subtitle.getEventTime(eventIndex + 1));
|
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(8900000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.text.subrip;
|
package com.google.android.exoplayer2.text.subrip;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -39,8 +41,8 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY_FILE);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY_FILE);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(0, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(0);
|
||||||
assertTrue(subtitle.getCues(0).isEmpty());
|
assertThat(subtitle.getCues(0).isEmpty()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDecodeTypical() throws IOException {
|
public void testDecodeTypical() throws IOException {
|
||||||
|
|
@ -48,7 +50,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_FILE);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_FILE);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(6, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||||
assertTypicalCue1(subtitle, 0);
|
assertTypicalCue1(subtitle, 0);
|
||||||
assertTypicalCue2(subtitle, 2);
|
assertTypicalCue2(subtitle, 2);
|
||||||
assertTypicalCue3(subtitle, 4);
|
assertTypicalCue3(subtitle, 4);
|
||||||
|
|
@ -59,7 +61,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_WITH_BYTE_ORDER_MARK);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_WITH_BYTE_ORDER_MARK);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(6, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||||
assertTypicalCue1(subtitle, 0);
|
assertTypicalCue1(subtitle, 0);
|
||||||
assertTypicalCue2(subtitle, 2);
|
assertTypicalCue2(subtitle, 2);
|
||||||
assertTypicalCue3(subtitle, 4);
|
assertTypicalCue3(subtitle, 4);
|
||||||
|
|
@ -70,7 +72,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_EXTRA_BLANK_LINE);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_EXTRA_BLANK_LINE);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(6, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||||
assertTypicalCue1(subtitle, 0);
|
assertTypicalCue1(subtitle, 0);
|
||||||
assertTypicalCue2(subtitle, 2);
|
assertTypicalCue2(subtitle, 2);
|
||||||
assertTypicalCue3(subtitle, 4);
|
assertTypicalCue3(subtitle, 4);
|
||||||
|
|
@ -82,7 +84,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_TIMECODE);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_TIMECODE);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
assertTypicalCue1(subtitle, 0);
|
assertTypicalCue1(subtitle, 0);
|
||||||
assertTypicalCue3(subtitle, 2);
|
assertTypicalCue3(subtitle, 2);
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +95,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_SEQUENCE);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_SEQUENCE);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
assertTypicalCue1(subtitle, 0);
|
assertTypicalCue1(subtitle, 0);
|
||||||
assertTypicalCue3(subtitle, 2);
|
assertTypicalCue3(subtitle, 2);
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +106,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_NEGATIVE_TIMESTAMPS);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_NEGATIVE_TIMESTAMPS);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(2, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||||
assertTypicalCue3(subtitle, 0);
|
assertTypicalCue3(subtitle, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +116,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_UNEXPECTED_END);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_UNEXPECTED_END);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
assertTypicalCue1(subtitle, 0);
|
assertTypicalCue1(subtitle, 0);
|
||||||
assertTypicalCue2(subtitle, 2);
|
assertTypicalCue2(subtitle, 2);
|
||||||
}
|
}
|
||||||
|
|
@ -124,40 +126,40 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE);
|
||||||
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
|
|
||||||
assertEquals(3, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(3);
|
||||||
|
|
||||||
assertEquals(0, subtitle.getEventTime(0));
|
assertThat(subtitle.getEventTime(0)).isEqualTo(0);
|
||||||
assertEquals("SubRip doesn't technically allow missing end timecodes.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString())
|
||||||
subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
|
.isEqualTo("SubRip doesn't technically allow missing end timecodes.");
|
||||||
|
|
||||||
assertEquals(2345000, subtitle.getEventTime(1));
|
assertThat(subtitle.getEventTime(1)).isEqualTo(2345000);
|
||||||
assertEquals("We interpret it to mean that a subtitle extends to the start of the next one.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString())
|
||||||
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));
|
assertThat(subtitle.getEventTime(2)).isEqualTo(3456000);
|
||||||
assertEquals("Or to the end of the media.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString())
|
||||||
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) {
|
private static void assertTypicalCue1(SubripSubtitle subtitle, int eventIndex) {
|
||||||
assertEquals(0, subtitle.getEventTime(eventIndex));
|
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(0);
|
||||||
assertEquals("This is the first subtitle.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
.isEqualTo("This is the first subtitle.");
|
||||||
assertEquals(1234000, subtitle.getEventTime(eventIndex + 1));
|
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(1234000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertTypicalCue2(SubripSubtitle subtitle, int eventIndex) {
|
private static void assertTypicalCue2(SubripSubtitle subtitle, int eventIndex) {
|
||||||
assertEquals(2345000, subtitle.getEventTime(eventIndex));
|
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(2345000);
|
||||||
assertEquals("This is the second subtitle.\nSecond subtitle with second line.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
.isEqualTo("This is the second subtitle.\nSecond subtitle with second line.");
|
||||||
assertEquals(3456000, subtitle.getEventTime(eventIndex + 1));
|
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(3456000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertTypicalCue3(SubripSubtitle subtitle, int eventIndex) {
|
private static void assertTypicalCue3(SubripSubtitle subtitle, int eventIndex) {
|
||||||
assertEquals(4567000, subtitle.getEventTime(eventIndex));
|
assertThat(subtitle.getEventTime(eventIndex)).isEqualTo(4567000);
|
||||||
assertEquals("This is the third subtitle.",
|
assertThat(subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString())
|
||||||
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
|
.isEqualTo("This is the third subtitle.");
|
||||||
assertEquals(8901000, subtitle.getEventTime(eventIndex + 1));
|
assertThat(subtitle.getEventTime(eventIndex + 1)).isEqualTo(8901000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.text.ttml;
|
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.test.InstrumentationTestCase;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
|
|
@ -61,23 +64,23 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
public void testInlineAttributes() throws IOException, SubtitleDecoderException {
|
public void testInlineAttributes() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
|
|
||||||
TtmlNode root = subtitle.getRoot();
|
TtmlNode root = subtitle.getRoot();
|
||||||
|
|
||||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||||
TtmlNode firstDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0);
|
TtmlNode firstDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0);
|
||||||
TtmlStyle firstPStyle = queryChildrenForTag(firstDiv, TtmlNode.TAG_P, 0).style;
|
TtmlStyle firstPStyle = queryChildrenForTag(firstDiv, TtmlNode.TAG_P, 0).style;
|
||||||
assertEquals(ColorParser.parseTtmlColor("yellow"), firstPStyle.getFontColor());
|
assertThat(firstPStyle.getFontColor()).isEqualTo(ColorParser.parseTtmlColor("yellow"));
|
||||||
assertEquals(ColorParser.parseTtmlColor("blue"), firstPStyle.getBackgroundColor());
|
assertThat(firstPStyle.getBackgroundColor()).isEqualTo(ColorParser.parseTtmlColor("blue"));
|
||||||
assertEquals("serif", firstPStyle.getFontFamily());
|
assertThat(firstPStyle.getFontFamily()).isEqualTo("serif");
|
||||||
assertEquals(TtmlStyle.STYLE_BOLD_ITALIC, firstPStyle.getStyle());
|
assertThat(firstPStyle.getStyle()).isEqualTo(TtmlStyle.STYLE_BOLD_ITALIC);
|
||||||
assertTrue(firstPStyle.isUnderline());
|
assertThat(firstPStyle.isUnderline()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritInlineAttributes() throws IOException, SubtitleDecoderException {
|
public void testInheritInlineAttributes() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
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,
|
assertSpans(subtitle, 20, "text 2", "sansSerif", TtmlStyle.STYLE_ITALIC,
|
||||||
0xFF00FFFF, ColorParser.parseTtmlColor("lime"), false, true, null);
|
0xFF00FFFF, ColorParser.parseTtmlColor("lime"), false, true, null);
|
||||||
}
|
}
|
||||||
|
|
@ -95,14 +98,14 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
*/
|
*/
|
||||||
public void testLime() throws IOException, SubtitleDecoderException {
|
public void testLime() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
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,
|
assertSpans(subtitle, 20, "text 2", "sansSerif", TtmlStyle.STYLE_ITALIC, 0xFF00FFFF, 0xFF00FF00,
|
||||||
false, true, null);
|
false, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritGlobalStyle() throws IOException, SubtitleDecoderException {
|
public void testInheritGlobalStyle() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_STYLE_TTML_FILE);
|
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,
|
assertSpans(subtitle, 10, "text 1", "serif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF,
|
||||||
0xFFFFFF00, true, false, null);
|
0xFFFFFF00, true, false, null);
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +113,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
public void testInheritGlobalStyleOverriddenByInlineAttributes() throws IOException,
|
public void testInheritGlobalStyleOverriddenByInlineAttributes() throws IOException,
|
||||||
SubtitleDecoderException {
|
SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_STYLE_OVERRIDE_TTML_FILE);
|
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,
|
assertSpans(subtitle, 10, "text 1", "serif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF,
|
||||||
0xFFFFFF00, true, false, null);
|
0xFFFFFF00, true, false, null);
|
||||||
|
|
@ -120,7 +123,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
public void testInheritGlobalAndParent() throws IOException, SubtitleDecoderException {
|
public void testInheritGlobalAndParent() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_GLOBAL_AND_PARENT_TTML_FILE);
|
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,
|
assertSpans(subtitle, 10, "text 1", "sansSerif", TtmlStyle.STYLE_NORMAL, 0xFFFF0000,
|
||||||
ColorParser.parseTtmlColor("lime"), false, true, Layout.Alignment.ALIGN_CENTER);
|
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 {
|
public void testInheritMultipleStyles() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
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,
|
assertSpans(subtitle, 10, "text 1", "sansSerif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF,
|
||||||
0xFFFFFF00, false, true, null);
|
0xFFFFFF00, false, true, null);
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +141,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
public void testInheritMultipleStylesWithoutLocalAttributes() throws IOException,
|
public void testInheritMultipleStylesWithoutLocalAttributes() throws IOException,
|
||||||
SubtitleDecoderException {
|
SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
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,
|
assertSpans(subtitle, 20, "text 2", "sansSerif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF,
|
||||||
0xFF000000, false, true, null);
|
0xFF000000, false, true, null);
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +149,7 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
public void testMergeMultipleStylesWithParentStyle() throws IOException,
|
public void testMergeMultipleStylesWithParentStyle() throws IOException,
|
||||||
SubtitleDecoderException {
|
SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
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,
|
assertSpans(subtitle, 30, "text 2.5", "sansSerifInline", TtmlStyle.STYLE_ITALIC, 0xFFFF0000,
|
||||||
0xFFFFFF00, true, true, null);
|
0xFFFFFF00, true, true, null);
|
||||||
}
|
}
|
||||||
|
|
@ -154,231 +157,232 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
public void testMultipleRegions() throws IOException, SubtitleDecoderException {
|
public void testMultipleRegions() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(MULTIPLE_REGIONS_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(MULTIPLE_REGIONS_TTML_FILE);
|
||||||
List<Cue> output = subtitle.getCues(1000000);
|
List<Cue> output = subtitle.getCues(1000000);
|
||||||
assertEquals(2, output.size());
|
assertThat(output).hasSize(2);
|
||||||
Cue ttmlCue = output.get(0);
|
Cue ttmlCue = output.get(0);
|
||||||
assertEquals("lorem", ttmlCue.text.toString());
|
assertThat(ttmlCue.text.toString()).isEqualTo("lorem");
|
||||||
assertEquals(10f / 100f, ttmlCue.position);
|
assertThat(ttmlCue.position).isEqualTo(10f / 100f);
|
||||||
assertEquals(10f / 100f, ttmlCue.line);
|
assertThat(ttmlCue.line).isEqualTo(10f / 100f);
|
||||||
assertEquals(20f / 100f, ttmlCue.size);
|
assertThat(ttmlCue.size).isEqualTo(20f / 100f);
|
||||||
|
|
||||||
ttmlCue = output.get(1);
|
ttmlCue = output.get(1);
|
||||||
assertEquals("amet", ttmlCue.text.toString());
|
assertThat(ttmlCue.text.toString()).isEqualTo("amet");
|
||||||
assertEquals(60f / 100f, ttmlCue.position);
|
assertThat(ttmlCue.position).isEqualTo(60f / 100f);
|
||||||
assertEquals(10f / 100f, ttmlCue.line);
|
assertThat(ttmlCue.line).isEqualTo(10f / 100f);
|
||||||
assertEquals(20f / 100f, ttmlCue.size);
|
assertThat(ttmlCue.size).isEqualTo(20f / 100f);
|
||||||
|
|
||||||
output = subtitle.getCues(5000000);
|
output = subtitle.getCues(5000000);
|
||||||
assertEquals(1, output.size());
|
assertThat(output).hasSize(1);
|
||||||
ttmlCue = output.get(0);
|
ttmlCue = output.get(0);
|
||||||
assertEquals("ipsum", ttmlCue.text.toString());
|
assertThat(ttmlCue.text.toString()).isEqualTo("ipsum");
|
||||||
assertEquals(40f / 100f, ttmlCue.position);
|
assertThat(ttmlCue.position).isEqualTo(40f / 100f);
|
||||||
assertEquals(40f / 100f, ttmlCue.line);
|
assertThat(ttmlCue.line).isEqualTo(40f / 100f);
|
||||||
assertEquals(20f / 100f, ttmlCue.size);
|
assertThat(ttmlCue.size).isEqualTo(20f / 100f);
|
||||||
|
|
||||||
output = subtitle.getCues(9000000);
|
output = subtitle.getCues(9000000);
|
||||||
assertEquals(1, output.size());
|
assertThat(output).hasSize(1);
|
||||||
ttmlCue = output.get(0);
|
ttmlCue = output.get(0);
|
||||||
assertEquals("dolor", ttmlCue.text.toString());
|
assertThat(ttmlCue.text.toString()).isEqualTo("dolor");
|
||||||
assertEquals(Cue.DIMEN_UNSET, ttmlCue.position);
|
assertThat(ttmlCue.position).isEqualTo(Cue.DIMEN_UNSET);
|
||||||
assertEquals(Cue.DIMEN_UNSET, ttmlCue.line);
|
assertThat(ttmlCue.line).isEqualTo(Cue.DIMEN_UNSET);
|
||||||
assertEquals(Cue.DIMEN_UNSET, ttmlCue.size);
|
assertThat(ttmlCue.size).isEqualTo(Cue.DIMEN_UNSET);
|
||||||
// TODO: Should be as below, once https://github.com/google/ExoPlayer/issues/2953 is fixed.
|
// TODO: Should be as below, once https://github.com/google/ExoPlayer/issues/2953 is fixed.
|
||||||
// assertEquals(10f / 100f, ttmlCue.position);
|
// assertEquals(10f / 100f, ttmlCue.position);
|
||||||
// assertEquals(80f / 100f, ttmlCue.line);
|
// assertEquals(80f / 100f, ttmlCue.line);
|
||||||
// assertEquals(1f, ttmlCue.size);
|
// assertEquals(1f, ttmlCue.size);
|
||||||
|
|
||||||
output = subtitle.getCues(21000000);
|
output = subtitle.getCues(21000000);
|
||||||
assertEquals(1, output.size());
|
assertThat(output).hasSize(1);
|
||||||
ttmlCue = output.get(0);
|
ttmlCue = output.get(0);
|
||||||
assertEquals("She first said this", ttmlCue.text.toString());
|
assertThat(ttmlCue.text.toString()).isEqualTo("She first said this");
|
||||||
assertEquals(45f / 100f, ttmlCue.position);
|
assertThat(ttmlCue.position).isEqualTo(45f / 100f);
|
||||||
assertEquals(45f / 100f, ttmlCue.line);
|
assertThat(ttmlCue.line).isEqualTo(45f / 100f);
|
||||||
assertEquals(35f / 100f, ttmlCue.size);
|
assertThat(ttmlCue.size).isEqualTo(35f / 100f);
|
||||||
output = subtitle.getCues(25000000);
|
output = subtitle.getCues(25000000);
|
||||||
ttmlCue = output.get(0);
|
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);
|
output = subtitle.getCues(29000000);
|
||||||
assertEquals(1, output.size());
|
assertThat(output).hasSize(1);
|
||||||
ttmlCue = output.get(0);
|
ttmlCue = output.get(0);
|
||||||
assertEquals("She first said this\nThen this\nFinally this", ttmlCue.text.toString());
|
assertThat(ttmlCue.text.toString()).isEqualTo("She first said this\nThen this\nFinally this");
|
||||||
assertEquals(45f / 100f, ttmlCue.position);
|
assertThat(ttmlCue.position).isEqualTo(45f / 100f);
|
||||||
assertEquals(45f / 100f, ttmlCue.line);
|
assertThat(ttmlCue.line).isEqualTo(45f / 100f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyStyleAttribute() throws IOException, SubtitleDecoderException {
|
public void testEmptyStyleAttribute() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||||
assertEquals(12, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||||
|
|
||||||
TtmlNode root = subtitle.getRoot();
|
TtmlNode root = subtitle.getRoot();
|
||||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||||
TtmlNode fourthDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 3);
|
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 {
|
public void testNonexistingStyleId() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||||
assertEquals(12, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||||
|
|
||||||
TtmlNode root = subtitle.getRoot();
|
TtmlNode root = subtitle.getRoot();
|
||||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||||
TtmlNode fifthDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 4);
|
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,
|
public void testNonExistingAndExistingStyleIdWithRedundantSpaces() throws IOException,
|
||||||
SubtitleDecoderException {
|
SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(INHERIT_MULTIPLE_STYLES_TTML_FILE);
|
||||||
assertEquals(12, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||||
|
|
||||||
TtmlNode root = subtitle.getRoot();
|
TtmlNode root = subtitle.getRoot();
|
||||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||||
TtmlNode sixthDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 5);
|
TtmlNode sixthDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 5);
|
||||||
|
|
||||||
String[] styleIds = queryChildrenForTag(sixthDiv, TtmlNode.TAG_P, 0).getStyleIds();
|
String[] styleIds = queryChildrenForTag(sixthDiv, TtmlNode.TAG_P, 0).getStyleIds();
|
||||||
assertEquals(2, styleIds.length);
|
assertThat(styleIds).hasLength(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleChaining() throws IOException, SubtitleDecoderException {
|
public void testMultipleChaining() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(CHAIN_MULTIPLE_STYLES_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(CHAIN_MULTIPLE_STYLES_TTML_FILE);
|
||||||
assertEquals(2, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||||
|
|
||||||
Map<String, TtmlStyle> globalStyles = subtitle.getGlobalStyles();
|
Map<String, TtmlStyle> globalStyles = subtitle.getGlobalStyles();
|
||||||
|
|
||||||
TtmlStyle style = globalStyles.get("s2");
|
TtmlStyle style = globalStyles.get("s2");
|
||||||
assertEquals("serif", style.getFontFamily());
|
assertThat(style.getFontFamily()).isEqualTo("serif");
|
||||||
assertEquals(0xFFFF0000, style.getBackgroundColor());
|
assertThat(style.getBackgroundColor()).isEqualTo(0xFFFF0000);
|
||||||
assertEquals(0xFF000000, style.getFontColor());
|
assertThat(style.getFontColor()).isEqualTo(0xFF000000);
|
||||||
assertEquals(TtmlStyle.STYLE_BOLD_ITALIC, style.getStyle());
|
assertThat(style.getStyle()).isEqualTo(TtmlStyle.STYLE_BOLD_ITALIC);
|
||||||
assertTrue(style.isLinethrough());
|
assertThat(style.isLinethrough()).isTrue();
|
||||||
|
|
||||||
style = globalStyles.get("s3");
|
style = globalStyles.get("s3");
|
||||||
// only difference: color must be RED
|
// only difference: color must be RED
|
||||||
assertEquals(0xFFFF0000, style.getFontColor());
|
assertThat(style.getFontColor()).isEqualTo(0xFFFF0000);
|
||||||
assertEquals("serif", style.getFontFamily());
|
assertThat(style.getFontFamily()).isEqualTo("serif");
|
||||||
assertEquals(0xFFFF0000, style.getBackgroundColor());
|
assertThat(style.getBackgroundColor()).isEqualTo(0xFFFF0000);
|
||||||
assertEquals(TtmlStyle.STYLE_BOLD_ITALIC, style.getStyle());
|
assertThat(style.getStyle()).isEqualTo(TtmlStyle.STYLE_BOLD_ITALIC);
|
||||||
assertTrue(style.isLinethrough());
|
assertThat(style.isLinethrough()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoUnderline() throws IOException, SubtitleDecoderException {
|
public void testNoUnderline() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(NO_UNDERLINE_LINETHROUGH_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(NO_UNDERLINE_LINETHROUGH_TTML_FILE);
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
|
|
||||||
TtmlNode root = subtitle.getRoot();
|
TtmlNode root = subtitle.getRoot();
|
||||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||||
TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0);
|
TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0);
|
||||||
|
|
||||||
TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style;
|
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 {
|
public void testNoLinethrough() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(NO_UNDERLINE_LINETHROUGH_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(NO_UNDERLINE_LINETHROUGH_TTML_FILE);
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
|
|
||||||
TtmlNode root = subtitle.getRoot();
|
TtmlNode root = subtitle.getRoot();
|
||||||
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||||
TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 1);
|
TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 1);
|
||||||
|
|
||||||
TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style;
|
TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style;
|
||||||
assertFalse("noLineThrough from inline attribute expected in second pNode",
|
assertWithMessage("noLineThrough from inline attribute expected in second pNode")
|
||||||
style.isLinethrough());
|
.that(style.isLinethrough())
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFontSizeSpans() throws IOException, SubtitleDecoderException {
|
public void testFontSizeSpans() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_TTML_FILE);
|
||||||
assertEquals(10, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(10);
|
||||||
|
|
||||||
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||||
assertEquals("text 1", String.valueOf(spannable));
|
assertThat(String.valueOf(spannable)).isEqualTo("text 1");
|
||||||
assertAbsoluteFontSize(spannable, 32);
|
assertAbsoluteFontSize(spannable, 32);
|
||||||
|
|
||||||
cues = subtitle.getCues(20 * 1000000);
|
cues = subtitle.getCues(20 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
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);
|
assertRelativeFontSize(spannable, 2.2f);
|
||||||
|
|
||||||
cues = subtitle.getCues(30 * 1000000);
|
cues = subtitle.getCues(30 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
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);
|
assertRelativeFontSize(spannable, 1.5f);
|
||||||
|
|
||||||
cues = subtitle.getCues(40 * 1000000);
|
cues = subtitle.getCues(40 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
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);
|
assertAbsoluteFontSize(spannable, 16);
|
||||||
|
|
||||||
cues = subtitle.getCues(50 * 1000000);
|
cues = subtitle.getCues(50 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
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);
|
assertRelativeFontSize(spannable, 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFontSizeWithMissingUnitIsIgnored() throws IOException, SubtitleDecoderException {
|
public void testFontSizeWithMissingUnitIsIgnored() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_MISSING_UNIT_TTML_FILE);
|
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);
|
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||||
assertEquals("no unit", String.valueOf(spannable));
|
assertThat(String.valueOf(spannable)).isEqualTo("no unit");
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFontSizeWithInvalidValueIsIgnored() throws IOException, SubtitleDecoderException {
|
public void testFontSizeWithInvalidValueIsIgnored() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_INVALID_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_INVALID_TTML_FILE);
|
||||||
assertEquals(6, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(6);
|
||||||
|
|
||||||
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||||
assertEquals("invalid", String.valueOf(spannable));
|
assertThat(String.valueOf(spannable)).isEqualTo("invalid");
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||||
|
|
||||||
|
|
||||||
cues = subtitle.getCues(20 * 1000000);
|
cues = subtitle.getCues(20 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||||
assertEquals("invalid", String.valueOf(spannable));
|
assertThat(String.valueOf(spannable)).isEqualTo("invalid");
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||||
|
|
||||||
|
|
||||||
cues = subtitle.getCues(30 * 1000000);
|
cues = subtitle.getCues(30 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
spannable = (SpannableStringBuilder) cues.get(0).text;
|
spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||||
assertEquals("invalid dot", String.valueOf(spannable));
|
assertThat(String.valueOf(spannable)).isEqualTo("invalid dot");
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFontSizeWithEmptyValueIsIgnored() throws IOException, SubtitleDecoderException {
|
public void testFontSizeWithEmptyValueIsIgnored() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_EMPTY_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(FONT_SIZE_EMPTY_TTML_FILE);
|
||||||
assertEquals(2, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(2);
|
||||||
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
List<Cue> cues = subtitle.getCues(10 * 1000000);
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||||
assertEquals("empty", String.valueOf(spannable));
|
assertThat(String.valueOf(spannable)).isEqualTo("empty");
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class)).hasLength(0);
|
||||||
assertEquals(0, spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class).length);
|
assertThat(spannable.getSpans(0, spannable.length(), AbsoluteSizeSpan.class)).hasLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFrameRate() throws IOException, SubtitleDecoderException {
|
public void testFrameRate() throws IOException, SubtitleDecoderException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(FRAME_RATE_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(FRAME_RATE_TTML_FILE);
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
assertEquals(1_000_000, subtitle.getEventTime(0));
|
assertThat(subtitle.getEventTime(0)).isEqualTo(1_000_000);
|
||||||
assertEquals(1_010_000, subtitle.getEventTime(1));
|
assertThat(subtitle.getEventTime(1)).isEqualTo(1_010_000);
|
||||||
assertEquals(1_001_000_000, subtitle.getEventTime(2), 1000);
|
assertThat((double) subtitle.getEventTime(2)).isWithin(1000).of(1_001_000_000);
|
||||||
assertEquals(2_002_000_000, subtitle.getEventTime(3), 2000);
|
assertThat((double) subtitle.getEventTime(3)).isWithin(2000).of(2_002_000_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertSpans(TtmlSubtitle subtitle, int second,
|
private void assertSpans(TtmlSubtitle subtitle, int second,
|
||||||
|
|
@ -389,9 +393,9 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
long timeUs = second * 1000000;
|
long timeUs = second * 1000000;
|
||||||
List<Cue> cues = subtitle.getCues(timeUs);
|
List<Cue> cues = subtitle.getCues(timeUs);
|
||||||
|
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
assertEquals(text, String.valueOf(cues.get(0).text));
|
assertThat(String.valueOf(cues.get(0).text)).isEqualTo(text);
|
||||||
assertEquals("single cue expected for timeUs: " + timeUs, 1, cues.size());
|
assertWithMessage("single cue expected for timeUs: " + timeUs).that(cues.size()).isEqualTo(1);
|
||||||
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
SpannableStringBuilder spannable = (SpannableStringBuilder) cues.get(0).text;
|
||||||
|
|
||||||
assertFont(spannable, font);
|
assertFont(spannable, font);
|
||||||
|
|
@ -407,67 +411,69 @@ public final class TtmlDecoderTest extends InstrumentationTestCase {
|
||||||
private void assertAbsoluteFontSize(Spannable spannable, int absoluteFontSize) {
|
private void assertAbsoluteFontSize(Spannable spannable, int absoluteFontSize) {
|
||||||
AbsoluteSizeSpan[] absoluteSizeSpans = spannable.getSpans(0, spannable.length(),
|
AbsoluteSizeSpan[] absoluteSizeSpans = spannable.getSpans(0, spannable.length(),
|
||||||
AbsoluteSizeSpan.class);
|
AbsoluteSizeSpan.class);
|
||||||
assertEquals(1, absoluteSizeSpans.length);
|
assertThat(absoluteSizeSpans).hasLength(1);
|
||||||
assertEquals(absoluteFontSize, absoluteSizeSpans[0].getSize());
|
assertThat(absoluteSizeSpans[0].getSize()).isEqualTo(absoluteFontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertRelativeFontSize(Spannable spannable, float relativeFontSize) {
|
private void assertRelativeFontSize(Spannable spannable, float relativeFontSize) {
|
||||||
RelativeSizeSpan[] relativeSizeSpans = spannable.getSpans(0, spannable.length(),
|
RelativeSizeSpan[] relativeSizeSpans = spannable.getSpans(0, spannable.length(),
|
||||||
RelativeSizeSpan.class);
|
RelativeSizeSpan.class);
|
||||||
assertEquals(1, relativeSizeSpans.length);
|
assertThat(relativeSizeSpans).hasLength(1);
|
||||||
assertEquals(relativeFontSize, relativeSizeSpans[0].getSizeChange());
|
assertThat(relativeSizeSpans[0].getSizeChange()).isEqualTo(relativeFontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertFont(Spannable spannable, String font) {
|
private void assertFont(Spannable spannable, String font) {
|
||||||
TypefaceSpan[] typefaceSpans = spannable.getSpans(0, spannable.length(), TypefaceSpan.class);
|
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) {
|
private void assertStyle(Spannable spannable, int fontStyle) {
|
||||||
StyleSpan[] styleSpans = spannable.getSpans(0, spannable.length(), StyleSpan.class);
|
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) {
|
private void assertUnderline(Spannable spannable, boolean isUnderline) {
|
||||||
UnderlineSpan[] underlineSpans = spannable.getSpans(0, spannable.length(), UnderlineSpan.class);
|
UnderlineSpan[] underlineSpans = spannable.getSpans(0, spannable.length(), UnderlineSpan.class);
|
||||||
assertEquals(isUnderline ? "must be underlined" : "must not be underlined",
|
assertWithMessage(isUnderline ? "must be underlined" : "must not be underlined")
|
||||||
isUnderline ? 1 : 0, underlineSpans.length);
|
.that(underlineSpans)
|
||||||
|
.hasLength(isUnderline ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertStrikethrough(Spannable spannable, boolean isStrikethrough) {
|
private void assertStrikethrough(Spannable spannable, boolean isStrikethrough) {
|
||||||
StrikethroughSpan[] striketroughSpans = spannable.getSpans(0, spannable.length(),
|
StrikethroughSpan[] striketroughSpans = spannable.getSpans(0, spannable.length(),
|
||||||
StrikethroughSpan.class);
|
StrikethroughSpan.class);
|
||||||
assertEquals(isStrikethrough ? "must be strikethrough" : "must not be strikethrough",
|
assertWithMessage(isStrikethrough ? "must be strikethrough" : "must not be strikethrough")
|
||||||
isStrikethrough ? 1 : 0, striketroughSpans.length);
|
.that(striketroughSpans)
|
||||||
|
.hasLength(isStrikethrough ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertBackground(Spannable spannable, int backgroundColor) {
|
private void assertBackground(Spannable spannable, int backgroundColor) {
|
||||||
BackgroundColorSpan[] backgroundColorSpans =
|
BackgroundColorSpan[] backgroundColorSpans =
|
||||||
spannable.getSpans(0, spannable.length(), BackgroundColorSpan.class);
|
spannable.getSpans(0, spannable.length(), BackgroundColorSpan.class);
|
||||||
if (backgroundColor != 0) {
|
if (backgroundColor != 0) {
|
||||||
assertEquals(backgroundColor, backgroundColorSpans[backgroundColorSpans.length - 1]
|
assertThat(backgroundColorSpans[backgroundColorSpans.length - 1].getBackgroundColor())
|
||||||
.getBackgroundColor());
|
.isEqualTo(backgroundColor);
|
||||||
} else {
|
} else {
|
||||||
assertEquals(0, backgroundColorSpans.length);
|
assertThat(backgroundColorSpans).hasLength(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertForeground(Spannable spannable, int foregroundColor) {
|
private void assertForeground(Spannable spannable, int foregroundColor) {
|
||||||
ForegroundColorSpan[] foregroundColorSpans =
|
ForegroundColorSpan[] foregroundColorSpans =
|
||||||
spannable.getSpans(0, spannable.length(), ForegroundColorSpan.class);
|
spannable.getSpans(0, spannable.length(), ForegroundColorSpan.class);
|
||||||
assertEquals(foregroundColor,
|
assertThat(foregroundColorSpans[foregroundColorSpans.length - 1].getForegroundColor())
|
||||||
foregroundColorSpans[foregroundColorSpans.length - 1].getForegroundColor());
|
.isEqualTo(foregroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertAlignment(Spannable spannable, Layout.Alignment alignment) {
|
private void assertAlignment(Spannable spannable, Layout.Alignment alignment) {
|
||||||
if (alignment != null) {
|
if (alignment != null) {
|
||||||
AlignmentSpan.Standard[] alignmentSpans =
|
AlignmentSpan.Standard[] alignmentSpans =
|
||||||
spannable.getSpans(0, spannable.length(), AlignmentSpan.Standard.class);
|
spannable.getSpans(0, spannable.length(), AlignmentSpan.Standard.class);
|
||||||
assertEquals(1, alignmentSpans.length);
|
assertThat(alignmentSpans).hasLength(1);
|
||||||
assertEquals(alignment, alignmentSpans[0].getAlignment());
|
assertThat(alignmentSpans[0].getAlignment()).isEqualTo(alignment);
|
||||||
} else {
|
} else {
|
||||||
assertEquals(0, spannable.getSpans
|
assertThat(spannable.getSpans(0, spannable.length(), AlignmentSpan.Standard.class))
|
||||||
(0, spannable.length(), AlignmentSpan.Standard.class).length);
|
.hasLength(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.text.tx3g;
|
package com.google.android.exoplayer2.text.tx3g;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
|
|
@ -52,7 +54,7 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
||||||
Tx3gDecoder decoder = new Tx3gDecoder(Collections.<byte[]>emptyList());
|
Tx3gDecoder decoder = new Tx3gDecoder(Collections.<byte[]>emptyList());
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_SUBTITLE);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_SUBTITLE);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
assertTrue(subtitle.getCues(0).isEmpty());
|
assertThat(subtitle.getCues(0)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDecodeJustText() throws IOException, SubtitleDecoderException {
|
public void testDecodeJustText() throws IOException, SubtitleDecoderException {
|
||||||
|
|
@ -60,8 +62,8 @@ public final class Tx3gDecoderTest extends InstrumentationTestCase {
|
||||||
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_JUST_TEXT);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_JUST_TEXT);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("CC Test", text.toString());
|
assertThat(text.toString()).isEqualTo("CC Test");
|
||||||
assertEquals(0, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(0);
|
||||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("CC Test", text.toString());
|
assertThat(text.toString()).isEqualTo("CC Test");
|
||||||
assertEquals(3, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(3);
|
||||||
StyleSpan styleSpan = findSpan(text, 0, 6, StyleSpan.class);
|
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);
|
findSpan(text, 0, 6, UnderlineSpan.class);
|
||||||
ForegroundColorSpan colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.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);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL_ALL_DEFAULTS);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("CC Test", text.toString());
|
assertThat(text.toString()).isEqualTo("CC Test");
|
||||||
assertEquals(0, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(0);
|
||||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_UTF16_BE_NO_STYL);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("你好", text.toString());
|
assertThat(text.toString()).isEqualTo("你好");
|
||||||
assertEquals(0, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(0);
|
||||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_UTF16_LE_NO_STYL);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("你好", text.toString());
|
assertThat(text.toString()).isEqualTo("你好");
|
||||||
assertEquals(0, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(0);
|
||||||
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_MULTIPLE_STYL);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("Line 2\nLine 3", text.toString());
|
assertThat(text.toString()).isEqualTo("Line 2\nLine 3");
|
||||||
assertEquals(4, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(4);
|
||||||
StyleSpan styleSpan = findSpan(text, 0, 5, StyleSpan.class);
|
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);
|
findSpan(text, 7, 12, UnderlineSpan.class);
|
||||||
ForegroundColorSpan colorSpan = findSpan(text, 0, 5, ForegroundColorSpan.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);
|
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);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_OTHER_EXTENSION);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("CC Test", text.toString());
|
assertThat(text.toString()).isEqualTo("CC Test");
|
||||||
assertEquals(2, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(2);
|
||||||
StyleSpan styleSpan = findSpan(text, 0, 6, StyleSpan.class);
|
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);
|
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);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("CC Test", text.toString());
|
assertThat(text.toString()).isEqualTo("CC Test");
|
||||||
assertEquals(5, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(5);
|
||||||
StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class);
|
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);
|
findSpan(text, 0, text.length(), UnderlineSpan.class);
|
||||||
TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.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);
|
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);
|
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);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_TBOX);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("CC Test", text.toString());
|
assertThat(text.toString()).isEqualTo("CC Test");
|
||||||
assertEquals(4, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(4);
|
||||||
StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class);
|
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);
|
findSpan(text, 0, text.length(), UnderlineSpan.class);
|
||||||
TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.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);
|
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);
|
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);
|
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
|
||||||
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
|
||||||
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
|
||||||
assertEquals("CC Test", text.toString());
|
assertThat(text.toString()).isEqualTo("CC Test");
|
||||||
assertEquals(3, text.getSpans(0, text.length(), Object.class).length);
|
assertThat(text.getSpans(0, text.length(), Object.class)).hasLength(3);
|
||||||
StyleSpan styleSpan = findSpan(text, 0, 6, StyleSpan.class);
|
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);
|
findSpan(text, 0, 6, UnderlineSpan.class);
|
||||||
ForegroundColorSpan colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.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);
|
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) {
|
private static void assertFractionalLinePosition(Cue cue, float expectedFraction) {
|
||||||
assertEquals(Cue.LINE_TYPE_FRACTION, cue.lineType);
|
assertThat(cue.lineType).isEqualTo(Cue.LINE_TYPE_FRACTION);
|
||||||
assertEquals(Cue.ANCHOR_TYPE_START, cue.lineAnchor);
|
assertThat(cue.lineAnchor).isEqualTo(Cue.ANCHOR_TYPE_START);
|
||||||
assertTrue(Math.abs(expectedFraction - cue.line) < 1e-6);
|
assertThat(Math.abs(expectedFraction - cue.line) < 1e-6).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.text.webvtt;
|
package com.google.android.exoplayer2.text.webvtt;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import android.text.Layout.Alignment;
|
import android.text.Layout.Alignment;
|
||||||
|
|
@ -61,7 +63,7 @@ public class WebvttDecoderTest extends InstrumentationTestCase {
|
||||||
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_FILE);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_FILE);
|
||||||
|
|
||||||
// Test event count.
|
// Test event count.
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
|
|
||||||
// Test cues.
|
// Test cues.
|
||||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
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);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_WITH_BAD_TIMESTAMPS);
|
||||||
|
|
||||||
// Test event count.
|
// Test event count.
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
|
|
||||||
// Test cues.
|
// Test cues.
|
||||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
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);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_WITH_IDS_FILE);
|
||||||
|
|
||||||
// Test event count.
|
// Test event count.
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
|
|
||||||
// Test cues.
|
// Test cues.
|
||||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
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);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(TYPICAL_WITH_COMMENTS_FILE);
|
||||||
|
|
||||||
// test event count
|
// test event count
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
|
|
||||||
// test cues
|
// test cues
|
||||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
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);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_TAGS_FILE);
|
||||||
|
|
||||||
// Test event count.
|
// Test event count.
|
||||||
assertEquals(8, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(8);
|
||||||
|
|
||||||
// Test cues.
|
// Test cues.
|
||||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
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 {
|
public void testDecodeWithPositioning() throws IOException, SubtitleDecoderException {
|
||||||
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_POSITIONING_FILE);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_POSITIONING_FILE);
|
||||||
// Test event count.
|
// Test event count.
|
||||||
assertEquals(12, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(12);
|
||||||
// Test cues.
|
// Test cues.
|
||||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.", Alignment.ALIGN_NORMAL,
|
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);
|
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);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_BAD_CUE_HEADER_FILE);
|
||||||
|
|
||||||
// Test event count.
|
// Test event count.
|
||||||
assertEquals(4, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(4);
|
||||||
|
|
||||||
// Test cues.
|
// Test cues.
|
||||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
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);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_CSS_STYLES);
|
||||||
|
|
||||||
// Test event count.
|
// Test event count.
|
||||||
assertEquals(8, subtitle.getEventTimeCount());
|
assertThat(subtitle.getEventTimeCount()).isEqualTo(8);
|
||||||
|
|
||||||
// Test cues.
|
// Test cues.
|
||||||
assertCue(subtitle, 0, 0, 1234000, "This is the first subtitle.");
|
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 s2 = getUniqueSpanTextAt(subtitle, 2345000);
|
||||||
Spanned s3 = getUniqueSpanTextAt(subtitle, 20000000);
|
Spanned s3 = getUniqueSpanTextAt(subtitle, 20000000);
|
||||||
Spanned s4 = getUniqueSpanTextAt(subtitle, 25000000);
|
Spanned s4 = getUniqueSpanTextAt(subtitle, 25000000);
|
||||||
assertEquals(1, s1.getSpans(0, s1.length(), ForegroundColorSpan.class).length);
|
assertThat(s1.getSpans(0, s1.length(), ForegroundColorSpan.class)).hasLength(1);
|
||||||
assertEquals(1, s1.getSpans(0, s1.length(), BackgroundColorSpan.class).length);
|
assertThat(s1.getSpans(0, s1.length(), BackgroundColorSpan.class)).hasLength(1);
|
||||||
assertEquals(2, s2.getSpans(0, s2.length(), ForegroundColorSpan.class).length);
|
assertThat(s2.getSpans(0, s2.length(), ForegroundColorSpan.class)).hasLength(2);
|
||||||
assertEquals(1, s3.getSpans(10, s3.length(), UnderlineSpan.class).length);
|
assertThat(s3.getSpans(10, s3.length(), UnderlineSpan.class)).hasLength(1);
|
||||||
assertEquals(2, s4.getSpans(0, 16, BackgroundColorSpan.class).length);
|
assertThat(s4.getSpans(0, 16, BackgroundColorSpan.class)).hasLength(2);
|
||||||
assertEquals(1, s4.getSpans(17, s4.length(), StyleSpan.class).length);
|
assertThat(s4.getSpans(17, s4.length(), StyleSpan.class)).hasLength(1);
|
||||||
assertEquals(Typeface.BOLD, s4.getSpans(17, s4.length(), StyleSpan.class)[0].getStyle());
|
assertThat(s4.getSpans(17, s4.length(), StyleSpan.class)[0].getStyle())
|
||||||
|
.isEqualTo(Typeface.BOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithComplexCssSelectors() throws IOException, SubtitleDecoderException {
|
public void testWithComplexCssSelectors() throws IOException, SubtitleDecoderException {
|
||||||
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_CSS_COMPLEX_SELECTORS);
|
WebvttSubtitle subtitle = getSubtitleForTestAsset(WITH_CSS_COMPLEX_SELECTORS);
|
||||||
Spanned text = getUniqueSpanTextAt(subtitle, 0);
|
Spanned text = getUniqueSpanTextAt(subtitle, 0);
|
||||||
assertEquals(1, text.getSpans(30, text.length(), ForegroundColorSpan.class).length);
|
assertThat(text.getSpans(30, text.length(), ForegroundColorSpan.class)).hasLength(1);
|
||||||
assertEquals(0xFFEE82EE,
|
assertThat(text.getSpans(30, text.length(), ForegroundColorSpan.class)[0].getForegroundColor())
|
||||||
text.getSpans(30, text.length(), ForegroundColorSpan.class)[0].getForegroundColor());
|
.isEqualTo(0xFFEE82EE);
|
||||||
assertEquals(1, text.getSpans(30, text.length(), TypefaceSpan.class).length);
|
assertThat(text.getSpans(30, text.length(), TypefaceSpan.class)).hasLength(1);
|
||||||
assertEquals("courier", text.getSpans(30, text.length(), TypefaceSpan.class)[0].getFamily());
|
assertThat(text.getSpans(30, text.length(), TypefaceSpan.class)[0].getFamily())
|
||||||
|
.isEqualTo("courier");
|
||||||
|
|
||||||
text = getUniqueSpanTextAt(subtitle, 2000000);
|
text = getUniqueSpanTextAt(subtitle, 2000000);
|
||||||
assertEquals(1, text.getSpans(5, text.length(), TypefaceSpan.class).length);
|
assertThat(text.getSpans(5, text.length(), TypefaceSpan.class)).hasLength(1);
|
||||||
assertEquals("courier", text.getSpans(5, text.length(), TypefaceSpan.class)[0].getFamily());
|
assertThat(text.getSpans(5, text.length(), TypefaceSpan.class)[0].getFamily())
|
||||||
|
.isEqualTo("courier");
|
||||||
|
|
||||||
text = getUniqueSpanTextAt(subtitle, 2500000);
|
text = getUniqueSpanTextAt(subtitle, 2500000);
|
||||||
assertEquals(1, text.getSpans(5, text.length(), StyleSpan.class).length);
|
assertThat(text.getSpans(5, text.length(), StyleSpan.class)).hasLength(1);
|
||||||
assertEquals(Typeface.BOLD, text.getSpans(5, text.length(), StyleSpan.class)[0].getStyle());
|
assertThat(text.getSpans(5, text.length(), StyleSpan.class)[0].getStyle())
|
||||||
assertEquals(1, text.getSpans(5, text.length(), TypefaceSpan.class).length);
|
.isEqualTo(Typeface.BOLD);
|
||||||
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, 4000000);
|
text = getUniqueSpanTextAt(subtitle, 4000000);
|
||||||
assertEquals(0, text.getSpans(6, 22, StyleSpan.class).length);
|
assertThat(text.getSpans(6, 22, StyleSpan.class)).hasLength(0);
|
||||||
assertEquals(1, text.getSpans(30, text.length(), StyleSpan.class).length);
|
assertThat(text.getSpans(30, text.length(), StyleSpan.class)).hasLength(1);
|
||||||
assertEquals(Typeface.BOLD, text.getSpans(30, text.length(), StyleSpan.class)[0].getStyle());
|
assertThat(text.getSpans(30, text.length(), StyleSpan.class)[0].getStyle())
|
||||||
|
.isEqualTo(Typeface.BOLD);
|
||||||
|
|
||||||
text = getUniqueSpanTextAt(subtitle, 5000000);
|
text = getUniqueSpanTextAt(subtitle, 5000000);
|
||||||
assertEquals(0, text.getSpans(9, 17, StyleSpan.class).length);
|
assertThat(text.getSpans(9, 17, StyleSpan.class)).hasLength(0);
|
||||||
assertEquals(1, text.getSpans(19, text.length(), StyleSpan.class).length);
|
assertThat(text.getSpans(19, text.length(), StyleSpan.class)).hasLength(1);
|
||||||
assertEquals(Typeface.ITALIC, text.getSpans(19, text.length(), StyleSpan.class)[0].getStyle());
|
assertThat(text.getSpans(19, text.length(), StyleSpan.class)[0].getStyle())
|
||||||
|
.isEqualTo(Typeface.ITALIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebvttSubtitle getSubtitleForTestAsset(String asset) throws IOException,
|
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,
|
private static void assertCue(WebvttSubtitle subtitle, int eventTimeIndex, long startTimeUs,
|
||||||
int endTimeUs, String text, Alignment textAlignment, float line, int lineType, int lineAnchor,
|
int endTimeUs, String text, Alignment textAlignment, float line, int lineType, int lineAnchor,
|
||||||
float position, int positionAnchor, float size) {
|
float position, int positionAnchor, float size) {
|
||||||
assertEquals(startTimeUs, subtitle.getEventTime(eventTimeIndex));
|
assertThat(subtitle.getEventTime(eventTimeIndex)).isEqualTo(startTimeUs);
|
||||||
assertEquals(endTimeUs, subtitle.getEventTime(eventTimeIndex + 1));
|
assertThat(subtitle.getEventTime(eventTimeIndex + 1)).isEqualTo(endTimeUs);
|
||||||
List<Cue> cues = subtitle.getCues(subtitle.getEventTime(eventTimeIndex));
|
List<Cue> cues = subtitle.getCues(subtitle.getEventTime(eventTimeIndex));
|
||||||
assertEquals(1, cues.size());
|
assertThat(cues).hasSize(1);
|
||||||
// Assert cue properties.
|
// Assert cue properties.
|
||||||
Cue cue = cues.get(0);
|
Cue cue = cues.get(0);
|
||||||
assertEquals(text, cue.text.toString());
|
assertThat(cue.text.toString()).isEqualTo(text);
|
||||||
assertEquals(textAlignment, cue.textAlignment);
|
assertThat(cue.textAlignment).isEqualTo(textAlignment);
|
||||||
assertEquals(line, cue.line);
|
assertThat(cue.line).isEqualTo(line);
|
||||||
assertEquals(lineType, cue.lineType);
|
assertThat(cue.lineType).isEqualTo(lineType);
|
||||||
assertEquals(lineAnchor, cue.lineAnchor);
|
assertThat(cue.lineAnchor).isEqualTo(lineAnchor);
|
||||||
assertEquals(position, cue.position);
|
assertThat(cue.position).isEqualTo(position);
|
||||||
assertEquals(positionAnchor, cue.positionAnchor);
|
assertThat(cue.positionAnchor).isEqualTo(positionAnchor);
|
||||||
assertEquals(size, cue.size);
|
assertThat(cue.size).isEqualTo(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
|
@ -75,7 +77,7 @@ public final class ContentDataSourceTest extends InstrumentationTestCase {
|
||||||
fail();
|
fail();
|
||||||
} catch (ContentDataSource.ContentDataSourceException e) {
|
} catch (ContentDataSource.ContentDataSourceException e) {
|
||||||
// Expected.
|
// Expected.
|
||||||
assertTrue(e.getCause() instanceof FileNotFoundException);
|
assertThat(e.getCause()).isInstanceOf(FileNotFoundException.class);
|
||||||
} finally {
|
} finally {
|
||||||
dataSource.close();
|
dataSource.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package com.google.android.exoplayer2.upstream.cache;
|
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.InstrumentationTestCase;
|
||||||
import android.test.MoreAsserts;
|
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
|
|
@ -9,10 +11,8 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link CachedContentIndex}.
|
* Tests {@link CachedContentIndex}.
|
||||||
|
|
@ -56,47 +56,45 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
CachedContent cachedContent1 = new CachedContent(5, key1, 10);
|
CachedContent cachedContent1 = new CachedContent(5, key1, 10);
|
||||||
index.addNew(cachedContent1);
|
index.addNew(cachedContent1);
|
||||||
CachedContent cachedContent2 = index.getOrAdd(key2);
|
CachedContent cachedContent2 = index.getOrAdd(key2);
|
||||||
assertTrue(cachedContent1.id != cachedContent2.id);
|
assertThat(cachedContent1.id != cachedContent2.id).isTrue();
|
||||||
|
|
||||||
// add a span
|
// add a span
|
||||||
File cacheSpanFile = SimpleCacheSpanTest
|
File cacheSpanFile = SimpleCacheSpanTest
|
||||||
.createCacheSpanFile(cacheDir, cachedContent1.id, 10, 20, 30);
|
.createCacheSpanFile(cacheDir, cachedContent1.id, 10, 20, 30);
|
||||||
SimpleCacheSpan span = SimpleCacheSpan.createCacheEntry(cacheSpanFile, index);
|
SimpleCacheSpan span = SimpleCacheSpan.createCacheEntry(cacheSpanFile, index);
|
||||||
assertNotNull(span);
|
assertThat(span).isNotNull();
|
||||||
cachedContent1.addSpan(span);
|
cachedContent1.addSpan(span);
|
||||||
|
|
||||||
// Check if they are added and get method returns null if the key isn't found
|
// Check if they are added and get method returns null if the key isn't found
|
||||||
assertEquals(cachedContent1, index.get(key1));
|
assertThat(index.get(key1)).isEqualTo(cachedContent1);
|
||||||
assertEquals(cachedContent2, index.get(key2));
|
assertThat(index.get(key2)).isEqualTo(cachedContent2);
|
||||||
assertNull(index.get(key3));
|
assertThat(index.get(key3)).isNull();
|
||||||
|
|
||||||
// test getAll()
|
// test getAll()
|
||||||
Collection<CachedContent> cachedContents = index.getAll();
|
Collection<CachedContent> cachedContents = index.getAll();
|
||||||
assertEquals(2, cachedContents.size());
|
assertThat(cachedContents).containsExactly(cachedContent1, cachedContent2);
|
||||||
assertTrue(Arrays.asList(cachedContent1, cachedContent2).containsAll(cachedContents));
|
|
||||||
|
|
||||||
// test getKeys()
|
// test getKeys()
|
||||||
Set<String> keys = index.getKeys();
|
Set<String> keys = index.getKeys();
|
||||||
assertEquals(2, keys.size());
|
assertThat(keys).containsExactly(key1, key2);
|
||||||
assertTrue(Arrays.asList(key1, key2).containsAll(keys));
|
|
||||||
|
|
||||||
// test getKeyForId()
|
// test getKeyForId()
|
||||||
assertEquals(key1, index.getKeyForId(cachedContent1.id));
|
assertThat(index.getKeyForId(cachedContent1.id)).isEqualTo(key1);
|
||||||
assertEquals(key2, index.getKeyForId(cachedContent2.id));
|
assertThat(index.getKeyForId(cachedContent2.id)).isEqualTo(key2);
|
||||||
|
|
||||||
// test remove()
|
// test remove()
|
||||||
index.maybeRemove(key2);
|
index.maybeRemove(key2);
|
||||||
index.maybeRemove(key3);
|
index.maybeRemove(key3);
|
||||||
assertEquals(cachedContent1, index.get(key1));
|
assertThat(index.get(key1)).isEqualTo(cachedContent1);
|
||||||
assertNull(index.get(key2));
|
assertThat(index.get(key2)).isNull();
|
||||||
assertTrue(cacheSpanFile.exists());
|
assertThat(cacheSpanFile.exists()).isTrue();
|
||||||
|
|
||||||
// test removeEmpty()
|
// test removeEmpty()
|
||||||
index.addNew(cachedContent2);
|
index.addNew(cachedContent2);
|
||||||
index.removeEmpty();
|
index.removeEmpty();
|
||||||
assertEquals(cachedContent1, index.get(key1));
|
assertThat(index.get(key1)).isEqualTo(cachedContent1);
|
||||||
assertNull(index.get(key2));
|
assertThat(index.get(key2)).isNull();
|
||||||
assertTrue(cacheSpanFile.exists());
|
assertThat(cacheSpanFile.exists()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStoreAndLoad() throws Exception {
|
public void testStoreAndLoad() throws Exception {
|
||||||
|
|
@ -109,11 +107,11 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
index.load();
|
index.load();
|
||||||
assertEquals(2, index.getAll().size());
|
assertThat(index.getAll()).hasSize(2);
|
||||||
assertEquals(5, index.assignIdForKey("ABCDE"));
|
assertThat(index.assignIdForKey("ABCDE")).isEqualTo(5);
|
||||||
assertEquals(10, index.getContentLength("ABCDE"));
|
assertThat(index.getContentLength("ABCDE")).isEqualTo(10);
|
||||||
assertEquals(2, index.assignIdForKey("KLMNO"));
|
assertThat(index.assignIdForKey("KLMNO")).isEqualTo(2);
|
||||||
assertEquals(2560, index.getContentLength("KLMNO"));
|
assertThat(index.getContentLength("KLMNO")).isEqualTo(2560);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStoreV1() throws Exception {
|
public void testStoreV1() throws Exception {
|
||||||
|
|
@ -124,13 +122,13 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
byte[] buffer = new byte[testIndexV1File.length];
|
byte[] buffer = new byte[testIndexV1File.length];
|
||||||
FileInputStream fos = new FileInputStream(new File(cacheDir, CachedContentIndex.FILE_NAME));
|
FileInputStream fos = new FileInputStream(new File(cacheDir, CachedContentIndex.FILE_NAME));
|
||||||
assertEquals(testIndexV1File.length, fos.read(buffer));
|
assertThat(fos.read(buffer)).isEqualTo(testIndexV1File.length);
|
||||||
assertEquals(-1, fos.read());
|
assertThat(fos.read()).isEqualTo(-1);
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
// TODO: The order of the CachedContent stored in index file isn't defined so this test may fail
|
// 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
|
// on a different implementation of the underlying set
|
||||||
MoreAsserts.assertEquals(testIndexV1File, buffer);
|
assertThat(buffer).isEqualTo(testIndexV1File);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAssignIdForKeyAndGetKeyForId() throws Exception {
|
public void testAssignIdForKeyAndGetKeyForId() throws Exception {
|
||||||
|
|
@ -138,29 +136,29 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
final String key2 = "key2";
|
final String key2 = "key2";
|
||||||
int id1 = index.assignIdForKey(key1);
|
int id1 = index.assignIdForKey(key1);
|
||||||
int id2 = index.assignIdForKey(key2);
|
int id2 = index.assignIdForKey(key2);
|
||||||
assertEquals(key1, index.getKeyForId(id1));
|
assertThat(index.getKeyForId(id1)).isEqualTo(key1);
|
||||||
assertEquals(key2, index.getKeyForId(id2));
|
assertThat(index.getKeyForId(id2)).isEqualTo(key2);
|
||||||
assertTrue(id1 != id2);
|
assertThat(id1 != id2).isTrue();
|
||||||
assertEquals(id1, index.assignIdForKey(key1));
|
assertThat(index.assignIdForKey(key1)).isEqualTo(id1);
|
||||||
assertEquals(id2, index.assignIdForKey(key2));
|
assertThat(index.assignIdForKey(key2)).isEqualTo(id2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetGetContentLength() throws Exception {
|
public void testSetGetContentLength() throws Exception {
|
||||||
final String key1 = "key1";
|
final String key1 = "key1";
|
||||||
assertEquals(C.LENGTH_UNSET, index.getContentLength(key1));
|
assertThat(index.getContentLength(key1)).isEqualTo(C.LENGTH_UNSET);
|
||||||
index.setContentLength(key1, 10);
|
index.setContentLength(key1, 10);
|
||||||
assertEquals(10, index.getContentLength(key1));
|
assertThat(index.getContentLength(key1)).isEqualTo(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetNewId() throws Exception {
|
public void testGetNewId() throws Exception {
|
||||||
SparseArray<String> idToKey = new SparseArray<>();
|
SparseArray<String> idToKey = new SparseArray<>();
|
||||||
assertEquals(0, CachedContentIndex.getNewId(idToKey));
|
assertThat(CachedContentIndex.getNewId(idToKey)).isEqualTo(0);
|
||||||
idToKey.put(10, "");
|
idToKey.put(10, "");
|
||||||
assertEquals(11, CachedContentIndex.getNewId(idToKey));
|
assertThat(CachedContentIndex.getNewId(idToKey)).isEqualTo(11);
|
||||||
idToKey.put(Integer.MAX_VALUE, "");
|
idToKey.put(Integer.MAX_VALUE, "");
|
||||||
assertEquals(0, CachedContentIndex.getNewId(idToKey));
|
assertThat(CachedContentIndex.getNewId(idToKey)).isEqualTo(0);
|
||||||
idToKey.put(0, "");
|
idToKey.put(0, "");
|
||||||
assertEquals(1, CachedContentIndex.getNewId(idToKey));
|
assertThat(CachedContentIndex.getNewId(idToKey)).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEncryption() throws Exception {
|
public void testEncryption() throws Exception {
|
||||||
|
|
@ -173,36 +171,40 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
// Rename the index file from the test above
|
// Rename the index file from the test above
|
||||||
File file1 = new File(cacheDir, CachedContentIndex.FILE_NAME);
|
File file1 = new File(cacheDir, CachedContentIndex.FILE_NAME);
|
||||||
File file2 = new File(cacheDir, "file2compare");
|
File file2 = new File(cacheDir, "file2compare");
|
||||||
assertTrue(file1.renameTo(file2));
|
assertThat(file1.renameTo(file2)).isTrue();
|
||||||
|
|
||||||
// Write a new index file
|
// Write a new index file
|
||||||
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
||||||
new CachedContentIndex(cacheDir, key));
|
new CachedContentIndex(cacheDir, key));
|
||||||
|
|
||||||
assertEquals(file2.length(), file1.length());
|
assertThat(file1.length()).isEqualTo(file2.length());
|
||||||
// Assert file content is different
|
// Assert file content is different
|
||||||
FileInputStream fis1 = new FileInputStream(file1);
|
FileInputStream fis1 = new FileInputStream(file1);
|
||||||
FileInputStream fis2 = new FileInputStream(file2);
|
FileInputStream fis2 = new FileInputStream(file2);
|
||||||
for (int b; (b = fis1.read()) == fis2.read(); ) {
|
for (int b; (b = fis1.read()) == fis2.read(); ) {
|
||||||
assertTrue(b != -1);
|
assertThat(b != -1).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean threw = false;
|
boolean threw = false;
|
||||||
try {
|
try {
|
||||||
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
||||||
new CachedContentIndex(cacheDir, key2));
|
new CachedContentIndex(cacheDir, key2));
|
||||||
} catch (AssertionFailedError e) {
|
} catch (AssertionError e) {
|
||||||
threw = true;
|
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 {
|
try {
|
||||||
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir, key),
|
||||||
new CachedContentIndex(cacheDir));
|
new CachedContentIndex(cacheDir));
|
||||||
} catch (AssertionFailedError e) {
|
} catch (AssertionError e) {
|
||||||
threw = true;
|
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.
|
// Non encrypted index file can be read even when encryption key provided.
|
||||||
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir),
|
assertStoredAndLoadedEqual(new CachedContentIndex(cacheDir),
|
||||||
|
|
@ -221,7 +223,7 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
index.maybeRemove(cachedContent.key);
|
index.maybeRemove(cachedContent.key);
|
||||||
|
|
||||||
assertNull(index.get(cachedContent.key));
|
assertThat(index.get(cachedContent.key)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCantRemoveNotEmptyCachedContent() throws Exception {
|
public void testCantRemoveNotEmptyCachedContent() throws Exception {
|
||||||
|
|
@ -234,7 +236,7 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
index.maybeRemove(cachedContent.key);
|
index.maybeRemove(cachedContent.key);
|
||||||
|
|
||||||
assertNotNull(index.get(cachedContent.key));
|
assertThat(index.get(cachedContent.key)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCantRemoveLockedCachedContent() throws Exception {
|
public void testCantRemoveLockedCachedContent() throws Exception {
|
||||||
|
|
@ -244,7 +246,7 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
index.maybeRemove(cachedContent.key);
|
index.maybeRemove(cachedContent.key);
|
||||||
|
|
||||||
assertNotNull(index.get(cachedContent.key));
|
assertThat(index.get(cachedContent.key)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertStoredAndLoadedEqual(CachedContentIndex index, CachedContentIndex index2)
|
private void assertStoredAndLoadedEqual(CachedContentIndex index, CachedContentIndex index2)
|
||||||
|
|
@ -256,10 +258,10 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
|
||||||
index2.load();
|
index2.load();
|
||||||
Set<String> keys = index.getKeys();
|
Set<String> keys = index.getKeys();
|
||||||
Set<String> keys2 = index2.getKeys();
|
Set<String> keys2 = index2.getKeys();
|
||||||
assertEquals(keys, keys2);
|
assertThat(keys2).isEqualTo(keys);
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
assertEquals(index.getContentLength(key), index2.getContentLength(key));
|
assertThat(index2.getContentLength(key)).isEqualTo(index.getContentLength(key));
|
||||||
assertEquals(index.get(key).getSpans(), index2.get(key).getSpans());
|
assertThat(index2.get(key).getSpans()).isEqualTo(index.get(key).getSpans());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream.cache;
|
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.any;
|
||||||
import static org.mockito.Mockito.anyString;
|
import static org.mockito.Mockito.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
@ -67,8 +68,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRegion_noSpansInCache() {
|
public void testGetRegion_noSpansInCache() {
|
||||||
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(100));
|
assertThat(tracker.getRegionEndTimeMs(100)).isEqualTo(CachedRegionTracker.NOT_CACHED);
|
||||||
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(150));
|
assertThat(tracker.getRegionEndTimeMs(150)).isEqualTo(CachedRegionTracker.NOT_CACHED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRegion_fullyCached() throws Exception {
|
public void testGetRegion_fullyCached() throws Exception {
|
||||||
|
|
@ -76,8 +77,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
||||||
cache,
|
cache,
|
||||||
newCacheSpan(100, 100));
|
newCacheSpan(100, 100));
|
||||||
|
|
||||||
assertEquals(CachedRegionTracker.CACHED_TO_END, tracker.getRegionEndTimeMs(101));
|
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(CachedRegionTracker.CACHED_TO_END);
|
||||||
assertEquals(CachedRegionTracker.CACHED_TO_END, tracker.getRegionEndTimeMs(121));
|
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(CachedRegionTracker.CACHED_TO_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRegion_partiallyCached() throws Exception {
|
public void testGetRegion_partiallyCached() throws Exception {
|
||||||
|
|
@ -85,8 +86,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
||||||
cache,
|
cache,
|
||||||
newCacheSpan(100, 40));
|
newCacheSpan(100, 40));
|
||||||
|
|
||||||
assertEquals(200, tracker.getRegionEndTimeMs(101));
|
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
|
||||||
assertEquals(200, tracker.getRegionEndTimeMs(121));
|
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRegion_multipleSpanAddsJoinedCorrectly() throws Exception {
|
public void testGetRegion_multipleSpanAddsJoinedCorrectly() throws Exception {
|
||||||
|
|
@ -97,8 +98,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
||||||
cache,
|
cache,
|
||||||
newCacheSpan(120, 20));
|
newCacheSpan(120, 20));
|
||||||
|
|
||||||
assertEquals(200, tracker.getRegionEndTimeMs(101));
|
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
|
||||||
assertEquals(200, tracker.getRegionEndTimeMs(121));
|
assertThat(tracker.getRegionEndTimeMs(121)).isEqualTo(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRegion_fullyCachedThenPartiallyRemoved() throws Exception {
|
public void testGetRegion_fullyCachedThenPartiallyRemoved() throws Exception {
|
||||||
|
|
@ -112,10 +113,10 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
||||||
cache,
|
cache,
|
||||||
newCacheSpan(140, 40));
|
newCacheSpan(140, 40));
|
||||||
|
|
||||||
assertEquals(200, tracker.getRegionEndTimeMs(101));
|
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(200);
|
||||||
assertEquals(200, tracker.getRegionEndTimeMs(121));
|
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 {
|
public void testGetRegion_subchunkEstimation() throws Exception {
|
||||||
|
|
@ -123,8 +124,8 @@ public final class CachedRegionTrackerTest extends InstrumentationTestCase {
|
||||||
cache,
|
cache,
|
||||||
newCacheSpan(100, 10));
|
newCacheSpan(100, 10));
|
||||||
|
|
||||||
assertEquals(50, tracker.getRegionEndTimeMs(101));
|
assertThat(tracker.getRegionEndTimeMs(101)).isEqualTo(50);
|
||||||
assertEquals(CachedRegionTracker.NOT_CACHED, tracker.getRegionEndTimeMs(111));
|
assertThat(tracker.getRegionEndTimeMs(111)).isEqualTo(CachedRegionTracker.NOT_CACHED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CacheSpan newCacheSpan(int position, int length) throws IOException {
|
private CacheSpan newCacheSpan(int position, int length) throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream.cache;
|
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.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -88,39 +91,39 @@ public class SimpleCacheSpanTest extends InstrumentationTestCase {
|
||||||
for (File file : cacheDir.listFiles()) {
|
for (File file : cacheDir.listFiles()) {
|
||||||
SimpleCacheSpan cacheEntry = SimpleCacheSpan.createCacheEntry(file, index);
|
SimpleCacheSpan cacheEntry = SimpleCacheSpan.createCacheEntry(file, index);
|
||||||
if (file.equals(wrongEscapedV2file)) {
|
if (file.equals(wrongEscapedV2file)) {
|
||||||
assertNull(cacheEntry);
|
assertThat(cacheEntry).isNull();
|
||||||
} else {
|
} else {
|
||||||
assertNotNull(cacheEntry);
|
assertThat(cacheEntry).isNotNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(v3file.exists());
|
assertThat(v3file.exists()).isTrue();
|
||||||
assertFalse(v2file.exists());
|
assertThat(v2file.exists()).isFalse();
|
||||||
assertTrue(wrongEscapedV2file.exists());
|
assertThat(wrongEscapedV2file.exists()).isTrue();
|
||||||
assertFalse(v1File.exists());
|
assertThat(v1File.exists()).isFalse();
|
||||||
|
|
||||||
File[] files = cacheDir.listFiles();
|
File[] files = cacheDir.listFiles();
|
||||||
assertEquals(4, files.length);
|
assertThat(files).hasLength(4);
|
||||||
|
|
||||||
Set<String> keys = index.getKeys();
|
Set<String> keys = index.getKeys();
|
||||||
assertEquals("There should be only one key for all files.", 1, keys.size());
|
assertWithMessage("There should be only one key for all files.").that(keys).hasSize(1);
|
||||||
assertTrue(keys.contains(key));
|
assertThat(keys).contains(key);
|
||||||
|
|
||||||
TreeSet<SimpleCacheSpan> spans = index.get(key).getSpans();
|
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<>();
|
HashMap<Long, Long> cachedPositions = new HashMap<>();
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(file, index);
|
SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(file, index);
|
||||||
if (cacheSpan != null) {
|
if (cacheSpan != null) {
|
||||||
assertEquals(key, cacheSpan.key);
|
assertThat(cacheSpan.key).isEqualTo(key);
|
||||||
cachedPositions.put(cacheSpan.position, cacheSpan.lastAccessTimestamp);
|
cachedPositions.put(cacheSpan.position, cacheSpan.lastAccessTimestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(1, (long) cachedPositions.get((long) 0));
|
assertThat(cachedPositions.get((long) 0)).isEqualTo(1);
|
||||||
assertEquals(2, (long) cachedPositions.get((long) 1));
|
assertThat(cachedPositions.get((long) 1)).isEqualTo(2);
|
||||||
assertEquals(6, (long) cachedPositions.get((long) 5));
|
assertThat(cachedPositions.get((long) 5)).isEqualTo(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createTestFile(File file, int length) throws IOException {
|
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);
|
File cacheFile = createCacheSpanFile(cacheDir, id, offset, 1, lastAccessTimestamp);
|
||||||
SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index);
|
SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index);
|
||||||
String message = cacheFile.toString();
|
String message = cacheFile.toString();
|
||||||
assertNotNull(message, cacheSpan);
|
assertWithMessage(message).that(cacheSpan).isNotNull();
|
||||||
assertEquals(message, cacheDir, cacheFile.getParentFile());
|
assertWithMessage(message).that(cacheFile.getParentFile()).isEqualTo(cacheDir);
|
||||||
assertEquals(message, key, cacheSpan.key);
|
assertWithMessage(message).that(cacheSpan.key).isEqualTo(key);
|
||||||
assertEquals(message, offset, cacheSpan.position);
|
assertWithMessage(message).that(cacheSpan.position).isEqualTo(offset);
|
||||||
assertEquals(message, 1, cacheSpan.length);
|
assertWithMessage(message).that(cacheSpan.length).isEqualTo(1);
|
||||||
assertTrue(message, cacheSpan.isCached);
|
assertWithMessage(message).that(cacheSpan.isCached).isTrue();
|
||||||
assertEquals(message, cacheFile, cacheSpan.file);
|
assertWithMessage(message).that(cacheSpan.file).isEqualTo(cacheFile);
|
||||||
assertEquals(message, lastAccessTimestamp, cacheSpan.lastAccessTimestamp);
|
assertWithMessage(message).that(cacheSpan.lastAccessTimestamp).isEqualTo(lastAccessTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNullCacheSpan(File parent, String key, long offset,
|
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,
|
File cacheFile = SimpleCacheSpan.getCacheFile(parent, index.assignIdForKey(key), offset,
|
||||||
lastAccessTimestamp);
|
lastAccessTimestamp);
|
||||||
CacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(cacheFile, index);
|
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.
|
// Check that we really did get to the end of input.
|
||||||
assertThat(input.readFully(new byte[1], 0, 1, true)).isFalse();
|
assertThat(input.readFully(new byte[1], 0, 1, true)).isFalse();
|
||||||
|
|
||||||
assertThat(output.events).hasSize(expectedEvents.size());
|
assertThat(output.events).containsExactlyElementsIn(expectedEvents).inOrder();
|
||||||
for (int i = 0; i < expectedEvents.size(); i++) {
|
|
||||||
assertThat(output.events.get(i)).isEqualTo(expectedEvents.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -83,11 +83,9 @@ public class SimpleCacheTest {
|
||||||
addCache(simpleCache, KEY_1, 0, 15);
|
addCache(simpleCache, KEY_1, 0, 15);
|
||||||
|
|
||||||
Set<String> cachedKeys = simpleCache.getKeys();
|
Set<String> cachedKeys = simpleCache.getKeys();
|
||||||
assertThat(cachedKeys).hasSize(1);
|
assertThat(cachedKeys).containsExactly(KEY_1);
|
||||||
assertThat(cachedKeys.contains(KEY_1)).isTrue();
|
|
||||||
cachedSpans = simpleCache.getCachedSpans(KEY_1);
|
cachedSpans = simpleCache.getCachedSpans(KEY_1);
|
||||||
assertThat(cachedSpans).hasSize(1);
|
assertThat(cachedSpans).contains(cacheSpan1);
|
||||||
assertThat(cachedSpans.contains(cacheSpan1)).isTrue();
|
|
||||||
assertThat(simpleCache.getCacheSpace()).isEqualTo(15);
|
assertThat(simpleCache.getCacheSpace()).isEqualTo(15);
|
||||||
|
|
||||||
simpleCache.releaseHoleSpan(cacheSpan1);
|
simpleCache.releaseHoleSpan(cacheSpan1);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ package com.google.android.exoplayer2.util;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static java.nio.charset.Charset.forName;
|
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.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.dash;
|
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.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.drm.DrmInitData;
|
import com.google.android.exoplayer2.drm.DrmInitData;
|
||||||
|
|
@ -36,25 +38,25 @@ public final class DashUtilTest extends TestCase {
|
||||||
public void testLoadDrmInitDataFromManifest() throws Exception {
|
public void testLoadDrmInitDataFromManifest() throws Exception {
|
||||||
Period period = newPeriod(newAdaptationSets(newRepresentations(newDrmInitData())));
|
Period period = newPeriod(newAdaptationSets(newRepresentations(newDrmInitData())));
|
||||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||||
assertEquals(newDrmInitData(), drmInitData);
|
assertThat(drmInitData).isEqualTo(newDrmInitData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoadDrmInitDataMissing() throws Exception {
|
public void testLoadDrmInitDataMissing() throws Exception {
|
||||||
Period period = newPeriod(newAdaptationSets(newRepresentations(null /* no init data */)));
|
Period period = newPeriod(newAdaptationSets(newRepresentations(null /* no init data */)));
|
||||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||||
assertNull(drmInitData);
|
assertThat(drmInitData).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoadDrmInitDataNoRepresentations() throws Exception {
|
public void testLoadDrmInitDataNoRepresentations() throws Exception {
|
||||||
Period period = newPeriod(newAdaptationSets(/* no representation */));
|
Period period = newPeriod(newAdaptationSets(/* no representation */));
|
||||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||||
assertNull(drmInitData);
|
assertThat(drmInitData).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoadDrmInitDataNoAdaptationSets() throws Exception {
|
public void testLoadDrmInitDataNoAdaptationSets() throws Exception {
|
||||||
Period period = newPeriod(/* no adaptation set */);
|
Period period = newPeriod(/* no adaptation set */);
|
||||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period);
|
||||||
assertNull(drmInitData);
|
assertThat(drmInitData).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Period newPeriod(AdaptationSet... adaptationSets) {
|
private static Period newPeriod(AdaptationSet... adaptationSets) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.dash.manifest;
|
package com.google.android.exoplayer2.source.dash.manifest;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.Format;
|
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"),
|
DashManifest mpd = parser.parse(Uri.parse("https://example.com/test.mpd"),
|
||||||
TestUtil.getInputStream(getInstrumentation(), SAMPLE_MPD_3_SEGMENT_TEMPLATE));
|
TestUtil.getInputStream(getInstrumentation(), SAMPLE_MPD_3_SEGMENT_TEMPLATE));
|
||||||
|
|
||||||
assertEquals(1, mpd.getPeriodCount());
|
assertThat(mpd.getPeriodCount()).isEqualTo(1);
|
||||||
|
|
||||||
Period period = mpd.getPeriod(0);
|
Period period = mpd.getPeriod(0);
|
||||||
assertNotNull(period);
|
assertThat(period).isNotNull();
|
||||||
assertEquals(2, period.adaptationSets.size());
|
assertThat(period.adaptationSets).hasSize(2);
|
||||||
|
|
||||||
for (AdaptationSet adaptationSet : period.adaptationSets) {
|
for (AdaptationSet adaptationSet : period.adaptationSets) {
|
||||||
assertNotNull(adaptationSet);
|
assertThat(adaptationSet).isNotNull();
|
||||||
for (Representation representation : adaptationSet.representations) {
|
for (Representation representation : adaptationSet.representations) {
|
||||||
if (representation instanceof Representation.MultiSegmentRepresentation) {
|
if (representation instanceof Representation.MultiSegmentRepresentation) {
|
||||||
Representation.MultiSegmentRepresentation multiSegmentRepresentation =
|
Representation.MultiSegmentRepresentation multiSegmentRepresentation =
|
||||||
(Representation.MultiSegmentRepresentation) representation;
|
(Representation.MultiSegmentRepresentation) representation;
|
||||||
int firstSegmentIndex = multiSegmentRepresentation.getFirstSegmentNum();
|
int firstSegmentIndex = multiSegmentRepresentation.getFirstSegmentNum();
|
||||||
RangedUri uri = multiSegmentRepresentation.getSegmentUrl(firstSegmentIndex);
|
RangedUri uri = multiSegmentRepresentation.getSegmentUrl(firstSegmentIndex);
|
||||||
assertTrue(uri.resolveUriString(representation.baseUrl).contains(
|
assertThat(
|
||||||
"redirector.googlevideo.com"));
|
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));
|
TestUtil.getInputStream(getInstrumentation(), SAMPLE_MPD_4_EVENT_STREAM));
|
||||||
|
|
||||||
Period period = mpd.getPeriod(0);
|
Period period = mpd.getPeriod(0);
|
||||||
assertEquals(3, period.eventStreams.size());
|
assertThat(period.eventStreams).hasSize(3);
|
||||||
|
|
||||||
// assert text-only event stream
|
// assert text-only event stream
|
||||||
EventStream eventStream1 = period.eventStreams.get(0);
|
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,
|
EventMessage expectedEvent1 = new EventMessage("urn:uuid:XYZY", "call", 10000, 0,
|
||||||
"+ 1 800 10101010".getBytes(), 0);
|
"+ 1 800 10101010".getBytes(), 0);
|
||||||
assertEquals(expectedEvent1, eventStream1.events[0]);
|
assertThat(eventStream1.events[0]).isEqualTo(expectedEvent1);
|
||||||
|
|
||||||
// assert CData-structured event stream
|
// assert CData-structured event stream
|
||||||
EventStream eventStream2 = period.eventStreams.get(1);
|
EventStream eventStream2 = period.eventStreams.get(1);
|
||||||
assertEquals(1, eventStream2.events.length);
|
assertThat(eventStream2.events.length).isEqualTo(1);
|
||||||
assertEquals(
|
assertThat(eventStream2.events[0])
|
||||||
new EventMessage("urn:dvb:iptv:cpm:2014", "", 1500000, 1,
|
.isEqualTo(
|
||||||
("<![CDATA[<BroadcastEvent>\n"
|
new EventMessage(
|
||||||
+ " <Program crid=\"crid://broadcaster.example.com/ABCDEF\"/>\n"
|
"urn:dvb:iptv:cpm:2014",
|
||||||
+ " <InstanceDescription>\n"
|
"",
|
||||||
+ " <Title xml:lang=\"en\">The title</Title>\n"
|
1500000,
|
||||||
+ " <Synopsis xml:lang=\"en\" length=\"medium\">The description</Synopsis>\n"
|
1,
|
||||||
+ " <ParentalGuidance>\n"
|
("<![CDATA[<BroadcastEvent>\n"
|
||||||
+ " <mpeg7:ParentalRating href=\"urn:dvb:iptv:rating:2014:15\"/>\n"
|
+ " <Program crid=\"crid://broadcaster.example.com/ABCDEF\"/>\n"
|
||||||
+ " <mpeg7:Region>GB</mpeg7:Region>\n"
|
+ " <InstanceDescription>\n"
|
||||||
+ " </ParentalGuidance>\n"
|
+ " <Title xml:lang=\"en\">The title</Title>\n"
|
||||||
+ " </InstanceDescription>\n"
|
+ " <Synopsis xml:lang=\"en\" length=\"medium\">"
|
||||||
+ " </BroadcastEvent>]]>").getBytes(), 300000000),
|
+ "The description</Synopsis>\n"
|
||||||
eventStream2.events[0]);
|
+ " <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
|
// assert xml-structured event stream
|
||||||
EventStream eventStream3 = period.eventStreams.get(2);
|
EventStream eventStream3 = period.eventStreams.get(2);
|
||||||
assertEquals(1, eventStream3.events.length);
|
assertThat(eventStream3.events.length).isEqualTo(1);
|
||||||
assertEquals(
|
assertThat(eventStream3.events[0])
|
||||||
new EventMessage("urn:scte:scte35:2014:xml+bin", "", 1000000, 2,
|
.isEqualTo(
|
||||||
("<scte35:Signal>\n"
|
new EventMessage(
|
||||||
+ " <scte35:Binary>\n"
|
"urn:scte:scte35:2014:xml+bin",
|
||||||
+ " /DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==\n"
|
"",
|
||||||
+ " </scte35:Binary>\n"
|
1000000,
|
||||||
+ " </scte35:Signal>").getBytes(), 1000000000),
|
2,
|
||||||
eventStream3.events[0]);
|
("<scte35:Signal>\n"
|
||||||
|
+ " <scte35:Binary>\n"
|
||||||
|
+ " /DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==\n"
|
||||||
|
+ " </scte35:Binary>\n"
|
||||||
|
+ " </scte35:Signal>")
|
||||||
|
.getBytes(),
|
||||||
|
1000000000));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseCea608AccessibilityChannel() {
|
public void testParseCea608AccessibilityChannel() {
|
||||||
assertEquals(1, DashManifestParser.parseCea608AccessibilityChannel(
|
assertThat(
|
||||||
buildCea608AccessibilityDescriptors("CC1=eng")));
|
DashManifestParser.parseCea608AccessibilityChannel(
|
||||||
assertEquals(2, DashManifestParser.parseCea608AccessibilityChannel(
|
buildCea608AccessibilityDescriptors("CC1=eng")))
|
||||||
buildCea608AccessibilityDescriptors("CC2=eng")));
|
.isEqualTo(1);
|
||||||
assertEquals(3, DashManifestParser.parseCea608AccessibilityChannel(
|
assertThat(
|
||||||
buildCea608AccessibilityDescriptors("CC3=eng")));
|
DashManifestParser.parseCea608AccessibilityChannel(
|
||||||
assertEquals(4, DashManifestParser.parseCea608AccessibilityChannel(
|
buildCea608AccessibilityDescriptors("CC2=eng")))
|
||||||
buildCea608AccessibilityDescriptors("CC4=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(
|
assertThat(
|
||||||
buildCea608AccessibilityDescriptors(null)));
|
DashManifestParser.parseCea608AccessibilityChannel(
|
||||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
buildCea608AccessibilityDescriptors(null)))
|
||||||
buildCea608AccessibilityDescriptors("")));
|
.isEqualTo(Format.NO_VALUE);
|
||||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
assertThat(
|
||||||
buildCea608AccessibilityDescriptors("CC0=eng")));
|
DashManifestParser.parseCea608AccessibilityChannel(
|
||||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
buildCea608AccessibilityDescriptors("")))
|
||||||
buildCea608AccessibilityDescriptors("CC5=eng")));
|
.isEqualTo(Format.NO_VALUE);
|
||||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea608AccessibilityChannel(
|
assertThat(
|
||||||
buildCea608AccessibilityDescriptors("Wrong format")));
|
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() {
|
public void testParseCea708AccessibilityChannel() {
|
||||||
assertEquals(1, DashManifestParser.parseCea708AccessibilityChannel(
|
assertThat(
|
||||||
buildCea708AccessibilityDescriptors("1=lang:eng")));
|
DashManifestParser.parseCea708AccessibilityChannel(
|
||||||
assertEquals(2, DashManifestParser.parseCea708AccessibilityChannel(
|
buildCea708AccessibilityDescriptors("1=lang:eng")))
|
||||||
buildCea708AccessibilityDescriptors("2=lang:eng")));
|
.isEqualTo(1);
|
||||||
assertEquals(3, DashManifestParser.parseCea708AccessibilityChannel(
|
assertThat(
|
||||||
buildCea708AccessibilityDescriptors("3=lang:eng")));
|
DashManifestParser.parseCea708AccessibilityChannel(
|
||||||
assertEquals(62, DashManifestParser.parseCea708AccessibilityChannel(
|
buildCea708AccessibilityDescriptors("2=lang:eng")))
|
||||||
buildCea708AccessibilityDescriptors("62=lang:eng")));
|
.isEqualTo(2);
|
||||||
assertEquals(63, DashManifestParser.parseCea708AccessibilityChannel(
|
assertThat(
|
||||||
buildCea708AccessibilityDescriptors("63=lang:eng")));
|
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(
|
assertThat(
|
||||||
buildCea708AccessibilityDescriptors(null)));
|
DashManifestParser.parseCea708AccessibilityChannel(
|
||||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
buildCea708AccessibilityDescriptors(null)))
|
||||||
buildCea708AccessibilityDescriptors("")));
|
.isEqualTo(Format.NO_VALUE);
|
||||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
assertThat(
|
||||||
buildCea708AccessibilityDescriptors("0=lang:eng")));
|
DashManifestParser.parseCea708AccessibilityChannel(
|
||||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
buildCea708AccessibilityDescriptors("")))
|
||||||
buildCea708AccessibilityDescriptors("64=lang:eng")));
|
.isEqualTo(Format.NO_VALUE);
|
||||||
assertEquals(Format.NO_VALUE, DashManifestParser.parseCea708AccessibilityChannel(
|
assertThat(
|
||||||
buildCea708AccessibilityDescriptors("Wrong format")));
|
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) {
|
private static List<Descriptor> buildCea608AccessibilityDescriptors(String value) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.dash.manifest;
|
package com.google.android.exoplayer2.source.dash.manifest;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
|
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) {
|
private static void assertManifestEquals(DashManifest expected, DashManifest actual) {
|
||||||
assertEquals(expected.availabilityStartTimeMs, actual.availabilityStartTimeMs);
|
assertThat(actual.availabilityStartTimeMs).isEqualTo(expected.availabilityStartTimeMs);
|
||||||
assertEquals(expected.durationMs, actual.durationMs);
|
assertThat(actual.durationMs).isEqualTo(expected.durationMs);
|
||||||
assertEquals(expected.minBufferTimeMs, actual.minBufferTimeMs);
|
assertThat(actual.minBufferTimeMs).isEqualTo(expected.minBufferTimeMs);
|
||||||
assertEquals(expected.dynamic, actual.dynamic);
|
assertThat(actual.dynamic).isEqualTo(expected.dynamic);
|
||||||
assertEquals(expected.minUpdatePeriodMs, actual.minUpdatePeriodMs);
|
assertThat(actual.minUpdatePeriodMs).isEqualTo(expected.minUpdatePeriodMs);
|
||||||
assertEquals(expected.timeShiftBufferDepthMs, actual.timeShiftBufferDepthMs);
|
assertThat(actual.timeShiftBufferDepthMs).isEqualTo(expected.timeShiftBufferDepthMs);
|
||||||
assertEquals(expected.suggestedPresentationDelayMs, actual.suggestedPresentationDelayMs);
|
assertThat(actual.suggestedPresentationDelayMs)
|
||||||
assertEquals(expected.publishTimeMs, actual.publishTimeMs);
|
.isEqualTo(expected.suggestedPresentationDelayMs);
|
||||||
assertEquals(expected.utcTiming, actual.utcTiming);
|
assertThat(actual.publishTimeMs).isEqualTo(expected.publishTimeMs);
|
||||||
assertEquals(expected.location, actual.location);
|
assertThat(actual.utcTiming).isEqualTo(expected.utcTiming);
|
||||||
assertEquals(expected.getPeriodCount(), actual.getPeriodCount());
|
assertThat(actual.location).isEqualTo(expected.location);
|
||||||
|
assertThat(actual.getPeriodCount()).isEqualTo(expected.getPeriodCount());
|
||||||
for (int i = 0; i < expected.getPeriodCount(); i++) {
|
for (int i = 0; i < expected.getPeriodCount(); i++) {
|
||||||
Period expectedPeriod = expected.getPeriod(i);
|
Period expectedPeriod = expected.getPeriod(i);
|
||||||
Period actualPeriod = actual.getPeriod(i);
|
Period actualPeriod = actual.getPeriod(i);
|
||||||
assertEquals(expectedPeriod.id, actualPeriod.id);
|
assertThat(actualPeriod.id).isEqualTo(expectedPeriod.id);
|
||||||
assertEquals(expectedPeriod.startMs, actualPeriod.startMs);
|
assertThat(actualPeriod.startMs).isEqualTo(expectedPeriod.startMs);
|
||||||
List<AdaptationSet> expectedAdaptationSets = expectedPeriod.adaptationSets;
|
List<AdaptationSet> expectedAdaptationSets = expectedPeriod.adaptationSets;
|
||||||
List<AdaptationSet> actualAdaptationSets = actualPeriod.adaptationSets;
|
List<AdaptationSet> actualAdaptationSets = actualPeriod.adaptationSets;
|
||||||
assertEquals(expectedAdaptationSets.size(), actualAdaptationSets.size());
|
assertThat(actualAdaptationSets).hasSize(expectedAdaptationSets.size());
|
||||||
for (int j = 0; j < expectedAdaptationSets.size(); j++) {
|
for (int j = 0; j < expectedAdaptationSets.size(); j++) {
|
||||||
AdaptationSet expectedAdaptationSet = expectedAdaptationSets.get(j);
|
AdaptationSet expectedAdaptationSet = expectedAdaptationSets.get(j);
|
||||||
AdaptationSet actualAdaptationSet = actualAdaptationSets.get(j);
|
AdaptationSet actualAdaptationSet = actualAdaptationSets.get(j);
|
||||||
assertEquals(expectedAdaptationSet.id, actualAdaptationSet.id);
|
assertThat(actualAdaptationSet.id).isEqualTo(expectedAdaptationSet.id);
|
||||||
assertEquals(expectedAdaptationSet.type, actualAdaptationSet.type);
|
assertThat(actualAdaptationSet.type).isEqualTo(expectedAdaptationSet.type);
|
||||||
assertEquals(expectedAdaptationSet.accessibilityDescriptors,
|
assertThat(actualAdaptationSet.accessibilityDescriptors)
|
||||||
actualAdaptationSet.accessibilityDescriptors);
|
.isEqualTo(expectedAdaptationSet.accessibilityDescriptors);
|
||||||
assertEquals(expectedAdaptationSet.representations, actualAdaptationSet.representations);
|
assertThat(actualAdaptationSet.representations)
|
||||||
|
.isEqualTo(expectedAdaptationSet.representations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.dash.manifest;
|
package com.google.android.exoplayer2.source.dash.manifest;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
|
@ -72,16 +74,16 @@ public class RangedUriTest extends TestCase {
|
||||||
|
|
||||||
private void assertMerge(RangedUri rangeA, RangedUri rangeB, RangedUri expected, String baseUrl) {
|
private void assertMerge(RangedUri rangeA, RangedUri rangeB, RangedUri expected, String baseUrl) {
|
||||||
RangedUri merged = rangeA.attemptMerge(rangeB, baseUrl);
|
RangedUri merged = rangeA.attemptMerge(rangeB, baseUrl);
|
||||||
assertEquals(expected, merged);
|
assertThat(merged).isEqualTo(expected);
|
||||||
merged = rangeB.attemptMerge(rangeA, baseUrl);
|
merged = rangeB.attemptMerge(rangeA, baseUrl);
|
||||||
assertEquals(expected, merged);
|
assertThat(merged).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNonMerge(RangedUri rangeA, RangedUri rangeB, String baseUrl) {
|
private void assertNonMerge(RangedUri rangeA, RangedUri rangeB, String baseUrl) {
|
||||||
RangedUri merged = rangeA.attemptMerge(rangeB, baseUrl);
|
RangedUri merged = rangeA.attemptMerge(rangeB, baseUrl);
|
||||||
assertNull(merged);
|
assertThat(merged).isNull();
|
||||||
merged = rangeB.attemptMerge(rangeA, baseUrl);
|
merged = rangeB.attemptMerge(rangeA, baseUrl);
|
||||||
assertNull(merged);
|
assertThat(merged).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.dash.manifest;
|
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.Format;
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
|
import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
|
||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
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);
|
MimeTypes.VIDEO_H264, 2500000, 1920, 1080, Format.NO_VALUE, null, 0);
|
||||||
Representation representation = Representation.newInstance("test_stream_1", 3, format, uri,
|
Representation representation = Representation.newInstance("test_stream_1", 3, format, uri,
|
||||||
base);
|
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,
|
format = Format.createVideoContainerFormat("150", MimeTypes.APPLICATION_MP4, null,
|
||||||
MimeTypes.VIDEO_H264, 2500000, 1920, 1080, Format.NO_VALUE, null, 0);
|
MimeTypes.VIDEO_H264, 2500000, 1920, 1080, Format.NO_VALUE, null, 0);
|
||||||
representation = Representation.newInstance("test_stream_1", Representation.REVISION_ID_DEFAULT,
|
representation = Representation.newInstance("test_stream_1", Representation.REVISION_ID_DEFAULT,
|
||||||
format, uri, base);
|
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;
|
package com.google.android.exoplayer2.source.dash.manifest;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,31 +28,31 @@ public class UrlTemplateTest extends TestCase {
|
||||||
String template = "QualityLevels($Bandwidth$)/Fragments(video=$Time$,format=mpd-time-csf)";
|
String template = "QualityLevels($Bandwidth$)/Fragments(video=$Time$,format=mpd-time-csf)";
|
||||||
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
||||||
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
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$";
|
template = "$RepresentationID$/$Number$";
|
||||||
urlTemplate = UrlTemplate.compile(template);
|
urlTemplate = UrlTemplate.compile(template);
|
||||||
url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
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";
|
template = "chunk_ctvideo_cfm4s_rid$RepresentationID$_cn$Number$_w2073857842_mpd.m4s";
|
||||||
urlTemplate = UrlTemplate.compile(template);
|
urlTemplate = UrlTemplate.compile(template);
|
||||||
url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
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() {
|
public void testFull() {
|
||||||
String template = "$Bandwidth$_a_$RepresentationID$_b_$Time$_c_$Number$";
|
String template = "$Bandwidth$_a_$RepresentationID$_b_$Time$_c_$Number$";
|
||||||
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
||||||
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
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() {
|
public void testFullWithDollarEscaping() {
|
||||||
String template = "$$$Bandwidth$$$_a$$_$RepresentationID$_b_$Time$_c_$Number$$$";
|
String template = "$$$Bandwidth$$$_a$$_$RepresentationID$_b_$Time$_c_$Number$$$";
|
||||||
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
||||||
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
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() {
|
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.assertCacheEmpty;
|
||||||
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData;
|
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData;
|
||||||
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertDataCached;
|
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 android.test.InstrumentationTestCase;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
|
@ -73,7 +76,7 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
DashManifest manifest = dashDownloader.getManifest();
|
DashManifest manifest = dashDownloader.getManifest();
|
||||||
|
|
||||||
assertNotNull(manifest);
|
assertThat(manifest).isNotNull();
|
||||||
assertCachedData(cache, fakeDataSet);
|
assertCachedData(cache, fakeDataSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +104,7 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
||||||
// on the second try it downloads the rest of the data
|
// on the second try it downloads the rest of the data
|
||||||
DashManifest manifest = dashDownloader.getManifest();
|
DashManifest manifest = dashDownloader.getManifest();
|
||||||
|
|
||||||
assertNotNull(manifest);
|
assertThat(manifest).isNotNull();
|
||||||
assertCachedData(cache, fakeDataSet);
|
assertCachedData(cache, fakeDataSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,8 +206,8 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
||||||
.setRandomData("text_segment_2", 2)
|
.setRandomData("text_segment_2", 2)
|
||||||
.setRandomData("text_segment_3", 3);
|
.setRandomData("text_segment_3", 3);
|
||||||
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
|
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
|
||||||
Factory factory = Mockito.mock(Factory.class);
|
Factory factory = mock(Factory.class);
|
||||||
Mockito.when(factory.createDataSource()).thenReturn(fakeDataSource);
|
when(factory.createDataSource()).thenReturn(fakeDataSource);
|
||||||
DashDownloader dashDownloader = new DashDownloader(TEST_MPD_URI,
|
DashDownloader dashDownloader = new DashDownloader(TEST_MPD_URI,
|
||||||
new DownloaderConstructorHelper(cache, factory));
|
new DownloaderConstructorHelper(cache, factory));
|
||||||
|
|
||||||
|
|
@ -213,15 +216,15 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
||||||
dashDownloader.download(null);
|
dashDownloader.download(null);
|
||||||
|
|
||||||
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
|
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
|
||||||
assertEquals(8, openedDataSpecs.length);
|
assertThat(openedDataSpecs.length).isEqualTo(8);
|
||||||
assertEquals(TEST_MPD_URI, openedDataSpecs[0].uri);
|
assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
|
||||||
assertEquals("audio_init_data", openedDataSpecs[1].uri.getPath());
|
assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
|
||||||
assertEquals("audio_segment_1", openedDataSpecs[2].uri.getPath());
|
assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
|
||||||
assertEquals("text_segment_1", openedDataSpecs[3].uri.getPath());
|
assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("text_segment_1");
|
||||||
assertEquals("audio_segment_2", openedDataSpecs[4].uri.getPath());
|
assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_2");
|
||||||
assertEquals("text_segment_2", openedDataSpecs[5].uri.getPath());
|
assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("text_segment_2");
|
||||||
assertEquals("audio_segment_3", openedDataSpecs[6].uri.getPath());
|
assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("audio_segment_3");
|
||||||
assertEquals("text_segment_3", openedDataSpecs[7].uri.getPath());
|
assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("text_segment_3");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testProgressiveDownloadSeparatePeriods() throws Exception {
|
public void testProgressiveDownloadSeparatePeriods() throws Exception {
|
||||||
|
|
@ -235,8 +238,8 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
||||||
.setRandomData("period_2_segment_2", 2)
|
.setRandomData("period_2_segment_2", 2)
|
||||||
.setRandomData("period_2_segment_3", 3);
|
.setRandomData("period_2_segment_3", 3);
|
||||||
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
|
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
|
||||||
Factory factory = Mockito.mock(Factory.class);
|
Factory factory = mock(Factory.class);
|
||||||
Mockito.when(factory.createDataSource()).thenReturn(fakeDataSource);
|
when(factory.createDataSource()).thenReturn(fakeDataSource);
|
||||||
DashDownloader dashDownloader = new DashDownloader(TEST_MPD_URI,
|
DashDownloader dashDownloader = new DashDownloader(TEST_MPD_URI,
|
||||||
new DownloaderConstructorHelper(cache, factory));
|
new DownloaderConstructorHelper(cache, factory));
|
||||||
|
|
||||||
|
|
@ -245,15 +248,15 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
||||||
dashDownloader.download(null);
|
dashDownloader.download(null);
|
||||||
|
|
||||||
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
|
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
|
||||||
assertEquals(8, openedDataSpecs.length);
|
assertThat(openedDataSpecs.length).isEqualTo(8);
|
||||||
assertEquals(TEST_MPD_URI, openedDataSpecs[0].uri);
|
assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
|
||||||
assertEquals("audio_init_data", openedDataSpecs[1].uri.getPath());
|
assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
|
||||||
assertEquals("audio_segment_1", openedDataSpecs[2].uri.getPath());
|
assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
|
||||||
assertEquals("audio_segment_2", openedDataSpecs[3].uri.getPath());
|
assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("audio_segment_2");
|
||||||
assertEquals("audio_segment_3", openedDataSpecs[4].uri.getPath());
|
assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_3");
|
||||||
assertEquals("period_2_segment_1", openedDataSpecs[5].uri.getPath());
|
assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("period_2_segment_1");
|
||||||
assertEquals("period_2_segment_2", openedDataSpecs[6].uri.getPath());
|
assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("period_2_segment_2");
|
||||||
assertEquals("period_2_segment_3", openedDataSpecs[7].uri.getPath());
|
assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("period_2_segment_3");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDownloadRepresentationFailure() throws Exception {
|
public void testDownloadRepresentationFailure() throws Exception {
|
||||||
|
|
@ -400,9 +403,9 @@ public class DashDownloaderTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
private static void assertCounters(DashDownloader dashDownloader, int totalSegments,
|
private static void assertCounters(DashDownloader dashDownloader, int totalSegments,
|
||||||
int downloadedSegments, int downloadedBytes) {
|
int downloadedSegments, int downloadedBytes) {
|
||||||
assertEquals(totalSegments, dashDownloader.getTotalSegments());
|
assertThat(dashDownloader.getTotalSegments()).isEqualTo(totalSegments);
|
||||||
assertEquals(downloadedSegments, dashDownloader.getDownloadedSegments());
|
assertThat(dashDownloader.getDownloadedSegments()).isEqualTo(downloadedSegments);
|
||||||
assertEquals(downloadedBytes, dashDownloader.getDownloadedBytes());
|
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.source.hls.offline.HlsDownloadTestData.MEDIA_PLAYLIST_DATA;
|
||||||
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCacheEmpty;
|
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.assertCachedData;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
|
|
@ -78,7 +79,7 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
|
||||||
public void testDownloadManifest() throws Exception {
|
public void testDownloadManifest() throws Exception {
|
||||||
HlsMasterPlaylist manifest = hlsDownloader.getManifest();
|
HlsMasterPlaylist manifest = hlsDownloader.getManifest();
|
||||||
|
|
||||||
assertNotNull(manifest);
|
assertThat(manifest).isNotNull();
|
||||||
assertCachedData(cache, fakeDataSet, MASTER_PLAYLIST_URI);
|
assertCachedData(cache, fakeDataSet, MASTER_PLAYLIST_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,9 +98,10 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
|
||||||
hlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
|
hlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
|
||||||
hlsDownloader.download(null);
|
hlsDownloader.download(null);
|
||||||
|
|
||||||
assertEquals(4, hlsDownloader.getTotalSegments());
|
assertThat(hlsDownloader.getTotalSegments()).isEqualTo(4);
|
||||||
assertEquals(4, hlsDownloader.getDownloadedSegments());
|
assertThat(hlsDownloader.getDownloadedSegments()).isEqualTo(4);
|
||||||
assertEquals(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12, hlsDownloader.getDownloadedBytes());
|
assertThat(hlsDownloader.getDownloadedBytes())
|
||||||
|
.isEqualTo(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInitStatus() throws Exception {
|
public void testInitStatus() throws Exception {
|
||||||
|
|
@ -111,9 +113,10 @@ public class HlsDownloaderTest extends InstrumentationTestCase {
|
||||||
newHlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
|
newHlsDownloader.selectRepresentations(new String[] {MEDIA_PLAYLIST_1_URI});
|
||||||
newHlsDownloader.init();
|
newHlsDownloader.init();
|
||||||
|
|
||||||
assertEquals(4, newHlsDownloader.getTotalSegments());
|
assertThat(newHlsDownloader.getTotalSegments()).isEqualTo(4);
|
||||||
assertEquals(4, newHlsDownloader.getDownloadedSegments());
|
assertThat(newHlsDownloader.getDownloadedSegments()).isEqualTo(4);
|
||||||
assertEquals(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12, newHlsDownloader.getDownloadedBytes());
|
assertThat(newHlsDownloader.getDownloadedBytes())
|
||||||
|
.isEqualTo(MEDIA_PLAYLIST_DATA.length + 10 + 11 + 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDownloadRepresentation() throws Exception {
|
public void testDownloadRepresentation() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.hls.playlist;
|
package com.google.android.exoplayer2.source.hls.playlist;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
|
|
@ -23,7 +25,6 @@ import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import junit.framework.TestCase;
|
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\","
|
+ "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"aud2\",LANGUAGE=\"en\",NAME=\"English\","
|
||||||
+ "AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"6\",URI=\"a2/prog_index.m3u8\"\n";
|
+ "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);
|
HlsMasterPlaylist masterPlaylist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_SIMPLE);
|
||||||
|
|
||||||
List<HlsMasterPlaylist.HlsUrl> variants = masterPlaylist.variants;
|
List<HlsMasterPlaylist.HlsUrl> variants = masterPlaylist.variants;
|
||||||
assertEquals(5, variants.size());
|
assertThat(variants).hasSize(5);
|
||||||
assertNull(masterPlaylist.muxedCaptionFormats);
|
assertThat(masterPlaylist.muxedCaptionFormats).isNull();
|
||||||
|
|
||||||
assertEquals(1280000, variants.get(0).format.bitrate);
|
assertThat(variants.get(0).format.bitrate).isEqualTo(1280000);
|
||||||
assertEquals("mp4a.40.2,avc1.66.30", variants.get(0).format.codecs);
|
assertThat(variants.get(0).format.codecs).isEqualTo("mp4a.40.2,avc1.66.30");
|
||||||
assertEquals(304, variants.get(0).format.width);
|
assertThat(variants.get(0).format.width).isEqualTo(304);
|
||||||
assertEquals(128, variants.get(0).format.height);
|
assertThat(variants.get(0).format.height).isEqualTo(128);
|
||||||
assertEquals("http://example.com/low.m3u8", variants.get(0).url);
|
assertThat(variants.get(0).url).isEqualTo("http://example.com/low.m3u8");
|
||||||
|
|
||||||
assertEquals(1280000, variants.get(1).format.bitrate);
|
assertThat(variants.get(1).format.bitrate).isEqualTo(1280000);
|
||||||
assertEquals("mp4a.40.2 , avc1.66.30 ", variants.get(1).format.codecs);
|
assertThat(variants.get(1).format.codecs).isEqualTo("mp4a.40.2 , avc1.66.30 ");
|
||||||
assertEquals("http://example.com/spaces_in_codecs.m3u8", variants.get(1).url);
|
assertThat(variants.get(1).url).isEqualTo("http://example.com/spaces_in_codecs.m3u8");
|
||||||
|
|
||||||
assertEquals(2560000, variants.get(2).format.bitrate);
|
assertThat(variants.get(2).format.bitrate).isEqualTo(2560000);
|
||||||
assertNull(variants.get(2).format.codecs);
|
assertThat(variants.get(2).format.codecs).isNull();
|
||||||
assertEquals(384, variants.get(2).format.width);
|
assertThat(variants.get(2).format.width).isEqualTo(384);
|
||||||
assertEquals(160, variants.get(2).format.height);
|
assertThat(variants.get(2).format.height).isEqualTo(160);
|
||||||
assertEquals(25.0f, variants.get(2).format.frameRate);
|
assertThat(variants.get(2).format.frameRate).isEqualTo(25.0f);
|
||||||
assertEquals("http://example.com/mid.m3u8", variants.get(2).url);
|
assertThat(variants.get(2).url).isEqualTo("http://example.com/mid.m3u8");
|
||||||
|
|
||||||
assertEquals(7680000, variants.get(3).format.bitrate);
|
assertThat(variants.get(3).format.bitrate).isEqualTo(7680000);
|
||||||
assertNull(variants.get(3).format.codecs);
|
assertThat(variants.get(3).format.codecs).isNull();
|
||||||
assertEquals(Format.NO_VALUE, variants.get(3).format.width);
|
assertThat(variants.get(3).format.width).isEqualTo(Format.NO_VALUE);
|
||||||
assertEquals(Format.NO_VALUE, variants.get(3).format.height);
|
assertThat(variants.get(3).format.height).isEqualTo(Format.NO_VALUE);
|
||||||
assertEquals(29.997f, variants.get(3).format.frameRate);
|
assertThat(variants.get(3).format.frameRate).isEqualTo(29.997f);
|
||||||
assertEquals("http://example.com/hi.m3u8", variants.get(3).url);
|
assertThat(variants.get(3).url).isEqualTo("http://example.com/hi.m3u8");
|
||||||
|
|
||||||
assertEquals(65000, variants.get(4).format.bitrate);
|
assertThat(variants.get(4).format.bitrate).isEqualTo(65000);
|
||||||
assertEquals("mp4a.40.5", variants.get(4).format.codecs);
|
assertThat(variants.get(4).format.codecs).isEqualTo("mp4a.40.5");
|
||||||
assertEquals(Format.NO_VALUE, variants.get(4).format.width);
|
assertThat(variants.get(4).format.width).isEqualTo(Format.NO_VALUE);
|
||||||
assertEquals(Format.NO_VALUE, variants.get(4).format.height);
|
assertThat(variants.get(4).format.height).isEqualTo(Format.NO_VALUE);
|
||||||
assertEquals((float) Format.NO_VALUE, variants.get(4).format.frameRate);
|
assertThat(variants.get(4).format.frameRate).isEqualTo((float) Format.NO_VALUE);
|
||||||
assertEquals("http://example.com/audio-only.m3u8", variants.get(4).url);
|
assertThat(variants.get(4).url).isEqualTo("http://example.com/audio-only.m3u8");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMasterPlaylistWithBandwdithAverage() throws IOException {
|
public void testMasterPlaylistWithBandwdithAverage() throws IOException {
|
||||||
|
|
@ -134,8 +135,8 @@ public class HlsMasterPlaylistParserTest extends TestCase {
|
||||||
|
|
||||||
List<HlsMasterPlaylist.HlsUrl> variants = masterPlaylist.variants;
|
List<HlsMasterPlaylist.HlsUrl> variants = masterPlaylist.variants;
|
||||||
|
|
||||||
assertEquals(1280000, variants.get(0).format.bitrate);
|
assertThat(variants.get(0).format.bitrate).isEqualTo(1280000);
|
||||||
assertEquals(1270000, variants.get(1).format.bitrate);
|
assertThat(variants.get(1).format.bitrate).isEqualTo(1270000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPlaylistWithInvalidHeader() throws IOException {
|
public void testPlaylistWithInvalidHeader() throws IOException {
|
||||||
|
|
@ -149,28 +150,28 @@ public class HlsMasterPlaylistParserTest extends TestCase {
|
||||||
|
|
||||||
public void testPlaylistWithClosedCaption() throws IOException {
|
public void testPlaylistWithClosedCaption() throws IOException {
|
||||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_CC);
|
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_CC);
|
||||||
assertEquals(1, playlist.muxedCaptionFormats.size());
|
assertThat(playlist.muxedCaptionFormats).hasSize(1);
|
||||||
Format closedCaptionFormat = playlist.muxedCaptionFormats.get(0);
|
Format closedCaptionFormat = playlist.muxedCaptionFormats.get(0);
|
||||||
assertEquals(MimeTypes.APPLICATION_CEA708, closedCaptionFormat.sampleMimeType);
|
assertThat(closedCaptionFormat.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_CEA708);
|
||||||
assertEquals(4, closedCaptionFormat.accessibilityChannel);
|
assertThat(closedCaptionFormat.accessibilityChannel).isEqualTo(4);
|
||||||
assertEquals("es", closedCaptionFormat.language);
|
assertThat(closedCaptionFormat.language).isEqualTo("es");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPlaylistWithoutClosedCaptions() throws IOException {
|
public void testPlaylistWithoutClosedCaptions() throws IOException {
|
||||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITHOUT_CC);
|
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITHOUT_CC);
|
||||||
assertEquals(Collections.emptyList(), playlist.muxedCaptionFormats);
|
assertThat(playlist.muxedCaptionFormats).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCodecPropagation() throws IOException {
|
public void testCodecPropagation() throws IOException {
|
||||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_AUDIO_MEDIA_TAG);
|
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_AUDIO_MEDIA_TAG);
|
||||||
|
|
||||||
Format firstAudioFormat = playlist.audios.get(0).format;
|
Format firstAudioFormat = playlist.audios.get(0).format;
|
||||||
assertEquals("mp4a.40.2", firstAudioFormat.codecs);
|
assertThat(firstAudioFormat.codecs).isEqualTo("mp4a.40.2");
|
||||||
assertEquals(MimeTypes.AUDIO_AAC, firstAudioFormat.sampleMimeType);
|
assertThat(firstAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
|
||||||
|
|
||||||
Format secondAudioFormat = playlist.audios.get(1).format;
|
Format secondAudioFormat = playlist.audios.get(1).format;
|
||||||
assertEquals("ac-3", secondAudioFormat.codecs);
|
assertThat(secondAudioFormat.codecs).isEqualTo("ac-3");
|
||||||
assertEquals(MimeTypes.AUDIO_AC3, secondAudioFormat.sampleMimeType);
|
assertThat(secondAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AC3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HlsMasterPlaylist parseMasterPlaylist(String uri, String playlistString)
|
private static HlsMasterPlaylist parseMasterPlaylist(String uri, String playlistString)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.hls.playlist;
|
package com.google.android.exoplayer2.source.hls.playlist;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment;
|
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)));
|
playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
|
||||||
try {
|
try {
|
||||||
HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUri, inputStream);
|
HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUri, inputStream);
|
||||||
assertNotNull(playlist);
|
assertThat(playlist).isNotNull();
|
||||||
|
|
||||||
HlsMediaPlaylist mediaPlaylist = (HlsMediaPlaylist) playlist;
|
HlsMediaPlaylist mediaPlaylist = (HlsMediaPlaylist) playlist;
|
||||||
assertEquals(HlsMediaPlaylist.PLAYLIST_TYPE_VOD, mediaPlaylist.playlistType);
|
assertThat(mediaPlaylist.playlistType).isEqualTo(HlsMediaPlaylist.PLAYLIST_TYPE_VOD);
|
||||||
assertEquals(mediaPlaylist.durationUs - 25000000, mediaPlaylist.startOffsetUs);
|
assertThat(mediaPlaylist.startOffsetUs).isEqualTo(mediaPlaylist.durationUs - 25000000);
|
||||||
|
|
||||||
assertEquals(2679, mediaPlaylist.mediaSequence);
|
assertThat(mediaPlaylist.mediaSequence).isEqualTo(2679);
|
||||||
assertEquals(3, mediaPlaylist.version);
|
assertThat(mediaPlaylist.version).isEqualTo(3);
|
||||||
assertTrue(mediaPlaylist.hasEndTag);
|
assertThat(mediaPlaylist.hasEndTag).isTrue();
|
||||||
List<Segment> segments = mediaPlaylist.segments;
|
List<Segment> segments = mediaPlaylist.segments;
|
||||||
assertNotNull(segments);
|
assertThat(segments).isNotNull();
|
||||||
assertEquals(5, segments.size());
|
assertThat(segments).hasSize(5);
|
||||||
|
|
||||||
Segment segment = segments.get(0);
|
Segment segment = segments.get(0);
|
||||||
assertEquals(4, mediaPlaylist.discontinuitySequence + segment.relativeDiscontinuitySequence);
|
assertThat(mediaPlaylist.discontinuitySequence + segment.relativeDiscontinuitySequence)
|
||||||
assertEquals(7975000, segment.durationUs);
|
.isEqualTo(4);
|
||||||
assertNull(segment.fullSegmentEncryptionKeyUri);
|
assertThat(segment.durationUs).isEqualTo(7975000);
|
||||||
assertNull(segment.encryptionIV);
|
assertThat(segment.fullSegmentEncryptionKeyUri).isNull();
|
||||||
assertEquals(51370, segment.byterangeLength);
|
assertThat(segment.encryptionIV).isNull();
|
||||||
assertEquals(0, segment.byterangeOffset);
|
assertThat(segment.byterangeLength).isEqualTo(51370);
|
||||||
assertEquals("https://priv.example.com/fileSequence2679.ts", segment.url);
|
assertThat(segment.byterangeOffset).isEqualTo(0);
|
||||||
|
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2679.ts");
|
||||||
|
|
||||||
segment = segments.get(1);
|
segment = segments.get(1);
|
||||||
assertEquals(0, segment.relativeDiscontinuitySequence);
|
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(0);
|
||||||
assertEquals(7975000, segment.durationUs);
|
assertThat(segment.durationUs).isEqualTo(7975000);
|
||||||
assertEquals("https://priv.example.com/key.php?r=2680", segment.fullSegmentEncryptionKeyUri);
|
assertThat(segment.fullSegmentEncryptionKeyUri)
|
||||||
assertEquals("0x1566B", segment.encryptionIV);
|
.isEqualTo("https://priv.example.com/key.php?r=2680");
|
||||||
assertEquals(51501, segment.byterangeLength);
|
assertThat(segment.encryptionIV).isEqualTo("0x1566B");
|
||||||
assertEquals(2147483648L, segment.byterangeOffset);
|
assertThat(segment.byterangeLength).isEqualTo(51501);
|
||||||
assertEquals("https://priv.example.com/fileSequence2680.ts", segment.url);
|
assertThat(segment.byterangeOffset).isEqualTo(2147483648L);
|
||||||
|
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2680.ts");
|
||||||
|
|
||||||
segment = segments.get(2);
|
segment = segments.get(2);
|
||||||
assertEquals(0, segment.relativeDiscontinuitySequence);
|
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(0);
|
||||||
assertEquals(7941000, segment.durationUs);
|
assertThat(segment.durationUs).isEqualTo(7941000);
|
||||||
assertNull(segment.fullSegmentEncryptionKeyUri);
|
assertThat(segment.fullSegmentEncryptionKeyUri).isNull();
|
||||||
assertEquals(null, segment.encryptionIV);
|
assertThat(segment.encryptionIV).isEqualTo(null);
|
||||||
assertEquals(51501, segment.byterangeLength);
|
assertThat(segment.byterangeLength).isEqualTo(51501);
|
||||||
assertEquals(2147535149L, segment.byterangeOffset);
|
assertThat(segment.byterangeOffset).isEqualTo(2147535149L);
|
||||||
assertEquals("https://priv.example.com/fileSequence2681.ts", segment.url);
|
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2681.ts");
|
||||||
|
|
||||||
segment = segments.get(3);
|
segment = segments.get(3);
|
||||||
assertEquals(1, segment.relativeDiscontinuitySequence);
|
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(1);
|
||||||
assertEquals(7975000, segment.durationUs);
|
assertThat(segment.durationUs).isEqualTo(7975000);
|
||||||
assertEquals("https://priv.example.com/key.php?r=2682", segment.fullSegmentEncryptionKeyUri);
|
assertThat(segment.fullSegmentEncryptionKeyUri)
|
||||||
|
.isEqualTo("https://priv.example.com/key.php?r=2682");
|
||||||
// 0xA7A == 2682.
|
// 0xA7A == 2682.
|
||||||
assertNotNull(segment.encryptionIV);
|
assertThat(segment.encryptionIV).isNotNull();
|
||||||
assertEquals("A7A", segment.encryptionIV.toUpperCase(Locale.getDefault()));
|
assertThat(segment.encryptionIV.toUpperCase(Locale.getDefault())).isEqualTo("A7A");
|
||||||
assertEquals(51740, segment.byterangeLength);
|
assertThat(segment.byterangeLength).isEqualTo(51740);
|
||||||
assertEquals(2147586650L, segment.byterangeOffset);
|
assertThat(segment.byterangeOffset).isEqualTo(2147586650L);
|
||||||
assertEquals("https://priv.example.com/fileSequence2682.ts", segment.url);
|
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2682.ts");
|
||||||
|
|
||||||
segment = segments.get(4);
|
segment = segments.get(4);
|
||||||
assertEquals(1, segment.relativeDiscontinuitySequence);
|
assertThat(segment.relativeDiscontinuitySequence).isEqualTo(1);
|
||||||
assertEquals(7975000, segment.durationUs);
|
assertThat(segment.durationUs).isEqualTo(7975000);
|
||||||
assertEquals("https://priv.example.com/key.php?r=2682", segment.fullSegmentEncryptionKeyUri);
|
assertThat(segment.fullSegmentEncryptionKeyUri)
|
||||||
|
.isEqualTo("https://priv.example.com/key.php?r=2682");
|
||||||
// 0xA7B == 2683.
|
// 0xA7B == 2683.
|
||||||
assertNotNull(segment.encryptionIV);
|
assertThat(segment.encryptionIV).isNotNull();
|
||||||
assertEquals("A7B", segment.encryptionIV.toUpperCase(Locale.getDefault()));
|
assertThat(segment.encryptionIV.toUpperCase(Locale.getDefault())).isEqualTo("A7B");
|
||||||
assertEquals(C.LENGTH_UNSET, segment.byterangeLength);
|
assertThat(segment.byterangeLength).isEqualTo(C.LENGTH_UNSET);
|
||||||
assertEquals(0, segment.byterangeOffset);
|
assertThat(segment.byterangeOffset).isEqualTo(0);
|
||||||
assertEquals("https://priv.example.com/fileSequence2683.ts", segment.url);
|
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
fail(exception.getMessage());
|
fail(exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.smoothstreaming.manifest;
|
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.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.ProtectionElement;
|
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) {
|
private static void assertManifestEquals(SsManifest expected, SsManifest actual) {
|
||||||
assertEquals(expected.durationUs, actual.durationUs);
|
assertThat(actual.durationUs).isEqualTo(expected.durationUs);
|
||||||
assertEquals(expected.dvrWindowLengthUs, actual.dvrWindowLengthUs);
|
assertThat(actual.dvrWindowLengthUs).isEqualTo(expected.dvrWindowLengthUs);
|
||||||
assertEquals(expected.isLive, actual.isLive);
|
assertThat(actual.isLive).isEqualTo(expected.isLive);
|
||||||
assertEquals(expected.lookAheadCount, actual.lookAheadCount);
|
assertThat(actual.lookAheadCount).isEqualTo(expected.lookAheadCount);
|
||||||
assertEquals(expected.majorVersion, actual.majorVersion);
|
assertThat(actual.majorVersion).isEqualTo(expected.majorVersion);
|
||||||
assertEquals(expected.minorVersion, actual.minorVersion);
|
assertThat(actual.minorVersion).isEqualTo(expected.minorVersion);
|
||||||
assertEquals(expected.protectionElement.uuid, actual.protectionElement.uuid);
|
assertThat(actual.protectionElement.uuid).isEqualTo(expected.protectionElement.uuid);
|
||||||
assertEquals(expected.protectionElement, actual.protectionElement);
|
assertThat(actual.protectionElement).isEqualTo(expected.protectionElement);
|
||||||
for (int i = 0; i < expected.streamElements.length; i++) {
|
for (int i = 0; i < expected.streamElements.length; i++) {
|
||||||
StreamElement expectedStreamElement = expected.streamElements[i];
|
StreamElement expectedStreamElement = expected.streamElements[i];
|
||||||
StreamElement actualStreamElement = actual.streamElements[i];
|
StreamElement actualStreamElement = actual.streamElements[i];
|
||||||
assertEquals(expectedStreamElement.chunkCount, actualStreamElement.chunkCount);
|
assertThat(actualStreamElement.chunkCount).isEqualTo(expectedStreamElement.chunkCount);
|
||||||
assertEquals(expectedStreamElement.displayHeight, actualStreamElement.displayHeight);
|
assertThat(actualStreamElement.displayHeight).isEqualTo(expectedStreamElement.displayHeight);
|
||||||
assertEquals(expectedStreamElement.displayWidth, actualStreamElement.displayWidth);
|
assertThat(actualStreamElement.displayWidth).isEqualTo(expectedStreamElement.displayWidth);
|
||||||
assertEquals(expectedStreamElement.language, actualStreamElement.language);
|
assertThat(actualStreamElement.language).isEqualTo(expectedStreamElement.language);
|
||||||
assertEquals(expectedStreamElement.maxHeight, actualStreamElement.maxHeight);
|
assertThat(actualStreamElement.maxHeight).isEqualTo(expectedStreamElement.maxHeight);
|
||||||
assertEquals(expectedStreamElement.maxWidth, actualStreamElement.maxWidth);
|
assertThat(actualStreamElement.maxWidth).isEqualTo(expectedStreamElement.maxWidth);
|
||||||
assertEquals(expectedStreamElement.name, actualStreamElement.name);
|
assertThat(actualStreamElement.name).isEqualTo(expectedStreamElement.name);
|
||||||
assertEquals(expectedStreamElement.subType, actualStreamElement.subType);
|
assertThat(actualStreamElement.subType).isEqualTo(expectedStreamElement.subType);
|
||||||
assertEquals(expectedStreamElement.timescale, actualStreamElement.timescale);
|
assertThat(actualStreamElement.timescale).isEqualTo(expectedStreamElement.timescale);
|
||||||
assertEquals(expectedStreamElement.type, actualStreamElement.type);
|
assertThat(actualStreamElement.type).isEqualTo(expectedStreamElement.type);
|
||||||
MoreAsserts.assertEquals(expectedStreamElement.formats, actualStreamElement.formats);
|
assertThat(actualStreamElement.formats).isEqualTo(expectedStreamElement.formats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.playbacktests.gts;
|
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.net.Uri;
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -89,15 +92,16 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2<Hos
|
||||||
|
|
||||||
// Download representations
|
// Download representations
|
||||||
DashDownloader dashDownloader = downloadContent(false, Float.NaN);
|
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").
|
testRunner.setStreamName("test_h264_fixed_download").
|
||||||
setDataSourceFactory(newOfflineCacheDataSourceFactory()).run();
|
setDataSourceFactory(newOfflineCacheDataSourceFactory()).run();
|
||||||
|
|
||||||
dashDownloader.remove();
|
dashDownloader.remove();
|
||||||
|
|
||||||
assertEquals("There should be no content left.", 0, cache.getKeys().size());
|
assertWithMessage("There should be no content left.").that(cache.getKeys().size()).isEqualTo(0);
|
||||||
assertEquals("There should be no content left.", 0, cache.getCacheSpace());
|
assertWithMessage("There should be no content left.").that(cache.getCacheSpace()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPartialDownload() throws Exception {
|
public void testPartialDownload() throws Exception {
|
||||||
|
|
@ -114,7 +118,7 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2<Hos
|
||||||
|
|
||||||
// Make sure it doesn't download any data
|
// Make sure it doesn't download any data
|
||||||
dashDownloader = downloadContent(true, Float.NaN);
|
dashDownloader = downloadContent(true, Float.NaN);
|
||||||
assertEquals(downloadedBytes, dashDownloader.getDownloadedBytes());
|
assertThat(dashDownloader.getDownloadedBytes()).isEqualTo(downloadedBytes);
|
||||||
|
|
||||||
testRunner.setStreamName("test_h264_fixed_partial_download")
|
testRunner.setStreamName("test_h264_fixed_partial_download")
|
||||||
.setDataSourceFactory(newOfflineCacheDataSourceFactory()).run();
|
.setDataSourceFactory(newOfflineCacheDataSourceFactory()).run();
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.playbacktests.gts;
|
package com.google.android.exoplayer2.playbacktests.gts;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
import com.google.android.exoplayer2.ExoPlayer;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
|
|
@ -603,8 +605,8 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MediaCodecInfo decoderInfo = MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H264, false);
|
MediaCodecInfo decoderInfo = MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H264, false);
|
||||||
assertNotNull(decoderInfo);
|
assertThat(decoderInfo).isNotNull();
|
||||||
assertTrue(Util.SDK_INT < 21 || decoderInfo.adaptive);
|
assertThat(Util.SDK_INT < 21 || decoderInfo.adaptive).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDecoderInfoH265V24() throws DecoderQueryException {
|
public void testDecoderInfoH265V24() throws DecoderQueryException {
|
||||||
|
|
@ -612,7 +614,7 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
|
||||||
// Pass.
|
// Pass.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H265, false).adaptive);
|
assertThat(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_H265, false).adaptive).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDecoderInfoVP9V24() throws DecoderQueryException {
|
public void testDecoderInfoVP9V24() throws DecoderQueryException {
|
||||||
|
|
@ -620,7 +622,7 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2<Ho
|
||||||
// Pass.
|
// Pass.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_VP9, false).adaptive);
|
assertThat(MediaCodecUtil.getDecoderInfo(MimeTypes.VIDEO_VP9, false).adaptive).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal.
|
// Internal.
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
|
|
||||||
/** {@link DashHostedTest} builder. */
|
/** {@link DashHostedTest} builder. */
|
||||||
public final class DashTestRunner {
|
public final class DashTestRunner {
|
||||||
|
|
@ -362,7 +361,7 @@ public final class DashTestRunner {
|
||||||
// Assert that consecutive dropped frames were within limit.
|
// Assert that consecutive dropped frames were within limit.
|
||||||
DecoderCountersUtil.assertConsecutiveDroppedBufferLimit(tag + VIDEO_TAG_SUFFIX,
|
DecoderCountersUtil.assertConsecutiveDroppedBufferLimit(tag + VIDEO_TAG_SUFFIX,
|
||||||
videoCounters, MAX_CONSECUTIVE_DROPPED_VIDEO_FRAMES);
|
videoCounters, MAX_CONSECUTIVE_DROPPED_VIDEO_FRAMES);
|
||||||
} catch (AssertionFailedError e) {
|
} catch (AssertionError e) {
|
||||||
if (trackSelector.includedAdditionalVideoFormats) {
|
if (trackSelector.includedAdditionalVideoFormats) {
|
||||||
// Retry limiting to CDD mandated formats (b/28220076).
|
// Retry limiting to CDD mandated formats (b/28220076).
|
||||||
Log.e(tag, "Too many dropped or consecutive dropped frames.", e);
|
Log.e(tag, "Too many dropped or consecutive dropped frames.", e);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.playbacktests.gts;
|
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.media.MediaDrm.MediaDrmStateException;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
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.MimeTypes;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Widevine encrypted DASH playbacks using offline keys.
|
* 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
|
// Renew license after playback should still work
|
||||||
offlineLicenseKeySetId = offlineLicenseHelper.renewLicense(offlineLicenseKeySetId);
|
offlineLicenseKeySetId = offlineLicenseHelper.renewLicense(offlineLicenseKeySetId);
|
||||||
Assert.assertNotNull(offlineLicenseKeySetId);
|
assertThat(offlineLicenseKeySetId).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWidevineOfflineReleasedLicenseV22() throws Throwable {
|
public void testWidevineOfflineReleasedLicenseV22() throws Throwable {
|
||||||
|
|
@ -136,8 +138,10 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
|
||||||
// Wait until the license expires
|
// Wait until the license expires
|
||||||
long licenseDuration =
|
long licenseDuration =
|
||||||
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId).first;
|
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId).first;
|
||||||
assertTrue("License duration should be less than 30 sec. "
|
assertWithMessage(
|
||||||
+ "Server settings might have changed.", licenseDuration < 30);
|
"License duration should be less than 30 sec. " + "Server settings might have changed.")
|
||||||
|
.that(licenseDuration < 30)
|
||||||
|
.isTrue();
|
||||||
while (licenseDuration > 0) {
|
while (licenseDuration > 0) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
wait(licenseDuration * 1000 + 2000);
|
wait(licenseDuration * 1000 + 2000);
|
||||||
|
|
@ -145,7 +149,9 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
|
||||||
long previousDuration = licenseDuration;
|
long previousDuration = licenseDuration;
|
||||||
licenseDuration =
|
licenseDuration =
|
||||||
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId).first;
|
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
|
// DefaultDrmSessionManager should renew the license and stream play fine
|
||||||
|
|
@ -162,8 +168,10 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa
|
||||||
Pair<Long, Long> licenseDurationRemainingSec =
|
Pair<Long, Long> licenseDurationRemainingSec =
|
||||||
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
|
||||||
long licenseDuration = licenseDurationRemainingSec.first;
|
long licenseDuration = licenseDurationRemainingSec.first;
|
||||||
assertTrue("License duration should be less than 30 sec. "
|
assertWithMessage(
|
||||||
+ "Server settings might have changed.", licenseDuration < 30);
|
"License duration should be less than 30 sec. " + "Server settings might have changed.")
|
||||||
|
.that(licenseDuration < 30)
|
||||||
|
.isTrue();
|
||||||
ActionSchedule schedule = new ActionSchedule.Builder(TAG)
|
ActionSchedule schedule = new ActionSchedule.Builder(TAG)
|
||||||
.waitForPlaybackState(Player.STATE_READY)
|
.waitForPlaybackState(Player.STATE_READY)
|
||||||
.delay(3000).pause().delay(licenseDuration * 1000 + 2000).play().build();
|
.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));
|
Uri.parse(DashTestData.WIDEVINE_H264_MANIFEST));
|
||||||
DrmInitData drmInitData = DashUtil.loadDrmInitData(dataSource, dashManifest.getPeriod(0));
|
DrmInitData drmInitData = DashUtil.loadDrmInitData(dataSource, dashManifest.getPeriod(0));
|
||||||
offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(drmInitData);
|
offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(drmInitData);
|
||||||
Assert.assertNotNull(offlineLicenseKeySetId);
|
assertThat(offlineLicenseKeySetId).isNotNull();
|
||||||
Assert.assertTrue(offlineLicenseKeySetId.length > 0);
|
assertThat(offlineLicenseKeySetId.length).isGreaterThan(0);
|
||||||
testRunner.setOfflineLicenseKeySetId(offlineLicenseKeySetId);
|
testRunner.setOfflineLicenseKeySetId(offlineLicenseKeySetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,5 @@ android {
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(modulePrefix + 'library-core')
|
compile project(modulePrefix + 'library-core')
|
||||||
compile 'org.mockito:mockito-core:' + mockitoVersion
|
compile 'org.mockito:mockito-core:' + mockitoVersion
|
||||||
|
compile 'com.google.truth:truth:' + truthVersion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,10 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.test.MoreAsserts;
|
|
||||||
import com.google.android.exoplayer2.testutil.FakeDataSet.FakeData;
|
import com.google.android.exoplayer2.testutil.FakeDataSet.FakeData;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||||
|
|
@ -76,7 +75,7 @@ public final class CacheAsserts {
|
||||||
assertDataCached(cache, uri, data);
|
assertDataCached(cache, uri, data);
|
||||||
totalLength += data.length;
|
totalLength += data.length;
|
||||||
}
|
}
|
||||||
assertEquals(totalLength, cache.getCacheSpace());
|
assertThat(cache.getCacheSpace()).isEqualTo(totalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,8 +111,9 @@ public final class CacheAsserts {
|
||||||
dataSource.open(dataSpec);
|
dataSource.open(dataSpec);
|
||||||
try {
|
try {
|
||||||
byte[] bytes = TestUtil.readToEnd(dataSource);
|
byte[] bytes = TestUtil.readToEnd(dataSource);
|
||||||
MoreAsserts.assertEquals(
|
assertWithMessage("Cached data doesn't match expected for '" + dataSpec.uri + "',")
|
||||||
"Cached data doesn't match expected for '" + dataSpec.uri + "',", expected, bytes);
|
.that(bytes)
|
||||||
|
.isEqualTo(expected);
|
||||||
} finally {
|
} finally {
|
||||||
dataSource.close();
|
dataSource.close();
|
||||||
}
|
}
|
||||||
|
|
@ -122,15 +122,15 @@ public final class CacheAsserts {
|
||||||
/** Asserts that there is no cache content for the given {@code uriStrings}. */
|
/** Asserts that there is no cache content for the given {@code uriStrings}. */
|
||||||
public static void assertDataNotCached(Cache cache, String... uriStrings) {
|
public static void assertDataNotCached(Cache cache, String... uriStrings) {
|
||||||
for (String uriString : uriStrings) {
|
for (String uriString : uriStrings) {
|
||||||
assertTrue(
|
assertWithMessage("There is cached data for '" + uriString + "',")
|
||||||
"There is cached data for '" + uriString + "',",
|
.that(cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))).isEmpty())
|
||||||
cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))).isEmpty());
|
.isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that the cache is empty. */
|
/** Asserts that the cache is empty. */
|
||||||
public static void assertCacheEmpty(Cache cache) {
|
public static void assertCacheEmpty(Cache cache) {
|
||||||
assertEquals(0, cache.getCacheSpace());
|
assertThat(cache.getCacheSpace()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CacheAsserts() {}
|
private CacheAsserts() {}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.decoder.DecoderCounters;
|
import com.google.android.exoplayer2.decoder.DecoderCounters;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assertions for {@link DecoderCounters}.
|
* Assertions for {@link DecoderCounters}.
|
||||||
|
|
@ -41,30 +42,60 @@ public final class DecoderCountersUtil {
|
||||||
int expected) {
|
int expected) {
|
||||||
counters.ensureUpdated();
|
counters.ensureUpdated();
|
||||||
int actual = counters.skippedOutputBufferCount;
|
int actual = counters.skippedOutputBufferCount;
|
||||||
TestCase.assertEquals("Codec(" + name + ") skipped " + actual + " buffers. Expected "
|
assertWithMessage(
|
||||||
+ expected + ".", expected, actual);
|
"Codec(" + name + ") skipped " + actual + " buffers. Expected " + expected + ".")
|
||||||
|
.that(actual)
|
||||||
|
.isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertTotalBufferCount(String name, DecoderCounters counters, int minCount,
|
public static void assertTotalBufferCount(String name, DecoderCounters counters, int minCount,
|
||||||
int maxCount) {
|
int maxCount) {
|
||||||
int actual = getTotalBufferCount(counters);
|
int actual = getTotalBufferCount(counters);
|
||||||
TestCase.assertTrue("Codec(" + name + ") output " + actual + " buffers. Expected in range ["
|
assertWithMessage(
|
||||||
+ minCount + ", " + maxCount + "].", minCount <= actual && actual <= maxCount);
|
"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) {
|
public static void assertDroppedBufferLimit(String name, DecoderCounters counters, int limit) {
|
||||||
counters.ensureUpdated();
|
counters.ensureUpdated();
|
||||||
int actual = counters.droppedBufferCount;
|
int actual = counters.droppedBufferCount;
|
||||||
TestCase.assertTrue("Codec(" + name + ") was late decoding: " + actual + " buffers. "
|
assertWithMessage(
|
||||||
+ "Limit: " + limit + ".", actual <= limit);
|
"Codec("
|
||||||
|
+ name
|
||||||
|
+ ") was late decoding: "
|
||||||
|
+ actual
|
||||||
|
+ " buffers. "
|
||||||
|
+ "Limit: "
|
||||||
|
+ limit
|
||||||
|
+ ".")
|
||||||
|
.that(actual)
|
||||||
|
.isAtMost(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertConsecutiveDroppedBufferLimit(String name, DecoderCounters counters,
|
public static void assertConsecutiveDroppedBufferLimit(String name, DecoderCounters counters,
|
||||||
int limit) {
|
int limit) {
|
||||||
counters.ensureUpdated();
|
counters.ensureUpdated();
|
||||||
int actual = counters.maxConsecutiveDroppedBufferCount;
|
int actual = counters.maxConsecutiveDroppedBufferCount;
|
||||||
TestCase.assertTrue("Codec(" + name + ") was late decoding: " + actual
|
assertWithMessage(
|
||||||
+ " buffers consecutively. " + "Limit: " + limit + ".", actual <= limit);
|
"Codec("
|
||||||
|
+ name
|
||||||
|
+ ") was late decoding: "
|
||||||
|
+ actual
|
||||||
|
+ " buffers consecutively. "
|
||||||
|
+ "Limit: "
|
||||||
|
+ limit
|
||||||
|
+ ".")
|
||||||
|
.that(actual)
|
||||||
|
.isAtMost(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
|
|
||||||
import android.os.ConditionVariable;
|
import android.os.ConditionVariable;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.SystemClock;
|
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.HandlerWrapper;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link HostedTest} for {@link ExoPlayer} playback tests.
|
* 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.
|
// Assert that the playback spanned the correct duration of time.
|
||||||
long minAllowedActualPlayingTimeMs = playingTimeToAssertMs - MAX_PLAYING_TIME_DISCREPANCY_MS;
|
long minAllowedActualPlayingTimeMs = playingTimeToAssertMs - MAX_PLAYING_TIME_DISCREPANCY_MS;
|
||||||
long maxAllowedActualPlayingTimeMs = playingTimeToAssertMs + MAX_PLAYING_TIME_DISCREPANCY_MS;
|
long maxAllowedActualPlayingTimeMs = playingTimeToAssertMs + MAX_PLAYING_TIME_DISCREPANCY_MS;
|
||||||
Assert.assertTrue("Total playing time: " + totalPlayingTimeMs + ". Expected: "
|
assertWithMessage(
|
||||||
+ playingTimeToAssertMs, minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
|
"Total playing time: " + totalPlayingTimeMs + ". Expected: " + playingTimeToAssertMs)
|
||||||
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs);
|
.that(
|
||||||
|
minAllowedActualPlayingTimeMs <= totalPlayingTimeMs
|
||||||
|
&& totalPlayingTimeMs <= maxAllowedActualPlayingTimeMs)
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
// Make any additional assertions.
|
// Make any additional assertions.
|
||||||
assertPassed(audioDecoderCounters, videoDecoderCounters);
|
assertPassed(audioDecoderCounters, videoDecoderCounters);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
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.Format;
|
||||||
import com.google.android.exoplayer2.LoadControl;
|
import com.google.android.exoplayer2.LoadControl;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
|
||||||
import com.google.android.exoplayer2.Renderer;
|
import com.google.android.exoplayer2.Renderer;
|
||||||
import com.google.android.exoplayer2.RenderersFactory;
|
import com.google.android.exoplayer2.RenderersFactory;
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
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.util.MimeTypes;
|
||||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to run an ExoPlayer test.
|
* Helper class to run an ExoPlayer test.
|
||||||
|
|
@ -97,7 +98,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
public Builder setTimeline(Timeline timeline) {
|
public Builder setTimeline(Timeline timeline) {
|
||||||
Assert.assertNull(mediaSource);
|
assertThat(mediaSource).isNull();
|
||||||
this.timeline = timeline;
|
this.timeline = timeline;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +112,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
public Builder setManifest(Object manifest) {
|
public Builder setManifest(Object manifest) {
|
||||||
Assert.assertNull(mediaSource);
|
assertThat(mediaSource).isNull();
|
||||||
this.manifest = manifest;
|
this.manifest = manifest;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -127,8 +128,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
public Builder setMediaSource(MediaSource mediaSource) {
|
public Builder setMediaSource(MediaSource mediaSource) {
|
||||||
Assert.assertNull(timeline);
|
assertThat(timeline).isNull();
|
||||||
Assert.assertNull(manifest);
|
assertThat(manifest).isNull();
|
||||||
this.mediaSource = mediaSource;
|
this.mediaSource = mediaSource;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -182,7 +183,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
public Builder setRenderers(Renderer... renderers) {
|
public Builder setRenderers(Renderer... renderers) {
|
||||||
Assert.assertNull(renderersFactory);
|
assertThat(renderersFactory).isNull();
|
||||||
this.renderers = renderers;
|
this.renderers = renderers;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +197,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
public Builder setRenderersFactory(RenderersFactory renderersFactory) {
|
public Builder setRenderersFactory(RenderersFactory renderersFactory) {
|
||||||
Assert.assertNull(renderers);
|
assertThat(renderers).isNull();
|
||||||
this.renderersFactory = renderersFactory;
|
this.renderersFactory = renderersFactory;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -478,10 +479,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
* @param timelines A list of expected {@link Timeline}s.
|
* @param timelines A list of expected {@link Timeline}s.
|
||||||
*/
|
*/
|
||||||
public void assertTimelinesEqual(Timeline... timelines) {
|
public void assertTimelinesEqual(Timeline... timelines) {
|
||||||
Assert.assertEquals(timelines.length, this.timelines.size());
|
assertThat(this.timelines).containsExactlyElementsIn(Arrays.asList(timelines)).inOrder();
|
||||||
for (int i = 0; i < timelines.length; i++) {
|
|
||||||
Assert.assertEquals(timelines[i], this.timelines.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -492,22 +490,16 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
* @param manifests A list of expected manifests.
|
* @param manifests A list of expected manifests.
|
||||||
*/
|
*/
|
||||||
public void assertManifestsEqual(Object... manifests) {
|
public void assertManifestsEqual(Object... manifests) {
|
||||||
Assert.assertEquals(manifests.length, this.manifests.size());
|
assertThat(this.manifests).containsExactlyElementsIn(Arrays.asList(manifests)).inOrder();
|
||||||
for (int i = 0; i < manifests.length; i++) {
|
|
||||||
Assert.assertEquals(manifests[i], this.manifests.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the timeline change reasons reported by
|
* Asserts that the timeline change reasons reported by {@link
|
||||||
* {@link Player.EventListener#onTimelineChanged(Timeline, Object, int)} are equal to the provided
|
* Player.EventListener#onTimelineChanged(Timeline, Object, int)} are equal to the provided
|
||||||
* timeline change reasons.
|
* timeline change reasons.
|
||||||
*/
|
*/
|
||||||
public void assertTimelineChangeReasonsEqual(@Player.TimelineChangeReason int... reasons) {
|
public void assertTimelineChangeReasonsEqual(Integer... reasons) {
|
||||||
Assert.assertEquals(reasons.length, timelineChangeReasons.size());
|
assertThat(timelineChangeReasons).containsExactlyElementsIn(Arrays.asList(reasons)).inOrder();
|
||||||
for (int i = 0; i < reasons.length; i++) {
|
|
||||||
Assert.assertEquals(reasons[i], (int) timelineChangeReasons.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -518,28 +510,26 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
* @param trackGroupArray The expected {@link TrackGroupArray}.
|
* @param trackGroupArray The expected {@link TrackGroupArray}.
|
||||||
*/
|
*/
|
||||||
public void assertTrackGroupsEqual(TrackGroupArray 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.
|
* Asserts that {@link Player.EventListener#onPositionDiscontinuity(int)} was not called.
|
||||||
*/
|
*/
|
||||||
public void assertNoPositionDiscontinuities() {
|
public void assertNoPositionDiscontinuities() {
|
||||||
Assert.assertTrue(discontinuityReasons.isEmpty());
|
assertThat(discontinuityReasons).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the discontinuity reasons reported by
|
* Asserts that the discontinuity reasons reported by {@link
|
||||||
* {@link Player.EventListener#onPositionDiscontinuity(int)} are equal to the provided values.
|
* Player.EventListener#onPositionDiscontinuity(int)} are equal to the provided values.
|
||||||
*
|
*
|
||||||
* @param discontinuityReasons The expected discontinuity reasons.
|
* @param discontinuityReasons The expected discontinuity reasons.
|
||||||
*/
|
*/
|
||||||
public void assertPositionDiscontinuityReasonsEqual(
|
public void assertPositionDiscontinuityReasonsEqual(Integer... discontinuityReasons) {
|
||||||
@DiscontinuityReason int... discontinuityReasons) {
|
assertThat(this.discontinuityReasons)
|
||||||
Assert.assertEquals(discontinuityReasons.length, this.discontinuityReasons.size());
|
.containsExactlyElementsIn(Arrays.asList(discontinuityReasons))
|
||||||
for (int i = 0; i < discontinuityReasons.length; i++) {
|
.inOrder();
|
||||||
Assert.assertEquals(discontinuityReasons[i], (int) this.discontinuityReasons.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -550,11 +540,10 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||||
*
|
*
|
||||||
* @param periodIndices A list of expected period indices.
|
* @param periodIndices A list of expected period indices.
|
||||||
*/
|
*/
|
||||||
public void assertPlayedPeriodIndices(int... periodIndices) {
|
public void assertPlayedPeriodIndices(Integer... periodIndices) {
|
||||||
Assert.assertEquals(periodIndices.length, this.periodIndices.size());
|
assertThat(this.periodIndices)
|
||||||
for (int i = 0; i < periodIndices.length; i++) {
|
.containsExactlyElementsIn(Arrays.asList(periodIndices))
|
||||||
Assert.assertEquals(periodIndices[i], (int) this.periodIndices.get(i));
|
.inOrder();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private implementation details.
|
// Private implementation details.
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.extractor.Extractor;
|
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 com.google.android.exoplayer2.util.Assertions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assertion methods for {@link Extractor}.
|
* Assertion methods for {@link Extractor}.
|
||||||
|
|
@ -126,7 +127,7 @@ public final class ExtractorAsserts {
|
||||||
.setSimulatePartialReads(simulatePartialReads).build();
|
.setSimulatePartialReads(simulatePartialReads).build();
|
||||||
|
|
||||||
if (sniffFirst) {
|
if (sniffFirst) {
|
||||||
Assert.assertTrue(TestUtil.sniffTestData(extractor, input));
|
assertThat(TestUtil.sniffTestData(extractor, input)).isTrue();
|
||||||
input.resetPeekPosition();
|
input.resetPeekPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.util.SparseBooleanArray;
|
import android.util.SparseBooleanArray;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fake {@link ExtractorInput} capable of simulating various scenarios.
|
* 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.
|
* @param position The position to set.
|
||||||
*/
|
*/
|
||||||
public void setPosition(int position) {
|
public void setPosition(int position) {
|
||||||
Assert.assertTrue(0 <= position && position <= data.length);
|
assertThat(0 <= position && position <= data.length).isTrue();
|
||||||
readPosition = position;
|
readPosition = position;
|
||||||
peekPosition = position;
|
peekPosition = position;
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +181,7 @@ public final class FakeExtractorInput implements ExtractorInput {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends Throwable> void setRetryPosition(long position, E e) throws E {
|
public <E extends Throwable> void setRetryPosition(long position, E e) throws E {
|
||||||
Assert.assertTrue(position >= 0);
|
assertThat(position >= 0).isTrue();
|
||||||
readPosition = (int) position;
|
readPosition = (int) position;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
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.app.Instrumentation;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import com.google.android.exoplayer2.extractor.ExtractorOutput;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fake {@link ExtractorOutput}.
|
* A fake {@link ExtractorOutput}.
|
||||||
|
|
@ -50,7 +52,7 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
||||||
public FakeTrackOutput track(int id, int type) {
|
public FakeTrackOutput track(int id, int type) {
|
||||||
FakeTrackOutput output = trackOutputs.get(id);
|
FakeTrackOutput output = trackOutputs.get(id);
|
||||||
if (output == null) {
|
if (output == null) {
|
||||||
Assert.assertFalse(tracksEnded);
|
assertThat(tracksEnded).isFalse();
|
||||||
numberOfTracks++;
|
numberOfTracks++;
|
||||||
output = new FakeTrackOutput();
|
output = new FakeTrackOutput();
|
||||||
trackOutputs.put(id, output);
|
trackOutputs.put(id, output);
|
||||||
|
|
@ -69,19 +71,19 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertEquals(FakeExtractorOutput expected) {
|
public void assertEquals(FakeExtractorOutput expected) {
|
||||||
Assert.assertEquals(expected.numberOfTracks, numberOfTracks);
|
assertThat(numberOfTracks).isEqualTo(expected.numberOfTracks);
|
||||||
Assert.assertEquals(expected.tracksEnded, tracksEnded);
|
assertThat(tracksEnded).isEqualTo(expected.tracksEnded);
|
||||||
if (expected.seekMap == null) {
|
if (expected.seekMap == null) {
|
||||||
Assert.assertNull(seekMap);
|
assertThat(seekMap).isNull();
|
||||||
} else {
|
} else {
|
||||||
// TODO: Bulk up this check if possible.
|
// TODO: Bulk up this check if possible.
|
||||||
Assert.assertNotNull(seekMap);
|
assertThat(seekMap).isNotNull();
|
||||||
Assert.assertEquals(expected.seekMap.getClass(), seekMap.getClass());
|
assertThat(seekMap.getClass()).isEqualTo(expected.seekMap.getClass());
|
||||||
Assert.assertEquals(expected.seekMap.isSeekable(), seekMap.isSeekable());
|
assertThat(seekMap.isSeekable()).isEqualTo(expected.seekMap.isSeekable());
|
||||||
Assert.assertEquals(expected.seekMap.getSeekPoints(0), seekMap.getSeekPoints(0));
|
assertThat(seekMap.getSeekPoints(0)).isEqualTo(expected.seekMap.getSeekPoints(0));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < numberOfTracks; i++) {
|
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));
|
trackOutputs.valueAt(i).assertEquals(expected.trackOutputs.valueAt(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +109,7 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
||||||
out.close();
|
out.close();
|
||||||
} else {
|
} else {
|
||||||
String expected = TestUtil.getString(instrumentation, dumpFile);
|
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;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
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.source.TrackGroupArray;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fake {@link MediaPeriod} that provides tracks from the given {@link TrackGroupArray}. Selecting
|
* Fake {@link MediaPeriod} that provides tracks from the given {@link TrackGroupArray}. Selecting
|
||||||
|
|
@ -119,14 +120,14 @@ public class FakeMediaPeriod implements MediaPeriod {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TrackGroupArray getTrackGroups() {
|
public TrackGroupArray getTrackGroups() {
|
||||||
Assert.assertTrue(prepared);
|
assertThat(prepared).isTrue();
|
||||||
return trackGroupArray;
|
return trackGroupArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
|
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
|
||||||
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
|
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
|
||||||
Assert.assertTrue(prepared);
|
assertThat(prepared).isTrue();
|
||||||
int rendererCount = selections.length;
|
int rendererCount = selections.length;
|
||||||
for (int i = 0; i < rendererCount; i++) {
|
for (int i = 0; i < rendererCount; i++) {
|
||||||
if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[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) {
|
if (streams[i] == null && selections[i] != null) {
|
||||||
TrackSelection selection = selections[i];
|
TrackSelection selection = selections[i];
|
||||||
Assert.assertTrue(1 <= selection.length());
|
assertThat(selection.length()).isAtLeast(1);
|
||||||
TrackGroup trackGroup = selection.getTrackGroup();
|
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());
|
int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
|
||||||
Assert.assertTrue(0 <= indexInTrackGroup);
|
assertThat(indexInTrackGroup).isAtLeast(0);
|
||||||
Assert.assertTrue(indexInTrackGroup < trackGroup.length);
|
assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
|
||||||
streams[i] = createSampleStream(selection);
|
streams[i] = createSampleStream(selection);
|
||||||
streamResetFlags[i] = true;
|
streamResetFlags[i] = true;
|
||||||
}
|
}
|
||||||
|
|
@ -159,7 +160,7 @@ public class FakeMediaPeriod implements MediaPeriod {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long readDiscontinuity() {
|
public long readDiscontinuity() {
|
||||||
Assert.assertTrue(prepared);
|
assertThat(prepared).isTrue();
|
||||||
long positionDiscontinuityUs = this.discontinuityPositionUs;
|
long positionDiscontinuityUs = this.discontinuityPositionUs;
|
||||||
this.discontinuityPositionUs = C.TIME_UNSET;
|
this.discontinuityPositionUs = C.TIME_UNSET;
|
||||||
return positionDiscontinuityUs;
|
return positionDiscontinuityUs;
|
||||||
|
|
@ -167,13 +168,13 @@ public class FakeMediaPeriod implements MediaPeriod {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getBufferedPositionUs() {
|
public long getBufferedPositionUs() {
|
||||||
Assert.assertTrue(prepared);
|
assertThat(prepared).isTrue();
|
||||||
return C.TIME_END_OF_SOURCE;
|
return C.TIME_END_OF_SOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long seekToUs(long positionUs) {
|
public long seekToUs(long positionUs) {
|
||||||
Assert.assertTrue(prepared);
|
assertThat(prepared).isTrue();
|
||||||
return positionUs + seekOffsetUs;
|
return positionUs + seekOffsetUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,13 +185,13 @@ public class FakeMediaPeriod implements MediaPeriod {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getNextLoadPositionUs() {
|
public long getNextLoadPositionUs() {
|
||||||
Assert.assertTrue(prepared);
|
assertThat(prepared).isTrue();
|
||||||
return C.TIME_END_OF_SOURCE;
|
return C.TIME_END_OF_SOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean continueLoading(long positionUs) {
|
public boolean continueLoading(long positionUs) {
|
||||||
Assert.assertTrue(prepared);
|
assertThat(prepared).isTrue();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
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 com.google.android.exoplayer2.util.Assertions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fake {@link MediaSource} that provides a given timeline. Creating the period will return a
|
* Fake {@link MediaSource} that provides a given timeline. Creating the period will return a
|
||||||
|
|
@ -75,7 +76,7 @@ public class FakeMediaSource implements MediaSource {
|
||||||
@Override
|
@Override
|
||||||
public synchronized void prepareSource(
|
public synchronized void prepareSource(
|
||||||
ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||||
Assert.assertFalse(preparedSource);
|
assertThat(preparedSource).isFalse();
|
||||||
preparedSource = true;
|
preparedSource = true;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
sourceInfoRefreshHandler = new Handler();
|
sourceInfoRefreshHandler = new Handler();
|
||||||
|
|
@ -86,13 +87,13 @@ public class FakeMediaSource implements MediaSource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
||||||
Assert.assertTrue(preparedSource);
|
assertThat(preparedSource).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
|
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
|
||||||
Assert.assertTrue(preparedSource);
|
assertThat(preparedSource).isTrue();
|
||||||
Assert.assertFalse(releasedSource);
|
assertThat(releasedSource).isFalse();
|
||||||
Assertions.checkIndex(id.periodIndex, 0, timeline.getPeriodCount());
|
Assertions.checkIndex(id.periodIndex, 0, timeline.getPeriodCount());
|
||||||
FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator);
|
FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator);
|
||||||
activeMediaPeriods.add(mediaPeriod);
|
activeMediaPeriods.add(mediaPeriod);
|
||||||
|
|
@ -102,18 +103,18 @@ public class FakeMediaSource implements MediaSource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releasePeriod(MediaPeriod mediaPeriod) {
|
public void releasePeriod(MediaPeriod mediaPeriod) {
|
||||||
Assert.assertTrue(preparedSource);
|
assertThat(preparedSource).isTrue();
|
||||||
Assert.assertFalse(releasedSource);
|
assertThat(releasedSource).isFalse();
|
||||||
FakeMediaPeriod fakeMediaPeriod = (FakeMediaPeriod) mediaPeriod;
|
FakeMediaPeriod fakeMediaPeriod = (FakeMediaPeriod) mediaPeriod;
|
||||||
Assert.assertTrue(activeMediaPeriods.remove(fakeMediaPeriod));
|
assertThat(activeMediaPeriods.remove(fakeMediaPeriod)).isTrue();
|
||||||
fakeMediaPeriod.release();
|
fakeMediaPeriod.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseSource() {
|
public void releaseSource() {
|
||||||
Assert.assertTrue(preparedSource);
|
assertThat(preparedSource).isTrue();
|
||||||
Assert.assertFalse(releasedSource);
|
assertThat(releasedSource).isFalse();
|
||||||
Assert.assertTrue(activeMediaPeriods.isEmpty());
|
assertThat(activeMediaPeriods.isEmpty()).isTrue();
|
||||||
releasedSource = true;
|
releasedSource = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,8 +128,8 @@ public class FakeMediaSource implements MediaSource {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Assert.assertFalse(releasedSource);
|
assertThat(releasedSource).isFalse();
|
||||||
Assert.assertTrue(preparedSource);
|
assertThat(preparedSource).isTrue();
|
||||||
timeline = newTimeline;
|
timeline = newTimeline;
|
||||||
manifest = newManifest;
|
manifest = newManifest;
|
||||||
listener.onSourceInfoRefreshed(FakeMediaSource.this, timeline, manifest);
|
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.
|
* Assert that the source and all periods have been released.
|
||||||
*/
|
*/
|
||||||
public void assertReleased() {
|
public void assertReleased() {
|
||||||
Assert.assertTrue(releasedSource || !preparedSource);
|
assertThat(releasedSource || !preparedSource).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert that a media period for the given id has been created.
|
* Assert that a media period for the given id has been created.
|
||||||
*/
|
*/
|
||||||
public void assertMediaPeriodCreated(MediaPeriodId mediaPeriodId) {
|
public void assertMediaPeriodCreated(MediaPeriodId mediaPeriodId) {
|
||||||
Assert.assertTrue(createdMediaPeriods.contains(mediaPeriodId));
|
assertThat(createdMediaPeriods).contains(mediaPeriodId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FakeMediaPeriod createFakeMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray,
|
protected FakeMediaPeriod createFakeMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
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.BaseRenderer;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||||
|
|
@ -26,7 +28,6 @@ import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fake {@link Renderer} that supports any format with the matching MIME type. The renderer
|
* 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;
|
buffer.data = null;
|
||||||
if (result == C.RESULT_FORMAT_READ) {
|
if (result == C.RESULT_FORMAT_READ) {
|
||||||
formatReadCount++;
|
formatReadCount++;
|
||||||
Assert.assertTrue(expectedFormats.contains(formatHolder.format));
|
assertThat(expectedFormats).contains(formatHolder.format);
|
||||||
} else if (result == C.RESULT_BUFFER_READ) {
|
} else if (result == C.RESULT_BUFFER_READ) {
|
||||||
bufferReadCount++;
|
bufferReadCount++;
|
||||||
if (buffer.isEndOfStream()) {
|
if (buffer.isEndOfStream()) {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
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.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||||
|
|
@ -25,7 +26,6 @@ import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fake {@link TrackOutput}.
|
* A fake {@link TrackOutput}.
|
||||||
|
|
@ -98,15 +98,15 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertSampleCount(int count) {
|
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) {
|
public void assertSample(int index, byte[] data, long timeUs, int flags, CryptoData cryptoData) {
|
||||||
byte[] actualData = getSampleData(index);
|
byte[] actualData = getSampleData(index);
|
||||||
MoreAsserts.assertEquals(data, actualData);
|
assertThat(actualData).isEqualTo(data);
|
||||||
Assert.assertEquals(timeUs, (long) sampleTimesUs.get(index));
|
assertThat(sampleTimesUs.get(index)).isEqualTo(timeUs);
|
||||||
Assert.assertEquals(flags, (int) sampleFlags.get(index));
|
assertThat(sampleFlags.get(index)).isEqualTo(flags);
|
||||||
Assert.assertEquals(cryptoData, cryptoDatas.get(index));
|
assertThat(cryptoDatas.get(index)).isEqualTo(cryptoData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getSampleData(int index) {
|
public byte[] getSampleData(int index) {
|
||||||
|
|
@ -115,18 +115,18 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertEquals(FakeTrackOutput expected) {
|
public void assertEquals(FakeTrackOutput expected) {
|
||||||
Assert.assertEquals(expected.format, format);
|
assertThat(format).isEqualTo(expected.format);
|
||||||
Assert.assertEquals(expected.sampleTimesUs.size(), sampleTimesUs.size());
|
assertThat(sampleTimesUs).hasSize(expected.sampleTimesUs.size());
|
||||||
MoreAsserts.assertEquals(expected.sampleData, sampleData);
|
assertThat(sampleData).isEqualTo(expected.sampleData);
|
||||||
for (int i = 0; i < sampleTimesUs.size(); i++) {
|
for (int i = 0; i < sampleTimesUs.size(); i++) {
|
||||||
Assert.assertEquals(expected.sampleTimesUs.get(i), sampleTimesUs.get(i));
|
assertThat(sampleTimesUs.get(i)).isEqualTo(expected.sampleTimesUs.get(i));
|
||||||
Assert.assertEquals(expected.sampleFlags.get(i), sampleFlags.get(i));
|
assertThat(sampleFlags.get(i)).isEqualTo(expected.sampleFlags.get(i));
|
||||||
Assert.assertEquals(expected.sampleStartOffsets.get(i), sampleStartOffsets.get(i));
|
assertThat(sampleStartOffsets.get(i)).isEqualTo(expected.sampleStartOffsets.get(i));
|
||||||
Assert.assertEquals(expected.sampleEndOffsets.get(i), sampleEndOffsets.get(i));
|
assertThat(sampleEndOffsets.get(i)).isEqualTo(expected.sampleEndOffsets.get(i));
|
||||||
if (expected.cryptoDatas.get(i) == null) {
|
if (expected.cryptoDatas.get(i) == null) {
|
||||||
Assert.assertNull(cryptoDatas.get(i));
|
assertThat(cryptoDatas.get(i)).isNull();
|
||||||
} else {
|
} 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;
|
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.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.source.TrackGroup;
|
import com.google.android.exoplayer2.source.TrackGroup;
|
||||||
import com.google.android.exoplayer2.source.chunk.MediaChunk;
|
import com.google.android.exoplayer2.source.chunk.MediaChunk;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fake {@link TrackSelection} that only returns 1 fixed track, and allows querying the number
|
* 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
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
// assert that track selection is in disabled state before this call.
|
// assert that track selection is in disabled state before this call.
|
||||||
Assert.assertFalse(isEnabled);
|
assertThat(isEnabled).isFalse();
|
||||||
enableCount++;
|
enableCount++;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +51,7 @@ public final class FakeTrackSelection implements TrackSelection {
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
// assert that track selection is in enabled state before this call.
|
// assert that track selection is in enabled state before this call.
|
||||||
Assert.assertTrue(isEnabled);
|
assertThat(isEnabled).isTrue();
|
||||||
releaseCount++;
|
releaseCount++;
|
||||||
isEnabled = false;
|
isEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +78,7 @@ public final class FakeTrackSelection implements TrackSelection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int indexOf(Format format) {
|
public int indexOf(Format format) {
|
||||||
Assert.assertTrue(isEnabled);
|
assertThat(isEnabled).isTrue();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,18 +120,18 @@ public final class FakeTrackSelection implements TrackSelection {
|
||||||
@Override
|
@Override
|
||||||
public void updateSelectedTrack(long playbackPositionUs, long bufferedDurationUs,
|
public void updateSelectedTrack(long playbackPositionUs, long bufferedDurationUs,
|
||||||
long availableDurationUs) {
|
long availableDurationUs) {
|
||||||
Assert.assertTrue(isEnabled);
|
assertThat(isEnabled).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue) {
|
public int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue) {
|
||||||
Assert.assertTrue(isEnabled);
|
assertThat(isEnabled).isTrue();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean blacklist(int index, long blacklistDurationMs) {
|
public boolean blacklist(int index, long blacklistDurationMs) {
|
||||||
Assert.assertTrue(isEnabled);
|
assertThat(isEnabled).isTrue();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
import static junit.framework.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
package com.google.android.exoplayer2.testutil;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertNotNull;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static org.junit.Assert.fail;
|
||||||
import static junit.framework.Assert.fail;
|
|
||||||
|
|
||||||
import android.os.ConditionVariable;
|
import android.os.ConditionVariable;
|
||||||
import android.os.Handler;
|
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) {
|
if (throwable[0] != null) {
|
||||||
Util.sneakyThrow(throwable[0]);
|
Util.sneakyThrow(throwable[0]);
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +137,7 @@ public class MediaSourceTestRunner {
|
||||||
holder[0] = mediaSource.createPeriod(periodId, allocator);
|
holder[0] = mediaSource.createPeriod(periodId, allocator);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertNotNull(holder[0]);
|
assertThat(holder[0]).isNotNull();
|
||||||
return holder[0];
|
return holder[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +200,7 @@ public class MediaSourceTestRunner {
|
||||||
* runner was created if neither method has been called).
|
* runner was created if neither method has been called).
|
||||||
*/
|
*/
|
||||||
public void assertNoTimelineChange() {
|
public void assertNoTimelineChange() {
|
||||||
assertTrue(timelines.isEmpty());
|
assertThat(timelines.isEmpty()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -224,7 +223,7 @@ public class MediaSourceTestRunner {
|
||||||
public Timeline assertTimelineChangeBlocking() {
|
public Timeline assertTimelineChangeBlocking() {
|
||||||
try {
|
try {
|
||||||
timeline = timelines.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
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();
|
assertNoTimelineChange();
|
||||||
return timeline;
|
return timeline;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
@ -254,12 +253,12 @@ public class MediaSourceTestRunner {
|
||||||
private void assertPrepareAndReleasePeriod(MediaPeriodId mediaPeriodId) {
|
private void assertPrepareAndReleasePeriod(MediaPeriodId mediaPeriodId) {
|
||||||
MediaPeriod mediaPeriod = createPeriod(mediaPeriodId);
|
MediaPeriod mediaPeriod = createPeriod(mediaPeriodId);
|
||||||
ConditionVariable preparedCondition = preparePeriod(mediaPeriod, 0);
|
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
|
// MediaSource is supposed to support multiple calls to createPeriod with the same id without an
|
||||||
// intervening call to releasePeriod.
|
// intervening call to releasePeriod.
|
||||||
MediaPeriod secondMediaPeriod = createPeriod(mediaPeriodId);
|
MediaPeriod secondMediaPeriod = createPeriod(mediaPeriodId);
|
||||||
ConditionVariable secondPreparedCondition = preparePeriod(secondMediaPeriod, 0);
|
ConditionVariable secondPreparedCondition = preparePeriod(secondMediaPeriod, 0);
|
||||||
assertTrue(secondPreparedCondition.block(TIMEOUT_MS));
|
assertThat(secondPreparedCondition.block(TIMEOUT_MS)).isTrue();
|
||||||
// Release the periods.
|
// Release the periods.
|
||||||
releasePeriod(mediaPeriod);
|
releasePeriod(mediaPeriod);
|
||||||
releasePeriod(secondMediaPeriod);
|
releasePeriod(secondMediaPeriod);
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,11 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
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.app.Instrumentation;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.test.MoreAsserts;
|
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.extractor.Extractor;
|
import com.google.android.exoplayer2.extractor.Extractor;
|
||||||
import com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException;
|
import com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException;
|
||||||
|
|
@ -29,7 +31,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for tests.
|
* Utility methods for tests.
|
||||||
|
|
@ -71,7 +72,7 @@ public class TestUtil {
|
||||||
while (position < length) {
|
while (position < length) {
|
||||||
int bytesRead = dataSource.read(data, position, data.length - position);
|
int bytesRead = dataSource.read(data, position, data.length - position);
|
||||||
if (bytesRead == C.RESULT_END_OF_INPUT) {
|
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 {
|
} else {
|
||||||
position += bytesRead;
|
position += bytesRead;
|
||||||
}
|
}
|
||||||
|
|
@ -164,13 +165,14 @@ public class TestUtil {
|
||||||
* data length. If false then it's asserted that {@link C#LENGTH_UNSET} is returned.
|
* 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}.
|
* @throws IOException If an error occurs reading fom the {@link DataSource}.
|
||||||
*/
|
*/
|
||||||
public static void assertDataSourceContent(DataSource dataSource, DataSpec dataSpec,
|
public static void assertDataSourceContent(
|
||||||
byte[] expectedData, boolean expectKnownLength) throws IOException {
|
DataSource dataSource, DataSpec dataSpec, byte[] expectedData, boolean expectKnownLength)
|
||||||
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
long length = dataSource.open(dataSpec);
|
long length = dataSource.open(dataSpec);
|
||||||
Assert.assertEquals(expectKnownLength ? expectedData.length : C.LENGTH_UNSET, length);
|
assertThat(length).isEqualTo(expectKnownLength ? expectedData.length : C.LENGTH_UNSET);
|
||||||
byte[] readData = TestUtil.readToEnd(dataSource);
|
byte[] readData = readToEnd(dataSource);
|
||||||
MoreAsserts.assertEquals(expectedData, readData);
|
assertThat(readData).isEqualTo(expectedData);
|
||||||
} finally {
|
} finally {
|
||||||
dataSource.close();
|
dataSource.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.testutil;
|
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.C;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
|
|
@ -27,6 +28,10 @@ import com.google.android.exoplayer2.Timeline.Window;
|
||||||
*/
|
*/
|
||||||
public final class TimelineAsserts {
|
public final class TimelineAsserts {
|
||||||
|
|
||||||
|
private static final int[] REPEAT_MODES = {
|
||||||
|
Player.REPEAT_MODE_OFF, Player.REPEAT_MODE_ONE, Player.REPEAT_MODE_ALL
|
||||||
|
};
|
||||||
|
|
||||||
private TimelineAsserts() {}
|
private TimelineAsserts() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,8 +41,8 @@ public final class TimelineAsserts {
|
||||||
assertWindowIds(timeline);
|
assertWindowIds(timeline);
|
||||||
assertPeriodCounts(timeline);
|
assertPeriodCounts(timeline);
|
||||||
for (boolean shuffled : new boolean[] {false, true}) {
|
for (boolean shuffled : new boolean[] {false, true}) {
|
||||||
assertEquals(C.INDEX_UNSET, timeline.getFirstWindowIndex(shuffled));
|
assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET);
|
||||||
assertEquals(C.INDEX_UNSET, timeline.getLastWindowIndex(shuffled));
|
assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,11 +54,11 @@ public final class TimelineAsserts {
|
||||||
*/
|
*/
|
||||||
public static void assertWindowIds(Timeline timeline, Object... expectedWindowIds) {
|
public static void assertWindowIds(Timeline timeline, Object... expectedWindowIds) {
|
||||||
Window window = new Window();
|
Window window = new Window();
|
||||||
assertEquals(expectedWindowIds.length, timeline.getWindowCount());
|
assertThat(timeline.getWindowCount()).isEqualTo(expectedWindowIds.length);
|
||||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||||
timeline.getWindow(i, window, true);
|
timeline.getWindow(i, window, true);
|
||||||
if (expectedWindowIds[i] != null) {
|
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();
|
Window window = new Window();
|
||||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||||
timeline.getWindow(i, window, true);
|
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,
|
@Player.RepeatMode int repeatMode, boolean shuffleModeEnabled,
|
||||||
int... expectedPreviousWindowIndices) {
|
int... expectedPreviousWindowIndices) {
|
||||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||||
assertEquals(expectedPreviousWindowIndices[i],
|
assertThat(timeline.getPreviousWindowIndex(i, repeatMode, shuffleModeEnabled))
|
||||||
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,
|
public static void assertNextWindowIndices(Timeline timeline, @Player.RepeatMode int repeatMode,
|
||||||
boolean shuffleModeEnabled, int... expectedNextWindowIndices) {
|
boolean shuffleModeEnabled, int... expectedNextWindowIndices) {
|
||||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||||
assertEquals(expectedNextWindowIndices[i],
|
assertThat(timeline.getNextWindowIndex(i, repeatMode, shuffleModeEnabled))
|
||||||
timeline.getNextWindowIndex(i, repeatMode, shuffleModeEnabled));
|
.isEqualTo(expectedNextWindowIndices[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,14 +111,14 @@ public final class TimelineAsserts {
|
||||||
for (int i = 0; i < windowCount; i++) {
|
for (int i = 0; i < windowCount; i++) {
|
||||||
accumulatedPeriodCounts[i + 1] = accumulatedPeriodCounts[i] + expectedPeriodCounts[i];
|
accumulatedPeriodCounts[i + 1] = accumulatedPeriodCounts[i] + expectedPeriodCounts[i];
|
||||||
}
|
}
|
||||||
assertEquals(accumulatedPeriodCounts[accumulatedPeriodCounts.length - 1],
|
assertThat(timeline.getPeriodCount())
|
||||||
timeline.getPeriodCount());
|
.isEqualTo(accumulatedPeriodCounts[accumulatedPeriodCounts.length - 1]);
|
||||||
Window window = new Window();
|
Window window = new Window();
|
||||||
Period period = new Period();
|
Period period = new Period();
|
||||||
for (int i = 0; i < windowCount; i++) {
|
for (int i = 0; i < windowCount; i++) {
|
||||||
timeline.getWindow(i, window, true);
|
timeline.getWindow(i, window, true);
|
||||||
assertEquals(accumulatedPeriodCounts[i], window.firstPeriodIndex);
|
assertThat(window.firstPeriodIndex).isEqualTo(accumulatedPeriodCounts[i]);
|
||||||
assertEquals(accumulatedPeriodCounts[i + 1] - 1, window.lastPeriodIndex);
|
assertThat(window.lastPeriodIndex).isEqualTo(accumulatedPeriodCounts[i + 1] - 1);
|
||||||
}
|
}
|
||||||
int expectedWindowIndex = 0;
|
int expectedWindowIndex = 0;
|
||||||
for (int i = 0; i < timeline.getPeriodCount(); i++) {
|
for (int i = 0; i < timeline.getPeriodCount(); i++) {
|
||||||
|
|
@ -121,18 +126,18 @@ public final class TimelineAsserts {
|
||||||
while (i >= accumulatedPeriodCounts[expectedWindowIndex + 1]) {
|
while (i >= accumulatedPeriodCounts[expectedWindowIndex + 1]) {
|
||||||
expectedWindowIndex++;
|
expectedWindowIndex++;
|
||||||
}
|
}
|
||||||
assertEquals(expectedWindowIndex, period.windowIndex);
|
assertThat(period.windowIndex).isEqualTo(expectedWindowIndex);
|
||||||
assertEquals(i, timeline.getIndexOfPeriod(period.uid));
|
assertThat(timeline.getIndexOfPeriod(period.uid)).isEqualTo(i);
|
||||||
for (@Player.RepeatMode int repeatMode
|
for (int repeatMode : REPEAT_MODES) {
|
||||||
: new int[] {Player.REPEAT_MODE_OFF, Player.REPEAT_MODE_ONE, Player.REPEAT_MODE_ALL}) {
|
|
||||||
if (i < accumulatedPeriodCounts[expectedWindowIndex + 1] - 1) {
|
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 {
|
} else {
|
||||||
int nextWindow = timeline.getNextWindowIndex(expectedWindowIndex, repeatMode, false);
|
int nextWindow = timeline.getNextWindowIndex(expectedWindowIndex, repeatMode, false);
|
||||||
int nextPeriod = nextWindow == C.INDEX_UNSET ? C.INDEX_UNSET
|
int nextPeriod = nextWindow == C.INDEX_UNSET ? C.INDEX_UNSET
|
||||||
: accumulatedPeriodCounts[nextWindow];
|
: accumulatedPeriodCounts[nextWindow];
|
||||||
assertEquals(nextPeriod, timeline.getNextPeriodIndex(i, period, window, repeatMode,
|
assertThat(timeline.getNextPeriodIndex(i, period, window, repeatMode, false))
|
||||||
false));
|
.isEqualTo(nextPeriod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +150,7 @@ public final class TimelineAsserts {
|
||||||
Period period = new Period();
|
Period period = new Period();
|
||||||
for (int i = 0; i < timeline.getPeriodCount(); i++) {
|
for (int i = 0; i < timeline.getPeriodCount(); i++) {
|
||||||
timeline.getPeriod(i, period);
|
timeline.getPeriod(i, period);
|
||||||
assertEquals(expectedAdGroupCounts[i], period.getAdGroupCount());
|
assertThat(period.getAdGroupCount()).isEqualTo(expectedAdGroupCounts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue