1 #/usr/bin/env python3.4 2 # 3 # Copyright (C) 2016 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 # use this file except in compliance with the License. You may obtain a copy of 7 # the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 # License for the specific language governing permissions and limitations under 15 # the License. 16 """ 17 Test script to exercise Gatt Apis. 18 """ 19 20 from acts.controllers.android import SL4AAPIError 21 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest 22 from acts.test_utils.bt.bt_test_utils import log_energy_info 23 from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test 24 25 26 class GattApiTest(BluetoothBaseTest): 27 28 def __init__(self, controllers): 29 BluetoothBaseTest.__init__(self, controllers) 30 self.ad = self.android_devices[0] 31 32 def setup_class(self): 33 return setup_multiple_devices_for_bt_test(self.android_devices) 34 35 def setup_test(self): 36 self.log.debug(log_energy_info(self.android_devices, "Start")) 37 for a in self.android_devices: 38 a.ed.clear_all_events() 39 return True 40 41 def teardown_test(self): 42 self.log.debug(log_energy_info(self.android_devices, "End")) 43 return True 44 45 @BluetoothBaseTest.bt_test_wrap 46 def test_open_gatt_server(self): 47 """Test a gatt server. 48 49 Test opening a gatt server. 50 51 Steps: 52 1. Create a gatt server callback. 53 2. Open the gatt server. 54 55 Expected Result: 56 Api to open gatt server should not fail. 57 58 Returns: 59 Pass if True 60 Fail if False 61 62 TAGS: LE, GATT 63 Priority: 1 64 """ 65 gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback() 66 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 67 return True 68 69 @BluetoothBaseTest.bt_test_wrap 70 def test_open_gatt_server_on_same_callback(self): 71 """Test repetitive opening of a gatt server. 72 73 Test opening a gatt server on the same callback twice in a row. 74 75 Steps: 76 1. Create a gatt server callback. 77 2. Open the gatt server. 78 3. Open the gatt server on the same callback as step 2. 79 80 Expected Result: 81 Api to open gatt server should not fail. 82 83 Returns: 84 Pass if True 85 Fail if False 86 87 TAGS: LE, GATT 88 Priority: 2 89 """ 90 gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback() 91 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 92 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 93 return True 94 95 @BluetoothBaseTest.bt_test_wrap 96 def test_open_gatt_server_on_invalid_callback(self): 97 """Test gatt server an an invalid callback. 98 99 Test opening a gatt server with an invalid callback. 100 101 Steps: 102 1. Open a gatt server with the gall callback set to -1. 103 104 Expected Result: 105 Api should fail to open a gatt server. 106 107 Returns: 108 Pass if True 109 Fail if False 110 111 TAGS: LE, GATT 112 Priority: 2 113 """ 114 invalid_callback_index = -1 115 try: 116 self.ad.droid.gattServerOpenGattServer(invalid_callback_index) 117 except SL4AAPIError as e: 118 self.log.info("Failed successfully with exception: {}.".format(e)) 119 return True 120 return False 121