Loading android/app/tests/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := BluetoothInstrumentationTests LOCAL_COMPATIBILITY_SUITE := device-tests LOCAL_INSTRUMENTATION_FOR := Bluetooth include $(BUILD_PACKAGE) android/app/tests/AndroidTest.xml 0 → 100644 +27 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright 2017 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. --> <configuration description="Runs Bluetooth Test Cases."> <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup"> <option name="test-file-name" value="BluetoothInstrumentationTests.apk" /> </target_preparer> <option name="test-suite-tag" value="apct" /> <option name="test-tag" value="BluetoothInstrumentationTests" /> <test class="com.android.tradefed.testtype.InstrumentationTest" > <option name="package" value="com.android.bluetooth.tests" /> <option name="runner" value="android.support.test.runner.AndroidJUnitRunner" /> </test> </configuration> No newline at end of file android/app/tests/src/com/android/bluetooth/core/FileSystemWriteTest.java→android/app/tests/src/com/android/bluetooth/FileSystemWriteTest.java +67 −0 Original line number Diff line number Diff line /* * Copyright 2017 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.bluetooth; import android.support.test.filters.MediumTest; import android.test.AndroidTestCase; import android.support.test.runner.AndroidJUnit4; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.io.File; import java.io.IOException; /** * Test Bluetooth's ability to write to the different directories that it * is supposed to own */ @MediumTest // Test Bluetooth's ability to write to the different directories that it // is supposed to own public class FileSystemWriteTest extends AndroidTestCase { @RunWith(AndroidJUnit4.class) public class FileSystemWriteTest { @Test public void testBluetoothDirWrite() { try { File file = new File("/data/misc/bluetooth/test.file"); assertTrue("File not created", file.createNewFile()); Assert.assertTrue("File not created", file.createNewFile()); file.delete(); } catch (IOException e) { fail("Exception creating file /data/misc/bluetooth/test.file: " + e); Assert.fail("Exception creating file /data/misc/bluetooth/test.file: " + e); } } @Test public void testBluedroidDirWrite() { try { File file = new File("/data/misc/bluedroid/test.file"); assertTrue("File not created", file.createNewFile()); Assert.assertTrue("File not created", file.createNewFile()); file.delete(); } catch (IOException e) { fail("Exception creating file /data/misc/bluedroid/test.file: " + e); Assert.fail("Exception creating file /data/misc/bluedroid/test.file: " + e); } } @Test public void testBluetoothLogsDirWrite() { try { File file = new File("/data/misc/bluetooth/logs/test.file"); assertTrue("File not created", file.createNewFile()); Assert.assertTrue("File not created", file.createNewFile()); file.delete(); } catch (IOException e) { fail("Exception creating file /data/misc/bluetooth/logs/test.file: " + e); Assert.fail("Exception creating file /data/misc/bluetooth/logs/test.file: " + e); } } } android/app/tests/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java +13 −18 Original line number Diff line number Diff line Loading @@ -22,40 +22,37 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; import android.os.HandlerThread; import android.os.Looper; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; import android.support.test.filters.MediumTest; import android.support.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.MockitoAnnotations; @MediumTest @RunWith(MockitoJUnitRunner.class) public class A2dpSinkStreamHandlerTest extends AndroidTestCase { static final int DUCK_PERCENT = 75; @RunWith(AndroidJUnit4.class) public class A2dpSinkStreamHandlerTest { private static final int DUCK_PERCENT = 75; private HandlerThread mHandlerThread; A2dpSinkStreamHandler mStreamHandler; ArgumentCaptor<OnAudioFocusChangeListener> mAudioFocusChangeListenerArgumentCaptor; private A2dpSinkStreamHandler mStreamHandler; @Mock Context mMockContext; @Mock private Context mMockContext; @Mock A2dpSinkStateMachine mMockA2dpSink; @Mock private A2dpSinkStateMachine mMockA2dpSink; @Mock AudioManager mMockAudioManager; @Mock private AudioManager mMockAudioManager; @Mock Resources mMockResources; @Mock private Resources mMockResources; @Mock PackageManager mMockPackageManager; @Mock private PackageManager mMockPackageManager; @Override @Before public void setUp() { MockitoAnnotations.initMocks(this); // Mock the looper if (Looper.myLooper() == null) { Looper.prepare(); Loading @@ -64,8 +61,6 @@ public class A2dpSinkStreamHandlerTest extends AndroidTestCase { mHandlerThread = new HandlerThread("A2dpSinkStreamHandlerTest"); mHandlerThread.start(); mAudioFocusChangeListenerArgumentCaptor = ArgumentCaptor.forClass(OnAudioFocusChangeListener.class); when(mMockContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mMockAudioManager); when(mMockContext.getResources()).thenReturn(mMockResources); when(mMockResources.getInteger(anyInt())).thenReturn(DUCK_PERCENT); Loading android/app/tests/src/com/android/bluetooth/avrcp/AvrcpTest.java +17 −4 Original line number Diff line number Diff line Loading @@ -9,22 +9,34 @@ import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.media.AudioManager; import android.os.Looper; import android.support.test.InstrumentationRegistry; import android.support.test.filters.MediumTest; import android.test.AndroidTestCase; import android.support.test.runner.AndroidJUnit4; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; /** * Unit tests for {@link Avrcp} */ @MediumTest public class AvrcpTest extends AndroidTestCase { @RunWith(AndroidJUnit4.class) public class AvrcpTest { @Test public void testCanStart() { if (Looper.myLooper() == null) { Looper.prepare(); } Avrcp a = Avrcp.make(getContext()); Avrcp a = Avrcp.make(InstrumentationRegistry.getTargetContext()); } @Test public void testFailedBrowseStart() { if (Looper.myLooper() == null) { Looper.prepare(); Loading Loading @@ -64,7 +76,8 @@ public class AvrcpTest extends AndroidTestCase { try { Avrcp a = Avrcp.make(mockContext); } catch (SecurityException e) { fail("Threw SecurityException instead of protecting against it: " + e.toString()); Assert.fail( "Threw SecurityException instead of protecting against it: " + e.toString()); } } } Loading
android/app/tests/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := BluetoothInstrumentationTests LOCAL_COMPATIBILITY_SUITE := device-tests LOCAL_INSTRUMENTATION_FOR := Bluetooth include $(BUILD_PACKAGE)
android/app/tests/AndroidTest.xml 0 → 100644 +27 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright 2017 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. --> <configuration description="Runs Bluetooth Test Cases."> <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup"> <option name="test-file-name" value="BluetoothInstrumentationTests.apk" /> </target_preparer> <option name="test-suite-tag" value="apct" /> <option name="test-tag" value="BluetoothInstrumentationTests" /> <test class="com.android.tradefed.testtype.InstrumentationTest" > <option name="package" value="com.android.bluetooth.tests" /> <option name="runner" value="android.support.test.runner.AndroidJUnitRunner" /> </test> </configuration> No newline at end of file
android/app/tests/src/com/android/bluetooth/core/FileSystemWriteTest.java→android/app/tests/src/com/android/bluetooth/FileSystemWriteTest.java +67 −0 Original line number Diff line number Diff line /* * Copyright 2017 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.bluetooth; import android.support.test.filters.MediumTest; import android.test.AndroidTestCase; import android.support.test.runner.AndroidJUnit4; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.io.File; import java.io.IOException; /** * Test Bluetooth's ability to write to the different directories that it * is supposed to own */ @MediumTest // Test Bluetooth's ability to write to the different directories that it // is supposed to own public class FileSystemWriteTest extends AndroidTestCase { @RunWith(AndroidJUnit4.class) public class FileSystemWriteTest { @Test public void testBluetoothDirWrite() { try { File file = new File("/data/misc/bluetooth/test.file"); assertTrue("File not created", file.createNewFile()); Assert.assertTrue("File not created", file.createNewFile()); file.delete(); } catch (IOException e) { fail("Exception creating file /data/misc/bluetooth/test.file: " + e); Assert.fail("Exception creating file /data/misc/bluetooth/test.file: " + e); } } @Test public void testBluedroidDirWrite() { try { File file = new File("/data/misc/bluedroid/test.file"); assertTrue("File not created", file.createNewFile()); Assert.assertTrue("File not created", file.createNewFile()); file.delete(); } catch (IOException e) { fail("Exception creating file /data/misc/bluedroid/test.file: " + e); Assert.fail("Exception creating file /data/misc/bluedroid/test.file: " + e); } } @Test public void testBluetoothLogsDirWrite() { try { File file = new File("/data/misc/bluetooth/logs/test.file"); assertTrue("File not created", file.createNewFile()); Assert.assertTrue("File not created", file.createNewFile()); file.delete(); } catch (IOException e) { fail("Exception creating file /data/misc/bluetooth/logs/test.file: " + e); Assert.fail("Exception creating file /data/misc/bluetooth/logs/test.file: " + e); } } }
android/app/tests/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java +13 −18 Original line number Diff line number Diff line Loading @@ -22,40 +22,37 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; import android.os.HandlerThread; import android.os.Looper; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; import android.support.test.filters.MediumTest; import android.support.test.runner.AndroidJUnit4; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.MockitoAnnotations; @MediumTest @RunWith(MockitoJUnitRunner.class) public class A2dpSinkStreamHandlerTest extends AndroidTestCase { static final int DUCK_PERCENT = 75; @RunWith(AndroidJUnit4.class) public class A2dpSinkStreamHandlerTest { private static final int DUCK_PERCENT = 75; private HandlerThread mHandlerThread; A2dpSinkStreamHandler mStreamHandler; ArgumentCaptor<OnAudioFocusChangeListener> mAudioFocusChangeListenerArgumentCaptor; private A2dpSinkStreamHandler mStreamHandler; @Mock Context mMockContext; @Mock private Context mMockContext; @Mock A2dpSinkStateMachine mMockA2dpSink; @Mock private A2dpSinkStateMachine mMockA2dpSink; @Mock AudioManager mMockAudioManager; @Mock private AudioManager mMockAudioManager; @Mock Resources mMockResources; @Mock private Resources mMockResources; @Mock PackageManager mMockPackageManager; @Mock private PackageManager mMockPackageManager; @Override @Before public void setUp() { MockitoAnnotations.initMocks(this); // Mock the looper if (Looper.myLooper() == null) { Looper.prepare(); Loading @@ -64,8 +61,6 @@ public class A2dpSinkStreamHandlerTest extends AndroidTestCase { mHandlerThread = new HandlerThread("A2dpSinkStreamHandlerTest"); mHandlerThread.start(); mAudioFocusChangeListenerArgumentCaptor = ArgumentCaptor.forClass(OnAudioFocusChangeListener.class); when(mMockContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mMockAudioManager); when(mMockContext.getResources()).thenReturn(mMockResources); when(mMockResources.getInteger(anyInt())).thenReturn(DUCK_PERCENT); Loading
android/app/tests/src/com/android/bluetooth/avrcp/AvrcpTest.java +17 −4 Original line number Diff line number Diff line Loading @@ -9,22 +9,34 @@ import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.media.AudioManager; import android.os.Looper; import android.support.test.InstrumentationRegistry; import android.support.test.filters.MediumTest; import android.test.AndroidTestCase; import android.support.test.runner.AndroidJUnit4; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; /** * Unit tests for {@link Avrcp} */ @MediumTest public class AvrcpTest extends AndroidTestCase { @RunWith(AndroidJUnit4.class) public class AvrcpTest { @Test public void testCanStart() { if (Looper.myLooper() == null) { Looper.prepare(); } Avrcp a = Avrcp.make(getContext()); Avrcp a = Avrcp.make(InstrumentationRegistry.getTargetContext()); } @Test public void testFailedBrowseStart() { if (Looper.myLooper() == null) { Looper.prepare(); Loading Loading @@ -64,7 +76,8 @@ public class AvrcpTest extends AndroidTestCase { try { Avrcp a = Avrcp.make(mockContext); } catch (SecurityException e) { fail("Threw SecurityException instead of protecting against it: " + e.toString()); Assert.fail( "Threw SecurityException instead of protecting against it: " + e.toString()); } } }