ScanResultTest.java revision 6d81118032b92caa0f5cfebe11af02a98f819d5e
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.bluetooth.le; 18 19import android.bluetooth.BluetoothAdapter; 20import android.bluetooth.BluetoothDevice; 21import android.os.Parcel; 22import android.test.suitebuilder.annotation.SmallTest; 23 24import junit.framework.TestCase; 25 26/** 27 * Unit test cases for Bluetooth LE scans. 28 * <p> 29 * To run this test, use adb shell am instrument -e class 'android.bluetooth.ScanResultTest' -w 30 * 'com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner' 31 */ 32public class ScanResultTest extends TestCase { 33 34 /** 35 * Test read and write parcel of ScanResult 36 */ 37 @SmallTest 38 public void testScanResultParceling() { 39 BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice( 40 "01:02:03:04:05:06"); 41 byte[] scanRecord = new byte[] { 42 1, 2, 3 }; 43 int rssi = -10; 44 long timestampMicros = 10000L; 45 46 ScanResult result = new ScanResult(device, scanRecord, rssi, timestampMicros); 47 Parcel parcel = Parcel.obtain(); 48 result.writeToParcel(parcel, 0); 49 // Need to reset parcel data position to the beginning. 50 parcel.setDataPosition(0); 51 ScanResult resultFromParcel = ScanResult.CREATOR.createFromParcel(parcel); 52 assertEquals(result, resultFromParcel); 53 } 54 55} 56