1 /*
2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 "rtsp_unit_test.h"
17 #include <iostream>
18 #include "protocol/rtsp/include/rtsp_common.h"
19 #include "protocol/rtsp/include/rtsp_request.h"
20 #include "protocol/rtsp/include/rtsp_response.h"
21 #include "protocol/rtsp/include/rtsp_sdp.h"
22
23 using namespace testing::ext;
24 using namespace OHOS::Sharing;
25
26 namespace OHOS {
27 namespace Sharing {
28
SetUpTestCase()29 void RtspUnitTest::SetUpTestCase() {}
TearDownTestCase()30 void RtspUnitTest::TearDownTestCase() {}
SetUp()31 void RtspUnitTest::SetUp() {}
TearDown()32 void RtspUnitTest::TearDown() {}
33
34 namespace {
35
36 HWTEST_F(RtspUnitTest, RtspUnitTest_001, Function | SmallTest | Level2)
37 {
38 auto ret = RtspCommon::GetRtspDate();
39 ASSERT_TRUE(ret != "");
40 }
41
42 HWTEST_F(RtspUnitTest, RtspUnitTest_002, Function | SmallTest | Level2)
43 {
44 const std::string str = "123";
45 auto ret = RtspCommon::Trim(str);
46 EXPECT_EQ(ret, str);
47 const std::string str1 = " 123";
48 auto ret1 = RtspCommon::Trim(str1);
49 EXPECT_EQ(ret1, str);
50 const std::string str2 = "123 ";
51 auto ret2 = RtspCommon::Trim(str2);
52 EXPECT_EQ(ret2, str);
53 const std::string str3 = " 123 ";
54 auto ret3 = RtspCommon::Trim(str3);
55 EXPECT_EQ(ret3, str);
56 }
57
58 HWTEST_F(RtspUnitTest, RtspUnitTest_003, Function | SmallTest | Level2)
59 {
60 const std::string str = "12 3";
61 auto ret = RtspCommon::Trim(str);
62 EXPECT_EQ(ret, str);
63 const std::string str1 = " 12 3";
64 auto ret1 = RtspCommon::Trim(str1);
65 EXPECT_EQ(ret1, str);
66 const std::string str2 = "12 3 ";
67 auto ret2 = RtspCommon::Trim(str2);
68 EXPECT_EQ(ret2, str);
69 const std::string str3 = " 12 3 ";
70 auto ret3 = RtspCommon::Trim(str3);
71 EXPECT_EQ(ret3, str);
72 }
73
74 HWTEST_F(RtspUnitTest, RtspUnitTest_004, Function | SmallTest | Level2)
75 {
76 const std::string method = RTSP_METHOD_OPTIONS;
77 auto ret = RtspCommon::VerifyMethod(method);
78 EXPECT_EQ(ret, true);
79 }
80
81 HWTEST_F(RtspUnitTest, RtspUnitTest_005, Function | SmallTest | Level2)
82 {
83 const std::string method = RTSP_METHOD_DESCRIBE;
84 auto ret = RtspCommon::VerifyMethod(method);
85 EXPECT_EQ(ret, true);
86 }
87
88 HWTEST_F(RtspUnitTest, RtspUnitTest_006, Function | SmallTest | Level2)
89 {
90 const std::string method = RTSP_METHOD_ANNOUNCE;
91 auto ret = RtspCommon::VerifyMethod(method);
92 EXPECT_EQ(ret, true);
93 }
94
95 HWTEST_F(RtspUnitTest, RtspUnitTest_007, Function | SmallTest | Level2)
96 {
97 const std::string method = RTSP_METHOD_SETUP;
98 auto ret = RtspCommon::VerifyMethod(method);
99 EXPECT_EQ(ret, true);
100 }
101
102 HWTEST_F(RtspUnitTest, RtspUnitTest_008, Function | SmallTest | Level2)
103 {
104 const std::string method = RTSP_METHOD_PLAY;
105 auto ret = RtspCommon::VerifyMethod(method);
106 EXPECT_EQ(ret, true);
107 }
108
109 HWTEST_F(RtspUnitTest, RtspUnitTest_009, Function | SmallTest | Level2)
110 {
111 const std::string method = RTSP_METHOD_PAUSE;
112 auto ret = RtspCommon::VerifyMethod(method);
113 EXPECT_EQ(ret, true);
114 }
115
116 HWTEST_F(RtspUnitTest, RtspUnitTest_010, Function | SmallTest | Level2)
117 {
118 const std::string method = RTSP_METHOD_TEARDOWN;
119 auto ret = RtspCommon::VerifyMethod(method);
120 EXPECT_EQ(ret, true);
121 }
122
123 HWTEST_F(RtspUnitTest, RtspUnitTest_011, Function | SmallTest | Level2)
124 {
125 const std::string method = RTSP_METHOD_GET_PARAMETER;
126 auto ret = RtspCommon::VerifyMethod(method);
127 EXPECT_EQ(ret, true);
128 }
129
130 HWTEST_F(RtspUnitTest, RtspUnitTest_012, Function | SmallTest | Level2)
131 {
132 const std::string method = RTSP_METHOD_SET_PARAMETER;
133 auto ret = RtspCommon::VerifyMethod(method);
134 EXPECT_EQ(ret, true);
135 }
136
137 HWTEST_F(RtspUnitTest, RtspUnitTest_013, Function | SmallTest | Level2)
138 {
139 const std::string method = RTSP_METHOD_REDIRECT;
140 auto ret = RtspCommon::VerifyMethod(method);
141 EXPECT_EQ(ret, true);
142 }
143
144 HWTEST_F(RtspUnitTest, RtspUnitTest_014, Function | SmallTest | Level2)
145 {
146 const std::string method = RTSP_METHOD_RECORD;
147 auto ret = RtspCommon::VerifyMethod(method);
148 EXPECT_EQ(ret, true);
149 }
150
151 HWTEST_F(RtspUnitTest, RtspUnitTest_015, Function | SmallTest | Level2)
152 {
153 const std::string method = "unknown";
154 auto ret = RtspCommon::VerifyMethod(method);
155 EXPECT_NE(ret, true);
156 }
157
158 HWTEST_F(RtspUnitTest, RtspUnitTest_016, Function | SmallTest | Level2)
159 {
160 const std::string str = "str";
161 const std::string delimiter = "s";
162 auto ret = RtspCommon::Split(str, delimiter);
163 ASSERT_TRUE(ret.size() > 0);
164 }
165
166 HWTEST_F(RtspUnitTest, RtspUnitTest_017, Function | SmallTest | Level2)
167 {
168 std::list<std::string> lines;
169 std::list<std::pair<std::string, std::string>> params;
170 lines.push_front("key:12");
171 lines.push_front("key2:212");
172 lines.push_front("key3:3212");
173 RtspCommon::SplitParameter(lines, params);
174 ASSERT_TRUE(params.size() == 3);
175 }
176
177 HWTEST_F(RtspUnitTest, RtspUnitTest_018, Function | SmallTest | Level2)
178 {
179 const std::string message =
180 "Request: GET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\r\nCSeq: 2\r\nContent-type: text/parameters";
181 std::vector<std::string> firstLine;
182 std::unordered_map<std::string, std::string> header;
183 std::list<std::string> body;
184 auto ret = RtspCommon::ParseMessage(message, firstLine, header, body);
185 ASSERT_TRUE(ret.code == RtspErrorType::OK);
186 }
187
188 HWTEST_F(RtspUnitTest, RtspUnitTest_020, Function | SmallTest | Level2)
189 {
190 auto request = std::make_shared<RtspRequest>();
191 EXPECT_NE(request, nullptr);
192 }
193
194 HWTEST_F(RtspUnitTest, RtspUnitTest_021, Function | SmallTest | Level2)
195 {
196 const std::string &request =
197 "OPTIONS * RTSP/1.0\r\nCSeq: 1\r\nUser-Agent: KaihongOS\r\nRequire: org.wfa.wfd1.0\r\n";
198 auto rtspRequest = std::make_shared<RtspRequest>(request);
199 EXPECT_NE(rtspRequest, nullptr);
200 }
201
202 HWTEST_F(RtspUnitTest, RtspUnitTest_022, Function | SmallTest | Level2)
203 {
204 const std::string &method = RTSP_METHOD_OPTIONS;
205 int32_t cseq = 1;
206 const std::string &url = "rtsp://192.168.49.1/wfd1.0/streamid=0 RTSP/1.0\r\n";
207 auto request = std::make_shared<RtspRequest>(method, cseq, url);
208 EXPECT_NE(request, nullptr);
209 }
210
211 HWTEST_F(RtspUnitTest, RtspUnitTest_023, Function | SmallTest | Level2)
212 {
213 const std::string &method = RTSP_METHOD_OPTIONS;
214 auto request = std::make_shared<RtspRequest>();
215 EXPECT_NE(request, nullptr);
216 request->SetMethod(method);
217 auto ret = request->GetMethod();
218 EXPECT_EQ(ret, method);
219 }
220
221 HWTEST_F(RtspUnitTest, RtspUnitTest_024, Function | SmallTest | Level2)
222 {
223 int32_t cseq = 1;
224 auto request = std::make_shared<RtspRequest>();
225 EXPECT_NE(request, nullptr);
226 request->SetCSeq(cseq);
227 auto ret = request->GetCSeq();
228 EXPECT_EQ(ret, cseq);
229 }
230
231 HWTEST_F(RtspUnitTest, RtspUnitTest_025, Function | SmallTest | Level2)
232 {
233 const std::string &url = "rtsp://192.168.49.1/wfd1.0/streamid=0 RTSP/1.0\r\n";
234 auto request = std::make_shared<RtspRequest>();
235 EXPECT_NE(request, nullptr);
236 request->SetUrl(url);
237 auto ret = request->GetUrl();
238 EXPECT_EQ(ret, url);
239 }
240
241 HWTEST_F(RtspUnitTest, RtspUnitTest_027, Function | SmallTest | Level2)
242 {
243 const std::string &userAgent = "userAgent";
244 auto request = std::make_shared<RtspRequest>();
245 EXPECT_NE(request, nullptr);
246 request->SetUserAgent(userAgent);
247 auto ret = request->GetUserAgent();
248 EXPECT_EQ(ret, userAgent);
249 }
250
251 HWTEST_F(RtspUnitTest, RtspUnitTest_028, Function | SmallTest | Level2)
252 {
253 const std::string &session = "session";
254 auto request = std::make_shared<RtspRequest>();
255 EXPECT_NE(request, nullptr);
256 request->SetSession(session);
257 auto ret = request->GetSession();
258 EXPECT_EQ(ret, session);
259 }
260
261 HWTEST_F(RtspUnitTest, RtspUnitTest_029, Function | SmallTest | Level2)
262 {
263 int32_t timeout = 10;
264 auto request = std::make_shared<RtspRequest>();
265 EXPECT_NE(request, nullptr);
266 request->SetTimeout(timeout);
267 EXPECT_EQ(timeout, request->timeout_);
268 }
269
270 HWTEST_F(RtspUnitTest, RtspUnitTest_030, Function | SmallTest | Level2)
271 {
272 const std::string &header = "header";
273 auto request = std::make_shared<RtspRequest>();
274 EXPECT_NE(request, nullptr);
275 request->AddCustomHeader(header);
276 EXPECT_EQ(header, request->customHeaders_);
277 request->ClearCustomHeader();
278 EXPECT_EQ(request->customHeaders_, "");
279 }
280
281 HWTEST_F(RtspUnitTest, RtspUnitTest_031, Function | SmallTest | Level2)
282 {
283 auto request = std::make_shared<RtspRequest>();
284 EXPECT_NE(request, nullptr);
285 auto ret = request->GetBody();
286 EXPECT_EQ(ret.size(), 0);
287 }
288
289 HWTEST_F(RtspUnitTest, RtspUnitTest_032, Function | SmallTest | Level2)
290 {
291 const std::string &method = RTSP_METHOD_OPTIONS;
292 int32_t cseq = 1;
293 const std::string &url = "rtsp://192.168.49.1/wfd1.0/streamid=0 RTSP/1.0\r\n";
294 auto request = std::make_shared<RtspRequest>(method, cseq, url);
295 EXPECT_NE(request, nullptr);
296 auto ret = request->Stringify();
297 EXPECT_NE(ret, "");
298 }
299
300 HWTEST_F(RtspUnitTest, RtspUnitTest_033, Function | SmallTest | Level2)
301 {
302 auto rtspRequest = std::make_shared<RtspRequest>();
303 EXPECT_NE(rtspRequest, nullptr);
304 const std::string &request =
305 "OPTIONS * RTSP/1.0\r\nCSeq: 1\r\nUser-Agent: KaihongOS\r\nRequire: org.wfa.wfd1.0\r\n";
306 auto ret = rtspRequest->Parse(request);
307 EXPECT_EQ(ret.code, RtspErrorType::OK);
308 }
309
310 HWTEST_F(RtspUnitTest, RtspUnitTest_034, Function | SmallTest | Level2)
311 {
312 auto request = std::make_shared<RtspRequest>();
313 EXPECT_NE(request, nullptr);
314 const std::string token = "token";
315 const std::string value = "value";
316 request->tokens_[token] = value;
317 auto ret = request->GetToken(token);
318 EXPECT_EQ(ret, value);
319 }
320
321 HWTEST_F(RtspUnitTest, RtspUnitTest_035, Function | SmallTest | Level2)
322 {
323 auto response = std::make_shared<RtspResponse>();
324 EXPECT_NE(response, nullptr);
325 }
326
327 HWTEST_F(RtspUnitTest, RtspUnitTest_036, Function | SmallTest | Level2)
328 {
329 int32_t cseq = 1;
330 int32_t status = 200;
331 auto response = std::make_shared<RtspResponse>(cseq, status);
332 EXPECT_NE(response, nullptr);
333 }
334
335 HWTEST_F(RtspUnitTest, RtspUnitTest_037, Function | SmallTest | Level2)
336 {
337 auto response = std::make_shared<RtspResponse>();
338 EXPECT_NE(response, nullptr);
339 const std::string &header = "header";
340 response->AddCustomHeader(header);
341 EXPECT_EQ(header, response->customHeaders_);
342 response->ClearCustomHeader();
343 EXPECT_EQ(response->customHeaders_, "");
344 }
345
346 HWTEST_F(RtspUnitTest, RtspUnitTest_038, Function | SmallTest | Level2)
347 {
348 int32_t timeout = 10;
349 auto response = std::make_shared<RtspResponse>();
350 EXPECT_NE(response, nullptr);
351 response->SetTimeout(timeout);
352 auto ret = response->GetTimeout();
353 EXPECT_EQ(ret, timeout);
354 }
355
356 HWTEST_F(RtspUnitTest, RtspUnitTest_039, Function | SmallTest | Level2)
357 {
358 const std::string &session = "session";
359 auto response = std::make_shared<RtspResponse>();
360 EXPECT_NE(response, nullptr);
361 response->SetSession(session);
362 auto ret = response->GetSession();
363 EXPECT_EQ(ret, session);
364 }
365
366 HWTEST_F(RtspUnitTest, RtspUnitTest_040, Function | SmallTest | Level2)
367 {
368 int32_t cseq = 1;
369 int32_t status = 200;
370 auto response = std::make_shared<RtspResponse>(cseq, status);
371 EXPECT_NE(response, nullptr);
372 auto ret = response->GetCSeq();
373 EXPECT_EQ(ret, cseq);
374 }
375
376 HWTEST_F(RtspUnitTest, RtspUnitTest_041, Function | SmallTest | Level2)
377 {
378 const std::string &responseMsg =
379 "RTSP/1.0 200 OK\r\nCSeq: 2\r\nDate: Thu, Nov 09 2023 08:43:36 GMT\r\nContent-Type: text/parameters\r\n"
380 "Content-Length: 961\r\n\r\n"
381 "wfd_video_formats : 38 00 02 10 00000080 00000000 00000000 00 0000 0000 00 none none\r\n"
382 "wfd_audio_codecs: AAC 00000001 00\r\nwfd_client_rtp_ports: RTP/AVP/UDP;unicast 6700 0 mode=play"
383 "\r\nwfd_display_edid: none\r\nwfd_connector_type: none\r\nwfd_uibc_capability: none\r\n"
384 "wfd2_rotation_capability: none\r\nwfd2_video_formats: none\r\n"
385 "wfd2_audio_codecs: none\r\nwfd2_video_stream_control: none\r\n"
386 "wfd_content_protection: none\r\nwfd_idr_request_capability: none\r\n"
387 "intel_friendly_name: none\r\nintel_sink_manufacturer_name: none\r\n"
388 "intel_sink_model_name: none\r\nintel_sink_version: none\r\n"
389 "intel_sink_device_URL: none\r\nmicrosoft_latency_management_capability: none\r\n"
390 "microsoft_format_change_capability: none\r\n"
391 "microsoft_diagnostics_capability: none\r\nmicrosoft_cursor: none\r\n"
392 "microsoft_rtcp_capability: none\r\n"
393 "microsoft_video_formats: none\r\n"
394 "microsoft_max_bitrate: none\r\nmicrosoft_multiscreen_projection: none\r\n"
395 "microsoft_audio_mute: none\r\nmicrosoft_color_space_conversion: none\r\nwfd_connector_type: 5\r\n";
396 int32_t cseq = 1;
397 int32_t status = 200;
398 auto response = std::make_shared<RtspResponse>(cseq, status);
399 EXPECT_NE(response, nullptr);
400 auto ret = response->Parse(responseMsg);
401 ASSERT_TRUE(ret.code == RtspErrorType::OK);
402 auto date = response->GetDate();
403 EXPECT_NE(date, "");
404 auto statusRet = response->GetStatus();
405 EXPECT_EQ(statusRet, status);
406 }
407
408 HWTEST_F(RtspUnitTest, RtspUnitTest_042, Function | SmallTest | Level2)
409 {
410 int32_t cseq = 1;
411 int32_t status = 200;
412 auto response = std::make_shared<RtspResponse>(cseq, status);
413 EXPECT_NE(response, nullptr);
414 const std::string &msg1 = "RTSP/1.0 401 Unauthorized\r\nCSeq: 3\r\n";
415 const std::string &msg2 = "WWW-Authenticate: Digest realm=\"IP Camera(23435)\",";
416 const std::string &msg3 = "nonce=\"8fd7c44874480bd643d970149224da11\",";
417 const std::string &msg4 = "stale=\"FALSE\"\r\nDate: Wed, Jun 03 2020 10:54:30 GMT\r\n";
418 response->Parse(msg1 + msg2 + msg3 + msg4);
419 auto ret = response->GetDigestRealm();
420 EXPECT_EQ(ret, "IP Camera(23435)\",nonce=\"8fd7c44874480bd643d970149224da11\",stale=\"FALSE");
421 }
422
423 HWTEST_F(RtspUnitTest, RtspUnitTest_043, Function | SmallTest | Level2)
424 {
425 int32_t cseq = 1;
426 int32_t status = 200;
427 auto response = std::make_shared<RtspResponse>(cseq, status);
428 EXPECT_NE(response, nullptr);
429 const std::string &msg1 = "RTSP/1.0 401 Unauthorized\r\nCSeq: 3\r\n";
430 const std::string &msg2 = "WWW-Authenticate: Digest realm=\"IP Camera(23435)\",";
431 const std::string &msg3 = "nonce=\"8fd7c44874480bd643d970149224da11\",";
432 const std::string &msg4 = "stale=\"FALSE\"\r\nDate: Wed, Jun 03 2020 10:54:30 GMT\r\n";
433 response->Parse(msg1 + msg2 + msg3 + msg4);
434 auto ret = response->GetNonce();
435 EXPECT_NE(ret, "\"8fd7c44874480bd643d970149224da11\"");
436 }
437
438 HWTEST_F(RtspUnitTest, RtspUnitTest_044, Function | SmallTest | Level2)
439 {
440 int32_t cseq = 1;
441 int32_t status = 200;
442 auto response = std::make_shared<RtspResponse>(cseq, status);
443 EXPECT_NE(response, nullptr);
444 auto ret = response->GetBody();
445 EXPECT_EQ(ret.size(), 0);
446 }
447
448 HWTEST_F(RtspUnitTest, RtspUnitTest_045, Function | SmallTest | Level2)
449 {
450 int32_t cseq = 1;
451 int32_t status = 200;
452 auto response = std::make_shared<RtspResponse>(cseq, status);
453 EXPECT_NE(response, nullptr);
454 auto ret = response->Stringify();
455 EXPECT_NE(ret, "");
456 }
457
458 HWTEST_F(RtspUnitTest, RtspUnitTest_046, Function | SmallTest | Level2)
459 {
460 int32_t cseq = 1;
461 int32_t status = 200;
462 auto response = std::make_shared<RtspResponse>(cseq, status);
463 EXPECT_NE(response, nullptr);
464 const std::string token = "token";
465 const std::string value = "value";
466 response->tokens_[token] = value;
467 auto ret = response->GetToken(token);
468 EXPECT_EQ(ret, value);
469 }
470
471 HWTEST_F(RtspUnitTest, RtspUnitTest_047, Function | SmallTest | Level2)
472 {
473 int32_t cseq = 1;
474 int32_t status = 200;
475 auto response = std::make_shared<RtspResponseOptions>(cseq, status);
476 EXPECT_NE(response, nullptr);
477 }
478
479 HWTEST_F(RtspUnitTest, RtspUnitTest_048, Function | SmallTest | Level2)
480 {
481 int32_t cseq = 1;
482 int32_t status = 200;
483 auto response = std::make_shared<RtspResponseOptions>(cseq, status);
484 EXPECT_NE(response, nullptr);
485 const std::string &lists = "lists";
486 response->SetPublicItems(lists);
487 EXPECT_EQ(response->publicItems_, lists);
488 }
489
490 HWTEST_F(RtspUnitTest, RtspUnitTest_049, Function | SmallTest | Level2)
491 {
492 int32_t cseq = 1;
493 int32_t status = 200;
494 auto response = std::make_shared<RtspResponseOptions>(cseq, status);
495 EXPECT_NE(response, nullptr);
496 auto ret = response->Stringify();
497 EXPECT_NE(ret, "");
498 }
499
500 HWTEST_F(RtspUnitTest, RtspUnitTest_050, Function | SmallTest | Level2)
501 {
502 int32_t cseq = 1;
503 int32_t status = 200;
504 auto response = std::make_shared<RtspResponseDescribe>(cseq, status);
505 EXPECT_NE(response, nullptr);
506 auto ret = response->Stringify();
507 EXPECT_NE(ret, "");
508 }
509
510 HWTEST_F(RtspUnitTest, RtspUnitTest_051, Function | SmallTest | Level2)
511 {
512 int32_t cseq = 1;
513 int32_t status = 200;
514 auto response = std::make_shared<RtspResponseDescribe>(cseq, status);
515 EXPECT_NE(response, nullptr);
516 const std::string &line = "line";
517 response->AddBodyItem(line);
518 EXPECT_NE(response->body_.size(), 0);
519 }
520
521 HWTEST_F(RtspUnitTest, RtspUnitTest_052, Function | SmallTest | Level2)
522 {
523 int32_t cseq = 1;
524 int32_t status = 200;
525 auto response = std::make_shared<RtspResponseDescribe>(cseq, status);
526 EXPECT_NE(response, nullptr);
527 const std::string &url = "rtsp://192.168.2.4/wfd1.0/streamid=0";
528 response->SetUrl(url);
529 EXPECT_EQ(response->url_, url);
530 }
531
532 HWTEST_F(RtspUnitTest, RtspUnitTest_053, Function | SmallTest | Level2)
533 {
534 int32_t cseq = 1;
535 int32_t status = 200;
536 auto response = std::make_shared<RtspResponseSetup>(cseq, status);
537 EXPECT_NE(response, nullptr);
538 auto ret = response->Stringify();
539 EXPECT_NE(ret, "");
540 }
541
542 HWTEST_F(RtspUnitTest, RtspUnitTest_054, Function | SmallTest | Level2)
543 {
544 int32_t cseq = 1;
545 int32_t status = 200;
546 auto response = std::make_shared<RtspResponseSetup>(cseq, status);
547 EXPECT_NE(response, nullptr);
548 const std::string &destination = "destination";
549 response->SetDestination(destination);
550 EXPECT_EQ(response->destination_, destination);
551 }
552
553 HWTEST_F(RtspUnitTest, RtspUnitTest_055, Function | SmallTest | Level2)
554 {
555 int32_t cseq = 1;
556 int32_t status = 200;
557 auto response = std::make_shared<RtspResponseSetup>(cseq, status);
558 EXPECT_NE(response, nullptr);
559 const std::string &source = "source";
560 response->SetSource(source);
561 EXPECT_EQ(response->source_, source);
562 }
563
564 HWTEST_F(RtspUnitTest, RtspUnitTest_056, Function | SmallTest | Level2)
565 {
566 int32_t cseq = 1;
567 int32_t status = 200;
568 auto response = std::make_shared<RtspResponseSetup>(cseq, status);
569 EXPECT_NE(response, nullptr);
570 int32_t minClientPort = 6700;
571 int32_t maxClientPort = 0;
572 response->SetClientPort(minClientPort, maxClientPort);
573 EXPECT_EQ(response->minClientPort_, minClientPort);
574 }
575
576 HWTEST_F(RtspUnitTest, RtspUnitTest_057, Function | SmallTest | Level2)
577 {
578 int32_t cseq = 1;
579 int32_t status = 200;
580 auto response = std::make_shared<RtspResponseSetup>(cseq, status);
581 EXPECT_NE(response, nullptr);
582 int32_t minClientPort = 6700;
583 int32_t maxClientPort = 6702;
584 response->SetClientPort(minClientPort, maxClientPort);
585 EXPECT_EQ(response->minClientPort_, minClientPort);
586 EXPECT_EQ(response->maxServerPort_, maxClientPort);
587 }
588
589 HWTEST_F(RtspUnitTest, RtspUnitTest_058, Function | SmallTest | Level2)
590 {
591 int32_t cseq = 1;
592 int32_t status = 200;
593 auto response = std::make_shared<RtspResponseSetup>(cseq, status);
594 EXPECT_NE(response, nullptr);
595 int32_t minServerPort = 67000;
596 int32_t maxServerPort = 67002;
597 response->SetServerPort(minServerPort, maxServerPort);
598 EXPECT_EQ(response->minServerPort_, minServerPort);
599 EXPECT_EQ(response->maxServerPort_, maxServerPort);
600 }
601
602 HWTEST_F(RtspUnitTest, RtspUnitTest_059, Function | SmallTest | Level2)
603 {
604 int32_t cseq = 1;
605 int32_t status = 200;
606 auto response = std::make_shared<RtspResponsePlay>(cseq, status);
607 EXPECT_NE(response, nullptr);
608 }
609
610 HWTEST_F(RtspUnitTest, RtspUnitTest_060, Function | SmallTest | Level2)
611 {
612 int32_t cseq = 1;
613 int32_t status = 200;
614 auto response = std::make_shared<RtspResponseTeardown>(cseq, status);
615 EXPECT_NE(response, nullptr);
616 }
617
618 HWTEST_F(RtspUnitTest, RtspUnitTest_061, Function | SmallTest | Level2)
619 {
620 int32_t cseq = 1;
621 int32_t status = 200;
622 auto response = std::make_shared<RtspResponseGetParameter>(cseq, status);
623 EXPECT_NE(response, nullptr);
624 auto ret = response->Stringify();
625 EXPECT_NE(ret, "");
626 }
627
628 HWTEST_F(RtspUnitTest, RtspUnitTest_062, Function | SmallTest | Level2)
629 {
630 int32_t cseq = 1;
631 int32_t status = 200;
632 auto response = std::make_shared<RtspResponseGetParameter>(cseq, status);
633 EXPECT_NE(response, nullptr);
634 const std::string &line = "line";
635 response->AddBodyItem(line);
636 EXPECT_NE(response->body_.size(), 0);
637 }
638
639 HWTEST_F(RtspUnitTest, RtspUnitTest_063, Function | SmallTest | Level2)
640 {
641 int32_t cseq = 1;
642 int32_t status = 200;
643 auto response = std::make_shared<RtspResponseSetParameter>(cseq, status);
644 EXPECT_NE(response, nullptr);
645 }
646
647 HWTEST_F(RtspUnitTest, RtspUnitTest_064, Function | SmallTest | Level2)
648 {
649 auto session = std::make_shared<SessionOrigin>();
650 EXPECT_NE(session, nullptr);
651 }
652
653 HWTEST_F(RtspUnitTest, RtspUnitTest_065, Function | SmallTest | Level2)
654 {
655 auto session = std::make_shared<SessionOrigin>();
656 EXPECT_NE(session, nullptr);
657 uint32_t sessionVersion = 1;
658 const std::string netType = "IN";
659 const std::string username = "StreamingServer";
660 const std::string addrType = "IP4";
661 const std::string sessionId = "3677033027";
662 const std::string unicastAddr = "192.168.1.44";
663 const std::string origin = "StreamingServer 3677033027 1 IN IP4 192.168.1.44";
664 auto ret = session->Parse(origin);
665 EXPECT_EQ(ret, true);
666 EXPECT_EQ(session->sessionVersion, sessionVersion);
667 EXPECT_EQ(session->netType, netType);
668 EXPECT_EQ(session->username, username);
669 EXPECT_EQ(session->addrType, addrType);
670 EXPECT_EQ(session->sessionId, sessionId);
671 EXPECT_EQ(session->unicastAddr, unicastAddr);
672 }
673
674 HWTEST_F(RtspUnitTest, RtspUnitTest_066, Function | SmallTest | Level2)
675 {
676 auto media = std::make_shared<MediaLine>();
677 EXPECT_NE(media, nullptr);
678 }
679
680 HWTEST_F(RtspUnitTest, RtspUnitTest_067, Function | SmallTest | Level2)
681 {
682 auto media = std::make_shared<MediaLine>();
683 EXPECT_NE(media, nullptr);
684 uint16_t port = 49170;
685 int32_t fmt = 0;
686 const std::string mediaType = "audio";
687 const std::string protoType = "RTP/AVP";
688 const std::string mediaLine = "audio 49170 RTP/AVP 0";
689 auto ret = media->Parse(mediaLine);
690 EXPECT_EQ(ret, true);
691 EXPECT_EQ(media->port, port);
692 EXPECT_EQ(media->fmt, fmt);
693 EXPECT_EQ(media->mediaType, mediaType);
694 EXPECT_EQ(media->protoType, protoType);
695 }
696
697 HWTEST_F(RtspUnitTest, RtspUnitTest_068, Function | SmallTest | Level2)
698 {
699 auto mediaDesc = std::make_shared<MediaDescription>();
700 EXPECT_NE(mediaDesc, nullptr);
701 const std::string mediaLine = "audio 49170 RTP/AVP 0";
702 auto ret1 = mediaDesc->media_.Parse(mediaLine);
703 ASSERT_TRUE(ret1);
704 auto ret2 = mediaDesc->GetMediaType();
705 EXPECT_EQ(ret2, "audio");
706 auto ret3 = mediaDesc->GetPayloadType();
707 EXPECT_EQ(ret3, 0);
708 }
709
710 HWTEST_F(RtspUnitTest, RtspUnitTest_069, Function | SmallTest | Level2)
711 {
712 auto mediaDesc = std::make_shared<MediaDescription>();
713 EXPECT_NE(mediaDesc, nullptr);
714 const std::string mediaLine = "video 49170/2 RTP/AVP 31";
715 auto ret1 = mediaDesc->media_.Parse(mediaLine);
716 ASSERT_TRUE(ret1);
717 auto ret2 = mediaDesc->GetMediaType();
718 EXPECT_EQ(ret2, "video");
719 auto ret3 = mediaDesc->GetPayloadType();
720 EXPECT_EQ(ret3, 31);
721 }
722
723 HWTEST_F(RtspUnitTest, RtspUnitTest_070, Function | SmallTest | Level2)
724 {
725 auto mediaDesc = std::make_shared<MediaDescription>();
726 EXPECT_NE(mediaDesc, nullptr);
727 mediaDesc->attributes_.push_back(
728 "fmtp:96 profile-level-id=4D4015;"
729 "sprop-parameter-sets=Z01AFZZWCwSbCEiAAAH0AAAw1DBgAHP2AOg1cABQ,aO88gA==;packetization-mode=1");
730 mediaDesc->attributes_.push_back("cliprect:0,0,576,352");
731 mediaDesc->attributes_.push_back("rtpmap:99 X-GSMLPC/8000");
732 mediaDesc->attributes_.push_back("control:trackID=101");
733 auto ret1 = mediaDesc->GetRtpMap();
734 EXPECT_EQ(ret1, "99 X-GSMLPC/8000");
735 auto ret2 = mediaDesc->GetTrackId();
736 EXPECT_EQ(ret2, "trackID=101");
737 }
738
739 HWTEST_F(RtspUnitTest, RtspUnitTest_071, Function | SmallTest | Level2)
740 {
741 auto mediaDesc = std::make_shared<MediaDescription>();
742 EXPECT_NE(mediaDesc, nullptr);
743 const std::string mediaLine = "video 49170/2 RTP/AVP 31";
744 auto ret1 = mediaDesc->media_.Parse(mediaLine);
745 ASSERT_TRUE(ret1);
746 mediaDesc->attributes_.push_back(
747 "fmtp:96 profile-level-id=4D4015;"
748 "sprop-parameter-sets=Z01AFZZWCwSbCEiAAAH0AAAw1DBgAHP2AOg1cABQ,aO88gA==;packetization-mode=1");
749 auto ret2 = mediaDesc->GetVideoSps();
750 EXPECT_EQ(ret2.size(), 30);
751 auto ret3 = mediaDesc->GetVideoPps();
752 EXPECT_EQ(ret3.size(), 0);
753 auto ret4 = mediaDesc->GetVideoSize();
754 EXPECT_EQ(ret4.first, 352);
755 EXPECT_EQ(ret4.second, 288);
756 }
757
758 HWTEST_F(RtspUnitTest, RtspUnitTest_072, Function | SmallTest | Level2)
759 {
760 auto mediaDesc = std::make_shared<MediaDescription>();
761 EXPECT_NE(mediaDesc, nullptr);
762 const std::string mediaLine = "audio 49170 RTP/AVP 0";
763 auto ret1 = mediaDesc->media_.Parse(mediaLine);
764 ASSERT_TRUE(ret1);
765 mediaDesc->attributes_.push_back(
766 "fmtp:96 profile-level-id=4D4015;"
767 "sprop-parameter-sets=Z01AFZZWCwSbCEiAAAH0AAAw1DBgAHP2AOg1cABQ,aO88gA==;packetization-mode=1");
768 auto ret2 = mediaDesc->GetVideoSps();
769 EXPECT_EQ(ret2.size(), 0);
770 auto ret3 = mediaDesc->GetVideoPps();
771 EXPECT_EQ(ret3.size(), 0);
772 }
773
774 HWTEST_F(RtspUnitTest, RtspUnitTest_073, Function | SmallTest | Level2)
775 {
776 auto mediaDesc = std::make_shared<MediaDescription>();
777 EXPECT_NE(mediaDesc, nullptr);
778 const std::string mediaLine = "audio 49170 RTP/AVP 0";
779 auto ret1 = mediaDesc->media_.Parse(mediaLine);
780 ASSERT_TRUE(ret1);
781 mediaDesc->attributes_.push_back("rtpmap:98 L16/11025/2");
782 mediaDesc->attributes_.push_back("fmtp:97 streamtype=5;profile-level-id=15; mode=AAC-hbr;"
783 " config=1308; SizeLength=13; IndexLength=3;IndexDeltaLength=3; Profile=1;");
784 auto ret2 = mediaDesc->GetAudioChannels();
785 EXPECT_EQ(ret2, 2);
786 auto ret3 = mediaDesc->GetAudioSamplingRate();
787 EXPECT_EQ(ret3, 11025);
788 auto ret4 = mediaDesc->GetAudioConfig();
789 EXPECT_EQ(ret4, "1308");
790 }
791
792 HWTEST_F(RtspUnitTest, RtspUnitTest_074, Function | SmallTest | Level2)
793 {
794 auto mediaDesc = std::make_shared<MediaDescription>();
795 EXPECT_NE(mediaDesc, nullptr);
796 const std::string mediaLine = "video 49170/2 RTP/AVP 31";
797 auto ret1 = mediaDesc->media_.Parse(mediaLine);
798 ASSERT_TRUE(ret1);
799 mediaDesc->attributes_.push_back("rtpmap:98 L16/11025/2");
800 mediaDesc->attributes_.push_back("fmtp:97 streamtype=5;profile-level-id=15; mode=AAC-hbr;"
801 " config=1308; SizeLength=13; IndexLength=3;IndexDeltaLength=3; Profile=1;");
802 auto ret2 = mediaDesc->GetAudioChannels();
803 EXPECT_EQ(ret2, 0);
804 auto ret3 = mediaDesc->GetAudioSamplingRate();
805 EXPECT_EQ(ret3, 0);
806 auto ret4 = mediaDesc->GetAudioConfig();
807 EXPECT_EQ(ret4, "");
808 }
809
810 HWTEST_F(RtspUnitTest, RtspUnitTest_075, Function | SmallTest | Level2)
811 {
812 auto rtspSdp = std::make_shared<RtspSdp>();
813 EXPECT_NE(rtspSdp, nullptr);
814 const std::string mediaLine = "m=video 49170/2 RTP/AVP 31 \r\n";
815 auto ret = rtspSdp->Parse(mediaLine);
816 EXPECT_EQ(ret, true);
817 }
818
819 HWTEST_F(RtspUnitTest, RtspUnitTest_076, Function | SmallTest | Level2)
820 {
821 auto rtspSdp = std::make_shared<RtspSdp>();
822 EXPECT_NE(rtspSdp, nullptr);
823 const std::string mediaLine = "v=0\r\nb=X-YZ:128\r\no=HWPSS 3427743244 1084119141 IN IP4 127.0.0.1\r\n"
824 "s=test1.mp4\r\ni=test\r\nu=uri\r\ne=email\r\np=123456\r\nt=121212 232322\r\n"
825 "r=121212\r\nz=zone;\r\na=attr\r\nc=connection\r\n";
826 auto ret = rtspSdp->Parse(mediaLine);
827 EXPECT_EQ(ret, true);
828 auto ret1 = rtspSdp->GetOrigin();
829 EXPECT_EQ(ret1.addrType, "IP4");
830 EXPECT_EQ(ret1.netType, "IN");
831 EXPECT_EQ(ret1.sessionId, "3427743244");
832 EXPECT_EQ(ret1.sessionVersion, 1084119141);
833 EXPECT_EQ(ret1.unicastAddr, "127.0.0.1");
834 EXPECT_EQ(ret1.username, "HWPSS");
835
836 auto ret2 = rtspSdp->GetName();
837 EXPECT_EQ(ret2, "test1.mp4");
838 auto ret3 = rtspSdp->GetInfo();
839 EXPECT_EQ(ret3, "test");
840 auto ret4 = rtspSdp->GetUri();
841 EXPECT_EQ(ret4, "uri");
842 auto ret5 = rtspSdp->GetEmail();
843 EXPECT_EQ(ret5, "email");
844 auto ret6 = rtspSdp->GetPhone();
845 EXPECT_EQ(ret6, "123456");
846 auto ret7 = rtspSdp->GetConnection();
847 EXPECT_EQ(ret7, "connection");
848 auto ret8 = rtspSdp->GetBandwidth();
849 EXPECT_EQ(ret8[0], "X-YZ:128");
850 auto ret9 = rtspSdp->GetTime();
851 EXPECT_EQ(ret9.first, 121212);
852 EXPECT_EQ(ret9.second, 232322);
853 auto ret10 = rtspSdp->getAttributes();
854 EXPECT_EQ(ret10[0], "attr");
855 }
856
857 } // namespace
858 } // namespace Sharing
859 } // namespace OHOS