diff options
Diffstat (limited to 'media/tests/MediaFrameworkTest/src')
5 files changed, 251 insertions, 253 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java index a203adc..62af3f3 100755 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java @@ -47,6 +47,7 @@ public class MediaFrameworkUnitTestRunner extends InstrumentationTestRunner { addMediaMetadataRetrieverStateUnitTests(suite); addMediaRecorderStateUnitTests(suite); addMediaPlayerStateUnitTests(suite); + addMediaScannerUnitTests(suite); return suite; } @@ -89,4 +90,8 @@ public class MediaFrameworkUnitTestRunner extends InstrumentationTestRunner { suite.addTestSuite(MediaPlayerSetVolumeStateUnitTest.class); suite.addTestSuite(MediaPlayerMetadataParserTest.class); } + + private void addMediaScannerUnitTests(TestSuite suite) { + suite.addTestSuite(MediaInserterTest.class); + } } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java index e3aa8cf..1fa5c0d 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java @@ -44,13 +44,7 @@ import java.util.UUID; */ public class MediaBassBoostTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { private String TAG = "MediaBassBoostTest"; - private final static int MIN_ENERGY_RATIO_2 = 3; private final static short TEST_STRENGTH = 500; - private final static int TEST_VOLUME = 4; - // Implementor UUID for volume controller effect defined in - // frameworks/base/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp - private final static UUID VOLUME_EFFECT_UUID = - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"); private BassBoost mBassBoost = null; private int mSession = -1; @@ -184,85 +178,6 @@ public class MediaBassBoostTest extends ActivityInstrumentationTestCase2<MediaFr } //----------------------------------------------------------------- - // 2 - Effect action - //---------------------------------- - - //Test case 2.0: test actual bass boost influence on sound - @LargeTest - public void test2_0SoundModification() throws Exception { - boolean result = false; - String msg = "test2_0SoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - TEST_VOLUME, - 0); - - try { - probe = new EnergyProbe(0); - // creating a volume controller on output mix ensures that ro.audio.silent mutes - // audio after the effects and not before - vc = new AudioEffect( - AudioEffect.EFFECT_TYPE_NULL, - VOLUME_EFFECT_UUID, - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setLooping(true); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - getBassBoost(mp.getAudioSessionId()); - mp.prepare(); - mp.start(); - Thread.sleep(200); - // measure reference energy around 1kHz - int refEnergy200 = probe.capture(200); - int refEnergy1000 = probe.capture(1000); - mBassBoost.setStrength((short)1000); - mBassBoost.setEnabled(true); - Thread.sleep(4000); - // measure energy around 1kHz with band level at min - int energy200 = probe.capture(200); - int energy1000 = probe.capture(1000); - // verify that the energy ration between low and high frequencies is at least - // MIN_ENERGY_RATIO_2 times higher with bassboost on. - assertTrue(msg + ": bass boost has no effect", - ((float)energy200/(float)energy1000) > - (MIN_ENERGY_RATIO_2 * ((float)refEnergy200/(float)refEnergy1000))); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseBassBoost(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - //----------------------------------------------------------------- // private methods //---------------------------------- diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java index ee91bbb..da9089d 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java @@ -49,11 +49,6 @@ public class MediaEqualizerTest extends ActivityInstrumentationTestCase2<MediaFr private final static int MAX_BAND_LEVEL = 1500; private final static int TEST_FREQUENCY_MILLIHERTZ = 1000000; private final static int MIN_NUMBER_OF_PRESETS = 4; - private final static int TEST_VOLUME = 4; - // Implementor UUID for volume controller effect defined in - // frameworks/base/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp - private final static UUID VOLUME_EFFECT_UUID = - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"); private Equalizer mEqualizer = null; private int mSession = -1; @@ -252,80 +247,6 @@ public class MediaEqualizerTest extends ActivityInstrumentationTestCase2<MediaFr } //----------------------------------------------------------------- - // 2 - Effect action - //---------------------------------- - - //Test case 2.0: test that the equalizer actually alters the sound - @LargeTest - public void test2_0SoundModification() throws Exception { - boolean result = false; - String msg = "test2_0SoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - TEST_VOLUME, - 0); - try { - probe = new EnergyProbe(0); - // creating a volume controller on output mix ensures that ro.audio.silent mutes - // audio after the effects and not before - vc = new AudioEffect( - AudioEffect.EFFECT_TYPE_NULL, - VOLUME_EFFECT_UUID, - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - getEqualizer(mp.getAudioSessionId()); - mp.prepare(); - mp.start(); - Thread.sleep(500); - // measure reference energy around 1kHz - int refEnergy = probe.capture(1000); - short band = mEqualizer.getBand(1000000); - short[] levelRange = mEqualizer.getBandLevelRange(); - mEqualizer.setBandLevel(band, levelRange[0]); - mEqualizer.setEnabled(true); - Thread.sleep(500); - // measure energy around 1kHz with band level at min - int energy = probe.capture(1000); - assertTrue(msg + ": equalizer has no effect at 1kHz", energy < refEnergy/4); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseEqualizer(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- // private methods //---------------------------------- diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java index b74e525..122545f 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java @@ -44,13 +44,7 @@ import java.util.UUID; */ public class MediaVirtualizerTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { private String TAG = "MediaVirtualizerTest"; - private final static int MIN_ENERGY_RATIO_2 = 2; private final static short TEST_STRENGTH = 500; - private final static int TEST_VOLUME = 4; - // Implementor UUID for volume controller effect defined in - // frameworks/base/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp - private final static UUID VOLUME_EFFECT_UUID = - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"); private Virtualizer mVirtualizer = null; private int mSession = -1; @@ -185,89 +179,6 @@ public class MediaVirtualizerTest extends ActivityInstrumentationTestCase2<Media } //----------------------------------------------------------------- - // 2 - Effect action - //---------------------------------- - - //Test case 2.0: test actual virtualizer influence on sound - @LargeTest - public void test2_0SoundModification() throws Exception { - boolean result = false; - String msg = "test2_0SoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - TEST_VOLUME, - 0); - - try { - probe = new EnergyProbe(0); - // creating a volume controller on output mix ensures that ro.audio.silent mutes - // audio after the effects and not before - vc = new AudioEffect( - AudioEffect.EFFECT_TYPE_NULL, - VOLUME_EFFECT_UUID, - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setLooping(true); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - getVirtualizer(mp.getAudioSessionId()); - mp.prepare(); - mp.start(); - Thread.sleep(200); - // measure reference energy around 1kHz - int refEnergy200 = probe.capture(200); - int refEnergy1000 = probe.capture(1000); - mVirtualizer.setStrength((short)1000); - mVirtualizer.setEnabled(true); - Thread.sleep(4000); - // measure energy around 1kHz with band level at min - int energy200 = probe.capture(200); - int energy1000 = probe.capture(1000); - // verify that the energy ration between low and high frequencies is at least - // MIN_ENERGY_RATIO_2 times higher with virtualizer on. - // NOTE: this is what is observed with current virtualizer implementation and the test - // audio file but is not the primary effect of the virtualizer. A better way would - // be to have a stereo PCM capture and check that a strongly paned input is centered - // when output. However, we cannot capture stereo with the visualizer. - assertTrue(msg + ": virtualizer has no effect", - ((float)energy200/(float)energy1000) > - (MIN_ENERGY_RATIO_2 * ((float)refEnergy200/(float)refEnergy1000))); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseVirtualizer(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - //----------------------------------------------------------------- // private methods //---------------------------------- diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java new file mode 100644 index 0000000..ad3c342 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.unit; + +import android.content.ContentValues; +import android.content.IContentProvider; +import android.media.MediaInserter; +import android.net.Uri; +import android.provider.MediaStore.Audio; +import android.provider.MediaStore.Files; +import android.provider.MediaStore.Images; +import android.provider.MediaStore.Video; +import android.test.InstrumentationTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import dalvik.annotation.TestTargetClass; + +import org.easymock.EasyMock; +import org.easymock.IArgumentMatcher; + +@TestTargetClass(MediaInserter.class) +public class MediaInserterTest extends InstrumentationTestCase { + + private MediaInserter mMediaInserter; + private static final int TEST_BUFFER_SIZE = 10; + private IContentProvider mMockProvider; + + private int mFilesCounter; + private int mAudioCounter; + private int mVideoCounter; + private int mImagesCounter; + + private static final String sVolumeName = "external"; + private static final Uri sAudioUri = Audio.Media.getContentUri(sVolumeName); + private static final Uri sVideoUri = Video.Media.getContentUri(sVolumeName); + private static final Uri sImagesUri = Images.Media.getContentUri(sVolumeName); + private static final Uri sFilesUri = Files.getContentUri(sVolumeName); + + private static class MediaUriMatcher implements IArgumentMatcher { + private Uri mUri; + + private MediaUriMatcher(Uri uri) { + mUri = uri; + } + + @Override + public boolean matches(Object argument) { + if (!(argument instanceof Uri)) { + return false; + } + + Uri actualUri = (Uri) argument; + if (actualUri == mUri) return true; + return false; + } + + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("expected a TableUri '").append(mUri).append("'"); + } + + private static Uri expectMediaUri(Uri in) { + EasyMock.reportMatcher(new MediaUriMatcher(in)); + return null; + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mMockProvider = EasyMock.createMock(IContentProvider.class); + mMediaInserter = new MediaInserter(mMockProvider, TEST_BUFFER_SIZE); + mFilesCounter = 0; + mAudioCounter = 0; + mVideoCounter = 0; + mImagesCounter = 0; + } + + private ContentValues createFileContent() { + ContentValues values = new ContentValues(); + values.put("_data", "/mnt/sdcard/file" + ++mFilesCounter); + return values; + } + + private ContentValues createAudioContent() { + ContentValues values = new ContentValues(); + values.put("_data", "/mnt/sdcard/audio" + ++mAudioCounter); + return values; + } + + private ContentValues createVideoContent() { + ContentValues values = new ContentValues(); + values.put("_data", "/mnt/sdcard/video" + ++mVideoCounter); + return values; + } + + private ContentValues createImageContent() { + ContentValues values = new ContentValues(); + values.put("_data", "/mnt/sdcard/image" + ++mImagesCounter); + return values; + } + + private ContentValues createContent(Uri uri) { + if (uri == sFilesUri) return createFileContent(); + else if (uri == sAudioUri) return createAudioContent(); + else if (uri == sVideoUri) return createVideoContent(); + else if (uri == sImagesUri) return createImageContent(); + else throw new IllegalArgumentException("Unknown URL: " + uri.toString()); + } + + private void fillBuffer(Uri uri, int numberOfFiles) throws Exception { + ContentValues values; + for (int i = 0; i < numberOfFiles; ++i) { + values = createContent(uri); + mMediaInserter.insert(uri, values); + } + } + + @SmallTest + public void testInsertContentsLessThanBufferSize() throws Exception { + EasyMock.replay(mMockProvider); + + fillBuffer(sFilesUri, TEST_BUFFER_SIZE - 4); + fillBuffer(sAudioUri, TEST_BUFFER_SIZE - 3); + fillBuffer(sVideoUri, TEST_BUFFER_SIZE - 2); + fillBuffer(sImagesUri, TEST_BUFFER_SIZE - 1); + + EasyMock.verify(mMockProvider); + } + + @SmallTest + public void testInsertContentsEqualToBufferSize() throws Exception { + EasyMock.expect(mMockProvider.bulkInsert( + (Uri) EasyMock.anyObject(), (ContentValues[]) EasyMock.anyObject())).andReturn(1); + EasyMock.expectLastCall().times(4); + EasyMock.replay(mMockProvider); + + fillBuffer(sFilesUri, TEST_BUFFER_SIZE); + fillBuffer(sAudioUri, TEST_BUFFER_SIZE); + fillBuffer(sVideoUri, TEST_BUFFER_SIZE); + fillBuffer(sImagesUri, TEST_BUFFER_SIZE); + + EasyMock.verify(mMockProvider); + } + + @SmallTest + public void testInsertContentsMoreThanBufferSize() throws Exception { + EasyMock.expect(mMockProvider.bulkInsert( + (Uri) EasyMock.anyObject(), (ContentValues[]) EasyMock.anyObject())).andReturn(1); + EasyMock.expectLastCall().times(4); + EasyMock.replay(mMockProvider); + + fillBuffer(sFilesUri, TEST_BUFFER_SIZE + 1); + fillBuffer(sAudioUri, TEST_BUFFER_SIZE + 2); + fillBuffer(sVideoUri, TEST_BUFFER_SIZE + 3); + fillBuffer(sImagesUri, TEST_BUFFER_SIZE + 4); + + EasyMock.verify(mMockProvider); + } + + @SmallTest + public void testFlushAllWithEmptyContents() throws Exception { + EasyMock.replay(mMockProvider); + + mMediaInserter.flushAll(); + + EasyMock.verify(mMockProvider); + } + + @SmallTest + public void testFlushAllWithSomeContents() throws Exception { + EasyMock.expect(mMockProvider.bulkInsert( + (Uri) EasyMock.anyObject(), (ContentValues[]) EasyMock.anyObject())).andReturn(1); + EasyMock.expectLastCall().times(4); + EasyMock.replay(mMockProvider); + + fillBuffer(sFilesUri, TEST_BUFFER_SIZE - 4); + fillBuffer(sAudioUri, TEST_BUFFER_SIZE - 3); + fillBuffer(sVideoUri, TEST_BUFFER_SIZE - 2); + fillBuffer(sImagesUri, TEST_BUFFER_SIZE - 1); + mMediaInserter.flushAll(); + + EasyMock.verify(mMockProvider); + } + + @SmallTest + public void testInsertContentsAfterFlushAll() throws Exception { + EasyMock.expect(mMockProvider.bulkInsert( + (Uri) EasyMock.anyObject(), (ContentValues[]) EasyMock.anyObject())).andReturn(1); + EasyMock.expectLastCall().times(8); + EasyMock.replay(mMockProvider); + + fillBuffer(sFilesUri, TEST_BUFFER_SIZE - 4); + fillBuffer(sAudioUri, TEST_BUFFER_SIZE - 3); + fillBuffer(sVideoUri, TEST_BUFFER_SIZE - 2); + fillBuffer(sImagesUri, TEST_BUFFER_SIZE - 1); + mMediaInserter.flushAll(); + + fillBuffer(sFilesUri, TEST_BUFFER_SIZE + 1); + fillBuffer(sAudioUri, TEST_BUFFER_SIZE + 2); + fillBuffer(sVideoUri, TEST_BUFFER_SIZE + 3); + fillBuffer(sImagesUri, TEST_BUFFER_SIZE + 4); + + EasyMock.verify(mMockProvider); + } + + @SmallTest + public void testInsertContentsWithDifferentSizePerContentType() throws Exception { + EasyMock.expect(mMockProvider.bulkInsert(MediaUriMatcher.expectMediaUri(sFilesUri), + (ContentValues[]) EasyMock.anyObject())).andReturn(1); + EasyMock.expectLastCall().times(1); + EasyMock.expect(mMockProvider.bulkInsert(MediaUriMatcher.expectMediaUri(sAudioUri), + (ContentValues[]) EasyMock.anyObject())).andReturn(1); + EasyMock.expectLastCall().times(2); + EasyMock.expect(mMockProvider.bulkInsert(MediaUriMatcher.expectMediaUri(sVideoUri), + (ContentValues[]) EasyMock.anyObject())).andReturn(1); + EasyMock.expectLastCall().times(3); + EasyMock.expect(mMockProvider.bulkInsert(MediaUriMatcher.expectMediaUri(sImagesUri), + (ContentValues[]) EasyMock.anyObject())).andReturn(1); + EasyMock.expectLastCall().times(4); + EasyMock.replay(mMockProvider); + + for (int i = 0; i < TEST_BUFFER_SIZE; ++i) { + fillBuffer(sFilesUri, 1); + fillBuffer(sAudioUri, 2); + fillBuffer(sVideoUri, 3); + fillBuffer(sImagesUri, 4); + } + + EasyMock.verify(mMockProvider); + } +} |