• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 "daudio_hdi_handler_test.h"
17 
18 using namespace testing::ext;
19 
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase(void)22 void DAudioHdiHandlerTest::SetUpTestCase(void) {}
23 
TearDownTestCase(void)24 void DAudioHdiHandlerTest::TearDownTestCase(void) {}
25 
SetUp()26 void DAudioHdiHandlerTest::SetUp()
27 {
28     hdiHandler_ = std::make_shared<DAudioHdiHandler>();
29 }
30 
TearDown()31 void DAudioHdiHandlerTest::TearDown()
32 {
33     hdiHandler_ = nullptr;
34 }
35 
36 /**
37  * @tc.name: InitHdiHandler_001
38  * @tc.desc: Verify the InitHdiHandler function.
39  * @tc.type: FUNC
40  * @tc.require: AR000H0E6H
41  */
42 HWTEST_F(DAudioHdiHandlerTest, InitHdiHandler_001, TestSize.Level1)
43 {
44     ASSERT_TRUE(hdiHandler_ != nullptr);
45     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler());
46     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler()); // test repeated initialization
47 }
48 
49 /**
50  * @tc.name: RegisterAudioDevice_001
51  * @tc.desc: Verify the RegisterAudioDevice function.
52  * @tc.type: FUNC
53  * @tc.require: AR000H0E6H
54  */
55 HWTEST_F(DAudioHdiHandlerTest, RegisterAudioDevice_001, TestSize.Level1)
56 {
57     ASSERT_TRUE(hdiHandler_ != nullptr);
58     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler());
59     hdiHandler_->audioSrvHdf_ = nullptr;
60     std::shared_ptr<IDAudioHdiCallback> callbackObjParam = std::make_shared<MockIDAudioHdiCallback>();
61     EXPECT_NE(HDF_SUCCESS, hdiHandler_->RegisterAudioDevice(devId_,
62         PIN_OUT_DAUDIO_DEFAULT, capability_, callbackObjParam));
63     EXPECT_NE(HDF_SUCCESS, hdiHandler_->RegisterAudioDevice(devId_,
64         PIN_IN_DAUDIO_DEFAULT, capability_, callbackObjParam));
65     EXPECT_NE(HDF_SUCCESS, hdiHandler_->RegisterAudioDevice(devId_, -1, capability_, callbackObjParam));
66     EXPECT_NE(HDF_SUCCESS, hdiHandler_->UnRegisterAudioDevice(devId_, PIN_OUT_DAUDIO_DEFAULT));
67     EXPECT_NE(HDF_SUCCESS, hdiHandler_->UnRegisterAudioDevice(devId_, PIN_IN_DAUDIO_DEFAULT));
68     EXPECT_NE(HDF_SUCCESS, hdiHandler_->UnRegisterAudioDevice("errorId", PIN_IN_DAUDIO_DEFAULT));
69 }
70 
71 /**
72  * @tc.name: RegisterAudioDevice_002
73  * @tc.desc: Verify the RegisterAudioDevice function.
74  * @tc.type: FUNC
75  * @tc.require: AR000H0E6H
76  */
77 HWTEST_F(DAudioHdiHandlerTest, RegisterAudioDevice_002, TestSize.Level1)
78 {
79     ASSERT_TRUE(hdiHandler_ != nullptr);
80     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler());
81     std::shared_ptr<IDAudioHdiCallback> callbackObjParam = std::make_shared<MockIDAudioHdiCallback>();
82     EXPECT_EQ(ERR_DH_AUDIO_HDI_CALL_FAILED,
83         hdiHandler_->RegisterAudioDevice(devId_, dhId_, capability_, callbackObjParam));
84     EXPECT_EQ(ERR_DH_AUDIO_HDI_CALL_FAILED, hdiHandler_->UnRegisterAudioDevice(devId_, dhId_));
85 }
86 
87 /**
88  * @tc.name: NotifyEvent_001
89  * @tc.desc: Verify the NotifyEvent function.
90  * @tc.type: FUNC
91  * @tc.require: AR000H0E6H
92  */
93 HWTEST_F(DAudioHdiHandlerTest, NotifyEvent_001, TestSize.Level1)
94 {
95     ASSERT_TRUE(hdiHandler_ != nullptr);
96     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler());
97     hdiHandler_->audioSrvHdf_ = nullptr;
98     AudioEvent audioEvent;
99     EXPECT_NE(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent));
100 }
101 
102 /**
103  * @tc.name: NotifyEvent_002
104  * @tc.desc: Verify the NotifyEvent function.
105  * @tc.type: FUNC
106  * @tc.require: AR000H0E6H
107  */
108 HWTEST_F(DAudioHdiHandlerTest, NotifyEvent_002, TestSize.Level1)
109 {
110     ASSERT_TRUE(hdiHandler_ != nullptr);
111     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->InitHdiHandler());
112     hdiHandler_->audioSrvHdf_ = sptr<MockIDAudioManager>(new MockIDAudioManager());
113     AudioEvent audioEvent1(AudioEventType::NOTIFY_OPEN_SPEAKER_RESULT, "");
114     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent1));
115     AudioEvent audioEvent2(AudioEventType::NOTIFY_CLOSE_SPEAKER_RESULT, "");
116     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent2));
117     AudioEvent audioEvent3(AudioEventType::NOTIFY_OPEN_MIC_RESULT, "");
118     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent3));
119     AudioEvent audioEvent4(AudioEventType::NOTIFY_CLOSE_MIC_RESULT, "");
120     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent4));
121     AudioEvent audioEvent5(AudioEventType::VOLUME_CHANGE, "");
122     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent5));
123     AudioEvent audioEvent6(AudioEventType::SPEAKER_CLOSED, "");
124     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent6));
125     AudioEvent audioEvent7(AudioEventType::MIC_CLOSED, "");
126     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent7));
127     AudioEvent audioEvent8(AudioEventType::AUDIO_FOCUS_CHANGE, "");
128     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent8));
129     AudioEvent audioEvent9(AudioEventType::AUDIO_RENDER_STATE_CHANGE, "");
130     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent9));
131     AudioEvent audioEvent(-1, "");
132     EXPECT_EQ(HDF_SUCCESS, hdiHandler_->NotifyEvent(devId_, dhId_, streamId_, audioEvent));
133 }
134 
135 /**
136  * @tc.name: UnRegisterAudioDevice_001
137  * @tc.desc: Verify the UnRegisterAudioDevice function.
138  * @tc.type: FUNC
139  * @tc.require: AR000H0E6H
140  */
141 HWTEST_F(DAudioHdiHandlerTest, UnRegisterAudioDevice_001, TestSize.Level1)
142 {
143     ASSERT_TRUE(hdiHandler_ != nullptr);
144     hdiHandler_->audioSrvHdf_ = nullptr;
145     EXPECT_NE(HDF_SUCCESS, hdiHandler_->UnRegisterAudioDevice(devId_, dhId_));
146 }
147 
148 /**
149  * @tc.name: UnInitHdiHandler_001
150  * @tc.desc: Verify the UnInitHdiHandler function.
151  * @tc.type: FUNC
152  * @tc.require: AR000H0E6H
153  */
154 HWTEST_F(DAudioHdiHandlerTest, UnInitHdiHandler_001, TestSize.Level1)
155 {
156     ASSERT_TRUE(hdiHandler_ != nullptr);
157     hdiHandler_->audioSrvHdf_ = nullptr;
158     EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, hdiHandler_->UninitHdiHandler());
159 }
160 } // DistributedHardware
161 } // OHOS
162