blob: 8c359c51a61dddc3174ee1f27cc2362d3787a469 [file] [log] [blame]
Amy Zhang45cc57a2020-07-09 22:56:25 -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 "FrontendTests.h"
18
19Return<void> FrontendCallback::onEvent(FrontendEventType /*frontendEventType*/) {
20 return Void();
21}
22
23Return<void> FrontendCallback::onScanMessage(FrontendScanMessageType /*type*/,
24 const FrontendScanMessage& /*message*/) {
25 return Void();
26}
27
28AssertionResult FrontendTests::getFrontendIds() {
29 Result status;
30 mService->getFrontendIds([&](Result result, const hidl_vec<FrontendId>& frontendIds) {
31 status = result;
32 mFeIds = frontendIds;
33 });
34 return AssertionResult(status == Result::SUCCESS);
35}
36
37AssertionResult FrontendTests::getFrontendInfo(uint32_t frontendId) {
38 Result status;
39 mService->getFrontendInfo(frontendId, [&](Result result, const FrontendInfo& frontendInfo) {
40 mFrontendInfo = frontendInfo;
41 status = result;
42 });
43 return AssertionResult(status == Result::SUCCESS);
44}
45
46AssertionResult FrontendTests::openFrontendById(uint32_t frontendId) {
47 Result status;
48 mService->openFrontendById(frontendId, [&](Result result, const sp<IFrontend>& frontend) {
49 mFrontend = frontend;
50 status = result;
51 });
52 return AssertionResult(status == Result::SUCCESS);
53}
54
55AssertionResult FrontendTests::setFrontendCallback() {
56 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
57 mFrontendCallback = new FrontendCallback();
58 auto callbackStatus = mFrontend->setCallback(mFrontendCallback);
59 return AssertionResult(callbackStatus.isOk());
60}
61
62AssertionResult FrontendTests::closeFrontend() {
63 EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
64 Result status;
65 status = mFrontend->close();
66 mFrontend = nullptr;
67 mFrontendCallback = nullptr;
68 return AssertionResult(status == Result::SUCCESS);
69}
70
71void FrontendTests::getFrontendIdByType(FrontendType feType, uint32_t& feId) {
72 ASSERT_TRUE(getFrontendIds());
73 ASSERT_TRUE(mFeIds.size() > 0);
74 for (size_t i = 0; i < mFeIds.size(); i++) {
75 ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
76 if (mFrontendInfo.type != feType) {
77 continue;
78 }
79 feId = mFeIds[i];
80 return;
81 }
82 feId = INVALID_ID;
83}