diff options
author | Sven Gothel <[email protected]> | 2022-05-16 14:22:59 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-05-16 14:56:20 +0200 |
commit | 7a0c3f5e16ee4c5eb728676f0523a2254888b9c8 (patch) | |
tree | 635e6b3c619b9146be14886c6cd03a9f5a58be54 /test | |
parent | 7af9bafddf73ef4f127693178dab976c3492b70f (diff) |
Tests: Have test_bringup00.cpp/TestBringup00.java pass valgrind and resetStates also pre-test for clear adapter state (POWERED)
Diffstat (limited to 'test')
-rw-r--r-- | test/direct_bt/test_bringup00.cpp | 19 | ||||
-rw-r--r-- | test/java/test/org/direct_bt/TestBringup00.java | 33 |
2 files changed, 51 insertions, 1 deletions
diff --git a/test/direct_bt/test_bringup00.cpp b/test/direct_bt/test_bringup00.cpp index 64925d56..701035d7 100644 --- a/test/direct_bt/test_bringup00.cpp +++ b/test/direct_bt/test_bringup00.cpp @@ -36,6 +36,21 @@ using namespace direct_bt; +void resetStates() { + std::shared_ptr<BTManager> mngr = BTManager::get(); + jau::darray<BTAdapterRef> adapters = mngr->getAdapters(); + for(BTAdapterRef a : adapters) { + a->removeAllStatusListener(); + a->stopAdvertising(); + a->stopDiscovery(); + REQUIRE( a->setPowered(false) ); + } + mngr->removeAllChangedAdapterSetCallbacks(); + BTDeviceRegistry::clearWaitForDevices(); + BTDeviceRegistry::clearProcessedDevices(); + BTSecurityRegistry::clear(); +} + /** * Testing BTManager bring up: * - test loading native libraries @@ -47,6 +62,7 @@ TEST_CASE( "BTManager Bringup Test 00", "[test][BTManager][bringup]" ) { // setenv("direct_bt.debug", "true", 1 /* overwrite */); } jau::fprintf_td(stderr, "Direct-BT Native Version %s (API %s)\n", DIRECT_BT_VERSION, DIRECT_BT_VERSION_API); + resetStates(); BTManagerRef manager = BTManager::get(); @@ -63,7 +79,10 @@ TEST_CASE( "BTManager Bringup Test 00", "[test][BTManager][bringup]" ) { REQUIRE( BTRole::Master == a->getRole() ); // default role REQUIRE( 4 <= a->getBTMajorVersion() ); } + jau::fprintf_td(stderr, "Manager: Closing\n"); + adapters.clear(); + resetStates(); manager->close(); /* implies: adapter.close(); */ jau::fprintf_td(stderr, "Test: Done\n"); diff --git a/test/java/test/org/direct_bt/TestBringup00.java b/test/java/test/org/direct_bt/TestBringup00.java index 76a57fcf..33b8c684 100644 --- a/test/java/test/org/direct_bt/TestBringup00.java +++ b/test/java/test/org/direct_bt/TestBringup00.java @@ -28,7 +28,9 @@ import java.lang.reflect.InvocationTargetException; import java.util.List; import org.direct_bt.BTRole; +import org.direct_bt.BTSecurityRegistry; import org.direct_bt.BTAdapter; +import org.direct_bt.BTDeviceRegistry; import org.direct_bt.BTException; import org.direct_bt.BTFactory; import org.direct_bt.BTManager; @@ -51,7 +53,33 @@ import jau.test.junit.util.SingletonJunitCase; public class TestBringup00 extends SingletonJunitCase { static final boolean DEBUG = false; - @Test(timeout = 5000) + private void resetStates() { + BTManager manager = null; + try { + manager = BTFactory.getDirectBTManager(); + } catch (BTException | NoSuchMethodException | SecurityException + | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | ClassNotFoundException e) { + e.printStackTrace(); + BTUtils.println(System.err, "Unable to instantiate Direct-BT BluetoothManager: "+e.getMessage()); + e.printStackTrace(); + } + if( null != manager ) { + final List<BTAdapter> adapters = manager.getAdapters(); + for(final BTAdapter a : adapters) { + a.removeAllStatusListener(); + a.stopAdvertising(); + a.stopDiscovery(); + Assert.assertTrue( a.setPowered(false) ); + } + } + manager.removeAllChangedAdapterSetListener(); + BTDeviceRegistry.clearWaitForDevices(); + BTDeviceRegistry.clearProcessedDevices(); + BTSecurityRegistry.clear(); + } + + @Test(timeout = 40000) // long timeout for valgrind public final void test01_ManagerBringup() { { // System.setProperty("direct_bt.debug", "true"); // native code @@ -62,6 +90,7 @@ public class TestBringup00 extends SingletonJunitCase { } BTFactory.initDirectBTLibrary(); DirectBTVersion.printVersionInfo(System.err); + resetStates(); BTManager manager = null; try { @@ -87,6 +116,8 @@ public class TestBringup00 extends SingletonJunitCase { Assert.assertTrue( 4 <= a.getBTMajorVersion() ); } // All implicit via destructor or shutdown hook! + adapters.clear(); + resetStates(); manager.shutdown(); /* implies: adapter.close(); */ } |