diff options
author | Wei Wang <weiwa@google.com> | 2014-07-23 00:33:44 -0700 |
---|---|---|
committer | Wei Wang <weiwa@google.com> | 2014-07-23 10:23:10 -0700 |
commit | 03259472b19fef586f5eec5d4e7d61c34a6cd298 (patch) | |
tree | cd8f4fc3384382fa1360f1ccabdea2287861b7c3 /core/tests/bluetoothtests/src | |
parent | 52ff21d841ad5b39b6def0c286a737fd4b74b2e2 (diff) | |
download | frameworks_base-03259472b19fef586f5eec5d4e7d61c34a6cd298.zip frameworks_base-03259472b19fef586f5eec5d4e7d61c34a6cd298.tar.gz frameworks_base-03259472b19fef586f5eec5d4e7d61c34a6cd298.tar.bz2 |
Fix parcel issues with empty service uuid. Added tests.
b/16490816
Change-Id: If26a4731f22e83df4f5ded2ad76901de6c49a010
Diffstat (limited to 'core/tests/bluetoothtests/src')
-rw-r--r-- | core/tests/bluetoothtests/src/android/bluetooth/le/AdvertiseDataTest.java | 144 | ||||
-rw-r--r-- | core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java | 1 |
2 files changed, 144 insertions, 1 deletions
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/le/AdvertiseDataTest.java b/core/tests/bluetoothtests/src/android/bluetooth/le/AdvertiseDataTest.java new file mode 100644 index 0000000..5e451ca --- /dev/null +++ b/core/tests/bluetoothtests/src/android/bluetooth/le/AdvertiseDataTest.java @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.bluetooth.le; + +import android.os.Parcel; +import android.os.ParcelUuid; +import android.test.suitebuilder.annotation.SmallTest; + +import junit.framework.TestCase; + +/** + * Unit test cases for {@link AdvertiseData}. + * <p> + * To run the test, use adb shell am instrument -e class 'android.bluetooth.le.AdvertiseDataTest' -w + * 'com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner' + */ +public class AdvertiseDataTest extends TestCase { + + private AdvertiseData.Builder mAdvertiseDataBuilder; + + @Override + protected void setUp() throws Exception { + mAdvertiseDataBuilder = new AdvertiseData.Builder(); + } + + @SmallTest + public void testEmptyData() { + Parcel parcel = Parcel.obtain(); + AdvertiseData data = mAdvertiseDataBuilder.build(); + data.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + AdvertiseData dataFromParcel = + AdvertiseData.CREATOR.createFromParcel(parcel); + assertEquals(data, dataFromParcel); + } + + @SmallTest + public void testEmptyServiceUuid() { + Parcel parcel = Parcel.obtain(); + AdvertiseData data = mAdvertiseDataBuilder.setIncludeDeviceName(true).build(); + data.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + AdvertiseData dataFromParcel = + AdvertiseData.CREATOR.createFromParcel(parcel); + assertEquals(data, dataFromParcel); + } + + @SmallTest + public void testEmptyManufacturerData() { + Parcel parcel = Parcel.obtain(); + int manufacturerId = 50; + byte[] manufacturerData = new byte[0]; + AdvertiseData data = + mAdvertiseDataBuilder.setIncludeDeviceName(true) + .setManufacturerData(manufacturerId, manufacturerData).build(); + data.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + AdvertiseData dataFromParcel = + AdvertiseData.CREATOR.createFromParcel(parcel); + assertEquals(data, dataFromParcel); + } + + @SmallTest + public void testEmptyServiceData() { + Parcel parcel = Parcel.obtain(); + ParcelUuid uuid = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB"); + byte[] serviceData = new byte[0]; + AdvertiseData data = + mAdvertiseDataBuilder.setIncludeDeviceName(true) + .setServiceData(uuid, serviceData).build(); + data.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + AdvertiseData dataFromParcel = + AdvertiseData.CREATOR.createFromParcel(parcel); + assertEquals(data, dataFromParcel); + } + + @SmallTest + public void testServiceUuid() { + Parcel parcel = Parcel.obtain(); + ParcelUuid uuid = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB"); + ParcelUuid uuid2 = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"); + + AdvertiseData data = + mAdvertiseDataBuilder.setIncludeDeviceName(true) + .addServiceUuid(uuid).addServiceUuid(uuid2).build(); + data.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + AdvertiseData dataFromParcel = + AdvertiseData.CREATOR.createFromParcel(parcel); + assertEquals(data, dataFromParcel); + } + + @SmallTest + public void testManufacturerData() { + Parcel parcel = Parcel.obtain(); + ParcelUuid uuid = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB"); + ParcelUuid uuid2 = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"); + + int manufacturerId = 50; + byte[] manufacturerData = new byte[] { + (byte) 0xF0, 0x00, 0x02, 0x15 }; + AdvertiseData data = + mAdvertiseDataBuilder.setIncludeDeviceName(true) + .addServiceUuid(uuid).addServiceUuid(uuid2) + .setManufacturerData(manufacturerId, manufacturerData).build(); + + data.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + AdvertiseData dataFromParcel = + AdvertiseData.CREATOR.createFromParcel(parcel); + assertEquals(data, dataFromParcel); + } + + @SmallTest + public void testServiceData() { + Parcel parcel = Parcel.obtain(); + ParcelUuid uuid = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB"); + byte[] serviceData = new byte[] { + (byte) 0xF0, 0x00, 0x02, 0x15 }; + AdvertiseData data = + mAdvertiseDataBuilder.setIncludeDeviceName(true) + .setServiceData(uuid, serviceData).build(); + data.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + AdvertiseData dataFromParcel = + AdvertiseData.CREATOR.createFromParcel(parcel); + assertEquals(data, dataFromParcel); + } +} diff --git a/core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java b/core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java index 25ea227..81f4baf 100644 --- a/core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java +++ b/core/tests/bluetoothtests/src/android/bluetooth/le/ScanFilterTest.java @@ -186,7 +186,6 @@ public class ScanFilterTest extends TestCase { parcel.setDataPosition(0); ScanFilter filterFromParcel = ScanFilter.CREATOR.createFromParcel(parcel); - System.out.println(filterFromParcel); assertEquals(filter, filterFromParcel); } } |