use of org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource in project robolectric by robolectric.
the class ShadowAudioRecordTest method nativeReadByteCallsAudioRecordSourceWhenSetNonBlockingMOnwards.
@Test
@Config(minSdk = M)
public void nativeReadByteCallsAudioRecordSourceWhenSetNonBlockingMOnwards() {
AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
ShadowAudioRecord.setSource(source);
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
audioRecord.read(new byte[100], 0, 100, AudioRecord.READ_NON_BLOCKING);
verify(source).readInByteArray(any(byte[].class), eq(0), eq(100), /* isBlocking=*/
eq(false));
verifyNoMoreInteractions(source);
}
use of org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource in project robolectric by robolectric.
the class ShadowAudioRecordTest method setSourceProvider_readBytesSlowly.
@Test
public void setSourceProvider_readBytesSlowly() {
byte[] audioRecordInput = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
AudioRecordSource audioRecordSource = createAudioRecordSource(audioRecordInput);
ShadowAudioRecord.setSourceProvider(audioRecord -> audioRecordSource);
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
byte[] audioRecordData = new byte[100];
int audioRecordBytesFirstRead = audioRecord.read(audioRecordData, 0, 3);
int audioRecordBytesSecondRead = audioRecord.read(audioRecordData, 3, 3);
int audioRecordBytesThirdRead = audioRecord.read(audioRecordData, 6, 94);
audioRecord.stop();
audioRecord.release();
assertThat(audioRecordBytesFirstRead).isEqualTo(3);
assertThat(audioRecordBytesSecondRead).isEqualTo(3);
assertThat(audioRecordBytesThirdRead).isEqualTo(2);
assertThat(Arrays.copyOf(audioRecordData, audioRecordInput.length)).isEqualTo(audioRecordInput);
}
use of org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource in project robolectric by robolectric.
the class ShadowAudioRecordTest method nativeReadShortCallsAudioRecordSourceWhenSetBlockingMOnwards.
@Test
@Config(minSdk = M)
public void nativeReadShortCallsAudioRecordSourceWhenSetBlockingMOnwards() {
AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
ShadowAudioRecord.setSource(source);
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
audioRecord.read(new short[100], 0, 100, AudioRecord.READ_BLOCKING);
verify(source).readInShortArray(any(short[].class), eq(0), eq(100), /* isBlocking=*/
eq(true));
verifyNoMoreInteractions(source);
}
Aggregations