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