use of org.altbeacon.beacon.Identifier in project android-beacon-library by AltBeacon.
the class RangingDataTest method testSerialization.
@Test
public void testSerialization() throws Exception {
Context context = RuntimeEnvironment.application;
ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
identifiers.add(Identifier.parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6"));
identifiers.add(Identifier.parse("1"));
identifiers.add(Identifier.parse("2"));
Region region = new Region("testRegion", identifiers);
ArrayList<Beacon> beacons = new ArrayList<Beacon>();
Beacon beacon = new Beacon.Builder().setIdentifiers(identifiers).setRssi(-1).setRunningAverageRssi(-2).setTxPower(-50).setBluetoothAddress("01:02:03:04:05:06").build();
beacon.setRssiMeasurementCount(1);
beacon.setPacketCount(2);
for (int i = 0; i < 10; i++) {
beacons.add(beacon);
}
RangingData data = new RangingData(beacons, region);
Bundle bundle = data.toBundle();
RangingData data2 = RangingData.fromBundle(bundle);
assertEquals("beacon count shouild be restored", 10, data2.getBeacons().size());
assertEquals("region identifier 1 shouild be restored", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", data2.getRegion().getId1().toString());
Beacon restoredBeacon = data2.getBeacons().iterator().next();
assertEquals("beacon identifier 1 shouild be restored", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", restoredBeacon.getId1().toString());
assertEquals("RSSI is restored", -1, restoredBeacon.getRssi());
assertEquals("Average RSSI is restored", -2.0, restoredBeacon.getRunningAverageRssi(), 0.0);
assertEquals("TXPower is restored", -50, restoredBeacon.getTxPower());
assertEquals("Measurement count is restored", 1, restoredBeacon.getMeasurementCount());
assertEquals("Packet count is restored", 2, restoredBeacon.getPacketCount());
}
use of org.altbeacon.beacon.Identifier in project android-beacon-library by AltBeacon.
the class ScanFilterUtilsTest method testScanFilterWithIdentifiers.
@Test
public void testScanFilterWithIdentifiers() throws Exception {
org.robolectric.shadows.ShadowLog.stream = System.err;
BeaconParser parser = new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
parser.setHardwareAssistManufacturerCodes(new int[] { 0x004c });
// no manifest available in robolectric
BeaconManager.setManifestCheckingDisabled(true);
ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
identifiers.add(Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"));
identifiers.add(Identifier.parse("0x0102"));
identifiers.add(Identifier.parse("0x0304"));
List<ScanFilterUtils.ScanFilterData> scanFilterDatas = new ScanFilterUtils().createScanFilterDataForBeaconParser(parser, identifiers);
assertEquals("scanFilters should be of correct size", 1, scanFilterDatas.size());
ScanFilterUtils.ScanFilterData sfd = scanFilterDatas.get(0);
assertEquals("manufacturer should be right", 0x004c, sfd.manufacturer);
assertEquals("mask length should be right", 22, sfd.mask.length);
assertArrayEquals("mask should be right", new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }, sfd.mask);
assertArrayEquals("filter should be right", new byte[] { (byte) 0x02, (byte) 0x15, (byte) 0x2F, (byte) 0x23, (byte) 0x44, (byte) 0x54, (byte) 0xCF, (byte) 0x6D, (byte) 0x4A, (byte) 0x0F, (byte) 0xAD, (byte) 0xF2, (byte) 0xF4, (byte) 0x91, (byte) 0x1B, (byte) 0xA9, (byte) 0xFF, (byte) 0xA6, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 }, sfd.filter);
}
use of org.altbeacon.beacon.Identifier in project android-beacon-library by AltBeacon.
the class RangingDataTest method testSerializationBenchmark.
@Test
public // On MacBookPro 2.5 GHz Core I7, 10000 serialization/deserialiation cycles of RangingData took 22ms
void testSerializationBenchmark() throws Exception {
Context context = RuntimeEnvironment.application;
ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
identifiers.add(Identifier.parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6"));
identifiers.add(Identifier.parse("1"));
identifiers.add(Identifier.parse("2"));
Region region = new Region("testRegion", identifiers);
ArrayList<Beacon> beacons = new ArrayList<Beacon>();
Beacon beacon = new Beacon.Builder().setIdentifiers(identifiers).setRssi(-1).setRunningAverageRssi(-2).setTxPower(-50).setBluetoothAddress("01:02:03:04:05:06").build();
for (int i = 0; i < 10; i++) {
beacons.add(beacon);
}
RangingData data = new RangingData(beacons, region);
long time1 = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
Bundle bundle = data.toBundle();
RangingData data2 = RangingData.fromBundle(bundle);
}
long time2 = System.currentTimeMillis();
System.out.println("*** Ranging Data Serialization benchmark: " + (time2 - time1));
}
Aggregations