• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17import time
18from acts.base_test import BaseTestClass
19from acts.controllers import native_android_device
20from acts.test_utils.bt.native_bt_test_utils import setup_native_bluetooth
21from acts.test_utils.bt.bt_test_utils import generate_id_by_size
22
23
24class BtNativeTest(BaseTestClass):
25    tests = None
26
27    def __init__(self, controllers):
28        BaseTestClass.__init__(self, controllers)
29        setup_native_bluetooth(self.native_devices)
30        self.droid = self.native_devices[0].droid
31        self.tests = ("test_binder_get_name",
32                      "test_binder_get_name_invalid_parameter",
33                      "test_binder_set_name_get_name",
34                      "test_binder_get_address", )
35        if len(self.native_devices) > 1:
36            self.droid1 = self.native_devices[1].droid
37            self.tests = self.tests + ("test_two_devices_set_get_name", )
38
39    def test_binder_get_name(self):
40        result = self.droid.BluetoothBinderGetName()
41        self.log.info("Bluetooth device name: {}".format(result))
42        return True
43
44    def test_binder_get_name_invalid_parameter(self):
45        try:
46            self.droid.BluetoothBinderGetName("unexpected_parameter")
47            return False
48        except Exception:
49            return True
50
51    def test_binder_set_name_get_name(self):
52        test_name = generate_id_by_size(4)
53        result = self.droid.BluetoothBinderSetName(test_name)
54        if not result:
55            return False
56        name = self.droid.BluetoothBinderGetName()
57        if test_name != name:
58            return False
59        return True
60
61    def test_binder_get_address(self):
62        result = self.droid.BluetoothBinderGetAddress()
63        self.log.info("Found BT address: {}".format(result))
64        if not result:
65            return False
66        return True
67
68    def test_two_devices_set_get_name(self):
69        test_name = generate_id_by_size(4)
70        for n in self.native_devices:
71            d = n.droid
72            d.BluetoothBinderSetName(test_name)
73            name = d.BluetoothBinderGetName()
74            if name != test_name:
75                return False
76        return True
77
78