Yu-Han Yang | 274ea0a | 2020-09-09 17:25:02 -0700 | [diff] [blame] | 1 | /* |
| 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 | #include <aidl/Gtest.h> |
| 17 | #include <aidl/Vintf.h> |
| 18 | |
| 19 | #include <android/hardware/gnss/IGnss.h> |
| 20 | #include <android/hardware/gnss/IGnssPsds.h> |
| 21 | #include <binder/IServiceManager.h> |
| 22 | #include <binder/ProcessState.h> |
| 23 | |
| 24 | using android::ProcessState; |
| 25 | using android::sp; |
| 26 | using android::String16; |
| 27 | using android::binder::Status; |
| 28 | using android::hardware::gnss::IGnss; |
| 29 | using android::hardware::gnss::IGnssPsds; |
| 30 | using android::hardware::gnss::PsdsType; |
| 31 | |
| 32 | class GnssAidlHalTest : public testing::TestWithParam<std::string> { |
| 33 | public: |
| 34 | virtual void SetUp() override { |
| 35 | gnss_hal_ = android::waitForDeclaredService<IGnss>(String16(GetParam().c_str())); |
| 36 | ASSERT_NE(gnss_hal_, nullptr); |
| 37 | } |
| 38 | |
| 39 | sp<IGnss> gnss_hal_; |
| 40 | }; |
| 41 | |
| 42 | /* |
| 43 | * SetupTeardownCreateCleanup: |
| 44 | * Requests the gnss HAL then calls cleanup |
| 45 | * |
| 46 | * Empty test fixture to verify basic Setup & Teardown |
| 47 | */ |
| 48 | TEST_P(GnssAidlHalTest, SetupTeardownCreateCleanup) {} |
| 49 | |
| 50 | /* |
| 51 | * TestPsdsExtension: |
| 52 | * 1. Gets the PsdsExtension and verifies that it returns a non-null extension. |
| 53 | * 2. Injects empty PSDS data and verifies that it returns false. |
| 54 | */ |
| 55 | TEST_P(GnssAidlHalTest, TestPsdsExtension) { |
| 56 | sp<IGnssPsds> iGnssPsds; |
| 57 | auto status = gnss_hal_->getExtensionPsds(&iGnssPsds); |
| 58 | ASSERT_TRUE(status.isOk()); |
| 59 | ASSERT_TRUE(iGnssPsds != nullptr); |
| 60 | |
| 61 | bool success; |
| 62 | status = iGnssPsds->injectPsdsData(PsdsType::LONG_TERM, std::vector<uint8_t>(), &success); |
| 63 | ASSERT_TRUE(status.isOk()); |
| 64 | ASSERT_FALSE(success); |
| 65 | } |
| 66 | |
| 67 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GnssAidlHalTest); |
| 68 | INSTANTIATE_TEST_SUITE_P(, GnssAidlHalTest, |
| 69 | testing::ValuesIn(android::getAidlHalInstanceNames(IGnss::descriptor)), |
| 70 | android::PrintInstanceNameToString); |
| 71 | |
| 72 | int main(int argc, char** argv) { |
| 73 | ::testing::InitGoogleTest(&argc, argv); |
| 74 | ProcessState::self()->setThreadPoolMaxThreadCount(1); |
| 75 | ProcessState::self()->startThreadPool(); |
| 76 | return RUN_ALL_TESTS(); |
| 77 | } |