Added some IBeaconUtils tests

This commit is contained in:
Alexandros Schillings
2015-07-03 18:06:10 +01:00
parent 70169dc0b7
commit 33f2a265f7
2 changed files with 42 additions and 3 deletions

View File

@@ -8,7 +8,7 @@ public class IBeaconUtils {
private static final double DISTANCE_THRESHOLD_IMMEDIATE = 0.5;
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.
@@ -103,7 +103,7 @@ public class IBeaconUtils {
* @return true if the device is an iBeacon, false otherwise
*/
public static boolean isThisAnIBeacon(final BluetoothLeDevice device) {
return isThisAnIBeacon(
device.getAdRecordStore().getRecordDataAsString(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getBytes());
final int key = AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA;
return isThisAnIBeacon(device.getAdRecordStore().getRecordDataAsString(key).getBytes());
}
}

View File

@@ -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 {
}
}