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_stop_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 AudioTransportStopStatusTest::SetUpTestCase(void)
32 {
33 }
34
TearDownTestCase(void)35 void AudioTransportStopStatusTest::TearDownTestCase(void)
36 {
37 }
38
SetUp(void)39 void AudioTransportStopStatusTest::SetUp(void)
40 {
41 audioChannel_ = std::shared_ptr<MockAudioDataChannel>();
42 processor_ = std::shared_ptr<MockIAudioProcessor>();
43 stateContext_ = std::shared_ptr<AudioTransportContext>();
44 audioStatus_ = std::make_shared<AudioTransportStopStatus>(stateContext_);
45 }
46
TearDown(void)47 void AudioTransportStopStatusTest::TearDown(void)
48 {
49 audioChannel_ = nullptr;
50 processor_ = nullptr;
51 stateContext_ = nullptr;
52 audioStatus_ = nullptr;
53 }
54
55 /**
56 * @tc.name: transport_stop_test_001
57 * @tc.desc: Verify start action when status is stop.
58 * @tc.type: FUNC
59 * @tc.require: AR000H0E5U
60 */
61 HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_001, TestSize.Level1)
62 {
63 std::string peerDevId = "peerDevId";
64 std::shared_ptr<IAudioChannel> audioChannel_ = std::make_shared<MockAudioDataChannel>(peerDevId);
65 std::shared_ptr<IAudioProcessor> processor_ = std::make_shared<MockIAudioProcessor>();
66 EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioStatus_->Start(audioChannel_, processor_));
67 EXPECT_EQ(DH_SUCCESS, audioStatus_->Stop(audioChannel_, processor_));
68 }
69
70 /**
71 * @tc.name: transport_stop_test_002
72 * @tc.desc: Verify stop action when status is stop.
73 * @tc.type: FUNC
74 * @tc.require: AR000H0E5U
75 */
76 HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_002, TestSize.Level1)
77 {
78 EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Start(audioChannel_, nullptr));
79 EXPECT_EQ(DH_SUCCESS, audioStatus_->Stop(audioChannel_, processor_));
80 }
81
82 /**
83 * @tc.name: transport_stop_test_003
84 * @tc.desc: Verify pause action when status is stop.
85 * @tc.type: FUNC
86 * @tc.require: AR000H0E5U
87 */
88 HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_003, TestSize.Level1)
89 {
90 EXPECT_EQ(ERR_DH_AUDIO_TRANS_ILLEGAL_OPERATION, audioStatus_->Pause(processor_));
91 }
92
93 /**
94 * @tc.name: transport_stop_test_004
95 * @tc.desc: Verify reStart action when status is stop.
96 * @tc.type: FUNC
97 * @tc.require: AR000H0E5U
98 */
99 HWTEST_F(AudioTransportStopStatusTest, transport_stop_test_004, TestSize.Level1)
100 {
101 AudioParam testLocalParaEnc = {
102 {
103 SAMPLE_RATE_48000,
104 STEREO,
105 SAMPLE_S16LE,
106 AUDIO_CODEC_FLAC
107 },
108 {
109 SOURCE_TYPE_INVALID,
110 NORMAL_MODE
111 },
112 {
113 CONTENT_TYPE_UNKNOWN,
114 STREAM_USAGE_UNKNOWN,
115 NORMAL_MODE
116 }
117 };
118 AudioParam testRemoteParaEnc = {
119 {
120 SAMPLE_RATE_48000,
121 STEREO,
122 SAMPLE_S16LE,
123 AUDIO_CODEC_FLAC
124 },
125 {
126 SOURCE_TYPE_INVALID,
127 NORMAL_MODE
128 },
129 {
130 CONTENT_TYPE_UNKNOWN,
131 STREAM_USAGE_UNKNOWN,
132 NORMAL_MODE
133 }
134 };
135 EXPECT_EQ(ERR_DH_AUDIO_TRANS_ILLEGAL_OPERATION,
136 audioStatus_->Restart(testLocalParaEnc, testRemoteParaEnc, processor_));
137 }
138
139 /**
140 * @tc.name: transport_getstatetype_test_001
141 * @tc.desc: Verify pause action when status is start.
142 * @tc.type: FUNC
143 * @tc.require: AR000H0E5U
144 */
145 HWTEST_F(AudioTransportStopStatusTest, transport_getstatetype_test_001, TestSize.Level1)
146 {
147 EXPECT_EQ(TRANSPORT_STATE_STOP, audioStatus_->GetStateType());
148 }
149 } // namespace DistributedHardware
150 } // namespace OHOS
151