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 #define INVALID_LNB_ID -1
29 
30 using android::Condition;
31 using android::Mutex;
32 
33 using ::testing::AssertionResult;
34 
35 using namespace aidl::android::hardware::tv::tuner;
36 using namespace std;
37 
38 class LnbCallback : public BnLnbCallback {
39   public:
40     virtual ::ndk::ScopedAStatus onEvent(LnbEventType lnbEventType) override;
41     virtual ::ndk::ScopedAStatus onDiseqcMessage(
42             const std::vector<uint8_t>& diseqcMessage) override;
43 
44   private:
45     bool mEventReceived = false;
46     android::Mutex mMsgLock;
47     android::Condition mMsgCondition;
48 };
49 
50 class LnbTests {
51   public:
setService(std::shared_ptr<ITuner> tuner)52     void setService(std::shared_ptr<ITuner> tuner) { mService = tuner; }
53 
54     AssertionResult getLnbIds(vector<int32_t>& ids);
55     AssertionResult openLnbById(int32_t lnbId);
56     AssertionResult openLnbByName(string lnbName, int32_t& lnbId);
57     AssertionResult setLnbCallback();
58     AssertionResult setVoltage(LnbVoltage voltage);
59     AssertionResult setTone(LnbTone tone);
60     AssertionResult setSatellitePosition(LnbPosition position);
61     AssertionResult sendDiseqcMessage(vector<uint8_t> diseqcMsg);
62     AssertionResult closeLnb();
63 
64   protected:
failure()65     static AssertionResult failure() { return ::testing::AssertionFailure(); }
66 
success()67     static AssertionResult success() { return ::testing::AssertionSuccess(); }
68 
69     std::shared_ptr<ITuner> mService;
70     std::shared_ptr<ILnb> mLnb;
71     std::shared_ptr<LnbCallback> mLnbCallback;
72     vector<int32_t> mLnbIds;
73 };
74