1 /*
2 * Copyright (c) 2022 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_transport_pause_status_test.h"
17
18 #include "audio_transport_context.h"
19 #include "daudio_errorcode.h"
20 #include "daudio_log.h"
21 #include "daudio_util.h"
22 #include "mock_audio_data_channel.h"
23 #include "mock_audio_processor.h"
24 #include "securec.h"
25
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace DistributedHardware {
30
SetUpTestCase(void)31 void AudioTransportPauseStatusTest::SetUpTestCase(void)
32 {
33 }
34
TearDownTestCase(void)35 void AudioTransportPauseStatusTest::TearDownTestCase(void)
36 {
37 }
38
SetUp(void)39 void AudioTransportPauseStatusTest::SetUp(void)
40 {
41 stateContext_ = std::shared_ptr<AudioTransportContext>();
42 audioStatus_ = std::make_shared<AudioTransportPauseStatus>(stateContext_);
43 }
44
TearDown(void)45 void AudioTransportPauseStatusTest::TearDown(void)
46 {
47 stateContext_ = nullptr;
48 audioStatus_ = nullptr;
49 }
50
51 /**
52 * @tc.name: transport_pause_test_001
53 * @tc.desc: Verify start action when status is pause.
54 * @tc.type: FUNC
55 * @tc.require: AR000H0E5U
56 */
57 HWTEST_F(AudioTransportPauseStatusTest, transport_pause_test_001, TestSize.Level1)
58 {
59 std::string peerDevId = "peerDevId";
60 std::shared_ptr<IAudioChannel> audioChannel_ = std::make_shared<MockAudioDataChannel>(peerDevId);
61 std::shared_ptr<IAudioProcessor> processor_ = std::make_shared<MockIAudioProcessor>();
62 EXPECT_EQ(ERR_DH_AUDIO_TRANS_ILLEGAL_OPERATION, audioStatus_->Start(audioChannel_, processor_));
63 EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Stop(nullptr, processor_));
64 }
65
66 /**
67 * @tc.name: transport_pause_test_002
68 * @tc.desc: Verify stop action when status is pause.
69 * @tc.type: FUNC
70 * @tc.require: AR000H0E5U
71 */
72 HWTEST_F(AudioTransportPauseStatusTest, transport_pause_test_002, TestSize.Level1)
73 {
74 std::string peerDevId = "peerDevId";
75 std::shared_ptr<IAudioChannel> audioChannel_ = std::make_shared<MockAudioDataChannel>(peerDevId);
76 std::shared_ptr<IAudioProcessor> processor_ = std::make_shared<MockIAudioProcessor>();
77 EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Stop(audioChannel_, processor_));
78 }
79
80 /**
81 * @tc.name: transport_pause_test_003
82 * @tc.desc: Verify pause action when status is pause.
83 * @tc.type: FUNC
84 * @tc.require: AR000H0E5U
85 */
86 HWTEST_F(AudioTransportPauseStatusTest, transport_pause_test_003, TestSize.Level1)
87 {
88 std::string peerDevId = "peerDevId";
89 std::shared_ptr<IAudioChannel> audioChannel_ = std::make_shared<MockAudioDataChannel>(peerDevId);
90 std::shared_ptr<IAudioProcessor> processor_ = std::make_shared<MockIAudioProcessor>();
91 EXPECT_EQ(DH_SUCCESS, audioStatus_->Pause(processor_));
92 }
93
94 /**
95 * @tc.name: transport_pause_test_004
96 * @tc.desc: Verify reStart action when status is pause.
97 * @tc.type: FUNC
98 * @tc.require: AR000H0E5U
99 */
100 HWTEST_F(AudioTransportPauseStatusTest, transport_pause_test_004, TestSize.Level1)
101 {
102 AudioParam testLocalParaEnc = {
103 {
104 SAMPLE_RATE_48000,
105 STEREO,
106 SAMPLE_S16LE,
107 AUDIO_CODEC_FLAC
108 },
109 {
110 SOURCE_TYPE_INVALID,
111 NORMAL_MODE
112 },
113 {
114 CONTENT_TYPE_UNKNOWN,
115 STREAM_USAGE_UNKNOWN,
116 NORMAL_MODE
117 }
118 };
119 AudioParam testRemoteParaEnc = {
120 {
121 SAMPLE_RATE_48000,
122 STEREO,
123 SAMPLE_S16LE,
124 AUDIO_CODEC_FLAC
125 },
126 {
127 SOURCE_TYPE_INVALID,
128 NORMAL_MODE
129 },
130 {
131 CONTENT_TYPE_UNKNOWN,
132 STREAM_USAGE_UNKNOWN,
133 NORMAL_MODE
134 }
135 };
136 std::string peerDevId = "peerDevId";
137 EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Restart(testLocalParaEnc, testRemoteParaEnc, nullptr));
138
139 std::shared_ptr<IAudioChannel> audioChannel_ = std::make_shared<MockAudioDataChannel>(peerDevId);
140 std::shared_ptr<IAudioProcessor> processor_ = std::make_shared<MockIAudioProcessor>();
141 EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Restart(testLocalParaEnc, testRemoteParaEnc, processor_));
142 }
143
144 /**
145 * @tc.name: transport_getstatetype_test_001
146 * @tc.desc: Verify pause action when status is start.
147 * @tc.type: FUNC
148 * @tc.require: AR000H0E5U
149 */
150 HWTEST_F(AudioTransportPauseStatusTest, transport_getstatetype_test_001, TestSize.Level1)
151 {
152 EXPECT_EQ(TRANSPORT_STATE_PAUSE, audioStatus_->GetStateType());
153 }
154 } // namespace DistributedHardware
155 } // namespace OHOS
156