blob: 12f48c3a2cf9aaeef9fa8979abac00f26e9d8829 [file] [log] [blame]
Venkatarama Avadhani90373fe2022-11-11 16:54:53 +05301/*
2 * Copyright (C) 2022 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 "EArc_hal_test"
18
19#include <aidl/Gtest.h>
20#include <aidl/Vintf.h>
21#include <aidl/android/hardware/tv/earc/BnEArcCallback.h>
22#include <aidl/android/hardware/tv/earc/IEArc.h>
23#include <aidl/android/hardware/tv/earc/IEArcStatus.h>
24#include <android-base/logging.h>
25#include <android/binder_manager.h>
26#include <android/binder_process.h>
27#include <gtest/gtest.h>
28#include <log/log.h>
29#include <sstream>
30#include <vector>
31
32using ::aidl::android::hardware::tv::earc::BnEArcCallback;
33using ::aidl::android::hardware::tv::earc::IEArc;
34using ::aidl::android::hardware::tv::earc::IEArcCallback;
35using ::aidl::android::hardware::tv::earc::IEArcStatus;
36using ::ndk::SpAIBinder;
37
38// The main test class for TV EARC HAL.
39class EArcTest : public ::testing::TestWithParam<std::string> {
40 static void serviceDied(void* /* cookie */) { ALOGE("VtsHalTvCecAidlTargetTest died"); }
41
42 public:
43 void SetUp() override {
44 eArc = IEArc::fromBinder(SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
45 ASSERT_NE(eArc, nullptr);
46 ALOGI("%s: getService() for eArc is %s", __func__, eArc->isRemote() ? "remote" : "local");
47
48 eArcCallback = ::ndk::SharedRefBase::make<EArcCallback>();
49 ASSERT_NE(eArcCallback, nullptr);
50 eArcDeathRecipient =
51 ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(&serviceDied));
52 ASSERT_EQ(AIBinder_linkToDeath(eArc->asBinder().get(), eArcDeathRecipient.get(), 0),
53 STATUS_OK);
54 }
55
56 class EArcCallback : public BnEArcCallback {
57 public:
58 ::ndk::ScopedAStatus onStateChange(IEArcStatus connected __unused,
59 int32_t portId __unused) {
60 return ::ndk::ScopedAStatus::ok();
61 };
62 ::ndk::ScopedAStatus onCapabilitiesReported(
63 const std::vector<uint8_t>& capabilities __unused, int32_t portId __unused) {
64 return ::ndk::ScopedAStatus::ok();
65 };
66 };
67
68 std::shared_ptr<IEArc> eArc;
69 std::shared_ptr<IEArcCallback> eArcCallback;
70 ::ndk::ScopedAIBinder_DeathRecipient eArcDeathRecipient;
71};
72
73GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EArcTest);
74INSTANTIATE_TEST_SUITE_P(PerInstance, EArcTest,
75 testing::ValuesIn(android::getAidlHalInstanceNames(IEArc::descriptor)),
76 android::PrintInstanceNameToString);
77
78TEST_P(EArcTest, setGetEArcEnabled) {
79 bool initial_state;
80 bool changed_state;
81 ASSERT_TRUE(eArc->isEArcEnabled(&initial_state).isOk());
82 ASSERT_TRUE(eArc->setEArcEnabled(!initial_state).isOk());
83 ASSERT_TRUE(eArc->isEArcEnabled(&changed_state).isOk());
84 ASSERT_TRUE(initial_state != changed_state);
85 ASSERT_TRUE(eArc->setEArcEnabled(initial_state).isOk());
86}
87
88TEST_P(EArcTest, SetCallback) {
89 ASSERT_TRUE(eArc->setCallback(eArcCallback).isOk());
90}
91
92TEST_P(EArcTest, GetState) {
93 IEArcStatus connectionStatus;
94 ASSERT_TRUE(eArc->getState(1, &connectionStatus).isOk());
95}
96
97TEST_P(EArcTest, GetLastReportedAudioCapabilities) {
98 std::vector<uint8_t> capabilities;
99 ASSERT_TRUE(eArc->getLastReportedAudioCapabilities(1, &capabilities).isOk());
100}