• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ewp/IBluetoothEwp.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::ewp::IBluetoothEwp;
26 using ndk::ScopedAStatus;
27 using ndk::SpAIBinder;
28 
29 class BluetoothEwpTest : public ::testing::TestWithParam<std::string> {
30 public:
31   virtual void SetUp() override;
32   virtual void TearDown() override;
33 
34   ndk::ScopedAStatus enableEwp(uint16_t event_mask);
35   ndk::ScopedAStatus disableEwp();
36 
37 private:
38   std::shared_ptr<IBluetoothEwp> bluetooth_ewp_;
39 };
40 
SetUp()41 void BluetoothEwpTest::SetUp() {
42   ALOGI("SetUp Bluetooth Ewp Test");
43   bluetooth_ewp_ = IBluetoothEwp::fromBinder(
44       ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
45   ASSERT_NE(bluetooth_ewp_, nullptr);
46 }
47 
TearDown()48 void BluetoothEwpTest::TearDown() {
49   ALOGI("TearDown Bluetooth Ewp Test");
50   bluetooth_ewp_ = nullptr;
51   ASSERT_EQ(bluetooth_ewp_, nullptr);
52 }
53 
enableEwp(uint16_t event_mask)54 ndk::ScopedAStatus BluetoothEwpTest::enableEwp(uint16_t event_mask){
55   return bluetooth_ewp_->enableEwp(event_mask);
56 }
57 
disableEwp()58 ndk::ScopedAStatus BluetoothEwpTest::disableEwp() {
59   return bluetooth_ewp_->disableEwp();
60 }
61 
TEST_P(BluetoothEwpTest,enableEwp)62 TEST_P(BluetoothEwpTest, enableEwp) {
63   uint16_t event_mask = 275;
64   ndk::ScopedAStatus status = enableEwp(event_mask);
65   ASSERT_TRUE(status.isOk());
66 }
67 
TEST_P(BluetoothEwpTest,disableEwp)68 TEST_P(BluetoothEwpTest, disableEwp) {
69   ndk::ScopedAStatus status = disableEwp();
70   ASSERT_TRUE(status.isOk());
71 }
72 
73 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothEwpTest);
74 INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothEwpTest,
75                          testing::ValuesIn(android::getAidlHalInstanceNames(
76                              IBluetoothEwp::descriptor)),
77                          android::PrintInstanceNameToString);
78 
main(int argc,char ** argv)79 int main(int argc, char **argv) {
80   ::testing::InitGoogleTest(&argc, argv);
81   ABinderProcess_startThreadPool();
82   int status = RUN_ALL_TESTS();
83   ALOGI("Test result = %d", status);
84   return status;
85 }
86 
87