OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / core / tests / coretests / src / android / bluetooth / BluetoothStressTest.java
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package android.bluetooth;
18
19 import android.content.Context;
20 import android.test.InstrumentationTestCase;
21
22 public class BluetoothStressTest extends InstrumentationTestCase {
23     private static final String TAG = "BluetoothStressTest";
24     private static final String OUTPUT_FILE = "BluetoothStressTestOutput.txt";
25
26     private BluetoothTestUtils mTestUtils;
27
28     @Override
29     protected void setUp() throws Exception {
30         super.setUp();
31
32         Context context = getInstrumentation().getTargetContext();
33         mTestUtils = new BluetoothTestUtils(context, TAG, OUTPUT_FILE);
34     }
35
36     @Override
37     protected void tearDown() throws Exception {
38         super.tearDown();
39
40         mTestUtils.close();
41     }
42
43     public void testEnable() {
44         int iterations = BluetoothTestRunner.sEnableIterations;
45         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
46
47         for (int i = 0; i < iterations; i++) {
48             mTestUtils.writeOutput("enable iteration " + (i + 1) + " of " + iterations);
49             mTestUtils.enable(adapter);
50             mTestUtils.disable(adapter);
51         }
52     }
53
54     public void testDiscoverable() {
55         int iterations = BluetoothTestRunner.sDiscoverableIterations;
56         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
57         mTestUtils.enable(adapter);
58
59         for (int i = 0; i < iterations; i++) {
60             mTestUtils.writeOutput("discoverable iteration " + (i + 1) + " of " + iterations);
61             mTestUtils.discoverable(adapter);
62             mTestUtils.undiscoverable(adapter);
63         }
64
65         mTestUtils.disable(adapter);
66     }
67
68     public void testScan() {
69         int iterations = BluetoothTestRunner.sScanIterations;
70         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
71         mTestUtils.enable(adapter);
72
73         for (int i = 0; i < iterations; i++) {
74             mTestUtils.writeOutput("scan iteration " + (i + 1) + " of " + iterations);
75             mTestUtils.startScan(adapter);
76             mTestUtils.stopScan(adapter);
77         }
78
79         mTestUtils.disable(adapter);
80     }
81
82     public void testPair() {
83         int iterations = BluetoothTestRunner.sPairIterations;
84         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
85         BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sPairAddress);
86         mTestUtils.enable(adapter);
87
88         for (int i = 0; i < iterations; i++) {
89             mTestUtils.writeOutput("pair iteration " + (i + 1) + " of " + iterations);
90             mTestUtils.pair(adapter, device, BluetoothTestRunner.sPairPasskey,
91                     BluetoothTestRunner.sPairPin);
92             mTestUtils.unpair(adapter, device);
93         }
94         mTestUtils.disable(adapter);
95     }
96
97     public void testAcceptPair() {
98         int iterations = BluetoothTestRunner.sPairIterations;
99         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
100         BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sPairAddress);
101         mTestUtils.enable(adapter);
102
103         for (int i = 0; i < iterations; i++) {
104             mTestUtils.writeOutput("acceptPair iteration " + (i + 1) + " of " + iterations);
105             mTestUtils.acceptPair(adapter, device, BluetoothTestRunner.sPairPasskey,
106                     BluetoothTestRunner.sPairPin);
107             mTestUtils.unpair(adapter, device);
108         }
109         mTestUtils.disable(adapter);
110     }
111
112     public void testConnectA2dp() {
113         int iterations = BluetoothTestRunner.sConnectA2dpIterations;
114         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
115         BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sA2dpAddress);
116
117         mTestUtils.enable(adapter);
118         mTestUtils.pair(adapter, device, BluetoothTestRunner.sPairPasskey,
119                 BluetoothTestRunner.sPairPin);
120
121         for (int i = 0; i < iterations; i++) {
122             mTestUtils.writeOutput("connectA2dp iteration " + (i + 1) + " of " + iterations);
123             mTestUtils.connectA2dp(adapter, device);
124             mTestUtils.disconnectA2dp(adapter, device);
125         }
126
127         // TODO: Unpair from device if device can accept pairing after unpairing
128         mTestUtils.disable(adapter);
129     }
130
131     public void testConnectHeadset() {
132         int iterations = BluetoothTestRunner.sConnectHeadsetIterations;
133         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
134         BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sHeadsetAddress);
135
136         mTestUtils.enable(adapter);
137         mTestUtils.pair(adapter, device, BluetoothTestRunner.sPairPasskey,
138                 BluetoothTestRunner.sPairPin);
139
140         for (int i = 0; i < iterations; i++) {
141             mTestUtils.writeOutput("connectHeadset iteration " + (i + 1) + " of " + iterations);
142             mTestUtils.connectHeadset(adapter, device);
143             mTestUtils.disconnectHeadset(adapter, device);
144         }
145
146         // TODO: Unpair from device if device can accept pairing after unpairing
147         mTestUtils.disable(adapter);
148     }
149 }