Search in sources :

Example 1 with AudioRecordSource

use of org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource in project robolectric by robolectric.

the class ShadowAudioRecordTest method nativeReadByteCallsAudioRecordSourceWhenSetBlockingMOnwards.

@Test
@Config(minSdk = M)
public void nativeReadByteCallsAudioRecordSourceWhenSetBlockingMOnwards() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(new byte[100], 0, 100, AudioRecord.READ_BLOCKING);
    verify(source).readInByteArray(any(byte[].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)

Example 2 with AudioRecordSource

use of org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource in project robolectric by robolectric.

the class ShadowAudioRecordTest method nativeReadFloatCallsAudioRecordSourceWhenSetNonBlocking.

@Test
@Config(minSdk = M)
public void nativeReadFloatCallsAudioRecordSourceWhenSetNonBlocking() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = new AudioRecord(AudioSource.MIC, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_FLOAT, 1024);
    audioRecord.startRecording();
    audioRecord.read(new float[100], 0, 100, AudioRecord.READ_NON_BLOCKING);
    verify(source).readInFloatArray(any(float[].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 3 with AudioRecordSource

use of org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource in project robolectric by robolectric.

the class ShadowAudioRecordTest method nativeReadByteBufferCallsAudioRecordSourceWhenSetBlockingMOnwards.

@Test
@Config(minSdk = M)
public void nativeReadByteBufferCallsAudioRecordSourceWhenSetBlockingMOnwards() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(ByteBuffer.allocate(100), 100, AudioRecord.READ_BLOCKING);
    verify(source).readInDirectBuffer(any(ByteBuffer.class), eq(100), /* isBlocking=*/
    eq(true));
    verifyNoMoreInteractions(source);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 4 with AudioRecordSource

use of org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource in project robolectric by robolectric.

the class ShadowAudioRecordTest method nativeReadShortCallsAudioRecordSourceWhenSet.

@Test
public void nativeReadShortCallsAudioRecordSourceWhenSet() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(new short[100], 0, 100);
    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)

Example 5 with AudioRecordSource

use of org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource in project robolectric by robolectric.

the class ShadowAudioRecordTest method nativeReadByteBufferCallsAudioRecordSourceWhenSet.

@Test
public void nativeReadByteBufferCallsAudioRecordSourceWhenSet() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(ByteBuffer.allocate(100), 100);
    verify(source).readInDirectBuffer(any(ByteBuffer.class), eq(100), /* isBlocking=*/
    eq(true));
    verifyNoMoreInteractions(source);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

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