Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15e7a215 authored by Jimmy Dalqvist's avatar Jimmy Dalqvist Committed by Steve Kondik
Browse files

Correct MediaAudioTrackTest testPlaybackHeadPositionAfterStop

When calling AudioTrack.stop the system needs some time to stop
the audiotrack and set the position to 0.
The current sleep time of 100ms is not enough.
Update the test to use the same strategy as the CTS test,
which is to call getPlaybackHeadPosition multiple time before
giving up and failing the test.

Change-Id: Ie938929c009c41e101782b4a46ac01a0aa73ee34
parent ad3fa417
Loading
Loading
Loading
Loading
+9 −3
Original line number Original line Diff line number Diff line
@@ -386,6 +386,7 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
        final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
        final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
        final int TEST_MODE = AudioTrack.MODE_STREAM;
        final int TEST_MODE = AudioTrack.MODE_STREAM;
        final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
        final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
        final int TEST_LOOP_CNT = 10;
        
        
        //-------- initialization --------------
        //-------- initialization --------------
        int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
        int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
@@ -399,9 +400,14 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
        track.play();
        track.play();
        Thread.sleep(100);
        Thread.sleep(100);
        track.stop();
        track.stop();
        Thread.sleep(100); // TODO: what is a sensible value?
        int count = 0;
        int pos = track.getPlaybackHeadPosition();
        int pos;
        log(TEST_NAME, "position ="+ pos);
        do {
            Thread.sleep(200);
            pos = track.getPlaybackHeadPosition();
            count++;
        } while((pos != 0) && (count < TEST_LOOP_CNT));
        log(TEST_NAME, "position =" + pos + ", read count ="+count);
        assertTrue(TEST_NAME, pos == 0);
        assertTrue(TEST_NAME, pos == 0);
        //-------- tear down      --------------
        //-------- tear down      --------------
        track.release();
        track.release();