]> git.basschouten.com Git - openhab-addons.git/blob
85dd0bb1e8c68e5846f7469c447674bd65080fb5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.UUID;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21
22 /**
23  * Tests {@link BluetoothCharacteristic}.
24  *
25  * @author Peter Rosenberg - Initial contribution
26  */
27 @NonNullByDefault
28 public class CharacteristicPropertiesTest {
29     private BluetoothCharacteristic characteristic = new BluetoothCharacteristic(UUID.randomUUID(), 0);
30
31     @Test
32     public void testAllSupportedProperties() {
33         // given
34         // when
35         int properties = 0;
36         properties |= BluetoothCharacteristic.PROPERTY_BROADCAST;
37         properties |= BluetoothCharacteristic.PROPERTY_READ;
38         properties |= BluetoothCharacteristic.PROPERTY_WRITE_NO_RESPONSE;
39         properties |= BluetoothCharacteristic.PROPERTY_WRITE;
40         properties |= BluetoothCharacteristic.PROPERTY_NOTIFY;
41         properties |= BluetoothCharacteristic.PROPERTY_INDICATE;
42         characteristic.setProperties(properties);
43
44         // then
45         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_BROADCAST), "Broastcast not set");
46         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_READ), "Read not set");
47         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE_NO_RESPONSE),
48                 "Write not response not set");
49         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE), "Write not set");
50         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_NOTIFY), "Notify not set");
51         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_INDICATE), "Indicate not set");
52         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_SIGNED_WRITE),
53                 "Signed write set");
54         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_EXTENDED_PROPS),
55                 "Extended props set");
56     }
57
58     @Test
59     public void testNoProperties() {
60         // given
61         // when
62         int properties = 0;
63         characteristic.setProperties(properties);
64
65         // then
66         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_BROADCAST),
67                 "Broastcast not set");
68         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_READ), "Read not set");
69         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE_NO_RESPONSE),
70                 "Write not response not set");
71         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE), "Write not set");
72         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_NOTIFY), "Notify not set");
73         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_INDICATE), "Indicate not set");
74         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_SIGNED_WRITE),
75                 "Signed write set");
76         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_EXTENDED_PROPS),
77                 "Extended props set");
78     }
79
80     @Test
81     public void testSomeSupportedProperties() {
82         // given
83         // when
84         int properties = 0;
85         properties |= BluetoothCharacteristic.PROPERTY_READ;
86         properties |= BluetoothCharacteristic.PROPERTY_NOTIFY;
87         characteristic.setProperties(properties);
88
89         // then
90         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_BROADCAST),
91                 "Broastcast not set");
92         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_READ), "Read not set");
93         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE_NO_RESPONSE),
94                 "Write not response not set");
95         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE), "Write not set");
96         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_NOTIFY), "Notify not set");
97         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_INDICATE), "Indicate not set");
98         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_SIGNED_WRITE),
99                 "Signed write set");
100         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_EXTENDED_PROPS),
101                 "Extended props set");
102     }
103 }