Added some IBeaconUtils tests
This commit is contained in:
@@ -8,7 +8,7 @@ public class IBeaconUtils {
|
|||||||
private static final double DISTANCE_THRESHOLD_IMMEDIATE = 0.5;
|
private static final double DISTANCE_THRESHOLD_IMMEDIATE = 0.5;
|
||||||
private static final double DISTANCE_THRESHOLD_NEAR = 3.0;
|
private static final double DISTANCE_THRESHOLD_NEAR = 3.0;
|
||||||
|
|
||||||
private static final byte[] MANUFACTURER_DATA_IBEACON_PREFIX = new byte[]{0x4C, 0x00, 0x02, 0x15};
|
private static final byte[] MANUFACTURER_DATA_IBEACON_PREFIX = {0x4C, 0x00, 0x02, 0x15};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the accuracy of an RSSI reading.
|
* Calculates the accuracy of an RSSI reading.
|
||||||
@@ -103,7 +103,7 @@ public class IBeaconUtils {
|
|||||||
* @return true if the device is an iBeacon, false otherwise
|
* @return true if the device is an iBeacon, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isThisAnIBeacon(final BluetoothLeDevice device) {
|
public static boolean isThisAnIBeacon(final BluetoothLeDevice device) {
|
||||||
return isThisAnIBeacon(
|
final int key = AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA;
|
||||||
device.getAdRecordStore().getRecordDataAsString(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getBytes());
|
return isThisAnIBeacon(device.getAdRecordStore().getRecordDataAsString(key).getBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package uk.co.alt236.bluetoothlelib.util;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class IBeaconUtilsTest extends TestCase {
|
||||||
|
|
||||||
|
public void testIsThisAnIBeacon() throws Exception {
|
||||||
|
assertFalse(IBeaconUtils.isThisAnIBeacon((byte[]) null));
|
||||||
|
assertFalse(IBeaconUtils.isThisAnIBeacon(new byte[0]));
|
||||||
|
assertFalse(IBeaconUtils.isThisAnIBeacon(new byte[25]));
|
||||||
|
|
||||||
|
assertTrue(IBeaconUtils.isThisAnIBeacon(new byte[]{
|
||||||
|
0x4C, 0x00, 0x02, 0x15, 0x00, // <- Magic iBeacon header
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetDistanceDescriptor() throws Exception {
|
||||||
|
assertEquals(IBeaconDistanceDescriptor.UNKNOWN, IBeaconUtils.getDistanceDescriptor(-1));
|
||||||
|
|
||||||
|
assertEquals(IBeaconDistanceDescriptor.IMMEDIATE, IBeaconUtils.getDistanceDescriptor(0));
|
||||||
|
assertEquals(IBeaconDistanceDescriptor.IMMEDIATE, IBeaconUtils.getDistanceDescriptor(0.4));
|
||||||
|
|
||||||
|
assertEquals(IBeaconDistanceDescriptor.NEAR, IBeaconUtils.getDistanceDescriptor(0.5));
|
||||||
|
assertEquals(IBeaconDistanceDescriptor.NEAR, IBeaconUtils.getDistanceDescriptor(2.9));
|
||||||
|
|
||||||
|
assertEquals(IBeaconDistanceDescriptor.FAR, IBeaconUtils.getDistanceDescriptor(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCalculateUuidString() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user