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_service_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 AudioZoneServiceUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)29 void AudioZoneServiceUnitTest::TearDownTestCase(void) {}
SetUp(void)30 void AudioZoneServiceUnitTest::SetUp(void)
31 {
32 AudioZoneService::GetInstance().Init(DelayedSingleton<AudioPolicyServerHandler>::GetInstance(),
33 std::make_shared<AudioInterruptService>());
34 }
TearDown(void)35 void AudioZoneServiceUnitTest::TearDown(void) {}
36
37 /**
38 * @tc.name : Test AudioZoneServiceUnitTest.
39 * @tc.number: AudioZoneService_001
40 * @tc.desc : Test EnableAudioZoneReport interface.
41 */
42 HWTEST_F(AudioZoneServiceUnitTest, AudioZoneService_001, TestSize.Level1)
43 {
44 EXPECT_EQ(AudioZoneService::GetInstance().EnableAudioZoneReport(0, true), SUCCESS);
45 EXPECT_EQ(AudioZoneService::GetInstance().EnableAudioZoneReport(0, false), SUCCESS);
46 }
47
48 /**
49 * @tc.name : Test AudioZoneServiceUnitTest.
50 * @tc.number: AudioZoneService_002
51 * @tc.desc : Test CheckIsZoneValid interface.
52 */
53 HWTEST_F(AudioZoneServiceUnitTest, AudioZoneService_002, TestSize.Level1)
54 {
55 EXPECT_EQ(AudioZoneService::GetInstance().CheckIsZoneValid(-1), false);
56 EXPECT_EQ(AudioZoneService::GetInstance().CheckIsZoneValid(1), false);
57 EXPECT_EQ(AudioZoneService::GetInstance().CheckIsZoneValid(1), false);
58 }
59
60 /**
61 * @tc.name : Test AudioZoneServiceUnitTest.
62 * @tc.number: AudioZoneService_003
63 * @tc.desc : Test InjectInterruptToAudioZone interface.
64 */
65 HWTEST_F(AudioZoneServiceUnitTest, AudioZoneService_003, TestSize.Level1)
66 {
67 std::list<std::pair<AudioInterrupt, AudioFocuState>> interrupts;
68 EXPECT_NE(AudioZoneService::GetInstance().InjectInterruptToAudioZone(0, "", interrupts), 0);
69 EXPECT_NE(AudioZoneService::GetInstance().InjectInterruptToAudioZone(0, "0", interrupts), 0);
70 }
71 } // namespace AudioStandard
72 } // namespace OHOS
73