• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021-2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# -----------------------------------------------------------------------------
16# Imports
17# -----------------------------------------------------------------------------
18from bumble.core import AdvertisingData
19
20
21# -----------------------------------------------------------------------------
22def test_ad_data():
23    data = bytes([2, AdvertisingData.TX_POWER_LEVEL, 123])
24    ad = AdvertisingData.from_bytes(data)
25    ad_bytes = bytes(ad)
26    assert(data == ad_bytes)
27    assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME) is None)
28    assert(ad.get(AdvertisingData.TX_POWER_LEVEL) == bytes([123]))
29    assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME, return_all=True) == [])
30    assert(ad.get(AdvertisingData.TX_POWER_LEVEL, return_all=True) == [bytes([123])])
31
32    data2 = bytes([2, AdvertisingData.TX_POWER_LEVEL, 234])
33    ad.append(data2)
34    ad_bytes = bytes(ad)
35    assert(ad_bytes == data + data2)
36    assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME) is None)
37    assert(ad.get(AdvertisingData.TX_POWER_LEVEL) == bytes([123]))
38    assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME, return_all=True) == [])
39    assert(ad.get(AdvertisingData.TX_POWER_LEVEL, return_all=True) == [bytes([123]), bytes([234])])
40
41
42# -----------------------------------------------------------------------------
43if __name__ == '__main__':
44    test_ad_data()