1 /* 2 * Copyright (C) 2016 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.location.cts; 18 19 import android.location.GnssMeasurement; 20 import android.location.GnssStatus; 21 import android.os.Parcel; 22 23 public class GnssMeasurementTest extends GnssTestCase { 24 public void testDescribeContents() { 25 GnssMeasurement measurement = new GnssMeasurement(); 26 measurement.describeContents(); 27 } 28 29 public void testReset() { 30 GnssMeasurement measurement = new GnssMeasurement(); 31 measurement.reset(); 32 } 33 34 private static void setTestValues(GnssMeasurement measurement) { 35 measurement.setAccumulatedDeltaRangeMeters(1.0); 36 measurement.setAccumulatedDeltaRangeState(2); 37 measurement.setAccumulatedDeltaRangeUncertaintyMeters(3.0); 38 measurement.setCarrierCycles(4); 39 measurement.setCarrierFrequencyHz(5.0f); 40 measurement.setCarrierPhase(6.0); 41 measurement.setCarrierPhaseUncertainty(7.0); 42 measurement.setCn0DbHz(8.0); 43 measurement.setCodeType("C"); 44 measurement.setConstellationType(GnssStatus.CONSTELLATION_GALILEO); 45 measurement.setMultipathIndicator(GnssMeasurement.MULTIPATH_INDICATOR_DETECTED); 46 measurement.setPseudorangeRateMetersPerSecond(9.0); 47 measurement.setPseudorangeRateUncertaintyMetersPerSecond(10.0); 48 measurement.setReceivedSvTimeNanos(11); 49 measurement.setReceivedSvTimeUncertaintyNanos(12); 50 measurement.setSnrInDb(13.0); 51 measurement.setState(14); 52 measurement.setSvid(15); 53 measurement.setTimeOffsetNanos(16.0); 54 } 55 56 private static void verifyTestValues(GnssMeasurement measurement) { 57 assertEquals(1.0, measurement.getAccumulatedDeltaRangeMeters()); 58 assertEquals(2, measurement.getAccumulatedDeltaRangeState()); 59 assertEquals(3.0, measurement.getAccumulatedDeltaRangeUncertaintyMeters()); 60 assertEquals(4, measurement.getCarrierCycles()); 61 assertEquals(5.0f, measurement.getCarrierFrequencyHz()); 62 assertEquals(6.0, measurement.getCarrierPhase()); 63 assertEquals(7.0, measurement.getCarrierPhaseUncertainty()); 64 assertEquals(8.0, measurement.getCn0DbHz()); 65 assertEquals(GnssStatus.CONSTELLATION_GALILEO, measurement.getConstellationType()); 66 assertEquals(GnssMeasurement.MULTIPATH_INDICATOR_DETECTED, 67 measurement.getMultipathIndicator()); 68 assertEquals("C", measurement.getCodeType()); 69 assertEquals(9.0, measurement.getPseudorangeRateMetersPerSecond()); 70 assertEquals(10.0, measurement.getPseudorangeRateUncertaintyMetersPerSecond()); 71 assertEquals(11, measurement.getReceivedSvTimeNanos()); 72 assertEquals(12, measurement.getReceivedSvTimeUncertaintyNanos()); 73 assertEquals(13.0, measurement.getSnrInDb()); 74 assertEquals(14, measurement.getState()); 75 assertEquals(15, measurement.getSvid()); 76 assertEquals(16.0, measurement.getTimeOffsetNanos()); 77 } 78 79 public void testWriteToParcel() { 80 GnssMeasurement measurement = new GnssMeasurement(); 81 setTestValues(measurement); 82 Parcel parcel = Parcel.obtain(); 83 measurement.writeToParcel(parcel, 0); 84 parcel.setDataPosition(0); 85 GnssMeasurement newMeasurement = GnssMeasurement.CREATOR.createFromParcel(parcel); 86 verifyTestValues(newMeasurement); 87 parcel.recycle(); 88 } 89 90 public void testSet() { 91 GnssMeasurement measurement = new GnssMeasurement(); 92 setTestValues(measurement); 93 GnssMeasurement newMeasurement = new GnssMeasurement(); 94 newMeasurement.set(measurement); 95 verifyTestValues(newMeasurement); 96 } 97 98 public void testSetReset() { 99 GnssMeasurement measurement = new GnssMeasurement(); 100 setTestValues(measurement); 101 102 assertTrue(measurement.hasCarrierCycles()); 103 measurement.resetCarrierCycles(); 104 assertFalse(measurement.hasCarrierCycles()); 105 106 assertTrue(measurement.hasCarrierFrequencyHz()); 107 measurement.resetCarrierFrequencyHz(); 108 assertFalse(measurement.hasCarrierFrequencyHz()); 109 110 assertTrue(measurement.hasCarrierPhase()); 111 measurement.resetCarrierPhase(); 112 assertFalse(measurement.hasCarrierPhase()); 113 114 assertTrue(measurement.hasCarrierPhaseUncertainty()); 115 measurement.resetCarrierPhaseUncertainty(); 116 assertFalse(measurement.hasCarrierPhaseUncertainty()); 117 118 assertTrue(measurement.hasSnrInDb()); 119 measurement.resetSnrInDb(); 120 assertFalse(measurement.hasSnrInDb()); 121 122 assertTrue(measurement.hasCodeType()); 123 measurement.resetCodeType(); 124 assertFalse(measurement.hasCodeType()); 125 } 126 } 127