summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-04-24 00:41:29 +0200
committerSven Gothel <[email protected]>2022-04-24 00:43:45 +0200
commit16f811d8da54bb670e5ba3a01d5cf046892fc368 (patch)
treea667ad282235a3dd82b0a07a39cec3c74b849513 /test
parentd69443252ce0514e7938e1777621519c2acbb1ee (diff)
Add test using fat fat `Direct-BT Jaulib Fat Jar`: TestBringup00 [ loading native libs, show all adapter, no extra permissions ]
Notable, the unit tests within the `test` package are using the fat jar files which include the native libraries. The unit tests within the `trial` package, e.g. `TestDBTClientServer00`, use the non-fat Direct-BT jar file only plus selected jaulib jar files for testing framework. In these trials, the native libraries are loaded 'natively', i.e. via given library path.
Diffstat (limited to 'test')
-rw-r--r--test/java/test/org/direct_bt/TestBringup00.java96
-rw-r--r--test/java/test/org/direct_bt/TestVersionInfo.java76
-rw-r--r--test/java/test/org/direct_bt/VersionInfo.java2
3 files changed, 172 insertions, 2 deletions
diff --git a/test/java/test/org/direct_bt/TestBringup00.java b/test/java/test/org/direct_bt/TestBringup00.java
new file mode 100644
index 00000000..76a57fcf
--- /dev/null
+++ b/test/java/test/org/direct_bt/TestBringup00.java
@@ -0,0 +1,96 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2022 Gothel Software e.K.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package test.org.direct_bt;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.direct_bt.BTRole;
+import org.direct_bt.BTAdapter;
+import org.direct_bt.BTException;
+import org.direct_bt.BTFactory;
+import org.direct_bt.BTManager;
+import org.direct_bt.BTUtils;
+import org.direct_bt.DirectBTVersion;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import jau.test.junit.util.SingletonJunitCase;
+
+/**
+ * Testing BTManager bring up using fat `Direct-BT Jaulib Fat Jar` and
+ * - test loading native libraries
+ * - show all installed adapter
+ * - no extra permissions required
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestBringup00 extends SingletonJunitCase {
+ static final boolean DEBUG = false;
+
+ @Test(timeout = 5000)
+ public final void test01_ManagerBringup() {
+ {
+ // System.setProperty("direct_bt.debug", "true"); // native code
+ // System.setProperty("direct_bt.debug", "true,gatt.data"); // native code
+ // System.setProperty("org.direct_bt.debug", "true"); // java
+ // System.setProperty("jau.debug", "true"); // java
+ // System.setProperty("jau.verbose", "true"); // java
+ }
+ BTFactory.initDirectBTLibrary();
+ 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();
+ BTUtils.println(System.err, "Adapter: Count "+adapters.size());
+ for(int i=0; i<adapters.size(); i++) {
+ BTUtils.println(System.err, i+": "+adapters.get(i).toString());
+ }
+ for(final BTAdapter a : adapters) {
+ Assert.assertFalse( a.isInitialized() );
+ Assert.assertFalse( a.isPowered() );
+ Assert.assertEquals( BTRole.Master, a.getRole() ); // default role
+ Assert.assertTrue( 4 <= a.getBTMajorVersion() );
+ }
+ // All implicit via destructor or shutdown hook!
+ manager.shutdown(); /* implies: adapter.close(); */
+ }
+
+ public static void main(final String args[]) {
+ org.junit.runner.JUnitCore.main(TestBringup00.class.getName());
+ }
+}
diff --git a/test/java/test/org/direct_bt/TestVersionInfo.java b/test/java/test/org/direct_bt/TestVersionInfo.java
new file mode 100644
index 00000000..e403c380
--- /dev/null
+++ b/test/java/test/org/direct_bt/TestVersionInfo.java
@@ -0,0 +1,76 @@
+/**
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2022 Gothel Software e.K.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package test.org.direct_bt;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+
+import org.jau.sec.SHASum;
+import org.jau.util.VersionUtil;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.direct_bt.DirectBTVersion;
+
+import jau.test.junit.util.SingletonJunitCase;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestVersionInfo extends SingletonJunitCase {
+ static boolean VERBOSE = false;
+
+ @Test
+ public void test01Info() {
+ System.err.println(VersionUtil.getPlatformInfo());
+ System.err.println("Version Info:");
+ System.err.println(DirectBTVersion.getInstance());
+ System.err.println("");
+ System.err.println("Full Manifest:");
+ System.err.println(DirectBTVersion.getInstance().getFullManifestInfo(null));
+ }
+
+ // @Test // FIXME: Add SHA signature in build system!
+ public void test02ValidateSHA()
+ throws IllegalArgumentException, IOException, URISyntaxException, SecurityException, NoSuchAlgorithmException
+ {
+ final DirectBTVersion info = DirectBTVersion.getInstance();
+ final String shaClassesThis = info.getImplementationSHAClassesThis();
+ System.err.println("SHA CLASSES.this (build-time): "+shaClassesThis);
+
+ final DirectBTVersion.JarSHASum shaSum = new DirectBTVersion.JarSHASum();
+ final byte[] shasum = shaSum.compute(VERBOSE);
+ final String shaClasses = SHASum.toHexString(shasum, null).toString();
+ System.err.println("SHA CLASSES.this (now): "+shaClasses);
+ Assert.assertEquals("SHA not equal", shaClassesThis, shaClasses);
+ }
+
+ public static void main(final String args[]) throws IOException {
+ // VERBOSE = true;
+ final String tstname = TestVersionInfo.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/test/java/test/org/direct_bt/VersionInfo.java b/test/java/test/org/direct_bt/VersionInfo.java
index 03f4ec7b..53b2a972 100644
--- a/test/java/test/org/direct_bt/VersionInfo.java
+++ b/test/java/test/org/direct_bt/VersionInfo.java
@@ -3,8 +3,6 @@ package test.org.direct_bt;
import java.io.IOException;
import org.direct_bt.BTFactory;
-import org.direct_bt.DirectBTVersion;
-import org.jau.util.VersionUtil;
public class VersionInfo {
public static void main(final String args[]) throws IOException {