Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2024 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 | #define LOG_TAG "ambient_intelligence_light_aidl_hal_test" |
| 18 | |
| 19 | #include <aidl/Gtest.h> |
| 20 | #include <aidl/Vintf.h> |
| 21 | #include <android/hardware/tv/mediaquality/IMediaQuality.h> |
| 22 | #include <binder/IServiceManager.h> |
| 23 | #include <binder/ProcessState.h> |
| 24 | #include <gtest/gtest.h> |
| 25 | #include <hidl/GtestPrinter.h> |
| 26 | #include <hidl/ServiceManagement.h> |
| 27 | |
| 28 | using android::ProcessState; |
| 29 | using android::sp; |
| 30 | using android::String16; |
| 31 | using android::binder::Status; |
| 32 | using android::hardware::hidl_vec; |
| 33 | using android::hardware::Return; |
| 34 | using android::hardware::Void; |
| 35 | using android::hardware::tv::mediaquality::IMediaQuality; |
| 36 | |
| 37 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 38 | #define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk()) |
| 39 | |
| 40 | class MediaQualityAidl : public testing::TestWithParam<std::string> { |
| 41 | public: |
| 42 | void SetUp() override { |
| 43 | mediaquality = android::waitForDeclaredService<IMediaQuality>(String16(GetParam().c_str())); |
| 44 | ASSERT_NE(mediaquality, nullptr); |
| 45 | } |
| 46 | |
| 47 | sp<IMediaQuality> mediaquality; |
| 48 | |
| 49 | void TearDown() override {} |
| 50 | }; |
| 51 | |
| 52 | TEST_P(MediaQualityAidl, TestSetAmbientLightDetectionEnabled) { |
| 53 | ASSERT_OK(mediaquality->setAmbientLightDetectionEnabled(true)); |
| 54 | } |
| 55 | |
| 56 | TEST_P(MediaQualityAidl, TestGetAmbientLightDetectionEnabled) { |
| 57 | bool enabled; |
| 58 | Status status = mediaquality->getAmbientLightDetectionEnabled(&enabled); |
| 59 | ASSERT_TRUE(status.isOk()); |
| 60 | ASSERT_TRUE(enabled); |
| 61 | } |
| 62 | |
| 63 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MediaQualityAidl); |
| 64 | |
| 65 | INSTANTIATE_TEST_SUITE_P( |
| 66 | PerInstance, MediaQualityAidl, |
| 67 | testing::ValuesIn(android::getAidlHalInstanceNames(IMediaQuality::descriptor)), |
| 68 | android::PrintInstanceNameToString); |
| 69 | |
| 70 | int main(int argc, char** argv) { |
| 71 | ::testing::InitGoogleTest(&argc, argv); |
| 72 | ProcessState::self()->setThreadPoolMaxThreadCount(1); |
| 73 | ProcessState::self()->startThreadPool(); |
| 74 | return RUN_ALL_TESTS(); |
| 75 | } |