summaryrefslogtreecommitdiffstats
path: root/tests/src/com/cyngn/audiofx/util
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/cyngn/audiofx/util')
-rw-r--r--tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java59
-rw-r--r--tests/src/com/cyngn/audiofx/util/TestDuckingMediaPlayer.java59
-rw-r--r--tests/src/com/cyngn/audiofx/util/TestMediaPlayer.java31
3 files changed, 149 insertions, 0 deletions
diff --git a/tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java b/tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java
new file mode 100644
index 0000000..e882c9d
--- /dev/null
+++ b/tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java
@@ -0,0 +1,59 @@
+package com.cyngn.audiofx.util;
+
+import android.content.Context;
+import android.content.Intent;
+import android.media.audiofx.AudioEffect;
+import android.os.IBinder;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.rule.ServiceTestRule;
+import android.support.test.runner.AndroidJUnit4;
+import com.cyngn.audiofx.service.AudioFxService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by roman on 3/1/16.
+ */
+@RunWith(AndroidJUnit4.class)
+public abstract class BaseAudioFxServiceInstrumentationTest {
+
+ private static final int MAX_ITERATION = 100;
+
+ protected AudioFxService.LocalBinder mService;
+
+ @Rule
+ public ServiceTestRule mServiceRule = new ServiceTestRule();
+
+ protected void setupService() throws TimeoutException {
+ int it = 0;
+
+ /**
+ * lol
+ * https://code.google.com/p/android/issues/detail?id=180396
+ */
+ IBinder binder;
+ while((binder = mServiceRule.bindService(
+ new Intent(InstrumentationRegistry.getTargetContext(),
+ AudioFxService.class))) == null && it < MAX_ITERATION){
+ it++;
+ }
+ mService = (AudioFxService.LocalBinder) binder;
+ assertNotNull(mService);
+ }
+
+ protected final Context getContext() {
+ return InstrumentationRegistry.getContext();
+ }
+
+ protected final Context getTargetContext() {
+ return InstrumentationRegistry.getTargetContext();
+ }
+
+}
diff --git a/tests/src/com/cyngn/audiofx/util/TestDuckingMediaPlayer.java b/tests/src/com/cyngn/audiofx/util/TestDuckingMediaPlayer.java
new file mode 100644
index 0000000..fc67cc2
--- /dev/null
+++ b/tests/src/com/cyngn/audiofx/util/TestDuckingMediaPlayer.java
@@ -0,0 +1,59 @@
+package com.cyngn.audiofx.util;
+
+import android.content.Context;
+import android.media.AudioManager;
+import android.util.Log;
+
+import com.cyngn.audiofx.tests.R;
+
+import static junit.framework.Assert.assertNotNull;
+
+/**
+ * Created by roman on 3/4/16.
+ */
+public class TestDuckingMediaPlayer extends TestMediaPlayer {
+
+ private static final String TAG = TestDuckingMediaPlayer.class.getSimpleName();
+ private AudioManager mAudioManager;
+
+ private AudioManager.OnAudioFocusChangeListener mAudioFocusChangeListener
+ = new AudioManager.OnAudioFocusChangeListener() {
+ public void onAudioFocusChange(int focusChange) {
+ Log.i(TAG, "onAudioFocusChange() called with " + "focusChange = [" + focusChange + "]");
+ switch(focusChange) {
+ case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
+ setVolume(0.4f);
+ break;
+
+ case AudioManager.AUDIOFOCUS_GAIN:
+ setVolume(1.f);
+ break;
+ }
+ }
+ };
+
+ public int start(int focus) throws IllegalStateException {
+ int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener, AudioManager.STREAM_MUSIC,
+ focus);
+ super.start();
+ return result;
+ }
+
+ @Override
+ public void stop() throws IllegalStateException {
+ mAudioManager.abandonAudioFocus(mAudioFocusChangeListener);
+ super.stop();
+ }
+
+ public TestDuckingMediaPlayer(Context context) {
+ mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ }
+
+ public TestDuckingMediaPlayer(Context context, int withResource) throws Exception {
+ super(context, withResource);
+ mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ }
+
+
+
+}
diff --git a/tests/src/com/cyngn/audiofx/util/TestMediaPlayer.java b/tests/src/com/cyngn/audiofx/util/TestMediaPlayer.java
new file mode 100644
index 0000000..ef08d1c
--- /dev/null
+++ b/tests/src/com/cyngn/audiofx/util/TestMediaPlayer.java
@@ -0,0 +1,31 @@
+package com.cyngn.audiofx.util;
+
+import android.content.Context;
+import android.content.res.AssetFileDescriptor;
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.MediaPlayer;
+
+import com.cyngn.audiofx.tests.R;
+
+import static junit.framework.Assert.assertNotNull;
+
+/**
+ * Created by roman on 3/4/16.
+ */
+public class TestMediaPlayer extends MediaPlayer {
+
+ public TestMediaPlayer() {
+ setAudioStreamType(AudioManager.STREAM_MUSIC);
+ }
+
+ public TestMediaPlayer(Context testContext, int withResource) throws Exception {
+ this();
+ AssetFileDescriptor afd = testContext.getResources().openRawResourceFd(withResource);
+ assertNotNull(afd);
+ setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
+ afd.close();
+ prepare();
+ }
+
+}