blob: 3527625ae6c78b8e1250b0b6d09b88a57b90f43d [file] [log] [blame]
Devin Moore0de7ad62021-11-05 17:30:04 +00001/*
2 * Copyright (C) 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#define LOG_TAG "ir_aidl_hal_test"
18
19#include <aidl/Gtest.h>
20#include <aidl/Vintf.h>
21#include <aidl/android/hardware/ir/IConsumerIr.h>
22#include <android-base/logging.h>
23#include <android/binder_auto_utils.h>
24#include <android/binder_manager.h>
25#include <gtest/gtest.h>
26#include <algorithm>
27#include <vector>
28
29using ::aidl::android::hardware::ir::ConsumerIrFreqRange;
30using ::aidl::android::hardware::ir::IConsumerIr;
31using ::ndk::SpAIBinder;
32
33class ConsumerIrTest : public ::testing::TestWithParam<std::string> {
34 public:
35 virtual void SetUp() override {
36 mIr = IConsumerIr::fromBinder(
37 SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
38 ASSERT_NE(mIr, nullptr);
39 }
40
41 std::shared_ptr<IConsumerIr> mIr;
42};
43
44// Test transmit() for the min and max frequency of every available range
45TEST_P(ConsumerIrTest, TransmitTest) {
46 std::vector<ConsumerIrFreqRange> ranges;
47 const auto& ret = mIr->getCarrierFreqs(&ranges);
48 ASSERT_TRUE(ret.isOk());
49
50 if (ranges.size() > 0) {
51 uint32_t len = 16;
52 std::vector<int32_t> vec;
53 vec.resize(len);
54 std::fill(vec.begin(), vec.end(), 1000);
55 for (auto range = ranges.begin(); range != ranges.end(); range++) {
56 EXPECT_TRUE(mIr->transmit(range->minHz, vec).isOk());
57 EXPECT_TRUE(mIr->transmit(range->maxHz, vec).isOk());
58 }
59 }
60}
61
62// Test transmit() when called with invalid frequencies
63TEST_P(ConsumerIrTest, BadFreqTest) {
64 uint32_t len = 16;
65 std::vector<int32_t> vec;
66 vec.resize(len);
67 std::fill(vec.begin(), vec.end(), 1);
68 const auto& res = mIr->transmit(-1, vec);
69 EXPECT_FALSE(res.isOk());
70 EXPECT_EQ(res.getExceptionCode(), EX_UNSUPPORTED_OPERATION);
71}
72
73GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ConsumerIrTest);
74INSTANTIATE_TEST_SUITE_P(
75 PerInstance, ConsumerIrTest,
76 testing::ValuesIn(android::getAidlHalInstanceNames(IConsumerIr::descriptor)),
77 ::android::PrintInstanceNameToString);