diff options
author | Eric Rowe <erowe@google.com> | 2010-11-03 18:19:46 -0700 |
---|---|---|
committer | Eric Rowe <erowe@google.com> | 2010-11-15 12:18:23 -0800 |
commit | 23c067692be74c4fcd50cea48f9d469ba5288213 (patch) | |
tree | 6118f9650aa51e87936755ab8ca75ba1aeba9177 /core | |
parent | df3191cb88c84aab433f4b67a3495cca86ce1844 (diff) | |
download | frameworks_base-23c067692be74c4fcd50cea48f9d469ba5288213.zip frameworks_base-23c067692be74c4fcd50cea48f9d469ba5288213.tar.gz frameworks_base-23c067692be74c4fcd50cea48f9d469ba5288213.tar.bz2 |
Add acceptPair method to BT stress.
Add a method to the test utils which waits to accept a bonding request from
another device. This is identical to the pairing method except that it
waits for a remote pair request instead of initiating the pairing
request itself. Also, add a test method to the test utils.
Change-Id: I97e215d3412d4b61757d6dc011b90cc5f2c8f084
Diffstat (limited to 'core')
-rw-r--r-- | core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java | 15 | ||||
-rw-r--r-- | core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java | 31 |
2 files changed, 38 insertions, 8 deletions
diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java b/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java index f019599..43cf06a 100644 --- a/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java +++ b/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java @@ -110,6 +110,21 @@ public class BluetoothStressTest extends InstrumentationTestCase { mTestUtils.disable(adapter); } + public void testAcceptPair() { + int iterations = BluetoothTestRunner.sPairIterations; + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sPairAddress); + mTestUtils.enable(adapter); + + for (int i = 0; i < iterations; i++) { + mTestUtils.writeOutput("acceptPair iteration " + (i + 1) + " of " + iterations); + mTestUtils.acceptPair(adapter, device, BluetoothTestRunner.sPairPasskey, + BluetoothTestRunner.sPairPin); + mTestUtils.unpair(adapter, device); + } + mTestUtils.disable(adapter); + } + public void testConnectA2dp() { int iterations = BluetoothTestRunner.sConnectA2dpIterations; if (iterations == 0) { diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java b/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java index 328891c..2027398 100644 --- a/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java +++ b/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java @@ -629,11 +629,22 @@ public class BluetoothTestUtils extends Assert { } public void pair(BluetoothAdapter adapter, BluetoothDevice device, int passkey, byte[] pin) { + pairOrAcceptPair(adapter, device, passkey, pin, true); + } + + public void acceptPair(BluetoothAdapter adapter, BluetoothDevice device, int passkey, + byte[] pin) { + pairOrAcceptPair(adapter, device, passkey, pin, false); + } + + private void pairOrAcceptPair(BluetoothAdapter adapter, BluetoothDevice device, int passkey, + byte[] pin, boolean pair) { int mask = PairReceiver.STATE_BONDING_FLAG | PairReceiver.STATE_BONDED_FLAG; long start = -1; + String methodName = pair ? "pair()" : "acceptPair()"; if (!adapter.isEnabled()) { - fail("pair() bluetooth not enabled"); + fail(methodName + " bluetooth not enabled"); } PairReceiver receiver = getPairReceiver(device, passkey, pin, mask); @@ -643,7 +654,9 @@ public class BluetoothTestUtils extends Assert { case BluetoothDevice.BOND_NONE: assertFalse(adapter.getBondedDevices().contains(device)); start = System.currentTimeMillis(); - assertTrue(device.createBond()); + if (pair) { + assertTrue(device.createBond()); + } break; case BluetoothDevice.BOND_BONDING: mask = 0; // Don't check for received intents since we might have missed them. @@ -652,8 +665,10 @@ public class BluetoothTestUtils extends Assert { assertTrue(adapter.getBondedDevices().contains(device)); return; default: + removeReceiver(receiver); - fail(String.format("pair() invalid state: device=%s, state=%d", device, state)); + fail(String.format("%s invalid state: device=%s, state=%d", methodName, device, + state)); } long s = System.currentTimeMillis(); @@ -664,10 +679,10 @@ public class BluetoothTestUtils extends Assert { if ((receiver.getFiredFlags() & mask) == mask) { long finish = receiver.getCompletedTime(); if (start != -1 && finish != -1) { - writeOutput(String.format("pair() completed in %d ms: device=%s", + writeOutput(String.format("%s completed in %d ms: device=%s", methodName, (finish - start), device)); } else { - writeOutput(String.format("pair() completed: device=%s", device)); + writeOutput(String.format("%s completed: device=%s", methodName, device)); } removeReceiver(receiver); return; @@ -678,9 +693,9 @@ public class BluetoothTestUtils extends Assert { int firedFlags = receiver.getFiredFlags(); removeReceiver(receiver); - fail(String.format("pair() timeout: device=%s, state=%d (expected %d), " - + "flags=0x%x (expected 0x%x)", device, state, BluetoothDevice.BOND_BONDED, - firedFlags, mask)); + fail(String.format("%s timeout: device=%s, state=%d (expected %d), " + + "flags=0x%x (expected 0x%x)", methodName, device, state, + BluetoothDevice.BOND_BONDED, firedFlags, mask)); } public void unpair(BluetoothAdapter adapter, BluetoothDevice device) { |