diff options
author | Wei Wang <weiwa@google.com> | 2014-07-28 21:46:44 -0700 |
---|---|---|
committer | Wei Wang <weiwa@google.com> | 2014-07-28 21:46:44 -0700 |
commit | 0462468aaff1089f08d0859e4920f90e4378b66b (patch) | |
tree | eb474e14d3b3d753630675b296ee870d68adfcee /core/tests/bluetoothtests/src | |
parent | f4e0c0cb8ef22fdb20ae74b444c9f4b7d15ded8b (diff) | |
download | frameworks_base-0462468aaff1089f08d0859e4920f90e4378b66b.zip frameworks_base-0462468aaff1089f08d0859e4920f90e4378b66b.tar.gz frameworks_base-0462468aaff1089f08d0859e4920f90e4378b66b.tar.bz2 |
Make scan filter accepts prefix. Add tests.
Change-Id: I714dd6d95ad2bc874dce1106b325762b19159119
Diffstat (limited to 'core/tests/bluetoothtests/src')
-rw-r--r-- | core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java b/core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java index 81f4baf..35da4bc 100644 --- a/core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java +++ b/core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java @@ -96,38 +96,56 @@ public class ScanFilterTest extends TestCase { @SmallTest public void testsetServiceDataFilter() { byte[] setServiceData = new byte[] { - 0x0b, 0x11, 0x50, 0x64 }; + 0x50, 0x64 }; ParcelUuid serviceDataUuid = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"); ScanFilter filter = mFilterBuilder.setServiceData(serviceDataUuid, setServiceData).build(); assertTrue("service data filter fails", filter.matches(mScanResult)); - byte[] nonMatchData = new byte[] { - 0x0b, 0x01, 0x50, 0x64 }; - filter = mFilterBuilder.setServiceData(serviceDataUuid, nonMatchData).build(); - assertFalse("service data filter fails", filter.matches(mScanResult)); + byte[] emptyData = new byte[0]; + filter = mFilterBuilder.setServiceData(serviceDataUuid, emptyData).build(); + assertTrue("service data filter fails", filter.matches(mScanResult)); + byte[] prefixData = new byte[] { + 0x50 }; + filter = mFilterBuilder.setServiceData(serviceDataUuid, prefixData).build(); + assertTrue("service data filter fails", filter.matches(mScanResult)); + + byte[] nonMatchData = new byte[] { + 0x51, 0x64 }; byte[] mask = new byte[] { - (byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xFF }; + (byte) 0x00, (byte) 0xFF }; filter = mFilterBuilder.setServiceData(serviceDataUuid, nonMatchData, mask).build(); assertTrue("partial service data filter fails", filter.matches(mScanResult)); + + filter = mFilterBuilder.setServiceData(serviceDataUuid, nonMatchData).build(); + assertFalse("service data filter fails", filter.matches(mScanResult)); } @SmallTest public void testManufacturerSpecificData() { byte[] setManufacturerData = new byte[] { - (byte) 0xE0, 0x00, 0x02, 0x15 }; - int manufacturerId = 224; + 0x02, 0x15 }; + int manufacturerId = 0xE0; ScanFilter filter = mFilterBuilder.setManufacturerData(manufacturerId, setManufacturerData).build(); - assertTrue("setManufacturerData filter fails", filter.matches(mScanResult)); + assertTrue("manufacturer data filter fails", filter.matches(mScanResult)); + + byte[] emptyData = new byte[0]; + filter = mFilterBuilder.setManufacturerData(manufacturerId, emptyData).build(); + assertTrue("manufacturer data filter fails", filter.matches(mScanResult)); + + byte[] prefixData = new byte[] { + 0x02 }; + filter = mFilterBuilder.setManufacturerData(manufacturerId, prefixData).build(); + assertTrue("manufacturer data filter fails", filter.matches(mScanResult)); + // Test data mask byte[] nonMatchData = new byte[] { - (byte) 0xF0, 0x00, 0x02, 0x15 }; + 0x02, 0x14 }; filter = mFilterBuilder.setManufacturerData(manufacturerId, nonMatchData).build(); - assertFalse("setManufacturerData filter fails", filter.matches(mScanResult)); - + assertFalse("manufacturer data filter fails", filter.matches(mScanResult)); byte[] mask = new byte[] { - (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF + (byte) 0xFF, (byte) 0x00 }; filter = mFilterBuilder.setManufacturerData(manufacturerId, nonMatchData, mask).build(); assertTrue("partial setManufacturerData filter fails", filter.matches(mScanResult)); @@ -153,27 +171,33 @@ public class ScanFilterTest extends TestCase { ParcelUuid.fromString("FFFFFFF0-FFFF-FFFF-FFFF-FFFFFFFFFFFF")).build(); testReadWriteParcelForFilter(filter); - byte[] setServiceData = new byte[] { - 0x0b, 0x11, 0x50, 0x64 }; + byte[] serviceData = new byte[] { + 0x50, 0x64 }; ParcelUuid serviceDataUuid = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"); - filter = mFilterBuilder.setServiceData(serviceDataUuid, setServiceData).build(); + filter = mFilterBuilder.setServiceData(serviceDataUuid, serviceData).build(); + testReadWriteParcelForFilter(filter); + + filter = mFilterBuilder.setServiceData(serviceDataUuid, new byte[0]).build(); testReadWriteParcelForFilter(filter); byte[] serviceDataMask = new byte[] { - (byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xFF }; - filter = mFilterBuilder.setServiceData(serviceDataUuid, setServiceData, serviceDataMask) + (byte) 0xFF, (byte) 0xFF }; + filter = mFilterBuilder.setServiceData(serviceDataUuid, serviceData, serviceDataMask) .build(); testReadWriteParcelForFilter(filter); byte[] manufacturerData = new byte[] { - (byte) 0xE0, 0x00, 0x02, 0x15 }; - int manufacturerId = 224; + 0x02, 0x15 }; + int manufacturerId = 0xE0; filter = mFilterBuilder.setManufacturerData(manufacturerId, manufacturerData).build(); testReadWriteParcelForFilter(filter); + filter = mFilterBuilder.setServiceData(serviceDataUuid, new byte[0]).build(); + testReadWriteParcelForFilter(filter); + byte[] manufacturerDataMask = new byte[] { - (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF + (byte) 0xFF, (byte) 0xFF }; filter = mFilterBuilder.setManufacturerData(manufacturerId, manufacturerData, manufacturerDataMask).build(); |