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 
17 package android.bluetooth;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.os.ParcelUuid;
22 
23 import com.google.common.truth.Expect;
24 
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.JUnit4;
29 
30 /** Unit test cases for {@link BluetoothUuid}. */
31 @RunWith(JUnit4.class)
32 public class BluetoothUuidTest {
33 
34     @Rule public Expect expect = Expect.create();
35 
36     @Test
testUuid16Parser()37     public void testUuid16Parser() {
38         byte[] uuid16 = new byte[] {0x0B, 0x11};
39         assertThat(BluetoothUuid.parseUuidFrom(uuid16))
40                 .isEqualTo(ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"));
41     }
42 
43     @Test
testUuid32Parser()44     public void testUuid32Parser() {
45         byte[] uuid32 = new byte[] {0x0B, 0x11, 0x33, (byte) 0xFE};
46         assertThat(BluetoothUuid.parseUuidFrom(uuid32))
47                 .isEqualTo(ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"));
48     }
49 
50     @Test
testUuid128Parser()51     public void testUuid128Parser() {
52         byte[] uuid128 =
53                 new byte[] {
54                     0x01,
55                     0x02,
56                     0x03,
57                     0x04,
58                     0x05,
59                     0x06,
60                     0x07,
61                     0x08,
62                     0x09,
63                     0x0A,
64                     0x0B,
65                     0x0C,
66                     0x0D,
67                     0x0E,
68                     0x0F,
69                     (byte) 0xFF
70                 };
71         assertThat(BluetoothUuid.parseUuidFrom(uuid128))
72                 .isEqualTo(ParcelUuid.fromString("FF0F0E0D-0C0B-0A09-0807-060504030201"));
73     }
74 
75     @Test
testUuidType()76     public void testUuidType() {
77         expect.that(
78                         BluetoothUuid.is16BitUuid(
79                                 ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB")))
80                 .isTrue();
81         expect.that(
82                         BluetoothUuid.is32BitUuid(
83                                 ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB")))
84                 .isFalse();
85         expect.that(
86                         BluetoothUuid.is16BitUuid(
87                                 ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB")))
88                 .isFalse();
89         expect.that(
90                         BluetoothUuid.is32BitUuid(
91                                 ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB")))
92                 .isTrue();
93         expect.that(
94                         BluetoothUuid.is32BitUuid(
95                                 ParcelUuid.fromString("FE33110B-1000-1000-8000-00805F9B34FB")))
96                 .isFalse();
97     }
98 }
99