FileDocCategorySizeDatePackage
MediaVirtualizerTest.javaAPI DocAndroid 5.1 API7607Thu Mar 12 22:22:30 GMT 2015com.android.mediaframeworktest.functional.audio

MediaVirtualizerTest

public class MediaVirtualizerTest extends android.test.ActivityInstrumentationTestCase2
Junit / Instrumentation test case for the media AudioTrack api

Fields Summary
private String
TAG
private static final short
TEST_STRENGTH
private android.media.audiofx.Virtualizer
mVirtualizer
private int
mSession
Constructors Summary
public MediaVirtualizerTest()


      
        super("com.android.mediaframeworktest", MediaFrameworkTest.class);
    
Methods Summary
private static voidassumeTrue(java.lang.String message, boolean cond)

        assertTrue("(assume)"+message, cond);
    
private voidgetVirtualizer(int session)

         if (mVirtualizer == null || session != mSession) {
             if (session != mSession && mVirtualizer != null) {
                 mVirtualizer.release();
                 mVirtualizer = null;
             }
             try {
                mVirtualizer = new Virtualizer(0, session);
                mSession = session;
            } catch (IllegalArgumentException e) {
                Log.e(TAG, "getVirtualizer() Virtualizer not found exception: "+e);
            } catch (UnsupportedOperationException e) {
                Log.e(TAG, "getVirtualizer() Effect library not loaded exception: "+e);
            }
         }
         assertNotNull("could not create mVirtualizer", mVirtualizer);
    
private voidlog(java.lang.String testName, java.lang.String message)

        Log.v(TAG, "["+testName+"] "+message);
    
private voidloge(java.lang.String testName, java.lang.String message)

        Log.e(TAG, "["+testName+"] "+message);
    
private voidreleaseVirtualizer()

        if (mVirtualizer != null) {
            mVirtualizer.release();
            mVirtualizer = null;
        }
   
protected voidsetUp()

      super.setUp();
    
protected voidtearDown()

        super.tearDown();
        releaseVirtualizer();
    
public voidtest0_0ConstructorAndRelease()

        boolean result = false;
        String msg = "test1_0ConstructorAndRelease()";
        Virtualizer virtualizer = null;
         try {
            virtualizer = new Virtualizer(0, 0);
            assertNotNull(msg + ": could not create Virtualizer", virtualizer);
            try {
                assertTrue(msg +": invalid effect ID", (virtualizer.getId() != 0));
            } catch (IllegalStateException e) {
                msg = msg.concat(": Virtualizer not initialized");
            }
            result = true;
        } catch (IllegalArgumentException e) {
            msg = msg.concat(": Virtualizer not found");
        } catch (UnsupportedOperationException e) {
            msg = msg.concat(": Effect library not loaded");
        } finally {
            if (virtualizer != null) {
                virtualizer.release();
            }
        }
        assertTrue(msg, result);
    
public voidtest1_0Strength()

        boolean result = false;
        String msg = "test1_0Strength()";
        getVirtualizer(0);
        try {
            if (mVirtualizer.getStrengthSupported()) {
                mVirtualizer.setStrength((short)TEST_STRENGTH);
                short strength = mVirtualizer.getRoundedStrength();
                // allow 10% difference between set strength and rounded strength
                assertTrue(msg +": got incorrect strength",
                        ((float)strength > (float)TEST_STRENGTH * 0.9f) &&
                        ((float)strength < (float)TEST_STRENGTH * 1.1f));
            } else {
                short strength = mVirtualizer.getRoundedStrength();
                assertTrue(msg +": got incorrect strength", strength >= 0 && strength <= 1000);
            }
            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 {
            releaseVirtualizer();
        }
        assertTrue(msg, result);
    
public voidtest1_1Properties()

        boolean result = false;
        String msg = "test1_1Properties()";
        getVirtualizer(0);
        try {
            Virtualizer.Settings settings = mVirtualizer.getProperties();
            String str = settings.toString();
            settings = new Virtualizer.Settings(str);
            mVirtualizer.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 {
            releaseVirtualizer();
        }
        assertTrue(msg, result);