Search in sources :

Example 11 with AudioRecordSource

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);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 12 with AudioRecordSource

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);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) Test(org.junit.Test)

Example 13 with AudioRecordSource

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);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

AudioRecord (android.media.AudioRecord)13 Test (org.junit.Test)13 AudioRecordSource (org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource)13 Config (org.robolectric.annotation.Config)8 ByteBuffer (java.nio.ByteBuffer)3