1 /*
2 * Copyright (c) 2022-2023 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 #define private public
17 #include "screen_data_channel_impl_test.h"
18 #undef private
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace DistributedHardware {
SetUpTestCase(void)25 void ScreenDataChannelImplTest::SetUpTestCase(void) {}
26
TearDownTestCase(void)27 void ScreenDataChannelImplTest::TearDownTestCase(void) {}
28
SetUp(void)29 void ScreenDataChannelImplTest::SetUp(void)
30 {
31 std::string peerDevId = "test";
32 dataChannelImpl_ = std::make_shared<ScreenDataChannelImpl>(peerDevId);
33 }
34
TearDown(void)35 void ScreenDataChannelImplTest::TearDown(void)
36 {
37 dataChannelImpl_ = nullptr;
38 }
39
40 /**
41 * @tc.name: CreateSession_001
42 * @tc.desc: Verify the CreateSession function.
43 * @tc.type: FUNC
44 * @tc.require: Issue Number
45 */
46 HWTEST_F(ScreenDataChannelImplTest, CreateSession_001, TestSize.Level1)
47 {
48 std::shared_ptr<IScreenChannelListener> listener = nullptr;
49 int32_t ret = dataChannelImpl_->CreateSession(listener);
50
51 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret);
52 }
53
54 /**
55 * @tc.name: CreateSession_002
56 * @tc.desc: Verify the CreateSession function.
57 * @tc.type: FUNC
58 * @tc.require: Issue Number
59 */
60 HWTEST_F(ScreenDataChannelImplTest, CreateSession_002, TestSize.Level1)
61 {
62 std::shared_ptr<IScreenChannelListener> listener = std::make_shared<MockIScreenChannelListener>();
63 dataChannelImpl_->jpegSessionFlag_ = false;
64 int32_t ret = dataChannelImpl_->CreateSession(listener);
65
66 EXPECT_EQ(-1, ret);
67 }
68
69 /**
70 * @tc.name: OpenSession_001
71 * @tc.desc: Verify the OpenSession function.
72 * @tc.type: FUNC
73 * @tc.require: Issue Number
74 */
75 HWTEST_F(ScreenDataChannelImplTest, OpenSession_001, TestSize.Level1)
76 {
77 int32_t ret = dataChannelImpl_->OpenSession();
78
79 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, ret);
80 }
81
82 /**
83 * @tc.name: SendFullData_001
84 * @tc.desc: Verify the SendFullData function.
85 * @tc.type: FUNC
86 * @tc.require: Issue Number
87 */
88 HWTEST_F(ScreenDataChannelImplTest, SendFullData_001, TestSize.Level1)
89 {
90 std::shared_ptr<DataBuffer> screenData = nullptr;
91 int32_t ret = dataChannelImpl_->SendFullData(screenData);
92
93 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret);
94 }
95
96 /**
97 * @tc.name: SendFullData_002
98 * @tc.desc: Verify the SendFullData function.
99 * @tc.type: FUNC
100 * @tc.require: Issue Number
101 */
102 HWTEST_F(ScreenDataChannelImplTest, SendFullData_002, TestSize.Level1)
103 {
104 std::shared_ptr<DataBuffer> data = std::make_shared<DataBuffer>(10);
105 dataChannelImpl_->sessionId_ = 1;
106 int32_t ret = dataChannelImpl_->SendFullData(data);
107
108 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, ret);
109 }
110
111 /**
112 * @tc.name: SendDirtyData_001
113 * @tc.desc: Verify the SendDirtyData function.
114 * @tc.type: FUNC
115 * @tc.require: Issue Number
116 */
117 HWTEST_F(ScreenDataChannelImplTest, SendDirtyData_001, TestSize.Level1)
118 {
119 std::shared_ptr<DataBuffer> screenData = nullptr;
120 int32_t ret = dataChannelImpl_->SendDirtyData(screenData);
121
122 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret);
123 }
124
125 /**
126 * @tc.name: SendDirtyData_002
127 * @tc.desc: Verify the SendDirtyData function.
128 * @tc.type: FUNC
129 * @tc.require: Issue Number
130 */
131 HWTEST_F(ScreenDataChannelImplTest, SendDirtyData_002, TestSize.Level1)
132 {
133 std::shared_ptr<DataBuffer> data = std::make_shared<DataBuffer>(10);
134 dataChannelImpl_->jpegSessionId_ = 1;
135 int32_t ret = dataChannelImpl_->SendFullData(data);
136
137 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, ret);
138 }
139
140 /**
141 * @tc.name: release_session_test_002
142 * @tc.desc: Verify the ReleaseSession function.
143 * @tc.type: FUNC
144 * @tc.require: Issue Number
145 */
146 HWTEST_F(ScreenDataChannelImplTest, release_session_test_002, TestSize.Level1)
147 {
148 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION, dataChannelImpl_->ReleaseSession());
149 }
150
151 /**
152 * @tc.name: close_session_test_001
153 * @tc.desc: Verify the CloseSession function.
154 * @tc.type: FUNC
155 * @tc.require: Issue Number
156 */
157 HWTEST_F(ScreenDataChannelImplTest, close_session_test_001, TestSize.Level1)
158 {
159 dataChannelImpl_->sessionId_ = 1;
160 EXPECT_EQ(DH_SUCCESS, dataChannelImpl_->CloseSession());
161 }
162
163 /**
164 * @tc.name: close_session_test_002
165 * @tc.desc: Verify the CloseSession function.
166 * @tc.type: FUNC
167 * @tc.require: Issue Number
168 */
169 HWTEST_F(ScreenDataChannelImplTest, close_session_test_002, TestSize.Level1)
170 {
171 dataChannelImpl_->channelListener_ = std::make_shared<MockIScreenChannelListener>();
172
173 StreamData ext = {0};
174 StreamFrameInfo *param = nullptr;
175
176 int32_t sessionId = 0;
177 StreamData data;
178 data.buf = new char[DATA_LEN];
179 data.bufLen = DATA_LEN;
180
181 dataChannelImpl_->OnStreamReceived(sessionId, &data, &ext, param);
182 delete[] data.buf;
183 dataChannelImpl_->sessionId_ = 0;
184 EXPECT_EQ(ERR_DH_SCREEN_TRANS_SESSION_NOT_OPEN, dataChannelImpl_->CloseSession());
185 }
186
187 // /**
188 // * @tc.name: send_data_test_001
189 // * @tc.desc: Verify the SendData function.
190 // * @tc.type: FUNC
191 // * @tc.require: Issue Number
192 // */
193 HWTEST_F(ScreenDataChannelImplTest, send_data_test_001, TestSize.Level1)
194 {
195 std::shared_ptr<IScreenChannelListener> listener = nullptr;
196 dataChannelImpl_->channelListener_ = listener;
197 int32_t sessionId = 0;
198 dataChannelImpl_->OnSessionOpened(sessionId, 0);
199 dataChannelImpl_->OnSessionClosed(sessionId);
200 std::shared_ptr<DataBuffer> data = std::make_shared<DataBuffer>(10);
201 data->SetDataType(VIDEO_PART_SCREEN_DATA);
202 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, dataChannelImpl_->SendData(data));
203 }
204
205 /**
206 * @tc.name: send_data_test_002
207 * @tc.desc: Verify the SendData function.
208 * @tc.type: FUNC
209 * @tc.require: Issue Number
210 */
211 HWTEST_F(ScreenDataChannelImplTest, send_data_test_002, TestSize.Level1)
212 {
213 std::shared_ptr<IScreenChannelListener> listener = nullptr;
214 dataChannelImpl_->channelListener_ = listener;
215 int32_t sessionId = 0;
216 dataChannelImpl_->OnSessionOpened(sessionId, 0);
217 dataChannelImpl_->OnSessionClosed(sessionId);
218 std::shared_ptr<DataBuffer> data = nullptr;
219 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, dataChannelImpl_->SendData(data));
220 }
221
222 // /**
223 // * @tc.name: send_data_test_003
224 // * @tc.desc: Verify the SendData function.
225 // * @tc.type: FUNC
226 // * @tc.require: Issue Number
227 // */
228 HWTEST_F(ScreenDataChannelImplTest, send_data_test_003, TestSize.Level1)
229 {
230 std::shared_ptr<IScreenChannelListener> listener = nullptr;
231 dataChannelImpl_->channelListener_ = listener;
232 int32_t sessionId = 0;
233 dataChannelImpl_->OnSessionOpened(sessionId, 10);
234 dataChannelImpl_->OnSessionClosed(sessionId);
235 std::shared_ptr<DataBuffer> data = std::make_shared<DataBuffer>(10);
236 data->SetDataType(VIDEO_FULL_SCREEN_DATA);
237 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, dataChannelImpl_->SendData(data));
238 }
239
240 /**
241 * @tc.name: on_session_opened_test_001
242 * @tc.desc: Verify the OnSessionOpened function.
243 * @tc.type: FUNC
244 * @tc.require: Issue Number
245 */
246 HWTEST_F(ScreenDataChannelImplTest, on_session_opened_test_001, TestSize.Level1)
247 {
248 std::shared_ptr<IScreenChannelListener> listener = std::make_shared<MockIScreenChannelListener>();
249 dataChannelImpl_->channelListener_ = listener;
250 int32_t sessionId = 1;
251 dataChannelImpl_->OnSessionOpened(sessionId, 0);
252 EXPECT_EQ(sessionId, dataChannelImpl_->sessionId_);
253 }
254
255 /**
256 * @tc.name: on_session_opened_test_002
257 * @tc.desc: Verify the OnSessionOpened function.
258 * @tc.type: FUNC
259 * @tc.require: Issue Number
260 */
261 HWTEST_F(ScreenDataChannelImplTest, on_session_opened_test_002, TestSize.Level1)
262 {
263 dataChannelImpl_->channelListener_ = std::make_shared<MockIScreenChannelListener>();
264 dataChannelImpl_->OnSessionOpened(-1, -1);
265 EXPECT_EQ(0, dataChannelImpl_->sessionId_);
266 }
267 } // DistributedHardware
268 } // OHOS