1 /*
2 * Copyright (C) 2023 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 #include <aidl/Gtest.h>
17 #include <aidl/Vintf.h>
18 #include <aidl/hardware/google/bluetooth/bt_channel_avoidance/IBTChannelAvoidance.h>
19 #include <android/binder_auto_utils.h>
20 #include <android/binder_manager.h>
21 #include <android/binder_process.h>
22 #include <binder/IServiceManager.h>
23 #include <binder/ProcessState.h>
24
25 using aidl::hardware::google::bluetooth::bt_channel_avoidance::IBTChannelAvoidance;
26 using ndk::ScopedAStatus;
27 using ndk::SpAIBinder;
28
29 class BTChannelAvoidanceTest : public ::testing::TestWithParam<std::string> {
30 public:
31 virtual void SetUp() override;
32 virtual void TearDown() override;
33
34 ndk::ScopedAStatus setBluetoothChannelStatus(const std::array<uint8_t, 10>& channel_map);
35
36 private:
37 std::shared_ptr<IBTChannelAvoidance> bt_channel_avoidance_;
38 };
39
SetUp()40 void BTChannelAvoidanceTest::SetUp() {
41 ALOGI("SetUp Bluetooth Channel Avoidance Test");
42 bt_channel_avoidance_ = IBTChannelAvoidance::fromBinder(
43 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
44 ASSERT_NE(bt_channel_avoidance_, nullptr);
45 }
46
TearDown()47 void BTChannelAvoidanceTest::TearDown() {
48 ALOGI("TearDown Bluetooth Channel Avoidance Test");
49 bt_channel_avoidance_ = nullptr;
50 ASSERT_EQ(bt_channel_avoidance_, nullptr);
51 }
52
setBluetoothChannelStatus(const std::array<uint8_t,10> & channel_map)53 ndk::ScopedAStatus BTChannelAvoidanceTest::setBluetoothChannelStatus(const std::array<uint8_t, 10>& channel_map) {
54 return bt_channel_avoidance_->setBluetoothChannelStatus(channel_map);
55 }
56
TEST_P(BTChannelAvoidanceTest,setBluetoothChannelStatus)57 TEST_P(BTChannelAvoidanceTest, setBluetoothChannelStatus) {
58 std::array<uint8_t, 10> channel_map = {127, 255, 255, 255, 255, 255, 255, 0, 0, 15};
59 ndk::ScopedAStatus status = setBluetoothChannelStatus(channel_map);
60 ASSERT_TRUE(status.isOk());
61 }
62
63 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BTChannelAvoidanceTest);
64 INSTANTIATE_TEST_SUITE_P(PerInstance, BTChannelAvoidanceTest,
65 testing::ValuesIn(android::getAidlHalInstanceNames(
66 IBTChannelAvoidance::descriptor)),
67 android::PrintInstanceNameToString);
68
main(int argc,char ** argv)69 int main(int argc, char **argv) {
70 ::testing::InitGoogleTest(&argc, argv);
71 ABinderProcess_startThreadPool();
72 int status = RUN_ALL_TESTS();
73 ALOGI("Test result = %d", status);
74 return status;
75 }
76
77