Hongguang | 600a6ae | 2021-07-08 18:51:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 | #pragma once |
| 18 | |
| 19 | #include <aidl/android/hardware/tv/tuner/BnLnbCallback.h> |
| 20 | #include <aidl/android/hardware/tv/tuner/ILnb.h> |
| 21 | #include <aidl/android/hardware/tv/tuner/ITuner.h> |
| 22 | #include <gtest/gtest.h> |
| 23 | #include <log/log.h> |
| 24 | #include <utils/Condition.h> |
| 25 | #include <utils/Mutex.h> |
| 26 | #include <map> |
| 27 | |
| 28 | using android::Condition; |
| 29 | using android::Mutex; |
| 30 | |
| 31 | using ::testing::AssertionResult; |
| 32 | |
| 33 | using namespace aidl::android::hardware::tv::tuner; |
| 34 | using namespace std; |
| 35 | |
| 36 | class LnbCallback : public BnLnbCallback { |
| 37 | public: |
| 38 | virtual ::ndk::ScopedAStatus onEvent(LnbEventType lnbEventType) override; |
| 39 | virtual ::ndk::ScopedAStatus onDiseqcMessage( |
| 40 | const std::vector<uint8_t>& diseqcMessage) override; |
| 41 | |
| 42 | private: |
| 43 | bool mEventReceived = false; |
| 44 | android::Mutex mMsgLock; |
| 45 | android::Condition mMsgCondition; |
| 46 | }; |
| 47 | |
| 48 | class LnbTests { |
| 49 | public: |
| 50 | void setService(std::shared_ptr<ITuner> tuner) { mService = tuner; } |
| 51 | |
| 52 | AssertionResult getLnbIds(vector<int32_t>& ids); |
| 53 | AssertionResult openLnbById(int32_t lnbId); |
| 54 | AssertionResult openLnbByName(string lnbName, int32_t& lnbId); |
| 55 | AssertionResult setLnbCallback(); |
| 56 | AssertionResult setVoltage(LnbVoltage voltage); |
| 57 | AssertionResult setTone(LnbTone tone); |
| 58 | AssertionResult setSatellitePosition(LnbPosition position); |
| 59 | AssertionResult sendDiseqcMessage(vector<uint8_t> diseqcMsg); |
| 60 | AssertionResult closeLnb(); |
| 61 | |
| 62 | protected: |
| 63 | static AssertionResult failure() { return ::testing::AssertionFailure(); } |
| 64 | |
| 65 | static AssertionResult success() { return ::testing::AssertionSuccess(); } |
| 66 | |
| 67 | std::shared_ptr<ITuner> mService; |
| 68 | std::shared_ptr<ILnb> mLnb; |
| 69 | std::shared_ptr<LnbCallback> mLnbCallback; |
| 70 | vector<int32_t> mLnbIds; |
| 71 | }; |