• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1mport time
2from acts.base_test import BaseTestClass
3from acts.controllers import native_android_device
4from acts.test_utils.bt.native_bt_test_utils import setup_native_bluetooth
5from acts.test_utils.bt.bt_test_utils import generate_id_by_size
6
7
8class BtNativeTest(BaseTestClass):
9    tests = None
10
11    def __init__(self, controllers):
12        BaseTestClass.__init__(self, controllers)
13        setup_native_bluetooth(self.native_android_devices)
14        self.droid = self.native_android_devices[0].droid
15        self.tests = (
16            "test_binder_get_name",
17            "test_binder_get_name_invalid_parameter",
18            "test_binder_set_name_get_name",
19            "test_binder_get_address", )
20        if len(self.native_android_devices) > 1:
21            self.droid1 = self.native_android_devices[1].droid
22            self.tests = self.tests + ("test_two_devices_set_get_name", )
23
24    def test_binder_get_name(self):
25        result = self.droid.BtBinderGetName()
26        self.log.info("Bluetooth device name: {}".format(result))
27        return True
28
29    def test_binder_get_name_invalid_parameter(self):
30        try:
31            self.droid.BtBinderGetName("unexpected_parameter")
32            return False
33        except Exception:
34            return True
35
36    def test_binder_set_name_get_name(self):
37        test_name = generate_id_by_size(4)
38        result = self.droid.BtBinderSetName(test_name)
39        if not result:
40            return False
41        name = self.droid.BtBinderGetName()
42        if test_name != name:
43            return False
44        return True
45
46    def test_binder_get_address(self):
47        result = self.droid.BtBinderGetAddress()
48        self.log.info("Found BT address: {}".format(result))
49        if not result:
50            return False
51        return True
52
53    def test_two_devices_set_get_name(self):
54        test_name = generate_id_by_size(4)
55        for n in self.native_android_devices:
56            d = n.droid
57            d.BtBinderSetName(test_name)
58            name = d.BtBinderGetName()
59            if name != test_name:
60                return False
61        return True
62
63