MediaEqualizerTestpublic class MediaEqualizerTest extends android.test.ActivityInstrumentationTestCase2 Junit / Instrumentation test case for the media AudioTrack api |
Fields Summary |
---|
private String | TAG | private static final int | MIN_NUMBER_OF_BANDS | private static final int | MIN_BAND_LEVEL | private static final int | MAX_BAND_LEVEL | private static final int | TEST_FREQUENCY_MILLIHERTZ | private static final int | MIN_NUMBER_OF_PRESETS | private android.media.audiofx.Equalizer | mEqualizer | private int | mSession |
Constructors Summary |
---|
public MediaEqualizerTest()
super("com.android.mediaframeworktest", MediaFrameworkTest.class);
|
Methods Summary |
---|
private static void | assumeTrue(java.lang.String message, boolean cond)
assertTrue("(assume)"+message, cond);
| private void | getEqualizer(int session)
if (mEqualizer == null || session != mSession) {
if (session != mSession && mEqualizer != null) {
mEqualizer.release();
mEqualizer = null;
}
try {
mEqualizer = new Equalizer(0, session);
mSession = session;
} catch (IllegalArgumentException e) {
Log.e(TAG, "getEqualizer() Equalizer not found exception: "+e);
} catch (UnsupportedOperationException e) {
Log.e(TAG, "getEqualizer() Effect library not loaded exception: "+e);
}
}
assertNotNull("could not create mEqualizer", mEqualizer);
| private void | log(java.lang.String testName, java.lang.String message)
Log.v(TAG, "["+testName+"] "+message);
| private void | loge(java.lang.String testName, java.lang.String message)
Log.e(TAG, "["+testName+"] "+message);
| private void | releaseEqualizer()
if (mEqualizer != null) {
mEqualizer.release();
mEqualizer = null;
}
| protected void | setUp()
super.setUp();
| protected void | tearDown()
super.tearDown();
releaseEqualizer();
| public void | test0_0ConstructorAndRelease()
boolean result = false;
String msg = "test1_0ConstructorAndRelease()";
Equalizer eq = null;
try {
eq = new Equalizer(0, 0);
assertNotNull(msg + ": could not create Equalizer", eq);
try {
assertTrue(msg +": invalid effect ID", (eq.getId() != 0));
} catch (IllegalStateException e) {
msg = msg.concat(": Equalizer not initialized");
}
result = true;
} catch (IllegalArgumentException e) {
msg = msg.concat(": Equalizer not found");
} catch (UnsupportedOperationException e) {
msg = msg.concat(": Effect library not loaded");
} finally {
if (eq != null) {
eq.release();
}
}
assertTrue(msg, result);
| public void | test1_0BandLevel()
boolean result = false;
String msg = "test1_0BandLevel()";
getEqualizer(0);
try {
short numBands = mEqualizer.getNumberOfBands();
assertTrue(msg + ": not enough bands", numBands >= MIN_NUMBER_OF_BANDS);
short[] levelRange = mEqualizer.getBandLevelRange();
assertTrue(msg + ": min level too high", levelRange[0] <= MIN_BAND_LEVEL);
assertTrue(msg + ": max level too low", levelRange[1] >= MAX_BAND_LEVEL);
mEqualizer.setBandLevel((short)0, levelRange[1]);
short level = mEqualizer.getBandLevel((short)0);
// 10% margin on actual level compared to requested level
assertTrue(msg + ": setBandLevel failed",
((float)level > (float)levelRange[1] * 0.9f) &&
((float)level < (float)levelRange[1] * 1.1f));
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");
} finally {
releaseEqualizer();
}
assertTrue(msg, result);
| public void | test1_1BandFrequency()
boolean result = false;
String msg = "test1_1BandFrequency()";
getEqualizer(0);
try {
short band = mEqualizer.getBand(TEST_FREQUENCY_MILLIHERTZ);
assertTrue(msg + ": getBand failed", band >= 0);
int[] freqRange = mEqualizer.getBandFreqRange(band);
assertTrue(msg + ": getBandFreqRange failed",
(freqRange[0] <= TEST_FREQUENCY_MILLIHERTZ) &&
(freqRange[1] >= TEST_FREQUENCY_MILLIHERTZ));
int freq = mEqualizer.getCenterFreq(band);
assertTrue(msg + ": getCenterFreq failed",
(freqRange[0] <= freq) && (freqRange[1] >= freq));
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");
} finally {
releaseEqualizer();
}
assertTrue(msg, result);
| public void | test1_2Presets()
boolean result = false;
String msg = "test1_2Presets()";
getEqualizer(0);
try {
short numPresets = mEqualizer.getNumberOfPresets();
assertTrue(msg + ": getNumberOfPresets failed", numPresets >= MIN_NUMBER_OF_PRESETS);
mEqualizer.usePreset((short)(numPresets - 1));
short preset = mEqualizer.getCurrentPreset();
assertEquals(msg + ": usePreset failed", preset, (short)(numPresets - 1));
String name = mEqualizer.getPresetName(preset);
assertNotNull(msg + ": getPresetName failed", name);
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");
} finally {
releaseEqualizer();
}
assertTrue(msg, result);
| public void | test1_3Properties()
boolean result = false;
String msg = "test1_3Properties()";
getEqualizer(0);
try {
Equalizer.Settings settings = mEqualizer.getProperties();
String str = settings.toString();
settings = new Equalizer.Settings(str);
mEqualizer.setProperties(settings);
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");
} finally {
releaseEqualizer();
}
assertTrue(msg, result);
|
|