FileDocCategorySizeDatePackage
ScanRecordTest.javaAPI DocAndroid 5.1 API2904Thu Mar 12 22:22:12 GMT 2015android.bluetooth.le

ScanRecordTest

public class ScanRecordTest extends TestCase
Unit test cases for {@link ScanRecord}.

To run this test, use adb shell am instrument -e class 'android.bluetooth.ScanRecordTest' -w 'com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner'

Fields Summary
Constructors Summary
Methods Summary
private static voidassertArrayEquals(byte[] expected, byte[] actual)

        if (!Arrays.equals(expected, actual)) {
            fail("expected:<" + Arrays.toString(expected) +
                    "> but was:<" + Arrays.toString(actual) + ">");
        }

    
public voidtestParser()

        byte[] scanRecord = new byte[] {
                0x02, 0x01, 0x1a, // advertising flags
                0x05, 0x02, 0x0b, 0x11, 0x0a, 0x11, // 16 bit service uuids
                0x04, 0x09, 0x50, 0x65, 0x64, // name
                0x02, 0x0A, (byte) 0xec, // tx power level
                0x05, 0x16, 0x0b, 0x11, 0x50, 0x64, // service data
                0x05, (byte) 0xff, (byte) 0xe0, 0x00, 0x02, 0x15, // manufacturer specific data
                0x03, 0x50, 0x01, 0x02, // an unknown data type won't cause trouble
        };
        ScanRecord data = ScanRecord.parseFromBytes(scanRecord);
        assertEquals(0x1a, data.getAdvertiseFlags());
        ParcelUuid uuid1 = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
        ParcelUuid uuid2 = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
        assertTrue(data.getServiceUuids().contains(uuid1));
        assertTrue(data.getServiceUuids().contains(uuid2));

        assertEquals("Ped", data.getDeviceName());
        assertEquals(-20, data.getTxPowerLevel());

        assertTrue(data.getManufacturerSpecificData().get(0x00E0) != null);
        assertArrayEquals(new byte[] {
                0x02, 0x15 }, data.getManufacturerSpecificData().get(0x00E0));

        assertTrue(data.getServiceData().containsKey(uuid2));
        assertArrayEquals(new byte[] {
                0x50, 0x64 }, data.getServiceData().get(uuid2));