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.assertArrayEquals; 18 import static org.junit.Assert.assertEquals; 19 20 import androidx.test.ext.junit.runners.AndroidJUnit4; 21 import androidx.test.filters.SmallTest; 22 23 import com.google.uwb.support.dltdoa.DlTDoAMeasurement; 24 import com.google.uwb.support.dltdoa.DlTDoARangingRoundsUpdate; 25 import com.google.uwb.support.dltdoa.DlTDoARangingRoundsUpdateStatus; 26 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 30 @SmallTest 31 @RunWith(AndroidJUnit4.class) 32 public class DlTDoATests { 33 34 @Test dlTDoAMeasurementTest()35 public void dlTDoAMeasurementTest() { 36 int messageType = 0x02; 37 int messageControl = 0x513; 38 int blockIndex = 4; 39 int roundIndex = 6; 40 int nLoS = 40; 41 long txTimestamp = 40_000L; 42 long rxTimestamp = 50_000L; 43 float anchorCfo = 433.33f; 44 float cfo = 56.33f; 45 long initiatorReplyTime = 100; 46 long responderReplyTime = 200; 47 int initiatorResponderTof = 400; 48 byte[] anchorLocation = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; 49 byte[] activeRangingRounds = new byte[]{0x01, 0x02}; 50 51 DlTDoAMeasurement dlTDoAMeasurement = new DlTDoAMeasurement.Builder() 52 .setMessageType(messageType) 53 .setMessageControl(messageControl) 54 .setBlockIndex(blockIndex) 55 .setRoundIndex(roundIndex) 56 .setNLoS(nLoS) 57 .setTxTimestamp(txTimestamp) 58 .setRxTimestamp(rxTimestamp) 59 .setAnchorCfo(anchorCfo) 60 .setCfo(cfo) 61 .setInitiatorReplyTime(initiatorReplyTime) 62 .setResponderReplyTime(responderReplyTime) 63 .setInitiatorResponderTof(initiatorResponderTof) 64 .setAnchorLocation(anchorLocation) 65 .setActiveRangingRounds(activeRangingRounds) 66 .build(); 67 68 DlTDoAMeasurement fromBundle = DlTDoAMeasurement.fromBundle(dlTDoAMeasurement.toBundle()); 69 70 assertEquals(fromBundle.getMessageType(), messageType); 71 assertEquals(fromBundle.getMessageControl(), messageControl); 72 assertEquals(fromBundle.getBlockIndex(), blockIndex); 73 assertEquals(fromBundle.getRoundIndex(), roundIndex); 74 assertEquals(fromBundle.getNLoS(), nLoS); 75 assertEquals(fromBundle.getTxTimestamp(), txTimestamp); 76 assertEquals(fromBundle.getRxTimestamp(), rxTimestamp); 77 assertEquals(fromBundle.getAnchorCfo(), anchorCfo, 0.0); 78 assertEquals(fromBundle.getCfo(), cfo, 0.0); 79 assertEquals(fromBundle.getInitiatorReplyTime(), initiatorReplyTime); 80 assertEquals(fromBundle.getResponderReplyTime(), responderReplyTime); 81 assertEquals(fromBundle.getInitiatorResponderTof(), initiatorResponderTof); 82 assertArrayEquals(fromBundle.getAnchorLocation(), anchorLocation); 83 assertArrayEquals(fromBundle.getActiveRangingRounds(), activeRangingRounds); 84 } 85 86 @Test dlTDoARangingRoundsUpdateTest()87 public void dlTDoARangingRoundsUpdateTest() { 88 int sessionId = 1234; 89 int noOfActiveRangingRounds = 3; 90 byte[] rangingRoundIndexes = new byte[]{0x01, 0x02, 0x03}; 91 92 DlTDoARangingRoundsUpdate dlTDoARangingRoundsUpdate = new DlTDoARangingRoundsUpdate 93 .Builder() 94 .setSessionId(sessionId) 95 .setNoOfRangingRounds(noOfActiveRangingRounds) 96 .setRangingRoundIndexes(rangingRoundIndexes) 97 .build(); 98 99 DlTDoARangingRoundsUpdate fromBundle = DlTDoARangingRoundsUpdate.fromBundle( 100 dlTDoARangingRoundsUpdate.toBundle()); 101 102 assertEquals(fromBundle.getSessionId(), sessionId); 103 assertEquals(fromBundle.getNoOfRangingRounds(), noOfActiveRangingRounds); 104 assertArrayEquals(fromBundle.getRangingRoundIndexes(), rangingRoundIndexes); 105 } 106 107 @Test dlTDoARangingRoundsUpdateStatusTest()108 public void dlTDoARangingRoundsUpdateStatusTest() { 109 int status = 1; 110 int noOfActiveRangingRounds = 2; 111 byte[] rangingRoundIndexes = new byte[]{0x02, 0x03}; 112 113 DlTDoARangingRoundsUpdateStatus dlTDoARangingRoundsUpdateStatus = 114 new DlTDoARangingRoundsUpdateStatus.Builder() 115 .setStatus(status) 116 .setNoOfRangingRounds(noOfActiveRangingRounds) 117 .setRangingRoundIndexes(rangingRoundIndexes) 118 .build(); 119 120 DlTDoARangingRoundsUpdateStatus fromBundle = DlTDoARangingRoundsUpdateStatus.fromBundle( 121 dlTDoARangingRoundsUpdateStatus.toBundle()); 122 123 assertEquals(fromBundle.getStatus(), status); 124 assertEquals(fromBundle.getNoOfRangingRounds(), noOfActiveRangingRounds); 125 assertArrayEquals(fromBundle.getRangingRoundIndexes(), rangingRoundIndexes); 126 } 127 } 128