1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cmath>
17 #include <cstdio>
18 #include <unistd.h>
19 #include <gtest/gtest.h>
20 #include <securec.h>
21 #include "hdf_base.h"
22 #include "osal_time.h"
23 #include "bluetooth_audio_session_service.h"
24 #include "bluetooth_hci_callback_impl.h"
25
26 using namespace OHOS::HDI::Bluetooth::A2dp::V1_0;
27 using IHciInterfaceSession = OHOS::HDI::Bluetooth::A2dp::V1_0::IBluetoothAudioSession;
28 using IHciInterfaceType = OHOS::HDI::Bluetooth::A2dp::V1_0::BluetoothAudioStatus;
29 using OHOS::HDI::Bluetooth::A2dp::V1_0::IBluetoothAudioCallback;
30 using namespace testing::ext;
31
BluetoothAudioSessionImplGetInstance(void)32 extern "C" IBluetoothAudioSession *BluetoothAudioSessionImplGetInstance(void)
33 {
34 return new (std::nothrow) BluetoothAudioSessionService();
35 }
36
37 namespace {
38 OHOS::sptr<IHciInterfaceSession> g_iBtHci = nullptr;
39 // OHOS::sptr<IBluetoothAudioCallback> g_hciCallbacks = nullptr;
40 sptr<SeClientCallback> g_hciCallbacks = nullptr;
41
42 }
43
44 class HdfBluetoothHdiTest : public testing::Test {
45 public:
46 static void SetUpTestCase();
47 static void TearDownTestCase();
48 void SetUp();
49 void TearDown();
50 };
SetUpTestCase()51 void HdfBluetoothHdiTest::SetUpTestCase()
52 {
53 g_iBtHci = IBluetoothAudioSession::Get(true);
54 }
TearDownTestCase()55 void HdfBluetoothHdiTest::TearDownTestCase()
56 {
57 }
SetUp()58 void HdfBluetoothHdiTest::SetUp()
59 {
60 }
TearDown()61 void HdfBluetoothHdiTest::TearDown()
62 {
63 }
64
65 /**
66 * @tc.name: A2dpBluetoothSession_0100
67 * @tc.desc: the bluetooth a2dp api StartSession test
68 * @tc.type: FUNC
69 */
HWTEST_F(HdfBluetoothHdiTest, SUB_DriverSystem_A2dpBluetoothSession_0100, TestSize.Level2)70 HWTEST_F(HdfBluetoothHdiTest, SUB_DriverSystem_A2dpBluetoothSession_0100, TestSize.Level2)
71 {
72 g_hciCallbacks = new (std::nothrow) SeClientCallback();
73 ASSERT_NE(nullptr, g_hciCallbacks);
74 std::cout << "g_hciCallbacks = " << g_hciCallbacks << std::endl;
75 ASSERT_NE(nullptr, g_iBtHci);
76 std::cout << "g_iBtHci0100 = " << g_iBtHci << std::endl;
77 SessionType sessionType = SessionType::SOFTWARE_ENCODING;
78 std::shared_ptr<SharedMemQueue<uint8_t>> queue = nullptr;
79 int32_t ret = g_iBtHci->StartSession(sessionType, g_hciCallbacks, queue);
80 std::cout << "A2dpBluetoothSession_0100_ret = " << ret << std::endl;
81 EXPECT_EQ(HDF_SUCCESS, ret);
82 }
83
84 /**
85 * @tc.name: A2dpBluetoothSession_0600
86 * @tc.desc: the bluetooth a2dp api StopSession test
87 * @tc.type: FUNC
88 */
HWTEST_F(HdfBluetoothHdiTest, SUB_DriverSystem_A2dpBluetoothSession_0600, TestSize.Level2)89 HWTEST_F(HdfBluetoothHdiTest, SUB_DriverSystem_A2dpBluetoothSession_0600, TestSize.Level2)
90 {
91 ASSERT_NE(nullptr, g_iBtHci);
92 SessionType sessionType = SessionType::UNKNOWN_TYPE;
93 int32_t ret = g_iBtHci->StopSession(sessionType);
94 std::cout << "A2dpBluetoothSession_0600_ret = " << ret << std::endl;
95 EXPECT_EQ(HDF_SUCCESS, ret);
96 }
97
98 /**
99 * @tc.name: A2dpBluetoothSession_1100
100 * @tc.desc: the bluetooth a2dp api RenderOperationResult test
101 * @tc.type: FUNC
102 */
103
HWTEST_F(HdfBluetoothHdiTest, SUB_DriverSystem_A2dpBluetoothSession_1100, TestSize.Level2)104 HWTEST_F(HdfBluetoothHdiTest, SUB_DriverSystem_A2dpBluetoothSession_1100, TestSize.Level2)
105 {
106 ASSERT_NE(nullptr, g_iBtHci);
107 Operation operation_render = Operation::SUSPEND_RENDER;
108 Status statusSuss = Status::SUCCESS;
109 int32_t ret = g_iBtHci->RenderOperationResult(operation_render, statusSuss);
110 std::cout << "A2dpBluetoothSession_1100_ret = " << ret << std::endl;
111 EXPECT_EQ(HDF_FAILURE, ret);
112 }
113
114 /**
115 * @tc.name: A2dpBluetoothSession_1600
116 * @tc.desc: the bluetooth a2dp enum types test
117 * @tc.type: FUNC
118 */
119
HWTEST_F(HdfBluetoothHdiTest, SUB_DriverSystem_A2dpBluetoothSession_1600, TestSize.Level2)120 HWTEST_F(HdfBluetoothHdiTest, SUB_DriverSystem_A2dpBluetoothSession_1600, TestSize.Level2)
121 {
122 Operation operation_suspend = Operation::SUSPEND_RENDER;
123 std::cout << "Operation SUSPEND_RENDER = " << operation_suspend << std::endl;
124 EXPECT_EQ(operation_suspend, 0);
125
126 Operation operation_start = Operation::START_RENDER;
127 std::cout << "Operation START_RENDER = " << operation_start << std::endl;
128 EXPECT_EQ(operation_start, 1);
129
130 Status staus_success = Status::SUCCESS;
131 std::cout << "Status SUCCESS = " << staus_success << std::endl;
132 EXPECT_EQ(staus_success, 0);
133
134 Status staus_failure = Status::FAILURE;
135 std::cout << "Status FAILURE = " << staus_failure << std::endl;
136 EXPECT_EQ(staus_failure, 1);
137
138 SessionType sessionType_unknownType = SessionType::UNKNOWN_TYPE;
139 std::cout << "SessionType UNKNOWN_TYPE = " << sessionType_unknownType << std::endl;
140
141 SessionType sessionType_softwareEncoding = SessionType::SOFTWARE_ENCODING;
142 std::cout << "SessionType SOFTWARE_ENCODING = " << sessionType_softwareEncoding << std::endl;
143
144 SessionType sessionType_hardwareEncoding = SessionType::HARDWARE_ENCODING;
145 std::cout << "SessionType HARDWARE_ENCODING = " << sessionType_hardwareEncoding << std::endl;
146 }