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_ctrl_transport_test.h"
17 using namespace testing::ext;
18
19 namespace OHOS {
20 namespace DistributedHardware {
SetUpTestCase(void)21 void AudioCtrlTransportTest::SetUpTestCase(void) {}
22
TearDownTestCase(void)23 void AudioCtrlTransportTest::TearDownTestCase(void) {}
24
SetUp(void)25 void AudioCtrlTransportTest::SetUp(void)
26 {
27 std::string peerDevId = "peerDevId";
28 trans = std::make_shared<AudioCtrlTransport>(peerDevId);
29 }
30
TearDown(void)31 void AudioCtrlTransportTest::TearDown(void) {}
32
33 /**
34 * @tc.name: SetUp_001
35 * @tc.desc: Verify the SetUp function.
36 * @tc.type: FUNC
37 * @tc.require: AR000H0E5U
38 */
39 HWTEST_F(AudioCtrlTransportTest, SetUp_001, TestSize.Level1)
40 {
41 std::shared_ptr<IAudioCtrlTransCallback> callback = nullptr;
42 EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, trans->SetUp(callback));
43 }
44
45 /**
46 * @tc.name: SetUp_002
47 * @tc.desc: Verify the SetUp function.
48 * @tc.type: FUNC
49 * @tc.require: AR000H0E5U
50 */
51 HWTEST_F(AudioCtrlTransportTest, SetUp_002, TestSize.Level1)
52 {
53 std::string peerDevId = "peerDevId";
54 std::shared_ptr<IAudioCtrlTransCallback> callback = std::make_shared<MockIAudioCtrlTransCallback>();
55 trans->audioChannel_ = std::make_shared<MockAudioCtrlChannel>(peerDevId);
56 EXPECT_EQ(DH_SUCCESS, trans->SetUp(callback));
57 }
58
59 /**
60 * @tc.name: Release_001
61 * @tc.desc: Verify the Release function.
62 * @tc.type: FUNC
63 * @tc.require: AR000H0E5U
64 */
65 HWTEST_F(AudioCtrlTransportTest, Release_001, TestSize.Level1)
66 {
67 EXPECT_EQ(DH_SUCCESS, trans->Release());
68 }
69
70 /**
71 * @tc.name: Release_002
72 * @tc.desc: Verify the Release function.
73 * @tc.type: FUNC
74 * @tc.require: AR000H0E5U
75 */
76 HWTEST_F(AudioCtrlTransportTest, Release_002, TestSize.Level1)
77 {
78 std::string peerDevId = "peerDevId";
79 trans->audioChannel_ = std::make_shared<MockAudioCtrlChannel>(peerDevId);
80 EXPECT_EQ(DH_SUCCESS, trans->Release());
81 }
82
83 /**
84 * @tc.name: Start_001
85 * @tc.desc: Verify the Start function.
86 * @tc.type: FUNC
87 * @tc.require: AR000H0E5U
88 */
89 HWTEST_F(AudioCtrlTransportTest, Start_001, TestSize.Level1)
90 {
91 trans->OnSessionOpened();
92 EXPECT_EQ(ERR_DH_AUDIO_TRANS_NULL_VALUE, trans->Start());
93 }
94
95 /**
96 * @tc.name: Start_002
97 * @tc.desc: Verify the Start function.
98 * @tc.type: FUNC
99 * @tc.require: AR000H0E5U
100 */
101 HWTEST_F(AudioCtrlTransportTest, Start_002, TestSize.Level1)
102 {
103 std::string peerDevId = "peerDevId";
104 trans->audioChannel_ = std::make_shared<MockAudioCtrlChannel>(peerDevId);
105 EXPECT_EQ(DH_SUCCESS, trans->Start());
106 }
107
108 /**
109 * @tc.name: Stop_001
110 * @tc.desc: Verify the Stop function.
111 * @tc.type: FUNC
112 * @tc.require: AR000H0E5U
113 */
114 HWTEST_F(AudioCtrlTransportTest, Stop_001, TestSize.Level1)
115 {
116 AudioEvent event;
117 trans->OnEventReceived(event);
118 trans->OnSessionClosed();
119 EXPECT_EQ(DH_SUCCESS, trans->Stop());
120 }
121
122 /**
123 * @tc.name: Stop_002
124 * @tc.desc: Verify the Stop function.
125 * @tc.type: FUNC
126 * @tc.require: AR000H0E5U
127 */
128 HWTEST_F(AudioCtrlTransportTest, Stop_002, TestSize.Level1)
129 {
130 std::string peerDevId = "peerDevId";
131 trans->audioChannel_ = std::make_shared<MockAudioCtrlChannel>(peerDevId);
132 EXPECT_EQ(DH_SUCCESS, trans->Stop());
133 }
134
135 /**
136 * @tc.name: SendAudioEvent_001
137 * @tc.desc: Verify the SendAudioEvent function.
138 * @tc.type: FUNC
139 * @tc.require: AR000H0E5U
140 */
141 HWTEST_F(AudioCtrlTransportTest, SendAudioEvent_001, TestSize.Level1)
142 {
143 std::string peerDevId = "peerDevId";
144 trans->audioChannel_ = std::make_shared<MockAudioCtrlChannel>(peerDevId);
145 AudioEvent event ;
146 EXPECT_EQ(DH_SUCCESS, trans->SendAudioEvent(event));
147 }
148
149 /**
150 * @tc.name: SendAudioEvent_002
151 * @tc.desc: Verify the SendAudioEvent function.
152 * @tc.type: FUNC
153 * @tc.require: AR000H0E5U
154 */
155 HWTEST_F(AudioCtrlTransportTest, SendAudioEvent_002, TestSize.Level1)
156 {
157 AudioEvent event ;
158 EXPECT_EQ(ERR_DH_AUDIO_TRANS_NULL_VALUE, trans->SendAudioEvent(event));
159 }
160
161 /**
162 * @tc.name: RegisterChannelListener_001
163 * @tc.desc: Verify the RegisterChannelListener function.
164 * @tc.type: FUNC
165 * @tc.require: AR000H0E5U
166 */
167 HWTEST_F(AudioCtrlTransportTest, RegisterChannelListener_001, TestSize.Level1)
168 {
169 std::shared_ptr<IAudioChannelListener> listener = nullptr;
170 EXPECT_EQ(ERR_DH_AUDIO_TRANS_NULL_VALUE, trans->RegisterChannelListener());
171 }
172
173 /**
174 * @tc.name: RegisterChannelListener_002
175 * @tc.desc: Verify the RegisterChannelListener function.
176 * @tc.type: FUNC
177 * @tc.require: AR000H0E5U
178 */
179 HWTEST_F(AudioCtrlTransportTest, RegisterChannelListener_002, TestSize.Level1)
180 {
181 std::string peerDevId = "peerDevId";
182 trans->audioChannel_ = std::make_shared<MockAudioCtrlChannel>(peerDevId);
183 std::shared_ptr<IAudioChannelListener> listener = std::make_shared<MockIAudioChannelListener>();
184 EXPECT_EQ(DH_SUCCESS, trans->RegisterChannelListener());
185 }
186
187 /**
188 * @tc.name: InitAudioCtrlTrans_002
189 * @tc.desc: Verify the InitAudioCtrlTrans function.
190 * @tc.type: FUNC
191 * @tc.require: AR000H0E5U
192 */
193 HWTEST_F(AudioCtrlTransportTest, InitAudioCtrlTrans_002, TestSize.Level1)
194 {
195 std::string peerDevId = "peerDevId";
196 const std::string netWorkId = "netWorkId";
197 trans->audioChannel_ = std::make_shared<MockAudioCtrlChannel>(peerDevId);
198 EXPECT_EQ(DH_SUCCESS, trans->InitAudioCtrlTrans(netWorkId));
199 }
200 } // namespace DistributedHardware
201 } // namespace OHOS
202