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 <gtest/gtest.h>
17 #include <cmath>
18 #include <memory>
19 #include "hpae_process_cluster.h"
20 #include "test_case_common.h"
21 #include "audio_errors.h"
22 #include "hpae_sink_input_node.h"
23 #include "hpae_remote_output_cluster.h"
24 #include "hpae_mixer_node.h"
25
26 using namespace testing::ext;
27 using namespace testing;
28
29 namespace OHOS {
30 namespace AudioStandard {
31 namespace HPAE {
32
33
34 class HpaeRemoteOutputClusterTest : public testing::Test {
35 public:
36 void SetUp();
37 void TearDown();
38 };
39
SetUp()40 void HpaeRemoteOutputClusterTest::SetUp()
41 {}
42
TearDown()43 void HpaeRemoteOutputClusterTest::TearDown()
44 {}
45
46 HWTEST_F(HpaeRemoteOutputClusterTest, constructNode_01, TestSize.Level0)
47 {
48 HpaeSinkInfo sinkInfo;
49 sinkInfo.needEmptyChunk = false;
50 HpaeNodeInfo nodeInfo1;
51 nodeInfo1.nodeId = 1001; // 1001: node id
52 nodeInfo1.frameLen = 960; // 960: frameLen
53 nodeInfo1.sessionId = 123456; // 123456: session id
54 nodeInfo1.samplingRate = SAMPLE_RATE_48000;
55 nodeInfo1.channels = STEREO;
56 nodeInfo1.format = SAMPLE_F32LE;
57 std::shared_ptr<HpaeRemoteOutputCluster> hpaeRemoteOutputCluster =
58 std::make_shared<HpaeRemoteOutputCluster>(nodeInfo1, sinkInfo);
59 EXPECT_NE(hpaeRemoteOutputCluster, nullptr);
60
61 HpaeNodeInfo nodeInfo2;
62 nodeInfo2.nodeId = 1002; // 1002: nodeId
63 nodeInfo2.frameLen = 960; // 960: frame len
64 nodeInfo2.samplingRate = SAMPLE_RATE_48000;
65 nodeInfo2.channels = STEREO;
66 nodeInfo2.format = SAMPLE_F32LE;
67 std::shared_ptr<HpaeMixerNode> hpaeMixerNode = std::make_shared<HpaeMixerNode>(nodeInfo2);
68 EXPECT_NE(hpaeMixerNode, nullptr);
69
70 hpaeRemoteOutputCluster->Connect(hpaeMixerNode);
71 hpaeRemoteOutputCluster->SetTimeoutStopThd(100); // 100: time
72 hpaeRemoteOutputCluster->DoProcess();
73 hpaeRemoteOutputCluster->GetConverterNodeCount();
74 hpaeRemoteOutputCluster->DeInit();
75 hpaeRemoteOutputCluster->Flush();
76 hpaeRemoteOutputCluster->Pause();
77 hpaeRemoteOutputCluster->ResetRender();
78 hpaeRemoteOutputCluster->Resume();
79 hpaeRemoteOutputCluster->Start();
80 hpaeRemoteOutputCluster->Stop();
81 hpaeRemoteOutputCluster->DisConnect(hpaeMixerNode);
82 }
83
84 HWTEST_F(HpaeRemoteOutputClusterTest, SetTimeoutStopThd_01, TestSize.Level0)
85 {
86 HpaeSinkInfo sinkInfo;
87 HpaeNodeInfo nodeInfo1;
88 nodeInfo1.nodeId = 1001; // 1001: node id
89 nodeInfo1.frameLen = 0;
90 nodeInfo1.sessionId = 123456; // 123456: session id
91 nodeInfo1.samplingRate = SAMPLE_RATE_48000;
92 nodeInfo1.channels = STEREO;
93 nodeInfo1.format = SAMPLE_F32LE;
94 std::shared_ptr<HpaeRemoteOutputCluster> hpaeRemoteOutputCluster =
95 std::make_shared<HpaeRemoteOutputCluster>(nodeInfo1, sinkInfo);
96 EXPECT_NE(hpaeRemoteOutputCluster, nullptr);
97
98 HpaeNodeInfo nodeInfo2;
99 nodeInfo2.nodeId = 1002; // 1002: node id
100 nodeInfo2.frameLen = 960; // 960: frameLen
101 nodeInfo2.samplingRate = SAMPLE_RATE_48000;
102 nodeInfo2.channels = STEREO;
103 nodeInfo2.format = SAMPLE_F32LE;
104 std::shared_ptr<HpaeMixerNode> hpaeMixerNode = std::make_shared<HpaeMixerNode>(nodeInfo2);
105 EXPECT_NE(hpaeMixerNode, nullptr);
106
107 hpaeRemoteOutputCluster->Connect(hpaeMixerNode);
108 hpaeRemoteOutputCluster->SetTimeoutStopThd(100); // 100: time
109 hpaeRemoteOutputCluster->DoProcess();
110 hpaeRemoteOutputCluster->GetConverterNodeCount();
111 hpaeRemoteOutputCluster->DeInit();
112 hpaeRemoteOutputCluster->Flush();
113 hpaeRemoteOutputCluster->Pause();
114 hpaeRemoteOutputCluster->ResetRender();
115 hpaeRemoteOutputCluster->Resume();
116 hpaeRemoteOutputCluster->Start();
117 hpaeRemoteOutputCluster->Stop();
118 hpaeRemoteOutputCluster->DisConnect(hpaeMixerNode);
119 }
120 } // namespace HPAE
121 } // namespace AudioStandard
122 } // namespace OHOS