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; 18 19import android.os.ParcelUuid; 20import android.test.suitebuilder.annotation.SmallTest; 21 22import junit.framework.TestCase; 23 24/** 25 * Unit test cases for {@link BluetoothUuid}. 26 * <p> 27 * To run this test, use adb shell am instrument -e class 'android.bluetooth.BluetoothUuidTest' -w 28 * 'com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner' 29 */ 30public class BluetoothUuidTest extends TestCase { 31 32 @SmallTest 33 public void testUuidParser() { 34 byte[] uuid16 = new byte[] { 35 0x0B, 0x11 }; 36 assertEquals(ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"), 37 BluetoothUuid.parseUuidFrom(uuid16)); 38 39 byte[] uuid32 = new byte[] { 40 0x0B, 0x11, 0x33, (byte) 0xFE }; 41 assertEquals(ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"), 42 BluetoothUuid.parseUuidFrom(uuid32)); 43 44 byte[] uuid128 = new byte[] { 45 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 46 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, (byte) 0xFF }; 47 assertEquals(ParcelUuid.fromString("FF0F0E0D-0C0B-0A09-0807-0060504030201"), 48 BluetoothUuid.parseUuidFrom(uuid128)); 49 } 50 51 @SmallTest 52 public void testUuidType() { 53 assertTrue(BluetoothUuid.is16BitUuid( 54 ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))); 55 assertFalse(BluetoothUuid.is32BitUuid( 56 ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))); 57 58 assertFalse(BluetoothUuid.is16BitUuid( 59 ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))); 60 assertTrue(BluetoothUuid.is32BitUuid( 61 ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))); 62 assertFalse(BluetoothUuid.is32BitUuid( 63 ParcelUuid.fromString("FE33110B-1000-1000-8000-00805F9B34FB"))); 64 65 } 66} 67