1 /*
2 * Copyright (C) 2016 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_hidl_hal_test"
18
19 #include <android-base/logging.h>
20
21 #include <android/hardware/ir/1.0/IConsumerIr.h>
22 #include <android/hardware/ir/1.0/types.h>
23
24 #include <gtest/gtest.h>
25 #include <hidl/GtestPrinter.h>
26 #include <hidl/ServiceManagement.h>
27 #include <algorithm>
28
29 using ::android::hardware::ir::V1_0::IConsumerIr;
30 using ::android::hardware::ir::V1_0::ConsumerIrFreqRange;
31 using ::android::hardware::hidl_vec;
32 using ::android::hardware::Return;
33 using ::android::sp;
34
35 class ConsumerIrHidlTest : public ::testing::TestWithParam<std::string> {
36 public:
SetUp()37 virtual void SetUp() override {
38 ir = IConsumerIr::getService(GetParam());
39 ASSERT_NE(ir, nullptr);
40 }
41
TearDown()42 virtual void TearDown() override {}
43
44 sp<IConsumerIr> ir;
45 };
46
47 // Test transmit() for the min and max frequency of every available range
TEST_P(ConsumerIrHidlTest,TransmitTest)48 TEST_P(ConsumerIrHidlTest, TransmitTest) {
49 bool success;
50 hidl_vec<ConsumerIrFreqRange> ranges;
51 auto cb = [&](bool s, hidl_vec<ConsumerIrFreqRange> v) {
52 ranges = v;
53 success = s;
54 };
55 Return<void> ret = ir->getCarrierFreqs(cb);
56 ASSERT_TRUE(ret.isOk());
57 ASSERT_TRUE(success);
58
59 if (ranges.size() > 0) {
60 uint32_t len = 16;
61 hidl_vec<int32_t> vec;
62 vec.resize(len);
63 std::fill(vec.begin(), vec.end(), 1000);
64 for (auto range = ranges.begin(); range != ranges.end(); range++) {
65 EXPECT_TRUE(ir->transmit(range->min, vec));
66 EXPECT_TRUE(ir->transmit(range->max, vec));
67 }
68 }
69 }
70
71 // Test transmit() when called with invalid frequencies
TEST_P(ConsumerIrHidlTest,BadFreqTest)72 TEST_P(ConsumerIrHidlTest, BadFreqTest) {
73 uint32_t len = 16;
74 hidl_vec<int32_t> vec;
75 vec.resize(len);
76 std::fill(vec.begin(), vec.end(), 1);
77 EXPECT_FALSE(ir->transmit(-1, vec));
78 }
79
80 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ConsumerIrHidlTest);
81 INSTANTIATE_TEST_SUITE_P(
82 PerInstance, ConsumerIrHidlTest,
83 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IConsumerIr::descriptor)),
84 android::hardware::PrintInstanceNameToString);
85