• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_source_input_cluster.h"
20 #include "test_case_common.h"
21 #include "audio_errors.h"
22 #include "hpae_source_input_node.h"
23 #include "hpae_source_output_node.h"
24 #include "hpae_format_convert.h"
25 
26 using namespace testing::ext;
27 using namespace testing;
28 
29 namespace OHOS {
30 namespace AudioStandard {
31 namespace HPAE {
32 
33 const uint32_t DEFAULT_FRAME_LENGTH = 960;
34 static std::string g_rootCapturerPath = "/data/source_file_io_48000_2_s16le.pcm";
35 
36 class HpaeSourceInputClusterTest : public ::testing::Test {
37 public:
38     void SetUp();
39     void TearDown();
40 };
41 
SetUp()42 void HpaeSourceInputClusterTest::SetUp()
43 {}
44 
TearDown()45 void HpaeSourceInputClusterTest::TearDown()
46 {}
47 
48 HWTEST_F(HpaeSourceInputClusterTest, constructHpaeSourceInputClusterNode, TestSize.Level0)
49 {
50     std::shared_ptr<NodeStatusCallback> testStatuscallback = std::make_shared<NodeStatusCallback>();
51     HpaeNodeInfo nodeInfo;
52     nodeInfo.frameLen = DEFAULT_FRAME_LENGTH;
53     nodeInfo.samplingRate = SAMPLE_RATE_48000;
54     nodeInfo.channels = STEREO;
55     nodeInfo.format = SAMPLE_F32LE;
56     nodeInfo.statusCallback = testStatuscallback;
57 
58     std::shared_ptr<HpaeSourceInputCluster> hpaeSourceInputCluster = std::make_shared<HpaeSourceInputCluster>(nodeInfo);
59     EXPECT_EQ(hpaeSourceInputCluster->GetSampleRate(), nodeInfo.samplingRate);
60     EXPECT_EQ(hpaeSourceInputCluster->GetFrameLen(), nodeInfo.frameLen);
61     EXPECT_EQ(hpaeSourceInputCluster->GetChannelCount(), nodeInfo.channels);
62     EXPECT_EQ(hpaeSourceInputCluster->GetBitWidth(), nodeInfo.format);
63     EXPECT_EQ(hpaeSourceInputCluster->GetSourceInputNodeUseCount(), 1);
64     std::shared_ptr<HpaeSourceOutputNode> hpaeSourceOutputNode = std::make_shared<HpaeSourceOutputNode>(nodeInfo);
65     hpaeSourceOutputNode->Connect(hpaeSourceInputCluster);
66     EXPECT_EQ(hpaeSourceInputCluster->GetSourceInputNodeUseCount(), 1 + 1);
67     EXPECT_EQ(hpaeSourceInputCluster->GetConverterNodeCount(), 0);
68 
69     nodeInfo.samplingRate = SAMPLE_RATE_16000;
70     std::shared_ptr<HpaeSourceOutputNode> hpaeSourceOutputNode1 = std::make_shared<HpaeSourceOutputNode>(nodeInfo);
71     hpaeSourceOutputNode1->ConnectWithInfo(hpaeSourceInputCluster, nodeInfo);
72     EXPECT_EQ(hpaeSourceInputCluster->GetSourceInputNodeUseCount(), 1 + 1 + 1);
73     EXPECT_EQ(hpaeSourceInputCluster->GetConverterNodeCount(), 1);
74 
75     hpaeSourceOutputNode1->DisConnectWithInfo(hpaeSourceInputCluster, hpaeSourceOutputNode1->GetNodeInfo());
76     EXPECT_EQ(hpaeSourceInputCluster->GetSourceInputNodeUseCount(), 1 + 1);
77     EXPECT_EQ(hpaeSourceInputCluster->GetConverterNodeCount(), 1); // no delete converter now
78 }
79 
80 HWTEST_F(HpaeSourceInputClusterTest, testInterfaces, TestSize.Level0)
81 {
82     std::shared_ptr<NodeStatusCallback> testStatuscallback = std::make_shared<NodeStatusCallback>();
83     HpaeNodeInfo nodeInfo;
84     nodeInfo.frameLen = DEFAULT_FRAME_LENGTH;
85     nodeInfo.samplingRate = SAMPLE_RATE_48000;
86     nodeInfo.channels = STEREO;
87     nodeInfo.format = SAMPLE_F32LE;
88     nodeInfo.sceneType = HPAE_SCENE_VOIP_UP;
89     nodeInfo.statusCallback = testStatuscallback;
90     nodeInfo.sourceBufferType = HPAE_SOURCE_BUFFER_TYPE_EC;
91     std::shared_ptr<HpaeSourceInputCluster> hpaeSourceInputCluster =
92         std::make_shared<HpaeSourceInputCluster>(nodeInfo);
93     hpaeSourceInputCluster->DoProcess();
94     hpaeSourceInputCluster->ResetAll();
95     EXPECT_NE(hpaeSourceInputCluster->GetSharedInstance(nodeInfo), nullptr);
96     EXPECT_NE(hpaeSourceInputCluster->CapturerSourcePause(), 0);
97     EXPECT_NE(hpaeSourceInputCluster->CapturerSourceResume(), 0);
98     EXPECT_NE(hpaeSourceInputCluster->CapturerSourceReset(), 0);
99     EXPECT_EQ(hpaeSourceInputCluster->GetOutputPortNum(nodeInfo), 0);
100     EXPECT_EQ(hpaeSourceInputCluster->GetSourceInputNodeType(), HPAE_SOURCE_DEFAULT);
101     EXPECT_NE(hpaeSourceInputCluster->CapturerSourceFlush(), 0);
102 
103     nodeInfo.sourceBufferType = HPAE_SOURCE_BUFFER_TYPE_MICREF;
104     hpaeSourceInputCluster = std::make_shared<HpaeSourceInputCluster>(nodeInfo);
105 }
106 }  // namespace HPAE
107 }  // namespace AudioStandard
108 }  // namespace OHOS