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_interrupt_dfx_collector_unit_test.h"
17
18 using namespace testing::ext;
19
20 namespace OHOS {
21 namespace AudioStandard {
22
SetUpTestCase(void)23 void AudioInterruptDfxCollectorUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)24 void AudioInterruptDfxCollectorUnitTest::TearDownTestCase(void) {}
SetUp(void)25 void AudioInterruptDfxCollectorUnitTest::SetUp(void) {}
TearDown(void)26 void AudioInterruptDfxCollectorUnitTest::TearDown(void) {}
27
SetUpTestCase(void)28 void InterruptDfxBuilderUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)29 void InterruptDfxBuilderUnitTest::TearDownTestCase(void) {}
SetUp(void)30 void InterruptDfxBuilderUnitTest::SetUp(void) {}
TearDown(void)31 void InterruptDfxBuilderUnitTest::TearDown(void) {}
32
33 /**
34 * @tc.name : Test AudioInterruptDfxCollector.
35 * @tc.number: FlushDfxMsg_001
36 * @tc.desc : Test AudioInterruptDfxCollector::FlushDfxMsg
37 */
38 HWTEST(AudioInterruptDfxCollectorUnitTest, FlushDfxMsg_001, TestSize.Level1)
39 {
40 AudioInterruptDfxCollector dfxCollector;
41 uint32_t index = 0;
42 uint32_t appUid = -1;
43 std::list<InterruptDfxInfo> dfxInfoList;
44
45 dfxCollector.dfxInfos_[index] = dfxInfoList;
46 dfxCollector.FlushDfxMsg(index, appUid);
47 EXPECT_NE(dfxCollector.dfxInfos_.size(), 0);
48
49 appUid = 1;
50 dfxCollector.FlushDfxMsg(index, appUid);
51 EXPECT_EQ(dfxCollector.dfxInfos_.size(), 0);
52 }
53
54 /**
55 * @tc.name : Test AudioInterruptDfxCollector.
56 * @tc.number: GetDfxIndexes_001
57 * @tc.desc : Test AudioInterruptDfxCollector::GetDfxIndexes
58 */
59 HWTEST(AudioInterruptDfxCollectorUnitTest, GetDfxIndexes_001, TestSize.Level1)
60 {
61 AudioInterruptDfxCollector dfxCollector;
62 uint32_t index = 0;
63
64 dfxCollector.GetDfxIndexes(index);
65 EXPECT_NE(dfxCollector.dfxIdx2InfoIdx_.size(), 0);
66 }
67
68 /**
69 * @tc.name : Test InterruptDfxBuilder.
70 * @tc.number: WriteActionMsg_001
71 * @tc.desc : Test InterruptDfxBuilder::WriteActionMsg
72 */
73 HWTEST(AudioInterruptDfxCollectorUnitTest, WriteActionMsg_001, TestSize.Level1)
74 {
75 InterruptDfxBuilder dfxBuilder;
76 uint8_t infoIndex = 0;
77 uint8_t effectIdx = 0;
78 InterruptStage stage = INTERRUPT_STAGE_STOP;
79
80 auto &ret = dfxBuilder.WriteActionMsg(infoIndex, effectIdx, stage);
81 EXPECT_EQ(&ret, &dfxBuilder);
82 }
83
84 /**
85 * @tc.name : Test InterruptDfxBuilder.
86 * @tc.number: WriteInfoMsg_001
87 * @tc.desc : Test InterruptDfxBuilder::WriteInfoMsg
88 */
89 HWTEST(AudioInterruptDfxCollectorUnitTest, WriteInfoMsg_001, TestSize.Level1)
90 {
91 InterruptDfxBuilder dfxBuilder;
92 AudioInterrupt audioInterrupt;
93 AudioSessionStrategy strategy;
94 InterruptRole interruptType = INTERRUPT_ROLE_DEFAULT;
95
96 strategy.concurrencyMode = AudioConcurrencyMode::DEFAULT;
97 auto &ret = dfxBuilder.WriteInfoMsg(audioInterrupt, strategy, interruptType);
98 EXPECT_EQ(&ret, &dfxBuilder);
99 }
100
101 /**
102 * @tc.name : Test InterruptDfxBuilder.
103 * @tc.number: WriteEffectMsg_001
104 * @tc.desc : Test InterruptDfxBuilder::WriteEffectMsg
105 */
106 HWTEST(AudioInterruptDfxCollectorUnitTest, WriteEffectMsg_001, TestSize.Level1)
107 {
108 InterruptDfxBuilder dfxBuilder;
109 uint8_t appstate = 1;
110 std::string bundleName = "com.ohos.test";
111 AudioInterrupt audioInterrupt;
112 InterruptHint hintType = INTERRUPT_HINT_NONE;
113
114 auto &ret = dfxBuilder.WriteEffectMsg(appstate, bundleName, audioInterrupt, hintType);
115 EXPECT_EQ(&ret, &dfxBuilder);
116 }
117
118 /**
119 * @tc.name : Test InterruptDfxBuilder.
120 * @tc.number: GetResult_001
121 * @tc.desc : Test InterruptDfxBuilder::GetResult
122 */
123 HWTEST(AudioInterruptDfxCollectorUnitTest, GetResult_001, TestSize.Level1)
124 {
125 InterruptDfxBuilder dfxBuilder;
126
127 auto ret = dfxBuilder.GetResult();
128 EXPECT_EQ(ret.interruptEffectVec.size(), 0);
129 }
130 } // AudioStandard
131 } // OHOS
132