1ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe/* 2ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * Copyright (C) 2010 The Android Open Source Project 3ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * 4ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * Licensed under the Apache License, Version 2.0 (the "License"); 5ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * you may not use this file except in compliance with the License. 6ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * You may obtain a copy of the License at 7ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * 8ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * http://www.apache.org/licenses/LICENSE-2.0 9ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * 10ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * Unless required by applicable law or agreed to in writing, software 11ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * distributed under the License is distributed on an "AS IS" BASIS, 12ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * See the License for the specific language governing permissions and 14ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * limitations under the License. 15ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe */ 16ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 17ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowepackage android.bluetooth; 18ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 19ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Roweimport android.content.Context; 20ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Roweimport android.test.InstrumentationTestCase; 21ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 22ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe/** 23ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * Instrumentation test case for stress test involving rebooting the device. 24ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * <p> 25ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * This test case tests that bluetooth is enabled after a device reboot. Because 26ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * the device will reboot, the instrumentation must be driven by a script on the 27ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * host side. 28ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe */ 29ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowepublic class BluetoothRebootStressTest extends InstrumentationTestCase { 30ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe private static final String TAG = "BluetoothRebootStressTest"; 31ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe private static final String OUTPUT_FILE = "BluetoothRebootStressTestOutput.txt"; 32ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 33ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe private BluetoothTestUtils mTestUtils; 34ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 35ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe @Override 36ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe protected void setUp() throws Exception { 37ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe super.setUp(); 38ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 39ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe Context context = getInstrumentation().getTargetContext(); 40ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe mTestUtils = new BluetoothTestUtils(context, TAG, OUTPUT_FILE); 41ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe } 42ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 43ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe @Override 44ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe protected void tearDown() throws Exception { 45ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe super.tearDown(); 46ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 47ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe mTestUtils.close(); 48ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe } 49ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 50ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe /** 51ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * Test method used to start the test by turning bluetooth on. 52ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe */ 53ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe public void testStart() { 54ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 55ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe mTestUtils.enable(adapter); 56ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe } 57ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 58ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe /** 59ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * Test method used in the middle iterations of the test to check if 60ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * bluetooth is on. Does not toggle bluetooth after the check. Assumes that 61ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * bluetooth has been turned on by {@code #testStart()} 62ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe */ 63ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe public void testMiddleNoToggle() { 64ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 65ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 66ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe assertTrue(adapter.isEnabled()); 67ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe } 68ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 69ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe /** 70ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * Test method used in the middle iterations of the test to check if 71ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * bluetooth is on. Toggles bluetooth after the check. Assumes that 72ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * bluetooth has been turned on by {@code #testStart()} 73ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe */ 74ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe public void testMiddleToggle() { 75ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 76ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 77ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe assertTrue(adapter.isEnabled()); 78ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 79ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe mTestUtils.disable(adapter); 80ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe mTestUtils.enable(adapter); 81ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe } 82ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 83ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe /** 84ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * Test method used in the stop the test by turning bluetooth off. Assumes 85ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe * that bluetooth has been turned on by {@code #testStart()} 86ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe */ 87ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe public void testStop() { 88ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 89ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 90ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe assertTrue(adapter.isEnabled()); 91ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe 92ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe mTestUtils.disable(adapter); 93ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe } 94ac3c1f550f30aa793ccf5dcd0da55b070fd55364Eric Rowe} 95