1/* 2 * Copyright (C) 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 */ 15import { describe, it, expect , Level, Size, TestType} from '@ohos/hypium'; 16import socket from "@ohos.net.socket"; 17import { BusinessError, Callback } from '@ohos.base'; 18import { ArrayBufferToString } from './utils/index'; 19 20function expectSuccess(): void { 21 expect(true).assertTrue(); 22} 23 24function expectFail(info: string = ''): void { 25 try { 26 expect(false).assertTrue(); 27 } catch (err) { 28 console.info(`${info} test failed`); 29 } 30}; 31 32 33function expectTrue(exp: boolean, info: string = ''): void { 34 try { 35 expect(exp).assertTrue(); 36 } catch (err) { 37 console.info(`${info} test failed`); 38 } 39}; 40 41function expectFalse(exp: boolean, info: string = ''): void { 42 try { 43 expect(exp).assertFalse(); 44 } catch (err) { 45 console.info(`${info} test failed`); 46 } 47}; 48 49function expectEqual(exp: string | number | boolean, assert: string | number | boolean, info: string = ''): void { 50 try { 51 console.info('JSON.stringify(exp),JSON.stringify(assert)' + JSON.stringify(exp), JSON.stringify(assert)) 52 expect(exp).assertEqual(assert); 53 } catch (err) { 54 console.info(`${info} test failed`); 55 } 56}; 57 58export default function TCPSocketTest() { 59 describe('ActsTCPSocketTest', () => { 60 61 /* * 62 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_ConstructTCPSocketInstance_0100 63 * @tc.name : testNetworkMgrSocketTCPSocketConstructTCPSocketInstance0100 64 * @tc.desc : Create a TCP Socket object 65 * @tc.size : MediumTest 66 * @tc.type : Function 67 * @tc.level : level 2 68 */ 69 it('testNetworkMgrSocketTCPSocketConstructTCPSocketInstance0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 70 let caseName: string = 'testNetworkMgrSocketTCPSocketConstructTCPSocketInstance0100'; 71 console.info(`${caseName} test start `); 72 try { 73 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 74 console.info(`${caseName} success`); 75 expect(tcp).assertInstanceOf('Object'); 76 done(); 77 } catch (err) { 78 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 79 expectFail(); 80 console.info(`${caseName} test end `); 81 done(); 82 } 83 }); 84 85 /* * 86 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_0100 87 * @tc.name : testNetworkMgrSocketTCPSocketBind0100 88 * @tc.desc : Bind IP address and port,Only fill in IPV4 address; callback 89 * @tc.size : MediumTest 90 * @tc.type : Function 91 * @tc.level : level 1 92 */ 93 it('testNetworkMgrSocketTCPSocketBind0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 94 let caseName: string = 'testNetworkMgrSocketTCPSocketBind0100'; 95 try { 96 console.info(`${caseName} test start `); 97 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 98 expect(tcp).assertInstanceOf('Object'); 99 let bindAddress: socket.NetAddress = { 100 address: '127.0.0.1' 101 }; 102 tcp.bind(bindAddress, async (err: BusinessError) => { 103 if (err) { 104 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 105 expectFail(); 106 } else { 107 console.info(`${caseName} success`); 108 expectSuccess(); 109 } 110 await tcp.close(); 111 console.info(`${caseName} test end `); 112 done(); 113 }); 114 } catch (err) { 115 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 116 expectFail(); 117 console.info(`${caseName} test end`); 118 done(); 119 } 120 }); 121 122 /* * 123 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_0300 124 * @tc.name : testNetworkMgrSocketTCPSocketBind0300 125 * @tc.desc : Bind IP address and port,the address and protocol are both IPV6; callback 126 * @tc.size : MediumTest 127 * @tc.type : Function 128 * @tc.level : level 1 129 */ 130 it('testNetworkMgrSocketTCPSocketBind0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 131 let caseName: string = 'testNetworkMgrSocketTCPSocketBind0300'; 132 try { 133 console.info(`${caseName} test start `); 134 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 135 expect(tcp).assertInstanceOf('Object'); 136 let bindAddress: socket.NetAddress = { 137 address: 'fe80::b3b:ecb5:77f:88dc%12', 138 family:2 139 }; 140 tcp.bind(bindAddress, async (err: BusinessError) => { 141 if (err) { 142 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 143 expectTrue(err.code===2301022); 144 } else { 145 console.info(`${caseName} success`); 146 expectFail(); 147 } 148 await tcp.close(); 149 console.info(`${caseName} test end `); 150 done(); 151 }); 152 } catch (err) { 153 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 154 expectFail(); 155 console.info(`${caseName} test end`); 156 done(); 157 } 158 }); 159 160 /* * 161 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_0500 162 * @tc.name : testNetworkMgrSocketTCPSocketBind0500 163 * @tc.desc : Bind IP address and port,bad address; callback 164 * @tc.size : MediumTest 165 * @tc.type : Function 166 * @tc.level : level 2 167 */ 168 it('testNetworkMgrSocketTCPSocketBind0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 169 let caseName: string = 'testNetworkMgrSocketTCPSocketBind0500'; 170 try { 171 console.info(`${caseName} test start `); 172 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 173 expect(tcp).assertInstanceOf('Object'); 174 let bindAddress: socket.NetAddress = { 175 address: '100.0.0.0', 176 port: 4444, 177 family: 1 178 }; 179 tcp.bind(bindAddress, async (err: BusinessError) => { 180 if (err) { 181 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 182 expectEqual(err.code, 2301099); 183 } else { 184 console.info(`${caseName} success`); 185 expectFail(); 186 } 187 await tcp.close(); 188 console.info(`${caseName} test end `); 189 done(); 190 }); 191 } catch (err) { 192 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 193 expectFail(); 194 console.info(`${caseName} test end `); 195 done(); 196 } 197 }); 198 199 /* * 200 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_0600 201 * @tc.name : testNetworkMgrSocketTCPSocketBind0600 202 * @tc.desc : Bind IP address and port,Port is boundary -1; callback 203 * @tc.size : MediumTest 204 * @tc.type : Function 205 * @tc.level : level 2 206 */ 207 it('testNetworkMgrSocketTCPSocketBind0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 208 let caseName: string = 'testNetworkMgrSocketTCPSocketBind0600'; 209 try { 210 console.info(`${caseName} test start `); 211 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 212 expect(tcp).assertInstanceOf('Object'); 213 let bindAddress: socket.NetAddress = { 214 address: '127.0.0.1', 215 port: -1, 216 family: 1 217 }; 218 tcp.bind(bindAddress, async (err: BusinessError) => { 219 if (err) { 220 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 221 expectFail(); 222 } else { 223 console.info(`${caseName} success`); 224 expectSuccess(); 225 } 226 await tcp.close(); 227 console.info(`${caseName} test end`); 228 done(); 229 }); 230 } catch (err) { 231 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 232 expectFail(); 233 console.info(`${caseName} test end`); 234 done(); 235 } 236 }); 237 238 /* * 239 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_0700 240 * @tc.name : testNetworkMgrSocketTCPSocketBind0700 241 * @tc.desc : Bind IP address and port,port is boundary 0; callback 242 * @tc.size : MediumTest 243 * @tc.type : Function 244 * @tc.level : level 2 245 */ 246 it('testNetworkMgrSocketTCPSocketBind0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 247 let caseName: string = 'testNetworkMgrSocketTCPSocketBind0700'; 248 try { 249 console.info(`${caseName} test start `); 250 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 251 expect(tcp).assertInstanceOf('Object'); 252 let bindAddress: socket.NetAddress = { 253 address: '127.0.0.1', 254 port: 0, 255 family: 1 256 }; 257 tcp.bind(bindAddress, async (err: BusinessError) => { 258 if (err) { 259 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 260 expectFail(); 261 } else { 262 console.info(`${caseName} success`); 263 expectSuccess(); 264 } 265 await tcp.close(); 266 console.info(`${caseName} test end`); 267 done(); 268 }); 269 } catch (err) { 270 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 271 expectFail(); 272 console.info(`${caseName} test end`); 273 done(); 274 } 275 }); 276 277 /* * 278 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_0800 279 * @tc.name : testNetworkMgrSocketTCPSocketBind0800 280 * @tc.desc : Bind IP address and port,Port is boundary 65535; callback 281 * @tc.size : MediumTest 282 * @tc.type : Function 283 * @tc.level : level 2 284 */ 285 it('testNetworkMgrSocketTCPSocketBind0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 286 let caseName: string = 'testNetworkMgrSocketTCPSocketBind0800'; 287 try { 288 console.info(`${caseName} test start `); 289 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 290 expect(tcp).assertInstanceOf('Object'); 291 let bindAddress: socket.NetAddress = { 292 address: '127.0.0.1', 293 port: 65535, 294 family: 1 295 }; 296 tcp.bind(bindAddress, async (err: BusinessError) => { 297 if (err) { 298 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 299 expectFail(); 300 } else { 301 console.info(`${caseName} success`); 302 expectSuccess(); 303 } 304 await tcp.close(); 305 console.info(`${caseName} test end`); 306 done(); 307 }); 308 } catch (err) { 309 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 310 expectFail(); 311 console.info(`${caseName} test end`); 312 done(); 313 } 314 }); 315 316 /* * 317 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_0900 318 * @tc.name : testNetworkMgrSocketTCPSocketBind0900 319 * @tc.desc : Bind IP address and port,Port is boundary 65536; callback 320 * @tc.size : MediumTest 321 * @tc.type : Function 322 * @tc.level : level 2 323 */ 324 it('testNetworkMgrSocketTCPSocketBind0900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 325 let caseName: string = 'testNetworkMgrSocketTCPSocketBind0900'; 326 try { 327 console.info(`${caseName} test start `); 328 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 329 expect(tcp).assertInstanceOf('Object'); 330 let bindAddress: socket.NetAddress = { 331 address: '127.0.0.1', 332 port: 65536, 333 family: 1 334 }; 335 tcp.bind(bindAddress, async (err: BusinessError) => { 336 if (err) { 337 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 338 expectFail(); 339 } else { 340 console.info(`${caseName} success`); 341 expectSuccess(); 342 } 343 await tcp.close(); 344 console.info(`${caseName} test end`); 345 done(); 346 }); 347 } catch (err) { 348 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 349 expectFail(); 350 console.info(`${caseName} test end`); 351 done(); 352 } 353 }); 354 355 /* * 356 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1000 357 * @tc.name : testNetworkMgrSocketTCPSocketBind1000 358 * @tc.desc : Bind IP address and port, bad family; callback 359 * @tc.size : MediumTest 360 * @tc.type : Function 361 * @tc.level : level 2 362 */ 363 it('testNetworkMgrSocketTCPSocketBind1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 364 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1000'; 365 try { 366 console.info(`${caseName} test start `); 367 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 368 expect(tcp).assertInstanceOf('Object'); 369 let bindAddress: socket.NetAddress = { 370 address: '127.0.0.1', 371 port: 4554, 372 family: 4 373 }; 374 tcp.bind(bindAddress, async (err: BusinessError) => { 375 if (err) { 376 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 377 expectFail(); 378 } else { 379 console.info(`${caseName} success`); 380 expectSuccess(); 381 } 382 await tcp.close(); 383 console.info(`${caseName} test end `); 384 done(); 385 }); 386 } catch (err) { 387 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 388 expectFail(); 389 console.info(`${caseName} test end `); 390 done(); 391 } 392 }); 393 394 /* * 395 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1100 396 * @tc.name : testNetworkMgrSocketTCPSocketBind1100 397 * @tc.desc : Bind IP address and port,Input parameter is null; callback 398 * @tc.size : MediumTest 399 * @tc.type : Function 400 * @tc.level : level 2 401 */ 402 it('testNetworkMgrSocketTCPSocketBind1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 403 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1100'; 404 try { 405 console.info(`${caseName} test start `); 406 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 407 expect(tcp).assertInstanceOf('Object'); 408 tcp.bind(null, (err: BusinessError) => { 409 if (err) { 410 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 411 expect(err.code).assertEqual(401); 412 } else { 413 console.info(`${caseName} success`); 414 expectFail(); 415 } 416 console.info(`${caseName} test end `); 417 done(); 418 }); 419 } catch (err) { 420 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 421 expectFail(); 422 console.info(`${caseName} test end `); 423 done(); 424 } 425 }); 426 427 /* * 428 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1200 429 * @tc.name : testNetworkMgrSocketTCPSocketBind1200 430 * @tc.desc : Bind IP address and port,Input parameter is undefined; callback 431 * @tc.size : MediumTest 432 * @tc.type : Function 433 * @tc.level : level 2 434 */ 435 it('testNetworkMgrSocketTCPSocketBind1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 436 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1200'; 437 try { 438 console.info(`${caseName} test start `); 439 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 440 expect(tcp).assertInstanceOf('Object'); 441 tcp.bind(undefined, (err: BusinessError) => { 442 if (err) { 443 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 444 expect(err.code).assertEqual(401); 445 } else { 446 console.info(`${caseName} success`); 447 expectFail(); 448 } 449 console.info(`${caseName} test end `); 450 done(); 451 }); 452 } catch (err) { 453 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 454 expectFail(); 455 console.info(`${caseName} test end `); 456 done(); 457 } 458 }); 459 460 /* * 461 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1300 462 * @tc.name : testNetworkMgrSocketTCPSocketBind1300 463 * @tc.desc : Bind IP address and port,Only fill in IPV4 address; promise 464 * @tc.size : MediumTest 465 * @tc.type : Function 466 * @tc.level : level 2 467 */ 468 it('testNetworkMgrSocketTCPSocketBind1300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 469 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1300'; 470 try { 471 console.info(`${caseName} test start `); 472 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 473 expect(tcp).assertInstanceOf('Object'); 474 let bindAddress: socket.NetAddress = { 475 address: '127.0.0.1' 476 }; 477 tcp.bind(bindAddress).then(() => { 478 console.info(`${caseName} success`); 479 expectSuccess(); 480 done(); 481 }).catch((err: BusinessError) => { 482 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 483 expectFail(); 484 done(); 485 }).finally(async () => { 486 await tcp.close(); 487 console.info(`${caseName} test end `); 488 done(); 489 }); 490 } catch (err) { 491 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 492 expectFail(); 493 console.info(`${caseName} test end `); 494 done(); 495 } 496 }); 497 498 /* * 499 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1400 500 * @tc.name : testNetworkMgrSocketTCPSocketBind1400 501 * @tc.desc : Bind IP address and port,Only fill in IPV6 address; promise 502 * @tc.size : MediumTest 503 * @tc.type : Function 504 * @tc.level : level 2 505 */ 506 it('testNetworkMgrSocketTCPSocketBind1400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 507 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1400'; 508 try { 509 console.info(`${caseName} test start `); 510 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 511 expect(tcp).assertInstanceOf('Object'); 512 let bindAddress: socket.NetAddress = { 513 address: 'fe80::b3b:ecb5:77f:88dc%12' 514 }; 515 tcp.bind(bindAddress).then(() => { 516 console.info(`${caseName} success`); 517 expectFail(); 518 done(); 519 }).catch((err: BusinessError) => { 520 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 521 expectSuccess(); 522 done(); 523 }).finally(async () => { 524 await tcp.close(); 525 console.info(`${caseName} test end `); 526 done(); 527 }); 528 } catch (err) { 529 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 530 expectFail(); 531 console.info(`${caseName} test end `); 532 done(); 533 } 534 }); 535 536 /* * 537 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1500 538 * @tc.name : testNetworkMgrSocketTCPSocketBind1500 539 * @tc.desc : Bind IP address and port,The address and protocol are both IPV6; promise 540 * @tc.size : MediumTest 541 * @tc.type : Function 542 * @tc.level : level 2 543 */ 544 it('testNetworkMgrSocketTCPSocketBind1500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 545 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1500'; 546 try { 547 console.info(`${caseName} test start `); 548 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 549 expect(tcp).assertInstanceOf('Object'); 550 let bindAddress: socket.NetAddress = { 551 address: 'fe80::b3b:ecb5:77f:88dc%12', 552 family:2 553 }; 554 tcp.bind(bindAddress).then(() => { 555 console.info(`${caseName} success`); 556 expectFail(); 557 done(); 558 }).catch((err: BusinessError) => { 559 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 560 expectTrue(err.code===2301022); 561 done(); 562 }).finally(async () => { 563 await tcp.close(); 564 console.info(`${caseName} test end `); 565 done(); 566 }); 567 } catch (err) { 568 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 569 expectFail(); 570 console.info(`${caseName} test end `); 571 done(); 572 } 573 }); 574 575 /* * 576 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1600 577 * @tc.name : testNetworkMgrSocketTCPSocketBind1600 578 * @tc.desc : Bind IP address and port,Address and protocol inversion; promise 579 * @tc.size : MediumTest 580 * @tc.type : Function 581 * @tc.level : level 2 582 */ 583 it('testNetworkMgrSocketTCPSocketBind1600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 584 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1600'; 585 try { 586 console.info(`${caseName} test start `); 587 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 588 expect(tcp).assertInstanceOf('Object'); 589 let bindAddress: socket.NetAddress = { 590 address: '127.0.0.1', 591 port: 7458, 592 family: 2 593 }; 594 tcp.bind(bindAddress).then(() => { 595 expectFail(); 596 done(); 597 }).catch((err: BusinessError) => { 598 console.info(`${caseName} fail ${JSON.stringify(err)}`); 599 expectTrue(err.code===401); 600 done(); 601 }).finally(() => { 602 console.info(`${caseName} test end`); 603 done(); 604 }); 605 } catch (err) { 606 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 607 expectFail(); 608 console.info(`${caseName} test end`); 609 done(); 610 } 611 }); 612 613 /* * 614 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1700 615 * @tc.name : testNetworkMgrSocketTCPSocketBind1700 616 * @tc.desc : Bind IP address and port, bad address; promise 617 * @tc.size : MediumTest 618 * @tc.type : Function 619 * @tc.level : level 2 620 */ 621 it('testNetworkMgrSocketTCPSocketBind1700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 622 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1700'; 623 try { 624 console.info(`${caseName} test start`); 625 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 626 expect(tcp).assertInstanceOf('Object'); 627 let bindAddress: socket.NetAddress = { 628 address: '100.0.0.1', 629 port: 7586, 630 family: 1 631 }; 632 tcp.bind(bindAddress).then(() => { 633 console.info(`${caseName} success`); 634 expectFail(); 635 done(); 636 }).catch((err: BusinessError) => { 637 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 638 expectEqual(err.code, 2301099); 639 done(); 640 }).finally(() => { 641 console.info(`${caseName} test end `); 642 done(); 643 }); 644 } catch (err) { 645 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 646 expectFail(); 647 console.info(`${caseName} test end `); 648 done(); 649 } 650 }); 651 652 /* * 653 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1800 654 * @tc.name : testNetworkMgrSocketTCPSocketBind1800 655 * @tc.desc : Bind IP address and port,Port number is -1; promise 656 * @tc.size : MediumTest 657 * @tc.type : Function 658 * @tc.level : level 2 659 */ 660 it('testNetworkMgrSocketTCPSocketBind1800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 661 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1800'; 662 try { 663 console.info(`${caseName} test start `); 664 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 665 expect(tcp).assertInstanceOf('Object'); 666 let bindAddress: socket.NetAddress = { 667 address: '127.0.0.1', 668 port: -1, 669 family: 1 670 }; 671 tcp.bind(bindAddress).then(() => { 672 console.info(`${caseName} success`); 673 expectSuccess(); 674 done(); 675 }).catch((err: BusinessError) => { 676 console.info(`${caseName} fail ${JSON.stringify(err)}`); 677 expectFail(); 678 done(); 679 }).finally(async () => { 680 await tcp.close(); 681 console.info(`${caseName} test end `); 682 done(); 683 }); 684 } catch (err) { 685 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 686 expectFail(); 687 console.info(`${caseName} test end `); 688 done(); 689 } 690 }); 691 692 /* * 693 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_1900 694 * @tc.name : testNetworkMgrSocketTCPSocketBind1900 695 * @tc.desc : Bind IP address and port,Port number is 0; promise 696 * @tc.size : MediumTest 697 * @tc.type : Function 698 * @tc.level : level 2 699 */ 700 it('testNetworkMgrSocketTCPSocketBind1900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 701 let caseName: string = 'testNetworkMgrSocketTCPSocketBind1900'; 702 try { 703 console.info(`${caseName} test start `); 704 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 705 expect(tcp).assertInstanceOf('Object'); 706 let bindAddress: socket.NetAddress = { 707 address: '127.0.0.1', 708 port: 0, 709 family: 1 710 }; 711 tcp.bind(bindAddress).then(() => { 712 console.info(`${caseName} success`); 713 expectSuccess(); 714 done(); 715 }).catch((err: BusinessError) => { 716 console.info(`${caseName} fail ${JSON.stringify(err)}`); 717 expectFail(); 718 done(); 719 }).finally(async () => { 720 await tcp.close(); 721 console.info(`${caseName} test end `); 722 done(); 723 }); 724 } catch (err) { 725 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 726 expectFail(); 727 console.info(`${caseName} test end `); 728 done(); 729 } 730 }); 731 732 /* * 733 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_2000 734 * @tc.name : testNetworkMgrSocketTCPSocketBind2000 735 * @tc.desc : Bind IP address and port,Port number is 65535; promise 736 * @tc.size : MediumTest 737 * @tc.type : Function 738 * @tc.level : level 2 739 */ 740 it('testNetworkMgrSocketTCPSocketBind2000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 741 let caseName: string = 'testNetworkMgrSocketTCPSocketBind2000'; 742 try { 743 console.info(`${caseName} test start `); 744 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 745 expect(tcp).assertInstanceOf('Object'); 746 let bindAddress: socket.NetAddress = { 747 address: '127.0.0.1', 748 port: 65535, 749 family: 1 750 }; 751 tcp.bind(bindAddress).then(() => { 752 console.info(`${caseName} success`); 753 expectSuccess(); 754 done(); 755 }).catch((err: BusinessError) => { 756 console.info(`${caseName} fail ${JSON.stringify(err)}`); 757 expectFail(); 758 done(); 759 }).finally(async () => { 760 await tcp.close(); 761 console.info(`${caseName} test end `); 762 done(); 763 }); 764 } catch (err) { 765 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 766 expectFail(); 767 console.info(`${caseName} test end `); 768 done(); 769 } 770 }); 771 772 /* * 773 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_2100 774 * @tc.name : testNetworkMgrSocketTCPSocketBind2100 775 * @tc.desc : Bind IP address and port,Port number is 65536; promise 776 * @tc.size : MediumTest 777 * @tc.type : Function 778 * @tc.level : level 2 779 */ 780 it('testNetworkMgrSocketTCPSocketBind2100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 781 let caseName: string = 'testNetworkMgrSocketTCPSocketBind2100'; 782 try { 783 console.info(`${caseName} test start `); 784 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 785 expect(tcp).assertInstanceOf('Object'); 786 let bindAddress: socket.NetAddress = { 787 address: '127.0.0.1', 788 port: 65536, 789 family: 1 790 }; 791 tcp.bind(bindAddress).then(() => { 792 console.info(`${caseName} success`); 793 expectSuccess(); 794 done(); 795 }).catch((err: BusinessError) => { 796 console.info(`${caseName} fail ${JSON.stringify(err)}`); 797 expectFail(); 798 done(); 799 }).finally(async () => { 800 await tcp.close(); 801 console.info(`${caseName} test end `); 802 done(); 803 }); 804 } catch (err) { 805 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 806 expectFail(); 807 console.info(`${caseName} test end `); 808 done(); 809 } 810 }); 811 812 /* * 813 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_2200 814 * @tc.name : testNetworkMgrSocketTCPSocketBind2200 815 * @tc.desc : Bind IP address and port, bad family; promise 816 * @tc.size : MediumTest 817 * @tc.type : Function 818 * @tc.level : level 2 819 */ 820 it('testNetworkMgrSocketTCPSocketBind2200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 821 let caseName: string = 'testNetworkMgrSocketTCPSocketBind2200'; 822 try { 823 console.info(`${caseName} test start `); 824 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 825 expect(tcp).assertInstanceOf('Object'); 826 let bindAddress: socket.NetAddress = { 827 address: '127.0.0.1', 828 port: 6335, 829 family: 4 830 }; 831 tcp.bind(bindAddress).then(() => { 832 console.info(`${caseName} success`); 833 expectSuccess(); 834 done(); 835 }).catch((err: BusinessError) => { 836 console.info(`${caseName} fail ${JSON.stringify(err)}`); 837 expectFail(); 838 done(); 839 }).finally(async () => { 840 await tcp.close(); 841 console.info(`${caseName} test end `); 842 done(); 843 }); 844 } catch (err) { 845 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 846 expectFail(); 847 console.info(`${caseName} test end `); 848 done(); 849 } 850 }); 851 852 /* * 853 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_2300 854 * @tc.name : testNetworkMgrSocketTCPSocketBind2300 855 * @tc.desc : Bind IP address and port with null; promise 856 * @tc.size : MediumTest 857 * @tc.type : Function 858 * @tc.level : level 2 859 */ 860 it('testNetworkMgrSocketTCPSocketBind2300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 861 let caseName: string = 'testNetworkMgrSocketTCPSocketBind2300'; 862 try { 863 console.info(`${caseName} test start `); 864 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 865 expect(tcp).assertInstanceOf('Object'); 866 tcp.bind(null).then(() => { 867 expectFail(); 868 done(); 869 }).catch((err: BusinessError) => { 870 console.info(`${caseName} fail ${JSON.stringify(err)}`); 871 expect(err.code).assertEqual(401); 872 done(); 873 }).finally(() => { 874 console.info(`${caseName} test end`); 875 done(); 876 }); 877 } catch (err) { 878 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 879 expectFail(); 880 console.info(`${caseName} test end`); 881 done(); 882 } 883 }); 884 885 /* * 886 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_2400 887 * @tc.name : testNetworkMgrSocketTCPSocketBind2400 888 * @tc.desc : Bind IP address and port with undefined; promise 889 * @tc.size : MediumTest 890 * @tc.type : Function 891 * @tc.level : level 2 892 */ 893 it('testNetworkMgrSocketTCPSocketBind2400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 894 let caseName: string = 'testNetworkMgrSocketTCPSocketBind2400'; 895 try { 896 console.info(`${caseName} test start `); 897 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 898 expect(tcp).assertInstanceOf('Object'); 899 tcp.bind(undefined).then(() => { 900 expectFail(); 901 done(); 902 }).catch((err: BusinessError) => { 903 console.info(`${caseName} fail ${JSON.stringify(err)}`); 904 expect(err.code).assertEqual(401); 905 done(); 906 }).finally(() => { 907 console.info(`${caseName} test end`); 908 done(); 909 }); 910 } catch (err) { 911 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 912 expectFail(); 913 console.info(`${caseName} test end`); 914 done(); 915 } 916 }); 917 918 /* * 919 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Bind_2500 920 * @tc.name : testNetworkMgrSocketTCPSocketBind2500 921 * @tc.desc : Bind IP address and port,Address is Domain name ; promise 922 * @tc.size : MediumTest 923 * @tc.type : Function 924 * @tc.level : level 2 925 */ 926 it('testNetworkMgrSocketTCPSocketBind2500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 927 let caseName: string = 'testNetworkMgrSocketTCPSocketBind2500'; 928 try { 929 console.info(`${caseName} test start `); 930 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 931 expect(tcp).assertInstanceOf('Object'); 932 let bindAddress: socket.NetAddress = { 933 address: 'www.baidu.com', 934 port: 80, 935 family: 1 936 }; 937 tcp.bind(bindAddress).then(() => { 938 expectFail(); 939 done(); 940 }).catch((err: BusinessError) => { 941 console.info(`${caseName} fail ${JSON.stringify(err)}`); 942 expectTrue(err.code===401); 943 done(); 944 }).finally(() => { 945 console.info(`${caseName} test end`); 946 done(); 947 }); 948 } catch (err) { 949 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 950 expectFail(); 951 console.info(`${caseName} test end`); 952 done(); 953 } 954 }); 955 956 /* * 957 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_0100 958 * @tc.name : testNetworkMgrSocketTCPSocketConnect0100 959 * @tc.desc : Connect to the specified server IP address and port; callback 960 * @tc.size : MediumTest 961 * @tc.type : Function 962 * @tc.level : level 2 963 */ 964 it('testNetworkMgrSocketTCPSocketConnect0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 965 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect0100'; 966 try { 967 console.info(`${caseName} test start`); 968 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 969 expect(tcp).assertInstanceOf('Object'); 970 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 971 expect(tcpServer).assertInstanceOf('Object'); 972 let listenAddress: socket.NetAddress = { 973 address: '127.0.0.1', 974 port: 4001, 975 family: 1 976 }; 977 await tcpServer.listen(listenAddress); 978 let tcpConnectOptions: socket.TCPConnectOptions = { 979 address:listenAddress 980 }; 981 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 982 if (err) { 983 console.info(`${caseName} fail ${JSON.stringify(err)}`); 984 expectFail(); 985 } else { 986 console.info(`${caseName} success`); 987 expectSuccess(); 988 } 989 await tcp.close(); 990 console.info(`${caseName} test end`); 991 done(); 992 }); 993 } catch (err) { 994 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 995 expectFail(); 996 console.info(`${caseName} test end`); 997 done(); 998 } 999 }); 1000 1001 /* * 1002 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_0200 1003 * @tc.name : testNetworkMgrSocketTCPSocketConnect0200 1004 * @tc.desc : Connect to the specified IP address and port,Input parameter is null; callback 1005 * @tc.size : MediumTest 1006 * @tc.type : Function 1007 * @tc.level : level 2 1008 */ 1009 it('testNetworkMgrSocketTCPSocketConnect0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1010 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect0200'; 1011 try { 1012 console.info(`${caseName} test start`); 1013 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1014 expect(tcp).assertInstanceOf('Object'); 1015 let bindAddress: socket.NetAddress = { 1016 address: '127.0.0.1', 1017 port: 4002, 1018 family: 1 1019 }; 1020 await tcp.bind(bindAddress); 1021 tcp.connect(null, async (err: BusinessError) => { 1022 if (err) { 1023 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1024 expectTrue(err.code===401); 1025 } else { 1026 console.info(`${caseName} success`); 1027 expectFail(); 1028 } 1029 await tcp.close(); 1030 console.info(`${caseName} test end`); 1031 done(); 1032 }); 1033 } catch (err) { 1034 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1035 expectFail(); 1036 console.info(`${caseName} test end`); 1037 done(); 1038 } 1039 }); 1040 1041 /* * 1042 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_0300 1043 * @tc.name : testNetworkMgrSocketTCPSocketConnect0300 1044 * @tc.desc : Connect to the specified IP address and port,Input parameter is undefined; callback 1045 * @tc.size : MediumTest 1046 * @tc.type : Function 1047 * @tc.level : level 2 1048 */ 1049 it('testNetworkMgrSocketTCPSocketConnect0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1050 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect0300'; 1051 try { 1052 console.info(`${caseName} test start`); 1053 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1054 expect(tcp).assertInstanceOf('Object'); 1055 let bindAddress: socket.NetAddress = { 1056 address: '127.0.0.1', 1057 port: 4003, 1058 family: 1 1059 }; 1060 await tcp.bind(bindAddress); 1061 tcp.connect(undefined, async (err: BusinessError) => { 1062 if (err) { 1063 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1064 expectTrue(err.code===401); 1065 } else { 1066 console.info(`${caseName} success`); 1067 expectFail(); 1068 } 1069 await tcp.close(); 1070 console.info(`${caseName} test end`); 1071 done(); 1072 }); 1073 } catch (err) { 1074 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1075 expectFail(); 1076 console.info(`${caseName} test end`); 1077 done(); 1078 } 1079 }); 1080 1081 /* * 1082 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_0400 1083 * @tc.name : testNetworkMgrSocketTCPSocketConnect0400 1084 * @tc.desc : Connect to the specified IP address and port,Set timeout and address; callback 1085 * @tc.size : MediumTest 1086 * @tc.type : Function 1087 * @tc.level : level 2 1088 */ 1089 it('testNetworkMgrSocketTCPSocketConnect0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1090 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect0400'; 1091 try { 1092 console.info(`${caseName} test start`); 1093 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1094 expect(tcp).assertInstanceOf('Object'); 1095 let bindAddress: socket.NetAddress = { 1096 address: '127.0.0.1', 1097 port: 4004, 1098 family: 1 1099 }; 1100 await tcp.bind(bindAddress); 1101 let tcpConnectOptions: socket.TCPConnectOptions = { 1102 address: { 1103 address: '127.0.0.1', 1104 port: 4004, 1105 family: 1 1106 }, 1107 timeout:5000 1108 }; 1109 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1110 if (err) { 1111 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1112 expectFail(); 1113 } else { 1114 console.info(`${caseName} success`); 1115 expectSuccess(); 1116 } 1117 await tcp.close(); 1118 console.info(`${caseName} test end`); 1119 done(); 1120 }); 1121 } catch (err) { 1122 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1123 expectFail(); 1124 console.info(`${caseName} test end`); 1125 done(); 1126 } 1127 }); 1128 1129 /* * 1130 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_0500 1131 * @tc.name : testNetworkMgrSocketTCPSocketConnect0500 1132 * @tc.desc : Connect to the specified IP address and port,hour is undefined; callback 1133 * @tc.size : MediumTest 1134 * @tc.type : Function 1135 * @tc.level : level 2 1136 */ 1137 it('testNetworkMgrSocketTCPSocketConnect0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1138 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect0500'; 1139 try { 1140 console.info(`${caseName} test start`); 1141 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1142 expect(tcp).assertInstanceOf('Object'); 1143 let bindAddress: socket.NetAddress = { 1144 address: '127.0.0.1', 1145 port: 4005, 1146 family: 1 1147 }; 1148 await tcp.bind(bindAddress); 1149 let tcpConnectOptions: socket.TCPConnectOptions = { 1150 address: bindAddress, 1151 timeout:undefined 1152 }; 1153 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1154 if (err) { 1155 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1156 expectFail(); 1157 } else { 1158 console.info(`${caseName} success`); 1159 expectSuccess(); 1160 } 1161 await tcp.close(); 1162 console.info(`${caseName} test end`); 1163 done(); 1164 }); 1165 } catch (err) { 1166 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1167 expectFail(); 1168 console.info(`${caseName} test end`); 1169 done(); 1170 } 1171 }); 1172 1173 /* * 1174 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_0600 1175 * @tc.name : testNetworkMgrSocketTCPSocketConnect0600 1176 * @tc.desc : Connect to the specified IP address and port, only has an IPV4 address; callback 1177 * @tc.size : MediumTest 1178 * @tc.type : Function 1179 * @tc.level : level 2 1180 */ 1181 it('testNetworkMgrSocketTCPSocketConnect0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1182 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect0600'; 1183 try { 1184 console.info(`${caseName} test start`); 1185 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1186 expect(tcp).assertInstanceOf('Object'); 1187 let bindAddress: socket.NetAddress = { 1188 address: '127.0.0.1', 1189 port: 4006, 1190 family: 1 1191 }; 1192 await tcp.bind(bindAddress); 1193 let tcpConnectOptions: socket.TCPConnectOptions = { 1194 address: { 1195 address: '127.0.0.1' 1196 } 1197 }; 1198 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1199 if (err) { 1200 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1201 expectTrue(err.code===2301115); 1202 } else { 1203 console.info(`${caseName} success`); 1204 expectFail(); 1205 } 1206 await tcp.close(); 1207 console.info(`${caseName} test end`); 1208 done(); 1209 }); 1210 } catch (err) { 1211 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1212 expectFail(); 1213 console.info(`${caseName} test end`); 1214 done(); 1215 } 1216 }); 1217 1218 /* * 1219 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_0700 1220 * @tc.name : testNetworkMgrSocketTCPSocketConnect0700 1221 * @tc.desc : Connect to the specified IP address and port, only has an IPV6 address; callback 1222 * @tc.size : MediumTest 1223 * @tc.type : Function 1224 * @tc.level : level 2 1225 */ 1226 it('testNetworkMgrSocketTCPSocketConnect0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1227 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect0700'; 1228 try { 1229 console.info(`${caseName} test start`); 1230 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1231 expect(tcp).assertInstanceOf('Object'); 1232 let bindAddress: socket.NetAddress = { 1233 address: 'fe80::b3b:ecb5:77f:88dc%12', 1234 port: 4007, 1235 family: 2 1236 }; 1237 await tcp.bind(bindAddress); 1238 let tcpConnectOptions: socket.TCPConnectOptions = { 1239 address: { 1240 address: 'fe80::b3b:ecb5:77f:88dc%12' 1241 } 1242 }; 1243 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1244 if (err) { 1245 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1246 expectFail(); 1247 } else { 1248 console.info(`${caseName} success`); 1249 expectSuccess(); 1250 } 1251 await tcp.close(); 1252 console.info(`${caseName} test end`); 1253 done(); 1254 }); 1255 } catch (err) { 1256 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1257 expectTrue(err.code===2301022); 1258 console.info(`${caseName} test end`); 1259 done(); 1260 } 1261 }); 1262 1263 /* * 1264 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_0800 1265 * @tc.name : testNetworkMgrSocketTCPSocketConnect0800 1266 * @tc.desc : Connect to the specified IP address and port,The address and protocol are both IPV6; callback 1267 * @tc.size : MediumTest 1268 * @tc.type : Function 1269 * @tc.level : level 2 1270 */ 1271 it('testNetworkMgrSocketTCPSocketConnect0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1272 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect0800'; 1273 try { 1274 console.info(`${caseName} test start`); 1275 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1276 expect(tcp).assertInstanceOf('Object'); 1277 let bindAddress: socket.NetAddress = { 1278 address: 'fe80::b3b:ecb5:77f:88dc%12', 1279 port: 4008, 1280 family: 2 1281 }; 1282 await tcp.bind(bindAddress); 1283 let tcpConnectOptions: socket.TCPConnectOptions = { 1284 address: bindAddress 1285 }; 1286 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1287 if (err) { 1288 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1289 expectFail(); 1290 } else { 1291 console.info(`${caseName} success`); 1292 expectSuccess(); 1293 } 1294 await tcp.close(); 1295 console.info(`${caseName} test end`); 1296 done(); 1297 }); 1298 } catch (err) { 1299 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1300 expectTrue(err.code===2301022); 1301 console.info(`${caseName} test end`); 1302 done(); 1303 } 1304 }); 1305 1306 /* * 1307 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1000 1308 * @tc.name : testNetworkMgrSocketTCPSocketConnect1000 1309 * @tc.desc : Connect to the specified IP address and port,bad address; callback 1310 * @tc.size : MediumTest 1311 * @tc.type : Function 1312 * @tc.level : level 2 1313 */ 1314 it('testNetworkMgrSocketTCPSocketConnect1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1315 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1000'; 1316 try { 1317 console.info(`${caseName} test start`); 1318 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1319 expect(tcp).assertInstanceOf('Object'); 1320 let bindAddress: socket.NetAddress = { 1321 address: '127.0.0.1', 1322 port: 4010, 1323 family: 1 1324 }; 1325 await tcp.bind(bindAddress); 1326 let tcpConnectOptions: socket.TCPConnectOptions = { 1327 address: { 1328 address: '100.0.0.0', 1329 port: 4010, 1330 family: 1 1331 } 1332 }; 1333 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1334 if (err) { 1335 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1336 expectTrue(err.code===2301022); 1337 } else { 1338 console.info(`${caseName} success`); 1339 expectFail(); 1340 } 1341 await tcp.close(); 1342 console.info(`${caseName} test end`); 1343 done(); 1344 }); 1345 } catch (err) { 1346 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1347 expectFail(); 1348 console.info(`${caseName} test end`); 1349 done(); 1350 } 1351 }); 1352 1353 /* * 1354 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1100 1355 * @tc.name : testNetworkMgrSocketTCPSocketConnect1100 1356 * @tc.desc : Connect to the specified IP address and port,Port is -1; callback 1357 * @tc.size : MediumTest 1358 * @tc.type : Function 1359 * @tc.level : level 2 1360 */ 1361 it('testNetworkMgrSocketTCPSocketConnect1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1362 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1100'; 1363 try { 1364 console.info(`${caseName} test start`); 1365 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1366 expect(tcp).assertInstanceOf('Object'); 1367 let bindAddress: socket.NetAddress = { 1368 address: '127.0.0.1', 1369 port: -1, 1370 family: 1 1371 }; 1372 await tcp.bind(bindAddress); 1373 let tcpConnectOptions: socket.TCPConnectOptions = { 1374 address: { 1375 address: '127.0.0.1', 1376 port: -1, 1377 family: 1 1378 } 1379 }; 1380 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1381 if (err) { 1382 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1383 expectFail(); 1384 } else { 1385 console.info(`${caseName} success`); 1386 expectSuccess(); 1387 } 1388 await tcp.close(); 1389 console.info(`${caseName} test end`); 1390 done(); 1391 }); 1392 } catch (err) { 1393 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1394 expectFail(); 1395 console.info(`${caseName} test end`); 1396 done(); 1397 } 1398 }); 1399 1400 /* * 1401 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1200 1402 * @tc.name : testNetworkMgrSocketTCPSocketConnect1200 1403 * @tc.desc : Connect to the specified IP address and port,Port is -0; callback 1404 * @tc.size : MediumTest 1405 * @tc.type : Function 1406 * @tc.level : level 2 1407 */ 1408 it('testNetworkMgrSocketTCPSocketConnect1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1409 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1200'; 1410 try { 1411 console.info(`${caseName} test start`); 1412 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1413 expect(tcp).assertInstanceOf('Object'); 1414 let bindAddress: socket.NetAddress = { 1415 address: '127.0.0.1', 1416 port: 0, 1417 family: 1 1418 }; 1419 await tcp.bind(bindAddress); 1420 let tcpConnectOptions: socket.TCPConnectOptions = { 1421 address: { 1422 address: '127.0.0.1', 1423 port: 0, 1424 family: 1 1425 } 1426 }; 1427 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1428 if (err.code === 2301115) { 1429 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1430 expectSuccess(); 1431 } else { 1432 console.info(`${caseName} success`); 1433 expectFail(); 1434 } 1435 await tcp.close(); 1436 console.info(`${caseName} test end`); 1437 done(); 1438 }); 1439 } catch (err) { 1440 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1441 expectFail(); 1442 console.info(`${caseName} test end`); 1443 done(); 1444 } 1445 }); 1446 1447 /* * 1448 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1300 1449 * @tc.name : testNetworkMgrSocketTCPSocketConnect1300 1450 * @tc.desc : Connect to the specified IP address and port,Port is 65535; callback 1451 * @tc.size : MediumTest 1452 * @tc.type : Function 1453 * @tc.level : level 2 1454 */ 1455 it('testNetworkMgrSocketTCPSocketConnect1300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1456 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1300'; 1457 try { 1458 console.info(`${caseName} test start`); 1459 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1460 expect(tcp).assertInstanceOf('Object'); 1461 let bindAddress: socket.NetAddress = { 1462 address: '127.0.0.1', 1463 port: 65535, 1464 family: 1 1465 }; 1466 await tcp.bind(bindAddress); 1467 let tcpConnectOptions: socket.TCPConnectOptions = { 1468 address: { 1469 address: '127.0.0.1', 1470 port: 65535, 1471 family: 1 1472 } 1473 }; 1474 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1475 if (err.code === 2301115) { 1476 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1477 expectSuccess(); 1478 } else { 1479 console.info(`${caseName} success`); 1480 expectFail(); 1481 } 1482 await tcp.close(); 1483 console.info(`${caseName} test end`); 1484 done(); 1485 }); 1486 } catch (err) { 1487 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1488 expectFail(); 1489 console.info(`${caseName} test end`); 1490 done(); 1491 } 1492 }); 1493 1494 /* * 1495 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1400 1496 * @tc.name : testNetworkMgrSocketTCPSocketConnect1400 1497 * @tc.desc : Connect to the specified IP address and port,Port is 65536; callback 1498 * @tc.size : MediumTest 1499 * @tc.type : Function 1500 * @tc.level : level 2 1501 */ 1502 it('testNetworkMgrSocketTCPSocketConnect1400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1503 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1400'; 1504 try { 1505 console.info(`${caseName} test start`); 1506 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1507 expect(tcp).assertInstanceOf('Object'); 1508 let bindAddress: socket.NetAddress = { 1509 address: '127.0.0.1', 1510 port: 65536, 1511 family: 1 1512 }; 1513 await tcp.bind(bindAddress); 1514 let tcpConnectOptions: socket.TCPConnectOptions = { 1515 address: { 1516 address: '127.0.0.1', 1517 port: 65536, 1518 family: 1 1519 } 1520 }; 1521 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1522 if (err) { 1523 console.info(`${caseName} success`); 1524 expectSuccess(); 1525 } else { 1526 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1527 expectFail(); 1528 } 1529 await tcp.close(); 1530 console.info(`${caseName} test end`); 1531 done(); 1532 }); 1533 } catch (err) { 1534 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1535 expectSuccess(); 1536 console.info(`${caseName} test end`); 1537 done(); 1538 } 1539 }); 1540 1541 /* * 1542 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1500 1543 * @tc.name : testNetworkMgrSocketTCPSocketConnect1500 1544 * @tc.desc : Connect to the specified IP address and port,bad family; callback 1545 * @tc.size : MediumTest 1546 * @tc.type : Function 1547 * @tc.level : level 2 1548 */ 1549 it('testNetworkMgrSocketTCPSocketConnect1500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1550 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1500'; 1551 try { 1552 console.info(`${caseName} test start`); 1553 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1554 expect(tcp).assertInstanceOf('Object'); 1555 let bindAddress: socket.NetAddress = { 1556 address: '127.0.0.1', 1557 port: 4015, 1558 family: 1 1559 }; 1560 await tcp.bind(bindAddress); 1561 let tcpConnectOptions: socket.TCPConnectOptions = { 1562 address: { 1563 address: '127.0.0.1', 1564 port: 4015, 1565 family: 3 1566 } 1567 }; 1568 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1569 if (err) { 1570 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1571 expectFail(); 1572 } else { 1573 console.info(`${caseName} success`); 1574 expectSuccess(); 1575 } 1576 await tcp.close(); 1577 console.info(`${caseName} test end`); 1578 done(); 1579 }); 1580 } catch (err) { 1581 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1582 expectFail(); 1583 console.info(`${caseName} test end`); 1584 done(); 1585 } 1586 }); 1587 1588 /* * 1589 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1600 1590 * @tc.name : testNetworkMgrSocketTCPSocketConnect1600 1591 * @tc.desc : Connect to the specified IP address and port,Connect without binding or listening; callback 1592 * @tc.size : MediumTest 1593 * @tc.type : Function 1594 * @tc.level : level 2 1595 */ 1596 it('testNetworkMgrSocketTCPSocketConnect1600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1597 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1600'; 1598 try { 1599 console.info(`${caseName} test start`); 1600 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1601 expect(tcp).assertInstanceOf('Object'); 1602 let tcpConnectOptions: socket.TCPConnectOptions = { 1603 address: { 1604 address: '127.0.0.1', 1605 port: 4016, 1606 family: 1 1607 } 1608 }; 1609 tcp.connect(tcpConnectOptions, async (err: BusinessError) => { 1610 if (err) { 1611 console.info(`${caseName} fail ${JSON.stringify(err)}`); 1612 expectTrue(err.code===2301115); 1613 } else { 1614 console.info(`${caseName} success`); 1615 expectSuccess(); 1616 } 1617 console.info(`${caseName} test end`); 1618 done(); 1619 }); 1620 } catch (err) { 1621 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 1622 expectFail(); 1623 console.info(`${caseName} test end`); 1624 done(); 1625 } 1626 }); 1627 1628 /* * 1629 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1700 1630 * @tc.name : testNetworkMgrSocketTCPSocketConnect1700 1631 * @tc.desc : Connect to the specified server IP address and port; promise 1632 * @tc.size : MediumTest 1633 * @tc.type : Function 1634 * @tc.level : level 2 1635 */ 1636 it('testNetworkMgrSocketTCPSocketConnect1700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1637 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1700'; 1638 try { 1639 console.info(`${caseName} test start`); 1640 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1641 expect(tcp).assertInstanceOf('Object'); 1642 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 1643 expect(tcpServer).assertInstanceOf('Object'); 1644 let listenAddress: socket.NetAddress = { 1645 address: '127.0.0.1', 1646 port: 4017 1647 }; 1648 await tcpServer.listen(listenAddress); 1649 let tcpConnectOptions: socket.TCPConnectOptions = { 1650 address: { 1651 address: '127.0.0.1', 1652 port: 4017 1653 }, 1654 }; 1655 tcp.connect(tcpConnectOptions).then(() => { 1656 console.info(`${caseName} success`); 1657 expectSuccess(); 1658 done(); 1659 }).catch((err: BusinessError) => { 1660 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 1661 expectFail(); 1662 done(); 1663 }).finally(async () => { 1664 await tcp.close(); 1665 console.info(`${caseName} test end`); 1666 done(); 1667 }); 1668 } catch (err) { 1669 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 1670 expectFail(); 1671 console.info(`${caseName} test end`); 1672 done(); 1673 } 1674 }); 1675 1676 /* * 1677 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1800 1678 * @tc.name : testNetworkMgrSocketTCPSocketConnect1800 1679 * @tc.desc : Connect to the specified IP address and port,Input parameter is null; promise 1680 * @tc.size : MediumTest 1681 * @tc.type : Function 1682 * @tc.level : level 2 1683 */ 1684 it('testNetworkMgrSocketTCPSocketConnect1800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1685 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1800'; 1686 try { 1687 console.info(`${caseName} test start`); 1688 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1689 expect(tcp).assertInstanceOf('Object'); 1690 let bindAddress: socket.NetAddress = { 1691 address: '127.0.0.1', 1692 port: 4018 1693 }; 1694 await tcp.bind(bindAddress); 1695 tcp.connect(null).then(() => { 1696 console.info(`${caseName} success`); 1697 expectFail(); 1698 done(); 1699 }).catch((err: BusinessError) => { 1700 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 1701 expectTrue(err.code===401); 1702 done(); 1703 }).finally(async () => { 1704 await tcp.close(); 1705 console.info(`${caseName} test end`); 1706 done(); 1707 }); 1708 } catch (err) { 1709 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 1710 expectFail(); 1711 console.info(`${caseName} test end`); 1712 done(); 1713 } 1714 }); 1715 1716 /* * 1717 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_1900 1718 * @tc.name : testNetworkMgrSocketTCPSocketConnect1900 1719 * @tc.desc : Connect to the specified IP address and port,Input parameter is undefined; promise 1720 * @tc.size : MediumTest 1721 * @tc.type : Function 1722 * @tc.level : level 2 1723 */ 1724 it('testNetworkMgrSocketTCPSocketConnect1900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1725 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect1900'; 1726 try { 1727 console.info(`${caseName} test start`); 1728 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1729 expect(tcp).assertInstanceOf('Object'); 1730 let bindAddress: socket.NetAddress = { 1731 address: '127.0.0.1', 1732 port: 4019 1733 }; 1734 await tcp.bind(bindAddress); 1735 tcp.connect(undefined).then(() => { 1736 console.info(`${caseName} success`); 1737 expectFail(); 1738 done(); 1739 }).catch((err: BusinessError) => { 1740 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 1741 expectTrue(err.code===401); 1742 done(); 1743 }).finally(async () => { 1744 await tcp.close(); 1745 console.info(`${caseName} test end`); 1746 done(); 1747 }); 1748 } catch (err) { 1749 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 1750 expectFail(); 1751 console.info(`${caseName} test end`); 1752 done(); 1753 } 1754 }); 1755 1756 /* * 1757 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2000 1758 * @tc.name : testNetworkMgrSocketTCPSocketConnect2000 1759 * @tc.desc : Connect to the specified IP address and port,Set timeout and address; promise 1760 * @tc.size : MediumTest 1761 * @tc.type : Function 1762 * @tc.level : level 2 1763 */ 1764 it('testNetworkMgrSocketTCPSocketConnect2000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1765 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2000'; 1766 try { 1767 console.info(`${caseName} test start`); 1768 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1769 expect(tcp).assertInstanceOf('Object'); 1770 let bindAddress: socket.NetAddress = { 1771 address: '127.0.0.1', 1772 port: 4020, 1773 family:1 1774 }; 1775 await tcp.bind(bindAddress); 1776 let tcpConnectOptions: socket.TCPConnectOptions = { 1777 address: { 1778 address: '127.0.0.1', 1779 port: 4020, 1780 family:1 1781 }, 1782 timeout:5000 1783 }; 1784 tcp.connect(tcpConnectOptions).then(() => { 1785 console.info(`${caseName} success`); 1786 expectSuccess(); 1787 done(); 1788 }).catch((err: BusinessError) => { 1789 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 1790 expectFail(); 1791 done(); 1792 }).finally(async () => { 1793 await tcp.close(); 1794 console.info(`${caseName} test end`); 1795 done(); 1796 }); 1797 } catch (err) { 1798 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 1799 expectFail(); 1800 console.info(`${caseName} test end`); 1801 done(); 1802 } 1803 }); 1804 1805 /* * 1806 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2100 1807 * @tc.name : testNetworkMgrSocketTCPSocketConnect2100 1808 * @tc.desc : Connect to the specified IP address and port,hour is undefined; promise 1809 * @tc.size : MediumTest 1810 * @tc.type : Function 1811 * @tc.level : level 2 1812 */ 1813 it('testNetworkMgrSocketTCPSocketConnect2100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1814 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2100'; 1815 try { 1816 console.info(`${caseName} test start`); 1817 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1818 expect(tcp).assertInstanceOf('Object'); 1819 let bindAddress: socket.NetAddress = { 1820 address: '127.0.0.1', 1821 port: 4021, 1822 family:1 1823 }; 1824 await tcp.bind(bindAddress); 1825 let tcpConnectOptions: socket.TCPConnectOptions = { 1826 address: { 1827 address: '127.0.0.1', 1828 port: 4021 1829 }, 1830 timeout:undefined 1831 }; 1832 tcp.connect(tcpConnectOptions).then(() => { 1833 console.info(`${caseName} success`); 1834 expectSuccess(); 1835 done(); 1836 }).catch((err: BusinessError) => { 1837 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 1838 expectFail(); 1839 done(); 1840 }).finally(async () => { 1841 await tcp.close(); 1842 console.info(`${caseName} test end`); 1843 done(); 1844 }); 1845 } catch (err) { 1846 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 1847 expectFail(); 1848 console.info(`${caseName} test end`); 1849 done(); 1850 } 1851 }); 1852 1853 /* * 1854 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2200 1855 * @tc.name : testNetworkMgrSocketTCPSocketConnect2200 1856 * @tc.desc : Connect to the specified IP address and port, only has an IPV4 address; promise 1857 * @tc.size : MediumTest 1858 * @tc.type : Function 1859 * @tc.level : level 2 1860 */ 1861 it('testNetworkMgrSocketTCPSocketConnect2200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1862 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2200'; 1863 try { 1864 console.info(`${caseName} test start`); 1865 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1866 expect(tcp).assertInstanceOf('Object'); 1867 let bindAddress: socket.NetAddress = { 1868 address: '127.0.0.1', 1869 port: 4022, 1870 family:1 1871 }; 1872 await tcp.bind(bindAddress); 1873 let tcpConnectOptions: socket.TCPConnectOptions = { 1874 address: { 1875 address: '127.0.0.1' 1876 } 1877 }; 1878 tcp.connect(tcpConnectOptions).then(() => { 1879 console.info(`${caseName} success`); 1880 expectFail(); 1881 done(); 1882 }).catch((err: BusinessError) => { 1883 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 1884 expectTrue(err.code===2301115); 1885 done(); 1886 }).finally(async () => { 1887 await tcp.close(); 1888 console.info(`${caseName} test end`); 1889 done(); 1890 }); 1891 } catch (err) { 1892 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 1893 expectFail(); 1894 console.info(`${caseName} test end`); 1895 done(); 1896 } 1897 }); 1898 1899 /* * 1900 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2300 1901 * @tc.name : testNetworkMgrSocketTCPSocketConnect2300 1902 * @tc.desc : Connect to the specified IP address and port, only has an IPV6 address; promise 1903 * @tc.size : MediumTest 1904 * @tc.type : Function 1905 * @tc.level : level 2 1906 */ 1907 it('testNetworkMgrSocketTCPSocketConnect2300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1908 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2300'; 1909 try { 1910 console.info(`${caseName} test start`); 1911 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1912 expect(tcp).assertInstanceOf('Object'); 1913 let bindAddress: socket.NetAddress = { 1914 address: 'fe80::b3b:ecb5:77f:88dc%12', 1915 port: 4023, 1916 family:2 1917 }; 1918 await tcp.bind(bindAddress); 1919 let tcpConnectOptions: socket.TCPConnectOptions = { 1920 address: { 1921 address:'fe80::b3b:ecb5:77f:88dc%12' 1922 } 1923 }; 1924 tcp.connect(tcpConnectOptions).then(() => { 1925 console.info(`${caseName} success`); 1926 expectSuccess(); 1927 done(); 1928 }).catch((err: BusinessError) => { 1929 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 1930 expectFail(); 1931 done(); 1932 }).finally(async () => { 1933 await tcp.close(); 1934 console.info(`${caseName} test end`); 1935 done(); 1936 }); 1937 } catch (err) { 1938 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 1939 expectTrue(err.code===2301022); 1940 console.info(`${caseName} test end`); 1941 done(); 1942 } 1943 }); 1944 1945 /* * 1946 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2400 1947 * @tc.name : testNetworkMgrSocketTCPSocketConnect2400 1948 * @tc.desc : Connect to the specified IP address and port,The address and protocol are both IPV6; promise 1949 * @tc.size : MediumTest 1950 * @tc.type : Function 1951 * @tc.level : level 2 1952 */ 1953 it('testNetworkMgrSocketTCPSocketConnect2400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1954 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2400'; 1955 try { 1956 console.info(`${caseName} test start`); 1957 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 1958 expect(tcp).assertInstanceOf('Object'); 1959 let bindAddress: socket.NetAddress = { 1960 address: 'fe80::b3b:ecb5:77f:88dc%12', 1961 port: 4024, 1962 family:2 1963 }; 1964 await tcp.bind(bindAddress); 1965 let tcpConnectOptions: socket.TCPConnectOptions = { 1966 address: bindAddress 1967 }; 1968 tcp.connect(tcpConnectOptions).then(() => { 1969 console.info(`${caseName} success`); 1970 expectSuccess(); 1971 done(); 1972 }).catch((err: BusinessError) => { 1973 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 1974 expectFail(); 1975 done(); 1976 }).finally(async () => { 1977 await tcp.close(); 1978 console.info(`${caseName} test end`); 1979 done(); 1980 }); 1981 } catch (err) { 1982 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 1983 expectTrue(err.code===2301022); 1984 console.info(`${caseName} test end`); 1985 done(); 1986 } 1987 }); 1988 1989 /* * 1990 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2500 1991 * @tc.name : testNetworkMgrSocketTCPSocketConnect2500 1992 * @tc.desc : Connect to the specified IP address and port,Address and protocol inversion; promise 1993 * @tc.size : MediumTest 1994 * @tc.type : Function 1995 * @tc.level : level 2 1996 */ 1997 it('testNetworkMgrSocketTCPSocketConnect2500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 1998 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2500'; 1999 try { 2000 console.info(`${caseName} test start`); 2001 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2002 expect(tcp).assertInstanceOf('Object'); 2003 let bindAddress: socket.NetAddress = { 2004 address: '127.0.0.1', 2005 port: 4025, 2006 family:1 2007 }; 2008 await tcp.bind(bindAddress); 2009 let tcpConnectOptions: socket.TCPConnectOptions = { 2010 address: { 2011 address: '127.0.0.1', 2012 port: 4025, 2013 family: 2 2014 } 2015 }; 2016 tcp.connect(tcpConnectOptions).then(() => { 2017 console.info(`${caseName} success`); 2018 expectFail(); 2019 done(); 2020 }).catch((err: BusinessError) => { 2021 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2022 expectTrue(err.code===401); 2023 done(); 2024 }).finally(async () => { 2025 await tcp.close(); 2026 console.info(`${caseName} test end`); 2027 done(); 2028 }); 2029 } catch (err) { 2030 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2031 expectFail(); 2032 console.info(`${caseName} test end`); 2033 done(); 2034 } 2035 }); 2036 2037 /* * 2038 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2600 2039 * @tc.name : testNetworkMgrSocketTCPSocketConnect2600 2040 * @tc.desc : Connect to the specified IP address and port,bad address; promise 2041 * @tc.size : MediumTest 2042 * @tc.type : Function 2043 * @tc.level : level 2 2044 */ 2045 it('testNetworkMgrSocketTCPSocketConnect2600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2046 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2600'; 2047 try { 2048 console.info(`${caseName} test start`); 2049 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2050 expect(tcp).assertInstanceOf('Object'); 2051 let bindAddress: socket.NetAddress = { 2052 address: '127.0.0.1', 2053 port: 4026, 2054 family:1 2055 }; 2056 await tcp.bind(bindAddress); 2057 let tcpConnectOptions: socket.TCPConnectOptions = { 2058 address: { 2059 address: '100.0.0.0', 2060 port: 4026, 2061 family: 1 2062 } 2063 }; 2064 tcp.connect(tcpConnectOptions).then(() => { 2065 console.info(`${caseName} success`); 2066 expectFail(); 2067 done(); 2068 }).catch((err: BusinessError) => { 2069 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2070 expectTrue(err.code===2301022); 2071 done(); 2072 }).finally(async () => { 2073 await tcp.close(); 2074 console.info(`${caseName} test end`); 2075 done(); 2076 }); 2077 } catch (err) { 2078 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2079 expectFail(); 2080 console.info(`${caseName} test end`); 2081 done(); 2082 } 2083 }); 2084 2085 /* * 2086 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2700 2087 * @tc.name : testNetworkMgrSocketTCPSocketConnect2700 2088 * @tc.desc : Connect to the specified IP address and port,Port is -1; promise 2089 * @tc.size : MediumTest 2090 * @tc.type : Function 2091 * @tc.level : level 2 2092 */ 2093 it('testNetworkMgrSocketTCPSocketConnect2700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2094 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2700'; 2095 try { 2096 console.info(`${caseName} test start`); 2097 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2098 expect(tcp).assertInstanceOf('Object'); 2099 let bindAddress: socket.NetAddress = { 2100 address: '127.0.0.1', 2101 port: -1, 2102 family:1 2103 }; 2104 await tcp.bind(bindAddress); 2105 let tcpConnectOptions: socket.TCPConnectOptions = { 2106 address: { 2107 address: '127.0.0.1', 2108 port: -1, 2109 family: 1 2110 } 2111 }; 2112 tcp.connect(tcpConnectOptions).then(() => { 2113 console.info(`${caseName} success`); 2114 expectFail(); 2115 done(); 2116 }).catch((err: BusinessError) => { 2117 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2118 expectSuccess(); 2119 done(); 2120 }).finally(async () => { 2121 await tcp.close(); 2122 console.info(`${caseName} test end`); 2123 done(); 2124 }); 2125 } catch (err) { 2126 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2127 expectFail(); 2128 console.info(`${caseName} test end`); 2129 done(); 2130 } 2131 }); 2132 2133 /* * 2134 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2800 2135 * @tc.name : testNetworkMgrSocketTCPSocketConnect2800 2136 * @tc.desc : Connect to the specified IP address and port,Port is -0; promise 2137 * @tc.size : MediumTest 2138 * @tc.type : Function 2139 * @tc.level : level 2 2140 */ 2141 it('testNetworkMgrSocketTCPSocketConnect2800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2142 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2800'; 2143 try { 2144 console.info(`${caseName} test start`); 2145 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2146 expect(tcp).assertInstanceOf('Object'); 2147 let bindAddress: socket.NetAddress = { 2148 address: '127.0.0.1', 2149 port: 0, 2150 family:1 2151 }; 2152 await tcp.bind(bindAddress); 2153 let tcpConnectOptions: socket.TCPConnectOptions = { 2154 address: { 2155 address: '127.0.0.1', 2156 port: 0, 2157 family: 1 2158 } 2159 }; 2160 tcp.connect(tcpConnectOptions).then(() => { 2161 console.info(`${caseName} success`); 2162 expectFail(); 2163 done(); 2164 }).catch((err: BusinessError) => { 2165 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2166 expectSuccess(); 2167 done(); 2168 }).finally(async () => { 2169 await tcp.close(); 2170 console.info(`${caseName} test end`); 2171 done(); 2172 }); 2173 } catch (err) { 2174 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2175 expectFail(); 2176 console.info(`${caseName} test end`); 2177 done(); 2178 } 2179 }); 2180 2181 /* * 2182 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_2900 2183 * @tc.name : testNetworkMgrSocketTCPSocketConnect2900 2184 * @tc.desc : Connect to the specified IP address and port,Port is 65535; promise 2185 * @tc.size : MediumTest 2186 * @tc.type : Function 2187 * @tc.level : level 2 2188 */ 2189 it('testNetworkMgrSocketTCPSocketConnect2900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2190 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect2900'; 2191 try { 2192 console.info(`${caseName} test start`); 2193 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2194 expect(tcp).assertInstanceOf('Object'); 2195 let bindAddress: socket.NetAddress = { 2196 address: '127.0.0.1', 2197 port: 65535, 2198 family:1 2199 }; 2200 await tcp.bind(bindAddress); 2201 let tcpConnectOptions: socket.TCPConnectOptions = { 2202 address: { 2203 address: '127.0.0.1', 2204 port: 65535, 2205 family: 1 2206 } 2207 }; 2208 tcp.connect(tcpConnectOptions).then(() => { 2209 console.info(`${caseName} success`); 2210 expectFail(); 2211 done(); 2212 }).catch((err: BusinessError) => { 2213 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2214 expectSuccess(); 2215 done(); 2216 }).finally(async () => { 2217 await tcp.close(); 2218 console.info(`${caseName} test end`); 2219 done(); 2220 }); 2221 } catch (err) { 2222 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2223 expectFail(); 2224 console.info(`${caseName} test end`); 2225 done(); 2226 } 2227 }); 2228 2229 /* * 2230 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_3000 2231 * @tc.name : testNetworkMgrSocketTCPSocketConnect3000 2232 * @tc.desc : Connect to the specified IP address and port,Port is 65536; promise 2233 * @tc.size : MediumTest 2234 * @tc.type : Function 2235 * @tc.level : level 2 2236 */ 2237 it('testNetworkMgrSocketTCPSocketConnect3000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2238 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect3000'; 2239 try { 2240 console.info(`${caseName} test start`); 2241 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2242 expect(tcp).assertInstanceOf('Object'); 2243 let bindAddress: socket.NetAddress = { 2244 address: '127.0.0.1', 2245 port: 65536, 2246 family:1 2247 }; 2248 await tcp.bind(bindAddress); 2249 let tcpConnectOptions: socket.TCPConnectOptions = { 2250 address: { 2251 address: '127.0.0.1', 2252 port: 65536, 2253 family: 1 2254 } 2255 }; 2256 tcp.connect(tcpConnectOptions).then(() => { 2257 console.info(`${caseName} success`); 2258 expectFail(); 2259 done(); 2260 }).catch((err: BusinessError) => { 2261 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2262 expectSuccess(); 2263 done(); 2264 }).finally(async () => { 2265 await tcp.close(); 2266 console.info(`${caseName} test end`); 2267 done(); 2268 }); 2269 } catch (err) { 2270 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2271 expectFail(); 2272 console.info(`${caseName} test end`); 2273 done(); 2274 } 2275 }); 2276 2277 /* * 2278 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_3100 2279 * @tc.name : testNetworkMgrSocketTCPSocketConnect3100 2280 * @tc.desc : Connect to the specified IP address and port,bad family; promise 2281 * @tc.size : MediumTest 2282 * @tc.type : Function 2283 * @tc.level : level 2 2284 */ 2285 it('testNetworkMgrSocketTCPSocketConnect3100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2286 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect3100'; 2287 try { 2288 console.info(`${caseName} test start`); 2289 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2290 expect(tcp).assertInstanceOf('Object'); 2291 let bindAddress: socket.NetAddress = { 2292 address: '127.0.0.1', 2293 port: 4031, 2294 family:1 2295 }; 2296 await tcp.bind(bindAddress); 2297 let tcpConnectOptions: socket.TCPConnectOptions = { 2298 address: { 2299 address: '127.0.0.1', 2300 port: 4031, 2301 family: 3 2302 } 2303 }; 2304 tcp.connect(tcpConnectOptions).then(() => { 2305 console.info(`${caseName} success`); 2306 expectSuccess(); 2307 done(); 2308 }).catch((err: BusinessError) => { 2309 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2310 expectFail(); 2311 done(); 2312 }).finally(async () => { 2313 await tcp.close(); 2314 console.info(`${caseName} test end`); 2315 done(); 2316 }); 2317 } catch (err) { 2318 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2319 expectFail(); 2320 console.info(`${caseName} test end`); 2321 done(); 2322 } 2323 }); 2324 2325 /* * 2326 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Connect_3200 2327 * @tc.name : testNetworkMgrSocketTCPSocketConnect3200 2328 * @tc.desc : Connect to the specified IP address and port,Connect without binding or listening; promise 2329 * @tc.size : MediumTest 2330 * @tc.type : Function 2331 * @tc.level : level 2 2332 */ 2333 it('testNetworkMgrSocketTCPSocketConnect3200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2334 let caseName: string = 'testNetworkMgrSocketTCPSocketConnect3200'; 2335 try { 2336 console.info(`${caseName} test start`); 2337 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2338 expect(tcp).assertInstanceOf('Object'); 2339 let tcpConnectOptions: socket.TCPConnectOptions = { 2340 address: { 2341 address: '127.0.0.1', 2342 port: 4032, 2343 family: 1 2344 } 2345 }; 2346 tcp.connect(tcpConnectOptions).then(() => { 2347 console.info(`${caseName} success`); 2348 expectFail(); 2349 done(); 2350 }).catch((err: BusinessError) => { 2351 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2352 expectTrue(err.code===2301115); 2353 done(); 2354 }).finally(async () => { 2355 await tcp.close(); 2356 console.info(`${caseName} test end`); 2357 done(); 2358 }); 2359 } catch (err) { 2360 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2361 expectFail(); 2362 console.info(`${caseName} test end`); 2363 done(); 2364 } 2365 }); 2366 2367 /* * 2368 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_0100 2369 * @tc.name : testNetworkMgrSocketTCPSocketSend0100 2370 * @tc.desc : Sending data through TCP Socket connection,To the client; callback 2371 * @tc.size : MediumTest 2372 * @tc.type : Function 2373 * @tc.level : level 2 2374 */ 2375 it('testNetworkMgrSocketTCPSocketSend0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2376 let caseName: string = 'testNetworkMgrSocketTCPSocketSend0100'; 2377 try { 2378 console.info(`${caseName} test start`); 2379 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2380 expect(tcp).assertInstanceOf('Object'); 2381 let bindAddress: socket.NetAddress = { 2382 address: '127.0.0.1', 2383 port: 4033 2384 }; 2385 await tcp.bind(bindAddress); 2386 let tcpConnectOptions: socket.TCPConnectOptions = { 2387 address: bindAddress 2388 }; 2389 await tcp.connect(tcpConnectOptions); 2390 let tcpSendOptions: socket.TCPSendOptions = { 2391 data: 'Hello, server!' 2392 }; 2393 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2394 if (err) { 2395 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2396 expectFail(); 2397 } else { 2398 console.info(`${caseName} success`); 2399 expectSuccess(); 2400 } 2401 await tcp.close(); 2402 console.info(`${caseName} test end`); 2403 done(); 2404 }); 2405 } catch (err) { 2406 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2407 expectFail(); 2408 console.info(`${caseName} test end`); 2409 done(); 2410 } 2411 }); 2412 2413 /* * 2414 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_0200 2415 * @tc.name : testNetworkMgrSocketTCPSocketSend0200 2416 * @tc.desc : Sending data through TCP Socket connection,To the server; callback 2417 * @tc.size : MediumTest 2418 * @tc.type : Function 2419 * @tc.level : level 2 2420 */ 2421 it('testNetworkMgrSocketTCPSocketSend0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2422 let caseName: string = 'testNetworkMgrSocketTCPSocketSend0200'; 2423 try { 2424 console.info(`${caseName} test start`); 2425 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2426 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 2427 let listenAddress: socket.NetAddress = { 2428 address: '127.0.0.1', 2429 port: 4034 2430 }; 2431 await tcpServer.listen(listenAddress); 2432 let tcpConnectOptions: socket.TCPConnectOptions = { 2433 address: listenAddress 2434 }; 2435 await tcp.connect(tcpConnectOptions); 2436 let tcpSendOptions: socket.TCPSendOptions = { 2437 data: 'Hello, server!' 2438 }; 2439 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2440 if (err) { 2441 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2442 expectFail(); 2443 } else { 2444 console.info(`${caseName} success`); 2445 expectSuccess(); 2446 } 2447 await tcp.close(); 2448 console.info(`${caseName} test end`); 2449 done(); 2450 }); 2451 } catch (err) { 2452 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2453 expectFail(); 2454 console.info(`${caseName} test end`); 2455 done(); 2456 } 2457 }); 2458 2459 /* * 2460 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_0400 2461 * @tc.name : testNetworkMgrSocketTCPSocketSend0400 2462 * @tc.desc : Sending data through TCP Socket connection,Input parameter is null; callback 2463 * @tc.size : MediumTest 2464 * @tc.type : Function 2465 * @tc.level : level 2 2466 */ 2467 it('testNetworkMgrSocketTCPSocketSend0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2468 let caseName: string = 'testNetworkMgrSocketTCPSocketSend0400'; 2469 try { 2470 console.info(`${caseName} test start`); 2471 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2472 expect(tcp).assertInstanceOf('Object'); 2473 let bindAddress: socket.NetAddress = { 2474 address: '127.0.0.1', 2475 port: 4036 2476 }; 2477 await tcp.bind(bindAddress); 2478 let tcpConnectOptions: socket.TCPConnectOptions = { 2479 address: bindAddress 2480 }; 2481 await tcp.connect(tcpConnectOptions); 2482 tcp.send(null, async (err: BusinessError) => { 2483 if (err) { 2484 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2485 expectTrue(err.code===401); 2486 done(); 2487 } else { 2488 console.info(`${caseName} success`); 2489 expectFail(); 2490 done(); 2491 } 2492 await tcp.close(); 2493 console.info(`${caseName} test end`); 2494 done(); 2495 }); 2496 } catch (err) { 2497 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2498 expectFail(); 2499 console.info(`${caseName} test end`); 2500 done(); 2501 } 2502 }); 2503 2504 /* * 2505 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_0500 2506 * @tc.name : testNetworkMgrSocketTCPSocketSend0500 2507 * @tc.desc : Sending data through TCP Socket connection,Input parameter is undefined; callback 2508 * @tc.size : MediumTest 2509 * @tc.type : Function 2510 * @tc.level : level 2 2511 */ 2512 it('testNetworkMgrSocketTCPSocketSend0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2513 let caseName: string = 'testNetworkMgrSocketTCPSocketSend0500'; 2514 try { 2515 console.info(`${caseName} test start`); 2516 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2517 expect(tcp).assertInstanceOf('Object'); 2518 let bindAddress: socket.NetAddress = { 2519 address: '127.0.0.1', 2520 port: 4037 2521 }; 2522 await tcp.bind(bindAddress); 2523 let tcpConnectOptions: socket.TCPConnectOptions = { 2524 address: bindAddress 2525 }; 2526 await tcp.connect(tcpConnectOptions); 2527 tcp.send(undefined, async (err: BusinessError) => { 2528 if (err) { 2529 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2530 expectTrue(err.code===401); 2531 } else { 2532 console.info(`${caseName} success`); 2533 expectFail() 2534 } 2535 await tcp.close(); 2536 console.info(`${caseName} test end`); 2537 done(); 2538 }); 2539 } catch (err) { 2540 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2541 expectFail(); 2542 console.info(`${caseName} test end`); 2543 done(); 2544 } 2545 }); 2546 2547 /* * 2548 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_0600 2549 * @tc.name : testNetworkMgrSocketTCPSocketSend0600 2550 * @tc.desc : Sending data through TCP Socket connection,Send data of arraybuffer type; callback 2551 * @tc.size : MediumTest 2552 * @tc.type : Function 2553 * @tc.level : level 2 2554 */ 2555 it('testNetworkMgrSocketTCPSocketSend0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2556 let caseName: string = 'testNetworkMgrSocketTCPSocketSend0600'; 2557 try { 2558 console.info(`${caseName} test start`); 2559 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2560 expect(tcp).assertInstanceOf('Object'); 2561 let bindAddress: socket.NetAddress = { 2562 address: '127.0.0.1', 2563 port: 4038 2564 }; 2565 await tcp.bind(bindAddress); 2566 let tcpConnectOptions: socket.TCPConnectOptions = { 2567 address: bindAddress, 2568 }; 2569 await tcp.connect(tcpConnectOptions); 2570 let tcpSendOptions: socket.TCPSendOptions = { 2571 data: new ArrayBuffer(123) 2572 }; 2573 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2574 if (err) { 2575 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2576 expectFail(); 2577 } else { 2578 console.info(`${caseName} success`); 2579 expectSuccess(); 2580 } 2581 await tcp.close(); 2582 console.info(`${caseName} test end`); 2583 done(); 2584 }); 2585 } catch (err) { 2586 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2587 expectFail(); 2588 console.info(`${caseName} test end`); 2589 done(); 2590 } 2591 }); 2592 2593 /* * 2594 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_0700 2595 * @tc.name : testNetworkMgrSocketTCPSocketSend0700 2596 * @tc.desc : Sending data through TCP Socket connection,Set data format to empty string; callback 2597 * @tc.size : MediumTest 2598 * @tc.type : Function 2599 * @tc.level : level 2 2600 */ 2601 it('testNetworkMgrSocketTCPSocketSend0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2602 let caseName: string = 'testNetworkMgrSocketTCPSocketSend0700'; 2603 try { 2604 console.info(`${caseName} test start`); 2605 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2606 expect(tcp).assertInstanceOf('Object'); 2607 let bindAddress: socket.NetAddress = { 2608 address: '127.0.0.1', 2609 port: 4039 2610 }; 2611 await tcp.bind(bindAddress); 2612 let tcpConnectOptions: socket.TCPConnectOptions = { 2613 address: bindAddress, 2614 }; 2615 await tcp.connect(tcpConnectOptions); 2616 let tcpSendOptions: socket.TCPSendOptions = { 2617 data: 'Hello, server!', 2618 encoding: '' 2619 }; 2620 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2621 if (err) { 2622 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2623 expectFail(); 2624 } else { 2625 console.info(`${caseName} success`); 2626 expectSuccess(); 2627 } 2628 await tcp.close(); 2629 console.info(`${caseName} test end`); 2630 done(); 2631 }); 2632 } catch (err) { 2633 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2634 expectFail(); 2635 console.info(`${caseName} test end`); 2636 done(); 2637 } 2638 }); 2639 2640 /* * 2641 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_0800 2642 * @tc.name : testNetworkMgrSocketTCPSocketSend0800 2643 * @tc.desc : Sending data through TCP Socket connection,Set data format to UTF-8; callback 2644 * @tc.size : MediumTest 2645 * @tc.type : Function 2646 * @tc.level : level 2 2647 */ 2648 it('testNetworkMgrSocketTCPSocketSend0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2649 let caseName: string = 'testNetworkMgrSocketTCPSocketSend0800'; 2650 try { 2651 console.info(`${caseName} test start`); 2652 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2653 expect(tcp).assertInstanceOf('Object'); 2654 let bindAddress: socket.NetAddress = { 2655 address: '127.0.0.1', 2656 port: 4040 2657 }; 2658 await tcp.bind(bindAddress); 2659 let tcpConnectOptions: socket.TCPConnectOptions = { 2660 address: bindAddress, 2661 }; 2662 await tcp.connect(tcpConnectOptions); 2663 let tcpSendOptions: socket.TCPSendOptions = { 2664 data: 'Hello, server!', 2665 encoding: 'UTF-8' 2666 }; 2667 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2668 if (err) { 2669 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2670 expectFail(); 2671 } else { 2672 console.info(`${caseName} success`); 2673 expectSuccess(); 2674 } 2675 await tcp.close(); 2676 console.info(`${caseName} test end`); 2677 done(); 2678 }); 2679 } catch (err) { 2680 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2681 expectFail(); 2682 console.info(`${caseName} test end`); 2683 done(); 2684 } 2685 }); 2686 2687 /* * 2688 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_0900 2689 * @tc.name : testNetworkMgrSocketTCPSocketSend0900 2690 * @tc.desc : Sending data through TCP Socket connection,Set data format to UTF-16BE; callback 2691 * @tc.size : MediumTest 2692 * @tc.type : Function 2693 * @tc.level : level 2 2694 */ 2695 it('testNetworkMgrSocketTCPSocketSend0900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2696 let caseName: string = 'testNetworkMgrSocketTCPSocketSend0900'; 2697 try { 2698 console.info(`${caseName} test start`); 2699 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2700 expect(tcp).assertInstanceOf('Object'); 2701 let bindAddress: socket.NetAddress = { 2702 address: '127.0.0.1', 2703 port: 4041 2704 }; 2705 await tcp.bind(bindAddress); 2706 let tcpConnectOptions: socket.TCPConnectOptions = { 2707 address: bindAddress, 2708 }; 2709 await tcp.connect(tcpConnectOptions); 2710 let tcpSendOptions: socket.TCPSendOptions = { 2711 data: 'Hello, server!', 2712 encoding: 'UTF-16BE' 2713 }; 2714 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2715 if (err) { 2716 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2717 expectFail(); 2718 } else { 2719 console.info(`${caseName} success`); 2720 expectSuccess(); 2721 } 2722 await tcp.close(); 2723 console.info(`${caseName} test end`); 2724 done(); 2725 }); 2726 } catch (err) { 2727 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2728 expectFail(); 2729 console.info(`${caseName} test end`); 2730 done(); 2731 } 2732 }); 2733 2734 /* * 2735 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1000 2736 * @tc.name : testNetworkMgrSocketTCPSocketSend1000 2737 * @tc.desc : Sending data through TCP Socket connection,Set data format to UTF-16LE; callback 2738 * @tc.size : MediumTest 2739 * @tc.type : Function 2740 * @tc.level : level 2 2741 */ 2742 it('testNetworkMgrSocketTCPSocketSend1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2743 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1000'; 2744 try { 2745 console.info(`${caseName} test start`); 2746 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2747 expect(tcp).assertInstanceOf('Object'); 2748 let bindAddress: socket.NetAddress = { 2749 address: '127.0.0.1', 2750 port: 4042 2751 }; 2752 await tcp.bind(bindAddress); 2753 let tcpConnectOptions: socket.TCPConnectOptions = { 2754 address: bindAddress, 2755 }; 2756 await tcp.connect(tcpConnectOptions); 2757 let tcpSendOptions: socket.TCPSendOptions = { 2758 data: 'Hello, server!', 2759 encoding: 'UTF-16LE' 2760 }; 2761 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2762 if (err) { 2763 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2764 expectFail(); 2765 } else { 2766 console.info(`${caseName} success`); 2767 expectSuccess(); 2768 } 2769 await tcp.close(); 2770 console.info(`${caseName} test end`); 2771 done(); 2772 }); 2773 } catch (err) { 2774 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2775 expectFail(); 2776 console.info(`${caseName} test end`); 2777 done(); 2778 } 2779 }); 2780 2781 /* * 2782 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1100 2783 * @tc.name : testNetworkMgrSocketTCPSocketSend1100 2784 * @tc.desc : Sending data through TCP Socket connection,Set data format to UTF-16; callback 2785 * @tc.size : MediumTest 2786 * @tc.type : Function 2787 * @tc.level : level 2 2788 */ 2789 it('testNetworkMgrSocketTCPSocketSend1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2790 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1100'; 2791 try { 2792 console.info(`${caseName} test start`); 2793 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2794 expect(tcp).assertInstanceOf('Object'); 2795 let bindAddress: socket.NetAddress = { 2796 address: '127.0.0.1', 2797 port: 4043 2798 }; 2799 await tcp.bind(bindAddress); 2800 let tcpConnectOptions: socket.TCPConnectOptions = { 2801 address: bindAddress, 2802 }; 2803 await tcp.connect(tcpConnectOptions); 2804 let tcpSendOptions: socket.TCPSendOptions = { 2805 data: 'Hello, server!', 2806 encoding: 'UTF-16' 2807 }; 2808 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2809 if (err) { 2810 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2811 expectFail(); 2812 } else { 2813 console.info(`${caseName} success`); 2814 expectSuccess(); 2815 } 2816 await tcp.close(); 2817 console.info(`${caseName} test end`); 2818 done(); 2819 }); 2820 } catch (err) { 2821 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2822 expectFail(); 2823 console.info(`${caseName} test end`); 2824 done(); 2825 } 2826 }); 2827 2828 /* * 2829 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1200 2830 * @tc.name : testNetworkMgrSocketTCPSocketSend1200 2831 * @tc.desc : Sending data through TCP Socket connection,Set data format to US-AECII; callback 2832 * @tc.size : MediumTest 2833 * @tc.type : Function 2834 * @tc.level : level 2 2835 */ 2836 it('testNetworkMgrSocketTCPSocketSend1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2837 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1200'; 2838 try { 2839 console.info(`${caseName} test start`); 2840 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2841 expect(tcp).assertInstanceOf('Object'); 2842 let bindAddress: socket.NetAddress = { 2843 address: '127.0.0.1', 2844 port: 4044 2845 }; 2846 await tcp.bind(bindAddress); 2847 let tcpConnectOptions: socket.TCPConnectOptions = { 2848 address: bindAddress, 2849 }; 2850 await tcp.connect(tcpConnectOptions); 2851 let tcpSendOptions: socket.TCPSendOptions = { 2852 data: 'Hello, server!', 2853 encoding: 'US-AECII' 2854 }; 2855 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2856 if (err) { 2857 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2858 expectFail(); 2859 } else { 2860 console.info(`${caseName} success`); 2861 expectSuccess(); 2862 } 2863 await tcp.close(); 2864 console.info(`${caseName} test end`); 2865 done(); 2866 }); 2867 } catch (err) { 2868 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2869 expectFail(); 2870 console.info(`${caseName} test end`); 2871 done(); 2872 } 2873 }); 2874 2875 /* * 2876 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1300 2877 * @tc.name : testNetworkMgrSocketTCPSocketSend1300 2878 * @tc.desc : Sending data through TCP Socket connection,Set data format to ISO-8859-1; callback 2879 * @tc.size : MediumTest 2880 * @tc.type : Function 2881 * @tc.level : level 2 2882 */ 2883 it('testNetworkMgrSocketTCPSocketSend1300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2884 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1300'; 2885 try { 2886 console.info(`${caseName} test start`); 2887 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2888 expect(tcp).assertInstanceOf('Object'); 2889 let bindAddress: socket.NetAddress = { 2890 address: '127.0.0.1', 2891 port: 4045 2892 }; 2893 await tcp.bind(bindAddress); 2894 let tcpConnectOptions: socket.TCPConnectOptions = { 2895 address: bindAddress, 2896 }; 2897 await tcp.connect(tcpConnectOptions); 2898 let tcpSendOptions: socket.TCPSendOptions = { 2899 data: 'Hello, server!', 2900 encoding: 'ISO-8859-1' 2901 }; 2902 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2903 if (err) { 2904 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2905 expectFail(); 2906 } else { 2907 console.info(`${caseName} success`); 2908 expectSuccess(); 2909 } 2910 await tcp.close(); 2911 console.info(`${caseName} test end`); 2912 done(); 2913 }); 2914 } catch (err) { 2915 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2916 expectFail(); 2917 console.info(`${caseName} test end`); 2918 done(); 2919 } 2920 }); 2921 2922 /* * 2923 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1400 2924 * @tc.name : testNetworkMgrSocketTCPSocketSend1400 2925 * @tc.desc : Sending data through TCP Socket connection,Set data format to GB2312; callback 2926 * @tc.size : MediumTest 2927 * @tc.type : Function 2928 * @tc.level : level 2 2929 */ 2930 it('testNetworkMgrSocketTCPSocketSend1400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2931 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1400'; 2932 try { 2933 console.info(`${caseName} test start`); 2934 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2935 expect(tcp).assertInstanceOf('Object'); 2936 let bindAddress: socket.NetAddress = { 2937 address: '127.0.0.1', 2938 port: 4046 2939 }; 2940 await tcp.bind(bindAddress); 2941 let tcpConnectOptions: socket.TCPConnectOptions = { 2942 address: bindAddress, 2943 }; 2944 await tcp.connect(tcpConnectOptions); 2945 let tcpSendOptions: socket.TCPSendOptions = { 2946 data: 'Hello, server!', 2947 encoding: 'GB2312' 2948 }; 2949 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2950 if (err) { 2951 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2952 expectFail(); 2953 } else { 2954 console.info(`${caseName} success`); 2955 expectSuccess(); 2956 } 2957 await tcp.close(); 2958 console.info(`${caseName} test end`); 2959 done(); 2960 }); 2961 } catch (err) { 2962 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 2963 expectFail(); 2964 console.info(`${caseName} test end`); 2965 done(); 2966 } 2967 }); 2968 2969 /* * 2970 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1500 2971 * @tc.name : testNetworkMgrSocketTCPSocketSend1500 2972 * @tc.desc : Sending data through TCP Socket connection,Set data format to undefined; callback 2973 * @tc.size : MediumTest 2974 * @tc.type : Function 2975 * @tc.level : level 2 2976 */ 2977 it('testNetworkMgrSocketTCPSocketSend1500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 2978 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1500'; 2979 try { 2980 console.info(`${caseName} test start`); 2981 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 2982 expect(tcp).assertInstanceOf('Object'); 2983 let bindAddress: socket.NetAddress = { 2984 address: '127.0.0.1', 2985 port: 4047 2986 }; 2987 await tcp.bind(bindAddress); 2988 let tcpConnectOptions: socket.TCPConnectOptions = { 2989 address: bindAddress 2990 }; 2991 await tcp.connect(tcpConnectOptions); 2992 let tcpSendOptions: socket.TCPSendOptions = { 2993 data: 'Hello, server!', 2994 encoding: undefined 2995 }; 2996 tcp.send(tcpSendOptions, async (err: BusinessError) => { 2997 if (err) { 2998 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 2999 expectFail(); 3000 } else { 3001 console.info(`${caseName} success`); 3002 expectSuccess(); 3003 } 3004 await tcp.close(); 3005 console.info(`${caseName} test end`); 3006 done(); 3007 }); 3008 } catch (err) { 3009 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3010 expectFail(); 3011 console.info(`${caseName} test end`); 3012 done(); 3013 } 3014 }); 3015 3016 /* * 3017 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1600 3018 * @tc.name : testNetworkMgrSocketTCPSocketSend1600 3019 * @tc.desc : Sending data through TCP Socket connection,To the client; promise 3020 * @tc.size : MediumTest 3021 * @tc.type : Function 3022 * @tc.level : level 2 3023 */ 3024 it('testNetworkMgrSocketTCPSocketSend1600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3025 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1600'; 3026 try { 3027 console.info(`${caseName} test start`); 3028 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3029 expect(tcp).assertInstanceOf('Object'); 3030 let bindAddress: socket.NetAddress = { 3031 address: '127.0.0.1', 3032 port: 4049 3033 }; 3034 await tcp.bind(bindAddress); 3035 let tcpConnectOptions: socket.TCPConnectOptions = { 3036 address:bindAddress 3037 }; 3038 await tcp.connect(tcpConnectOptions); 3039 let tcpSendOptions: socket.TCPSendOptions = { 3040 data: 'Hello, server!' 3041 }; 3042 tcp.send(tcpSendOptions).then(() => { 3043 console.info(`${caseName} success`); 3044 expectSuccess(); 3045 done(); 3046 }).catch((err: BusinessError) => { 3047 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3048 expectFail(); 3049 done(); 3050 }).finally(async () => { 3051 await tcp.close(); 3052 console.info(`${caseName} test end`); 3053 done(); 3054 }); 3055 } catch (err) { 3056 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3057 expectFail(); 3058 console.info(`${caseName} test end`); 3059 done(); 3060 } 3061 }); 3062 3063 /* * 3064 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1700 3065 * @tc.name : testNetworkMgrSocketTCPSocketSend1700 3066 * @tc.desc : Sending data through TCP Socket connection,To the server; promise 3067 * @tc.size : MediumTest 3068 * @tc.type : Function 3069 * @tc.level : level 2 3070 */ 3071 it('testNetworkMgrSocketTCPSocketSend1700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3072 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1700'; 3073 try { 3074 console.info(`${caseName} test start`); 3075 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3076 expect(tcp).assertInstanceOf('Object'); 3077 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 3078 let listenAddress: socket.NetAddress = { 3079 address: '127.0.0.1', 3080 port: 4048 3081 }; 3082 await tcpServer.listen(listenAddress); 3083 let tcpConnectOptions: socket.TCPConnectOptions = { 3084 address:listenAddress 3085 }; 3086 await tcp.connect(tcpConnectOptions); 3087 let tcpSendOptions: socket.TCPSendOptions = { 3088 data: 'Hello, server!' 3089 }; 3090 tcp.send(tcpSendOptions).then(() => { 3091 console.info(`${caseName} success`); 3092 expectSuccess(); 3093 done(); 3094 }).catch((err: BusinessError) => { 3095 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3096 expectFail(); 3097 done(); 3098 }).finally(async () => { 3099 await tcp.close(); 3100 console.info(`${caseName} test end`); 3101 done(); 3102 }); 3103 } catch (err) { 3104 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3105 expectFail(); 3106 console.info(`${caseName} test end`); 3107 done(); 3108 } 3109 }); 3110 3111 /* * 3112 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_1900 3113 * @tc.name : testNetworkMgrSocketTCPSocketSend1900 3114 * @tc.desc : Sending data through TCP Socket connection,Input parameter is null; promise 3115 * @tc.size : MediumTest 3116 * @tc.type : Function 3117 * @tc.level : level 2 3118 */ 3119 it('testNetworkMgrSocketTCPSocketSend1900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3120 let caseName: string = 'testNetworkMgrSocketTCPSocketSend1900'; 3121 try { 3122 console.info(`${caseName} test start`); 3123 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3124 expect(tcp).assertInstanceOf('Object'); 3125 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 3126 let listenAddress: socket.NetAddress = { 3127 address: '127.0.0.1', 3128 port: 4050 3129 }; 3130 await tcpServer.listen(listenAddress); 3131 let tcpConnectOptions: socket.TCPConnectOptions = { 3132 address:listenAddress 3133 }; 3134 await tcp.connect(tcpConnectOptions); 3135 tcp.send(null).then(() => { 3136 console.info(`${caseName} success`); 3137 expectFail(); 3138 done(); 3139 }).catch((err: BusinessError) => { 3140 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3141 expectTrue(err.code===401); 3142 done(); 3143 }).finally(async () => { 3144 await tcp.close(); 3145 console.info(`${caseName} test end`); 3146 done(); 3147 }); 3148 } catch (err) { 3149 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3150 expectFail(); 3151 console.info(`${caseName} test end`); 3152 done(); 3153 } 3154 }); 3155 3156 /* * 3157 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2000 3158 * @tc.name : testNetworkMgrSocketTCPSocketSend2000 3159 * @tc.desc : Sending data through TCP Socket connection,Input parameter is undefined; promise 3160 * @tc.size : MediumTest 3161 * @tc.type : Function 3162 * @tc.level : level 2 3163 */ 3164 it('testNetworkMgrSocketTCPSocketSend2000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3165 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2000'; 3166 try { 3167 console.info(`${caseName} test start`); 3168 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3169 expect(tcp).assertInstanceOf('Object'); 3170 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 3171 let listenAddress: socket.NetAddress = { 3172 address: '127.0.0.1', 3173 port: 4051 3174 }; 3175 await tcpServer.listen(listenAddress); 3176 let tcpConnectOptions: socket.TCPConnectOptions = { 3177 address:listenAddress 3178 }; 3179 await tcp.connect(tcpConnectOptions); 3180 tcp.send(undefined).then(() => { 3181 console.info(`${caseName} success`); 3182 expectFail(); 3183 done(); 3184 }).catch((err: BusinessError) => { 3185 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3186 expectTrue(err.code===401); 3187 done(); 3188 }).finally(async () => { 3189 await tcp.close(); 3190 console.info(`${caseName} test end`); 3191 done(); 3192 }); 3193 } catch (err) { 3194 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3195 expectFail(); 3196 console.info(`${caseName} test end`); 3197 done(); 3198 } 3199 }); 3200 3201 /* * 3202 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2100 3203 * @tc.name : testNetworkMgrSocketTCPSocketSend2100 3204 * @tc.desc : Sending data through TCP Socket connection,Send data of arraybuffer type; promise 3205 * @tc.size : MediumTest 3206 * @tc.type : Function 3207 * @tc.level : level 2 3208 */ 3209 it('testNetworkMgrSocketTCPSocketSend2100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3210 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2100'; 3211 try { 3212 console.info(`${caseName} test start`); 3213 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3214 expect(tcp).assertInstanceOf('Object'); 3215 let bindAddress: socket.NetAddress = { 3216 address: '127.0.0.1', 3217 port: 4052 3218 }; 3219 await tcp.bind(bindAddress); 3220 let tcpConnectOptions: socket.TCPConnectOptions = { 3221 address:bindAddress 3222 }; 3223 await tcp.connect(tcpConnectOptions); 3224 let tcpSendOptions: socket.TCPSendOptions = { 3225 data: new ArrayBuffer(123) 3226 }; 3227 tcp.send(tcpSendOptions).then(() => { 3228 console.info(`${caseName} success`); 3229 expectSuccess(); 3230 done(); 3231 }).catch((err: BusinessError) => { 3232 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3233 expectFail(); 3234 done(); 3235 }).finally(async () => { 3236 await tcp.close(); 3237 console.info(`${caseName} test end`); 3238 done(); 3239 }); 3240 } catch (err) { 3241 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3242 expectFail(); 3243 console.info(`${caseName} test end`); 3244 done(); 3245 } 3246 }); 3247 3248 /* * 3249 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2200 3250 * @tc.name : testNetworkMgrSocketTCPSocketSend2200 3251 * @tc.desc : Sending data through TCP Socket connection,Set data format to empty string; promise 3252 * @tc.size : MediumTest 3253 * @tc.type : Function 3254 * @tc.level : level 2 3255 */ 3256 it('testNetworkMgrSocketTCPSocketSend2200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3257 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2200'; 3258 try { 3259 console.info(`${caseName} test start`); 3260 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3261 expect(tcp).assertInstanceOf('Object'); 3262 let bindAddress: socket.NetAddress = { 3263 address: '127.0.0.1', 3264 port: 4053 3265 }; 3266 await tcp.bind(bindAddress); 3267 let tcpConnectOptions: socket.TCPConnectOptions = { 3268 address:bindAddress 3269 }; 3270 await tcp.connect(tcpConnectOptions); 3271 let tcpSendOptions: socket.TCPSendOptions = { 3272 data: 'Hello, server!', 3273 encoding: '' 3274 }; 3275 tcp.send(tcpSendOptions).then(() => { 3276 console.info(`${caseName} success`); 3277 expectSuccess(); 3278 done(); 3279 }).catch((err: BusinessError) => { 3280 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3281 expectFail(); 3282 done(); 3283 }).finally(async () => { 3284 await tcp.close(); 3285 console.info(`${caseName} test end`); 3286 done(); 3287 }); 3288 } catch (err) { 3289 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3290 expectFail(); 3291 console.info(`${caseName} test end`); 3292 done(); 3293 } 3294 }); 3295 3296 /* * 3297 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2300 3298 * @tc.name : testNetworkMgrSocketTCPSocketSend2300 3299 * @tc.desc : Sending data through TCP Socket connection,Set data format to UTF-8; promise 3300 * @tc.size : MediumTest 3301 * @tc.type : Function 3302 * @tc.level : level 2 3303 */ 3304 it('testNetworkMgrSocketTCPSocketSend2300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3305 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2300'; 3306 try { 3307 console.info(`${caseName} test start`); 3308 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3309 expect(tcp).assertInstanceOf('Object'); 3310 let bindAddress: socket.NetAddress = { 3311 address: '127.0.0.1', 3312 port: 4054 3313 }; 3314 await tcp.bind(bindAddress); 3315 let tcpConnectOptions: socket.TCPConnectOptions = { 3316 address: bindAddress 3317 }; 3318 await tcp.connect(tcpConnectOptions); 3319 let tcpSendOptions: socket.TCPSendOptions = { 3320 data: 'Hello, server!', 3321 encoding: 'UTF-8' 3322 }; 3323 tcp.send(tcpSendOptions).then(() => { 3324 console.info(`${caseName} success`); 3325 expectSuccess(); 3326 done(); 3327 }).catch((err: BusinessError) => { 3328 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3329 expectFail(); 3330 done(); 3331 }).finally(async () => { 3332 await tcp.close(); 3333 console.info(`${caseName} test end`); 3334 done(); 3335 }); 3336 } catch (err) { 3337 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3338 expectFail(); 3339 console.info(`${caseName} test end`); 3340 done(); 3341 } 3342 }); 3343 3344 /* * 3345 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2400 3346 * @tc.name : testNetworkMgrSocketTCPSocketSend2400 3347 * @tc.desc : Sending data through TCP Socket connection,Set data format to UTF-16BE; promise 3348 * @tc.size : MediumTest 3349 * @tc.type : Function 3350 * @tc.level : level 2 3351 */ 3352 it('testNetworkMgrSocketTCPSocketSend2400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3353 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2400'; 3354 try { 3355 console.info(`${caseName} test start`); 3356 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3357 expect(tcp).assertInstanceOf('Object'); 3358 let bindAddress: socket.NetAddress = { 3359 address: '127.0.0.1', 3360 port: 4055 3361 }; 3362 await tcp.bind(bindAddress); 3363 let tcpConnectOptions: socket.TCPConnectOptions = { 3364 address:bindAddress 3365 }; 3366 await tcp.connect(tcpConnectOptions); 3367 let tcpSendOptions: socket.TCPSendOptions = { 3368 data: 'Hello, server!', 3369 encoding: 'UTF-16BE' 3370 }; 3371 tcp.send(tcpSendOptions).then(() => { 3372 console.info(`${caseName} success`); 3373 expectSuccess(); 3374 done(); 3375 }).catch((err: BusinessError) => { 3376 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3377 expectFail(); 3378 done(); 3379 }).finally(async () => { 3380 await tcp.close(); 3381 console.info(`${caseName} test end`); 3382 done(); 3383 }); 3384 } catch (err) { 3385 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3386 expectFail(); 3387 console.info(`${caseName} test end`); 3388 done(); 3389 } 3390 }); 3391 3392 /* * 3393 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2500 3394 * @tc.name : testNetworkMgrSocketTCPSocketSend2500 3395 * @tc.desc : Sending data through TCP Socket connection,Set data format to UTF-16LE; promise 3396 * @tc.size : MediumTest 3397 * @tc.type : Function 3398 * @tc.level : level 2 3399 */ 3400 it('testNetworkMgrSocketTCPSocketSend2500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3401 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2500'; 3402 try { 3403 console.info(`${caseName} test start`); 3404 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3405 expect(tcp).assertInstanceOf('Object'); 3406 let bindAddress: socket.NetAddress = { 3407 address: '127.0.0.1', 3408 port: 4056 3409 }; 3410 await tcp.bind(bindAddress); 3411 let tcpConnectOptions: socket.TCPConnectOptions = { 3412 address: bindAddress 3413 }; 3414 await tcp.connect(tcpConnectOptions); 3415 let tcpSendOptions: socket.TCPSendOptions = { 3416 data: 'Hello, server!', 3417 encoding: 'UTF-16LE' 3418 }; 3419 tcp.send(tcpSendOptions).then(() => { 3420 console.info(`${caseName} success`); 3421 expectSuccess(); 3422 done(); 3423 }).catch((err: BusinessError) => { 3424 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3425 expectFail(); 3426 done(); 3427 }).finally(async () => { 3428 await tcp.close(); 3429 console.info(`${caseName} test end`); 3430 done(); 3431 }); 3432 } catch (err) { 3433 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3434 expectFail(); 3435 console.info(`${caseName} test end`); 3436 done(); 3437 } 3438 }); 3439 3440 /* * 3441 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2600 3442 * @tc.name : testNetworkMgrSocketTCPSocketSend2600 3443 * @tc.desc : Sending data through TCP Socket connection,Set data format to UTF-16; promise 3444 * @tc.size : MediumTest 3445 * @tc.type : Function 3446 * @tc.level : level 2 3447 */ 3448 it('testNetworkMgrSocketTCPSocketSend2600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3449 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2600'; 3450 try { 3451 console.info(`${caseName} test start`); 3452 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3453 expect(tcp).assertInstanceOf('Object'); 3454 let bindAddress: socket.NetAddress = { 3455 address: '127.0.0.1', 3456 port: 4057 3457 }; 3458 await tcp.bind(bindAddress); 3459 let tcpConnectOptions: socket.TCPConnectOptions = { 3460 address: bindAddress 3461 }; 3462 await tcp.connect(tcpConnectOptions); 3463 let tcpSendOptions: socket.TCPSendOptions = { 3464 data: 'Hello, server!', 3465 encoding: 'UTF-16' 3466 }; 3467 tcp.send(tcpSendOptions).then(() => { 3468 console.info(`${caseName} success`); 3469 expectSuccess(); 3470 done(); 3471 }).catch((err: BusinessError) => { 3472 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3473 expectFail(); 3474 done(); 3475 }).finally(async () => { 3476 await tcp.close(); 3477 console.info(`${caseName} test end`); 3478 done(); 3479 }); 3480 } catch (err) { 3481 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3482 expectFail(); 3483 console.info(`${caseName} test end`); 3484 done(); 3485 } 3486 }); 3487 3488 /* * 3489 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2700 3490 * @tc.name : testNetworkMgrSocketTCPSocketSend2700 3491 * @tc.desc : Sending data through TCP Socket connection,Set data format to US-AECII; promise 3492 * @tc.size : MediumTest 3493 * @tc.type : Function 3494 * @tc.level : level 2 3495 */ 3496 it('testNetworkMgrSocketTCPSocketSend2700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3497 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2700'; 3498 try { 3499 console.info(`${caseName} test start`); 3500 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3501 expect(tcp).assertInstanceOf('Object'); 3502 let bindAddress: socket.NetAddress = { 3503 address: '127.0.0.1', 3504 port: 4058 3505 }; 3506 await tcp.bind(bindAddress); 3507 let tcpConnectOptions: socket.TCPConnectOptions = { 3508 address:bindAddress 3509 }; 3510 await tcp.connect(tcpConnectOptions); 3511 let tcpSendOptions: socket.TCPSendOptions = { 3512 data: 'Hello, server!', 3513 encoding: 'US-AECII' 3514 }; 3515 tcp.send(tcpSendOptions).then(() => { 3516 console.info(`${caseName} success`); 3517 expectSuccess(); 3518 done(); 3519 }).catch((err: BusinessError) => { 3520 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3521 expectFail(); 3522 done(); 3523 }).finally(async () => { 3524 await tcp.close(); 3525 console.info(`${caseName} test end`); 3526 done(); 3527 }); 3528 } catch (err) { 3529 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3530 expectFail(); 3531 console.info(`${caseName} test end`); 3532 done(); 3533 } 3534 }); 3535 3536 /* * 3537 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2800 3538 * @tc.name : testNetworkMgrSocketTCPSocketSend2800 3539 * @tc.desc : Sending data through TCP Socket connection,Set data format to ISO-8859-1; promise 3540 * @tc.size : MediumTest 3541 * @tc.type : Function 3542 * @tc.level : level 2 3543 */ 3544 it('testNetworkMgrSocketTCPSocketSend2800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3545 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2800'; 3546 try { 3547 console.info(`${caseName} test start`); 3548 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3549 expect(tcp).assertInstanceOf('Object'); 3550 let bindAddress: socket.NetAddress = { 3551 address: '127.0.0.1', 3552 port: 4059 3553 }; 3554 await tcp.bind(bindAddress); 3555 let tcpConnectOptions: socket.TCPConnectOptions = { 3556 address: bindAddress 3557 }; 3558 await tcp.connect(tcpConnectOptions); 3559 let tcpSendOptions: socket.TCPSendOptions = { 3560 data: 'Hello, server!', 3561 encoding: 'ISO-8859-1' 3562 }; 3563 tcp.send(tcpSendOptions).then(() => { 3564 console.info(`${caseName} success`); 3565 expectSuccess(); 3566 done(); 3567 }).catch((err: BusinessError) => { 3568 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3569 expectFail(); 3570 done(); 3571 }).finally(async () => { 3572 await tcp.close(); 3573 console.info(`${caseName} test end`); 3574 done(); 3575 }); 3576 } catch (err) { 3577 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3578 expectFail(); 3579 console.info(`${caseName} test end`); 3580 done(); 3581 } 3582 }); 3583 3584 /* * 3585 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_2900 3586 * @tc.name : testNetworkMgrSocketTCPSocketSend2900 3587 * @tc.desc : Sending data through TCP Socket connection,Set data format to GB2312; promise 3588 * @tc.size : MediumTest 3589 * @tc.type : Function 3590 * @tc.level : level 2 3591 */ 3592 it('testNetworkMgrSocketTCPSocketSend2900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3593 let caseName: string = 'testNetworkMgrSocketTCPSocketSend2900'; 3594 try { 3595 console.info(`${caseName} test start`); 3596 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3597 expect(tcp).assertInstanceOf('Object'); 3598 let bindAddress: socket.NetAddress = { 3599 address: '127.0.0.1', 3600 port: 4060 3601 }; 3602 await tcp.bind(bindAddress); 3603 let tcpConnectOptions: socket.TCPConnectOptions = { 3604 address:bindAddress 3605 }; 3606 await tcp.connect(tcpConnectOptions); 3607 let tcpSendOptions: socket.TCPSendOptions = { 3608 data: 'Hello, server!', 3609 encoding: 'GB2312' 3610 }; 3611 tcp.send(tcpSendOptions).then(() => { 3612 console.info(`${caseName} success`); 3613 expectSuccess(); 3614 done(); 3615 }).catch((err: BusinessError) => { 3616 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3617 expectFail(); 3618 done(); 3619 }).finally(async () => { 3620 await tcp.close(); 3621 console.info(`${caseName} test end`); 3622 done(); 3623 }); 3624 } catch (err) { 3625 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3626 expectFail(); 3627 console.info(`${caseName} test end`); 3628 done(); 3629 } 3630 }); 3631 3632 /* * 3633 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Send_3000 3634 * @tc.name : testNetworkMgrSocketTCPSocketSend3000 3635 * @tc.desc : Sending data through TCP Socket connection,Set data format to undefined; promise 3636 * @tc.size : MediumTest 3637 * @tc.type : Function 3638 * @tc.level : level 2 3639 */ 3640 it('testNetworkMgrSocketTCPSocketSend3000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3641 let caseName: string = 'testNetworkMgrSocketTCPSocketSend3000'; 3642 try { 3643 console.info(`${caseName} test start`); 3644 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3645 expect(tcp).assertInstanceOf('Object'); 3646 let bindAddress: socket.NetAddress = { 3647 address: '127.0.0.1', 3648 port: 4061 3649 }; 3650 await tcp.bind(bindAddress); 3651 let tcpConnectOptions: socket.TCPConnectOptions = { 3652 address:bindAddress 3653 }; 3654 await tcp.connect(tcpConnectOptions); 3655 let tcpSendOptions: socket.TCPSendOptions = { 3656 data: 'Hello, server!', 3657 encoding: undefined 3658 }; 3659 tcp.send(tcpSendOptions).then(() => { 3660 console.info(`${caseName} success`); 3661 expectSuccess(); 3662 done(); 3663 }).catch((err: BusinessError) => { 3664 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3665 expectFail(); 3666 done(); 3667 }).finally(async () => { 3668 await tcp.close(); 3669 console.info(`${caseName} test end`); 3670 done(); 3671 }); 3672 } catch (err) { 3673 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3674 expectFail(); 3675 console.info(`${caseName} test end`); 3676 done(); 3677 } 3678 }); 3679 3680 /* * 3681 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Close_0100 3682 * @tc.name : testNetworkMgrSocketTCPSocketClose0100 3683 * @tc.desc : Close the TCP Socket connection,Call close before binding or listening; callback 3684 * @tc.size : MediumTest 3685 * @tc.type : Function 3686 * @tc.level : level 2 3687 */ 3688 it('testNetworkMgrSocketTCPSocketClose0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3689 let caseName: string = 'testNetworkMgrSocketTCPSocketClose0100'; 3690 try { 3691 console.info(`${caseName} test start`); 3692 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3693 expect(tcp).assertInstanceOf('Object'); 3694 tcp.close((err: BusinessError) => { 3695 if (err) { 3696 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3697 expectTrue(err.code===2300999); 3698 } else { 3699 console.info(`${caseName} success`); 3700 expectFail(); 3701 } 3702 console.info(`${caseName} test end`); 3703 done(); 3704 }); 3705 } catch (err) { 3706 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3707 expectFail(); 3708 console.info(`${caseName} test end`); 3709 done(); 3710 } 3711 }); 3712 3713 /* * 3714 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Close_0200 3715 * @tc.name : testNetworkMgrSocketTCPSocketClose0200 3716 * @tc.desc : Close the TCP Socket connection,After bind and connect; callback 3717 * @tc.size : MediumTest 3718 * @tc.type : Function 3719 * @tc.level : level 2 3720 */ 3721 it('testNetworkMgrSocketTCPSocketClose0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3722 let caseName: string = 'testNetworkMgrSocketTCPSocketClose0200'; 3723 try { 3724 console.info(`${caseName} test start`); 3725 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3726 expect(tcp).assertInstanceOf('Object'); 3727 let bindAddress: socket.NetAddress = { 3728 address: '127.0.0.1', 3729 port: 4062 3730 }; 3731 await tcp.bind(bindAddress); 3732 let tcpConnectOptions: socket.TCPConnectOptions = { 3733 address: bindAddress, 3734 }; 3735 await tcp.connect(tcpConnectOptions); 3736 tcp.close((err: BusinessError) => { 3737 if (err) { 3738 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3739 expectFail(); 3740 } else { 3741 console.info(`${caseName} success`); 3742 expectSuccess(); 3743 } 3744 console.info(`${caseName} test end`); 3745 done(); 3746 }); 3747 } catch (err) { 3748 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3749 expectFail(); 3750 console.info(`${caseName} test end`); 3751 done(); 3752 } 3753 }); 3754 3755 /* * 3756 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Close_0300 3757 * @tc.name : testNetworkMgrSocketTCPSocketClose0300 3758 * @tc.desc : Close the TCP Socket connection ,after listen and connect; callback 3759 * @tc.size : MediumTest 3760 * @tc.type : Function 3761 * @tc.level : level 2 3762 */ 3763 it('testNetworkMgrSocketTCPSocketClose0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3764 let caseName: string = 'testNetworkMgrSocketTCPSocketClose0300'; 3765 try { 3766 console.info(`${caseName} test start`); 3767 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3768 expect(tcp).assertInstanceOf('Object'); 3769 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 3770 expect(tcpServer).assertInstanceOf('Object'); 3771 let listenAddress: socket.NetAddress = { 3772 address: '127.0.0.1', 3773 port: 4063, 3774 family: 1 3775 }; 3776 await tcpServer.listen(listenAddress); 3777 let tcpConnectOptions: socket.TCPConnectOptions = { 3778 address: listenAddress, 3779 }; 3780 await tcp.connect(tcpConnectOptions); 3781 tcp.close((err: BusinessError) => { 3782 if (err) { 3783 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3784 expectFail(); 3785 } else { 3786 console.info(`${caseName} success`); 3787 expectSuccess(); 3788 } 3789 console.info(`${caseName} test end`); 3790 done(); 3791 }); 3792 } catch (err) { 3793 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3794 expectFail(); 3795 console.info(`${caseName} test end`); 3796 done(); 3797 } 3798 }); 3799 3800 /* * 3801 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Close_0400 3802 * @tc.name : testNetworkMgrSocketTCPSocketClose0400 3803 * @tc.desc : Close the TCP Socket connection,Call close before binding or listening; promise 3804 * @tc.size : MediumTest 3805 * @tc.type : Function 3806 * @tc.level : level 2 3807 */ 3808 it('testNetworkMgrSocketTCPSocketClose0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3809 let caseName: string = 'testNetworkMgrSocketTCPSocketClose0400'; 3810 console.info(`${caseName} test start`); 3811 try { 3812 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3813 expect(tcp).assertInstanceOf('Object'); 3814 tcp.close().then(() => { 3815 console.info(`${caseName} success`); 3816 expectFail(); 3817 done(); 3818 }).catch((err: BusinessError) => { 3819 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3820 expectTrue(err.code===2300999); 3821 done(); 3822 }).finally(() => { 3823 console.info(`${caseName} test end`); 3824 done(); 3825 }); 3826 } catch (err) { 3827 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3828 expectFail(); 3829 console.info(`${caseName} test end`); 3830 done(); 3831 } 3832 }); 3833 3834 /* * 3835 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Close_0500 3836 * @tc.name : testNetworkMgrSocketTCPSocketClose0500 3837 * @tc.desc : Close the TCP Socket connection,after bind and connect; promise 3838 * @tc.size : MediumTest 3839 * @tc.type : Function 3840 * @tc.level : level 2 3841 */ 3842 it('testNetworkMgrSocketTCPSocketClose0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3843 let caseName: string = 'testNetworkMgrSocketTCPSocketClose0500'; 3844 console.info(`${caseName} test start`); 3845 try { 3846 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3847 expect(tcp).assertInstanceOf('Object'); 3848 let bindAddress: socket.NetAddress = { 3849 address: '127.0.0.1', 3850 port: 4064 3851 }; 3852 await tcp.bind(bindAddress); 3853 let tcpConnectOptions: socket.TCPConnectOptions = { 3854 address: bindAddress, 3855 }; 3856 await tcp.connect(tcpConnectOptions); 3857 tcp.close().then(() => { 3858 console.info(`${caseName} success`); 3859 expectSuccess(); 3860 done(); 3861 }).catch((err: BusinessError) => { 3862 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3863 expectFail(); 3864 done(); 3865 }).finally(() => { 3866 console.info(`${caseName} test end`); 3867 done(); 3868 }); 3869 } catch (err) { 3870 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3871 expectFail(); 3872 console.info(`${caseName} test end`); 3873 done(); 3874 } 3875 }); 3876 3877 /* * 3878 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_Close_0600 3879 * @tc.name : testNetworkMgrSocketTCPSocketClose0600 3880 * @tc.desc : Close the TCP Socket connection,after listen and connect; promise 3881 * @tc.size : MediumTest 3882 * @tc.type : Function 3883 * @tc.level : level 2 3884 */ 3885 it('testNetworkMgrSocketTCPSocketClose0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3886 let caseName: string = 'testNetworkMgrSocketTCPSocketClose0500'; 3887 console.info(`${caseName} test start`); 3888 try { 3889 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3890 expect(tcp).assertInstanceOf('Object'); 3891 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 3892 expect(tcpServer).assertInstanceOf('Object'); 3893 let listenAddress: socket.NetAddress = { 3894 address: '127.0.0.1', 3895 port: 4065, 3896 family: 1 3897 }; 3898 await tcpServer.listen(listenAddress); 3899 let tcpConnectOptions: socket.TCPConnectOptions = { 3900 address: listenAddress, 3901 }; 3902 await tcp.connect(tcpConnectOptions); 3903 tcp.close().then(() => { 3904 console.info(`${caseName} success`); 3905 expectSuccess(); 3906 done(); 3907 }).catch((err: BusinessError) => { 3908 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3909 expectFail(); 3910 done(); 3911 }).finally(() => { 3912 console.info(`${caseName} test end`); 3913 done(); 3914 }); 3915 } catch (err) { 3916 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3917 expectFail(); 3918 console.info(`${caseName} test end`); 3919 done(); 3920 } 3921 }); 3922 3923 /* * 3924 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetRemoteAddress_0100 3925 * @tc.name : testNetworkMgrSocketTCPSocketGetRemoteAddress0100 3926 * @tc.desc : Get the Opposite Socket Address,before bind or listen; callback 3927 * @tc.size : MediumTest 3928 * @tc.type : Function 3929 * @tc.level : level 2 3930 */ 3931 it('testNetworkMgrSocketTCPSocketGetRemoteAddress0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3932 let caseName: string = 'testNetworkMgrSocketTCPSocketGetRemoteAddress0100'; 3933 try { 3934 console.info(`${caseName} test start`); 3935 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3936 expect(tcp).assertInstanceOf('Object'); 3937 tcp.getRemoteAddress(async (err: BusinessError, data: socket.NetAddress) => { 3938 if (err) { 3939 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 3940 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 3941 expectEqual(err.code, 2301009); 3942 } else { 3943 console.info(`${caseName} success data:${JSON.stringify(data)}`); 3944 expectFail(); 3945 } 3946 console.info(`${caseName} test end`); 3947 done(); 3948 }); 3949 } catch (err) { 3950 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3951 expectFail(); 3952 console.info(`${caseName} test end`); 3953 done(); 3954 } 3955 }); 3956 3957 /* * 3958 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetRemoteAddress_0200 3959 * @tc.name : testNetworkMgrSocketTCPSocketGetRemoteAddress0200 3960 * @tc.desc : Get the Opposite Socket Address,after bind and connect; callback 3961 * @tc.size : MediumTest 3962 * @tc.type : Function 3963 * @tc.level : level 2 3964 */ 3965 it('testNetworkMgrSocketTCPSocketGetRemoteAddress0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 3966 let caseName: string = 'testNetworkMgrSocketTCPSocketGetRemoteAddress0200'; 3967 try { 3968 console.info(`${caseName} test start`); 3969 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 3970 expect(tcp).assertInstanceOf('Object'); 3971 let bindAddress: socket.NetAddress = { 3972 address: '127.0.0.1', 3973 port: 4066, 3974 family: 1 3975 }; 3976 await tcp.bind(bindAddress); 3977 let tcpConnectOptions: socket.TCPConnectOptions = { 3978 address: bindAddress, 3979 }; 3980 await tcp.connect(tcpConnectOptions); 3981 tcp.getRemoteAddress(async (err: BusinessError, data: socket.NetAddress) => { 3982 if (err) { 3983 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 3984 expectFail(); 3985 } else { 3986 console.info(`${caseName} success data:${JSON.stringify(data)}`); 3987 expectEqual(data.address as string, '127.0.0.1'); 3988 expectEqual(data.port as number, 4066); 3989 expectEqual(data.family as number, 1); 3990 } 3991 await tcp.close(); 3992 console.info(`${caseName} test end`); 3993 done(); 3994 }); 3995 } catch (err) { 3996 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 3997 expectFail(); 3998 console.info(`${caseName} test end`); 3999 done(); 4000 } 4001 }); 4002 4003 /* * 4004 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetRemoteAddress_0300 4005 * @tc.name : testNetworkMgrSocketTCPSocketGetRemoteAddress0300 4006 * @tc.desc : Get the Opposite Socket Address, after listen and connect; callback 4007 * @tc.size : MediumTest 4008 * @tc.type : Function 4009 * @tc.level : level 2 4010 */ 4011 it('testNetworkMgrSocketTCPSocketGetRemoteAddress0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4012 let caseName: string = 'testNetworkMgrSocketTCPSocketGetRemoteAddress0300'; 4013 try { 4014 console.info(`${caseName} test start`); 4015 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4016 expect(tcp).assertInstanceOf('Object'); 4017 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 4018 expect(tcpServer).assertInstanceOf('Object'); 4019 let listenAddress: socket.NetAddress = { 4020 address: '127.0.0.1', 4021 port: 4067, 4022 family: 1 4023 }; 4024 await tcpServer.listen(listenAddress); 4025 let tcpConnectOptions: socket.TCPConnectOptions = { 4026 address: listenAddress, 4027 }; 4028 await tcp.connect(tcpConnectOptions); 4029 tcp.getRemoteAddress(async (err: BusinessError, data: socket.NetAddress) => { 4030 if (err) { 4031 console.info(`${caseName} fail ${JSON.stringify(err)}`); 4032 expectFail(); 4033 } else { 4034 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4035 expectEqual(data.address as string, '127.0.0.1'); 4036 expectEqual(data.port as number, 4067); 4037 expectEqual(data.family as number, 1); 4038 } 4039 await tcp.close(); 4040 console.info(`${caseName} test end`); 4041 done(); 4042 }); 4043 } catch (err) { 4044 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`) 4045 expectFail(); 4046 console.info(`${caseName} test end`); 4047 done(); 4048 } 4049 }); 4050 4051 /* * 4052 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetRemoteAddress_0400 4053 * @tc.name : testNetworkMgrSocketTCPSocketGetRemoteAddress0400 4054 * @tc.desc : Get the Opposite Socket Address,before bind or listen; promise 4055 * @tc.size : MediumTest 4056 * @tc.type : Function 4057 * @tc.level : level 2 4058 */ 4059 it('testNetworkMgrSocketTCPSocketGetRemoteAddress0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4060 let caseName: string = 'testNetworkMgrSocketTCPSocketGetRemoteAddress0400'; 4061 console.info(`${caseName} test start`); 4062 try { 4063 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4064 expect(tcp).assertInstanceOf('Object'); 4065 tcp.getRemoteAddress().then((data: socket.NetAddress) => { 4066 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4067 expectFail(); 4068 done(); 4069 }).catch((err: BusinessError) => { 4070 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 4071 expectTrue(err.code===2301009); 4072 done(); 4073 }).finally(async () => { 4074 console.info(`${caseName} test end`); 4075 done(); 4076 }); 4077 } catch (err) { 4078 console.info(`${caseName}_2 fail err:${JSON.stringify(err)}`); 4079 expectFail(); 4080 console.info(`${caseName} test end`); 4081 done(); 4082 } 4083 }); 4084 4085 /* * 4086 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetRemoteAddress_0500 4087 * @tc.name : testNetworkMgrSocketTCPSocketGetRemoteAddress0500 4088 * @tc.desc : Get the Opposite Socket Address, after bind and connect; promise 4089 * @tc.size : MediumTest 4090 * @tc.type : Function 4091 * @tc.level : level 2 4092 */ 4093 it('testNetworkMgrSocketTCPSocketGetRemoteAddress0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4094 let caseName: string = 'testNetworkMgrSocketTCPSocketGetRemoteAddress0500'; 4095 console.info(`${caseName} test start`); 4096 try { 4097 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4098 expect(tcp).assertInstanceOf('Object'); 4099 let bindAddress: socket.NetAddress = { 4100 address: '127.0.0.1', 4101 port: 4068, 4102 family:1 4103 }; 4104 await tcp.bind(bindAddress); 4105 let tcpConnectOptions: socket.TCPConnectOptions = { 4106 address: bindAddress, 4107 }; 4108 await tcp.connect(tcpConnectOptions); 4109 tcp.getRemoteAddress().then((data: socket.NetAddress) => { 4110 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4111 expectEqual(data.address as string, '127.0.0.1'); 4112 expectEqual(data.port as number, 4068); 4113 expectEqual(data.family as number, 1); 4114 done(); 4115 }).catch((err: BusinessError) => { 4116 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 4117 expectFail(); 4118 done(); 4119 }).finally(async () => { 4120 await tcp.close(); 4121 console.info(`${caseName} test end`); 4122 done(); 4123 }); 4124 } catch (err) { 4125 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4126 expectFail(); 4127 console.info(`${caseName} test end`); 4128 done(); 4129 } 4130 }); 4131 4132 /* * 4133 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetRemoteAddress_0600 4134 * @tc.name : testNetworkMgrSocketTCPSocketGetRemoteAddress0600 4135 * @tc.desc : Get the Opposite Socket Address,after listen and connect; promise 4136 * @tc.size : MediumTest 4137 * @tc.type : Function 4138 * @tc.level : level 2 4139 */ 4140 it('testNetworkMgrSocketTCPSocketGetRemoteAddress0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4141 let caseName: string = 'testNetworkMgrSocketTCPSocketGetRemoteAddress0600'; 4142 console.info(`${caseName} test start`); 4143 try { 4144 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4145 expect(tcp).assertInstanceOf('Object'); 4146 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 4147 expect(tcpServer).assertInstanceOf('Object'); 4148 let listenAddress: socket.NetAddress = { 4149 address: '127.0.0.1', 4150 port: 4069, 4151 family:1 4152 }; 4153 await tcpServer.listen(listenAddress); 4154 let tcpConnectOptions: socket.TCPConnectOptions = { 4155 address: listenAddress, 4156 }; 4157 await tcp.connect(tcpConnectOptions); 4158 tcp.getRemoteAddress().then((data: socket.NetAddress) => { 4159 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4160 expectEqual(data.address as string, '127.0.0.1'); 4161 expectEqual(data.port as number, 4069); 4162 expectEqual(data.family as number, 1); 4163 done(); 4164 }).catch((err: BusinessError) => { 4165 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4166 expectFail(); 4167 done(); 4168 }).finally(async () => { 4169 await tcp.close(); 4170 console.info(`${caseName} test end`); 4171 done(); 4172 }); 4173 } catch (err) { 4174 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4175 expectFail(); 4176 console.info(`${caseName} test end`); 4177 done(); 4178 } 4179 }); 4180 4181 /* * 4182 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetState_0100 4183 * @tc.name : testNetworkMgrSocketTCPSocketGetState0100 4184 * @tc.desc : Get TCPSocket status,before bind or listen; callback 4185 * @tc.size : MediumTest 4186 * @tc.type : Function 4187 * @tc.level : level 2 4188 */ 4189 it('testNetworkMgrSocketTCPSocketGetState0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4190 let caseName: string = 'testNetworkMgrSocketTCPSocketGetState0100'; 4191 try { 4192 console.info(`${caseName} test start`); 4193 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4194 expect(tcp).assertInstanceOf('Object'); 4195 tcp.getState((err: BusinessError, data: socket.SocketStateBase) => { 4196 if (err) { 4197 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4198 expectFail(); 4199 } else { 4200 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4201 expectEqual(data.isBound as boolean, false); 4202 expectEqual(data.isClose as boolean, false); 4203 expectEqual(data.isConnected as boolean, false); 4204 } 4205 console.info(`${caseName} test end`); 4206 tcp.close(); 4207 done(); 4208 }); 4209 } catch (err) { 4210 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4211 expectFail(); 4212 console.info(`${caseName} test end`); 4213 done(); 4214 } 4215 }); 4216 4217 /* * 4218 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetState_0200 4219 * @tc.name : testNetworkMgrSocketTCPSocketGetState0200 4220 * @tc.desc : Get TCPSocket status,after bind; callback 4221 * @tc.size : MediumTest 4222 * @tc.type : Function 4223 * @tc.level : level 2 4224 */ 4225 it('testNetworkMgrSocketTCPSocketGetState0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4226 let caseName: string = 'testNetworkMgrSocketTCPSocketGetState0200'; 4227 try { 4228 console.info(`${caseName} test start`); 4229 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4230 expect(tcp).assertInstanceOf('Object'); 4231 let bindAddress: socket.NetAddress = { 4232 address: '127.0.0.1', 4233 port: 4070 4234 }; 4235 await tcp.bind(bindAddress); 4236 tcp.getState(async (err: BusinessError, data: socket.SocketStateBase) => { 4237 if (err) { 4238 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 4239 expectFail(); 4240 } else { 4241 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4242 expectEqual(data.isBound as boolean, true); 4243 expectEqual(data.isClose as boolean, false); 4244 expectEqual(data.isConnected as boolean, false); 4245 } 4246 await tcp.close(); 4247 console.info(`${caseName} test end`); 4248 done(); 4249 }); 4250 } catch (err) { 4251 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4252 expectFail(); 4253 console.info(`${caseName} test end`); 4254 done(); 4255 } 4256 }); 4257 4258 /* * 4259 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetState_0300 4260 * @tc.name : testNetworkMgrSocketTCPSocketGetState0300 4261 * @tc.desc : Get TCPSocket status,after bind and connect; callback 4262 * @tc.size : MediumTest 4263 * @tc.type : Function 4264 * @tc.level : level 2 4265 */ 4266 it('testNetworkMgrSocketTCPSocketGetState0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4267 let caseName: string = 'testNetworkMgrSocketTCPSocketGetState0300'; 4268 try { 4269 console.info(`${caseName} test start`); 4270 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4271 expect(tcp).assertInstanceOf('Object'); 4272 let bindAddress: socket.NetAddress = { 4273 address: '127.0.0.1', 4274 port: 4071 4275 }; 4276 await tcp.bind(bindAddress); 4277 let tcpConnectOptions: socket.TCPConnectOptions = { 4278 address: bindAddress, 4279 }; 4280 await tcp.connect(tcpConnectOptions); 4281 tcp.getState(async (err: BusinessError, data: socket.SocketStateBase) => { 4282 if (err) { 4283 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 4284 expectFail(); 4285 } else { 4286 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4287 expectEqual(data.isBound as boolean, true); 4288 expectEqual(data.isClose as boolean, false); 4289 expectEqual(data.isConnected as boolean, true); 4290 } 4291 await tcp.close(); 4292 console.info(`${caseName} test end`); 4293 done(); 4294 }); 4295 } catch (err) { 4296 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4297 expectFail(); 4298 console.info(`${caseName} test end`); 4299 done(); 4300 } 4301 }); 4302 4303 /* * 4304 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetState_0400 4305 * @tc.name : testNetworkMgrSocketTCPSocketGetState0400 4306 * @tc.desc : Get TCPSocket status,after listen and connect; callback 4307 * @tc.size : MediumTest 4308 * @tc.type : Function 4309 * @tc.level : level 2 4310 */ 4311 it('testNetworkMgrSocketTCPSocketGetState0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4312 let caseName: string = 'testNetworkMgrSocketTCPSocketGetState0400'; 4313 try { 4314 console.info(`${caseName} test start`); 4315 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4316 expect(tcp).assertInstanceOf('Object'); 4317 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 4318 expect(tcpServer).assertInstanceOf('Object'); 4319 let listenAddress: socket.NetAddress = { 4320 address: '127.0.0.1', 4321 port: 4072, 4322 family: 1 4323 }; 4324 await tcpServer.listen(listenAddress); 4325 let tcpConnectOptions: socket.TCPConnectOptions = { 4326 address: listenAddress, 4327 }; 4328 await tcp.connect(tcpConnectOptions); 4329 tcp.getState(async (err: BusinessError, data: socket.SocketStateBase) => { 4330 if (err) { 4331 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 4332 expectFail(); 4333 } else { 4334 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4335 expectEqual(data.isBound as boolean, true); 4336 expectEqual(data.isClose as boolean, false); 4337 expectEqual(data.isConnected as boolean, true); 4338 } 4339 await tcp.close(); 4340 console.info(`${caseName} test end`); 4341 done(); 4342 }); 4343 } catch (err) { 4344 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4345 expectFail(); 4346 console.info(`${caseName} test end`); 4347 done(); 4348 } 4349 }); 4350 4351 /* * 4352 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetState_0500 4353 * @tc.name : testNetworkMgrSocketTCPSocketGetState0500 4354 * @tc.desc : Get TCPSocket status,before bind or listen; callback 4355 * @tc.size : MediumTest 4356 * @tc.type : Function 4357 * @tc.level : level 2 4358 */ 4359 it('testNetworkMgrSocketTCPSocketGetState0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4360 let caseName: string = 'testNetworkMgrSocketTCPSocketGetState0500'; 4361 try { 4362 console.info(`${caseName} test start`); 4363 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4364 expect(tcp).assertInstanceOf('Object'); 4365 tcp.getState().then((data: socket.SocketStateBase) => { 4366 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4367 expectEqual(data.isBound as boolean, false); 4368 expectEqual(data.isClose as boolean, false); 4369 expectEqual(data.isConnected as boolean, false); 4370 tcp.close(); 4371 done(); 4372 }).catch((err: BusinessError) => { 4373 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4374 expectFail(); 4375 done(); 4376 }).finally(() => { 4377 console.info(`${caseName} test end`); 4378 done(); 4379 }); 4380 } catch (err) { 4381 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4382 expectFail(); 4383 console.info(`${caseName} test end`); 4384 done(); 4385 } 4386 }); 4387 4388 /* * 4389 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetState_0600 4390 * @tc.name : testNetworkMgrSocketTCPSocketGetState0600 4391 * @tc.desc : Get TCPSocket status; promise 4392 * @tc.size : MediumTest 4393 * @tc.type : Function 4394 * @tc.level : level 2 4395 */ 4396 it('testNetworkMgrSocketTCPSocketGetState0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4397 let caseName: string = 'testNetworkMgrSocketTCPSocketGetState0600' 4398 console.info(`${caseName} test start`); 4399 try { 4400 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4401 expect(tcp).assertInstanceOf('Object'); 4402 let bindAddress: socket.NetAddress = { 4403 address: '127.0.0.1', 4404 port: 4073 4405 }; 4406 await tcp.bind(bindAddress); 4407 await tcp.getState().then((data: socket.SocketStateBase) => { 4408 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4409 expectEqual(data.isBound as boolean, true); 4410 expectEqual(data.isClose as boolean, false); 4411 expectEqual(data.isConnected as boolean, false); 4412 done(); 4413 }).catch((err: BusinessError) => { 4414 console.info(`${caseName} Fail err:${JSON.stringify(err)}`); 4415 expectFail(); 4416 done(); 4417 }).finally(async () => { 4418 await tcp.close(); 4419 console.info(`${caseName} test end`); 4420 done(); 4421 }); 4422 } catch (err) { 4423 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4424 expectFail(); 4425 console.info(`${caseName} test end`); 4426 done(); 4427 } 4428 }); 4429 4430 /* * 4431 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetState_0700 4432 * @tc.name : testNetworkMgrSocketTCPSocketGetState0700 4433 * @tc.desc : Get TCPSocket status; promise 4434 * @tc.size : MediumTest 4435 * @tc.type : Function 4436 * @tc.level : level 2 4437 */ 4438 it('testNetworkMgrSocketTCPSocketGetState0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4439 let caseName: string = 'testNetworkMgrSocketTCPSocketGetState0700'; 4440 try { 4441 console.info(`${caseName} test start`); 4442 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4443 expect(tcp).assertInstanceOf('Object'); 4444 let bindAddress: socket.NetAddress = { 4445 address: '127.0.0.1', 4446 port: 4074 4447 }; 4448 await tcp.bind(bindAddress); 4449 let tcpConnectOptions: socket.TCPConnectOptions = { 4450 address: bindAddress, 4451 }; 4452 await tcp.connect(tcpConnectOptions); 4453 tcp.getState().then((data: socket.SocketStateBase) => { 4454 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4455 expectEqual(data.isBound as boolean, true); 4456 expectEqual(data.isClose as boolean, false); 4457 expectEqual(data.isConnected as boolean, true); 4458 done(); 4459 }).catch((err: BusinessError) => { 4460 console.info(`${caseName} Fail err:${JSON.stringify(err)}`); 4461 expectFail(); 4462 done(); 4463 }).finally(async () => { 4464 tcp.close(); 4465 console.info(`${caseName} test end`); 4466 done(); 4467 }); 4468 } catch (err) { 4469 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4470 expectFail(); 4471 console.info(`${caseName} test end`); 4472 done(); 4473 } 4474 }); 4475 4476 /* * 4477 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetState_0800 4478 * @tc.name : testNetworkMgrSocketTCPSocketGetState0800 4479 * @tc.desc : Get TCPSocket status; promise 4480 * @tc.size : MediumTest 4481 * @tc.type : Function 4482 * @tc.level : level 2 4483 */ 4484 it('testNetworkMgrSocketTCPSocketGetState0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4485 let caseName: string = 'testNetworkMgrSocketTCPSocketGetState0800'; 4486 try { 4487 console.info(`${caseName} test start`); 4488 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4489 expect(tcp).assertInstanceOf('Object'); 4490 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 4491 expect(tcpServer).assertInstanceOf('Object'); 4492 let listenAddress: socket.NetAddress = { 4493 address: '127.0.0.1', 4494 port: 4075, 4495 family: 1 4496 }; 4497 await tcpServer.listen(listenAddress); 4498 let tcpConnectOptions: socket.TCPConnectOptions = { 4499 address: listenAddress, 4500 }; 4501 await tcp.connect(tcpConnectOptions); 4502 tcp.getState().then((data: socket.SocketStateBase) => { 4503 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4504 expectEqual(data.isBound as boolean, true); 4505 expectEqual(data.isClose as boolean, false); 4506 expectEqual(data.isConnected as boolean, true); 4507 done(); 4508 }).catch((err: BusinessError) => { 4509 console.info(`${caseName} Fail err:${JSON.stringify(err)}`); 4510 expectFail(); 4511 done(); 4512 }).finally(async () => { 4513 tcp.close(); 4514 console.info(`${caseName} test end`); 4515 done(); 4516 }); 4517 } catch (err) { 4518 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4519 expectFail(); 4520 console.info(`${caseName} test end`); 4521 done(); 4522 } 4523 }); 4524 4525 /* * 4526 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetSocketFd_0100 4527 * @tc.name : testNetworkMgrSocketTCPSocketGetSocketFd0100 4528 * @tc.desc : Get TCPSocket status,before bind or listen; callback 4529 * @tc.size : MediumTest 4530 * @tc.type : Function 4531 * @tc.level : level 2 4532 */ 4533 it('testNetworkMgrSocketTCPSocketGetSocketFd0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4534 let caseName: string = 'testNetworkMgrSocketTCPSocketGetSocketFd0100'; 4535 try { 4536 console.info(`${caseName} test start`); 4537 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4538 expect(tcp).assertInstanceOf('Object'); 4539 tcp.getSocketFd((err: BusinessError, data: number) => { 4540 if (err) { 4541 console.info(`${caseName} fail ${JSON.stringify(err)}`); 4542 expectFail(); 4543 } else { 4544 console.info(`${caseName} success: ${JSON.stringify(data)}`); 4545 expectTrue(data === undefined); 4546 } 4547 console.info(`${caseName} test end`); 4548 done(); 4549 }); 4550 } catch (err) { 4551 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4552 expectFail(); 4553 console.info(`${caseName} test end`); 4554 done(); 4555 } 4556 }); 4557 4558 /* * 4559 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetSocketFd_0200 4560 * @tc.name : testNetworkMgrSocketTCPSocketGetSocketFd0200 4561 * @tc.desc : Get TCPSocket status,after bind; callback 4562 * @tc.size : MediumTest 4563 * @tc.type : Function 4564 * @tc.level : level 2 4565 */ 4566 it('testNetworkMgrSocketTCPSocketGetSocketFd0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4567 let caseName: string = 'testNetworkMgrSocketTCPSocketGetSocketFd0200'; 4568 try { 4569 console.info(`${caseName} test start`); 4570 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4571 expect(tcp).assertInstanceOf('Object'); 4572 let bindAddress: socket.NetAddress = { 4573 address: '127.0.0.1', 4574 port: 4076 4575 }; 4576 await tcp.bind(bindAddress); 4577 tcp.getSocketFd(async (err: BusinessError, data: number) => { 4578 if (err) { 4579 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4580 expectFail(); 4581 } else { 4582 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4583 expectTrue(data !== undefined); 4584 } 4585 await tcp.close(); 4586 console.info(`${caseName} test end`); 4587 done(); 4588 }); 4589 } catch (err) { 4590 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4591 expectFail(); 4592 console.info(`${caseName} test end`); 4593 done(); 4594 } 4595 }); 4596 4597 /* * 4598 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetSocketFd_0300 4599 * @tc.name : testNetworkMgrSocketTCPSocketGetSocketFd0300 4600 * @tc.desc : Get TCPSocket status,after bind and connect; callback 4601 * @tc.size : MediumTest 4602 * @tc.type : Function 4603 * @tc.level : level 2 4604 */ 4605 it('testNetworkMgrSocketTCPSocketGetSocketFd0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4606 let caseName: string = 'testNetworkMgrSocketTCPSocketGetSocketFd0300'; 4607 try { 4608 console.info(`${caseName} test start`); 4609 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4610 expect(tcp).assertInstanceOf('Object'); 4611 let bindAddress: socket.NetAddress = { 4612 address: '127.0.0.1', 4613 port: 4077 4614 }; 4615 await tcp.bind(bindAddress); 4616 let tcpConnectOptions: socket.TCPConnectOptions = { 4617 address: bindAddress, 4618 }; 4619 await tcp.connect(tcpConnectOptions); 4620 tcp.getSocketFd(async (err: BusinessError, data: number) => { 4621 if (err) { 4622 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 4623 expectFail(); 4624 } else { 4625 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4626 expectTrue(data !== undefined); 4627 } 4628 await tcp.close(); 4629 console.info(`${caseName} test end`); 4630 done(); 4631 }); 4632 } catch (err) { 4633 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4634 expectFail(); 4635 console.info(`${caseName} test end`); 4636 done(); 4637 } 4638 }); 4639 4640 /* * 4641 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetSocketFd_0400 4642 * @tc.name : testNetworkMgrSocketTCPSocketGetSocketFd0400 4643 * @tc.desc : Get TCPSocket status,after listen and connect; callback 4644 * @tc.size : MediumTest 4645 * @tc.type : Function 4646 * @tc.level : level 2 4647 */ 4648 it('testNetworkMgrSocketTCPSocketGetSocketFd0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4649 let caseName: string = 'testNetworkMgrSocketTCPSocketGetSocketFd0400'; 4650 try { 4651 console.info(`${caseName} test start`); 4652 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4653 expect(tcp).assertInstanceOf('Object'); 4654 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 4655 expect(tcpServer).assertInstanceOf('Object'); 4656 let listenAddress: socket.NetAddress = { 4657 address: '127.0.0.1', 4658 port: 4078, 4659 family: 1 4660 }; 4661 await tcpServer.listen(listenAddress); 4662 let tcpConnectOptions: socket.TCPConnectOptions = { 4663 address: listenAddress, 4664 }; 4665 await tcp.connect(tcpConnectOptions); 4666 tcp.getSocketFd(async (err: BusinessError, data: number) => { 4667 if (err) { 4668 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4669 expectFail(); 4670 } else { 4671 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4672 expectTrue(data !== undefined); 4673 } 4674 await tcp.close(); 4675 console.info(`${caseName} test end`); 4676 done(); 4677 }); 4678 } catch (err) { 4679 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4680 expectFail(); 4681 console.info(`${caseName} test end`); 4682 done(); 4683 } 4684 }); 4685 4686 /* * 4687 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetSocketFd_0500 4688 * @tc.name : testNetworkMgrSocketTCPSocketGetSocketFd0500 4689 * @tc.desc : Get TCPSocket status, before bind or listen; promise 4690 * @tc.size : MediumTest 4691 * @tc.type : Function 4692 * @tc.level : level 2 4693 */ 4694 it('testNetworkMgrSocketTCPSocketGetSocketFd0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4695 let caseName: string = 'testNetworkMgrSocketTCPSocketGetSocketFd0500'; 4696 try { 4697 console.info(`${caseName} test start`); 4698 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4699 expect(tcp).assertInstanceOf('Object'); 4700 tcp.getSocketFd().then((data: number) => { 4701 console.info(`${caseName} fail data:${JSON.stringify(data)}`); 4702 expectTrue(data === undefined); 4703 done(); 4704 }).catch((err: BusinessError) => { 4705 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4706 expectFail(); 4707 done(); 4708 }).finally(() => { 4709 console.info(`${caseName} test end`); 4710 done(); 4711 }); 4712 } catch (err) { 4713 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4714 expectFail(); 4715 console.info(`${caseName} test end`); 4716 done(); 4717 } 4718 }); 4719 4720 /* * 4721 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetSocketFd_0600 4722 * @tc.name : testNetworkMgrSocketTCPSocketGetSocketFd0600 4723 * @tc.desc : Get TCPSocket status,after bind; promise 4724 * @tc.size : MediumTest 4725 * @tc.type : Function 4726 * @tc.level : level 2 4727 */ 4728 it('testNetworkMgrSocketTCPSocketGetSocketFd0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4729 let caseName: string = 'testNetworkMgrSocketTCPSocketGetSocketFd0600'; 4730 try { 4731 console.info(`${caseName} test start`); 4732 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4733 expect(tcp).assertInstanceOf('Object'); 4734 let bindAddress: socket.NetAddress = { 4735 address: '127.0.0.1', 4736 port: 4079 4737 }; 4738 await tcp.bind(bindAddress); 4739 tcp.getSocketFd().then((data: number) => { 4740 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4741 expectTrue(data !== undefined); 4742 done(); 4743 }).catch((err: BusinessError) => { 4744 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4745 expectFail(); 4746 done(); 4747 }).finally(async () => { 4748 await tcp.close(); 4749 console.info(`${caseName} test end`); 4750 done(); 4751 }) 4752 } catch (err) { 4753 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4754 expectFail(); 4755 console.info(`${caseName} test end`); 4756 done(); 4757 } 4758 }); 4759 4760 /* * 4761 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetSocketFd_0700 4762 * @tc.name : testNetworkMgrSocketTCPSocketGetSocketFd0700 4763 * @tc.desc : Get TCPSocket status,after bind and connect; promise 4764 * @tc.size : MediumTest 4765 * @tc.type : Function 4766 * @tc.level : level 2 4767 */ 4768 it('testNetworkMgrSocketTCPSocketGetSocketFd0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4769 let caseName: string = 'testNetworkMgrSocketTCPSocketGetSocketFd0700'; 4770 try { 4771 console.info(`${caseName} test start`); 4772 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4773 expect(tcp).assertInstanceOf('Object') 4774 let bindAddress: socket.NetAddress = { 4775 address: '127.0.0.1', 4776 port: 4080 4777 }; 4778 await tcp.bind(bindAddress); 4779 let tcpConnectOptions: socket.TCPConnectOptions = { 4780 address: bindAddress, 4781 }; 4782 await tcp.connect(tcpConnectOptions); 4783 tcp.getSocketFd().then((data: number) => { 4784 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4785 expectTrue(data !== undefined); 4786 done(); 4787 }).catch((err: BusinessError) => { 4788 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 4789 expectFail(); 4790 done(); 4791 }).finally(async () => { 4792 await tcp.close(); 4793 console.info(`${caseName} test end`); 4794 done(); 4795 }); 4796 } catch (err) { 4797 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4798 expectFail(); 4799 console.info(`${caseName} test end`); 4800 done(); 4801 } 4802 }); 4803 4804 /* * 4805 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_GetSocketFd_0800 4806 * @tc.name : testNetworkMgrSocketTCPSocketGetSocketFd0800 4807 * @tc.desc : Get TCPSocket status,after listen and connect; promise 4808 * @tc.size : MediumTest 4809 * @tc.type : Function 4810 * @tc.level : level 2 4811 */ 4812 it('testNetworkMgrSocketTCPSocketGetSocketFd0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4813 let caseName: string = 'testNetworkMgrSocketTCPSocketGetSocketFd0800'; 4814 try { 4815 console.info(`${caseName} test start`); 4816 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4817 expect(tcp).assertInstanceOf('Object') 4818 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 4819 expect(tcpServer).assertInstanceOf('Object') 4820 let listenAddress: socket.NetAddress = { 4821 address: '127.0.0.1', 4822 port: 4081, 4823 family: 1 4824 }; 4825 await tcpServer.listen(listenAddress); 4826 let tcpConnectOptions: socket.TCPConnectOptions = { 4827 address: listenAddress, 4828 }; 4829 await tcp.connect(tcpConnectOptions); 4830 tcp.getSocketFd().then((data: number) => { 4831 console.info(`${caseName} success data:${JSON.stringify(data)}`); 4832 expectTrue(data !== undefined); 4833 done(); 4834 }).catch((err: BusinessError) => { 4835 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4836 expectFail(); 4837 done(); 4838 }).finally(async () => { 4839 await tcp.close(); 4840 console.info(`${caseName} test end`); 4841 done(); 4842 }); 4843 } catch (err) { 4844 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4845 expectFail(); 4846 console.info(`${caseName} test end`); 4847 done(); 4848 } 4849 }); 4850 4851 /* * 4852 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0100 4853 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0100 4854 * @tc.desc : Get TCPSocket status,after bind; callback 4855 * @tc.size : MediumTest 4856 * @tc.type : Function 4857 * @tc.level : level 2 4858 */ 4859 it('testNetworkMgrSocketTCPSocketSetExtraOptions0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4860 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0100'; 4861 try { 4862 console.info(`${caseName} test start`); 4863 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4864 expect(tcp).assertInstanceOf('Object'); 4865 let bindAddress: socket.NetAddress = { 4866 address: '127.0.0.1', 4867 port: 4082 4868 }; 4869 await tcp.bind(bindAddress); 4870 let tcpExtraOptions: socket.TCPExtraOptions = { 4871 keepAlive: true, 4872 OOBInline: true, 4873 TCPNoDelay: true, 4874 socketLinger: { 4875 on: true, linger: 10 4876 }, 4877 receiveBufferSize: 1000, 4878 sendBufferSize: 1000, 4879 reuseAddress: true, 4880 socketTimeout: 3000 4881 }; 4882 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 4883 if (err) { 4884 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4885 expectFail(); 4886 } else { 4887 console.info(`${caseName} success`); 4888 expectSuccess(); 4889 } 4890 await tcp.close(); 4891 console.info(`${caseName} test end`); 4892 done(); 4893 }); 4894 } catch (err) { 4895 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4896 expectFail(); 4897 console.info(`${caseName} test end`); 4898 done(); 4899 } 4900 }); 4901 4902 /* * 4903 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0200 4904 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0200 4905 * @tc.desc : Get TCPSocket status,after bind and connect; callback 4906 * @tc.size : MediumTest 4907 * @tc.type : Function 4908 * @tc.level : level 2 4909 */ 4910 it('testNetworkMgrSocketTCPSocketSetExtraOptions0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4911 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0200'; 4912 try { 4913 console.info(`${caseName} test start`); 4914 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4915 expect(tcp).assertInstanceOf('Object'); 4916 let bindAddress: socket.NetAddress = { 4917 address: '127.0.0.1', 4918 port: 4083 4919 }; 4920 await tcp.bind(bindAddress); 4921 let tcpConnectOptions: socket.TCPConnectOptions = { 4922 address: bindAddress, 4923 }; 4924 await tcp.connect(tcpConnectOptions); 4925 let tcpExtraOptions: socket.TCPExtraOptions = { 4926 keepAlive: true, 4927 OOBInline: true, 4928 TCPNoDelay: true, 4929 socketLinger: { 4930 on: true, linger: 10 4931 }, 4932 receiveBufferSize: 1000, 4933 sendBufferSize: 1000, 4934 reuseAddress: true, 4935 socketTimeout: 3000 4936 }; 4937 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 4938 if (err) { 4939 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 4940 expectFail(); 4941 } else { 4942 console.info(`${caseName} success`); 4943 expectSuccess(); 4944 } 4945 await tcp.close(); 4946 console.info(`${caseName} test end`); 4947 done(); 4948 }); 4949 } catch (err) { 4950 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 4951 expectFail(); 4952 console.info(`${caseName} test end`); 4953 done(); 4954 } 4955 }); 4956 4957 /* * 4958 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0300 4959 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0300 4960 * @tc.desc : Get TCPSocket status,after listen and connect; callback 4961 * @tc.size : MediumTest 4962 * @tc.type : Function 4963 * @tc.level : level 2 4964 */ 4965 it('testNetworkMgrSocketTCPSocketSetExtraOptions0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 4966 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0300'; 4967 try { 4968 console.info(`${caseName} test start`); 4969 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 4970 expect(tcp).assertInstanceOf('Object'); 4971 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 4972 expect(tcpServer).assertInstanceOf('Object'); 4973 let listenAddress: socket.NetAddress = { 4974 address: '127.0.0.1', 4975 port: 4084, 4976 family: 1 4977 }; 4978 await tcpServer.listen(listenAddress); 4979 let tcpConnectOptions: socket.TCPConnectOptions = { 4980 address: listenAddress, 4981 }; 4982 await tcp.connect(tcpConnectOptions); 4983 let tcpExtraOptions: socket.TCPExtraOptions = { 4984 keepAlive: true, 4985 OOBInline: true, 4986 TCPNoDelay: true, 4987 socketLinger: { 4988 on: true, linger: 10 4989 }, 4990 receiveBufferSize: 1000, 4991 sendBufferSize: 1000, 4992 reuseAddress: true, 4993 socketTimeout: 3000 4994 }; 4995 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 4996 if (err) { 4997 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 4998 expectFail(); 4999 } else { 5000 console.info(`${caseName} success`); 5001 expectSuccess(); 5002 } 5003 await tcp.close(); 5004 console.info(`${caseName} test end`); 5005 done(); 5006 }); 5007 } catch (err) { 5008 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5009 expectFail(); 5010 console.info(`${caseName} test end`); 5011 done(); 5012 } 5013 }); 5014 5015 /* * 5016 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0400 5017 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0400 5018 * @tc.desc : Get TCPSocket status,Input parameter is null; callback 5019 * @tc.size : MediumTest 5020 * @tc.type : Function 5021 * @tc.level : level 2 5022 */ 5023 it('testNetworkMgrSocketTCPSocketSetExtraOptions0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5024 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0400'; 5025 try { 5026 console.info(`${caseName} test start`); 5027 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5028 expect(tcp).assertInstanceOf('Object'); 5029 let bindAddress: socket.NetAddress = { 5030 address: '127.0.0.1', 5031 port: 4085 5032 }; 5033 await tcp.bind(bindAddress); 5034 tcp.setExtraOptions(null, async (err: BusinessError) => { 5035 if (err) { 5036 console.info(`${caseName} fail 111 err:${JSON.stringify(err)}`); 5037 expectEqual(err.code, 401); 5038 } else { 5039 console.info(`${caseName} success`); 5040 expectFail(); 5041 } 5042 await tcp.close(); 5043 console.info(`${caseName} test end`); 5044 done(); 5045 }); 5046 } catch (err) { 5047 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5048 expectFail(); 5049 console.info(`${caseName} test end`); 5050 done(); 5051 } 5052 }); 5053 5054 /* * 5055 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0500 5056 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0500 5057 * @tc.desc : Get TCPSocket status,Input parameter is undefined; callback 5058 * @tc.size : MediumTest 5059 * @tc.type : Function 5060 * @tc.level : level 2 5061 */ 5062 it('testNetworkMgrSocketTCPSocketSetExtraOptions0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5063 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0500'; 5064 try { 5065 console.info(`${caseName} test start`); 5066 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5067 expect(tcp).assertInstanceOf('Object'); 5068 let bindAddress: socket.NetAddress = { 5069 address: '127.0.0.1', 5070 port: 4086 5071 }; 5072 await tcp.bind(bindAddress); 5073 tcp.setExtraOptions(undefined, async (err: BusinessError) => { 5074 if (err) { 5075 console.info(`${caseName} fail 111 err:${JSON.stringify(err)}`); 5076 expectEqual(err.code, 401); 5077 } else { 5078 console.info(`${caseName} success`); 5079 expectFail(); 5080 } 5081 await tcp.close(); 5082 console.info(`${caseName} test end`); 5083 done(); 5084 }); 5085 } catch (err) { 5086 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5087 expectFail(); 5088 console.info(`${caseName} test end`); 5089 done(); 5090 } 5091 }); 5092 5093 /* * 5094 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0600 5095 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0600 5096 * @tc.desc : Get TCPSocket status,Input parameter keepAlive is false; callback 5097 * @tc.size : MediumTest 5098 * @tc.type : Function 5099 * @tc.level : level 2 5100 */ 5101 it('testNetworkMgrSocketTCPSocketSetExtraOptions0600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5102 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0600'; 5103 try { 5104 console.info(`${caseName} test start`); 5105 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5106 expect(tcp).assertInstanceOf('Object'); 5107 let bindAddress: socket.NetAddress = { 5108 address: '127.0.0.1', 5109 port: 9001 5110 }; 5111 await tcp.bind(bindAddress); 5112 let tcpExtraOptions: socket.TCPExtraOptions = { 5113 keepAlive: false, 5114 socketLinger: { 5115 on: true, linger: 10 5116 } 5117 }; 5118 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5119 if (err) { 5120 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5121 expectFail(); 5122 } else { 5123 console.info(`${caseName} success`); 5124 expectSuccess(); 5125 } 5126 await tcp.close(); 5127 console.info(`${caseName} test end`); 5128 done(); 5129 }); 5130 } catch (err) { 5131 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5132 expectFail(); 5133 console.info(`${caseName} test end`); 5134 done(); 5135 } 5136 }); 5137 5138 /* * 5139 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0700 5140 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0700 5141 * @tc.desc : Get TCPSocket status,Input parameter keepAlive is true; callback 5142 * @tc.size : MediumTest 5143 * @tc.type : Function 5144 * @tc.level : level 2 5145 */ 5146 it('testNetworkMgrSocketTCPSocketSetExtraOptions0700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5147 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0700'; 5148 try { 5149 console.info(`${caseName} test start`); 5150 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5151 expect(tcp).assertInstanceOf('Object'); 5152 let bindAddress: socket.NetAddress = { 5153 address: '127.0.0.1', 5154 port: 9002 5155 }; 5156 await tcp.bind(bindAddress); 5157 let tcpExtraOptions: socket.TCPExtraOptions = { 5158 keepAlive: true, 5159 socketLinger: { 5160 on: true, linger: 10 5161 } 5162 }; 5163 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5164 if (err) { 5165 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5166 expectFail(); 5167 } else { 5168 console.info(`${caseName} success`); 5169 expectSuccess(); 5170 } 5171 await tcp.close(); 5172 console.info(`${caseName} test end`); 5173 done(); 5174 }); 5175 } catch (err) { 5176 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5177 expectFail(); 5178 console.info(`${caseName} test end`); 5179 done(); 5180 } 5181 }); 5182 5183 /* * 5184 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0800 5185 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0800 5186 * @tc.desc : Get TCPSocket status,Input parameter OOBlnLine is false ; callback 5187 * @tc.size : MediumTest 5188 * @tc.type : Function 5189 * @tc.level : level 2 5190 */ 5191 it('testNetworkMgrSocketTCPSocketSetExtraOptions0800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5192 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0800'; 5193 try { 5194 console.info(`${caseName} test start`); 5195 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5196 expect(tcp).assertInstanceOf('Object'); 5197 let bindAddress: socket.NetAddress = { 5198 address: '127.0.0.1', 5199 port: 9003 5200 }; 5201 await tcp.bind(bindAddress); 5202 let tcpExtraOptions: socket.TCPExtraOptions = { 5203 OOBInline: false, 5204 socketLinger: { 5205 on: true, linger: 10 5206 } 5207 }; 5208 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5209 if (err) { 5210 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5211 expectFail(); 5212 } else { 5213 console.info(`${caseName} success`); 5214 expectSuccess(); 5215 } 5216 await tcp.close(); 5217 console.info(`${caseName} test end`); 5218 done(); 5219 }); 5220 } catch (err) { 5221 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5222 expectFail(); 5223 console.info(`${caseName} test end`); 5224 done(); 5225 } 5226 }); 5227 5228 /* * 5229 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_0900 5230 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions0900 5231 * @tc.desc : Get TCPSocket status, Input parameter OOBlnLine is true; callback 5232 * @tc.size : MediumTest 5233 * @tc.type : Function 5234 * @tc.level : level 2 5235 */ 5236 it('testNetworkMgrSocketTCPSocketSetExtraOptions0900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5237 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions0900'; 5238 try { 5239 console.info(`${caseName} test start`); 5240 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5241 expect(tcp).assertInstanceOf('Object'); 5242 let bindAddress: socket.NetAddress = { 5243 address: '127.0.0.1', 5244 port: 9004 5245 }; 5246 await tcp.bind(bindAddress); 5247 let tcpExtraOptions: socket.TCPExtraOptions = { 5248 OOBInline: true, 5249 socketLinger: { 5250 on: true, linger: 10 5251 } 5252 }; 5253 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5254 if (err) { 5255 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5256 expectFail(); 5257 } else { 5258 console.info(`${caseName} success`); 5259 expectSuccess(); 5260 } 5261 await tcp.close(); 5262 console.info(`${caseName} test end`); 5263 done(); 5264 }); 5265 } catch (err) { 5266 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5267 expectFail(); 5268 console.info(`${caseName} test end`); 5269 done(); 5270 } 5271 }); 5272 5273 /* * 5274 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1000 5275 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1000 5276 * @tc.desc : Get TCPSocket status,Input parameter TCPNoDelay is false; callback 5277 * @tc.size : MediumTest 5278 * @tc.type : Function 5279 * @tc.level : level 2 5280 */ 5281 it('testNetworkMgrSocketTCPSocketSetExtraOptions1000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5282 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1000'; 5283 try { 5284 console.info(`${caseName} test start`); 5285 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5286 expect(tcp).assertInstanceOf('Object'); 5287 let bindAddress: socket.NetAddress = { 5288 address: '127.0.0.1', 5289 port: 9005 5290 }; 5291 await tcp.bind(bindAddress); 5292 let tcpExtraOptions: socket.TCPExtraOptions = { 5293 TCPNoDelay: false, 5294 socketLinger: { 5295 on: true, linger: 10 5296 } 5297 }; 5298 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5299 if (err) { 5300 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5301 expectFail(); 5302 } else { 5303 console.info(`${caseName} success`); 5304 expectSuccess(); 5305 } 5306 await tcp.close(); 5307 console.info(`${caseName} test end`); 5308 done(); 5309 }); 5310 } catch (err) { 5311 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5312 expectFail(); 5313 console.info(`${caseName} test end`); 5314 done(); 5315 } 5316 }); 5317 5318 /* * 5319 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1100 5320 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1100 5321 * @tc.desc : Get TCPSocket status,Input parameter TCPNoDelay is true; callback 5322 * @tc.size : MediumTest 5323 * @tc.type : Function 5324 * @tc.level : level 2 5325 */ 5326 it('testNetworkMgrSocketTCPSocketSetExtraOptions1100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5327 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1100'; 5328 try { 5329 console.info(`${caseName} test start`); 5330 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5331 expect(tcp).assertInstanceOf('Object'); 5332 let bindAddress: socket.NetAddress = { 5333 address: '127.0.0.1', 5334 port: 9006 5335 }; 5336 await tcp.bind(bindAddress); 5337 let tcpExtraOptions: socket.TCPExtraOptions = { 5338 TCPNoDelay: true, 5339 socketLinger: { 5340 on: true, linger: 10 5341 } 5342 }; 5343 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5344 if (err) { 5345 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5346 expectFail(); 5347 } else { 5348 console.info(`${caseName} success`); 5349 expectSuccess(); 5350 } 5351 await tcp.close(); 5352 console.info(`${caseName} test end`); 5353 done(); 5354 }); 5355 } catch (err) { 5356 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5357 expectFail(); 5358 console.info(`${caseName} test end`); 5359 done(); 5360 } 5361 }); 5362 5363 /* * 5364 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1200 5365 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1200 5366 * @tc.desc : Get TCPSocket status,Input parameter receiveBufferSize is -1; callback 5367 * @tc.size : MediumTest 5368 * @tc.type : Function 5369 * @tc.level : level 2 5370 */ 5371 it('testNetworkMgrSocketTCPSocketSetExtraOptions1200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5372 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1200'; 5373 try { 5374 console.info(`${caseName} test start`); 5375 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5376 expect(tcp).assertInstanceOf('Object'); 5377 let bindAddress: socket.NetAddress = { 5378 address: '127.0.0.1', 5379 port: 9007 5380 }; 5381 await tcp.bind(bindAddress); 5382 let tcpExtraOptions: socket.TCPExtraOptions = { 5383 receiveBufferSize: -1, 5384 socketLinger: { 5385 on: true, linger: 10 5386 } 5387 }; 5388 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5389 if (err) { 5390 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5391 expectFail(); 5392 } else { 5393 console.info(`${caseName} success`); 5394 expectSuccess(); 5395 } 5396 await tcp.close(); 5397 console.info(`${caseName} test end`); 5398 done(); 5399 }); 5400 } catch (err) { 5401 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5402 expectFail(); 5403 console.info(`${caseName} test end`); 5404 done(); 5405 } 5406 }); 5407 5408 /* * 5409 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1300 5410 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1300 5411 * @tc.desc : Get TCPSocket status,Input parameter receiveBufferSize is 0; callback 5412 * @tc.size : MediumTest 5413 * @tc.type : Function 5414 * @tc.level : level 2 5415 */ 5416 it('testNetworkMgrSocketTCPSocketSetExtraOptions1300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5417 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1300'; 5418 try { 5419 console.info(`${caseName} test start`); 5420 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5421 expect(tcp).assertInstanceOf('Object'); 5422 let bindAddress: socket.NetAddress = { 5423 address: '127.0.0.1', 5424 port: 9008 5425 }; 5426 await tcp.bind(bindAddress); 5427 let tcpExtraOptions: socket.TCPExtraOptions = { 5428 receiveBufferSize: 0, 5429 socketLinger: { 5430 on: true, linger: 10 5431 } 5432 }; 5433 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5434 if (err) { 5435 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5436 expectFail(); 5437 } else { 5438 console.info(`${caseName} success`); 5439 expectSuccess(); 5440 } 5441 await tcp.close(); 5442 console.info(`${caseName} test end`); 5443 done(); 5444 }); 5445 } catch (err) { 5446 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5447 expectFail(); 5448 console.info(`${caseName} test end`); 5449 done(); 5450 } 5451 }); 5452 5453 /* * 5454 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1400 5455 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1400 5456 * @tc.desc : Get TCPSocket status,Input parameter receiveBufferSize is 100; callback 5457 * @tc.size : MediumTest 5458 * @tc.type : Function 5459 * @tc.level : level 2 5460 */ 5461 it('testNetworkMgrSocketTCPSocketSetExtraOptions1400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5462 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1400'; 5463 try { 5464 console.info(`${caseName} test start`); 5465 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5466 expect(tcp).assertInstanceOf('Object'); 5467 let bindAddress: socket.NetAddress = { 5468 address: '127.0.0.1', 5469 port: 9009 5470 }; 5471 await tcp.bind(bindAddress); 5472 let tcpExtraOptions: socket.TCPExtraOptions = { 5473 receiveBufferSize: 100, 5474 socketLinger: { 5475 on: true, linger: 10 5476 } 5477 }; 5478 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5479 if (err) { 5480 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5481 expectFail(); 5482 } else { 5483 console.info(`${caseName} success`); 5484 expectSuccess(); 5485 } 5486 await tcp.close(); 5487 console.info(`${caseName} test end`); 5488 done(); 5489 }); 5490 } catch (err) { 5491 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5492 expectFail(); 5493 console.info(`${caseName} test end`); 5494 done(); 5495 } 5496 }); 5497 5498 /* * 5499 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1500 5500 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1500 5501 * @tc.desc : Get TCPSocket status,Input parameter sendBufferSize is -1; callback 5502 * @tc.size : MediumTest 5503 * @tc.type : Function 5504 * @tc.level : level 2 5505 */ 5506 it('testNetworkMgrSocketTCPSocketSetExtraOptions1500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5507 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1500'; 5508 try { 5509 console.info(`${caseName} test start`); 5510 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5511 expect(tcp).assertInstanceOf('Object'); 5512 let bindAddress: socket.NetAddress = { 5513 address: '127.0.0.1', 5514 port: 9010 5515 }; 5516 await tcp.bind(bindAddress); 5517 let tcpExtraOptions: socket.TCPExtraOptions = { 5518 sendBufferSize: -1, 5519 socketLinger: { 5520 on: true, linger: 10 5521 } 5522 }; 5523 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5524 if (err) { 5525 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5526 expectFail(); 5527 } else { 5528 console.info(`${caseName} success`); 5529 expectSuccess(); 5530 } 5531 await tcp.close(); 5532 console.info(`${caseName} test end`); 5533 done(); 5534 }); 5535 } catch (err) { 5536 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5537 expectFail(); 5538 console.info(`${caseName} test end`); 5539 done(); 5540 } 5541 }); 5542 5543 /* * 5544 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1600 5545 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1600 5546 * @tc.desc : Get TCPSocket status,Input parameter sendBufferSize is 0; callback 5547 * @tc.size : MediumTest 5548 * @tc.type : Function 5549 * @tc.level : level 2 5550 */ 5551 it('testNetworkMgrSocketTCPSocketSetExtraOptions1600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5552 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1600'; 5553 try { 5554 console.info(`${caseName} test start`); 5555 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5556 expect(tcp).assertInstanceOf('Object'); 5557 let bindAddress: socket.NetAddress = { 5558 address: '127.0.0.1', 5559 port: 9011 5560 }; 5561 await tcp.bind(bindAddress); 5562 let tcpExtraOptions: socket.TCPExtraOptions = { 5563 sendBufferSize: 0, 5564 socketLinger: { 5565 on: true, linger: 10 5566 } 5567 }; 5568 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5569 if (err) { 5570 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5571 expectFail(); 5572 } else { 5573 console.info(`${caseName} success`); 5574 expectSuccess(); 5575 } 5576 await tcp.close(); 5577 console.info(`${caseName} test end`); 5578 done(); 5579 }); 5580 } catch (err) { 5581 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5582 expectFail(); 5583 console.info(`${caseName} test end`); 5584 done(); 5585 } 5586 }); 5587 5588 /* * 5589 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1700 5590 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1700 5591 * @tc.desc : Get TCPSocket status,Input parameter sendBufferSize is 100; callback 5592 * @tc.size : MediumTest 5593 * @tc.type : Function 5594 * @tc.level : level 2 5595 */ 5596 it('testNetworkMgrSocketTCPSocketSetExtraOptions1700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5597 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1700'; 5598 try { 5599 console.info(`${caseName} test start`); 5600 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5601 expect(tcp).assertInstanceOf('Object'); 5602 let bindAddress: socket.NetAddress = { 5603 address: '127.0.0.1', 5604 port: 9012 5605 }; 5606 await tcp.bind(bindAddress); 5607 let tcpExtraOptions: socket.TCPExtraOptions = { 5608 sendBufferSize: 100, 5609 socketLinger: { 5610 on: true, linger: 10 5611 } 5612 }; 5613 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5614 if (err) { 5615 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5616 expectFail(); 5617 } else { 5618 console.info(`${caseName} success`); 5619 expectSuccess(); 5620 } 5621 await tcp.close(); 5622 console.info(`${caseName} test end`); 5623 done(); 5624 }); 5625 } catch (err) { 5626 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5627 expectFail(); 5628 console.info(`${caseName} test end`); 5629 done(); 5630 } 5631 }); 5632 5633 /* * 5634 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1800 5635 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1800 5636 * @tc.desc : Get TCPSocket status,Input parameter reuseAddress is true; callback 5637 * @tc.size : MediumTest 5638 * @tc.type : Function 5639 * @tc.level : level 2 5640 */ 5641 it('testNetworkMgrSocketTCPSocketSetExtraOptions1800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5642 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1800'; 5643 try { 5644 console.info(`${caseName} test start`); 5645 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5646 expect(tcp).assertInstanceOf('Object'); 5647 let bindAddress: socket.NetAddress = { 5648 address: '127.0.0.1', 5649 port: 9013 5650 }; 5651 await tcp.bind(bindAddress); 5652 let tcpExtraOptions: socket.TCPExtraOptions = { 5653 reuseAddress: true, 5654 socketLinger: { 5655 on: true, linger: 10 5656 } 5657 }; 5658 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5659 if (err) { 5660 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5661 expectFail(); 5662 } else { 5663 console.info(`${caseName} success`); 5664 expectSuccess(); 5665 } 5666 await tcp.close(); 5667 console.info(`${caseName} test end`); 5668 done(); 5669 }); 5670 } catch (err) { 5671 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5672 expectFail(); 5673 console.info(`${caseName} test end`); 5674 done(); 5675 } 5676 }); 5677 5678 /* * 5679 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_1900 5680 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions1900 5681 * @tc.desc : Get TCPSocket status,Input parameter reuseAddress is false; callback 5682 * @tc.size : MediumTest 5683 * @tc.type : Function 5684 * @tc.level : level 2 5685 */ 5686 it('testNetworkMgrSocketTCPSocketSetExtraOptions1900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5687 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions1900'; 5688 try { 5689 console.info(`${caseName} test start`); 5690 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5691 expect(tcp).assertInstanceOf('Object'); 5692 let bindAddress: socket.NetAddress = { 5693 address: '127.0.0.1', 5694 port: 9014 5695 }; 5696 await tcp.bind(bindAddress); 5697 let tcpExtraOptions: socket.TCPExtraOptions = { 5698 reuseAddress: false, 5699 socketLinger: { 5700 on: true, linger: 10 5701 } 5702 }; 5703 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5704 if (err) { 5705 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5706 expectFail(); 5707 } else { 5708 console.info(`${caseName} success`); 5709 expectSuccess(); 5710 } 5711 await tcp.close(); 5712 console.info(`${caseName} test end`); 5713 done(); 5714 }); 5715 } catch (err) { 5716 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5717 expectFail(); 5718 console.info(`${caseName} test end`); 5719 done(); 5720 } 5721 }); 5722 5723 /* * 5724 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2000 5725 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2000 5726 * @tc.desc : Get TCPSocket status,Input parameter socketTimeout is -1; callback 5727 * @tc.size : MediumTest 5728 * @tc.type : Function 5729 * @tc.level : level 2 5730 */ 5731 it('testNetworkMgrSocketTCPSocketSetExtraOptions2000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5732 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions2000'; 5733 try { 5734 console.info(`${caseName} test start`); 5735 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5736 expect(tcp).assertInstanceOf('Object'); 5737 let bindAddress: socket.NetAddress = { 5738 address: '127.0.0.1', 5739 port: 9014 5740 }; 5741 await tcp.bind(bindAddress); 5742 let tcpExtraOptions: socket.TCPExtraOptions = { 5743 socketTimeout: -1, 5744 socketLinger: { 5745 on: true, linger: 10 5746 } 5747 }; 5748 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5749 if (err) { 5750 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5751 expectTrue(err.code===2301033); 5752 } else { 5753 console.info(`${caseName} success`); 5754 expectFail(); 5755 } 5756 await tcp.close(); 5757 console.info(`${caseName} test end`); 5758 done(); 5759 }); 5760 } catch (err) { 5761 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5762 expectFail(); 5763 console.info(`${caseName} test end`); 5764 done(); 5765 } 5766 }); 5767 5768 /* * 5769 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2100 5770 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2100 5771 * @tc.desc : Get TCPSocket status,Input parameter socketTimeout is 0; callback 5772 * @tc.size : MediumTest 5773 * @tc.type : Function 5774 * @tc.level : level 2 5775 */ 5776 it('testNetworkMgrSocketTCPSocketSetExtraOptions2100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5777 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions2100'; 5778 try { 5779 console.info(`${caseName} test start`); 5780 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5781 expect(tcp).assertInstanceOf('Object'); 5782 let bindAddress: socket.NetAddress = { 5783 address: '127.0.0.1', 5784 port: 9014 5785 }; 5786 await tcp.bind(bindAddress); 5787 let tcpExtraOptions: socket.TCPExtraOptions = { 5788 socketTimeout: 0, 5789 socketLinger: { 5790 on: true, linger: 10 5791 } 5792 }; 5793 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5794 if (err) { 5795 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5796 expectFail(); 5797 } else { 5798 console.info(`${caseName} success`); 5799 expectSuccess(); 5800 } 5801 await tcp.close(); 5802 console.info(`${caseName} test end`); 5803 done(); 5804 }); 5805 } catch (err) { 5806 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5807 expectFail(); 5808 console.info(`${caseName} test end`); 5809 done(); 5810 } 5811 }); 5812 5813 /* * 5814 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2200 5815 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2200 5816 * @tc.desc : Get TCPSocket status,Input parameter socketTimeout is 100; callback 5817 * @tc.size : MediumTest 5818 * @tc.type : Function 5819 * @tc.level : level 2 5820 */ 5821 it('testNetworkMgrSocketTCPSocketSetExtraOptions2200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5822 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions2200'; 5823 try { 5824 console.info(`${caseName} test start`); 5825 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5826 expect(tcp).assertInstanceOf('Object'); 5827 let bindAddress: socket.NetAddress = { 5828 address: '127.0.0.1', 5829 port: 9015 5830 }; 5831 await tcp.bind(bindAddress); 5832 let tcpExtraOptions: socket.TCPExtraOptions = { 5833 socketTimeout: 100, 5834 socketLinger: { 5835 on: true, linger: 10 5836 } 5837 }; 5838 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5839 if (err) { 5840 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5841 expectFail(); 5842 } else { 5843 console.info(`${caseName} success`); 5844 expectSuccess(); 5845 } 5846 await tcp.close(); 5847 console.info(`${caseName} test end`); 5848 done(); 5849 }); 5850 } catch (err) { 5851 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5852 expectFail(); 5853 console.info(`${caseName} test end`); 5854 done(); 5855 } 5856 }); 5857 5858 /* * 5859 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2300 5860 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2300 5861 * @tc.desc : Get TCPSocket status,Input parameter linger is -1; callback 5862 * @tc.size : MediumTest 5863 * @tc.type : Function 5864 * @tc.level : level 2 5865 */ 5866 it('testNetworkMgrSocketTCPSocketSetExtraOptions2300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5867 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions2300'; 5868 try { 5869 console.info(`${caseName} test start`); 5870 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5871 expect(tcp).assertInstanceOf('Object'); 5872 let bindAddress: socket.NetAddress = { 5873 address: '127.0.0.1', 5874 port: 9016 5875 }; 5876 await tcp.bind(bindAddress); 5877 let tcpExtraOptions: socket.TCPExtraOptions = { 5878 socketLinger: { 5879 on: true, linger:-1 5880 } 5881 }; 5882 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5883 if (err) { 5884 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5885 expectFail(); 5886 } else { 5887 console.info(`${caseName} success`); 5888 expectSuccess(); 5889 } 5890 await tcp.close(); 5891 console.info(`${caseName} test end`); 5892 done(); 5893 }); 5894 } catch (err) { 5895 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5896 expectFail(); 5897 console.info(`${caseName} test end`); 5898 done(); 5899 } 5900 }); 5901 5902 /* * 5903 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2400 5904 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2400 5905 * @tc.desc : Get TCPSocket status,Input parameter linger is 0; callback 5906 * @tc.size : MediumTest 5907 * @tc.type : Function 5908 * @tc.level : level 2 5909 */ 5910 it('testNetworkMgrSocketTCPSocketSetExtraOptions2400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5911 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions2400'; 5912 try { 5913 console.info(`${caseName} test start`); 5914 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5915 expect(tcp).assertInstanceOf('Object'); 5916 let bindAddress: socket.NetAddress = { 5917 address: '127.0.0.1', 5918 port: 9017 5919 }; 5920 await tcp.bind(bindAddress); 5921 let tcpExtraOptions: socket.TCPExtraOptions = { 5922 socketLinger: { 5923 on: true, linger:0 5924 } 5925 }; 5926 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5927 if (err) { 5928 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5929 expectFail(); 5930 } else { 5931 console.info(`${caseName} success`); 5932 expectSuccess(); 5933 } 5934 await tcp.close(); 5935 console.info(`${caseName} test end`); 5936 done(); 5937 }); 5938 } catch (err) { 5939 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5940 expectFail(); 5941 console.info(`${caseName} test end`); 5942 done(); 5943 } 5944 }); 5945 5946 /* * 5947 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2500 5948 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2500 5949 * @tc.desc : Get TCPSocket status,Input parameter linger is 65535; callback 5950 * @tc.size : MediumTest 5951 * @tc.type : Function 5952 * @tc.level : level 2 5953 */ 5954 it('testNetworkMgrSocketTCPSocketSetExtraOptions2500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5955 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions2500'; 5956 try { 5957 console.info(`${caseName} test start`); 5958 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 5959 expect(tcp).assertInstanceOf('Object'); 5960 let bindAddress: socket.NetAddress = { 5961 address: '127.0.0.1', 5962 port: 9018 5963 }; 5964 await tcp.bind(bindAddress); 5965 let tcpExtraOptions: socket.TCPExtraOptions = { 5966 socketLinger: { 5967 on: true, linger:65535 5968 } 5969 }; 5970 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 5971 if (err) { 5972 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 5973 expectFail(); 5974 } else { 5975 console.info(`${caseName} success`); 5976 expectSuccess(); 5977 } 5978 await tcp.close(); 5979 console.info(`${caseName} test end`); 5980 done(); 5981 }); 5982 } catch (err) { 5983 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 5984 expectFail(); 5985 console.info(`${caseName} test end`); 5986 done(); 5987 } 5988 }); 5989 5990 /* * 5991 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2600 5992 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2600 5993 * @tc.desc : Get TCPSocket status,Input parameter linger is 65536; callback 5994 * @tc.size : MediumTest 5995 * @tc.type : Function 5996 * @tc.level : level 2 5997 */ 5998 it('testNetworkMgrSocketTCPSocketSetExtraOptions2600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 5999 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions2600'; 6000 try { 6001 console.info(`${caseName} test start`); 6002 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6003 expect(tcp).assertInstanceOf('Object'); 6004 let bindAddress: socket.NetAddress = { 6005 address: '127.0.0.1', 6006 port: 9019 6007 }; 6008 await tcp.bind(bindAddress); 6009 let tcpExtraOptions: socket.TCPExtraOptions = { 6010 socketLinger: { 6011 on: true, linger:65536 6012 } 6013 }; 6014 tcp.setExtraOptions(tcpExtraOptions, async (err: BusinessError) => { 6015 if (err) { 6016 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6017 expectFail(); 6018 } else { 6019 console.info(`${caseName} success`); 6020 expectSuccess(); 6021 } 6022 await tcp.close(); 6023 console.info(`${caseName} test end`); 6024 done(); 6025 }); 6026 } catch (err) { 6027 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 6028 expectFail(); 6029 console.info(`${caseName} test end`); 6030 done(); 6031 } 6032 }); 6033 6034 /* * 6035 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2700 6036 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2700 6037 * @tc.desc : Get TCPSocket status,after bind; promise 6038 * @tc.size : MediumTest 6039 * @tc.type : Function 6040 * @tc.level : level 2 6041 */ 6042 it('testNetworkMgrSocketTCPSocketSetExtraOptions2700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6043 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions2700'; 6044 console.info(`${caseName} test start`); 6045 try { 6046 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6047 expect(tcp).assertInstanceOf('Object') 6048 let bindAddress: socket.NetAddress = { 6049 address: '127.0.0.1', 6050 port: 9004 6051 }; 6052 await tcp.bind(bindAddress); 6053 let tcpExtraOptions: socket.TCPExtraOptions = { 6054 keepAlive: true, 6055 OOBInline: true, 6056 TCPNoDelay: true, 6057 socketLinger: { 6058 on: true, linger: 10 6059 }, 6060 receiveBufferSize: 1000, 6061 sendBufferSize: 1000, 6062 reuseAddress: true, 6063 socketTimeout: 3000 6064 }; 6065 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6066 console.info(`${caseName} success `); 6067 expectSuccess(); 6068 done(); 6069 }).catch((err: BusinessError) => { 6070 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6071 expectFail(); 6072 done(); 6073 }).finally(async () => { 6074 await tcp.close(); 6075 console.info(`${caseName} test end`); 6076 done(); 6077 }); 6078 } catch (err) { 6079 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6080 expectFail(); 6081 console.info(`${caseName} test end`); 6082 done(); 6083 } 6084 }); 6085 6086 /* * 6087 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2800 6088 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2800 6089 * @tc.desc : Get TCPSocket status,after bind and connect; promise 6090 * @tc.size : MediumTest 6091 * @tc.type : Function 6092 * @tc.level : level 2 6093 */ 6094 it('testNetworkMgrSocketTCPSocketSetExtraOptions2800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6095 let caseName: String = 'testNetworkMgrSocketTCPSocketSetExtraOptions2800'; 6096 try { 6097 console.info(`${caseName} test start`); 6098 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6099 expect(tcp).assertInstanceOf('Object'); 6100 let bindAddress: socket.NetAddress = { 6101 address: '127.0.0.1', 6102 port: 4088 6103 }; 6104 await tcp.bind(bindAddress); 6105 let tcpConnectOptions: socket.TCPConnectOptions = { 6106 address: bindAddress, 6107 }; 6108 await tcp.connect(tcpConnectOptions); 6109 let tcpExtraOptions: socket.TCPExtraOptions = { 6110 keepAlive: true, 6111 OOBInline: true, 6112 TCPNoDelay: true, 6113 socketLinger: { 6114 on: true, linger: 10 6115 }, 6116 receiveBufferSize: 1000, 6117 sendBufferSize: 1000, 6118 reuseAddress: true, 6119 socketTimeout: 3000 6120 }; 6121 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6122 console.info(`${caseName} success `); 6123 expectSuccess(); 6124 done(); 6125 }).catch((err: BusinessError) => { 6126 console.info(`${caseName}_1 fail err:${JSON.stringify(err)}`); 6127 expectFail(); 6128 done(); 6129 }).finally(async () => { 6130 await tcp.close(); 6131 console.info(`${caseName} test end`); 6132 done(); 6133 }) 6134 } catch (err) { 6135 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 6136 expectFail(); 6137 console.info(`${caseName} test end`); 6138 done(); 6139 } 6140 }); 6141 6142 /* * 6143 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_2900 6144 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions2900 6145 * @tc.desc : Get TCPSocket status,after listen and connect; promise 6146 * @tc.size : MediumTest 6147 * @tc.type : Function 6148 * @tc.level : level 2 6149 */ 6150 it('testNetworkMgrSocketTCPSocketSetExtraOptions2900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6151 let caseName: String = 'testNetworkMgrSocketTCPSocketSetExtraOptions2900'; 6152 try { 6153 console.info(`${caseName} test start`); 6154 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6155 expect(tcp).assertInstanceOf('Object'); 6156 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 6157 expect(tcpServer).assertInstanceOf('Object'); 6158 let listenAddress: socket.NetAddress = { 6159 address: '127.0.0.1', 6160 port: 4089, 6161 family: 1 6162 }; 6163 await tcpServer.listen(listenAddress); 6164 let tcpConnectOptions: socket.TCPConnectOptions = { 6165 address: listenAddress, 6166 }; 6167 await tcp.connect(tcpConnectOptions); 6168 let tcpExtraOptions: socket.TCPExtraOptions = { 6169 keepAlive: true, 6170 OOBInline: true, 6171 TCPNoDelay: true, 6172 socketLinger: { 6173 on: true, linger: 10 6174 }, 6175 receiveBufferSize: 1000, 6176 sendBufferSize: 1000, 6177 reuseAddress: true, 6178 socketTimeout: 3000 6179 }; 6180 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6181 console.info(`${caseName} success `); 6182 expectSuccess(); 6183 done(); 6184 }).catch((err: BusinessError) => { 6185 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6186 expectFail(); 6187 done(); 6188 }).finally(async () => { 6189 await tcp.close(); 6190 console.info(`${caseName} test end`); 6191 done(); 6192 }); 6193 } catch (err) { 6194 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 6195 expectFail(); 6196 console.info(`${caseName} test end`); 6197 done(); 6198 } 6199 }); 6200 6201 /* * 6202 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3000 6203 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3000 6204 * @tc.desc : Get TCPSocket status,Input parameter is null; promise 6205 * @tc.size : MediumTest 6206 * @tc.type : Function 6207 * @tc.level : level 2 6208 */ 6209 it('testNetworkMgrSocketTCPSocketSetExtraOptions3000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6210 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3000'; 6211 console.info(`${caseName} test start`); 6212 try { 6213 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6214 expect(tcp).assertInstanceOf('Object'); 6215 let bindAddress: socket.NetAddress = { 6216 address: '127.0.0.1', 6217 port: 4090 6218 }; 6219 await tcp.bind(bindAddress); 6220 tcp.setExtraOptions(null).then(() => { 6221 console.info(`${caseName} success `); 6222 expectFail(); 6223 done(); 6224 }).catch((err: BusinessError) => { 6225 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6226 expectEqual(err.code, 401); 6227 done(); 6228 }).finally(async () => { 6229 await tcp.close(); 6230 console.info(`${caseName} test end`); 6231 done(); 6232 }); 6233 } catch (err) { 6234 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6235 expectFail(); 6236 console.info(`${caseName} test end`); 6237 done(); 6238 } 6239 }); 6240 6241 /* * 6242 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3100 6243 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3100 6244 * @tc.desc : Get TCPSocket status,Input parameter is undefined; promise 6245 * @tc.size : MediumTest 6246 * @tc.type : Function 6247 * @tc.level : level 2 6248 */ 6249 it('testNetworkMgrSocketTCPSocketSetExtraOptions3100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6250 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3100'; 6251 console.info(`${caseName} test start`); 6252 try { 6253 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6254 expect(tcp).assertInstanceOf('Object'); 6255 let bindAddress: socket.NetAddress = { 6256 address: '127.0.0.1', 6257 port: 4091 6258 }; 6259 await tcp.bind(bindAddress); 6260 tcp.setExtraOptions(undefined).then(() => { 6261 console.info(`${caseName} success `); 6262 expectFail(); 6263 done(); 6264 }).catch((err: BusinessError) => { 6265 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6266 expectEqual(err.code, 401); 6267 done(); 6268 }).finally(async () => { 6269 await tcp.close(); 6270 console.info(`${caseName} test end`); 6271 done(); 6272 }); 6273 } catch (err) { 6274 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6275 expectFail(); 6276 console.info(`${caseName} test end`); 6277 done(); 6278 } 6279 }); 6280 6281 /* * 6282 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3200 6283 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3200 6284 * @tc.desc : Get TCPSocket status,Input parameter keepAlive is false; promise 6285 * @tc.size : MediumTest 6286 * @tc.type : Function 6287 * @tc.level : level 2 6288 */ 6289 it('testNetworkMgrSocketTCPSocketSetExtraOptions3200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6290 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3200'; 6291 console.info(`${caseName} test start`); 6292 try { 6293 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6294 expect(tcp).assertInstanceOf('Object') 6295 let bindAddress: socket.NetAddress = { 6296 address: '127.0.0.1', 6297 port: 10001 6298 }; 6299 await tcp.bind(bindAddress); 6300 let tcpExtraOptions: socket.TCPExtraOptions = { 6301 keepAlive: true, 6302 socketLinger: { 6303 on: true, linger: 10 6304 }, 6305 }; 6306 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6307 console.info(`${caseName} success `); 6308 expectSuccess(); 6309 done(); 6310 }).catch((err: BusinessError) => { 6311 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6312 expectFail(); 6313 done(); 6314 }).finally(async () => { 6315 await tcp.close(); 6316 console.info(`${caseName} test end`); 6317 done(); 6318 }); 6319 } catch (err) { 6320 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6321 expectFail(); 6322 console.info(`${caseName} test end`); 6323 done(); 6324 } 6325 }); 6326 6327 /* * 6328 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3300 6329 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3300 6330 * @tc.desc : Get TCPSocket status,Input parameter keepAlive is true; promise 6331 * @tc.size : MediumTest 6332 * @tc.type : Function 6333 * @tc.level : level 2 6334 */ 6335 it('testNetworkMgrSocketTCPSocketSetExtraOptions3300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6336 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3300'; 6337 console.info(`${caseName} test start`); 6338 try { 6339 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6340 expect(tcp).assertInstanceOf('Object') 6341 let bindAddress: socket.NetAddress = { 6342 address: '127.0.0.1', 6343 port: 10002 6344 }; 6345 await tcp.bind(bindAddress); 6346 let tcpExtraOptions: socket.TCPExtraOptions = { 6347 keepAlive: false, 6348 socketLinger: { 6349 on: false, linger: 10 6350 }, 6351 }; 6352 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6353 console.info(`${caseName} success `); 6354 expectSuccess(); 6355 done(); 6356 }).catch((err: BusinessError) => { 6357 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6358 expectFail(); 6359 done(); 6360 }).finally(async () => { 6361 await tcp.close(); 6362 console.info(`${caseName} test end`); 6363 done(); 6364 }); 6365 } catch (err) { 6366 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6367 expectFail(); 6368 console.info(`${caseName} test end`); 6369 done(); 6370 } 6371 }); 6372 6373 /* * 6374 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3400 6375 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3400 6376 * @tc.desc : Get TCPSocket status,Input parameter OOBlnLine is false; promise 6377 * @tc.size : MediumTest 6378 * @tc.type : Function 6379 * @tc.level : level 2 6380 */ 6381 it('testNetworkMgrSocketTCPSocketSetExtraOptions3400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6382 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3400'; 6383 console.info(`${caseName} test start`); 6384 try { 6385 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6386 expect(tcp).assertInstanceOf('Object') 6387 let bindAddress: socket.NetAddress = { 6388 address: '127.0.0.1', 6389 port: 10003 6390 }; 6391 await tcp.bind(bindAddress); 6392 let tcpExtraOptions: socket.TCPExtraOptions = { 6393 OOBInline: false, 6394 socketLinger: { 6395 on: true, linger: 10 6396 }, 6397 }; 6398 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6399 console.info(`${caseName} success `); 6400 expectSuccess(); 6401 done(); 6402 }).catch((err: BusinessError) => { 6403 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6404 expectFail(); 6405 done(); 6406 }).finally(async () => { 6407 await tcp.close(); 6408 console.info(`${caseName} test end`); 6409 done(); 6410 }); 6411 } catch (err) { 6412 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6413 expectFail(); 6414 console.info(`${caseName} test end`); 6415 done(); 6416 } 6417 }); 6418 6419 /* * 6420 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3500 6421 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3500 6422 * @tc.desc : Get TCPSocket status, Input parameter OOBlnLine is true; promise 6423 * @tc.size : MediumTest 6424 * @tc.type : Function 6425 * @tc.level : level 2 6426 */ 6427 it('testNetworkMgrSocketTCPSocketSetExtraOptions3500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6428 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3500'; 6429 console.info(`${caseName} test start`); 6430 try { 6431 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6432 expect(tcp).assertInstanceOf('Object') 6433 let bindAddress: socket.NetAddress = { 6434 address: '127.0.0.1', 6435 port: 10003 6436 }; 6437 await tcp.bind(bindAddress); 6438 let tcpExtraOptions: socket.TCPExtraOptions = { 6439 OOBInline: true, 6440 socketLinger: { 6441 on: true, linger: 10 6442 }, 6443 }; 6444 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6445 console.info(`${caseName} success `); 6446 expectSuccess(); 6447 done(); 6448 }).catch((err: BusinessError) => { 6449 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6450 expectFail(); 6451 done(); 6452 }).finally(async () => { 6453 await tcp.close(); 6454 console.info(`${caseName} test end`); 6455 done(); 6456 }); 6457 } catch (err) { 6458 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6459 expectFail(); 6460 console.info(`${caseName} test end`); 6461 done(); 6462 } 6463 }); 6464 6465 /* * 6466 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3600 6467 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3600 6468 * @tc.desc : Get TCPSocket status,Input parameter TCPNoDelay is false; promise 6469 * @tc.size : MediumTest 6470 * @tc.type : Function 6471 * @tc.level : level 2 6472 */ 6473 it('testNetworkMgrSocketTCPSocketSetExtraOptions3600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6474 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3600'; 6475 console.info(`${caseName} test start`); 6476 try { 6477 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6478 expect(tcp).assertInstanceOf('Object') 6479 let bindAddress: socket.NetAddress = { 6480 address: '127.0.0.1', 6481 port: 10004 6482 }; 6483 await tcp.bind(bindAddress); 6484 let tcpExtraOptions: socket.TCPExtraOptions = { 6485 TCPNoDelay: false, 6486 socketLinger: { 6487 on: true, linger: 10 6488 }, 6489 }; 6490 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6491 console.info(`${caseName} success `); 6492 expectSuccess(); 6493 done(); 6494 }).catch((err: BusinessError) => { 6495 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6496 expectFail(); 6497 done(); 6498 }).finally(async () => { 6499 await tcp.close(); 6500 console.info(`${caseName} test end`); 6501 done(); 6502 }); 6503 } catch (err) { 6504 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6505 expectFail(); 6506 console.info(`${caseName} test end`); 6507 done(); 6508 } 6509 }); 6510 6511 /* * 6512 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3700 6513 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3700 6514 * @tc.desc : Get TCPSocket status,Input parameter TCPNoDelay is true; promise 6515 * @tc.size : MediumTest 6516 * @tc.type : Function 6517 * @tc.level : level 2 6518 */ 6519 it('testNetworkMgrSocketTCPSocketSetExtraOptions3700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6520 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3700'; 6521 console.info(`${caseName} test start`); 6522 try { 6523 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6524 expect(tcp).assertInstanceOf('Object') 6525 let bindAddress: socket.NetAddress = { 6526 address: '127.0.0.1', 6527 port: 10004 6528 }; 6529 await tcp.bind(bindAddress); 6530 let tcpExtraOptions: socket.TCPExtraOptions = { 6531 TCPNoDelay: false, 6532 socketLinger: { 6533 on: true, linger: 10 6534 }, 6535 }; 6536 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6537 console.info(`${caseName} success `); 6538 expectSuccess(); 6539 done(); 6540 }).catch((err: BusinessError) => { 6541 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6542 expectFail(); 6543 done(); 6544 }).finally(async () => { 6545 await tcp.close(); 6546 console.info(`${caseName} test end`); 6547 done(); 6548 }); 6549 } catch (err) { 6550 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6551 expectFail(); 6552 console.info(`${caseName} test end`); 6553 done(); 6554 } 6555 }); 6556 6557 /* * 6558 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3800 6559 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3800 6560 * @tc.desc : Get TCPSocket status,Input parameter receiveBufferSize is -1; promise 6561 * @tc.size : MediumTest 6562 * @tc.type : Function 6563 * @tc.level : level 2 6564 */ 6565 it('testNetworkMgrSocketTCPSocketSetExtraOptions3800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6566 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3800'; 6567 console.info(`${caseName} test start`); 6568 try { 6569 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6570 expect(tcp).assertInstanceOf('Object') 6571 let bindAddress: socket.NetAddress = { 6572 address: '127.0.0.1', 6573 port: 10005 6574 }; 6575 await tcp.bind(bindAddress); 6576 let tcpExtraOptions: socket.TCPExtraOptions = { 6577 receiveBufferSize: -1, 6578 socketLinger: { 6579 on: true, linger: 10 6580 }, 6581 }; 6582 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6583 console.info(`${caseName} success `); 6584 expectSuccess(); 6585 done(); 6586 }).catch((err: BusinessError) => { 6587 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6588 expectFail(); 6589 done(); 6590 }).finally(async () => { 6591 await tcp.close(); 6592 console.info(`${caseName} test end`); 6593 done(); 6594 }); 6595 } catch (err) { 6596 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6597 expectFail(); 6598 console.info(`${caseName} test end`); 6599 done(); 6600 } 6601 }); 6602 6603 /* * 6604 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_3900 6605 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions3900 6606 * @tc.desc : Get TCPSocket status,Input parameter receiveBufferSize is 0; promise 6607 * @tc.size : MediumTest 6608 * @tc.type : Function 6609 * @tc.level : level 2 6610 */ 6611 it('testNetworkMgrSocketTCPSocketSetExtraOptions3900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6612 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions3900'; 6613 console.info(`${caseName} test start`); 6614 try { 6615 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6616 expect(tcp).assertInstanceOf('Object') 6617 let bindAddress: socket.NetAddress = { 6618 address: '127.0.0.1', 6619 port: 10006 6620 }; 6621 await tcp.bind(bindAddress); 6622 let tcpExtraOptions: socket.TCPExtraOptions = { 6623 receiveBufferSize: 0, 6624 socketLinger: { 6625 on: true, linger: 10 6626 }, 6627 }; 6628 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6629 console.info(`${caseName} success `); 6630 expectSuccess(); 6631 done(); 6632 }).catch((err: BusinessError) => { 6633 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6634 expectFail(); 6635 done(); 6636 }).finally(async () => { 6637 await tcp.close(); 6638 console.info(`${caseName} test end`); 6639 done(); 6640 }); 6641 } catch (err) { 6642 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6643 expectFail(); 6644 console.info(`${caseName} test end`); 6645 done(); 6646 } 6647 }); 6648 6649 /* * 6650 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4000 6651 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4000 6652 * @tc.desc : Get TCPSocket status,Input parameter receiveBufferSize is 100; promise 6653 * @tc.size : MediumTest 6654 * @tc.type : Function 6655 * @tc.level : level 2 6656 */ 6657 it('testNetworkMgrSocketTCPSocketSetExtraOptions4000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6658 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4000'; 6659 console.info(`${caseName} test start`); 6660 try { 6661 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6662 expect(tcp).assertInstanceOf('Object') 6663 let bindAddress: socket.NetAddress = { 6664 address: '127.0.0.1', 6665 port: 10007 6666 }; 6667 await tcp.bind(bindAddress); 6668 let tcpExtraOptions: socket.TCPExtraOptions = { 6669 receiveBufferSize: 100, 6670 socketLinger: { 6671 on: true, linger: 10 6672 }, 6673 }; 6674 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6675 console.info(`${caseName} success `); 6676 expectSuccess(); 6677 done(); 6678 }).catch((err: BusinessError) => { 6679 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6680 expectFail(); 6681 done(); 6682 }).finally(async () => { 6683 await tcp.close(); 6684 console.info(`${caseName} test end`); 6685 done(); 6686 }); 6687 } catch (err) { 6688 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6689 expectFail(); 6690 console.info(`${caseName} test end`); 6691 done(); 6692 } 6693 }); 6694 6695 /* * 6696 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4100 6697 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4100 6698 * @tc.desc : Get TCPSocket status,Input parameter sendBufferSize is -1; promise 6699 * @tc.size : MediumTest 6700 * @tc.type : Function 6701 * @tc.level : level 2 6702 */ 6703 it('testNetworkMgrSocketTCPSocketSetExtraOptions4100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6704 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4100'; 6705 console.info(`${caseName} test start`); 6706 try { 6707 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6708 expect(tcp).assertInstanceOf('Object') 6709 let bindAddress: socket.NetAddress = { 6710 address: '127.0.0.1', 6711 port: 10008 6712 }; 6713 await tcp.bind(bindAddress); 6714 let tcpExtraOptions: socket.TCPExtraOptions = { 6715 sendBufferSize: -1, 6716 socketLinger: { 6717 on: true, linger: 10 6718 }, 6719 }; 6720 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6721 console.info(`${caseName} success `); 6722 expectSuccess(); 6723 done(); 6724 }).catch((err: BusinessError) => { 6725 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6726 expectFail(); 6727 done(); 6728 }).finally(async () => { 6729 await tcp.close(); 6730 console.info(`${caseName} test end`); 6731 done(); 6732 }); 6733 } catch (err) { 6734 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6735 expectFail(); 6736 console.info(`${caseName} test end`); 6737 done(); 6738 } 6739 }); 6740 6741 /* * 6742 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4200 6743 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4200 6744 * @tc.desc : Get TCPSocket status,Input parameter sendBufferSize is 0; promise 6745 * @tc.size : MediumTest 6746 * @tc.type : Function 6747 * @tc.level : level 2 6748 */ 6749 it('testNetworkMgrSocketTCPSocketSetExtraOptions4200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6750 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4200'; 6751 console.info(`${caseName} test start`); 6752 try { 6753 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6754 expect(tcp).assertInstanceOf('Object') 6755 let bindAddress: socket.NetAddress = { 6756 address: '127.0.0.1', 6757 port: 10008 6758 }; 6759 await tcp.bind(bindAddress); 6760 let tcpExtraOptions: socket.TCPExtraOptions = { 6761 sendBufferSize: 0, 6762 socketLinger: { 6763 on: true, linger: 10 6764 }, 6765 }; 6766 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6767 console.info(`${caseName} success `); 6768 expectSuccess(); 6769 done(); 6770 }).catch((err: BusinessError) => { 6771 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6772 expectFail(); 6773 done(); 6774 }).finally(async () => { 6775 await tcp.close(); 6776 console.info(`${caseName} test end`); 6777 done(); 6778 }); 6779 } catch (err) { 6780 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6781 expectFail(); 6782 console.info(`${caseName} test end`); 6783 done(); 6784 } 6785 }); 6786 6787 /* * 6788 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4300 6789 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4300 6790 * @tc.desc : Get TCPSocket status,Input parameter sendBufferSize is 100; promise 6791 * @tc.size : MediumTest 6792 * @tc.type : Function 6793 * @tc.level : level 2 6794 */ 6795 it('testNetworkMgrSocketTCPSocketSetExtraOptions4300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6796 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4300'; 6797 console.info(`${caseName} test start`); 6798 try { 6799 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6800 expect(tcp).assertInstanceOf('Object') 6801 let bindAddress: socket.NetAddress = { 6802 address: '127.0.0.1', 6803 port: 10008 6804 }; 6805 await tcp.bind(bindAddress); 6806 let tcpExtraOptions: socket.TCPExtraOptions = { 6807 sendBufferSize: 100, 6808 socketLinger: { 6809 on: true, linger: 10 6810 }, 6811 }; 6812 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6813 console.info(`${caseName} success `); 6814 expectSuccess(); 6815 done(); 6816 }).catch((err: BusinessError) => { 6817 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6818 expectFail(); 6819 done(); 6820 }).finally(async () => { 6821 await tcp.close(); 6822 console.info(`${caseName} test end`); 6823 done(); 6824 }); 6825 } catch (err) { 6826 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6827 expectFail(); 6828 console.info(`${caseName} test end`); 6829 done(); 6830 } 6831 }); 6832 6833 /* * 6834 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4400 6835 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4400 6836 * @tc.desc : Get TCPSocket status,Input parameter reuseAddress is true; promise 6837 * @tc.size : MediumTest 6838 * @tc.type : Function 6839 * @tc.level : level 2 6840 */ 6841 it('testNetworkMgrSocketTCPSocketSetExtraOptions4400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6842 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4400'; 6843 console.info(`${caseName} test start`); 6844 try { 6845 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6846 expect(tcp).assertInstanceOf('Object') 6847 let bindAddress: socket.NetAddress = { 6848 address: '127.0.0.1', 6849 port: 10009 6850 }; 6851 await tcp.bind(bindAddress); 6852 let tcpExtraOptions: socket.TCPExtraOptions = { 6853 reuseAddress: true, 6854 socketLinger: { 6855 on: true, linger: 10 6856 }, 6857 }; 6858 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6859 console.info(`${caseName} success `); 6860 expectSuccess(); 6861 done(); 6862 }).catch((err: BusinessError) => { 6863 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6864 expectFail(); 6865 done(); 6866 }).finally(async () => { 6867 await tcp.close(); 6868 console.info(`${caseName} test end`); 6869 done(); 6870 }); 6871 } catch (err) { 6872 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6873 expectFail(); 6874 console.info(`${caseName} test end`); 6875 done(); 6876 } 6877 }); 6878 6879 /* * 6880 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4500 6881 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4500 6882 * @tc.desc : Get TCPSocket status,Input parameter reuseAddress is false; promise 6883 * @tc.size : MediumTest 6884 * @tc.type : Function 6885 * @tc.level : level 2 6886 */ 6887 it('testNetworkMgrSocketTCPSocketSetExtraOptions4500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6888 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4500'; 6889 console.info(`${caseName} test start`); 6890 try { 6891 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6892 expect(tcp).assertInstanceOf('Object') 6893 let bindAddress: socket.NetAddress = { 6894 address: '127.0.0.1', 6895 port: 10010 6896 }; 6897 await tcp.bind(bindAddress); 6898 let tcpExtraOptions: socket.TCPExtraOptions = { 6899 reuseAddress: false, 6900 socketLinger: { 6901 on: true, linger: 10 6902 }, 6903 }; 6904 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6905 console.info(`${caseName} success `); 6906 expectSuccess(); 6907 done(); 6908 }).catch((err: BusinessError) => { 6909 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6910 expectFail(); 6911 done(); 6912 }).finally(async () => { 6913 await tcp.close(); 6914 console.info(`${caseName} test end`); 6915 done(); 6916 }); 6917 } catch (err) { 6918 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6919 expectFail(); 6920 console.info(`${caseName} test end`); 6921 done(); 6922 } 6923 }); 6924 6925 /* * 6926 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4600 6927 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4600 6928 * @tc.desc : Get TCPSocket status,Input parameter socketTimeout is -1; promise 6929 * @tc.size : MediumTest 6930 * @tc.type : Function 6931 * @tc.level : level 2 6932 */ 6933 it('testNetworkMgrSocketTCPSocketSetExtraOptions4600', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6934 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4600'; 6935 console.info(`${caseName} test start`); 6936 try { 6937 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6938 expect(tcp).assertInstanceOf('Object') 6939 let bindAddress: socket.NetAddress = { 6940 address: '127.0.0.1', 6941 port: 10011 6942 }; 6943 await tcp.bind(bindAddress); 6944 let tcpExtraOptions: socket.TCPExtraOptions = { 6945 socketTimeout: -1, 6946 socketLinger: { 6947 on: true, linger: 10 6948 }, 6949 }; 6950 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6951 console.info(`${caseName} success `); 6952 expectFail(); 6953 done(); 6954 }).catch((err: BusinessError) => { 6955 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 6956 expectTrue(err.code===2301033); 6957 done(); 6958 }).finally(async () => { 6959 await tcp.close(); 6960 console.info(`${caseName} test end`); 6961 done(); 6962 }); 6963 } catch (err) { 6964 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 6965 expectFail(); 6966 console.info(`${caseName} test end`); 6967 done(); 6968 } 6969 }); 6970 6971 /* * 6972 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4700 6973 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4700 6974 * @tc.desc : Get TCPSocket status,Input parameter socketTimeout is 0; promise 6975 * @tc.size : MediumTest 6976 * @tc.type : Function 6977 * @tc.level : level 2 6978 */ 6979 it('testNetworkMgrSocketTCPSocketSetExtraOptions4700', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 6980 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4700'; 6981 console.info(`${caseName} test start`); 6982 try { 6983 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 6984 expect(tcp).assertInstanceOf('Object') 6985 let bindAddress: socket.NetAddress = { 6986 address: '127.0.0.1', 6987 port: 10012 6988 }; 6989 await tcp.bind(bindAddress); 6990 let tcpExtraOptions: socket.TCPExtraOptions = { 6991 socketTimeout: 0, 6992 socketLinger: { 6993 on: true, linger: 10 6994 }, 6995 }; 6996 tcp.setExtraOptions(tcpExtraOptions).then(() => { 6997 console.info(`${caseName} success `); 6998 expectSuccess(); 6999 done(); 7000 }).catch((err: BusinessError) => { 7001 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 7002 expectFail(); 7003 done(); 7004 }).finally(async () => { 7005 await tcp.close(); 7006 console.info(`${caseName} test end`); 7007 done(); 7008 }); 7009 } catch (err) { 7010 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 7011 expectFail(); 7012 console.info(`${caseName} test end`); 7013 done(); 7014 } 7015 }); 7016 7017 /* * 7018 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4800 7019 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4800 7020 * @tc.desc : Get TCPSocket status,Input parameter socketTimeout is 100; promise 7021 * @tc.size : MediumTest 7022 * @tc.type : Function 7023 * @tc.level : level 2 7024 */ 7025 it('testNetworkMgrSocketTCPSocketSetExtraOptions4800', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7026 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4800'; 7027 console.info(`${caseName} test start`); 7028 try { 7029 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7030 expect(tcp).assertInstanceOf('Object') 7031 let bindAddress: socket.NetAddress = { 7032 address: '127.0.0.1', 7033 port: 10013 7034 }; 7035 await tcp.bind(bindAddress); 7036 let tcpExtraOptions: socket.TCPExtraOptions = { 7037 socketTimeout: 100, 7038 socketLinger: { 7039 on: true, linger: 10 7040 }, 7041 }; 7042 tcp.setExtraOptions(tcpExtraOptions).then(() => { 7043 console.info(`${caseName} success `); 7044 expectSuccess(); 7045 done(); 7046 }).catch((err: BusinessError) => { 7047 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 7048 expectFail(); 7049 done(); 7050 }).finally(async () => { 7051 await tcp.close(); 7052 console.info(`${caseName} test end`); 7053 done(); 7054 }); 7055 } catch (err) { 7056 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 7057 expectFail(); 7058 console.info(`${caseName} test end`); 7059 done(); 7060 } 7061 }); 7062 7063 /* * 7064 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_4900 7065 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions4900 7066 * @tc.desc : Get TCPSocket status,Input parameter linger is -1; promise 7067 * @tc.size : MediumTest 7068 * @tc.type : Function 7069 * @tc.level : level 2 7070 */ 7071 it('testNetworkMgrSocketTCPSocketSetExtraOptions4900', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7072 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions4900'; 7073 console.info(`${caseName} test start`); 7074 try { 7075 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7076 expect(tcp).assertInstanceOf('Object') 7077 let bindAddress: socket.NetAddress = { 7078 address: '127.0.0.1', 7079 port: 10014 7080 }; 7081 await tcp.bind(bindAddress); 7082 let tcpExtraOptions: socket.TCPExtraOptions = { 7083 socketLinger: { 7084 on: true, linger: -1 7085 }, 7086 }; 7087 tcp.setExtraOptions(tcpExtraOptions).then(() => { 7088 console.info(`${caseName} success `); 7089 expectSuccess(); 7090 done(); 7091 }).catch((err: BusinessError) => { 7092 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 7093 expectFail(); 7094 done(); 7095 }).finally(async () => { 7096 await tcp.close(); 7097 console.info(`${caseName} test end`); 7098 done(); 7099 }); 7100 } catch (err) { 7101 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 7102 expectFail(); 7103 console.info(`${caseName} test end`); 7104 done(); 7105 } 7106 }); 7107 7108 /* * 7109 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_5000 7110 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions5000 7111 * @tc.desc : Get TCPSocket status,Input parameter linger is 0; promise 7112 * @tc.size : MediumTest 7113 * @tc.type : Function 7114 * @tc.level : level 2 7115 */ 7116 it('testNetworkMgrSocketTCPSocketSetExtraOptions5000', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7117 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions5000'; 7118 console.info(`${caseName} test start`); 7119 try { 7120 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7121 expect(tcp).assertInstanceOf('Object'); 7122 let bindAddress: socket.NetAddress = { 7123 address: '127.0.0.1', 7124 port: 10015 7125 }; 7126 await tcp.bind(bindAddress); 7127 let tcpExtraOptions: socket.TCPExtraOptions = { 7128 socketLinger: { 7129 on: true, linger: 0 7130 }, 7131 }; 7132 tcp.setExtraOptions(tcpExtraOptions).then(() => { 7133 console.info(`${caseName} success `); 7134 expectSuccess(); 7135 done(); 7136 }).catch((err: BusinessError) => { 7137 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 7138 expectFail(); 7139 done(); 7140 }).finally(async () => { 7141 await tcp.close(); 7142 console.info(`${caseName} test end`); 7143 done(); 7144 }); 7145 } catch (err) { 7146 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 7147 expectFail(); 7148 console.info(`${caseName} test end`); 7149 done(); 7150 } 7151 }); 7152 7153 /* * 7154 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_5100 7155 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions5100 7156 * @tc.desc : Get TCPSocket status,Input parameter linger is 65535; promise 7157 * @tc.size : MediumTest 7158 * @tc.type : Function 7159 * @tc.level : level 2 7160 */ 7161 it('testNetworkMgrSocketTCPSocketSetExtraOptions5100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7162 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions5100'; 7163 console.info(`${caseName} test start`); 7164 try { 7165 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7166 expect(tcp).assertInstanceOf('Object'); 7167 let bindAddress: socket.NetAddress = { 7168 address: '127.0.0.1', 7169 port: 10017 7170 }; 7171 await tcp.bind(bindAddress); 7172 let tcpExtraOptions: socket.TCPExtraOptions = { 7173 socketLinger: { 7174 on: true, linger: 65535 7175 }, 7176 }; 7177 tcp.setExtraOptions(tcpExtraOptions).then(() => { 7178 console.info(`${caseName} success `); 7179 expectSuccess(); 7180 done(); 7181 }).catch((err: BusinessError) => { 7182 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 7183 expectFail(); 7184 done(); 7185 }).finally(async () => { 7186 await tcp.close(); 7187 console.info(`${caseName} test end`); 7188 done(); 7189 }); 7190 } catch (err) { 7191 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 7192 expectFail(); 7193 console.info(`${caseName} test end`); 7194 done(); 7195 } 7196 }); 7197 7198 /* * 7199 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_SetExtraOptions_5200 7200 * @tc.name : testNetworkMgrSocketTCPSocketSetExtraOptions5200 7201 * @tc.desc : Get TCPSocket status,Input parameter linger is 65536; promise 7202 * @tc.size : MediumTest 7203 * @tc.type : Function 7204 * @tc.level : level 2 7205 */ 7206 it('testNetworkMgrSocketTCPSocketSetExtraOptions5200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7207 let caseName: string = 'testNetworkMgrSocketTCPSocketSetExtraOptions5200'; 7208 console.info(`${caseName} test start`); 7209 try { 7210 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7211 expect(tcp).assertInstanceOf('Object') 7212 let bindAddress: socket.NetAddress = { 7213 address: '127.0.0.1', 7214 port: 10018 7215 }; 7216 await tcp.bind(bindAddress); 7217 let tcpExtraOptions: socket.TCPExtraOptions = { 7218 socketLinger: { 7219 on: true, linger: 65536 7220 }, 7221 }; 7222 tcp.setExtraOptions(tcpExtraOptions).then(() => { 7223 console.info(`${caseName} success `); 7224 expectSuccess(); 7225 done(); 7226 }).catch((err: BusinessError) => { 7227 console.info(`${caseName} fail err:${JSON.stringify(err)}`); 7228 expectFail(); 7229 done(); 7230 }).finally(async () => { 7231 await tcp.close(); 7232 console.info(`${caseName} test end`); 7233 done(); 7234 }); 7235 } catch (err) { 7236 console.info(`${caseName}_catch fail ${JSON.stringify(err)}`); 7237 expectFail(); 7238 console.info(`${caseName} test end`); 7239 done(); 7240 } 7241 }); 7242 7243 /* * 7244 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OnMessage_0100 7245 * @tc.name : testNetworkMgrSocketTCPSocketOnMessage0100 7246 * @tc.desc : Subscription to receive message events for TCPSocket connections,after bind and connect 7247 * @tc.size : MediumTest 7248 * @tc.type : Function 7249 * @tc.level : level 2 7250 */ 7251 it('testNetworkMgrSocketTCPSocketOnMessage0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7252 let caseName: string = 'testNetworkMgrSocketTCPSocketOnMessage0100'; 7253 try { 7254 console.info(`${caseName} test start`); 7255 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7256 expect(tcp).assertInstanceOf('Object'); 7257 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 7258 expect(tcpServer).assertInstanceOf('Object'); 7259 let listenAddress: socket.NetAddress = { 7260 address: '127.0.0.1', 7261 port: 4092 7262 }; 7263 await tcpServer.listen(listenAddress); 7264 let tcpConnectOptions: socket.TCPConnectOptions = { 7265 address: listenAddress, 7266 }; 7267 let clientSendOptions: socket.TCPSendOptions = { 7268 data: 'Hello, server!', 7269 encoding: 'UTF-8' 7270 }; 7271 tcpServer.on('connect', async (client: socket.TCPSocketConnection) => { 7272 await client.send(clientSendOptions); 7273 }); 7274 await tcp.connect(tcpConnectOptions); 7275 class SocketInfo { 7276 message: ArrayBuffer = new ArrayBuffer(1); 7277 remoteInfo: socket.SocketRemoteInfo = {} as socket.SocketRemoteInfo; 7278 }; 7279 const callback: Callback<socket.SocketMessageInfo> = async (value: SocketInfo) => { 7280 console.info(`${caseName} value:${ArrayBufferToString(value.message)}`); 7281 expectTrue(ArrayBufferToString(value.message) === 'Hello, server!'); 7282 tcpServer.off('connect'); 7283 await tcp.close(); 7284 console.info(`${caseName} test end`); 7285 done(); 7286 }; 7287 tcp.on('message', callback); 7288 } catch (err) { 7289 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7290 expectFail(); 7291 console.info(`${caseName} test end`); 7292 done(); 7293 } 7294 }); 7295 7296 /* * 7297 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OnMessage_0200 7298 * @tc.name : testNetworkMgrSocketTCPSocketOnMessage0200 7299 * @tc.desc : Subscription to receive message events for TCPSocket connections,after listen and connect 7300 * @tc.size : MediumTest 7301 * @tc.type : Function 7302 * @tc.level : level 2 7303 */ 7304 it('testNetworkMgrSocketTCPSocketOnMessage0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7305 let caseName: string = 'testNetworkMgrSocketTCPSocketOnMessage0200'; 7306 try { 7307 console.info(`${caseName} test start`); 7308 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7309 expect(tcp).assertInstanceOf('Object'); 7310 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 7311 expect(tcpServer).assertInstanceOf('Object'); 7312 let listenAddress: socket.NetAddress = { 7313 address: '127.0.0.1', 7314 port: 4093 7315 }; 7316 await tcpServer.listen(listenAddress); 7317 let tcpConnectOptions: socket.TCPConnectOptions = { 7318 address: listenAddress, 7319 }; 7320 let clientSendOptions: socket.TCPSendOptions = { 7321 data: 'Hello, server!', 7322 encoding: 'UTF-8' 7323 }; 7324 tcpServer.on('connect', async (client: socket.TCPSocketConnection) => { 7325 await client.send(clientSendOptions); 7326 }); 7327 await tcp.connect(tcpConnectOptions); 7328 class SocketInfo { 7329 message: ArrayBuffer = new ArrayBuffer(1); 7330 remoteInfo: socket.SocketRemoteInfo = {} as socket.SocketRemoteInfo; 7331 }; 7332 const callback: Callback<socket.SocketMessageInfo> = async (value: SocketInfo) => { 7333 console.info(`${caseName} value:${ArrayBufferToString(value.message)}`); 7334 expectTrue(ArrayBufferToString(value.message) === 'Hello, server!'); 7335 tcpServer.off('connect'); 7336 await tcp.close(); 7337 console.info(`${caseName} test end`); 7338 done(); 7339 }; 7340 tcp.on('message', callback); 7341 } catch (err) { 7342 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7343 expectFail(); 7344 console.info(`${caseName} test end`); 7345 done(); 7346 } 7347 }); 7348 7349 /* * 7350 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OffMessage_0100 7351 * @tc.name : testNetworkMgrSocketTCPSocketOffMessage0100 7352 * @tc.desc : Unsubscribe from receiving message events for TCPSocket connections,After a subscription 7353 * @tc.size : MediumTest 7354 * @tc.type : Function 7355 * @tc.level : level 2 7356 */ 7357 it('testNetworkMgrSocketTCPSocketOffMessage0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7358 let caseName: string = 'testNetworkMgrSocketTCPSocketOffMessage0100'; 7359 try { 7360 console.info(`${caseName} test start`); 7361 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7362 expect(tcp).assertInstanceOf('Object'); 7363 let bindAddress: socket.NetAddress = { 7364 address: '127.0.0.1', 7365 port: 4094 7366 }; 7367 await tcp.bind(bindAddress); 7368 let tcpConnectOptions: socket.TCPConnectOptions = { 7369 address: bindAddress, 7370 }; 7371 await tcp.connect(tcpConnectOptions); 7372 let tcpSendOptions: socket.TCPSendOptions = { 7373 data: 'Hello, client!', 7374 encoding: 'UTF-8' 7375 }; 7376 const callback: Callback<socket.SocketMessageInfo> = () => { 7377 expectFail(); 7378 console.info(`${caseName} test end`); 7379 done(); 7380 }; 7381 tcp.on('message', callback); 7382 tcp.off('message', callback); 7383 await tcp.send(tcpSendOptions); 7384 await tcp.close(); 7385 expectSuccess(); 7386 done(); 7387 } catch (err) { 7388 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7389 expectFail(); 7390 console.info(`${caseName} test end`); 7391 done(); 7392 } 7393 }); 7394 7395 /* * 7396 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OffMessage_0200 7397 * @tc.name : testNetworkMgrSocketTCPSocketOffMessage0200 7398 * @tc.desc : Unsubscribe from receiving message events for TCPSocket connections,After Subscribing multiple times 7399 * @tc.size : MediumTest 7400 * @tc.type : Function 7401 * @tc.level : level 2 7402 */ 7403 it('testNetworkMgrSocketTCPSocketOffMessage0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7404 let caseName: string = 'testNetworkMgrSocketTCPSocketOffMessage0200'; 7405 try { 7406 console.info(`${caseName} test start`); 7407 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7408 expect(tcp).assertInstanceOf('Object'); 7409 let bindAddress: socket.NetAddress = { 7410 address: '127.0.0.1', 7411 port: 4095 7412 }; 7413 await tcp.bind(bindAddress); 7414 let tcpConnectOptions: socket.TCPConnectOptions = { 7415 address: bindAddress, 7416 }; 7417 await tcp.connect(tcpConnectOptions); 7418 let tcpSendOptions: socket.TCPSendOptions = { 7419 data: 'Hello, client!', 7420 encoding: 'UTF-8' 7421 }; 7422 const callback1: Callback<socket.SocketMessageInfo> = () => { 7423 expectFail(); 7424 console.info(`${caseName} callback1 test end`); 7425 done(); 7426 }; 7427 const callback2: Callback<socket.SocketMessageInfo> = () => { 7428 expectFail(); 7429 console.info(`${caseName} callback2 test end`); 7430 done(); 7431 }; 7432 tcp.on('message', callback1); 7433 tcp.on('message', callback2); 7434 tcp.off('message'); 7435 await tcp.send(tcpSendOptions); 7436 expectSuccess(); 7437 await tcp.close(); 7438 done(); 7439 } catch (err) { 7440 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7441 expectFail(); 7442 console.info(`${caseName} test end`); 7443 done(); 7444 } 7445 }); 7446 7447 /* * 7448 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OnConnect_0100 7449 * @tc.name : testNetworkMgrSocketTCPSocketOnConnect0100 7450 * @tc.desc : Subscription to connection events for TCPSocket after bind 7451 * @tc.size : MediumTest 7452 * @tc.type : Function 7453 * @tc.level : level 2 7454 */ 7455 it('testNetworkMgrSocketTCPSocketOnConnect0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7456 let caseName: string = 'testNetworkMgrSocketTCPSocketOnConnect0100'; 7457 try { 7458 console.info(`${caseName} test start`); 7459 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7460 expect(tcp).assertInstanceOf('Object'); 7461 let bindAddress: socket.NetAddress = { 7462 address: '127.0.0.1', 7463 port: 4096 7464 }; 7465 await tcp.bind(bindAddress); 7466 let tcpConnectOptions: socket.TCPConnectOptions = { 7467 address: bindAddress, 7468 }; 7469 const callback: Callback<void> = async () => { 7470 expectSuccess(); 7471 console.info(`${caseName} test end`); 7472 await tcp.close(); 7473 done(); 7474 }; 7475 tcp.on('connect', callback); 7476 await tcp.connect(tcpConnectOptions); 7477 } catch (err) { 7478 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7479 expectFail(); 7480 console.info(`${caseName} test end`); 7481 done(); 7482 } 7483 }); 7484 7485 /* * 7486 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OnConnect_0200 7487 * @tc.name : testNetworkMgrSocketTCPSocketOnConnect0200 7488 * @tc.desc : Subscription to connection events for TCPSocket,after listen 7489 * @tc.size : MediumTest 7490 * @tc.type : Function 7491 * @tc.level : level 2 7492 */ 7493 it('testNetworkMgrSocketTCPSocketOnConnect0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7494 let caseName: string = 'testNetworkMgrSocketTCPSocketOnConnect0200'; 7495 try { 7496 console.info(`${caseName} test start`); 7497 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7498 expect(tcp).assertInstanceOf('Object'); 7499 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 7500 expect(tcpServer).assertInstanceOf('Object'); 7501 let listenAddress: socket.NetAddress = { 7502 address: '127.0.0.1', 7503 port: 4097 7504 }; 7505 await tcpServer.listen(listenAddress); 7506 let tcpConnectOptions: socket.TCPConnectOptions = { 7507 address: listenAddress, 7508 }; 7509 const callback: Callback<void> = async () => { 7510 console.info(`${caseName} test end`); 7511 await tcp.close(); 7512 expectSuccess(); 7513 done(); 7514 }; 7515 tcp.on('connect', callback); 7516 await tcp.connect(tcpConnectOptions); 7517 console.info(`${caseName} test end`); 7518 done(); 7519 } catch (err) { 7520 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7521 expectFail(); 7522 console.info(`${caseName} test end`); 7523 done(); 7524 } 7525 }); 7526 7527 /* * 7528 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OffConnect_0100 7529 * @tc.name : testNetworkMgrSocketTCPSocketOffConnect0100 7530 * @tc.desc : Unsubscribe from TCP Socket connection events,After a subscription 7531 * @tc.size : MediumTest 7532 * @tc.type : Function 7533 * @tc.level : level 2 7534 */ 7535 it('testNetworkMgrSocketTCPSocketOffConnect0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7536 let caseName: string = 'testNetworkMgrSocketTCPSocketOffConnect0100'; 7537 try { 7538 console.info(`${caseName} test start`); 7539 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7540 expect(tcp).assertInstanceOf('Object'); 7541 let bindAddress: socket.NetAddress = { 7542 address: '127.0.0.1', 7543 port: 4098 7544 }; 7545 await tcp.bind(bindAddress); 7546 let tcpConnectOptions: socket.TCPConnectOptions = { 7547 address: bindAddress, 7548 }; 7549 const callback: Callback<void> = async () => { 7550 expectFail(); 7551 console.info(`${caseName} test end`); 7552 done(); 7553 }; 7554 tcp.on('connect', callback); 7555 tcp.off('connect', callback); 7556 await tcp.connect(tcpConnectOptions); 7557 expectSuccess(); 7558 console.info(`${caseName} test end`); 7559 done(); 7560 } catch (err) { 7561 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7562 expectFail(); 7563 console.info(`${caseName} test end`); 7564 done(); 7565 } 7566 }); 7567 7568 /* * 7569 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OffConnect_0100 7570 * @tc.name : testNetworkMgrSocketTCPSocketOffConnect0100 7571 * @tc.desc : Unsubscribe from TCP Socket connection events,After Subscribing multiple times 7572 * @tc.size : MediumTest 7573 * @tc.type : Function 7574 * @tc.level : level 2 7575 */ 7576 it('testNetworkMgrSocketTCPSocketOffConnect0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7577 let caseName: string = 'testNetworkMgrSocketTCPSocketOffConnect0200'; 7578 try { 7579 console.info(`${caseName} test start`); 7580 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7581 expect(tcp).assertInstanceOf('Object'); 7582 let bindAddress: socket.NetAddress = { 7583 address: '127.0.0.1', 7584 port: 4099 7585 }; 7586 await tcp.bind(bindAddress); 7587 let tcpConnectOptions: socket.TCPConnectOptions = { 7588 address: bindAddress, 7589 }; 7590 const callback1: Callback<void> = async () => { 7591 expectFail(); 7592 console.info(`${caseName} test end`); 7593 done(); 7594 }; 7595 const callback2: Callback<void> = async () => { 7596 expectFail(); 7597 console.info(`${caseName} test end`); 7598 done(); 7599 }; 7600 tcp.on('connect', callback1); 7601 tcp.on('connect', callback2); 7602 tcp.off('connect'); 7603 await tcp.connect(tcpConnectOptions); 7604 expectSuccess(); 7605 console.info(`${caseName} test end`); 7606 done(); 7607 } catch (err) { 7608 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7609 expectFail(); 7610 console.info(`${caseName} test end`); 7611 done(); 7612 } 7613 }); 7614 7615 /* * 7616 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OnClose_0100 7617 * @tc.name : testNetworkMgrSocketTCPSocketOnClose0100 7618 * @tc.desc : Subscribe to the closure event of TCPSocket, after bind 7619 * @tc.size : MediumTest 7620 * @tc.type : Function 7621 * @tc.level : level 2 7622 */ 7623 it('testNetworkMgrSocketTCPSocketOnClose0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7624 let caseName: string = 'testNetworkMgrSocketTCPSocketOnClose0100'; 7625 try { 7626 console.info(`${caseName} test start`); 7627 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7628 expect(tcp).assertInstanceOf('Object'); 7629 let bindAddress: socket.NetAddress = { 7630 address: '127.0.0.1', 7631 port: 4100 7632 }; 7633 await tcp.bind(bindAddress); 7634 const callback: Callback<void> = async () => { 7635 expectSuccess(); 7636 console.info(`${caseName} test end`); 7637 done(); 7638 }; 7639 tcp.on('close', callback); 7640 await tcp.close(); 7641 console.info(`${caseName} test end`); 7642 done(); 7643 } catch (err) { 7644 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7645 expectFail(); 7646 console.info(`${caseName} test end`); 7647 done(); 7648 } 7649 }); 7650 7651 /* * 7652 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OnClose_0200 7653 * @tc.name : testNetworkMgrSocketTCPSocketOnClose0200 7654 * @tc.desc : Subscribe to the closure event of TCPSocket,after listen 7655 * @tc.size : MediumTest 7656 * @tc.type : Function 7657 * @tc.level : level 2 7658 */ 7659 it('testNetworkMgrSocketTCPSocketOnClose0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7660 let caseName: string = 'testNetworkMgrSocketTCPSocketOnClose0200'; 7661 try { 7662 console.info(`${caseName} test start`); 7663 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7664 expect(tcp).assertInstanceOf('Object'); 7665 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance(); 7666 expect(tcpServer).assertInstanceOf('Object'); 7667 let listenAddress: socket.NetAddress = { 7668 address: '127.0.0.1', 7669 port: 4101 7670 }; 7671 await tcpServer.listen(listenAddress); 7672 let tcpConnectOptions: socket.TCPConnectOptions = { 7673 address: listenAddress, 7674 timeout: 6000 7675 }; 7676 await tcp.connect(tcpConnectOptions); 7677 const callback: Callback<void> = () => { 7678 expectSuccess(); 7679 console.info(`${caseName} test end`); 7680 done(); 7681 }; 7682 tcp.on('close', callback); 7683 await tcp.close(); 7684 console.info(`${caseName} test end`); 7685 done(); 7686 } catch (err) { 7687 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7688 expectFail(); 7689 console.info(`${caseName} test end`); 7690 done(); 7691 } 7692 }); 7693 7694 /* * 7695 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OffClose_0100 7696 * @tc.name : testNetworkMgrSocketTCPSocketOffClose0100 7697 * @tc.desc : Unsubscribe from the closing event of TCPSocket,After a subscription 7698 * @tc.size : MediumTest 7699 * @tc.type : Function 7700 * @tc.level : level 2 7701 */ 7702 it('testNetworkMgrSocketTCPSocketOffClose0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7703 let caseName: string = 'testNetworkMgrSocketTCPSocketOffClose0100'; 7704 try { 7705 console.info(`${caseName} test start`); 7706 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7707 expect(tcp).assertInstanceOf('Object'); 7708 let bindAddress: socket.NetAddress = { 7709 address: '127.0.0.1', 7710 port: 4102 7711 }; 7712 await tcp.bind(bindAddress); 7713 const callback: Callback<void> = async () => { 7714 expectFail(); 7715 console.info(`${caseName} test end`); 7716 done(); 7717 }; 7718 tcp.on('close', callback); 7719 tcp.off('close', callback); 7720 await tcp.close(); 7721 expectSuccess(); 7722 console.info(`${caseName} test end`); 7723 done(); 7724 } catch (err) { 7725 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7726 expectFail(); 7727 console.info(`${caseName} test end`); 7728 done(); 7729 } 7730 }); 7731 7732 /* * 7733 * @tc.number: SUB_NetworkMgr_Socket_TCPSocket_OffClose_0200 7734 * @tc.name : testNetworkMgrSocketTCPSocketOffClose0200 7735 * @tc.desc : Unsubscribe from the closing event of TCPSocket,After Subscribing multiple times 7736 * @tc.size : MediumTest 7737 * @tc.type : Function 7738 * @tc.level : level 2 7739 */ 7740 it('testNetworkMgrSocketTCPSocketOffClose0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { 7741 let caseName: string = 'testNetworkMgrSocketTCPSocketOffClose0200'; 7742 try { 7743 console.info(`${caseName} test start`); 7744 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance(); 7745 expect(tcp).assertInstanceOf('Object'); 7746 let bindAddress: socket.NetAddress = { 7747 address: '127.0.0.1', 7748 port: 4103 7749 }; 7750 await tcp.bind(bindAddress); 7751 const callback1: Callback<void> = async () => { 7752 expectFail(); 7753 console.info(`${caseName} test end`); 7754 done(); 7755 }; 7756 const callback2: Callback<void> = async () => { 7757 expectFail(); 7758 console.info(`${caseName} test end`); 7759 done(); 7760 }; 7761 tcp.on('close', callback1); 7762 tcp.on('close', callback2); 7763 tcp.off('close'); 7764 await tcp.close(); 7765 expectSuccess(); 7766 console.info(`${caseName} test end`); 7767 done(); 7768 } catch (err) { 7769 console.info(`${caseName}_catch fail err:${JSON.stringify(err)}`); 7770 expectFail(); 7771 console.info(`${caseName} test end`); 7772 done(); 7773 } 7774 }); 7775 7776 7777 }) 7778} 7779