blob: 2fdbe2ce260ab05c549bdab0ce3b38889410bef7 [file] [log] [blame]
Amy Zhange5a9da22020-06-01 19:12:29 -07001/*
2 * Copyright 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 <android-base/logging.h>
18#include <android/hardware/tv/tuner/1.0/ILnb.h>
19#include <android/hardware/tv/tuner/1.0/ITuner.h>
20#include <android/hardware/tv/tuner/1.0/types.h>
21#include <gtest/gtest.h>
22#include <hidl/HidlSupport.h>
23#include <hidl/HidlTransportSupport.h>
24#include <hidl/ServiceManagement.h>
25#include <hidl/Status.h>
26#include <hidlmemory/FrameworkUtils.h>
27#include <utils/Condition.h>
28#include <utils/Mutex.h>
29#include <map>
30
31using android::Condition;
32using android::Mutex;
33using android::sp;
34using android::hardware::hidl_vec;
35using android::hardware::Return;
36using android::hardware::Void;
37using android::hardware::tv::tuner::V1_0::ILnb;
38using android::hardware::tv::tuner::V1_0::ILnbCallback;
39using android::hardware::tv::tuner::V1_0::ITuner;
40using android::hardware::tv::tuner::V1_0::LnbEventType;
41using android::hardware::tv::tuner::V1_0::LnbPosition;
42using android::hardware::tv::tuner::V1_0::LnbTone;
43using android::hardware::tv::tuner::V1_0::LnbVoltage;
44using android::hardware::tv::tuner::V1_0::Result;
45
46using ::testing::AssertionResult;
47
48using namespace std;
49
50class LnbCallback : public ILnbCallback {
51 public:
52 virtual Return<void> onEvent(LnbEventType lnbEventType) override;
53 virtual Return<void> onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) override;
54
55 private:
56 bool mEventReceived = false;
57 android::Mutex mMsgLock;
58 android::Condition mMsgCondition;
59};
60
61class LnbTests {
62 public:
63 void setService(sp<ITuner> tuner) { mService = tuner; }
64
65 AssertionResult getLnbIds(vector<uint32_t>& ids);
66 AssertionResult openLnbById(uint32_t lnbId);
67 AssertionResult openLnbByName(string lnbName);
68 AssertionResult setLnbCallback();
69 AssertionResult setVoltage(LnbVoltage voltage);
70 AssertionResult setTone(LnbTone tone);
71 AssertionResult setSatellitePosition(LnbPosition position);
72 AssertionResult sendDiseqcMessage(vector<uint8_t> diseqcMsg);
73 AssertionResult closeLnb();
74
75 protected:
76 static AssertionResult failure() { return ::testing::AssertionFailure(); }
77
78 static AssertionResult success() { return ::testing::AssertionSuccess(); }
79
80 sp<ITuner> mService;
81 sp<ILnb> mLnb;
82 sp<LnbCallback> mLnbCallback;
83 hidl_vec<uint32_t> mLnbIds;
84};