blob: 24d68839a8d0f870093e83e8fae5311af7034fc2 [file] [log] [blame]
Yu-Han Yanga5098612019-02-08 16:22:07 -08001/*
2 * Copyright (C) 2019 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#include <Utils.h>
18#include "gtest/gtest.h"
19
20namespace android {
21namespace hardware {
22namespace gnss {
23namespace common {
24
25using V1_0::GnssLocationFlags;
26
27void Utils::checkLocation(const GnssLocation& location, bool check_speed,
28 bool check_more_accuracies) {
29 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
30 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
31 if (check_speed) {
32 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
33 }
34 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
35 // New uncertainties available in O must be provided,
36 // at least when paired with modern hardware (2017+)
37 if (check_more_accuracies) {
38 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
39 if (check_speed) {
40 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
41 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
42 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
43 }
44 }
45 }
46 EXPECT_GE(location.latitudeDegrees, -90.0);
47 EXPECT_LE(location.latitudeDegrees, 90.0);
48 EXPECT_GE(location.longitudeDegrees, -180.0);
49 EXPECT_LE(location.longitudeDegrees, 180.0);
50 EXPECT_GE(location.altitudeMeters, -1000.0);
51 EXPECT_LE(location.altitudeMeters, 30000.0);
52 if (check_speed) {
53 EXPECT_GE(location.speedMetersPerSec, 0.0);
54 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
55
56 // Non-zero speeds must be reported with an associated bearing
57 if (location.speedMetersPerSec > 0.0) {
58 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
59 }
60 }
61
62 /*
63 * Tolerating some especially high values for accuracy estimate, in case of
64 * first fix with especially poor geometry (happens occasionally)
65 */
66 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
67 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
68
69 /*
70 * Some devices may define bearing as -180 to +180, others as 0 to 360.
71 * Both are okay & understandable.
72 */
73 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
74 EXPECT_GE(location.bearingDegrees, -180.0);
75 EXPECT_LE(location.bearingDegrees, 360.0);
76 }
77 if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
78 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
79 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
80 }
81 if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
82 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
83 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
84 }
85 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
86 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
87 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
88 }
89
90 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
91 EXPECT_GT(location.timestamp, 1.48e12);
92}
93
94} // namespace common
95} // namespace gnss
96} // namespace hardware
97} // namespace android