1 /*
2  * Copyright (C) 2022 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 import static org.junit.Assert.assertEquals;
18 
19 import android.os.PersistableBundle;
20 
21 import androidx.test.ext.junit.runners.AndroidJUnit4;
22 import androidx.test.filters.SmallTest;
23 
24 import com.google.uwb.support.multichip.ChipInfoParams;
25 
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 @SmallTest
30 @RunWith(AndroidJUnit4.class)
31 public class MultichipTests {
32 
33     @Test
testChipInfoParams()34     public void testChipInfoParams() {
35         String chipId = "testChipId";
36         double positionX = 1.0;
37         double positionY = 2.0;
38         double positionZ = 3.0;
39 
40         // Use Builder to build chipInfoParams
41         ChipInfoParams chipInfoParams = ChipInfoParams.createBuilder().setChipId(chipId)
42                 .setPositionX(positionX).setPositionY(positionY).setPositionZ(positionZ).build();
43 
44         assertEquals(chipInfoParams.getChipId(), chipId);
45         assertEquals(chipInfoParams.getPositionX(), positionX, 0);
46         assertEquals(chipInfoParams.getPositionY(), positionY, 0);
47         assertEquals(chipInfoParams.getPositionZ(), positionZ, 0);
48 
49         // Convert to and from PersistableBundle
50         PersistableBundle bundle = chipInfoParams.toBundle();
51         ChipInfoParams fromBundle = ChipInfoParams.fromBundle(bundle);
52 
53         assertEquals(fromBundle.getChipId(), chipId);
54         assertEquals(fromBundle.getPositionX(), positionX, 0);
55         assertEquals(fromBundle.getPositionY(), positionY, 0);
56         assertEquals(fromBundle.getPositionZ(), positionZ, 0);
57     }
58 
59     @Test
testChipInfoParamsDefaults()60     public void testChipInfoParamsDefaults() {
61         ChipInfoParams chipInfoParams = ChipInfoParams.createBuilder().build();
62 
63         assertEquals(chipInfoParams.getChipId(), "UNKNOWN_CHIP_ID");
64         assertEquals(chipInfoParams.getPositionX(), 0.0, 0);
65         assertEquals(chipInfoParams.getPositionY(), 0.0, 0);
66         assertEquals(chipInfoParams.getPositionZ(), 0.0, 0);
67     }
68 }
69