use of android.media.AudioRecord in project robolectric by robolectric.
the class ShadowAudioRecordTest method nativeReadByteBufferFillsAudioDataByDefault.
@Test
public void nativeReadByteBufferFillsAudioDataByDefault() {
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
assertThat(audioRecord.read(ByteBuffer.allocate(100), 100)).isEqualTo(100);
}
use of android.media.AudioRecord in project robolectric by robolectric.
the class ShadowAudioRecordTest method startReturnsSuccess.
@Test
public void startReturnsSuccess() {
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
assertThat(audioRecord.getRecordingState()).isEqualTo(AudioRecord.RECORDSTATE_RECORDING);
}
use of android.media.AudioRecord in project robolectric by robolectric.
the class ShadowAudioRecordTest method nativeReadByteBufferCallsAudioRecordSourceWhenSetNonBlockingMOnwards.
@Test
@Config(minSdk = M)
public void nativeReadByteBufferCallsAudioRecordSourceWhenSetNonBlockingMOnwards() {
AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
ShadowAudioRecord.setSource(source);
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
audioRecord.read(ByteBuffer.allocate(100), 100, AudioRecord.READ_NON_BLOCKING);
verify(source).readInDirectBuffer(any(ByteBuffer.class), eq(100), /* isBlocking=*/
eq(false));
verifyNoMoreInteractions(source);
}
use of android.media.AudioRecord 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 android.media.AudioRecord 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);
}
Aggregations