summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorEric Rowe <erowe@google.com>2010-11-03 17:50:24 -0700
committerEric Rowe <erowe@google.com>2010-11-04 14:22:39 -0700
commit776e64da8832844882b5116ab3e4af75ea28e27a (patch)
treee7a06cdbc24bf48d38f05935773395329065718f /core
parent42361551b1e97884735b44dd49147ac133fa146e (diff)
downloadframeworks_base-776e64da8832844882b5116ab3e4af75ea28e27a.zip
frameworks_base-776e64da8832844882b5116ab3e4af75ea28e27a.tar.gz
frameworks_base-776e64da8832844882b5116ab3e4af75ea28e27a.tar.bz2
DO NOT MERGE 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: I6391d03e9f33c040afd64d73083acfe3184251eb
Diffstat (limited to 'core')
-rw-r--r--core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java15
-rw-r--r--core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java29
2 files changed, 36 insertions, 8 deletions
diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java b/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java
index 892dc8a..d30c5e8 100644
--- a/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java
+++ b/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java
@@ -94,6 +94,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;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java b/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java
index a9025fb..f40d857 100644
--- a/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java
+++ b/core/tests/coretests/src/android/bluetooth/BluetoothTestUtils.java
@@ -635,6 +635,17 @@ 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) {
+ String methodName = pair ? "pair()" : "acceptPair()";
int mask = PairReceiver.PAIR_FLAG;
int pairMask = PairReceiver.PAIR_STATE_BONDING | PairReceiver.PAIR_STATE_BONDED;
@@ -642,7 +653,7 @@ public class BluetoothTestUtils extends Assert {
mReceivers.add(pairReceiver);
if (!adapter.isEnabled()) {
- fail("pair() bluetooth not enabled");
+ fail(methodName + " bluetooth not enabled");
}
int state = device.getBondState();
@@ -656,10 +667,12 @@ public class BluetoothTestUtils extends Assert {
break;
case BluetoothDevice.BOND_NONE:
assertFalse(adapter.getBondedDevices().contains(device));
- assertTrue(device.createBond());
+ if (pair) {
+ assertTrue(device.createBond());
+ }
break;
default:
- fail("pair() invalide state: state=" + state);
+ fail(methodName + " invalide state: state=" + state);
}
long s = System.currentTimeMillis();
@@ -669,8 +682,8 @@ public class BluetoothTestUtils extends Assert {
assertTrue(adapter.getBondedDevices().contains(device));
if ((pairReceiver.getFiredFlags() & mask) == mask
&& (pairReceiver.getPairFiredFlags() & pairMask) == pairMask) {
- writeOutput(String.format("pair() completed in %d ms: device=%s",
- (System.currentTimeMillis() - s), device));
+ writeOutput(String.format("%s completed in %d ms: device=%s",
+ methodName, (System.currentTimeMillis() - s), device));
mReceivers.remove(pairReceiver);
mContext.unregisterReceiver(pairReceiver);
return;
@@ -682,9 +695,9 @@ public class BluetoothTestUtils extends Assert {
int firedFlags = pairReceiver.getFiredFlags();
int pairFiredFlags = pairReceiver.getPairFiredFlags();
pairReceiver.resetFiredFlags();
- fail(String.format("pair() timeout: state=%d (expected %d), flags=0x%x (expected 0x%x), "
- + "pairFlags=0x%x (expected 0x%x)", state, BluetoothDevice.BOND_BONDED, firedFlags,
- mask, pairFiredFlags, pairMask));
+ fail(String.format("%s timeout: state=%d (expected %d), flags=0x%x (expected 0x%x), "
+ + "pairFlags=0x%x (expected 0x%x)", methodName, state, BluetoothDevice.BOND_BONDED,
+ firedFlags, mask, pairFiredFlags, pairMask));
}
public void unpair(BluetoothAdapter adapter, BluetoothDevice device) {