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 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 #include <sys/mman.h>
19
20 #include "distributed_audio_client.h"
21 #include "audio_manager.h"
22 #include "daudio_errorcode.h"
23 #include "daudio_log.h"
24
25 #define HDF_LOG_TAG HDF_AUDIO_UT
26
27 using namespace std;
28 using namespace testing::ext;
29 namespace OHOS {
30 namespace DistributedHardware {
31 class AudioManagerTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 };
36
SetUpTestCase()37 void AudioManagerTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void AudioManagerTest::TearDownTestCase()
42 {
43 }
44
45 /**
46 * @tc.name: GetAllAdaptersAbnormal
47 * @tc.desc: Verify the abnormal branch of the GetAllAdapters, when param is null.
48 * @tc.type: FUNC
49 * @tc.require: AR000H0E6H
50 */
51 HWTEST_F(AudioManagerTest, GetAllAdaptersAbnormal, TestSize.Level1)
52 {
53 struct AudioManagerContext managerContext;
54 int32_t size = 0;
55 AudioAdapterDescriptor *descs = nullptr;
56
57 int32_t ret = managerContext.instance_.GetAllAdapters(nullptr, &descs, &size);
58 EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret);
59 ret = managerContext.instance_.GetAllAdapters(&managerContext.instance_, nullptr, &size);
60 EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret);
61 ret = managerContext.instance_.GetAllAdapters(&managerContext.instance_, &descs, nullptr);
62 EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret);
63 }
64
65 /**
66 * @tc.name: LoadAdapterAbnormal
67 * @tc.desc: Verify the abnormal branch of the LoadAdapter, when param is null.
68 * @tc.type: FUNC
69 * @tc.require: AR000H0E6H
70 */
71 HWTEST_F(AudioManagerTest, LoadAdapterAbnormal, TestSize.Level1)
72 {
73 struct AudioManagerContext managerContext;
74 AudioAdapterDescriptor desc = {};
75 AudioAdapter *adapter = nullptr;
76 struct AudioManager *manager = nullptr;
77
78 int32_t ret = managerContext.instance_.LoadAdapter(nullptr, &desc, &adapter);
79 EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret);
80 ret = managerContext.instance_.LoadAdapter(&managerContext.instance_, nullptr, &adapter);
81 EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret);
82 ret = managerContext.instance_.LoadAdapter(&managerContext.instance_, &desc, nullptr);
83 EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret);
84 managerContext.instance_.UnloadAdapter(manager, adapter);
85 }
86 } // DistributedHardware
87 } // OHOS