1 /*
2 * Copyright (c) 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 /**
17 * @addtogroup Audio
18 * @{
19 *
20 * @brief Test audio-related APIs, including custom data types and functions for loading drivers,
21 * accessing a driver adapter.
22 *
23 * @since 1.0
24 * @version 1.0
25 */
26
27 /**
28 * @file audio_hdi_common.h
29 *
30 * @brief Declares APIs for operations related to the audio adapter.
31 *
32 * @since 1.0
33 * @version 1.0
34 */
35
36 #include "audio_hdi_common.h"
37 #include "audio_usb_manager_test.h"
38
39 using namespace std;
40 using namespace testing::ext;
41 using namespace OHOS::Audio;
42
43 namespace {
44 const string ADAPTER_NAME_USB = "usb";
45
46 class AudioUsbManagerTest : public testing::Test {
47 public:
48 static void SetUpTestCase(void);
49 static void TearDownTestCase(void);
50 void SetUp();
51 void TearDown();
52 static TestAudioManager *manager;
53 };
54
55 TestAudioManager *AudioUsbManagerTest::manager = nullptr;
56
SetUpTestCase(void)57 void AudioUsbManagerTest::SetUpTestCase(void)
58 {
59 manager = GetAudioManagerFuncs();
60 ASSERT_NE(nullptr, manager);
61 }
62
TearDownTestCase(void)63 void AudioUsbManagerTest::TearDownTestCase(void) {}
64
SetUp(void)65 void AudioUsbManagerTest::SetUp(void) {}
66
TearDown(void)67 void AudioUsbManagerTest::TearDown(void) {}
68
69 /**
70 * @tc.name AudioGetAllAdapters_001
71 * @tc.desc test GetAllAdapters interface,Returns 0 if the list is obtained successfully
72 * @tc.type: FUNC
73 */
74 HWTEST_F(AudioUsbManagerTest, AudioGetAllAdapters_001, TestSize.Level1)
75 {
76 int32_t ret = -1;
77 int size = 0;
78 struct AudioAdapterDescriptor *descs = nullptr;
79
80 ASSERT_NE(nullptr, manager);
81 ret = manager->GetAllAdapters(manager, &descs, &size);
82 EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
83 EXPECT_EQ(AUDIO_ADAPTER_MAX_NUM, size);
84 }
85 /**
86 * @tc.name AudioLoadAdapter_001
87 * @tc.desc test LoadAdapter interface,Returns 0 if the driver is loaded successfully
88 * @tc.type: FUNC
89 */
90 HWTEST_F(AudioUsbManagerTest, AudioLoadAdapter_001, TestSize.Level1)
91 {
92 int32_t ret = -1;
93 int size = 0;
94 struct AudioAdapterDescriptor *descs = nullptr;
95
96 ASSERT_NE(nullptr, manager);
97 ret = GetAdapters(manager, &descs, size);
98 ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
99 struct AudioAdapterDescriptor *desc = &descs[0];
100 ASSERT_TRUE(desc != nullptr);
101 struct AudioAdapter *adapter = nullptr;
102 ret = manager->LoadAdapter(manager, desc, &adapter);
103 ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
104 ret = -1;
105 if (adapter != nullptr) {
106 if (adapter->InitAllPorts != nullptr && adapter->CreateRender != nullptr &&
107 adapter->DestroyRender != nullptr && adapter->CreateCapture != nullptr &&
108 adapter->DestroyCapture != nullptr && adapter->GetPortCapability != nullptr &&
109 adapter->SetPassthroughMode != nullptr && adapter->GetPassthroughMode != nullptr) {
110 ret = 0;
111 }
112 }
113 EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
114 manager->UnloadAdapter(manager, adapter);
115 }
116 }
117