]> git.basschouten.com Git - openhab-addons.git/blob
089425bbc079c8151161d5190dbd3725637d068e
[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.junit.jupiter.api.Test;
20
21 /**
22  * Tests {@link BluetoothCharacteristic}.
23  *
24  * @author Peter Rosenberg - Initial contribution
25  */
26 public class CharacteristicPropertiesTest {
27     private BluetoothCharacteristic characteristic = new BluetoothCharacteristic(UUID.randomUUID(), 0);
28
29     @Test
30     public void testAllSupportedProperties() {
31         // given
32         // when
33         int properties = 0;
34         properties |= BluetoothCharacteristic.PROPERTY_BROADCAST;
35         properties |= BluetoothCharacteristic.PROPERTY_READ;
36         properties |= BluetoothCharacteristic.PROPERTY_WRITE_NO_RESPONSE;
37         properties |= BluetoothCharacteristic.PROPERTY_WRITE;
38         properties |= BluetoothCharacteristic.PROPERTY_NOTIFY;
39         properties |= BluetoothCharacteristic.PROPERTY_INDICATE;
40         characteristic.setProperties(properties);
41
42         // then
43         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_BROADCAST), "Broastcast not set");
44         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_READ), "Read not set");
45         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE_NO_RESPONSE),
46                 "Write not response not set");
47         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE), "Write not set");
48         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_NOTIFY), "Notify not set");
49         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_INDICATE), "Indicate not set");
50         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_SIGNED_WRITE),
51                 "Signed write set");
52         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_EXTENDED_PROPS),
53                 "Extended props set");
54     }
55
56     @Test
57     public void testNoProperties() {
58         // given
59         // when
60         int properties = 0;
61         characteristic.setProperties(properties);
62
63         // then
64         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_BROADCAST),
65                 "Broastcast not set");
66         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_READ), "Read not set");
67         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE_NO_RESPONSE),
68                 "Write not response not set");
69         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE), "Write not set");
70         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_NOTIFY), "Notify not set");
71         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_INDICATE), "Indicate not set");
72         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_SIGNED_WRITE),
73                 "Signed write set");
74         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_EXTENDED_PROPS),
75                 "Extended props set");
76     }
77
78     @Test
79     public void testSomeSupportedProperties() {
80         // given
81         // when
82         int properties = 0;
83         properties |= BluetoothCharacteristic.PROPERTY_READ;
84         properties |= BluetoothCharacteristic.PROPERTY_NOTIFY;
85         characteristic.setProperties(properties);
86
87         // then
88         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_BROADCAST),
89                 "Broastcast not set");
90         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_READ), "Read not set");
91         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE_NO_RESPONSE),
92                 "Write not response not set");
93         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_WRITE), "Write not set");
94         assertTrue(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_NOTIFY), "Notify not set");
95         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_INDICATE), "Indicate not set");
96         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_SIGNED_WRITE),
97                 "Signed write set");
98         assertFalse(characteristic.hasPropertyEnabled(BluetoothCharacteristic.PROPERTY_EXTENDED_PROPS),
99                 "Extended props set");
100     }
101 }