• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
23  * Instrumentation test case for stress test involving rebooting the device.
24  * <p>
25  * This test case tests that bluetooth is enabled after a device reboot. Because
26  * the device will reboot, the instrumentation must be driven by a script on the
27  * host side.
28  */
29 public class BluetoothRebootStressTest extends InstrumentationTestCase {
30     private static final String TAG = "BluetoothRebootStressTest";
31     private static final String OUTPUT_FILE = "BluetoothRebootStressTestOutput.txt";
32 
33     private BluetoothTestUtils mTestUtils;
34 
35     @Override
setUp()36     protected void setUp() throws Exception {
37         super.setUp();
38 
39         Context context = getInstrumentation().getTargetContext();
40         mTestUtils = new BluetoothTestUtils(context, TAG, OUTPUT_FILE);
41     }
42 
43     @Override
tearDown()44     protected void tearDown() throws Exception {
45         super.tearDown();
46 
47         mTestUtils.close();
48     }
49 
50     /**
51      * Test method used to start the test by turning bluetooth on.
52      */
testStart()53     public void testStart() {
54         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
55         mTestUtils.enable(adapter);
56     }
57 
58     /**
59      * Test method used in the middle iterations of the test to check if
60      * bluetooth is on. Does not toggle bluetooth after the check. Assumes that
61      * bluetooth has been turned on by {@code #testStart()}
62      */
testMiddleNoToggle()63     public void testMiddleNoToggle() {
64         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
65 
66         assertTrue(adapter.isEnabled());
67     }
68 
69     /**
70      * Test method used in the middle iterations of the test to check if
71      * bluetooth is on. Toggles bluetooth after the check. Assumes that
72      * bluetooth has been turned on by {@code #testStart()}
73      */
testMiddleToggle()74     public void testMiddleToggle() {
75         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
76 
77         assertTrue(adapter.isEnabled());
78 
79         mTestUtils.disable(adapter);
80         mTestUtils.enable(adapter);
81     }
82 
83     /**
84      * Test method used in the stop the test by turning bluetooth off. Assumes
85      * that bluetooth has been turned on by {@code #testStart()}
86      */
testStop()87     public void testStop() {
88         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
89 
90         assertTrue(adapter.isEnabled());
91 
92         mTestUtils.disable(adapter);
93     }
94 }
95