1 /*
2 * Copyright (c) 2025 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 "audio_zone_client_manager_unit_test.h"
17 #include "audio_errors.h"
18 #include "audio_policy_log.h"
19
20 #include <thread>
21 #include <memory>
22 #include <vector>
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace AudioStandard {
27
SetUpTestCase(void)28 void AudioZoneClientManagerUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)29 void AudioZoneClientManagerUnitTest::TearDownTestCase(void) {}
SetUp(void)30 void AudioZoneClientManagerUnitTest::SetUp(void) {}
TearDown(void)31 void AudioZoneClientManagerUnitTest::TearDown(void) {}
32
33 /**
34 * @tc.name : Test AudioZoneClientManagerUnitTest.
35 * @tc.number: AudioZoneClientManager_001
36 * @tc.desc : Test AddAudioInterruptCallback interface.
37 */
38 HWTEST_F(AudioZoneClientManagerUnitTest, AudioZoneClientManager_001, TestSize.Level1)
39 {
40 std::shared_ptr<AudioZoneEvent> event = std::make_shared<AudioZoneEvent>();
41 event->type = AudioZoneEventType::AUDIO_ZONE_ADD_EVENT;
42 AudioZoneClientManager::GetInstance().DispatchEvent(event);
43 event->type = AudioZoneEventType::AUDIO_ZONE_REMOVE_EVENT;
44 AudioZoneClientManager::GetInstance().DispatchEvent(event);
45 event->type = AudioZoneEventType::AUDIO_ZONE_CHANGE_EVENT;
46 AudioZoneClientManager::GetInstance().DispatchEvent(event);
47 event->type = AudioZoneEventType::AUDIO_ZONE_INTERRUPT_EVENT;
48 AudioZoneClientManager::GetInstance().DispatchEvent(event);
49 event->deviceTag = "1";
50 event->type = AudioZoneEventType::AUDIO_ZONE_INTERRUPT_EVENT;
51 AudioZoneClientManager::GetInstance().DispatchEvent(event);
52 event->descriptor = std::make_shared<AudioZoneDescriptor>();
53 AudioZoneClientManager::GetInstance().DispatchEvent(event);
54 EXPECT_NE(event, nullptr);
55 }
56
57 /**
58 * @tc.name : Test UnRegisterAudioZoneClientUnitTest.
59 * @tc.number: UnRegisterAudioZoneClient_001
60 * @tc.desc : Test UnRegisterAudioZoneClient interface.
61 */
62 HWTEST_F(AudioZoneClientManagerUnitTest, UnRegisterAudioZoneClient_001, TestSize.Level1)
63 {
64 pid_t clientPid = 1000;
65 AudioZoneClientManager::GetInstance().UnRegisterAudioZoneClient(clientPid);
66 EXPECT_TRUE(AudioZoneClientManager::GetInstance().clients_.find(clientPid) ==
67 AudioZoneClientManager::GetInstance().clients_.end());
68 }
69 } // namespace AudioStandard
70 } // namespace OHOS
71