Unit test, trial using actual BT adapter.
Unit test, trial using actual BT adapter.Basic client and server Bluetooth tests, requiring one BT adapter:
package trial.org.direct_bt;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import org.direct_bt.BTMode;
import org.direct_bt.BTRole;
import org.direct_bt.BTSecurityLevel;
import org.direct_bt.BTAdapter;
import org.direct_bt.BTException;
import org.direct_bt.BTFactory;
import org.direct_bt.BTManager;
import org.direct_bt.DirectBTVersion;
import org.jau.io.PrintUtil;
import org.jau.net.EUI48;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestDBTClientServer00 extends BaseDBTClientServer {
static final boolean DEBUG = false;
@Test(timeout = 5000)
DirectBTVersion.printVersionInfo(System.err);
BTManager manager = null;
try {
manager = BTFactory.getDirectBTManager();
} catch (BTException | NoSuchMethodException | SecurityException
| IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException e) {
e.printStackTrace();
Assert.assertNull("Unable to instantiate Direct-BT BluetoothManager: "+e.getMessage(), e);
}
if( null == manager ) {
return;
}
final List<BTAdapter> adapters = manager.getAdapters();
PrintUtil.println(System.err, "Adapter: Count "+adapters.size());
for(int i=0; i<adapters.size(); i++) {
PrintUtil.println(System.err, i+": "+adapters.get(i).toString());
}
Assert.assertTrue("Adapter count not >= 1 but "+adapters.size(), adapters.size() >= 1);
for(final BTAdapter a : adapters) {
Assert.assertFalse( a.isInitialized() );
Assert.assertFalse( a.isPowered() );
Assert.assertEquals( BTRole.Master, a.getRole() );
Assert.assertTrue( 4 <= a.getBTMajorVersion() );
}
}
@Test(timeout = 5000)
BTManager manager = null;
try {
manager = BTFactory.getDirectBTManager();
} catch (BTException | NoSuchMethodException | SecurityException
| IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException e) {
e.printStackTrace();
Assert.assertNull("Unable to instantiate Direct-BT BluetoothManager: "+e.getMessage(), e);
}
if( null == manager ) {
return;
}
final String serverName = "TestDBTCS00-S-T10";
final DBTServer01 server = new DBTServer01(serverName, EUI48.ALL_DEVICE, BTMode.DUAL, true , BTSecurityLevel.NONE);
server.setProtocolSessionsLeft(1);
final DBTEndpoint.ChangedAdapterSetListener myChangedAdapterSetListener =
DBTEndpoint.initChangedAdapterSetListener(manager, Arrays.asList(server));
DBTEndpoint.checkInitializedState(server);
DBTServerTest.startAdvertising(server, false , "test10_startAdvertising");
DBTServerTest.stop(server, "test10_stopAdvertising");
{
final BTAdapter adapter = server.getAdapter();
{
adapter.removeAllStatusListener();
}
DBTEndpoint.startDiscovery(adapter, false );
DBTEndpoint.stopDiscovery(adapter, true );
}
final int count = manager.removeChangedAdapterSetListener(myChangedAdapterSetListener);
PrintUtil.println(System.err, "****** EOL Removed ChangedAdapterSetCallback " + count);
}
public static void main(
final String args[]) {
org.junit.runner.JUnitCore.main(TestDBTClientServer00.class.getName());
}
}
final void test01_ManagerBringup()
Testing BTManager bring up using non-fat Direct-BT Jar and.
final void test10_ServerStartStop_and_ToggleDiscovery()
static void main(final String args[])