1 /*
2 * Copyright (c) 2022-2024 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 #include "lnn_decision_db.h"
16 #include "softbus_feature_config.h"
17 #include "softbus_proxychannel_pipeline.h"
18 #include "trans_auth_message.h"
19 #include "trans_channel_callback.h"
20 #include "trans_channel_manager.c"
21 #include "trans_lane_pending_ctl.h"
22 #include "trans_session_service.h"
23 #include "trans_tcp_direct_callback.h"
24 #include "trans_tcp_direct_manager.h"
25 #include "trans_tcp_direct_test.h"
26 #include "trans_tcp_direct_wifi.h"
27
28 using namespace testing::ext;
29
30 namespace OHOS {
31
32 #define PID 2024
33 #define UID 4000
34
35 static const char *g_pkgName = "dms";
36 static const char *g_ip = "192.168.8.1";
37 static int32_t g_netWorkId = 100;
38
39 class TransTcpDirectMessageTest : public testing::Test {
40 public:
TransTcpDirectMessageTest()41 TransTcpDirectMessageTest()
42 {}
~TransTcpDirectMessageTest()43 ~TransTcpDirectMessageTest()
44 {}
45 static void SetUpTestCase(void);
46 static void TearDownTestCase(void);
SetUp()47 void SetUp() override
48 {}
TearDown()49 void TearDown() override
50 {}
51 };
52
SetUpTestCase(void)53 void TransTcpDirectMessageTest::SetUpTestCase(void)
54 {
55 SoftbusConfigInit();
56 ConnServerInit();
57 AuthInit();
58 BusCenterServerInit();
59 TransServerInit();
60 TransProxyPipelineInit();
61 }
62
TearDownTestCase(void)63 void TransTcpDirectMessageTest::TearDownTestCase(void)
64 {
65 ConnServerDeinit();
66 AuthDeinit();
67 BusCenterServerDeinit();
68 TransServerDeinit();
69 }
70
TestSetSessionConn()71 SessionConn *TestSetSessionConn()
72 {
73 SessionConn *conn = (SessionConn*)SoftBusCalloc(sizeof(SessionConn));
74 if (conn == nullptr) {
75 return nullptr;
76 }
77 (void)memset_s(conn, sizeof(SessionConn), 0, sizeof(SessionConn));
78 conn->serverSide = true;
79 conn->channelId = 1;
80 conn->status = TCP_DIRECT_CHANNEL_STATUS_INIT;
81 conn->timeout = 0;
82 conn->req = INVALID_VALUE;
83 conn->authHandle.authId = 1;
84 conn->requestId = 1;
85 conn->listenMod = DIRECT_CHANNEL_SERVER_WIFI;
86 conn->appInfo.myData.pid = 1;
87 conn->appInfo.fd = g_netWorkId;
88 (void)memcpy_s(conn->appInfo.myData.pkgName, PKG_NAME_SIZE_MAX_LEN, g_pkgName, (strlen(g_pkgName)+1));
89 return conn;
90 }
91
TestSetAppInfo()92 AppInfo *TestSetAppInfo()
93 {
94 AppInfo *appInfo = (AppInfo *)SoftBusCalloc(sizeof(AppInfo));
95 if (appInfo == nullptr) {
96 return nullptr;
97 }
98
99 (void)memset_s(appInfo, sizeof(AppInfo), 0, sizeof(AppInfo));
100 appInfo->businessType = BUSINESS_TYPE_BYTE;
101 appInfo->appType = APP_TYPE_NORMAL;
102 appInfo->myData.apiVersion = API_V2;
103 appInfo->peerData.apiVersion = API_V2;
104 appInfo->encrypt = APP_INFO_FILE_FEATURES_SUPPORT;
105 appInfo->algorithm = APP_INFO_ALGORITHM_AES_GCM_256;
106 appInfo->crc = APP_INFO_FILE_FEATURES_SUPPORT;
107 return appInfo;
108 }
109 /**
110 * @tc.name: OpenP2pDirectChannelTest001
111 * @tc.desc: OpenP2pDirectChannel, use the wrong parameter.
112 * @tc.type: FUNC
113 * @tc.require:
114 */
115 HWTEST_F(TransTcpDirectMessageTest, OpenP2pDirectChannelTest001, TestSize.Level1)
116 {
117 AppInfo *appInfo = (AppInfo *)SoftBusCalloc(sizeof(AppInfo));
118 ASSERT_TRUE(appInfo != nullptr);
119 ConnectOption *connInfo = (ConnectOption *)SoftBusCalloc(sizeof(ConnectOption));
120 ASSERT_TRUE(connInfo != nullptr);
121 int32_t channelId = 1;
122 (void)memset_s(appInfo, sizeof(AppInfo), 0, sizeof(AppInfo));
123 (void)memset_s(connInfo, sizeof(ConnectOption), 0, sizeof(ConnectOption));
124 int32_t ret = OpenP2pDirectChannel(nullptr, connInfo, &channelId);
125 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
126
127 ret = OpenP2pDirectChannel(appInfo, nullptr, &channelId);
128 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
129
130 ret = OpenP2pDirectChannel(appInfo, connInfo, nullptr);
131 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
132
133 ret = OpenP2pDirectChannel(appInfo, connInfo, &channelId);
134 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
135
136 appInfo->businessType = BUSINESS_TYPE_BYTE;
137 appInfo->appType = APP_TYPE_NORMAL;
138 appInfo->myData.apiVersion = API_V2;
139 appInfo->peerData.apiVersion = API_V2;
140 appInfo->encrypt = APP_INFO_FILE_FEATURES_SUPPORT;
141 appInfo->algorithm = APP_INFO_ALGORITHM_AES_GCM_256;
142 appInfo->crc = APP_INFO_FILE_FEATURES_SUPPORT;
143 (void)memcpy_s(appInfo->myData.addr, IP_LEN, g_ip, strlen(g_ip));
144
145 connInfo->type = CONNECT_P2P;
146 ret = OpenP2pDirectChannel(appInfo, connInfo, &channelId);
147 EXPECT_EQ(SOFTBUS_MEM_ERR, ret);
148
149 connInfo->type = CONNECT_BR;
150 ret = OpenP2pDirectChannel(appInfo, connInfo, &channelId);
151 EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
152
153 StopP2pSessionListener();
154 SoftBusFree(appInfo);
155 SoftBusFree(connInfo);
156 }
157
158 /**
159 * @tc.name: P2pDirectChannelInitTest002
160 * @tc.desc: P2pDirectChannelInit, use the wrong parameter.
161 * @tc.type: FUNC
162 * @tc.require:
163 */
164 HWTEST_F(TransTcpDirectMessageTest, P2pDirectChannelInitTest002, TestSize.Level1)
165 {
166 int32_t ret = P2pDirectChannelInit();
167 EXPECT_EQ(ret, SOFTBUS_OK);
168 }
169
170 /**
171 * @tc.name: GenerateTdcChannelIdTest003
172 * @tc.desc: GenerateTdcChannelId, use the wrong parameter.
173 * @tc.type: FUNC
174 * @tc.require:
175 */
176 HWTEST_F(TransTcpDirectMessageTest, GenerateTdcChannelIdTest003, TestSize.Level1)
177 {
178 uint64_t ret = TransTdcGetNewSeqId();
179 EXPECT_TRUE(ret);
180
181 int32_t res = GenerateTdcChannelId();
182 EXPECT_TRUE(res);
183
184 const IServerChannelCallBack *cb = TransServerGetChannelCb();
185 ret = TransTcpDirectInit(cb);
186 EXPECT_EQ(ret, SOFTBUS_OK);
187
188 res = CreatSessionConnList();
189 ASSERT_EQ(res, SOFTBUS_OK);
190
191 SoftBusList *softbuslist = GetSessionConnList();
192 EXPECT_TRUE(softbuslist != nullptr);
193
194 res = GetSessionConnLock();
195 EXPECT_EQ(res, SOFTBUS_OK);
196
197 ReleaseSessionConnLock();
198 TransTcpDirectDeinit();
199 }
200
201 /**
202 * @tc.name: GetSessionConnByRequestIdTest004
203 * @tc.desc: GetSessionConnByRequestId, use the wrong parameter.
204 * @tc.type: FUNC
205 * @tc.require:
206 */
207 HWTEST_F(TransTcpDirectMessageTest, GetSessionConnByRequestIdTest004, TestSize.Level1)
208 {
209 uint32_t requestId = 1;
210 SessionConn *session = GetSessionConnByRequestId(requestId);
211 EXPECT_TRUE(session == nullptr);
212
213 const IServerChannelCallBack *cb = TransServerGetChannelCb();
214 int32_t ret = TransTcpDirectInit(cb);
215 EXPECT_EQ(ret, SOFTBUS_OK);
216
217 SessionConn *conn = TestSetSessionConn();
218 ret = TransTdcAddSessionConn(conn);
219 EXPECT_EQ(ret, SOFTBUS_OK);
220
221 session = GetSessionConnByRequestId(requestId);
222 EXPECT_TRUE(session != nullptr);
223
224 requestId = INVALID_VALUE;
225 session = GetSessionConnByRequestId(requestId);
226 EXPECT_TRUE(session == nullptr);
227
228 TransTcpDirectDeinit();
229 }
230
231 /**
232 * @tc.name: GetSessionConnByReqTest005
233 * @tc.desc: GetSessionConnByReq, use the wrong parameter.
234 * @tc.type: FUNC
235 * @tc.require:
236 */
237 HWTEST_F(TransTcpDirectMessageTest, GetSessionConnByReqTest005, TestSize.Level1)
238 {
239 int64_t req = INVALID_VALUE;
240 SessionConn *session = GetSessionConnByReq(req);
241 EXPECT_TRUE(session != nullptr);
242
243 const IServerChannelCallBack *cb = TransServerGetChannelCb();
244 int32_t ret = TransTcpDirectInit(cb);
245 EXPECT_EQ(ret, SOFTBUS_OK);
246
247 SessionConn *conn = TestSetSessionConn();
248 ret = TransTdcAddSessionConn(conn);
249 EXPECT_EQ(ret, SOFTBUS_OK);
250 req = 0;
251 session = GetSessionConnByReq(req);
252 EXPECT_TRUE(session == nullptr);
253 TransTcpDirectDeinit();
254 }
255
256 /**
257 * @tc.name: CreateNewSessinConnTest006
258 * @tc.desc: CreateNewSessinConn, use the wrong parameter.
259 * @tc.type: FUNC
260 * @tc.require:
261 */
262 HWTEST_F(TransTcpDirectMessageTest, CreateNewSessinConnTest006, TestSize.Level1)
263 {
264 SessionConn *session = CreateNewSessinConn(AUTH_P2P, true);
265 EXPECT_EQ(nullptr, session);
266 }
267
268 /**
269 * @tc.name: GetSessionConnByFdTest007
270 * @tc.desc: GetSessionConnByFd, use the wrong parameter.
271 * @tc.type: FUNC
272 * @tc.require:
273 */
274 HWTEST_F(TransTcpDirectMessageTest, GetSessionConnByFdTest007, TestSize.Level1)
275 {
276 int32_t fd = g_netWorkId;
277 SessionConn *conn = (SessionConn*)SoftBusMalloc(sizeof(SessionConn));
278 ASSERT_TRUE(conn != nullptr);
279 (void)memset_s(conn, sizeof(SessionConn), 0, sizeof(SessionConn));
280
281 const IServerChannelCallBack *cb = TransServerGetChannelCb();
282 int32_t ret = TransTcpDirectInit(cb);
283 EXPECT_EQ(ret, SOFTBUS_OK);
284
285 SessionConn *con = TestSetSessionConn();
286 ret = TransTdcAddSessionConn(con);
287 EXPECT_EQ(ret, SOFTBUS_OK);
288
289 int32_t session = GetSessionConnByFd(fd, conn);
290 EXPECT_TRUE(session == SOFTBUS_OK);
291 fd = 123;
292 session = GetSessionConnByFd(fd, conn);
293 EXPECT_TRUE(session == SOFTBUS_TRANS_GET_SESSION_CONN_FAILED);
294
295 SoftBusFree(conn);
296 }
297
298 /**
299 * @tc.name: GetSessionConnByIdTest008
300 * @tc.desc: GetSessionConnById, use the wrong parameter.
301 * @tc.type: FUNC
302 * @tc.require:
303 */
304 HWTEST_F(TransTcpDirectMessageTest, GetSessionConnByIdTest008, TestSize.Level1)
305 {
306 int32_t channelId = 1;
307 SessionConn *conn = (SessionConn*)SoftBusMalloc(sizeof(SessionConn));
308 ASSERT_TRUE(conn != nullptr);
309 (void)memset_s(conn, sizeof(SessionConn), 0, sizeof(SessionConn));
310
311 int32_t session = GetSessionConnById(channelId, nullptr);
312 EXPECT_TRUE(session == SOFTBUS_OK);
313
314 channelId = 0;
315 session = GetSessionConnById(channelId, conn);
316 EXPECT_TRUE(session != SOFTBUS_OK);
317
318 SoftBusFree(conn);
319 }
320
321 /**
322 * @tc.name: SetAppInfoByIdTest009
323 * @tc.desc: SetAppInfoById, use the wrong parameter.
324 * @tc.type: FUNC
325 * @tc.require:
326 */
327 HWTEST_F(TransTcpDirectMessageTest, SetAppInfoByIdTest009, TestSize.Level1)
328 {
329 int32_t channelId = 1;
330 AppInfo *appInfo = TestSetAppInfo();
331
332 int32_t ret = SetAppInfoById(channelId, appInfo);
333 EXPECT_EQ(ret, SOFTBUS_OK);
334 channelId = 0;
335 ret = SetAppInfoById(channelId, appInfo);
336 EXPECT_EQ(ret, SOFTBUS_TRANS_SET_APP_INFO_FAILED);
337 SoftBusFree(appInfo);
338 appInfo = nullptr;
339 }
340
341 /**
342 * @tc.name: GetAppInfoByIdTest0010
343 * @tc.desc: GetAppInfoById, use the wrong parameter.
344 * @tc.type: FUNC
345 * @tc.require:
346 */
347 HWTEST_F(TransTcpDirectMessageTest, GetAppInfoByIdTest0010, TestSize.Level1)
348 {
349 int32_t channelId = 1;
350 AppInfo *appInfo = TestSetAppInfo();
351 int32_t ret = GetAppInfoById(channelId, appInfo);
352 EXPECT_EQ(ret, SOFTBUS_OK);
353 channelId = 0;
354 ret = GetAppInfoById(channelId, appInfo);
355 EXPECT_EQ(ret, SOFTBUS_TRANS_GET_APP_INFO_FAILED);
356
357 SoftBusFree(appInfo);
358 appInfo = nullptr;
359 }
360
361 /**
362 * @tc.name: SetAuthHandleByChanIdTest0011
363 * @tc.desc: SetAuthHandleByChanId, use the wrong parameter.
364 * @tc.type: FUNC
365 * @tc.require:
366 */
367 HWTEST_F(TransTcpDirectMessageTest, SetAuthHandleByChanIdTest0011, TestSize.Level1)
368 {
369 int32_t channelId = 1;
370 AuthHandle authHandle = { .authId = 1, .type = 1 };
371 int32_t ret = SetAuthHandleByChanId(channelId, &authHandle);
372 EXPECT_EQ(ret, SOFTBUS_OK);
373 channelId = 0;
374 ret = SetAuthHandleByChanId(channelId, &authHandle);
375 EXPECT_EQ(ret, SOFTBUS_TRANS_SET_AUTH_HANDLE_FAILED);
376 }
377
378 /**
379 * @tc.name: GetAuthHandleByChanIdTest0012
380 * @tc.desc: GetAuthHandleByChanId, use the wrong parameter.
381 * @tc.type: FUNC
382 * @tc.require:
383 */
384 HWTEST_F(TransTcpDirectMessageTest, GetAuthHandleByChanIdTest0012, TestSize.Level1)
385 {
386 AuthHandle authHandle = { .authId = AUTH_INVALID_ID };
387 int32_t channelId = 1;
388 int32_t ret = GetAuthHandleByChanId(channelId, &authHandle);
389 EXPECT_EQ(ret, SOFTBUS_OK);
390
391 const IServerChannelCallBack *cb = TransServerGetChannelCb();
392 int32_t res = TransTcpDirectInit(cb);
393 EXPECT_EQ(res, SOFTBUS_OK);
394
395 SessionConn *con = TestSetSessionConn();
396 res = TransTdcAddSessionConn(con);
397 EXPECT_EQ(res, SOFTBUS_OK);
398
399 channelId = 0;
400 ret = GetAuthHandleByChanId(channelId, &authHandle);
401 EXPECT_EQ(authHandle.authId, AUTH_INVALID_ID);
402 TransTcpDirectDeinit();
403 }
404
405 /**
406 * @tc.name: GetAuthIdByChanIdTest0013
407 * @tc.desc: GetAuthIdByChanId, use the wrong parameter.
408 * @tc.type: FUNC
409 * @tc.require:
410 */
411 HWTEST_F(TransTcpDirectMessageTest, GetAuthIdByChanIdTest0013, TestSize.Level1)
412 {
413 int32_t channelId = 1;
414 TransDelSessionConnById(channelId);
415
416 const IServerChannelCallBack *cb = TransServerGetChannelCb();
417 int32_t res = TransTcpDirectInit(cb);
418 EXPECT_EQ(res, SOFTBUS_OK);
419
420 SessionConn *con = TestSetSessionConn();
421 res = TransTdcAddSessionConn(con);
422 EXPECT_EQ(res, SOFTBUS_OK);
423 channelId = 0;
424 TransDelSessionConnById(channelId);
425
426 TransTcpDirectDeinit();
427 }
428
429 /**
430 * @tc.name: TransTdcAddSessionConnTest0014
431 * @tc.desc: TransTdcAddSessionConn, use the wrong parameter.
432 * @tc.type: FUNC
433 * @tc.require:
434 */
435 HWTEST_F(TransTcpDirectMessageTest, TransTdcAddSessionConnTest0014, TestSize.Level1)
436 {
437 SessionConn *con = TestSetSessionConn();
438 int32_t ret = TransTdcAddSessionConn(nullptr);
439 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
440
441 const IServerChannelCallBack *cb = TransServerGetChannelCb();
442 ret = TransTcpDirectInit(cb);
443 EXPECT_EQ(ret, SOFTBUS_OK);
444
445 ret = TransTdcAddSessionConn(con);
446 EXPECT_EQ(ret, SOFTBUS_OK);
447
448 TransTcpDirectDeinit();
449 }
450
451 /**
452 * @tc.name: SetSessionKeyByChanIdTest0015
453 * @tc.desc: SetSessionKeyByChanId, use the wrong parameter.
454 * @tc.type: FUNC
455 * @tc.require:
456 */
457 HWTEST_F(TransTcpDirectMessageTest, SetSessionKeyByChanIdTest0015, TestSize.Level1)
458 {
459 int32_t channelId = 1;
460 const char *sessionKey = "key";
461 int32_t keyLen = 0;
462 const IServerChannelCallBack *cb = TransServerGetChannelCb();
463 int32_t ret = TransTcpDirectInit(cb);
464 EXPECT_EQ(ret, SOFTBUS_OK);
465
466 SessionConn *con = TestSetSessionConn();
467 ret = TransTdcAddSessionConn(con);
468 EXPECT_EQ(ret, SOFTBUS_OK);
469
470 SetSessionKeyByChanId(channelId, nullptr, keyLen);
471 SetSessionKeyByChanId(channelId, sessionKey, keyLen);
472
473 keyLen = strlen(sessionKey);
474 SetSessionKeyByChanId(channelId, sessionKey, keyLen);
475 TransTcpDirectDeinit();
476 }
477
478 /**
479 * @tc.name: SetSessionConnStatusByIdTest0016
480 * @tc.desc: SetSessionConnStatusById, use the wrong parameter.
481 * @tc.type: FUNC
482 * @tc.require:
483 */
484 HWTEST_F(TransTcpDirectMessageTest, SetSessionConnStatusByIdTest0016, TestSize.Level1)
485 {
486 int32_t channelId = 1;
487 uint32_t status = TCP_DIRECT_CHANNEL_STATUS_CONNECTED;
488 const IServerChannelCallBack *cb = TransServerGetChannelCb();
489 int32_t ret = TransTcpDirectInit(cb);
490 EXPECT_EQ(ret, SOFTBUS_OK);
491
492 SessionConn *con = TestSetSessionConn();
493 ret = TransTdcAddSessionConn(con);
494 EXPECT_EQ(ret, SOFTBUS_OK);
495
496 ret = SetSessionConnStatusById(channelId, status);
497 EXPECT_EQ(ret, SOFTBUS_OK);
498
499 channelId = 0;
500 ret = SetSessionConnStatusById(channelId, status);
501 EXPECT_EQ(ret, SOFTBUS_NOT_FIND);
502 TransTcpDirectDeinit();
503 }
504
505 /**
506 * @tc.name: TcpTranGetAppInfobyChannelIdTest0017
507 * @tc.desc: TcpTranGetAppInfobyChannelId, use the wrong parameter.
508 * @tc.type: FUNC
509 * @tc.require:
510 */
511 HWTEST_F(TransTcpDirectMessageTest, TcpTranGetAppInfobyChannelIdTest0017, TestSize.Level1)
512 {
513 int32_t channelId = 1;
514 AppInfo* appInfo = TestSetAppInfo();
515 const IServerChannelCallBack *cb = TransServerGetChannelCb();
516 int32_t ret = TransTcpDirectInit(cb);
517 EXPECT_EQ(ret, SOFTBUS_OK);
518
519 SessionConn *con = TestSetSessionConn();
520 ret = TransTdcAddSessionConn(con);
521 EXPECT_EQ(ret, SOFTBUS_OK);
522
523 ret = TcpTranGetAppInfobyChannelId(channelId, appInfo);
524 EXPECT_EQ(ret, SOFTBUS_OK);
525
526 channelId = 0;
527 ret = TcpTranGetAppInfobyChannelId(channelId, appInfo);
528 EXPECT_EQ(ret, SOFTBUS_NOT_FIND);
529 }
530
531 /**
532 * @tc.name: TransGetLocalConfigTest001
533 * @tc.desc: TransGetLocalConfig
534 * @tc.type: FUNC
535 * @tc.require:
536 */
537 HWTEST_F(TransTcpDirectMessageTest, TransGetLocalConfigTest001, TestSize.Level1)
538 {
539 int32_t channelType = -1;
540 int32_t bussinessType = BUSINESS_TYPE_BYTE;
541 uint32_t len;
542 int32_t ret = TransCommonGetLocalConfig(channelType, bussinessType, &len);
543 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
544 }
545
546 /**
547 * @tc.name: TransGetLocalConfigTest002
548 * @tc.desc: TransGetLocalConfig
549 * @tc.type: FUNC
550 * @tc.require:
551 */
552 HWTEST_F(TransTcpDirectMessageTest, TransGetLocalConfigTest002, TestSize.Level1)
553 {
554 int32_t channelType = CHANNEL_TYPE_TCP_DIRECT;
555 int32_t bussinessType = BUSINESS_TYPE_BYTE;
556 uint32_t len;
557 int32_t ret = TransCommonGetLocalConfig(channelType, bussinessType, &len);
558 EXPECT_EQ(ret, SOFTBUS_OK);
559 }
560
561 /**
562 * @tc.name: TransGetChannelIdsByAuthIdAndStatus001
563 * @tc.desc: TransGetLocalConfig
564 * @tc.type: FUNC
565 * @tc.require:
566 */
567 HWTEST_F(TransTcpDirectMessageTest, TransGetChannelIdsByAuthIdAndStatus001, TestSize.Level1)
568 {
569 AuthHandle authHandle = {
570 .type = 1,
571 .authId = 1,
572 };
573 const IServerChannelCallBack *cb = TransServerGetChannelCb();
574 int32_t ret = TransTcpDirectInit(cb);
575 EXPECT_EQ(ret, SOFTBUS_OK);
576
577 SessionConn *con = TestSetSessionConn();
578 con->status = TCP_DIRECT_CHANNEL_STATUS_AUTH_CHANNEL;
579 con->authHandle.type = 1;
580 ret = TransTdcAddSessionConn(con);
581 EXPECT_EQ(ret, SOFTBUS_OK);
582
583 SessionConn *con2 = TestSetSessionConn();
584 con2->status = TCP_DIRECT_CHANNEL_STATUS_VERIFY_P2P;
585 con2->channelId = 1;
586 con2->authHandle.type = 1;
587 ret = TransTdcAddSessionConn(con2);
588 EXPECT_EQ(ret, SOFTBUS_OK);
589
590 SessionConn *con3 = TestSetSessionConn();
591 con3->status = TCP_DIRECT_CHANNEL_STATUS_VERIFY_P2P;
592 con3->channelId = 2;
593 con3->authHandle.type = 1;
594 ret = TransTdcAddSessionConn(con3);
595 EXPECT_EQ(ret, SOFTBUS_OK);
596
597 int count = 0;
598 int32_t *channelId = GetChannelIdsByAuthIdAndStatus(&count, &authHandle, TCP_DIRECT_CHANNEL_STATUS_VERIFY_P2P);
599 EXPECT_EQ(count, 2);
600 EXPECT_EQ(channelId[0], 1);
601 EXPECT_EQ(channelId[1], 2);
602 SoftBusFree(con);
603 SoftBusFree(con2);
604 SoftBusFree(con3);
605 SoftBusFree(channelId);
606 }
607 } // namespace OHOS
608