blob: 2447bf8c84bb8bf4b306a0687229daa169f42751 [file] [log] [blame]
Yu-Han Yang1e1a6762020-09-30 17:01:53 -07001/*
2 * Copyright (C) 2020 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 "gnss_hal_test.h"
18#include <hidl/ServiceManagement.h>
19
20using GnssConstellationTypeAidl = android::hardware::gnss::GnssConstellationType;
21
22void GnssHalTest::SetUp() {
23 // Get AIDL handle
24 aidl_gnss_hal_ = android::waitForDeclaredService<IGnssAidl>(String16(GetParam().c_str()));
25 ASSERT_NE(aidl_gnss_hal_, nullptr);
26
27 const auto& hidlInstanceNames = android::hardware::getAllHalInstanceNames(
28 android::hardware::gnss::V2_1::IGnss::descriptor);
29 gnss_hal_ = IGnss_V2_1::getService(hidlInstanceNames[0]);
30 ASSERT_NE(gnss_hal_, nullptr);
31
32 SetUpGnssCallback();
33}
34
35void GnssHalTest::SetUpGnssCallback() {
36 aidl_gnss_cb_ = new GnssCallbackAidl();
37 ASSERT_NE(aidl_gnss_cb_, nullptr);
38
39 auto status = aidl_gnss_hal_->setCallback(aidl_gnss_cb_);
40 if (!status.isOk()) {
41 ALOGE("Failed to setCallback");
42 }
43
44 ASSERT_TRUE(status.isOk());
45
46 /*
47 * Capabilities callback should trigger.
48 */
49 EXPECT_TRUE(aidl_gnss_cb_->capabilities_cbq_.retrieve(aidl_gnss_cb_->last_capabilities_,
50 TIMEOUT_SEC));
51
52 EXPECT_EQ(aidl_gnss_cb_->capabilities_cbq_.calledCount(), 1);
53
54 // Invoke the super method.
55 GnssHalTestTemplate<IGnss_V2_1>::SetUpGnssCallback();
56}