Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
DBTClientTest.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24package trial.org.direct_bt;
25
26import org.direct_bt.BTAdapter;
27import org.direct_bt.BTRole;
28import org.direct_bt.DiscoveryPolicy;
29import org.direct_bt.HCIStatusCode;
30import org.junit.Assert;
31
32public interface DBTClientTest extends DBTEndpoint {
33
34 /**
35 * Set DiscoveryPolicy
36 *
37 * Default is {@link DiscoveryPolicy#PAUSE_CONNECTED_UNTIL_READY}
38 */
40
41 /**
42 * Set disconnect after processing.
43 *
44 * Default is `true`.
45 */
46 void setDisconnectDeviceed(final boolean v);
47
48 /**
49 * Set remove device when disconnecting.
50 *
51 * This removes the device from all instances within adapter
52 * and hence all potential side-effects of the current instance.
53 *
54 * Default is `false`, since it is good to test whether such side-effects exists.
55 */
56 void setRemoveDevice(final boolean v);
57
59
61
62 public static void startDiscovery(final DBTClientTest client, final boolean current_exp_discovering_state, final String msg) {
63 final BTAdapter adapter = client.getAdapter();
64 Assert.assertFalse(adapter.isAdvertising());
65 Assert.assertEquals(current_exp_discovering_state, adapter.isDiscovering());
66
67 Assert.assertEquals( HCIStatusCode.SUCCESS, client.startDiscovery(msg) );
68 while( !adapter.isDiscovering() ) { // pending action
69 try { Thread.sleep(100); } catch (final InterruptedException e) { e.printStackTrace(); }
70 }
71 Assert.assertFalse(adapter.isAdvertising());
72 Assert.assertTrue(adapter.isDiscovering());
73 Assert.assertEquals( BTRole.Master, adapter.getRole() );
74 }
75
76 public static void stopDiscovery(final DBTClientTest client, final boolean current_exp_discovering_state, final String msg) {
77 final BTAdapter adapter = client.getAdapter();
78 Assert.assertFalse(adapter.isAdvertising());
79 Assert.assertEquals(current_exp_discovering_state, adapter.isDiscovering());
80 Assert.assertEquals( BTRole.Master, adapter.getRole() );
81
82 Assert.assertEquals( HCIStatusCode.SUCCESS, client.stopDiscovery(msg) );
83 while( adapter.isDiscovering() ) { // pending action
84 try { Thread.sleep(100); } catch (final InterruptedException e) { e.printStackTrace(); }
85 }
86 Assert.assertFalse(adapter.isAdvertising());
87 Assert.assertFalse(adapter.isDiscovering());
88 Assert.assertEquals( BTRole.Master, adapter.getRole() );
89 }
90}
Bluetooth roles from the perspective of the link layer (connection initiator).
Definition: BTRole.java:36
Master
Master or central role, discovering remote devices and initiating connection.
Definition: BTRole.java:40
Discovery policy defines the BTAdapter discovery mode after connecting a remote BTDevice:
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
BTAdapter represents one local Bluetooth Controller.
Definition: BTAdapter.java:48
boolean isAdvertising()
Returns the adapter's current advertising state.
boolean isDiscovering()
Returns true if the meta discovering state is not ScanType#NONE.
BTRole getRole()
Return the current BTRole of this adapter.
void setDisconnectDeviceed(final boolean v)
Set disconnect after processing.
HCIStatusCode startDiscovery(String msg)
static void stopDiscovery(final DBTClientTest client, final boolean current_exp_discovering_state, final String msg)
static void startDiscovery(final DBTClientTest client, final boolean current_exp_discovering_state, final String msg)
void setRemoveDevice(final boolean v)
Set remove device when disconnecting.
HCIStatusCode stopDiscovery(String msg)
void setDiscoveryPolicy(final DiscoveryPolicy v)
Set DiscoveryPolicy.
BTAdapter getAdapter()
Return the adapter for this endpoint.