• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_start_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 AudioTransportStartStatusTest::SetUpTestCase(void)
32 {
33 }
34 
TearDownTestCase(void)35 void AudioTransportStartStatusTest::TearDownTestCase(void)
36 {
37 }
38 
SetUp(void)39 void AudioTransportStartStatusTest::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<AudioTransportStartStatus>(stateContext_);
45 }
46 
TearDown(void)47 void AudioTransportStartStatusTest::TearDown(void)
48 {
49     audioChannel_ = nullptr;
50     processor_ = nullptr;
51     stateContext_ = nullptr;
52     audioStatus_ = nullptr;
53 }
54 
55 /**
56  * @tc.name: transport_start_test_001
57  * @tc.desc: Verify start action when status is start.
58  * @tc.type: FUNC
59  * @tc.require: AR000H0E5U
60  */
61 HWTEST_F(AudioTransportStartStatusTest, transport_start_test_001, TestSize.Level1)
62 {
63     EXPECT_EQ(DH_SUCCESS, audioStatus_->Start(audioChannel_, processor_));
64 }
65 
66 /**
67  * @tc.name: transport_Stop_test_001
68  * @tc.desc: Verify stop action when status is stop.
69  * @tc.type: FUNC
70  * @tc.require: AR000H0E5U
71  */
72 HWTEST_F(AudioTransportStartStatusTest, transport_Stop_test_001, TestSize.Level1)
73 {
74     EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Stop(audioChannel_, processor_));
75 }
76 
77 /**
78  * @tc.name: transport_stop_test_002
79  * @tc.desc: Verify stop action when status is start.
80  * @tc.type: FUNC
81  * @tc.require: AR000H0E5U
82  */
83 HWTEST_F(AudioTransportStartStatusTest, transport_stop_test_002, TestSize.Level1)
84 {
85     std::shared_ptr<IAudioProcessor> processor_ = std::make_shared<MockIAudioProcessor>();
86     EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Stop(audioChannel_, processor_));
87 }
88 
89 /**
90  * @tc.name: transport_Pause_test_001
91  * @tc.desc: Verify pause action when status is start.
92  * @tc.type: FUNC
93  * @tc.require: AR000H0E5U
94  */
95 HWTEST_F(AudioTransportStartStatusTest, transport_pause_test_001, TestSize.Level1)
96 {
97     EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, audioStatus_->Pause(processor_));
98 }
99 
100 /**
101  * @tc.name: transport_Pause_test_002
102  * @tc.desc: Verify pause action when status is start.
103  * @tc.type: FUNC
104  * @tc.require: AR000H0E5U
105  */
106 HWTEST_F(AudioTransportStartStatusTest, transport_Pause_test_002, TestSize.Level1)
107 {
108     processor_ = std::make_shared<MockIAudioProcessor>();
109     EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, audioStatus_->Pause(processor_));
110 }
111 
112 /**
113  * @tc.name: transport_Restart_test_001
114  * @tc.desc: Verify action when status is start.
115  * @tc.type: FUNC
116  * @tc.require: AR000H0E5U
117  */
118 HWTEST_F(AudioTransportStartStatusTest, transport_restart_test_001, TestSize.Level1)
119 {
120     AudioParam testLocalParaEnc = {
121         {
122             SAMPLE_RATE_48000,
123             STEREO,
124             SAMPLE_S16LE,
125             AUDIO_CODEC_FLAC
126         },
127         {
128             SOURCE_TYPE_INVALID,
129             NORMAL_MODE
130         },
131         {
132             CONTENT_TYPE_UNKNOWN,
133             STREAM_USAGE_UNKNOWN,
134             NORMAL_MODE
135         }
136     };
137     AudioParam testRemoteParaEnc = {
138         {
139             SAMPLE_RATE_48000,
140             STEREO,
141             SAMPLE_S16LE,
142             AUDIO_CODEC_FLAC
143         },
144         {
145             SOURCE_TYPE_INVALID,
146             NORMAL_MODE
147         },
148         {
149             CONTENT_TYPE_UNKNOWN,
150             STREAM_USAGE_UNKNOWN,
151             NORMAL_MODE
152         }
153     };
154     EXPECT_EQ(DH_SUCCESS, audioStatus_->Restart(testLocalParaEnc, testRemoteParaEnc, processor_));
155 }
156 
157 /**
158  * @tc.name: transport_getstatetype_test_001
159  * @tc.desc: Verify pause action when status is start.
160  * @tc.type: FUNC
161  * @tc.require: AR000H0E5U
162  */
163 HWTEST_F(AudioTransportStartStatusTest, transport_getstatetype_test_001, TestSize.Level1)
164 {
165     EXPECT_EQ(TRANSPORT_STATE_START, audioStatus_->GetStateType());
166 }
167 } // namespace DistributedHardware
168 } // namespace OHOS
169