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""" 17Test script to exercise Gatt Apis. 18""" 19 20from acts.controllers.android import SL4AAPIError 21from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest 22from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test 23 24 25class GattApiTest(BluetoothBaseTest): 26 27 def __init__(self, controllers): 28 BluetoothBaseTest.__init__(self, controllers) 29 self.ad = self.android_devices[0] 30 31 def setup_class(self): 32 return setup_multiple_devices_for_bt_test(self.android_devices) 33 34 def setup_test(self): 35 for a in self.android_devices: 36 a.ed.clear_all_events() 37 return True 38 39 def teardown_test(self): 40 return True 41 42 @BluetoothBaseTest.bt_test_wrap 43 def test_open_gatt_server(self): 44 """Test a gatt server. 45 46 Test opening a gatt server. 47 48 Steps: 49 1. Create a gatt server callback. 50 2. Open the gatt server. 51 52 Expected Result: 53 Api to open gatt server should not fail. 54 55 Returns: 56 Pass if True 57 Fail if False 58 59 TAGS: LE, GATT 60 Priority: 1 61 """ 62 gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback() 63 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 64 return True 65 66 @BluetoothBaseTest.bt_test_wrap 67 def test_open_gatt_server_on_same_callback(self): 68 """Test repetitive opening of a gatt server. 69 70 Test opening a gatt server on the same callback twice in a row. 71 72 Steps: 73 1. Create a gatt server callback. 74 2. Open the gatt server. 75 3. Open the gatt server on the same callback as step 2. 76 77 Expected Result: 78 Api to open gatt server should not fail. 79 80 Returns: 81 Pass if True 82 Fail if False 83 84 TAGS: LE, GATT 85 Priority: 2 86 """ 87 gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback() 88 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 89 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 90 return True 91 92 @BluetoothBaseTest.bt_test_wrap 93 def test_open_gatt_server_on_invalid_callback(self): 94 """Test gatt server an an invalid callback. 95 96 Test opening a gatt server with an invalid callback. 97 98 Steps: 99 1. Open a gatt server with the gall callback set to -1. 100 101 Expected Result: 102 Api should fail to open a gatt server. 103 104 Returns: 105 Pass if True 106 Fail if False 107 108 TAGS: LE, GATT 109 Priority: 2 110 """ 111 invalid_callback_index = -1 112 try: 113 self.ad.droid.gattServerOpenGattServer(invalid_callback_index) 114 except SL4AAPIError as e: 115 self.log.info("Failed successfully with exception: {}.".format(e)) 116 return True 117 return False 118