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 <iostream>
17 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
19 #include "audio_utils.h"
20 #include "common/hdi_adapter_info.h"
21 #include "manager/hdi_adapter_manager.h"
22
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace AudioStandard {
27 class RemoteFastAudioCaptureSourceUnitTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 virtual void SetUp();
32 virtual void TearDown();
33
34 protected:
35 static uint32_t id_;
36 static std::shared_ptr<IAudioCaptureSource> source_;
37 static IAudioSourceAttr attr_;
38 };
39
40 uint32_t RemoteFastAudioCaptureSourceUnitTest::id_ = HDI_INVALID_ID;
41 std::shared_ptr<IAudioCaptureSource> RemoteFastAudioCaptureSourceUnitTest::source_ = nullptr;
42 IAudioSourceAttr RemoteFastAudioCaptureSourceUnitTest::attr_ = {};
43
SetUpTestCase()44 void RemoteFastAudioCaptureSourceUnitTest::SetUpTestCase()
45 {
46 id_ = HdiAdapterManager::GetInstance().GetId(HDI_ID_BASE_CAPTURE, HDI_ID_TYPE_REMOTE_FAST, "test", true);
47 }
48
TearDownTestCase()49 void RemoteFastAudioCaptureSourceUnitTest::TearDownTestCase()
50 {
51 HdiAdapterManager::GetInstance().ReleaseId(id_);
52 }
53
SetUp()54 void RemoteFastAudioCaptureSourceUnitTest::SetUp()
55 {
56 source_ = HdiAdapterManager::GetInstance().GetCaptureSource(id_, true);
57 if (source_ == nullptr) {
58 return;
59 }
60 attr_.adapterName = "test";
61 attr_.channel = 2; // 2: channel
62 source_->Init(attr_);
63 }
64
TearDown()65 void RemoteFastAudioCaptureSourceUnitTest::TearDown()
66 {
67 if (source_ && source_->IsInited()) {
68 source_->DeInit();
69 }
70 source_ = nullptr;
71 }
72
73 /**
74 * @tc.name : Test RemoteFastSource API
75 * @tc.number : RemoteFastSourceUnitTest_001
76 * @tc.desc : Test remote fast source create
77 */
78 HWTEST_F(RemoteFastAudioCaptureSourceUnitTest, RemoteFastSourceUnitTest_001, TestSize.Level1)
79 {
80 EXPECT_TRUE(source_);
81 }
82
83 /**
84 * @tc.name : Test RemoteFastSource API
85 * @tc.number : RemoteFastSourceUnitTest_002
86 * @tc.desc : Test remote fast source deinit
87 */
88 HWTEST_F(RemoteFastAudioCaptureSourceUnitTest, RemoteFastSourceUnitTest_002, TestSize.Level1)
89 {
90 EXPECT_TRUE(source_);
91 source_->DeInit();
92 EXPECT_FALSE(source_->IsInited());
93 }
94
95 /**
96 * @tc.name : Test RemoteFastSource API
97 * @tc.number : RemoteFastSourceUnitTest_003
98 * @tc.desc : Test remote fast source start, stop, resume, pause, flush, reset
99 */
100 HWTEST_F(RemoteFastAudioCaptureSourceUnitTest, RemoteFastSourceUnitTest_003, TestSize.Level1)
101 {
102 EXPECT_TRUE(source_);
103 int32_t ret = source_->Start();
104 EXPECT_EQ(ret, ERR_NOT_STARTED);
105 ret = source_->Stop();
106 EXPECT_EQ(ret, SUCCESS);
107 ret = source_->Resume();
108 EXPECT_EQ(ret, ERR_ILLEGAL_STATE);
109 ret = source_->Pause();
110 EXPECT_EQ(ret, ERR_ILLEGAL_STATE);
111 ret = source_->Flush();
112 EXPECT_EQ(ret, ERR_ILLEGAL_STATE);
113 ret = source_->Reset();
114 EXPECT_EQ(ret, ERR_ILLEGAL_STATE);
115 ret = source_->Stop();
116 EXPECT_EQ(ret, SUCCESS);
117 }
118
119 } // namespace AudioStandard
120 } // namespace OHOS
121