1 /*
2 * Copyright (C) 2023 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 <aidl/Gtest.h>
18 #include <aidl/Vintf.h>
19 #include <aidl/android/frameworks/location/altitude/AddMslAltitudeToLocationRequest.h>
20 #include <aidl/android/frameworks/location/altitude/AddMslAltitudeToLocationResponse.h>
21 #include <aidl/android/frameworks/location/altitude/IAltitudeService.h>
22 #include <android/binder_manager.h>
23 #include <android/binder_process.h>
24
25 using ::aidl::android::frameworks::location::altitude::AddMslAltitudeToLocationRequest;
26 using ::aidl::android::frameworks::location::altitude::AddMslAltitudeToLocationResponse;
27 using ::aidl::android::frameworks::location::altitude::IAltitudeService;
28 using ::android::getAidlHalInstanceNames;
29 using ::android::PrintInstanceNameToString;
30 using ndk::SpAIBinder;
31 using ::testing::Eq;
32 using ::testing::InitGoogleTest;
33 using ::testing::TestWithParam;
34 using ::testing::ValuesIn;
35
36 class AltitudeServiceTest : public TestWithParam<std::string> {
37 public:
SetUp()38 void SetUp() override {
39 SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
40 service = IAltitudeService::fromBinder(binder);
41 ASSERT_NE(service, nullptr);
42 }
43 std::shared_ptr<IAltitudeService> service;
44 };
45
TEST_P(AltitudeServiceTest,TestGetDistanceBasedExpiringGeoidHeight)46 TEST_P(AltitudeServiceTest, TestGetDistanceBasedExpiringGeoidHeight) {
47 // Test known location near Hawaii.
48 AddMslAltitudeToLocationRequest request;
49 request.latitudeDegrees = 19.545519;
50 request.longitudeDegrees = -155.998774;
51 request.altitudeMeters = -1;
52 request.verticalAccuracyMeters = 1;
53
54 AddMslAltitudeToLocationResponse response;
55 service->addMslAltitudeToLocation(request, &response);
56 ASSERT_NEAR(response.mslAltitudeMeters, -19.2359, 2);
57 ASSERT_NEAR(response.mslAltitudeAccuracyMeters, 1.05f, 0.5f);
58 }
59
60 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AltitudeServiceTest);
61 INSTANTIATE_TEST_SUITE_P(AltitudeService, AltitudeServiceTest,
62 ValuesIn(getAidlHalInstanceNames(IAltitudeService::descriptor)),
63 PrintInstanceNameToString);
64
main(int argc,char ** argv)65 int main(int argc, char** argv) {
66 InitGoogleTest(&argc, argv);
67 ABinderProcess_setThreadPoolMaxThreadCount(1);
68 ABinderProcess_startThreadPool();
69 return RUN_ALL_TESTS();
70 }
71